annotate src/debug.c @ 60:97b7706bdda2

Work around bogus 7c.b5 blocks in some messages that have been read. They appear to have attachments, but of some unknown format. Before the message was read, it did not have any attachments. Use autoscan to cleanup our autoconf system. Use autoconf to detect when we need to use our XGetopt files and other header files. More fields, including BCC. Fix missing LE32_CPU byte swapping for FILETIME types.
author Carl Byington <carl@five-ten-sg.com>
date Sat, 16 Feb 2008 12:26:35 -0800
parents f66078abed38
children b12f4e50e2e8
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
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
2 #include "define.h"
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
3
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
4 #include <stdio.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
5 #include <stdlib.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
6 #include <stdarg.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
7 #include <ctype.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
8 #include <string.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
9 #include <limits.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
10
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
11 #ifdef _WIN32
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
12 # define vsnprintf _vsnprintf
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
13 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
14
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
15 struct pst_debug_item {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
16 int type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
17 char * function;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
18 unsigned int line;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
19 char * file;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
20 char * text;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
21 struct pst_debug_item *next;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
22 } *item_head=NULL, *item_tail=NULL, *item_ptr=NULL, *info_ptr=NULL, *temp_list=NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
23
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
24
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
25 struct pst_debug_func {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
26 char * name;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
27 struct pst_debug_func *next;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
28 } *func_head=NULL, *func_ptr=NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
29
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
30
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
31 void pst_debug_write_msg(struct pst_debug_item *item, char *fmt, va_list *ap, int size);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
32 void pst_debug_write_hex(struct pst_debug_item *item, unsigned char *buf, size_t size, int col);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
33 void * xmalloc(size_t size);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
34
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
35 // the largest text size we will store in memory. Otherwise we
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
36 // will do a debug_write, then create a new record, and write the
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
37 // text body directly to the file
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
38 #define MAX_MESSAGE_SIZE 4096
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
39
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
40 void pst_debug(char *fmt, ...) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
41 va_list ap;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
42 va_start(ap,fmt);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
43 vfprintf(stderr, fmt, ap);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
44 va_end(ap);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
45 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
46
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
47
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
48 #define NUM_COL 30
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
49 void pst_debug_hexdumper(FILE *out, unsigned char *buf, size_t size, int col, int delta) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
50 int off = 0, toff;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
51 int count = 0;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
52
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
53 if (!out) return; // no file
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
54 if (col == -1) col = NUM_COL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
55 fprintf(out, "\n");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
56 while (off < size) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
57 fprintf(out, "%06X\t:", off+delta);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
58 toff = off;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
59 while (count < col && off < size) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
60 fprintf(out, "%02hhx ", buf[off]);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
61 off++; count++;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
62 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
63 off = toff;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
64 while (count < col) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
65 // 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
66 fprintf(out, " ");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
67 count++;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
68 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
69 count = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
70 fprintf(out, ":");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
71 while (count < col && off < size) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
72 fprintf(out, "%c", isgraph(buf[off])?buf[off]:'.');
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
73 off++; count ++;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
74 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
75
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
76 fprintf(out, "\n");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
77 count=0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
78 }
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
79
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
80 fprintf(out, "\n");
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
81 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
82
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
83
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
84 FILE *debug_fp = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
85 unsigned int max_items=DEBUG_MAX_ITEMS, curr_items=0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
86
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
87
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
88 void pst_debug_init(char* fname) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
89 unsigned char version = DEBUG_VERSION;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
90 item_head = item_tail = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
91 curr_items = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
92 if (debug_fp) pst_debug_close();
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
93 if (!fname) return;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
94 if ((debug_fp = fopen(fname, "wb")) == NULL) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
95 fprintf(stderr, "Opening of file %s failed\n", fname);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
96 exit(1);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
97 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
98 fwrite(&version, 1, sizeof(char), debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
99 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
100
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
101
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
102 // function must be called before pst_debug_msg. It sets up the
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
103 // structure for the function that follows
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
104 void pst_debug_msg_info(int line, char* file, int type) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
105 char *x;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
106 if (!debug_fp) return; // no file
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
107 info_ptr = (struct pst_debug_item*) xmalloc(sizeof(struct pst_debug_item));
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
108 info_ptr->type = type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
109 info_ptr->line = line;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
110 x = (func_head==NULL?"No Function":func_head->name);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
111 info_ptr->function = (char*) xmalloc(strlen(x)+1);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
112 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
113
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
114 info_ptr->file = (char*) xmalloc(strlen(file)+1);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
115 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
116
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
117 //put the current record on a temp linked list
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
118 info_ptr->next = temp_list;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
119 temp_list = info_ptr;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
120 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
121
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
122
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
123 void pst_debug_msg_text(char* fmt, ...) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
124 va_list ap;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
125 int f, g;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
126 char x[2];
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
127 struct pst_debug_item *temp;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
128 if (!debug_fp) return; // no file
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
129 va_start(ap, fmt);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
130 // get the record off of the temp_list
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
131 info_ptr = temp_list;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
132 if (info_ptr)
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
133 temp_list = info_ptr->next;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
134 else {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
135 fprintf(stderr, "NULL info_ptr. ERROR!!\n");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
136 exit(-2);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
137 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
138 // according to glibc 2.1, this should return the req. number of bytes for
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
139 // the string
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
140 #ifdef _WIN32
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
141 // vsnprintf trick doesn't work. must use function called _vscprintf
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
142 // cannot find much documentation about this on internet or anywhere.
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
143 // I assume it isn't a standard function, but only in VisualC++
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
144 f = _vscprintf(fmt, ap);
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
145 #else
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
146 f = vsnprintf(x, 1, fmt, ap);
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
147 #endif
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
148 va_end(ap); // must be called after vsnprintf()
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
149
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
150 if (f > 0 && f < MAX_MESSAGE_SIZE) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
151 info_ptr->text = (char*) xmalloc(f+1);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
152 va_start(ap, fmt);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
153 if ((g = vsnprintf(info_ptr->text, f, fmt, ap)) == -1) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
154 fprintf(stderr, "_debug_msg: Dieing! vsnprintf returned -1 for format \"%s\"\n", fmt);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
155 exit(-2);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
156 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
157 va_end(ap);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
158 info_ptr->text[g] = '\0';
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
159 if (f != g) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
160 fprintf(stderr, "_debug_msg: f != g\n");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
161 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
162 } else if (f > 0) { // it is over the max_message_size then
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
163 f += strlen(info_ptr->file)+strlen(info_ptr->function);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
164 temp = info_ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
165 pst_debug_write(); // dump the current messages
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
166 info_ptr = temp;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
167 va_start(ap, fmt);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
168 pst_debug_write_msg(info_ptr, fmt, &ap, f);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
169 va_end(ap);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
170 free(info_ptr->function);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
171 free(info_ptr->file);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
172 free(info_ptr);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
173 info_ptr = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
174 return;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
175 } else {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
176 fprintf(stderr, "_debug_msg: error getting requested size of debug message\n");
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
177 info_ptr->text = "ERROR Saving\n";
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
178 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
179
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
180 if (!item_head)
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
181 item_head = info_ptr;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
182
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
183 info_ptr->next = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
184 if (item_tail) item_tail->next = info_ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
185 item_tail = info_ptr;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
186
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
187 if (++curr_items == max_items) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
188 // here we will jump off and save the contents
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
189 pst_debug_write();
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
190 info_ptr = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
191 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
192 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
193
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
194
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
195 void pst_debug_hexdump(unsigned char *x, size_t y, int cols, int delta) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
196 struct pst_debug_item *temp;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
197 if (!debug_fp) return; // no file
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
198 info_ptr = temp_list;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
199 if (info_ptr) temp_list = info_ptr->next;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
200 temp = info_ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
201 pst_debug_write();
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
202 info_ptr = temp;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
203 pst_debug_write_hex(info_ptr, x, y, cols);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
204 free(info_ptr->function);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
205 free(info_ptr->file);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
206 free(info_ptr);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
207 info_ptr = NULL;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
208 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
209
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
210
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
211 void pst_debug_func(char *function) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
212 func_ptr = xmalloc (sizeof(struct pst_debug_func));
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
213 func_ptr->name = xmalloc(strlen(function)+1);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
214 strcpy(func_ptr->name, function);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
215 func_ptr->next = func_head;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
216 func_head = func_ptr;
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
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
220 void pst_debug_func_ret() {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
221 //remove the head item
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
222 func_ptr = func_head;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
223 if (func_head) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
224 func_head = func_head->next;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
225 free(func_ptr->name);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
226 free(func_ptr);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
227 } else {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
228 DIE(("function list is empty!\n"));
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
229 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
230 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
231
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
232
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
233 void pst_debug_close(void) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
234 pst_debug_write();
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
235 while (func_head) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
236 func_ptr = func_head;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
237 func_head = func_head->next;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
238 free(func_ptr->name);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
239 free(func_ptr);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
240 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
241 if (debug_fp) fclose(debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
242 debug_fp = NULL;
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
243 }
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
244
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
245
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
246 void pst_debug_write() {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
247 size_t size, ptr, funcname, filename, text, end;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
248 char *buf = NULL, rec_type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
249 if (!debug_fp) return; // no file
48
f66078abed38 more fixes for 64 bit format
carl
parents: 46
diff changeset
250 off_t index_pos = ftell(debug_fp);
43
f6db1f060a95 start on outlook 2003 64 bit format
carl
parents: 37
diff changeset
251 off_t file_pos = index_pos;
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
252 // add 2. One for the pointer to the next index,
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
253 // one for the count of this index
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
254 int index_size = ((curr_items+2) * sizeof(off_t));
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
255 off_t *index;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
256 int index_ptr = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
257 struct pst_debug_file_rec_m mfile_rec;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
258 struct pst_debug_file_rec_l lfile_rec;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
259
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
260 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
261
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
262 index = (off_t*)xmalloc(index_size);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
263 memset(index, 0, index_size); // valgrind, avoid writing uninitialized data
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
264 file_pos += index_size;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
265 // write the index first, we will re-write it later, but
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
266 // we want to allocate the space
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
267 fwrite(index, index_size, 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
268 index[index_ptr++] = curr_items;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
269
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
270 item_ptr = item_head;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
271 while (item_ptr) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
272 file_pos = ftell(debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
273 index[index_ptr++] = file_pos;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
274 size = strlen(item_ptr->function) +
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
275 strlen(item_ptr->file) +
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
276 strlen(item_ptr->text) + 3; //for the three \0s
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
277 if (buf) free(buf);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
278 buf = xmalloc(size+1);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
279 ptr = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
280 funcname=ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
281 ptr += sprintf(&(buf[ptr]), "%s", item_ptr->function)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
282 filename=ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
283 ptr += sprintf(&(buf[ptr]), "%s", item_ptr->file)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
284 text=ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
285 ptr += sprintf(&(buf[ptr]), "%s", item_ptr->text)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
286 end=ptr;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
287 if (end > USHRT_MAX) { // bigger than can be stored in a short
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
288 rec_type = 'L';
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
289 fwrite(&rec_type, 1, sizeof(char), debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
290 lfile_rec.type = item_ptr->type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
291 lfile_rec.line = item_ptr->line;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
292 lfile_rec.funcname = funcname;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
293 lfile_rec.filename = filename;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
294 lfile_rec.text = text;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
295 lfile_rec.end = end;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
296 fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
297 } else {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
298 rec_type = 'M';
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
299 fwrite(&rec_type, 1, sizeof(char), debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
300 mfile_rec.type = item_ptr->type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
301 mfile_rec.line = item_ptr->line;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
302 mfile_rec.funcname = funcname;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
303 mfile_rec.filename = filename;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
304 mfile_rec.text = text;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
305 mfile_rec.end = end;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
306 fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
307 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
308 fwrite(buf, 1, ptr, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
309 if (buf) free(buf); buf = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
310 item_head = item_ptr->next;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
311 free(item_ptr->function);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
312 free(item_ptr->file);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
313 free(item_ptr->text);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
314 free(item_ptr);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
315 item_ptr = item_head;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
316 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
317 curr_items = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
318 index[index_ptr] = ftell(debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
319
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
320 // we should now have a complete index
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
321 fseek(debug_fp, index_pos, SEEK_SET);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
322 fwrite(index, index_size, 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
323 fseek(debug_fp, 0, SEEK_END);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
324 item_ptr = item_head = item_tail = NULL;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
325 free(index);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
326 if (buf) free(buf);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
327 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
328
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
329
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
330 void pst_debug_write_msg(struct pst_debug_item *item, char *fmt, va_list *ap, int size) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
331 struct pst_debug_file_rec_l lfile_rec;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
332 struct pst_debug_file_rec_m mfile_rec;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
333 unsigned char rec_type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
334 int index_size = 3 * sizeof(off_t);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
335 off_t index[3];
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
336 off_t index_pos, file_pos;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
337 char zero='\0';
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
338 unsigned int end;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
339 if (!debug_fp) return; // no file
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
340 index[0] = 1; //only one item in this index
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
341 index_pos = ftell(debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
342 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
343
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
344 index[1] = ftell(debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
345
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
346 if (size > USHRT_MAX) { // bigger than can be stored in a short
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
347 rec_type = 'L';
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
348 fwrite(&rec_type, 1, sizeof(char), debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
349 lfile_rec.type = item->type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
350 lfile_rec.line = item->line;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
351 lfile_rec.funcname = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
352 lfile_rec.filename = strlen(item->function)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
353 lfile_rec.text = lfile_rec.filename+strlen(item->file)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
354 fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
355 } else {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
356 rec_type = 'M';
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
357 fwrite(&rec_type, 1, sizeof(char), debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
358 mfile_rec.type = item->type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
359 mfile_rec.line = item->line;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
360 mfile_rec.funcname = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
361 mfile_rec.filename = strlen(item->function)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
362 mfile_rec.text = mfile_rec.filename+strlen(item->file)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
363 fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
364 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
365 file_pos = ftell(debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
366 fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
367 fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
368 vfprintf(debug_fp, fmt, *ap);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
369 fwrite(&zero, 1, 1, debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
370
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
371 end = ftell(debug_fp)-file_pos;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
372
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
373 index[2] = ftell(debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
374 fseek(debug_fp, index_pos, SEEK_SET);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
375 fwrite(index, index_size, 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
376 if (size > USHRT_MAX) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
377 fwrite(&rec_type, 1, sizeof(char), debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
378 lfile_rec.end = end;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
379 fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
380 } else {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
381 fwrite(&rec_type, 1, sizeof(char), debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
382 mfile_rec.end = end;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
383 fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
384 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
385 fseek(debug_fp, 0, SEEK_END);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
386 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
387
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
388
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
389 void pst_debug_write_hex(struct pst_debug_item *item, unsigned char *buf, size_t size, int col) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
390 struct pst_debug_file_rec_l lfile_rec;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
391 unsigned char rec_type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
392 int index_size = 3 * sizeof(off_t);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
393 off_t index_pos, file_pos, index[3];
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
394 char zero='\0';
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
395 if (!debug_fp) return; // no file
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
396 index[0] = 1; // only one item in this index run
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
397 index[1] = 0; // valgrind, avoid writing uninitialized data
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
398 index[2] = 0; // ""
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
399 index_pos = ftell(debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
400 fwrite(index, index_size, 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
401 index[1] = ftell(debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
402
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
403 // always use the long
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
404 rec_type = 'L';
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
405 fwrite(&rec_type, 1, sizeof(char), debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
406 lfile_rec.funcname = 0;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
407 lfile_rec.filename = strlen(item->function)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
408 lfile_rec.text = lfile_rec.filename+strlen(item->file)+1;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
409 lfile_rec.end = 0; // valgrind, avoid writing uninitialized data
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
410 lfile_rec.line = item->line;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
411 lfile_rec.type = item->type;
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
412 fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
413
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
414 file_pos = ftell(debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
415 fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
416 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
417
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
418 pst_debug_hexdumper(debug_fp, buf, size, col, 0);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
419 fwrite(&zero, 1, 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
420 lfile_rec.end = ftell(debug_fp) - file_pos;
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
421
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
422 index[2] = ftell(debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
423 fseek(debug_fp, index_pos, SEEK_SET);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
424 fwrite(index, index_size, 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
425 fwrite(&rec_type, 1, sizeof(char), debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
426 fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
427 fseek(debug_fp, 0, SEEK_END);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
428 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
429
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
430
36
6fe121a971c9 valgrind fixes
carl
parents: 35
diff changeset
431 void *xmalloc(size_t size) {
46
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
432 void *mem = malloc(size);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
433 if (!mem) {
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
434 fprintf(stderr, "xMalloc: Out Of memory [req: %ld]\n", (long)size);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
435 exit(1);
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
436 }
b2a7f2e0926a more fixes for 64 bit format
carl
parents: 43
diff changeset
437 return mem;
33
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
438 }
12cac756bc05 enable -d option, but if not specified, don't generate a debug file
carl
parents: 31
diff changeset
439