Authors: Robert Shearman <rob@codeweavers.com>, Eric Pouech <pouech-eric@wanadoo.fr>
[wine/multimedia.git] / dlls / dbghelp / stabs.c
blobda0df42120c476bf070385e6ca15d7448b58efa4
1 /*
2 * File stabs.c - read stabs information from the modules
4 * Copyright (C) 1996, Eric Youngdale.
5 * 1999-2004, Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * Maintenance Information
23 * -----------------------
25 * For documentation on the stabs format see for example
26 * The "stabs" debug format
27 * by Julia Menapace, Jim Kingdon, David Mackenzie
28 * of Cygnus Support
29 * available (hopefully) from http:\\sources.redhat.com\gdb\onlinedocs
32 #include "config.h"
34 #include <sys/types.h>
35 #include <fcntl.h>
36 #include <sys/stat.h>
37 #ifdef HAVE_SYS_MMAN_H
38 #include <sys/mman.h>
39 #endif
40 #include <limits.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #ifdef HAVE_UNISTD_H
44 # include <unistd.h>
45 #endif
46 #include <stdio.h>
47 #ifndef PATH_MAX
48 #define PATH_MAX MAX_PATH
49 #endif
50 #include <assert.h>
51 #include <stdarg.h>
53 #include "windef.h"
54 #include "winbase.h"
55 #include "winreg.h"
56 #include "winnls.h"
58 #include "dbghelp_private.h"
60 #include "wine/debug.h"
62 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp_stabs);
64 #ifndef N_UNDF
65 #define N_UNDF 0x00
66 #endif
68 #define N_GSYM 0x20
69 #define N_FUN 0x24
70 #define N_STSYM 0x26
71 #define N_LCSYM 0x28
72 #define N_MAIN 0x2a
73 #define N_ROSYM 0x2c
74 #define N_OPT 0x3c
75 #define N_RSYM 0x40
76 #define N_SLINE 0x44
77 #define N_SO 0x64
78 #define N_LSYM 0x80
79 #define N_BINCL 0x82
80 #define N_SOL 0x84
81 #define N_PSYM 0xa0
82 #define N_EINCL 0xa2
83 #define N_LBRAC 0xc0
84 #define N_EXCL 0xc2
85 #define N_RBRAC 0xe0
87 struct stab_nlist
89 union
91 char* n_name;
92 struct stab_nlist* n_next;
93 long n_strx;
94 } n_un;
95 unsigned char n_type;
96 char n_other;
97 short n_desc;
98 unsigned long n_value;
101 static void stab_strcpy(char* dest, int sz, const char* source)
104 * A strcpy routine that stops when we hit the ':' character.
105 * Faster than copying the whole thing, and then nuking the
106 * ':'.
108 while (*source != '\0' && *source != ':' && sz-- > 0)
109 *dest++ = *source++;
110 *dest-- = '\0';
111 /* GCC seems to emit, in some cases, a .<digit>+ suffix.
112 * This is used for static variable inside functions, so
113 * that we can have several such variables with same name in
114 * the same compilation unit
115 * We simply ignore that suffix when present (we also get rid
116 * of it in ELF symtab parsing)
118 if (isdigit(*dest))
120 while (isdigit(*dest)) dest--;
121 if (*dest == '.') *dest = '\0';
124 assert(sz > 0);
127 typedef struct
129 char* name;
130 unsigned long value;
131 struct symt** vector;
132 int nrofentries;
133 } include_def;
135 #define MAX_INCLUDES 5120
137 static include_def* include_defs = NULL;
138 static int num_include_def = 0;
139 static int num_alloc_include_def = 0;
140 static int cu_include_stack[MAX_INCLUDES];
141 static int cu_include_stk_idx = 0;
142 static struct symt** cu_vector = NULL;
143 static int cu_nrofentries = 0;
144 static struct symt_basic* stabs_basic[36];
146 static int stabs_new_include(const char* file, unsigned long val)
148 if (num_include_def == num_alloc_include_def)
150 num_alloc_include_def += 256;
151 if (!include_defs)
152 include_defs = HeapAlloc(GetProcessHeap(), 0,
153 sizeof(include_defs[0]) * num_alloc_include_def);
154 else
155 include_defs = HeapReAlloc(GetProcessHeap(), 0, include_defs,
156 sizeof(include_defs[0]) * num_alloc_include_def);
157 memset(include_defs + num_include_def, 0, sizeof(include_defs[0]) * 256);
159 include_defs[num_include_def].name = strcpy(HeapAlloc(GetProcessHeap(), 0, strlen(file) + 1), file);
160 include_defs[num_include_def].value = val;
161 include_defs[num_include_def].vector = NULL;
162 include_defs[num_include_def].nrofentries = 0;
164 return num_include_def++;
167 static int stabs_find_include(const char* file, unsigned long val)
169 int i;
171 for (i = 0; i < num_include_def; i++)
173 if (val == include_defs[i].value &&
174 strcmp(file, include_defs[i].name) == 0)
175 return i;
177 return -1;
180 static int stabs_add_include(int idx)
182 if (idx < 0) return -1;
183 cu_include_stk_idx++;
185 /* if this happens, just bump MAX_INCLUDES */
186 /* we could also handle this as another dynarray */
187 assert(cu_include_stk_idx < MAX_INCLUDES);
188 cu_include_stack[cu_include_stk_idx] = idx;
189 return cu_include_stk_idx;
192 static void stabs_reset_includes(void)
195 * The struct symt:s that we would need to use are reset when
196 * we start a new file. (at least the ones in filenr == 0)
198 cu_include_stk_idx = 0;/* keep 0 as index for the .c file itself */
199 memset(cu_vector, 0, sizeof(cu_vector[0]) * cu_nrofentries);
202 static void stabs_free_includes(void)
204 int i;
206 stabs_reset_includes();
207 for (i = 0; i < num_include_def; i++)
209 HeapFree(GetProcessHeap(), 0, include_defs[i].name);
210 HeapFree(GetProcessHeap(), 0, include_defs[i].vector);
212 HeapFree(GetProcessHeap(), 0, include_defs);
213 include_defs = NULL;
214 num_include_def = 0;
215 num_alloc_include_def = 0;
216 HeapFree(GetProcessHeap(), 0, cu_vector);
217 cu_vector = NULL;
218 cu_nrofentries = 0;
221 static struct symt** stabs_find_ref(long filenr, long subnr)
223 struct symt** ret;
225 /* FIXME: I could perhaps create a dummy include_def for each compilation
226 * unit which would allow not to handle those two cases separately
228 if (filenr == 0)
230 if (cu_nrofentries <= subnr)
232 if (!cu_vector)
233 cu_vector = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
234 sizeof(cu_vector[0]) * (subnr+1));
235 else
236 cu_vector = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
237 cu_vector, sizeof(cu_vector[0]) * (subnr+1));
238 cu_nrofentries = subnr + 1;
240 ret = &cu_vector[subnr];
242 else
244 include_def* idef;
246 assert(filenr <= cu_include_stk_idx);
247 idef = &include_defs[cu_include_stack[filenr]];
249 if (idef->nrofentries <= subnr)
251 if (!idef->vector)
252 idef->vector = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
253 sizeof(idef->vector[0]) * (subnr+1));
254 else
255 idef->vector = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
256 idef->vector, sizeof(idef->vector[0]) * (subnr+1));
257 idef->nrofentries = subnr + 1;
259 ret = &idef->vector[subnr];
261 TRACE("(%ld,%ld) => %p (%p)\n", filenr, subnr, ret, *ret);
262 return ret;
265 static struct symt** stabs_read_type_enum(const char** x)
267 long filenr, subnr;
269 if (**x == '(')
271 (*x)++; /* '(' */
272 filenr = strtol(*x, (char**)x, 10); /* <int> */
273 (*x)++; /* ',' */
274 subnr = strtol(*x, (char**)x, 10); /* <int> */
275 (*x)++; /* ')' */
277 else
279 filenr = 0;
280 subnr = strtol(*x, (char**)x, 10); /* <int> */
282 return stabs_find_ref(filenr, subnr);
285 #define PTS_DEBUG
286 struct ParseTypedefData
288 const char* ptr;
289 char buf[1024];
290 int idx;
291 struct module* module;
292 #ifdef PTS_DEBUG
293 struct PTS_Error
295 const char* ptr;
296 unsigned line;
297 } errors[16];
298 int err_idx;
299 #endif
302 #ifdef PTS_DEBUG
303 static void stabs_pts_push(struct ParseTypedefData* ptd, unsigned line)
305 assert(ptd->err_idx < sizeof(ptd->errors) / sizeof(ptd->errors[0]));
306 ptd->errors[ptd->err_idx].line = line;
307 ptd->errors[ptd->err_idx].ptr = ptd->ptr;
308 ptd->err_idx++;
310 #define PTS_ABORTIF(ptd, t) do { if (t) { stabs_pts_push((ptd), __LINE__); return -1;} } while (0)
311 #else
312 #define PTS_ABORTIF(ptd, t) do { if (t) return -1; } while (0)
313 #endif
315 static int stabs_get_basic(struct ParseTypedefData* ptd, unsigned basic, struct symt** symt)
317 PTS_ABORTIF(ptd, basic >= sizeof(stabs_basic) / sizeof(stabs_basic[0]));
319 if (!stabs_basic[basic])
321 switch (basic)
323 case 1: stabs_basic[basic] = symt_new_basic(ptd->module, btInt, "int", 4); break;
324 case 2: stabs_basic[basic] = symt_new_basic(ptd->module, btChar, "char", 1); break;
325 case 3: stabs_basic[basic] = symt_new_basic(ptd->module, btInt, "short int", 2); break;
326 case 4: stabs_basic[basic] = symt_new_basic(ptd->module, btInt, "long int", 4); break;
327 case 5: stabs_basic[basic] = symt_new_basic(ptd->module, btUInt, "unsigned char", 1); break;
328 case 6: stabs_basic[basic] = symt_new_basic(ptd->module, btInt, "signed char", 1); break;
329 case 7: stabs_basic[basic] = symt_new_basic(ptd->module, btUInt, "unsigned short int", 2); break;
330 case 8: stabs_basic[basic] = symt_new_basic(ptd->module, btUInt, "unsigned int", 4); break;
331 case 9: stabs_basic[basic] = symt_new_basic(ptd->module, btUInt, "unsigned", 2); break;
332 case 10: stabs_basic[basic] = symt_new_basic(ptd->module, btUInt, "unsigned long int", 2); break;
333 case 11: stabs_basic[basic] = symt_new_basic(ptd->module, btVoid, "void", 0); break;
334 case 12: stabs_basic[basic] = symt_new_basic(ptd->module, btFloat, "float", 4); break;
335 case 13: stabs_basic[basic] = symt_new_basic(ptd->module, btFloat, "double", 8); break;
336 case 14: stabs_basic[basic] = symt_new_basic(ptd->module, btFloat, "long double", 12); break;
337 case 15: stabs_basic[basic] = symt_new_basic(ptd->module, btInt, "integer", 4); break;
338 case 16: stabs_basic[basic] = symt_new_basic(ptd->module, btBool, "bool", 1); break;
339 /* case 17: short real */
340 /* case 18: real */
341 case 25: stabs_basic[basic] = symt_new_basic(ptd->module, btComplex, "float complex", 8); break;
342 case 26: stabs_basic[basic] = symt_new_basic(ptd->module, btComplex, "double complex", 16); break;
343 case 30: stabs_basic[basic] = symt_new_basic(ptd->module, btWChar, "wchar_t", 2); break;
344 case 31: stabs_basic[basic] = symt_new_basic(ptd->module, btInt, "long long int", 8); break;
345 case 32: stabs_basic[basic] = symt_new_basic(ptd->module, btUInt, "long long unsigned", 8); break;
346 /* starting at 35 are wine extensions (especially for R implementation) */
347 case 35: stabs_basic[basic] = symt_new_basic(ptd->module, btComplex, "long double complex", 24); break;
348 default: PTS_ABORTIF(ptd, 1);
351 *symt = &stabs_basic[basic]->symt;
352 return 0;
355 static int stabs_pts_read_type_def(struct ParseTypedefData* ptd,
356 const char* typename, struct symt** dt);
358 static int stabs_pts_read_id(struct ParseTypedefData* ptd)
360 const char* first = ptd->ptr;
361 unsigned int len;
363 PTS_ABORTIF(ptd, (ptd->ptr = strchr(ptd->ptr, ':')) == NULL);
364 len = ptd->ptr - first;
365 PTS_ABORTIF(ptd, len >= sizeof(ptd->buf) - ptd->idx);
366 memcpy(ptd->buf + ptd->idx, first, len);
367 ptd->buf[ptd->idx + len] = '\0';
368 ptd->idx += len + 1;
369 ptd->ptr++; /* ':' */
370 return 0;
373 static int stabs_pts_read_number(struct ParseTypedefData* ptd, long* v)
375 char* last;
377 *v = strtol(ptd->ptr, &last, 10);
378 PTS_ABORTIF(ptd, last == ptd->ptr);
379 ptd->ptr = last;
380 return 0;
383 static int stabs_pts_read_type_reference(struct ParseTypedefData* ptd,
384 long* filenr, long* subnr)
386 if (*ptd->ptr == '(')
388 /* '(' <int> ',' <int> ')' */
389 ptd->ptr++;
390 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, filenr) == -1);
391 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
392 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, subnr) == -1);
393 PTS_ABORTIF(ptd, *ptd->ptr++ != ')');
395 else
397 *filenr = 0;
398 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, subnr) == -1);
400 return 0;
403 struct pts_range_value
405 unsigned long long val;
406 int sign;
409 static int stabs_pts_read_range_value(struct ParseTypedefData* ptd, struct pts_range_value* prv)
411 char* last;
413 switch (*ptd->ptr)
415 case '0':
416 while (*ptd->ptr == '0') ptd->ptr++;
417 if (*ptd->ptr >= '1' && *ptd->ptr <= '7')
419 switch (ptd->ptr[1])
421 case '0':
422 PTS_ABORTIF(ptd, ptd->ptr[0] != '1');
423 prv->sign = -1;
424 prv->val = 0;
425 while (isdigit(*ptd->ptr)) prv->val = (prv->val << 3) + *ptd->ptr++ - '0';
426 break;
427 case '7':
428 prv->sign = 1;
429 prv->val = 0;
430 while (isdigit(*ptd->ptr)) prv->val = (prv->val << 3) + *ptd->ptr++ - '0';
431 break;
432 default: PTS_ABORTIF(ptd, 1); break;
434 } else prv->sign = 0;
435 break;
436 case '-':
437 prv->sign = -1;
438 prv->val = strtoull(++ptd->ptr, &last, 10);
439 ptd->ptr = last;
440 break;
441 case '+':
442 default:
443 prv->sign = 1;
444 prv->val = strtoull(ptd->ptr, &last, 10);
445 ptd->ptr = last;
446 break;
448 return 0;
451 static int stabs_pts_read_range(struct ParseTypedefData* ptd, const char* typename,
452 struct symt** dt)
454 struct symt* ref;
455 struct pts_range_value lo;
456 struct pts_range_value hi;
457 unsigned size;
458 enum BasicType bt;
459 int i;
460 unsigned long long v;
462 /* type ';' <int> ';' <int> ';' */
463 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &ref) == -1);
464 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
465 PTS_ABORTIF(ptd, stabs_pts_read_range_value(ptd, &lo) == -1);
466 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
467 PTS_ABORTIF(ptd, stabs_pts_read_range_value(ptd, &hi) == -1);
468 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
470 /* basically, we don't use ref... in some cases, for example, float is declared
471 * as a derivated type of int... which won't help us... so we guess the types
472 * from the various formats
474 if (lo.sign == 0 && hi.sign < 0)
476 bt = btUInt;
477 size = hi.val;
479 else if (lo.sign < 0 && hi.sign == 0)
481 bt = btUInt;
482 size = lo.val;
484 else if (lo.sign > 0 && hi.sign == 0)
486 bt = btFloat;
487 size = lo.val;
489 else if (lo.sign < 0 && hi.sign > 0)
491 v = 1 << 7;
492 for (i = 7; i < 64; i += 8)
494 if (lo.val == v && hi.val == v - 1)
496 bt = btInt;
497 size = (i + 1) / 8;
498 break;
500 v <<= 8;
502 PTS_ABORTIF(ptd, i >= 64);
504 else if (lo.sign == 0 && hi.sign > 0)
506 if (hi.val == 127) /* specific case for char... */
508 bt = btChar;
509 size = 1;
511 else
513 v = 1;
514 for (i = 8; i <= 64; i += 8)
516 v <<= 8;
517 if (hi.val + 1 == v)
519 bt = btUInt;
520 size = (i + 1) / 8;
521 break;
524 PTS_ABORTIF(ptd, i > 64);
527 else PTS_ABORTIF(ptd, 1);
529 *dt = &symt_new_basic(ptd->module, bt, typename, size)->symt;
530 return 0;
533 static inline int stabs_pts_read_method_info(struct ParseTypedefData* ptd)
535 struct symt* dt;
536 char* tmp;
537 char mthd;
541 /* get type of return value */
542 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &dt) == -1);
543 if (*ptd->ptr == ';') ptd->ptr++;
545 /* get types of parameters */
546 if (*ptd->ptr == ':')
548 PTS_ABORTIF(ptd, !(tmp = strchr(ptd->ptr + 1, ';')));
549 ptd->ptr = tmp + 1;
551 PTS_ABORTIF(ptd, !(*ptd->ptr >= '0' && *ptd->ptr <= '9'));
552 ptd->ptr++;
553 PTS_ABORTIF(ptd, !(ptd->ptr[0] >= 'A' && *ptd->ptr <= 'D'));
554 mthd = *++ptd->ptr;
555 PTS_ABORTIF(ptd, mthd != '.' && mthd != '?' && mthd != '*');
556 ptd->ptr++;
557 if (mthd == '*')
559 long int ofs;
560 struct symt* dt;
562 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &ofs) == -1);
563 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
564 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &dt) == -1);
565 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
567 } while (*ptd->ptr != ';');
568 ptd->ptr++;
570 return 0;
573 static inline int stabs_pts_read_aggregate(struct ParseTypedefData* ptd,
574 struct symt_udt* sdt)
576 long sz, ofs;
577 struct symt* adt;
578 struct symt* dt = NULL;
579 int idx;
580 int doadd;
582 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &sz) == -1);
584 doadd = symt_set_udt_size(ptd->module, sdt, sz);
585 if (*ptd->ptr == '!') /* C++ inheritence */
587 long num_classes;
589 ptd->ptr++;
590 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &num_classes) == -1);
591 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
592 while (--num_classes >= 0)
594 ptd->ptr += 2; /* skip visibility and inheritence */
595 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &ofs) == -1);
596 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
598 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &adt) == -1);
600 if (doadd)
602 char tmp[256];
603 WCHAR* name;
604 DWORD size;
606 symt_get_info(adt, TI_GET_SYMNAME, &name);
607 strcmp(tmp, "__inherited_class_");
608 WideCharToMultiByte(CP_ACP, 0, name, -1,
609 tmp + strlen(tmp), sizeof(tmp) - strlen(tmp),
610 NULL, NULL);
611 HeapFree(GetProcessHeap(), 0, name);
612 /* FIXME: TI_GET_LENGTH will not always work, especially when adt
613 * has just been seen as a forward definition and not the real stuff
614 * yet.
615 * As we don't use much the size of members in structs, this may not
616 * be much of a problem
618 symt_get_info(adt, TI_GET_LENGTH, &size);
619 symt_add_udt_element(ptd->module, sdt, tmp, adt, ofs, size * 8);
621 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
625 /* if the structure has already been filled, just redo the parsing
626 * but don't store results into the struct
627 * FIXME: there's a quite ugly memory leak in there...
630 /* Now parse the individual elements of the structure/union. */
631 while (*ptd->ptr != ';')
633 /* agg_name : type ',' <int:offset> ',' <int:size> */
634 idx = ptd->idx;
636 if (ptd->ptr[0] == '$' && ptd->ptr[1] == 'v')
638 long x;
640 if (ptd->ptr[2] == 'f')
642 /* C++ virtual method table */
643 ptd->ptr += 3;
644 stabs_read_type_enum(&ptd->ptr);
645 PTS_ABORTIF(ptd, *ptd->ptr++ != ':');
646 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &dt) == -1);
647 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
648 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &x) == -1);
649 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
650 ptd->idx = idx;
651 continue;
653 else if (ptd->ptr[2] == 'b')
655 ptd->ptr += 3;
656 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &dt) == -1);
657 PTS_ABORTIF(ptd, *ptd->ptr++ != ':');
658 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &dt) == -1);
659 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
660 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &x) == -1);
661 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
662 ptd->idx = idx;
663 continue;
667 PTS_ABORTIF(ptd, stabs_pts_read_id(ptd) == -1);
668 /* Ref. TSDF R2.130 Section 7.4. When the field name is a method name
669 * it is followed by two colons rather than one.
671 if (*ptd->ptr == ':')
673 ptd->ptr++;
674 stabs_pts_read_method_info(ptd);
675 ptd->idx = idx;
676 continue;
678 else
680 /* skip C++ member protection /0 /1 or /2 */
681 if (*ptd->ptr == '/') ptd->ptr += 2;
683 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &adt) == -1);
685 switch (*ptd->ptr++)
687 case ',':
688 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &ofs) == -1);
689 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
690 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &sz) == -1);
691 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
693 if (doadd) symt_add_udt_element(ptd->module, sdt, ptd->buf + idx, adt, ofs, sz);
694 break;
695 case ':':
697 char* tmp;
698 /* method parameters... terminated by ';' */
699 PTS_ABORTIF(ptd, !(tmp = strchr(ptd->ptr, ';')));
700 ptd->ptr = tmp + 1;
702 break;
703 default:
704 PTS_ABORTIF(ptd, TRUE);
706 ptd->idx = idx;
708 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
709 if (*ptd->ptr == '~')
711 ptd->ptr++;
712 PTS_ABORTIF(ptd, *ptd->ptr++ != '%');
713 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &dt) == -1);
714 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
716 return 0;
719 static inline int stabs_pts_read_enum(struct ParseTypedefData* ptd,
720 struct symt_enum* edt)
722 long value;
723 int idx;
725 while (*ptd->ptr != ';')
727 idx = ptd->idx;
728 PTS_ABORTIF(ptd, stabs_pts_read_id(ptd) == -1);
729 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &value) == -1);
730 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
731 symt_add_enum_element(ptd->module, edt, ptd->buf + idx, value);
732 ptd->idx = idx;
734 ptd->ptr++;
735 return 0;
738 static inline int stabs_pts_read_array(struct ParseTypedefData* ptd,
739 struct symt** adt)
741 long lo, hi;
742 struct symt* rdt;
744 /* ar<typeinfo_nodef>;<int>;<int>;<typeinfo> */
746 PTS_ABORTIF(ptd, *ptd->ptr++ != 'r');
747 /* FIXME: range type is lost, always assume int */
748 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &rdt) == -1);
749 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
750 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &lo) == -1);
751 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
752 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &hi) == -1);
753 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
755 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &rdt) == -1);
757 *adt = &symt_new_array(ptd->module, lo, hi, rdt)->symt;
758 return 0;
761 static int stabs_pts_read_type_def(struct ParseTypedefData* ptd, const char* typename,
762 struct symt** ret_dt)
764 int idx;
765 long sz = -1;
766 struct symt* new_dt = NULL; /* newly created data type */
767 struct symt* ref_dt; /* referenced data type (pointer...) */
768 long filenr1, subnr1, tmp;
770 /* things are a bit complicated because of the way the typedefs are stored inside
771 * the file, because addresses can change when realloc is done, so we must call
772 * over and over stabs_find_ref() to keep the correct values around
774 PTS_ABORTIF(ptd, stabs_pts_read_type_reference(ptd, &filenr1, &subnr1) == -1);
776 while (*ptd->ptr == '=')
778 ptd->ptr++;
779 PTS_ABORTIF(ptd, new_dt != btNoType);
781 /* first handle attribute if any */
782 switch (*ptd->ptr)
784 case '@':
785 if (*++ptd->ptr == 's')
787 ptd->ptr++;
788 if (stabs_pts_read_number(ptd, &sz) == -1)
790 ERR("Not an attribute... NIY\n");
791 ptd->ptr -= 2;
792 return -1;
794 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
796 break;
798 /* then the real definitions */
799 switch (*ptd->ptr++)
801 case '*':
802 case '&':
803 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &ref_dt) == -1);
804 new_dt = &symt_new_pointer(ptd->module, ref_dt)->symt;
805 break;
806 case 'k': /* 'const' modifier */
807 case 'B': /* 'volatile' modifier */
808 /* just kinda ignore the modifier, I guess -gmt */
809 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, typename, &new_dt) == -1);
810 break;
811 case '(':
812 ptd->ptr--;
813 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, typename, &new_dt) == -1);
814 break;
815 case 'a':
816 PTS_ABORTIF(ptd, stabs_pts_read_array(ptd, &new_dt) == -1);
817 break;
818 case 'r':
819 PTS_ABORTIF(ptd, stabs_pts_read_range(ptd, typename, &new_dt) == -1);
820 assert(!*stabs_find_ref(filenr1, subnr1));
821 *stabs_find_ref(filenr1, subnr1) = new_dt;
822 break;
823 case 'f':
824 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &ref_dt) == -1);
825 new_dt = &symt_new_function_signature(ptd->module, ref_dt)->symt;
826 break;
827 case 'e':
828 new_dt = &symt_new_enum(ptd->module, typename)->symt;
829 PTS_ABORTIF(ptd, stabs_pts_read_enum(ptd, (struct symt_enum*)new_dt) == -1);
830 break;
831 case 's':
832 case 'u':
834 struct symt_udt* udt;
835 enum UdtKind kind = (ptd->ptr[-1] == 's') ? UdtStruct : UdtUnion;
836 /* udt can have been already defined in a forward definition */
837 udt = (struct symt_udt*)*stabs_find_ref(filenr1, subnr1);
838 if (!udt)
840 udt = symt_new_udt(ptd->module, typename, 0, kind);
841 /* we need to set it here, because a struct can hold a pointer
842 * to itself
844 new_dt = *stabs_find_ref(filenr1, subnr1) = &udt->symt;
846 else
848 if (udt->symt.tag != SymTagUDT)
850 ERR("Forward declaration (%p/%s) is not an aggregate (%u)\n",
851 udt, symt_get_name(&udt->symt), udt->symt.tag);
852 return -1;
854 if (strcmp(udt->hash_elt.name, typename))
855 ERR("Forward declaration name mismatch %s <> %s\n",
856 udt->hash_elt.name, typename);
857 /* should check typename is the same too */
858 new_dt = &udt->symt;
860 PTS_ABORTIF(ptd, stabs_pts_read_aggregate(ptd, udt) == -1);
862 break;
863 case 'x':
864 idx = ptd->idx;
865 tmp = *ptd->ptr++;
866 PTS_ABORTIF(ptd, stabs_pts_read_id(ptd) == -1);
867 switch (tmp)
869 case 'e':
870 new_dt = &symt_new_enum(ptd->module, ptd->buf + idx)->symt;
871 break;
872 case 's':
873 new_dt = &symt_new_udt(ptd->module, ptd->buf + idx, 0, UdtStruct)->symt;
874 break;
875 case 'u':
876 new_dt = &symt_new_udt(ptd->module, ptd->buf + idx, 0, UdtUnion)->symt;
877 break;
878 default:
879 return -1;
881 ptd->idx = idx;
882 break;
883 case '-':
885 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &tmp) == -1);
886 PTS_ABORTIF(ptd, stabs_get_basic(ptd, tmp, &new_dt) == -1);
887 PTS_ABORTIF(ptd, *ptd->ptr++ != ';');
889 break;
890 case '#':
891 if (*ptd->ptr == '#')
893 ptd->ptr++;
894 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &ref_dt) == -1);
895 new_dt = &symt_new_function_signature(ptd->module, ref_dt)->symt;
897 else
899 struct symt* cls_dt;
900 struct symt* pmt_dt;
902 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &cls_dt) == -1);
903 PTS_ABORTIF(ptd, *ptd->ptr++ != ',');
904 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &ref_dt) == -1);
905 new_dt = &symt_new_function_signature(ptd->module, ref_dt)->symt;
906 while (*ptd->ptr == ',')
908 ptd->ptr++;
909 PTS_ABORTIF(ptd, stabs_pts_read_type_def(ptd, NULL, &pmt_dt) == -1);
912 break;
913 case 'R':
915 long type, len, unk;
916 int basic;
918 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &type) == -1);
919 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
920 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &len) == -1);
921 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
922 PTS_ABORTIF(ptd, stabs_pts_read_number(ptd, &unk) == -1);
923 PTS_ABORTIF(ptd, *ptd->ptr++ != ';'); /* ';' */
925 switch (type) /* see stabs_get_basic for the details */
927 case 1: basic = 12; break;
928 case 2: basic = 13; break;
929 case 3: basic = 25; break;
930 case 4: basic = 26; break;
931 case 5: basic = 35; break;
932 case 6: basic = 14; break;
933 default: PTS_ABORTIF(ptd, 1);
935 PTS_ABORTIF(ptd, stabs_get_basic(ptd, basic, &new_dt) == -1);
937 break;
938 default:
939 ERR("Unknown type '%c'\n", ptd->ptr[-1]);
940 return -1;
944 if (!new_dt)
946 /* is it a forward declaration that has been filled ? */
947 new_dt = *stabs_find_ref(filenr1, subnr1);
948 /* if not, this should be void (which is defined as a ref to itself, but we
949 * don't correctly catch it)
951 if (!new_dt && typename)
953 new_dt = &symt_new_basic(ptd->module, btVoid, typename, 0)->symt;
954 PTS_ABORTIF(ptd, strcmp(typename, "void"));
958 *stabs_find_ref(filenr1, subnr1) = *ret_dt = new_dt;
960 TRACE("Adding (%ld,%ld) %s\n", filenr1, subnr1, typename);
962 return 0;
965 static int stabs_parse_typedef(struct module* module, const char* ptr,
966 const char* typename)
968 struct ParseTypedefData ptd;
969 struct symt* dt;
970 int ret = -1;
972 /* check for already existing definition */
974 TRACE("%s\n", debugstr_a(ptr));
975 ptd.module = module;
976 ptd.idx = 0;
977 #ifdef PTS_DEBUG
978 ptd.err_idx = 0;
979 #endif
980 for (ptd.ptr = ptr - 1; ;)
982 ptd.ptr = strchr(ptd.ptr + 1, ':');
983 if (ptd.ptr == NULL || *++ptd.ptr != ':') break;
985 if (ptd.ptr)
987 if (*ptd.ptr != '(') ptd.ptr++;
988 /* most of type definitions take one char, except Tt */
989 if (*ptd.ptr != '(') ptd.ptr++;
990 ret = stabs_pts_read_type_def(&ptd, typename, &dt);
993 if (ret == -1 || *ptd.ptr)
995 #ifdef PTS_DEBUG
996 int i;
997 TRACE("Failure on %s\n", debugstr_a(ptr));
998 if (ret == -1)
1000 for (i = 0; i < ptd.err_idx; i++)
1002 TRACE("[%d]: line %d => %s\n",
1003 i, ptd.errors[i].line, debugstr_a(ptd.errors[i].ptr));
1006 else
1007 TRACE("[0]: => %s\n", debugstr_a(ptd.ptr));
1009 #else
1010 ERR("Failure on %s at %s\n", debugstr_a(ptr), debugstr_a(ptd.ptr));
1011 #endif
1012 return FALSE;
1015 return TRUE;
1018 static struct symt* stabs_parse_type(const char* stab)
1020 const char* c = stab - 1;
1023 * Look through the stab definition, and figure out what struct symt
1024 * this represents. If we have something we know about, assign the
1025 * type.
1026 * According to "The \"stabs\" debug format" (Rev 2.130) the name may be
1027 * a C++ name and contain double colons e.g. foo::bar::baz:t5=*6.
1031 if ((c = strchr(c + 1, ':')) == NULL) return NULL;
1032 } while (*++c == ':');
1035 * The next characters say more about the type (i.e. data, function, etc)
1036 * of symbol. Skip them. (C++ for example may have Tt).
1037 * Actually this is a very weak description; I think Tt is the only
1038 * multiple combination we should see.
1040 while (*c && *c != '(' && !isdigit(*c))
1041 c++;
1043 * The next is either an integer or a (integer,integer).
1044 * The stabs_read_type_enum() takes care that stab_types is large enough.
1046 return *stabs_read_type_enum(&c);
1049 struct pending_loc_var
1051 char name[256];
1052 struct symt* type;
1053 unsigned offset;
1054 unsigned regno;
1057 /******************************************************************
1058 * stabs_finalize_function
1060 * Ends function creation: mainly:
1061 * - cleans up line number information
1062 * - tries to set up a debug-start tag (FIXME: heuristic to be enhanced)
1064 static void stabs_finalize_function(struct module* module, struct symt_function* func)
1066 IMAGEHLP_LINE il;
1068 if (!func) return;
1069 symt_normalize_function(module, func);
1070 /* To define the debug-start of the function, we use the second line number.
1071 * Not 100% bullet proof, but better than nothing
1073 if (symt_fill_func_line_info(module, func, func->address, &il) &&
1074 symt_get_func_line_next(module, &il))
1076 symt_add_function_point(module, func, SymTagFuncDebugStart,
1077 il.Address - func->address, NULL);
1081 BOOL stabs_parse(struct module* module, const char* addr,
1082 unsigned long load_offset, unsigned int staboff, int stablen,
1083 unsigned int strtaboff, int strtablen)
1085 struct symt_function* curr_func = NULL;
1086 struct symt_block* block = NULL;
1087 struct symt_compiland* compiland = NULL;
1088 char currpath[PATH_MAX];
1089 char srcpath[PATH_MAX];
1090 int i, j;
1091 int nstab;
1092 const char* ptr;
1093 char* stabbuff;
1094 unsigned int stabbufflen;
1095 const struct stab_nlist* stab_ptr;
1096 const char* strs;
1097 int strtabinc;
1098 char symname[4096];
1099 unsigned incl[32];
1100 int incl_stk = -1;
1101 int source_idx = -1;
1102 struct pending_loc_var* pending_vars = NULL;
1103 unsigned num_pending_vars = 0;
1104 unsigned num_allocated_pending_vars = 0;
1105 BOOL ret = TRUE;
1107 nstab = stablen / sizeof(struct stab_nlist);
1108 stab_ptr = (const struct stab_nlist*)(addr + staboff);
1109 strs = (const char*)(addr + strtaboff);
1111 memset(currpath, 0, sizeof(currpath));
1112 memset(srcpath, 0, sizeof(srcpath));
1113 memset(stabs_basic, 0, sizeof(stabs_basic));
1116 * Allocate a buffer into which we can build stab strings for cases
1117 * where the stab is continued over multiple lines.
1119 stabbufflen = 65536;
1120 stabbuff = HeapAlloc(GetProcessHeap(), 0, stabbufflen);
1122 strtabinc = 0;
1123 stabbuff[0] = '\0';
1124 for (i = 0; i < nstab; i++, stab_ptr++)
1126 ptr = strs + stab_ptr->n_un.n_strx;
1127 if (ptr[strlen(ptr) - 1] == '\\')
1130 * Indicates continuation. Append this to the buffer, and go onto the
1131 * next record. Repeat the process until we find a stab without the
1132 * '/' character, as this indicates we have the whole thing.
1134 unsigned len = strlen(ptr);
1135 if (strlen(stabbuff) + len > stabbufflen)
1137 stabbufflen += 65536;
1138 stabbuff = HeapReAlloc(GetProcessHeap(), 0, stabbuff, stabbufflen);
1140 strncat(stabbuff, ptr, len - 1);
1141 continue;
1143 else if (stabbuff[0] != '\0')
1145 strcat(stabbuff, ptr);
1146 ptr = stabbuff;
1149 if (strchr(ptr, '=') != NULL)
1152 * The stabs aren't in writable memory, so copy it over so we are
1153 * sure we can scribble on it.
1155 if (ptr != stabbuff)
1157 strcpy(stabbuff, ptr);
1158 ptr = stabbuff;
1160 stab_strcpy(symname, sizeof(symname), ptr);
1161 if (!stabs_parse_typedef(module, ptr, symname))
1163 /* skip this definition */
1164 stabbuff[0] = '\0';
1165 continue;
1169 #if 0
1170 const char* defs[] = {"","","","", /* 00 */
1171 "","","","", /* 08 */
1172 "","","","", /* 10 */
1173 "","","","", /* 18 */
1174 "gsym","","fun","stsym", /* 20 */
1175 "lcsym","main","rosym","", /* 28 */
1176 "","","","", /* 30 */
1177 "","","opt","", /* 38 */
1178 "rsym","","sline","", /* 40 */
1179 "","","","", /* 48 */
1180 "","","","", /* 50 */
1181 "","","","", /* 58 */
1182 "","","so","", /* 60 */
1183 "","","","", /* 68 */
1184 "","","","", /* 70 */
1185 "","","","", /* 78 */
1186 "lsym","bincl","sol","", /* 80 */
1187 "","","","", /* 88 */
1188 "","","","", /* 90 */
1189 "","","","", /* 98 */
1190 "psym","eincl","","", /* a0 */
1191 "","","","", /* a8 */
1192 "","","","", /* b0 */
1193 "","","","", /* b8 */
1194 "lbrac","excl","","", /* c0 */
1195 "","","","", /* c8 */
1196 "","","","", /* d0 */
1197 "","","","", /* d8 */
1198 "rbrac","","","", /* e0 */
1201 FIXME("Got %s<%u> %u/%lu (%s)\n",
1202 defs[stab_ptr->n_type / 2], stab_ptr->n_type, stab_ptr->n_desc, stab_ptr->n_value, debugstr_a(ptr));
1203 #endif
1205 switch (stab_ptr->n_type)
1207 case N_GSYM:
1209 * These are useless with ELF. They have no value, and you have to
1210 * read the normal symbol table to get the address. Thus we
1211 * ignore them, and when we process the normal symbol table
1212 * we should do the right thing.
1214 * With a.out or mingw, they actually do make some amount of sense.
1216 stab_strcpy(symname, sizeof(symname), ptr);
1217 symt_new_global_variable(module, compiland, symname, TRUE /* FIXME */,
1218 load_offset + stab_ptr->n_value, 0,
1219 stabs_parse_type(ptr));
1220 break;
1221 case N_LCSYM:
1222 case N_STSYM:
1223 /* These are static symbols and BSS symbols. */
1224 stab_strcpy(symname, sizeof(symname), ptr);
1225 symt_new_global_variable(module, compiland, symname, TRUE /* FIXME */,
1226 load_offset + stab_ptr->n_value, 0,
1227 stabs_parse_type(ptr));
1228 break;
1229 case N_LBRAC:
1230 block = symt_open_func_block(module, curr_func, block,
1231 stab_ptr->n_value, 0);
1232 for (j = 0; j < num_pending_vars; j++)
1234 symt_add_func_local(module, curr_func, pending_vars[j].regno,
1235 pending_vars[j].offset,
1236 block, pending_vars[j].type, pending_vars[j].name);
1238 num_pending_vars = 0;
1239 break;
1240 case N_RBRAC:
1241 block = symt_close_func_block(module, curr_func, block,
1242 stab_ptr->n_value);
1243 break;
1244 case N_PSYM:
1245 /* These are function parameters. */
1246 if (curr_func != NULL)
1248 struct symt* param_type = stabs_parse_type(ptr);
1249 stab_strcpy(symname, sizeof(symname), ptr);
1250 symt_add_func_local(module, curr_func, 0, stab_ptr->n_value,
1251 NULL, param_type, symname);
1252 symt_add_function_signature_parameter(module,
1253 (struct symt_function_signature*)curr_func->type,
1254 param_type);
1256 break;
1257 case N_RSYM:
1258 /* These are registers (as local variables) */
1259 if (curr_func != NULL)
1261 unsigned reg;
1263 if (num_pending_vars == num_allocated_pending_vars)
1265 num_allocated_pending_vars += 8;
1266 if (!pending_vars)
1267 pending_vars = HeapAlloc(GetProcessHeap(), 0,
1268 num_allocated_pending_vars * sizeof(pending_vars[0]));
1269 else
1270 pending_vars = HeapReAlloc(GetProcessHeap(), 0, pending_vars,
1271 num_allocated_pending_vars * sizeof(pending_vars[0]));
1273 switch (stab_ptr->n_value)
1275 case 0: reg = CV_REG_EAX; break;
1276 case 1: reg = CV_REG_ECX; break;
1277 case 2: reg = CV_REG_EDX; break;
1278 case 3: reg = CV_REG_EBX; break;
1279 case 4: reg = CV_REG_ESP; break;
1280 case 5: reg = CV_REG_EBP; break;
1281 case 6: reg = CV_REG_ESI; break;
1282 case 7: reg = CV_REG_EDI; break;
1283 case 11:
1284 case 12:
1285 case 13:
1286 case 14:
1287 case 15:
1288 case 16:
1289 case 17:
1290 case 18:
1291 case 19: reg = CV_REG_ST0 + stab_ptr->n_value - 12; break;
1292 default:
1293 FIXME("Unknown register value (%lu)\n", stab_ptr->n_value);
1294 reg = CV_REG_NONE;
1295 break;
1298 stab_strcpy(pending_vars[num_pending_vars].name,
1299 sizeof(pending_vars[num_pending_vars].name), ptr);
1300 pending_vars[num_pending_vars].type = stabs_parse_type(ptr);
1301 pending_vars[num_pending_vars].offset = 0;
1302 pending_vars[num_pending_vars].regno = reg;
1303 num_pending_vars++;
1305 break;
1306 case N_LSYM:
1307 /* These are local variables */
1308 if (curr_func != NULL)
1310 if (num_pending_vars == num_allocated_pending_vars)
1312 num_allocated_pending_vars += 8;
1313 if (!pending_vars)
1314 pending_vars = HeapAlloc(GetProcessHeap(), 0,
1315 num_allocated_pending_vars * sizeof(pending_vars[0]));
1316 else
1317 pending_vars = HeapReAlloc(GetProcessHeap(), 0, pending_vars,
1318 num_allocated_pending_vars * sizeof(pending_vars[0]));
1320 stab_strcpy(pending_vars[num_pending_vars].name,
1321 sizeof(pending_vars[num_pending_vars].name), ptr);
1322 pending_vars[num_pending_vars].type = stabs_parse_type(ptr);
1323 pending_vars[num_pending_vars].offset = stab_ptr->n_value;
1324 pending_vars[num_pending_vars].regno = 0;
1325 num_pending_vars++;
1327 break;
1328 case N_SLINE:
1330 * This is a line number. These are always relative to the start
1331 * of the function (N_FUN), and this makes the lookup easier.
1333 if (curr_func != NULL)
1335 assert(source_idx >= 0);
1336 symt_add_func_line(module, curr_func, source_idx,
1337 stab_ptr->n_desc, stab_ptr->n_value);
1339 break;
1340 case N_FUN:
1341 /* First, clean up the previous function we were working on. */
1342 stabs_finalize_function(module, curr_func);
1345 * For now, just declare the various functions. Later
1346 * on, we will add the line number information and the
1347 * local symbols.
1350 * Copy the string to a temp buffer so we
1351 * can kill everything after the ':'. We do
1352 * it this way because otherwise we end up dirtying
1353 * all of the pages related to the stabs, and that
1354 * sucks up swap space like crazy.
1356 stab_strcpy(symname, sizeof(symname), ptr);
1357 if (*symname)
1359 struct symt_function_signature* func_type;
1360 func_type = symt_new_function_signature(module,
1361 stabs_parse_type(ptr));
1362 curr_func = symt_new_function(module, compiland, symname,
1363 load_offset + stab_ptr->n_value, 0,
1364 &func_type->symt);
1366 else
1368 /* some GCC seem to use a N_FUN "" to mark the end of a function */
1369 curr_func = NULL;
1371 break;
1372 case N_SO:
1374 * This indicates a new source file. Append the records
1375 * together, to build the correct path name.
1377 if (*ptr == '\0') /* end of N_SO file */
1379 /* Nuke old path. */
1380 currpath[0] = '\0';
1381 stabs_finalize_function(module, curr_func);
1382 curr_func = NULL;
1383 source_idx = -1;
1384 incl_stk = -1;
1385 assert(block == NULL);
1386 compiland = NULL;
1388 else
1390 stabs_reset_includes();
1391 if (*ptr != '/')
1393 strcpy(currpath, srcpath);
1394 strcat(currpath, ptr);
1395 compiland = symt_new_compiland(module, currpath);
1396 source_idx = source_new(module, currpath);
1398 else
1400 strcpy(srcpath, ptr);
1401 compiland = symt_new_compiland(module, srcpath);
1402 source_idx = source_new(module, srcpath);
1405 break;
1406 case N_SOL:
1407 if (*ptr != '/')
1409 strcpy(currpath, srcpath);
1410 strcat(currpath, ptr);
1412 else
1413 strcpy(currpath, ptr);
1414 source_idx = source_new(module, currpath);
1415 break;
1416 case N_UNDF:
1417 strs += strtabinc;
1418 strtabinc = stab_ptr->n_value;
1419 stabs_finalize_function(module, curr_func);
1420 curr_func = NULL;
1421 break;
1422 case N_OPT:
1423 /* Ignore this. We don't care what it points to. */
1424 break;
1425 case N_BINCL:
1426 stabs_add_include(stabs_new_include(ptr, stab_ptr->n_value));
1427 assert(incl_stk < (int)(sizeof(incl) / sizeof(incl[0])) - 1);
1428 incl[++incl_stk] = source_idx;
1429 source_idx = source_new(module, ptr);
1430 break;
1431 case N_EINCL:
1432 assert(incl_stk >= 0);
1433 source_idx = incl[incl_stk--];
1434 break;
1435 case N_EXCL:
1436 if (stabs_add_include(stabs_find_include(ptr, stab_ptr->n_value)) < 0)
1438 ERR("Excluded header not found (%s,%ld)\n", ptr, stab_ptr->n_value);
1439 module_reset_debug_info(module);
1440 ret = FALSE;
1441 goto done;
1443 break;
1444 case N_MAIN:
1445 /* Always ignore these. GCC doesn't even generate them. */
1446 break;
1447 default:
1448 ERR("Unknown stab type 0x%02x\n", stab_ptr->n_type);
1449 break;
1451 stabbuff[0] = '\0';
1452 TRACE("0x%02x %lx %s\n",
1453 stab_ptr->n_type, stab_ptr->n_value, debugstr_a(strs + stab_ptr->n_un.n_strx));
1455 module->module.SymType = SymDia;
1456 done:
1457 HeapFree(GetProcessHeap(), 0, stabbuff);
1458 stabs_free_includes();
1459 if (pending_vars) HeapFree(GetProcessHeap(), 0, pending_vars);
1461 return ret;