annotate src/debug.c @ 31:b88ceb81dba2

mege changes from Joe Nahmias
author carl
date Tue, 10 Jul 2007 17:17:28 -0700
parents c508ee15dfca
children 12cac756bc05
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, ...);
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
32 void _debug_hexdump(unsigned char *x, int y, int cols);
16
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);
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
38 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
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
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
162 va_end(ap); // must be called after vsnprintf()
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
163
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
164 if (f > 0 && f < MAX_MESSAGE_SIZE) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
165 info_ptr->text = (char*) xmalloc(f+1);
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
166 va_start(ap, fmt);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
167 if ((g = vsnprintf(info_ptr->text, f, fmt, ap)) == -1) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
168 fprintf(stderr, "_debug_msg: Dieing! vsnprintf returned -1 for format \"%s\"\n", fmt);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
169 exit(-2);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
170 }
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
171 va_end(ap);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
172 info_ptr->text[g] = '\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
173 if (f != g) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
174 fprintf(stderr, "_debug_msg: f != g\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
175 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
176 } else if (f > 0) { // it is over the max_message_size then
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
177 f += strlen(info_ptr->file)+strlen(info_ptr->function);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
178 temp = info_ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
179 _debug_write(); // dump the current messages
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
180 info_ptr = temp;
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
181 va_start(ap, fmt);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
182 _debug_write_msg(info_ptr, fmt, &ap, f);
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
183 va_end(ap);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
184 free(info_ptr->function);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
185 free(info_ptr->file);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
186 free(info_ptr);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
187 info_ptr = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
188 return;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
189 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
190 fprintf(stderr, "_debug_msg: error getting requested size of debug message\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
191 info_ptr->text = "ERROR Saving\n";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
192 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
193
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
194 if (item_head == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
195 item_head = info_ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
196
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
197 info_ptr->next = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
198 if (item_tail != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
199 item_tail->next = info_ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
200 item_tail = info_ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
201
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
202 if (++curr_items == max_items) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
203 // here we will jump off and save the contents
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
204 _debug_write();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
205 info_ptr = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
206 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
207 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
208
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
209 void _debug_hexdump(unsigned char *x, int y, int cols) {
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
210 struct _debug_item *temp;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
211 if (debug_fp == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
212 return;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
213 info_ptr = temp_list;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
214 if (info_ptr != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
215 temp_list = info_ptr->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
216 temp = info_ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
217 _debug_write();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
218 info_ptr = temp;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
219 _debug_write_hex(info_ptr, x, y, cols);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
220 free(info_ptr->function);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
221 free(info_ptr->file);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
222 free(info_ptr);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
223 info_ptr = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
224 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
225
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
226 void _debug_func(char *function) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
227 func_ptr = xmalloc (sizeof(struct _debug_func));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
228 func_ptr->name = xmalloc(strlen(function)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
229 strcpy(func_ptr->name, function);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
230 func_ptr->next = func_head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
231 func_head = func_ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
232 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
233
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
234 void _debug_func_ret() {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
235 //remove the head item
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
236 func_ptr = func_head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
237 if (func_head != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
238 func_head = func_head->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
239 free(func_ptr->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
240 free(func_ptr);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
241 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
242 DIE(("function list is empty!\n"));
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
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
246 void _debug_close(void) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
247 _debug_write();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
248 while (func_head != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
249 func_ptr = func_head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
250 func_head = func_head->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
251 free(func_ptr->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
252 free(func_ptr);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
253 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
254
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
255 if (debug_fp != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
256 fclose(debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
257 debug_fp = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
258
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
259 if (func_head != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
260 while (func_head != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
261 printf("function '%s' still on stack\n", func_head->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
262 func_head = func_head->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
263 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
264 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
265
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
266 void _debug_write() {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
267 size_t size, ptr, funcname, filename, text, end;
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
268 char *buf = NULL, rec_type;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
269 long index_pos = ftell (debug_fp), file_pos = index_pos;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
270 // add 2. One for the pointer to the next index,
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
271 // one for the count of this index
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
272 int index_size = ((curr_items+2) * sizeof(int));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
273 int *index;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
274 int index_ptr = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
275 struct _debug_file_rec_m mfile_rec;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
276 struct _debug_file_rec_l lfile_rec;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
277
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
278 if (curr_items == 0)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
279 // no items to write.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
280 return;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
281 index = (int*) xmalloc(index_size);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
282 file_pos += index_size;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
283 // write the index first, we will re-write it later, but
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
284 // we want to allocate the space
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
285 fwrite(index, index_size, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
286 index[index_ptr++] = curr_items;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
287
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
288 item_ptr = item_head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
289 while (item_ptr != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
290 file_pos = ftell(debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
291 index[index_ptr++] = file_pos;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
292 size = strlen(item_ptr->function)+strlen(item_ptr->file)+
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
293 strlen(item_ptr->text) + 3; //for the three \0s
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
294 if (buf) free(buf);
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
295 buf = xmalloc(size+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
296 ptr = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
297 funcname=ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
298 ptr += sprintf(&(buf[ptr]), "%s", item_ptr->function)+1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
299 filename=ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
300 ptr += sprintf(&(buf[ptr]), "%s", item_ptr->file)+1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
301 text=ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
302 ptr += sprintf(&(buf[ptr]), "%s", item_ptr->text)+1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
303 end=ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
304 if (end > USHRT_MAX) { // bigger than can be stored in a short
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
305 rec_type = 'L';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
306 fwrite(&rec_type, 1, sizeof(char), debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
307 lfile_rec.type = item_ptr->type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
308 lfile_rec.line = item_ptr->line;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
309 lfile_rec.funcname = funcname;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
310 lfile_rec.filename = filename;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
311 lfile_rec.text = text;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
312 lfile_rec.end = end;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
313 fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
314 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
315 rec_type = 'M';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
316 fwrite(&rec_type, 1, sizeof(char), debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
317 mfile_rec.type = item_ptr->type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
318 mfile_rec.line = item_ptr->line;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
319 mfile_rec.funcname = funcname;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
320 mfile_rec.filename = filename;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
321 mfile_rec.text = text;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
322 mfile_rec.end = end;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
323 fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
324 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
325 fwrite(buf, 1, ptr, debug_fp);
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
326 if (buf) free(buf); buf = NULL;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
327 item_head = item_ptr->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
328 free(item_ptr->function);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
329 free(item_ptr->file);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
330 free(item_ptr->text);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
331 free(item_ptr);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
332 item_ptr = item_head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
333 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
334 curr_items = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
335 index[index_ptr] = ftell(debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
336
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
337 // we should now have a complete index
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
338 fseek(debug_fp, index_pos, SEEK_SET);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
339 fwrite(index, index_size, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
340 fseek(debug_fp, 0, SEEK_END);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
341 item_ptr = item_head = item_tail = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
342 free(index);
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
343 if (buf) free(buf); buf = NULL;
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
344 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
345
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
346 void _debug_write_msg(struct _debug_item *item, char *fmt, va_list *ap, int size) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
347 struct _debug_file_rec_l lfile_rec;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
348 struct _debug_file_rec_m mfile_rec;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
349 unsigned char rec_type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
350 int index_size = 3 * sizeof(int);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
351 int *index = malloc(index_size);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
352 int index_pos, file_pos;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
353 char zero='\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
354 unsigned int end;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
355 index[0] = 1; //only one item in this index
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
356 index_pos = ftell(debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
357 fwrite(index, index_size, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
358
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
359 index[1] = ftell(debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
360
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
361 if (size > USHRT_MAX) { // bigger than can be stored in a short
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
362 rec_type = 'L';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
363 fwrite(&rec_type, 1, sizeof(char), debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
364 lfile_rec.type = item->type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
365 lfile_rec.line = item->line;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
366 lfile_rec.funcname = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
367 lfile_rec.filename = strlen(item->function)+1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
368 lfile_rec.text = lfile_rec.filename+strlen(item->file)+1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
369 fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
370 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
371 rec_type = 'M';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
372 fwrite(&rec_type, 1, sizeof(char), debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
373 mfile_rec.type = item->type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
374 mfile_rec.line = item->line;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
375 mfile_rec.funcname = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
376 mfile_rec.filename = strlen(item->function)+1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
377 mfile_rec.text = mfile_rec.filename+strlen(item->file)+1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
378 fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
379 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
380 file_pos = ftell(debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
381 fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
382 fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
383 vfprintf(debug_fp, fmt, *ap);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
384 fwrite(&zero, 1, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
385
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
386 end = ftell(debug_fp)-file_pos;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
387
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
388 index[2] = ftell(debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
389 fseek(debug_fp, index_pos, SEEK_SET);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
390 fwrite(index, index_size, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
391 if (size > USHRT_MAX) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
392 fwrite(&rec_type, 1, sizeof(char), debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
393 lfile_rec.end = end;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
394 fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
395 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
396 fwrite(&rec_type, 1, sizeof(char), debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
397 mfile_rec.end = end;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
398 fwrite(&mfile_rec, sizeof(mfile_rec), 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
399 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
400 fseek(debug_fp, 0, SEEK_END);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
401 // that should do it...
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
402 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
403
31
b88ceb81dba2 mege changes from Joe Nahmias
carl
parents: 16
diff changeset
404 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
405 struct _debug_file_rec_l lfile_rec;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
406 unsigned char rec_type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
407 int index_size = 3 * sizeof(int);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
408 int *index = malloc(index_size);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
409 int index_pos, file_pos;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
410 char zero='\0';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
411 index[0] = 1; // only one item in this index run
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
412 index_pos = ftell(debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
413 fwrite(index, index_size, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
414 index[1] = ftell(debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
415
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
416 // always use the long
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
417 rec_type = 'L';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
418 fwrite(&rec_type, 1, sizeof(char), debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
419 lfile_rec.type = item->type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
420 lfile_rec.line = item->line;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
421 lfile_rec.funcname = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
422 lfile_rec.filename = strlen(item->function)+1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
423 lfile_rec.text = lfile_rec.filename+strlen(item->file)+1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
424 fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
425
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
426 file_pos = ftell(debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
427 fwrite(item->function, strlen(item->function)+1, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
428 fwrite(item->file, strlen(item->file)+1, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
429
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
430 _pst_debug_hexdump(debug_fp, buf, size, col);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
431 fwrite(&zero, 1, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
432 lfile_rec.end = ftell(debug_fp)-file_pos;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
433
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
434 index[2] = ftell(debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
435 fseek(debug_fp, index_pos, SEEK_SET);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
436 fwrite(index, index_size, 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
437 fwrite(&rec_type, 1, sizeof(char), debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
438 fwrite(&lfile_rec, sizeof(lfile_rec), 1, debug_fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
439 fseek(debug_fp, 0, SEEK_END);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
440 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
441
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
442 void * xmalloc(size_t size) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
443 void *mem = malloc(size);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
444 if (mem == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
445 fprintf(stderr, "xMalloc: Out Of memory [req: %ld]\n", (long)size);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
446 exit(1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
447 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
448 return mem;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
449 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
450