annotate src/debug.c @ 18:69ab1d8b3293

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