annotate src/debug.c @ 45:b961bcdadd0e

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