annotate src/debug.c @ 176:ac6e22c8a9cf

build separate libpst, libpst-libs, libpst-devel rpms. remove many functions from the interface by making them static.
author Carl Byington <carl@five-ten-sg.com>
date Wed, 08 Apr 2009 14:13:06 -0700
parents 6954d315aaa8
children 2f38c4ce606f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
1 #include "define.h"
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
2
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
3 struct pst_debug_item {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
4 int type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
5 char * function;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
6 unsigned int line;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
7 char * file;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
8 char * text;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
9 struct pst_debug_item *next;
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
10 };
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
11
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
12 static struct pst_debug_item *item_head=NULL, *item_tail=NULL, *item_ptr=NULL, *info_ptr=NULL, *temp_list=NULL;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
13
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
14
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
15 struct pst_debug_func {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
16 char * name;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
17 struct pst_debug_func *next;
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
18 };
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
19
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
20 static struct pst_debug_func *func_head=NULL, *func_ptr=NULL;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
21
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
22
176
ac6e22c8a9cf build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
23 static void pst_debug_write_msg(struct pst_debug_item *item, const char *fmt, va_list *ap, int size);
ac6e22c8a9cf build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
24 static void pst_debug_write_hex(struct pst_debug_item *item, char *buf, size_t size, int col);
ac6e22c8a9cf build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
25 static void pst_debug_write();
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
26
176
ac6e22c8a9cf build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
27
ac6e22c8a9cf build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
28 static size_t pst_debug_fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream);
ac6e22c8a9cf build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
29 static size_t pst_debug_fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream) {
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
30 return fwrite(ptr, size, nitems, stream);
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
31 }
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
32
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
33
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
34 // the largest text size we will store in memory. Otherwise we
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
35 // will do a debug_write, then create a new record, and write the
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
36 // text body directly to the file
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
37 #define MAX_MESSAGE_SIZE 4096
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
38
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
39 void pst_debug(const char *fmt, ...) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
40 va_list ap;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
41 va_start(ap,fmt);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
42 vfprintf(stderr, fmt, ap);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
43 va_end(ap);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
44 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
45
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
46
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
47 #define NUM_COL 30
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
48 void pst_debug_hexdumper(FILE *out, char *buf, size_t size, int col, int delta) {
70
b12f4e50e2e8 Patch from Joachim Metz <joachim.metz@gmail.com> for 64 bit compile.
Carl Byington <carl@five-ten-sg.com>
parents: 48
diff changeset
49 size_t off = 0, toff;
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
50 int count = 0;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
51
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
52 if (!out) return; // no file
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
53 if (col == -1) col = NUM_COL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
54 fprintf(out, "\n");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
55 while (off < size) {
125
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
56 fprintf(out, "%06"PRIx64"\t:", (int64_t)(off+delta));
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
57 toff = off;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
58 while (count < col && off < size) {
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
59 fprintf(out, "%02hhx ", (unsigned char)buf[off]);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
60 off++; count++;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
61 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
62 off = toff;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
63 while (count < col) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
64 // only happens at end of block to pad the text over to the text column
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
65 fprintf(out, " ");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
66 count++;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
67 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
68 count = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
69 fprintf(out, ":");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
70 while (count < col && off < size) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
71 fprintf(out, "%c", isgraph(buf[off])?buf[off]:'.');
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
72 off++; count ++;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
73 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
74
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
75 fprintf(out, "\n");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
76 count=0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
77 }
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
78
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
79 fprintf(out, "\n");
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
80 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
81
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
82
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
83 static FILE *debug_fp = NULL;
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
84 static unsigned int max_items=DEBUG_MAX_ITEMS, curr_items=0;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
85
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
86
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
87 void pst_debug_init(const char* fname) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
88 unsigned char version = DEBUG_VERSION;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
89 item_head = item_tail = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
90 curr_items = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
91 if (debug_fp) pst_debug_close();
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
92 if (!fname) return;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
93 if ((debug_fp = fopen(fname, "wb")) == NULL) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
94 fprintf(stderr, "Opening of file %s failed\n", fname);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
95 exit(1);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
96 }
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
97 pst_debug_fwrite(&version, sizeof(char), 1, debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
98 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
99
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
100
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
101 // function must be called before pst_debug_msg. It sets up the
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
102 // structure for the function that follows
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
103 void pst_debug_msg_info(int line, const char* file, int type) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
104 char *x;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
105 if (!debug_fp) return; // no file
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
106 info_ptr = (struct pst_debug_item*) pst_malloc(sizeof(struct pst_debug_item));
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
107 info_ptr->type = type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
108 info_ptr->line = line;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
109 x = (func_head==NULL?"No Function":func_head->name);
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
110 info_ptr->function = (char*) pst_malloc(strlen(x)+1);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
111 strcpy(info_ptr->function, x);
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
112
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
113 info_ptr->file = (char*) pst_malloc(strlen(file)+1);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
114 strcpy(info_ptr->file, file);
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
115
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
116 //put the current record on a temp linked list
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
117 info_ptr->next = temp_list;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
118 temp_list = info_ptr;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
119 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
120
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
121
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
122 void pst_debug_msg_text(const char* fmt, ...) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
123 va_list ap;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
124 int f, g;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
125 char x[2];
79
56fa05fd5271 Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents: 75
diff changeset
126 #ifdef _WIN32
56fa05fd5271 Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents: 75
diff changeset
127 char *buf = NULL;
56fa05fd5271 Patch from Robert Simpson for encryption type 2.
Carl Byington <carl@five-ten-sg.com>
parents: 75
diff changeset
128 #endif
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
129 struct pst_debug_item *temp;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
130 if (!debug_fp) return; // no file
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
131 // get the record off of the temp_list
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
132 info_ptr = temp_list;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
133 if (info_ptr)
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
134 temp_list = info_ptr->next;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
135 else {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
136 fprintf(stderr, "NULL info_ptr. ERROR!!\n");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
137 exit(-2);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
138 }
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
139
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
140 #ifdef _WIN32
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
141 // vsnprintf trick doesn't work on msvc.
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
142 g = 2000;
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
143 f = -1;
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
144 while (f < 0) {
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
145 buf = realloc(buf, g+1);
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
146 va_start(ap, fmt);
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
147 f = vsnprintf(buf, g, fmt, ap);
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
148 va_end(ap);
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
149 g += g/2;
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
150 }
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
151 free(buf);
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
152 #else
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
153 // according to glibc 2.1, this should return the req. number of bytes for
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
154 // the string
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
155 va_start(ap, fmt);
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
156 f = vsnprintf(x, 1, fmt, ap);
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
157 va_end(ap);
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
158 #endif
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
159
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
160 if (f > 0 && f < MAX_MESSAGE_SIZE) {
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
161 info_ptr->text = (char*) pst_malloc(f+1);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
162 va_start(ap, fmt);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
163 if ((g = vsnprintf(info_ptr->text, f, fmt, ap)) == -1) {
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
164 fprintf(stderr, "_debug_msg: Dying! vsnprintf returned -1 for format \"%s\"\n", fmt);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
165 exit(-2);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
166 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
167 va_end(ap);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
168 info_ptr->text[g] = '\0';
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
169 if (f != g) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
170 fprintf(stderr, "_debug_msg: f != g\n");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
171 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
172 } else if (f > 0) { // it is over the max_message_size then
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
173 f += strlen(info_ptr->file)+strlen(info_ptr->function);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
174 temp = info_ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
175 pst_debug_write(); // dump the current messages
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
176 info_ptr = temp;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
177 va_start(ap, fmt);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
178 pst_debug_write_msg(info_ptr, fmt, &ap, f);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
179 va_end(ap);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
180 free(info_ptr->function);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
181 free(info_ptr->file);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
182 free(info_ptr);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
183 info_ptr = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
184 return;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
185 } else {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
186 fprintf(stderr, "_debug_msg: error getting requested size of debug message\n");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
187 info_ptr->text = "ERROR Saving\n";
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
188 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
189
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
190 // add to the linked list of pending items
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
191 if (!item_head) item_head = info_ptr;
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
192 info_ptr->next = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
193 if (item_tail) item_tail->next = info_ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
194 item_tail = info_ptr;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
195
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
196 if (++curr_items == max_items) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
197 // here we will jump off and save the contents
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
198 pst_debug_write();
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
199 info_ptr = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
200 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
201 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
202
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
203
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
204 void pst_debug_hexdump(char *x, size_t y, int cols, int delta) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
205 struct pst_debug_item *temp;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
206 if (!debug_fp) return; // no file
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
207 info_ptr = temp_list;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
208 if (info_ptr) temp_list = info_ptr->next;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
209 temp = info_ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
210 pst_debug_write();
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
211 info_ptr = temp;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
212 pst_debug_write_hex(info_ptr, x, y, cols);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
213 free(info_ptr->function);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
214 free(info_ptr->file);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
215 free(info_ptr);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
216 info_ptr = NULL;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
217 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
218
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
219
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
220 void pst_debug_func(const char *function) {
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
221 func_ptr = pst_malloc (sizeof(struct pst_debug_func));
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
222 func_ptr->name = pst_malloc(strlen(function)+1);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
223 strcpy(func_ptr->name, function);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
224 func_ptr->next = func_head;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
225 func_head = func_ptr;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
226 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
227
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
228
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
229 void pst_debug_func_ret() {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
230 //remove the head item
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
231 func_ptr = func_head;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
232 if (func_head) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
233 func_head = func_head->next;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
234 free(func_ptr->name);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
235 free(func_ptr);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
236 } else {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
237 DIE(("function list is empty!\n"));
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
238 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
239 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
240
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
241
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
242 void pst_debug_close(void) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
243 pst_debug_write();
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
244 while (func_head) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
245 func_ptr = func_head;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
246 func_head = func_head->next;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
247 free(func_ptr->name);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
248 free(func_ptr);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
249 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
250 if (debug_fp) fclose(debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
251 debug_fp = NULL;
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
252 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
253
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
254
176
ac6e22c8a9cf build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
255 static void pst_debug_write() {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
256 size_t size, ptr, funcname, filename, text, end;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
257 char *buf = NULL, rec_type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
258 if (!debug_fp) return; // no file
125
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
259 int64_t index_pos = ftello(debug_fp);
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
260 int64_t file_pos = index_pos;
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
261 // add 2. One for the pointer to the next index,
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
262 // one for the count of this index
125
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
263 int index_size = ((curr_items+2) * sizeof(int64_t));
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
264 int64_t *index;
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
265 int index_ptr = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
266 struct pst_debug_file_rec_m mfile_rec;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
267 struct pst_debug_file_rec_l lfile_rec;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
268
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
269 if (curr_items == 0) return; // no items to write.
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
270
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
271 index = (int64_t*)pst_malloc(index_size);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
272 memset(index, 0, index_size); // valgrind, avoid writing uninitialized data
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
273 file_pos += index_size;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
274 // write the index first, we will re-write it later, but
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
275 // we want to allocate the space
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
276 pst_debug_fwrite(index, index_size, 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
277 index[index_ptr++] = curr_items;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
278
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
279 item_ptr = item_head;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
280 while (item_ptr) {
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
281 file_pos = ftello(debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
282 index[index_ptr++] = file_pos;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
283 size = strlen(item_ptr->function) +
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
284 strlen(item_ptr->file) +
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
285 strlen(item_ptr->text) + 3; //for the three \0s
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
286 if (buf) free(buf);
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
287 buf = pst_malloc(size+1);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
288 ptr = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
289 funcname=ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
290 ptr += sprintf(&(buf[ptr]), "%s", item_ptr->function)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
291 filename=ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
292 ptr += sprintf(&(buf[ptr]), "%s", item_ptr->file)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
293 text=ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
294 ptr += sprintf(&(buf[ptr]), "%s", item_ptr->text)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
295 end=ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
296 if (end > USHRT_MAX) { // bigger than can be stored in a short
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
297 rec_type = 'L';
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
298 pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
299 lfile_rec.type = item_ptr->type;
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
300 lfile_rec.line = item_ptr->line;
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
301 lfile_rec.funcname = funcname;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
302 lfile_rec.filename = filename;
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
303 lfile_rec.text = text;
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
304 lfile_rec.end = end;
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
305 pst_debug_fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
306 } else {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
307 rec_type = 'M';
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
308 pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
309 mfile_rec.type = item_ptr->type;
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
310 mfile_rec.line = item_ptr->line;
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
311 mfile_rec.funcname = funcname;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
312 mfile_rec.filename = filename;
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
313 mfile_rec.text = text;
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
314 mfile_rec.end = end;
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
315 pst_debug_fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
316 }
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
317 pst_debug_fwrite(buf, ptr, 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
318 if (buf) free(buf); buf = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
319 item_head = item_ptr->next;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
320 free(item_ptr->function);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
321 free(item_ptr->file);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
322 free(item_ptr->text);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
323 free(item_ptr);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
324 item_ptr = item_head;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
325 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
326 curr_items = 0;
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
327 index[index_ptr] = ftello(debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
328
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
329 // we should now have a complete index
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
330 fseeko(debug_fp, index_pos, SEEK_SET);
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
331 pst_debug_fwrite(index, index_size, 1, debug_fp);
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
332 fseeko(debug_fp, 0, SEEK_END);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
333 item_ptr = item_head = item_tail = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
334 free(index);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
335 if (buf) free(buf);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
336 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
337
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
338
176
ac6e22c8a9cf build separate libpst, libpst-libs, libpst-devel rpms.
Carl Byington <carl@five-ten-sg.com>
parents: 172
diff changeset
339 static void pst_debug_write_msg(struct pst_debug_item *item, const char *fmt, va_list *ap, int size) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
340 struct pst_debug_file_rec_l lfile_rec;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
341 struct pst_debug_file_rec_m mfile_rec;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
342 unsigned char rec_type;
125
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
343 int index_size = 3 * sizeof(int64_t);
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
344 int64_t index[3];
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
345 int64_t index_pos, file_pos;
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
346 char zero = '\0';
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
347 unsigned int end;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
348 if (!debug_fp) return; // no file
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
349 index[0] = 1; // only one item in this index
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
350 index[1] = 0; // valgrind, avoid writing uninitialized data
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
351 index[2] = 0; // ""
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
352 index_pos = ftello(debug_fp);
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
353 pst_debug_fwrite(index, index_size, 1, debug_fp);
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
354
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
355 index[1] = ftello(debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
356
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
357 if (size > USHRT_MAX) { // bigger than can be stored in a short
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
358 rec_type = 'L';
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
359 pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
360 lfile_rec.type = item->type;
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
361 lfile_rec.line = item->line;
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
362 lfile_rec.funcname = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
363 lfile_rec.filename = strlen(item->function)+1;
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
364 lfile_rec.text = lfile_rec.filename+strlen(item->file)+1;
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
365 lfile_rec.end = 0; // valgrind, avoid writing uninitialized data
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
366 pst_debug_fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
367 } else {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
368 rec_type = 'M';
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
369 pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
370 mfile_rec.type = item->type;
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
371 mfile_rec.line = item->line;
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
372 mfile_rec.funcname = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
373 mfile_rec.filename = strlen(item->function)+1;
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
374 mfile_rec.text = mfile_rec.filename+strlen(item->file)+1;
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
375 mfile_rec.end = 0; // valgrind, avoid writing uninitialized data
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
376 pst_debug_fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
377 }
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
378 file_pos = ftello(debug_fp);
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
379 pst_debug_fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
380 pst_debug_fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
381 vfprintf(debug_fp, fmt, *ap);
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
382 pst_debug_fwrite(&zero, 1, 1, debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
383
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
384 end = (unsigned int) (ftello(debug_fp) - file_pos);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
385
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
386 index[2] = ftello(debug_fp);
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
387 fseeko(debug_fp, index_pos, SEEK_SET);
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
388 pst_debug_fwrite(index, index_size, 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
389 if (size > USHRT_MAX) {
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
390 pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
391 lfile_rec.end = end;
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
392 pst_debug_fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
393 } else {
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
394 pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
395 mfile_rec.end = end;
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
396 pst_debug_fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
397 }
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
398 fseeko(debug_fp, 0, SEEK_END);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
399 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
400
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
401
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
402 void pst_debug_write_hex(struct pst_debug_item *item, char *buf, size_t size, int col) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
403 struct pst_debug_file_rec_l lfile_rec;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
404 unsigned char rec_type;
125
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
405 int index_size = 3 * sizeof(int64_t);
23a36ac0514d recover dropped pragma pack line, use int64_t rather than off_t to avoid forcing users of the shared library to enable large file support.
Carl Byington <carl@five-ten-sg.com>
parents: 123
diff changeset
406 int64_t index_pos, file_pos, index[3];
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
407 char zero='\0';
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
408 if (!debug_fp) return; // no file
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
409 index[0] = 1; // only one item in this index run
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
410 index[1] = 0; // valgrind, avoid writing uninitialized data
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
411 index[2] = 0; // ""
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
412 index_pos = ftello(debug_fp);
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
413 pst_debug_fwrite(index, index_size, 1, debug_fp);
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
414 index[1] = ftello(debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
415
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
416 // always use the long
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
417 rec_type = 'L';
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
418 pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
419 lfile_rec.funcname = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
420 lfile_rec.filename = strlen(item->function)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
421 lfile_rec.text = lfile_rec.filename+strlen(item->file)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
422 lfile_rec.end = 0; // valgrind, avoid writing uninitialized data
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
423 lfile_rec.line = item->line;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
424 lfile_rec.type = item->type;
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
425 pst_debug_fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
426
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
427 file_pos = ftello(debug_fp);
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
428 pst_debug_fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
429 pst_debug_fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
430
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
431 pst_debug_hexdumper(debug_fp, buf, size, col, 0);
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
432 pst_debug_fwrite(&zero, 1, 1, debug_fp);
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
433 lfile_rec.end = ftello(debug_fp) - file_pos;
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
434
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
435 index[2] = ftello(debug_fp);
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
436 fseeko(debug_fp, index_pos, SEEK_SET);
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
437 pst_debug_fwrite(index, index_size, 1, debug_fp);
101
1fc33da23175 fix for orphan children when building descriptor tree, avoid writing uninitialized data to debug log file
Carl Byington <carl@five-ten-sg.com>
parents: 91
diff changeset
438 pst_debug_fwrite(&rec_type, sizeof(char), 1, debug_fp);
73
3cb02cb1e6cd Patch from Robert Simpson to fix doubly-linked list in the cache_ptr code, and allow arrays of unicode strings (without converting them).
Carl Byington <carl@five-ten-sg.com>
parents: 70
diff changeset
439 pst_debug_fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
75
987aa872294e Use ftello/fseeko to properly handle large files.
Carl Byington <carl@five-ten-sg.com>
parents: 73
diff changeset
440 fseeko(debug_fp, 0, SEEK_END);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
441 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
442
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
443
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
444 void *pst_malloc(size_t size) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
445 void *mem = malloc(size);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
446 if (!mem) {
172
6954d315aaa8 move version-info into main configure.in, and set it properly.
Carl Byington <carl@five-ten-sg.com>
parents: 129
diff changeset
447 fprintf(stderr, "pst_malloc: Out Of memory [req: %ld]\n", (long)size);
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
448 exit(1);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
449 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
450 return mem;
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
451 }
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
452