2 * File msc.c - read VC++ debug information from COFF and eventually
5 * Copyright (C) 1996, Eric Youngdale.
6 * Copyright (C) 1999-2000, Ulrich Weigand.
7 * Copyright (C) 2004-2005, Eric Pouech.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * Note - this handles reading debug information for 32 bit applications
26 * that run under Windows-NT for example. I doubt that this would work well
27 * for 16 bit applications, but I don't think it really matters since the
28 * file format is different, and we should never get in here in such cases.
31 * Get 16 bit CV stuff working.
32 * Add symbol size to internal symbol table.
36 #include "wine/port.h"
47 #define PATH_MAX MAX_PATH
55 #include "wine/exception.h"
56 #include "wine/debug.h"
58 #include "dbghelp_private.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp_msc);
63 #define MAX_PATHNAME_LEN 1024
65 /*========================================================================
66 * Debug file access helper routines
69 static void dump(const void* ptr, unsigned len)
73 const char* hexof = "0123456789abcdef";
74 const BYTE* x = (const BYTE*)ptr;
76 for (i = 0; i < len; i += 16)
78 sprintf(msg, "%08x: ", i);
79 memset(msg + 10, ' ', 3 * 16 + 1 + 16);
80 for (j = 0; j < min(16, len - i); j++)
82 msg[10 + 3 * j + 0] = hexof[x[i + j] >> 4];
83 msg[10 + 3 * j + 1] = hexof[x[i + j] & 15];
84 msg[10 + 3 * j + 2] = ' ';
85 msg[10 + 3 * 16 + 1 + j] = (x[i + j] >= 0x20 && x[i + j] < 0x7f) ?
88 msg[10 + 3 * 16] = ' ';
89 msg[10 + 3 * 16 + 1 + 16] = '\0';
94 /*========================================================================
95 * Process CodeView type information.
98 #define MAX_BUILTIN_TYPES 0x0480
99 #define FIRST_DEFINABLE_TYPE 0x1000
101 static struct symt* cv_basic_types[MAX_BUILTIN_TYPES];
103 #define SymTagCVBitField (SymTagMax + 0x100)
104 struct codeview_bitfield
108 unsigned bitposition;
112 struct cv_defined_module
115 unsigned int num_defined_types;
116 struct symt** defined_types;
118 struct codeview_bitfield* bitfields;
119 unsigned num_bitfields;
120 unsigned used_bitfields;
122 /* FIXME: don't make it static */
123 #define CV_MAX_MODULES 32
124 static struct cv_defined_module cv_zmodules[CV_MAX_MODULES];
125 static struct cv_defined_module*cv_current_module;
127 static void codeview_init_basic_types(struct module* module)
130 * These are the common builtin types that are used by VC++.
132 cv_basic_types[T_NOTYPE] = NULL;
133 cv_basic_types[T_ABS] = NULL;
134 cv_basic_types[T_VOID] = &symt_new_basic(module, btVoid, "void", 0)->symt;
135 cv_basic_types[T_CHAR] = &symt_new_basic(module, btChar, "char", 1)->symt;
136 cv_basic_types[T_SHORT] = &symt_new_basic(module, btInt, "short int", 2)->symt;
137 cv_basic_types[T_LONG] = &symt_new_basic(module, btInt, "long int", 4)->symt;
138 cv_basic_types[T_QUAD] = &symt_new_basic(module, btInt, "long long int", 8)->symt;
139 cv_basic_types[T_UCHAR] = &symt_new_basic(module, btUInt, "unsigned char", 1)->symt;
140 cv_basic_types[T_USHORT] = &symt_new_basic(module, btUInt, "unsigned short", 2)->symt;
141 cv_basic_types[T_ULONG] = &symt_new_basic(module, btUInt, "unsigned long", 4)->symt;
142 cv_basic_types[T_UQUAD] = &symt_new_basic(module, btUInt, "unsigned long long", 8)->symt;
143 cv_basic_types[T_REAL32] = &symt_new_basic(module, btFloat, "float", 4)->symt;
144 cv_basic_types[T_REAL64] = &symt_new_basic(module, btFloat, "double", 8)->symt;
145 cv_basic_types[T_RCHAR] = &symt_new_basic(module, btInt, "signed char", 1)->symt;
146 cv_basic_types[T_WCHAR] = &symt_new_basic(module, btWChar, "wchar_t", 2)->symt;
147 cv_basic_types[T_INT4] = &symt_new_basic(module, btInt, "INT4", 4)->symt;
148 cv_basic_types[T_UINT4] = &symt_new_basic(module, btUInt, "UINT4", 4)->symt;
150 cv_basic_types[T_32PVOID] = &symt_new_pointer(module, cv_basic_types[T_VOID])->symt;
151 cv_basic_types[T_32PCHAR] = &symt_new_pointer(module, cv_basic_types[T_CHAR])->symt;
152 cv_basic_types[T_32PSHORT] = &symt_new_pointer(module, cv_basic_types[T_SHORT])->symt;
153 cv_basic_types[T_32PLONG] = &symt_new_pointer(module, cv_basic_types[T_LONG])->symt;
154 cv_basic_types[T_32PQUAD] = &symt_new_pointer(module, cv_basic_types[T_QUAD])->symt;
155 cv_basic_types[T_32PUCHAR] = &symt_new_pointer(module, cv_basic_types[T_UCHAR])->symt;
156 cv_basic_types[T_32PUSHORT] = &symt_new_pointer(module, cv_basic_types[T_USHORT])->symt;
157 cv_basic_types[T_32PULONG] = &symt_new_pointer(module, cv_basic_types[T_ULONG])->symt;
158 cv_basic_types[T_32PUQUAD] = &symt_new_pointer(module, cv_basic_types[T_UQUAD])->symt;
159 cv_basic_types[T_32PREAL32] = &symt_new_pointer(module, cv_basic_types[T_REAL32])->symt;
160 cv_basic_types[T_32PREAL64] = &symt_new_pointer(module, cv_basic_types[T_REAL64])->symt;
161 cv_basic_types[T_32PRCHAR] = &symt_new_pointer(module, cv_basic_types[T_RCHAR])->symt;
162 cv_basic_types[T_32PWCHAR] = &symt_new_pointer(module, cv_basic_types[T_WCHAR])->symt;
163 cv_basic_types[T_32PINT4] = &symt_new_pointer(module, cv_basic_types[T_INT4])->symt;
164 cv_basic_types[T_32PUINT4] = &symt_new_pointer(module, cv_basic_types[T_UINT4])->symt;
167 static int numeric_leaf(int* value, const unsigned short int* leaf)
169 unsigned short int type = *leaf++;
172 if (type < LF_NUMERIC)
182 *value = *(const char*)leaf;
187 *value = *(const short*)leaf;
192 *value = *(const unsigned short*)leaf;
197 *value = *(const int*)leaf;
202 *value = *(const unsigned int*)leaf;
207 FIXME("Unsupported numeric leaf type %04x\n", type);
209 *value = 0; /* FIXME */
213 FIXME("Unsupported numeric leaf type %04x\n", type);
215 *value = 0; /* FIXME */
219 FIXME("Unsupported numeric leaf type %04x\n", type);
221 *value = 0; /* FIXME */
225 FIXME("Unsupported numeric leaf type %04x\n", type);
227 *value = 0; /* FIXME */
231 FIXME("Unsupported numeric leaf type %04x\n", type);
233 *value = 0; /* FIXME */
237 FIXME("Unsupported numeric leaf type %04x\n", type);
239 *value = 0; /* FIXME */
243 FIXME("Unsupported numeric leaf type %04x\n", type);
245 *value = 0; /* FIXME */
249 FIXME("Unsupported numeric leaf type %04x\n", type);
251 *value = 0; /* FIXME */
255 FIXME("Unsupported numeric leaf type %04x\n", type);
257 *value = 0; /* FIXME */
261 FIXME("Unsupported numeric leaf type %04x\n", type);
263 *value = 0; /* FIXME */
267 FIXME("Unsupported numeric leaf type %04x\n", type);
269 *value = 0; /* FIXME */
273 FIXME("Unknown numeric leaf type %04x\n", type);
282 /* convert a pascal string (as stored in debug information) into
283 * a C string (null terminated).
285 static const char* terminate_string(const struct p_string* p_name)
287 static char symname[256];
289 memcpy(symname, p_name->name, p_name->namelen);
290 symname[p_name->namelen] = '\0';
292 return (!*symname || strcmp(symname, "__unnamed") == 0) ? NULL : symname;
295 static struct symt* codeview_get_type(unsigned int typeno, BOOL allow_special)
297 struct symt* symt = NULL;
300 * Convert Codeview type numbers into something we can grok internally.
301 * Numbers < FIRST_DEFINABLE_TYPE are all fixed builtin types.
302 * Numbers from FIRST_DEFINABLE_TYPE and up are all user defined (structs, etc).
304 if (typeno < FIRST_DEFINABLE_TYPE)
306 if (typeno < MAX_BUILTIN_TYPES)
307 symt = cv_basic_types[typeno];
311 unsigned mod_index = typeno >> 24;
312 unsigned mod_typeno = typeno & 0x00FFFFFF;
313 struct cv_defined_module* mod;
315 mod = (mod_index == 0) ? cv_current_module : &cv_zmodules[mod_index];
317 if (mod_index >= CV_MAX_MODULES || !mod->allowed)
318 FIXME("Module of index %d isn't loaded yet (%x)\n", mod_index, typeno);
321 if (mod_typeno - FIRST_DEFINABLE_TYPE < mod->num_defined_types)
322 symt = mod->defined_types[mod_typeno - FIRST_DEFINABLE_TYPE];
325 if (!allow_special && symt && symt->tag == SymTagCVBitField)
326 FIXME("bitfields are only handled for UDTs\n");
327 if (!symt && typeno) FIXME("Returning NULL symt for type-id %x\n", typeno);
331 static int codeview_add_type(unsigned int typeno, struct symt* dt)
333 if (typeno < FIRST_DEFINABLE_TYPE)
334 FIXME("What the heck\n");
335 if (!cv_current_module)
337 FIXME("Adding %x to non allowed module\n", typeno);
340 if ((typeno >> 24) != 0)
341 FIXME("No module index while inserting type-id assumption is wrong %x\n",
343 while (typeno - FIRST_DEFINABLE_TYPE >= cv_current_module->num_defined_types)
345 cv_current_module->num_defined_types += 0x100;
346 if (cv_current_module->defined_types)
347 cv_current_module->defined_types = (struct symt**)
348 HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
349 cv_current_module->defined_types,
350 cv_current_module->num_defined_types * sizeof(struct symt*));
352 cv_current_module->defined_types = (struct symt**)
353 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
354 cv_current_module->num_defined_types * sizeof(struct symt*));
356 if (cv_current_module->defined_types == NULL) return FALSE;
359 cv_current_module->defined_types[typeno - FIRST_DEFINABLE_TYPE] = dt;
363 static void codeview_clear_type_table(void)
367 for (i = 0; i < CV_MAX_MODULES; i++)
369 if (cv_zmodules[i].allowed && cv_zmodules[i].defined_types)
370 HeapFree(GetProcessHeap(), 0, cv_zmodules[i].defined_types);
371 cv_zmodules[i].allowed = FALSE;
372 cv_zmodules[i].defined_types = NULL;
373 cv_zmodules[i].num_defined_types = 0;
374 HeapFree(GetProcessHeap(), 0, cv_zmodules[i].bitfields);
375 cv_zmodules[i].bitfields = NULL;
376 cv_zmodules[i].num_bitfields = cv_zmodules[i].used_bitfields = 0;
378 cv_current_module = NULL;
381 static int codeview_add_type_pointer(struct module* module, unsigned int typeno,
382 unsigned int datatype)
384 struct symt* symt = &symt_new_pointer(module,
385 codeview_get_type(datatype, FALSE))->symt;
386 return codeview_add_type(typeno, symt);
389 static int codeview_add_type_array(struct module* module,
390 unsigned int typeno, const char* name,
391 unsigned int elemtype, unsigned int arr_len)
394 struct symt* elem = codeview_get_type(elemtype, FALSE);
400 symt_get_info(elem, TI_GET_LENGTH, &elem_size);
401 if (elem_size) arr_max = arr_len / (DWORD)elem_size;
403 symt = &symt_new_array(module, 0, arr_max, elem)->symt;
404 return codeview_add_type(typeno, symt);
407 static int codeview_add_type_bitfield(unsigned int typeno, unsigned int bitoff,
408 unsigned int nbits, unsigned int basetype)
410 if (cv_current_module->used_bitfields >= cv_current_module->num_bitfields)
412 if (cv_current_module->bitfields)
414 cv_current_module->num_bitfields *= 2;
415 cv_current_module->bitfields =
416 HeapReAlloc(GetProcessHeap(), 0,
417 cv_current_module->bitfields,
418 cv_current_module->num_bitfields * sizeof(struct codeview_bitfield));
422 cv_current_module->num_bitfields = 64;
423 cv_current_module->bitfields =
424 HeapAlloc(GetProcessHeap(), 0,
425 cv_current_module->num_bitfields * sizeof(struct codeview_bitfield));
427 if (!cv_current_module->bitfields) return 0;
430 cv_current_module->bitfields[cv_current_module->used_bitfields].symt.tag = SymTagCVBitField;
431 cv_current_module->bitfields[cv_current_module->used_bitfields].subtype = basetype;
432 cv_current_module->bitfields[cv_current_module->used_bitfields].bitposition = bitoff;
433 cv_current_module->bitfields[cv_current_module->used_bitfields].bitlength = nbits;
435 return codeview_add_type(typeno, &cv_current_module->bitfields[cv_current_module->used_bitfields++].symt);
438 static int codeview_add_type_enum_field_list(struct module* module,
440 const unsigned char* list, int len)
442 struct symt_enum* symt;
443 const unsigned char* ptr = list;
445 symt = symt_new_enum(module, NULL);
446 while (ptr - list < len)
448 const union codeview_fieldtype* type = (const union codeview_fieldtype*)ptr;
450 if (*ptr >= 0xf0) /* LF_PAD... */
456 switch (type->generic.id)
458 case LF_ENUMERATE_V1:
460 int value, vlen = numeric_leaf(&value, &type->enumerate_v1.value);
461 const struct p_string* p_name = (const struct p_string*)((const unsigned char*)&type->enumerate_v1.value + vlen);
463 symt_add_enum_element(module, symt, terminate_string(p_name), value);
464 ptr += 2 + 2 + vlen + (1 + p_name->namelen);
467 case LF_ENUMERATE_V3:
469 int value, vlen = numeric_leaf(&value, &type->enumerate_v3.value);
470 const char* name = (const char*)&type->enumerate_v3.value + vlen;
472 symt_add_enum_element(module, symt, name, value);
473 ptr += 2 + 2 + vlen + (1 + strlen(name));
478 FIXME("Unsupported type %04x in ENUM field list\n", type->generic.id);
483 return codeview_add_type(typeno, &symt->symt);
486 static int codeview_add_type_struct_field_list(struct module* module,
488 const unsigned char* list, int len)
490 struct symt_udt* symt;
491 const unsigned char* ptr = list;
493 const struct p_string* p_name;
495 struct symt* subtype;
497 symt = symt_new_udt(module, NULL, 0, UdtStruct /* don't care */);
498 while (ptr - list < len)
500 const union codeview_fieldtype* type = (const union codeview_fieldtype*)ptr;
502 if (*ptr >= 0xf0) /* LF_PAD... */
508 switch (type->generic.id)
511 leaf_len = numeric_leaf(&value, &type->bclass_v1.offset);
513 /* FIXME: ignored for now */
515 ptr += 2 + 2 + 2 + leaf_len;
519 leaf_len = numeric_leaf(&value, &type->bclass_v2.offset);
521 /* FIXME: ignored for now */
523 ptr += 2 + 2 + 4 + leaf_len;
529 const unsigned short int* p_vboff;
531 leaf_len = numeric_leaf(&value, &type->vbclass_v1.vbpoff);
532 p_vboff = (const unsigned short int*)((const char*)&type->vbclass_v1.vbpoff + leaf_len);
533 vplen = numeric_leaf(&vpoff, p_vboff);
535 /* FIXME: ignored for now */
537 ptr += 2 + 2 + 2 + 2 + leaf_len + vplen;
544 const unsigned short int* p_vboff;
546 leaf_len = numeric_leaf(&value, &type->vbclass_v2.vbpoff);
547 p_vboff = (const unsigned short int*)((const char*)&type->vbclass_v2.vbpoff + leaf_len);
548 vplen = numeric_leaf(&vpoff, p_vboff);
550 /* FIXME: ignored for now */
552 ptr += 2 + 2 + 4 + 4 + leaf_len + vplen;
557 leaf_len = numeric_leaf(&value, &type->member_v1.offset);
558 p_name = (const struct p_string*)((const char*)&type->member_v1.offset + leaf_len);
559 subtype = codeview_get_type(type->member_v1.type, TRUE);
561 if (!subtype || subtype->tag != SymTagCVBitField)
563 DWORD64 elem_size = 0;
564 if (subtype) symt_get_info(subtype, TI_GET_LENGTH, &elem_size);
565 symt_add_udt_element(module, symt, terminate_string(p_name),
566 codeview_get_type(type->member_v1.type, TRUE),
567 value << 3, (DWORD)elem_size << 3);
571 struct codeview_bitfield* cvbf = (struct codeview_bitfield*)subtype;
572 symt_add_udt_element(module, symt, terminate_string(p_name),
573 codeview_get_type(cvbf->subtype, FALSE),
574 cvbf->bitposition, cvbf->bitlength);
577 ptr += 2 + 2 + 2 + leaf_len + (1 + p_name->namelen);
581 leaf_len = numeric_leaf(&value, &type->member_v2.offset);
582 p_name = (const struct p_string*)((const unsigned char*)&type->member_v2.offset + leaf_len);
583 subtype = codeview_get_type(type->member_v2.type, TRUE);
585 if (!subtype || subtype->tag != SymTagCVBitField)
587 DWORD64 elem_size = 0;
588 if (subtype) symt_get_info(subtype, TI_GET_LENGTH, &elem_size);
589 symt_add_udt_element(module, symt, terminate_string(p_name),
590 subtype, value << 3, (DWORD)elem_size << 3);
594 struct codeview_bitfield* cvbf = (struct codeview_bitfield*)subtype;
595 symt_add_udt_element(module, symt, terminate_string(p_name),
596 codeview_get_type(cvbf->subtype, FALSE),
597 cvbf->bitposition, cvbf->bitlength);
600 ptr += 2 + 2 + 4 + leaf_len + (1 + p_name->namelen);
604 leaf_len = numeric_leaf(&value, &type->member_v3.offset);
605 c_name = (const char*)&type->member_v3.offset + leaf_len;
606 subtype = codeview_get_type(type->member_v3.type, TRUE);
608 if (!subtype || subtype->tag != SymTagCVBitField)
610 DWORD64 elem_size = 0;
611 if (subtype) symt_get_info(subtype, TI_GET_LENGTH, &elem_size);
612 symt_add_udt_element(module, symt, c_name,
613 subtype, value << 3, (DWORD)elem_size << 3);
617 struct codeview_bitfield* cvbf = (struct codeview_bitfield*)subtype;
618 symt_add_udt_element(module, symt, c_name,
619 codeview_get_type(cvbf->subtype, FALSE),
620 cvbf->bitposition, cvbf->bitlength);
623 ptr += 2 + 2 + 4 + leaf_len + (strlen(c_name) + 1);
627 /* FIXME: ignored for now */
628 ptr += 2 + 2 + 2 + (1 + type->stmember_v1.p_name.namelen);
632 /* FIXME: ignored for now */
633 ptr += 2 + 4 + 2 + (1 + type->stmember_v2.p_name.namelen);
637 /* FIXME: ignored for now */
638 ptr += 2 + 2 + 2 + (1 + type->method_v1.p_name.namelen);
642 /* FIXME: ignored for now */
643 ptr += 2 + 2 + 4 + (1 + type->method_v2.p_name.namelen);
647 /* FIXME: ignored for now */
648 ptr += 2 + 2 + (1 + type->nesttype_v1.p_name.namelen);
652 /* FIXME: ignored for now */
653 ptr += 2 + 2 + 4 + (1 + type->nesttype_v2.p_name.namelen);
657 /* FIXME: ignored for now */
662 /* FIXME: ignored for now */
666 case LF_ONEMETHOD_V1:
667 /* FIXME: ignored for now */
668 switch ((type->onemethod_v1.attribute >> 2) & 7)
670 case 4: case 6: /* (pure) introducing virtual method */
671 ptr += 2 + 2 + 2 + 4 + (1 + type->onemethod_virt_v1.p_name.namelen);
675 ptr += 2 + 2 + 2 + (1 + type->onemethod_v1.p_name.namelen);
680 case LF_ONEMETHOD_V2:
681 /* FIXME: ignored for now */
682 switch ((type->onemethod_v2.attribute >> 2) & 7)
684 case 4: case 6: /* (pure) introducing virtual method */
685 ptr += 2 + 2 + 4 + 4 + (1 + type->onemethod_virt_v2.p_name.namelen);
689 ptr += 2 + 2 + 4 + (1 + type->onemethod_v2.p_name.namelen);
695 FIXME("Unsupported type %04x in STRUCT field list\n", type->generic.id);
700 return codeview_add_type(typeno, &symt->symt);
703 static int codeview_add_type_enum(struct module* module, unsigned int typeno,
704 const char* name, unsigned int fieldlist)
706 struct symt_enum* symt = symt_new_enum(module, name);
707 struct symt* list = codeview_get_type(fieldlist, FALSE);
709 /* FIXME: this is rather ugly !!! */
710 if (list) symt->vchildren = ((struct symt_enum*)list)->vchildren;
712 return codeview_add_type(typeno, &symt->symt);
715 static int codeview_add_type_struct(struct module* module, unsigned int typeno,
716 const char* name, int structlen,
717 unsigned int fieldlist, enum UdtKind kind)
719 struct symt_udt* symt = symt_new_udt(module, name, structlen, kind);
720 struct symt* list = codeview_get_type(fieldlist, FALSE);
722 /* FIXME: this is rather ugly !!! */
723 if (list) symt->vchildren = ((struct symt_udt*)list)->vchildren;
725 return codeview_add_type(typeno, &symt->symt);
728 static int codeview_new_func_signature(struct module* module, unsigned typeno,
729 unsigned ret_type, enum CV_call_e call_conv)
732 symt = &symt_new_function_signature(module,
733 codeview_get_type(ret_type, FALSE),
735 return codeview_add_type(typeno, symt);
738 static int codeview_parse_type_table(struct module* module, const BYTE* table,
741 unsigned int curr_type = 0x1000;
742 const BYTE* ptr = table;
744 const union codeview_type* type;
746 const struct p_string* p_name;
749 while (ptr - table < len)
752 type = (const union codeview_type*)ptr;
754 switch (type->generic.id)
757 /* FIXME: we don't handle modifiers,
758 * but readd previous type on the curr_type
760 WARN("Modifier on %x: %s%s%s%s\n",
761 type->modifier_v1.type,
762 type->modifier_v1.attribute & 0x01 ? "const " : "",
763 type->modifier_v1.attribute & 0x02 ? "volatile " : "",
764 type->modifier_v1.attribute & 0x04 ? "unaligned " : "",
765 type->modifier_v1.attribute & ~0x07 ? "unknown " : "");
766 codeview_add_type(curr_type,
767 codeview_get_type(type->modifier_v1.type, FALSE));
770 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
771 WARN("Modifier on %x: %s%s%s%s\n",
772 type->modifier_v2.type,
773 type->modifier_v2.attribute & 0x01 ? "const " : "",
774 type->modifier_v2.attribute & 0x02 ? "volatile " : "",
775 type->modifier_v2.attribute & 0x04 ? "unaligned " : "",
776 type->modifier_v2.attribute & ~0x07 ? "unknown " : "");
777 codeview_add_type(curr_type,
778 codeview_get_type(type->modifier_v2.type, FALSE));
782 retv = codeview_add_type_pointer(module, curr_type,
783 type->pointer_v1.datatype);
786 retv = codeview_add_type_pointer(module, curr_type,
787 type->pointer_v2.datatype);
791 leaf_len = numeric_leaf(&value, &type->array_v1.arrlen);
792 p_name = (const struct p_string*)((const unsigned char*)&type->array_v1.arrlen + leaf_len);
794 retv = codeview_add_type_array(module, curr_type, terminate_string(p_name),
795 type->array_v1.elemtype, value);
798 leaf_len = numeric_leaf(&value, &type->array_v2.arrlen);
799 p_name = (const struct p_string*)((const unsigned char*)&type->array_v2.arrlen + leaf_len);
801 retv = codeview_add_type_array(module, curr_type, terminate_string(p_name),
802 type->array_v2.elemtype, value);
805 leaf_len = numeric_leaf(&value, &type->array_v3.arrlen);
806 c_name = (const char*)&type->array_v3.arrlen + leaf_len;
808 retv = codeview_add_type_array(module, curr_type, c_name,
809 type->array_v3.elemtype, value);
813 /* a bitfield is a CodeView specific data type which represent a bitfield
814 * in a structure or a class. For now, we store it in a SymTag-like type
815 * (so that the rest of the process is seamless), but check at udt
816 * inclusion type for its presence
818 retv = codeview_add_type_bitfield(curr_type, type->bitfield_v1.bitoff,
819 type->bitfield_v1.nbits,
820 type->bitfield_v1.type);
823 retv = codeview_add_type_bitfield(curr_type, type->bitfield_v2.bitoff,
824 type->bitfield_v2.nbits,
825 type->bitfield_v2.type);
827 case LF_FIELDLIST_V1:
828 case LF_FIELDLIST_V2:
831 * A 'field list' is a CodeView-specific data type which doesn't
832 * directly correspond to any high-level data type. It is used
833 * to hold the collection of members of a struct, class, union
834 * or enum type. The actual definition of that type will follow
835 * later, and refer to the field list definition record.
837 * As we don't have a field list type ourselves, we look ahead
838 * in the field list to try to find out whether this field list
839 * will be used for an enum or struct type, and create a dummy
840 * type of the corresponding sort. Later on, the definition of
841 * the 'real' type will copy the member / enumeration data.
843 const unsigned char* list = type->fieldlist.list;
844 int len = (ptr + type->generic.len + 2) - list;
846 if (((const union codeview_fieldtype*)list)->generic.id == LF_ENUMERATE_V1 ||
847 ((const union codeview_fieldtype*)list)->generic.id == LF_ENUMERATE_V3)
848 retv = codeview_add_type_enum_field_list(module, curr_type, list, len);
850 retv = codeview_add_type_struct_field_list(module, curr_type, list, len);
854 case LF_STRUCTURE_V1:
856 leaf_len = numeric_leaf(&value, &type->struct_v1.structlen);
857 p_name = (const struct p_string*)((const unsigned char*)&type->struct_v1.structlen + leaf_len);
859 retv = codeview_add_type_struct(module, curr_type, terminate_string(p_name),
860 value, type->struct_v1.fieldlist,
861 type->generic.id == LF_CLASS_V1 ? UdtClass : UdtStruct);
864 case LF_STRUCTURE_V2:
866 leaf_len = numeric_leaf(&value, &type->struct_v2.structlen);
867 p_name = (const struct p_string*)((const unsigned char*)&type->struct_v2.structlen + leaf_len);
869 retv = codeview_add_type_struct(module, curr_type, terminate_string(p_name),
870 value, type->struct_v2.fieldlist,
871 type->generic.id == LF_CLASS_V2 ? UdtClass : UdtStruct);
874 case LF_STRUCTURE_V3:
876 leaf_len = numeric_leaf(&value, &type->struct_v3.structlen);
877 c_name = (const char*)&type->struct_v3.structlen + leaf_len;
879 retv = codeview_add_type_struct(module, curr_type, c_name,
880 value, type->struct_v3.fieldlist,
881 type->generic.id == LF_CLASS_V3 ? UdtClass : UdtStruct);
885 leaf_len = numeric_leaf(&value, &type->union_v1.un_len);
886 p_name = (const struct p_string*)((const unsigned char*)&type->union_v1.un_len + leaf_len);
888 retv = codeview_add_type_struct(module, curr_type, terminate_string(p_name),
889 value, type->union_v1.fieldlist, UdtUnion);
892 leaf_len = numeric_leaf(&value, &type->union_v2.un_len);
893 p_name = (const struct p_string*)((const unsigned char*)&type->union_v2.un_len + leaf_len);
895 retv = codeview_add_type_struct(module, curr_type, terminate_string(p_name),
896 value, type->union_v2.fieldlist, UdtUnion);
899 leaf_len = numeric_leaf(&value, &type->union_v3.un_len);
900 c_name = (const char*)&type->union_v3.un_len + leaf_len;
902 retv = codeview_add_type_struct(module, curr_type, c_name,
903 value, type->union_v3.fieldlist, UdtUnion);
906 retv = codeview_add_type_enum(module, curr_type, terminate_string(&type->enumeration_v1.p_name),
907 type->enumeration_v1.field);
911 retv = codeview_add_type_enum(module, curr_type, terminate_string(&type->enumeration_v2.p_name),
912 type->enumeration_v2.field);
915 retv = codeview_add_type_enum(module, curr_type, type->enumeration_v3.name,
916 type->enumeration_v3.field);
918 case LF_PROCEDURE_V1:
919 retv = codeview_new_func_signature(module, curr_type,
920 type->procedure_v1.rvtype,
921 type->procedure_v1.call);
923 case LF_PROCEDURE_V2:
924 retv = codeview_new_func_signature(module, curr_type,
925 type->procedure_v2.rvtype,
926 type->procedure_v2.call);
928 case LF_MFUNCTION_V1:
929 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
930 * nor class information, this would just do for now
932 retv = codeview_new_func_signature(module, curr_type,
933 type->mfunction_v1.rvtype,
934 type->mfunction_v1.call);
936 case LF_MFUNCTION_V2:
937 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
938 * nor class information, this would just do for now
940 retv = codeview_new_func_signature(module, curr_type,
941 type->mfunction_v2.rvtype,
942 type->mfunction_v2.call);
949 FIXME("Not adding parameters' types to function signature\n");
954 FIXME("Unsupported type-id leaf %x\n", type->generic.id);
955 dump(type, 2 + type->generic.len);
958 if (!retv) return FALSE;
960 ptr += type->generic.len + 2;
966 /*========================================================================
967 * Process CodeView line number information.
970 static struct codeview_linetab* codeview_snarf_linetab(struct module* module,
971 const BYTE* linetab, int size,
975 char filename[PATH_MAX];
976 const unsigned int* filetab;
977 const struct p_string* p_fn;
980 struct codeview_linetab* lt_hdr;
981 const unsigned int* lt_ptr;
986 const struct startend* start;
988 struct symt_compiland* compiland;
991 * Now get the important bits.
997 filetab = (const unsigned int*) pnt.c;
1000 * Now count up the number of segments in the file.
1003 for (i = 0; i < nfile; i++)
1005 pnt2.uc = linetab + filetab[i];
1010 * Next allocate the header we will be returning.
1011 * There is one header for each segment, so that we can reach in
1012 * and pull bits as required.
1014 lt_hdr = (struct codeview_linetab*)
1015 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nseg + 1) * sizeof(*lt_hdr));
1022 * Now fill the header we will be returning, one for each segment.
1023 * Note that this will basically just contain pointers into the existing
1024 * line table, and we do not actually copy any additional information
1025 * or allocate any additional memory.
1029 for (i = 0; i < nfile; i++)
1032 * Get the pointer into the segment information.
1034 pnt2.uc = linetab + filetab[i];
1035 file_segcount = *pnt2.s;
1038 lt_ptr = (const unsigned int*) pnt2.c;
1039 start = (const struct startend*)(lt_ptr + file_segcount);
1042 * Now snarf the filename for all of the segments for this file.
1046 p_fn = (const struct p_string*)(start + file_segcount);
1047 memset(filename, 0, sizeof(filename));
1048 memcpy(filename, p_fn->name, p_fn->namelen);
1049 compiland = symt_new_compiland(module, filename);
1052 compiland = symt_new_compiland(module, (const char*)(start + file_segcount));
1054 for (k = 0; k < file_segcount; k++, this_seg++)
1056 pnt2.uc = linetab + lt_ptr[k];
1057 lt_hdr[this_seg].start = start[k].start;
1058 lt_hdr[this_seg].end = start[k].end;
1059 lt_hdr[this_seg].compiland = compiland;
1060 lt_hdr[this_seg].segno = *pnt2.s++;
1061 lt_hdr[this_seg].nline = *pnt2.s++;
1062 lt_hdr[this_seg].offtab = pnt2.ui;
1063 lt_hdr[this_seg].linetab = (const unsigned short*)(pnt2.ui + lt_hdr[this_seg].nline);
1073 /*========================================================================
1074 * Process CodeView symbol information.
1077 static unsigned int codeview_map_offset(const struct msc_debug_info* msc_dbg,
1078 unsigned int offset)
1080 int nomap = msc_dbg->nomap;
1081 const OMAP_DATA* omapp = msc_dbg->omapp;
1084 if (!nomap || !omapp) return offset;
1086 /* FIXME: use binary search */
1087 for (i = 0; i < nomap - 1; i++)
1088 if (omapp[i].from <= offset && omapp[i+1].from > offset)
1089 return !omapp[i].to ? 0 : omapp[i].to + (offset - omapp[i].from);
1094 static const struct codeview_linetab*
1095 codeview_get_linetab(const struct codeview_linetab* linetab,
1096 unsigned seg, unsigned offset)
1099 * Check whether we have line number information
1103 for (; linetab->linetab; linetab++)
1104 if (linetab->segno == seg &&
1105 linetab->start <= offset && linetab->end > offset)
1107 if (!linetab->linetab) linetab = NULL;
1112 static unsigned codeview_get_address(const struct msc_debug_info* msc_dbg,
1113 unsigned seg, unsigned offset)
1115 int nsect = msc_dbg->nsect;
1116 const IMAGE_SECTION_HEADER* sectp = msc_dbg->sectp;
1118 if (!seg || seg > nsect) return 0;
1119 return msc_dbg->module->module.BaseOfImage +
1120 codeview_map_offset(msc_dbg, sectp[seg-1].VirtualAddress + offset);
1123 static void codeview_add_func_linenum(struct module* module,
1124 struct symt_function* func,
1125 const struct codeview_linetab* linetab,
1126 unsigned offset, unsigned size)
1130 if (!linetab) return;
1131 for (i = 0; i < linetab->nline; i++)
1133 if (linetab->offtab[i] >= offset && linetab->offtab[i] < offset + size)
1135 symt_add_func_line(module, func, linetab->compiland->source,
1136 linetab->linetab[i], linetab->offtab[i] - offset);
1141 static int codeview_snarf(const struct msc_debug_info* msc_dbg, const BYTE* root,
1142 int offset, int size,
1143 struct codeview_linetab* linetab)
1145 struct symt_function* curr_func = NULL;
1147 const struct codeview_linetab* flt;
1148 struct symt_block* block = NULL;
1153 * Loop over the different types of records and whenever we
1154 * find something we are interested in, record it and move on.
1156 for (i = offset; i < size; i += length)
1158 const union codeview_symbol* sym = (const union codeview_symbol*)(root + i);
1159 length = sym->generic.len + 2;
1160 if (i + length > size) break;
1161 if (length & 3) FIXME("unpadded len %u\n", length);
1163 switch (sym->generic.id)
1166 * Global and local data symbols. We don't associate these
1167 * with any given source file.
1171 flt = codeview_get_linetab(linetab, sym->data_v1.segment, sym->data_v1.offset);
1172 symt_new_global_variable(msc_dbg->module,
1173 flt ? flt->compiland : NULL,
1174 terminate_string(&sym->data_v1.p_name), sym->generic.id == S_LDATA_V1,
1175 codeview_get_address(msc_dbg, sym->data_v1.segment, sym->data_v1.offset),
1177 codeview_get_type(sym->data_v1.symtype, FALSE));
1181 flt = codeview_get_linetab(linetab, sym->data_v2.segment, sym->data_v2.offset);
1182 name = terminate_string(&sym->data_v2.p_name);
1184 symt_new_global_variable(msc_dbg->module, flt ? flt->compiland : NULL,
1185 name, sym->generic.id == S_LDATA_V2,
1186 codeview_get_address(msc_dbg, sym->data_v2.segment, sym->data_v2.offset),
1188 codeview_get_type(sym->data_v2.symtype, FALSE));
1192 flt = codeview_get_linetab(linetab, sym->data_v3.segment, sym->data_v3.offset);
1193 if (*sym->data_v3.name)
1194 symt_new_global_variable(msc_dbg->module, flt ? flt->compiland : NULL,
1196 sym->generic.id == S_LDATA_V3,
1197 codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset),
1199 codeview_get_type(sym->data_v3.symtype, FALSE));
1202 case S_PUB_V1: /* FIXME is this really a 'data_v1' structure ?? */
1203 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1205 flt = codeview_get_linetab(linetab, sym->data_v1.segment, sym->data_v1.offset);
1206 symt_new_public(msc_dbg->module, flt ? flt->compiland : NULL,
1207 terminate_string(&sym->data_v1.p_name),
1208 codeview_get_address(msc_dbg, sym->data_v1.segment, sym->data_v1.offset),
1209 1, TRUE /* FIXME */, TRUE /* FIXME */);
1212 case S_PUB_V2: /* FIXME is this really a 'data_v2' structure ?? */
1213 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1215 flt = codeview_get_linetab(linetab, sym->data_v2.segment, sym->data_v2.offset);
1216 symt_new_public(msc_dbg->module, flt ? flt->compiland : NULL,
1217 terminate_string(&sym->data_v2.p_name),
1218 codeview_get_address(msc_dbg, sym->data_v2.segment, sym->data_v2.offset),
1219 1, TRUE /* FIXME */, TRUE /* FIXME */);
1224 * Sort of like a global function, but it just points
1225 * to a thunk, which is a stupid name for what amounts to
1226 * a PLT slot in the normal jargon that everyone else uses.
1229 flt = codeview_get_linetab(linetab, sym->thunk_v1.segment, sym->thunk_v1.offset);
1230 symt_new_thunk(msc_dbg->module, flt ? flt->compiland : NULL,
1231 terminate_string(&sym->thunk_v1.p_name), sym->thunk_v1.thtype,
1232 codeview_get_address(msc_dbg, sym->thunk_v1.segment, sym->thunk_v1.offset),
1233 sym->thunk_v1.thunk_len);
1236 flt = codeview_get_linetab(linetab, sym->thunk_v3.segment, sym->thunk_v3.offset);
1237 symt_new_thunk(msc_dbg->module, flt ? flt->compiland : NULL,
1238 sym->thunk_v3.name, sym->thunk_v3.thtype,
1239 codeview_get_address(msc_dbg, sym->thunk_v3.segment, sym->thunk_v3.offset),
1240 sym->thunk_v3.thunk_len);
1244 * Global and static functions.
1248 flt = codeview_get_linetab(linetab, sym->proc_v1.segment, sym->proc_v1.offset);
1249 if (curr_func) FIXME("nested function\n");
1250 curr_func = symt_new_function(msc_dbg->module,
1251 flt ? flt->compiland : NULL,
1252 terminate_string(&sym->proc_v1.p_name),
1253 codeview_get_address(msc_dbg, sym->proc_v1.segment, sym->proc_v1.offset),
1254 sym->proc_v1.proc_len,
1255 codeview_get_type(sym->proc_v1.proctype, FALSE));
1256 codeview_add_func_linenum(msc_dbg->module, curr_func, flt,
1257 sym->proc_v1.offset, sym->proc_v1.proc_len);
1258 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugStart, sym->proc_v1.debug_start, NULL);
1259 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugEnd, sym->proc_v1.debug_end, NULL);
1263 flt = codeview_get_linetab(linetab, sym->proc_v2.segment, sym->proc_v2.offset);
1264 if (curr_func) FIXME("nested function\n");
1265 curr_func = symt_new_function(msc_dbg->module,
1266 flt ? flt->compiland : NULL,
1267 terminate_string(&sym->proc_v2.p_name),
1268 codeview_get_address(msc_dbg, sym->proc_v2.segment, sym->proc_v2.offset),
1269 sym->proc_v2.proc_len,
1270 codeview_get_type(sym->proc_v2.proctype, FALSE));
1271 codeview_add_func_linenum(msc_dbg->module, curr_func, flt,
1272 sym->proc_v2.offset, sym->proc_v2.proc_len);
1273 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugStart, sym->proc_v2.debug_start, NULL);
1274 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugEnd, sym->proc_v2.debug_end, NULL);
1278 flt = codeview_get_linetab(linetab, sym->proc_v3.segment, sym->proc_v3.offset);
1279 if (curr_func) FIXME("nested function\n");
1280 curr_func = symt_new_function(msc_dbg->module,
1281 flt ? flt->compiland : NULL,
1283 codeview_get_address(msc_dbg, sym->proc_v3.segment, sym->proc_v3.offset),
1284 sym->proc_v3.proc_len,
1285 codeview_get_type(sym->proc_v3.proctype, FALSE));
1286 codeview_add_func_linenum(msc_dbg->module, curr_func, flt,
1287 sym->proc_v3.offset, sym->proc_v3.proc_len);
1288 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugStart, sym->proc_v3.debug_start, NULL);
1289 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugEnd, sym->proc_v3.debug_end, NULL);
1292 * Function parameters and stack variables.
1295 symt_add_func_local(msc_dbg->module, curr_func, 0, sym->stack_v1.offset,
1296 block, codeview_get_type(sym->stack_v1.symtype, FALSE),
1297 terminate_string(&sym->stack_v1.p_name));
1300 symt_add_func_local(msc_dbg->module, curr_func, 0, sym->stack_v2.offset,
1301 block, codeview_get_type(sym->stack_v2.symtype, FALSE),
1302 terminate_string(&sym->stack_v2.p_name));
1305 symt_add_func_local(msc_dbg->module, curr_func, 0, sym->stack_v3.offset,
1306 block, codeview_get_type(sym->stack_v3.symtype, FALSE),
1307 sym->stack_v3.name);
1311 symt_add_func_local(msc_dbg->module, curr_func, 0, sym->register_v1.reg,
1312 block, codeview_get_type(sym->register_v1.type, FALSE),
1313 terminate_string(&sym->register_v1.p_name));
1316 symt_add_func_local(msc_dbg->module, curr_func, 0, sym->register_v2.reg,
1317 block, codeview_get_type(sym->register_v2.type, FALSE),
1318 terminate_string(&sym->register_v2.p_name));
1322 block = symt_open_func_block(msc_dbg->module, curr_func, block,
1323 codeview_get_address(msc_dbg, sym->block_v1.segment, sym->block_v1.offset),
1324 sym->block_v1.length);
1327 block = symt_open_func_block(msc_dbg->module, curr_func, block,
1328 codeview_get_address(msc_dbg, sym->block_v3.segment, sym->block_v3.offset),
1329 sym->block_v3.length);
1335 block = symt_close_func_block(msc_dbg->module, curr_func, block, 0);
1339 symt_normalize_function(msc_dbg->module, curr_func);
1344 /* FIXME: we should use this as a compiland, instead of guessing it on the fly */
1345 case S_COMPILAND_V1:
1346 TRACE("S-Compiland-V1e %x %s\n",
1347 sym->compiland_v1.unknown,
1348 terminate_string(&sym->compiland_v1.p_name));
1351 case S_COMPILAND_V2:
1352 TRACE("S-Compiland-V2 %s\n",
1353 terminate_string(&sym->compiland_v2.p_name));
1354 if (TRACE_ON(dbghelp_msc))
1356 const char* ptr1 = sym->compiland_v2.p_name.name + sym->compiland_v2.p_name.namelen;
1360 ptr2 = ptr1 + strlen(ptr1) + 1;
1361 TRACE("\t%s => %s\n", ptr1, ptr2);
1362 ptr1 = ptr2 + strlen(ptr2) + 1;
1366 case S_COMPILAND_V3:
1367 TRACE("S-Compiland-V3 %s\n", sym->compiland_v3.name);
1368 if (TRACE_ON(dbghelp_msc))
1370 const char* ptr1 = sym->compiland_v3.name + strlen(sym->compiland_v3.name);
1374 ptr2 = ptr1 + strlen(ptr1) + 1;
1375 TRACE("\t%s => %s\n", ptr1, ptr2);
1376 ptr1 = ptr2 + strlen(ptr2) + 1;
1382 TRACE("S-ObjName %.*s\n", ((const BYTE*)sym)[8], (const BYTE*)sym + 9);
1388 symt_add_function_point(msc_dbg->module, curr_func, SymTagLabel,
1389 codeview_get_address(msc_dbg, sym->label_v1.segment, sym->label_v1.offset) - curr_func->address,
1390 terminate_string(&sym->label_v1.p_name));
1393 FIXME("No current function for label %s\n",
1394 terminate_string(&sym->label_v1.p_name));
1399 symt_add_function_point(msc_dbg->module, curr_func, SymTagLabel,
1400 codeview_get_address(msc_dbg, sym->label_v3.segment, sym->label_v3.offset) - curr_func->address,
1401 sym->label_v3.name);
1404 FIXME("No current function for label %s\n", sym->label_v3.name);
1410 const struct p_string* name;
1414 vlen = numeric_leaf(&val, &sym->constant_v1.cvalue);
1415 name = (const struct p_string*)((const char*)&sym->constant_v1.cvalue + vlen);
1416 se = codeview_get_type(sym->constant_v1.type, FALSE);
1418 else if (se->tag == SymTagEnum) x = ((struct symt_enum*)se)->name;
1421 TRACE("S-Constant-V1 %u %s %x (%s)\n",
1422 val, terminate_string(name), sym->constant_v1.type, x);
1423 /* FIXME: we should add this as a constant value */
1429 const struct p_string* name;
1433 vlen = numeric_leaf(&val, &sym->constant_v2.cvalue);
1434 name = (const struct p_string*)((const char*)&sym->constant_v2.cvalue + vlen);
1435 se = codeview_get_type(sym->constant_v2.type, FALSE);
1437 else if (se->tag == SymTagEnum) x = ((struct symt_enum*)se)->name;
1440 TRACE("S-Constant-V2 %u %s %x (%s)\n",
1441 val, terminate_string(name), sym->constant_v2.type, x);
1442 /* FIXME: we should add this as a constant value */
1452 vlen = numeric_leaf(&val, &sym->constant_v3.cvalue);
1453 name = (const char*)&sym->constant_v3.cvalue + vlen;
1454 se = codeview_get_type(sym->constant_v3.type, FALSE);
1456 else if (se->tag == SymTagEnum) x = ((struct symt_enum*)se)->name;
1459 TRACE("S-Constant-V3 %u %s %x (%s)\n",
1460 val, name, sym->constant_v3.type, x);
1461 /* FIXME: we should add this as a constant value */
1466 if (sym->udt_v1.type)
1468 if ((symt = codeview_get_type(sym->udt_v1.type, FALSE)))
1469 symt_new_typedef(msc_dbg->module, symt,
1470 terminate_string(&sym->udt_v1.p_name));
1472 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1473 terminate_string(&sym->udt_v1.p_name), sym->udt_v1.type);
1477 if (sym->udt_v2.type)
1479 if ((symt = codeview_get_type(sym->udt_v2.type, FALSE)))
1480 symt_new_typedef(msc_dbg->module, symt,
1481 terminate_string(&sym->udt_v2.p_name));
1483 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1484 terminate_string(&sym->udt_v2.p_name), sym->udt_v2.type);
1488 if (sym->udt_v3.type)
1490 if ((symt = codeview_get_type(sym->udt_v3.type, FALSE)))
1491 symt_new_typedef(msc_dbg->module, symt, sym->udt_v3.name);
1493 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1494 sym->udt_v3.name, sym->udt_v3.type);
1499 * These are special, in that they are always followed by an
1500 * additional length-prefixed string which is *not* included
1501 * into the symbol length count. We need to skip it.
1506 name = (const char*)sym + length;
1507 length += (*name + 1 + 3) & ~3;
1511 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1513 flt = codeview_get_linetab(linetab, sym->data_v3.segment, sym->data_v3.offset);
1514 symt_new_public(msc_dbg->module,
1515 flt ? flt->compiland : NULL,
1517 codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset),
1518 1, FALSE /* FIXME */, FALSE);
1521 case S_PUB_FUNC1_V3:
1522 case S_PUB_FUNC2_V3: /* using a data_v3 isn't what we'd expect */
1523 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1525 flt = codeview_get_linetab(linetab, sym->data_v3.segment, sym->data_v3.offset);
1526 symt_new_public(msc_dbg->module,
1527 flt ? flt->compiland : NULL,
1529 codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset),
1530 1, TRUE /* FIXME */, TRUE);
1534 case S_MSTOOL_V3: /* just to silence a few warnings */
1538 FIXME("Unsupported symbol id %x\n", sym->generic.id);
1539 dump(sym, 2 + sym->generic.len);
1544 if (curr_func) symt_normalize_function(msc_dbg->module, curr_func);
1546 HeapFree(GetProcessHeap(), 0, linetab);
1550 /*========================================================================
1556 const char* filename;
1557 enum {PDB_JG, PDB_DS} kind;
1563 struct PDB_JG_TOC* toc;
1568 struct PDB_DS_TOC* toc;
1573 static void* pdb_jg_read(const struct PDB_JG_HEADER* pdb, const WORD* block_list,
1579 if (!size) return NULL;
1581 num_blocks = (size + pdb->block_size - 1) / pdb->block_size;
1582 buffer = HeapAlloc(GetProcessHeap(), 0, num_blocks * pdb->block_size);
1584 for (i = 0; i < num_blocks; i++)
1585 memcpy(buffer + i * pdb->block_size,
1586 (const char*)pdb + block_list[i] * pdb->block_size, pdb->block_size);
1591 static void* pdb_ds_read(const struct PDB_DS_HEADER* pdb, const DWORD* block_list,
1597 if (!size) return NULL;
1599 num_blocks = (size + pdb->block_size - 1) / pdb->block_size;
1600 buffer = HeapAlloc(GetProcessHeap(), 0, num_blocks * pdb->block_size);
1602 for (i = 0; i < num_blocks; i++)
1603 memcpy(buffer + i * pdb->block_size,
1604 (const char*)pdb + block_list[i] * pdb->block_size, pdb->block_size);
1609 static void* pdb_read_jg_file(const struct PDB_JG_HEADER* pdb,
1610 const struct PDB_JG_TOC* toc, DWORD file_nr)
1612 const WORD* block_list;
1615 if (!toc || file_nr >= toc->num_files) return NULL;
1617 block_list = (const WORD*) &toc->file[toc->num_files];
1618 for (i = 0; i < file_nr; i++)
1619 block_list += (toc->file[i].size + pdb->block_size - 1) / pdb->block_size;
1621 return pdb_jg_read(pdb, block_list, toc->file[file_nr].size);
1624 static void* pdb_read_ds_file(const struct PDB_DS_HEADER* pdb,
1625 const struct PDB_DS_TOC* toc, DWORD file_nr)
1627 const DWORD* block_list;
1630 if (!toc || file_nr >= toc->num_files) return NULL;
1632 if (toc->file_size[file_nr] == 0 || toc->file_size[file_nr] == 0xFFFFFFFF)
1634 FIXME(">>> requesting NULL stream (%lu)\n", file_nr);
1637 block_list = &toc->file_size[toc->num_files];
1638 for (i = 0; i < file_nr; i++)
1639 block_list += (toc->file_size[i] + pdb->block_size - 1) / pdb->block_size;
1641 return pdb_ds_read(pdb, block_list, toc->file_size[file_nr]);
1644 static void* pdb_read_file(const char* image, const struct pdb_lookup* pdb_lookup,
1647 switch (pdb_lookup->kind)
1650 return pdb_read_jg_file((const struct PDB_JG_HEADER*)image,
1651 pdb_lookup->u.jg.toc, file_nr);
1653 return pdb_read_ds_file((const struct PDB_DS_HEADER*)image,
1654 pdb_lookup->u.ds.toc, file_nr);
1659 static unsigned pdb_get_file_size(const struct pdb_lookup* pdb_lookup, DWORD file_nr)
1661 switch (pdb_lookup->kind)
1663 case PDB_JG: return pdb_lookup->u.jg.toc->file[file_nr].size;
1664 case PDB_DS: return pdb_lookup->u.ds.toc->file_size[file_nr];
1669 static void pdb_free(void* buffer)
1671 HeapFree(GetProcessHeap(), 0, buffer);
1674 static void pdb_free_lookup(const struct pdb_lookup* pdb_lookup)
1676 switch (pdb_lookup->kind)
1679 if (pdb_lookup->u.jg.toc) pdb_free(pdb_lookup->u.jg.toc);
1682 if (pdb_lookup->u.ds.toc) pdb_free(pdb_lookup->u.ds.toc);
1687 static void pdb_convert_types_header(PDB_TYPES* types, const BYTE* image)
1689 memset(types, 0, sizeof(PDB_TYPES));
1692 if (*(const DWORD*)image < 19960000) /* FIXME: correct version? */
1694 /* Old version of the types record header */
1695 const PDB_TYPES_OLD* old = (const PDB_TYPES_OLD*)image;
1696 types->version = old->version;
1697 types->type_offset = sizeof(PDB_TYPES_OLD);
1698 types->type_size = old->type_size;
1699 types->first_index = old->first_index;
1700 types->last_index = old->last_index;
1701 types->file = old->file;
1705 /* New version of the types record header */
1706 *types = *(const PDB_TYPES*)image;
1710 static void pdb_convert_symbols_header(PDB_SYMBOLS* symbols,
1711 int* header_size, const BYTE* image)
1713 memset(symbols, 0, sizeof(PDB_SYMBOLS));
1716 if (*(const DWORD*)image != 0xffffffff)
1718 /* Old version of the symbols record header */
1719 const PDB_SYMBOLS_OLD* old = (const PDB_SYMBOLS_OLD*)image;
1720 symbols->version = 0;
1721 symbols->module_size = old->module_size;
1722 symbols->offset_size = old->offset_size;
1723 symbols->hash_size = old->hash_size;
1724 symbols->srcmodule_size = old->srcmodule_size;
1725 symbols->pdbimport_size = 0;
1726 symbols->hash1_file = old->hash1_file;
1727 symbols->hash2_file = old->hash2_file;
1728 symbols->gsym_file = old->gsym_file;
1730 *header_size = sizeof(PDB_SYMBOLS_OLD);
1734 /* New version of the symbols record header */
1735 *symbols = *(const PDB_SYMBOLS*)image;
1736 *header_size = sizeof(PDB_SYMBOLS);
1740 static void pdb_convert_symbol_file(const PDB_SYMBOLS* symbols,
1741 PDB_SYMBOL_FILE_EX* sfile,
1742 unsigned* size, const void* image)
1745 if (symbols->version < 19970000)
1747 const PDB_SYMBOL_FILE *sym_file = (const PDB_SYMBOL_FILE*)image;
1748 memset(sfile, 0, sizeof(*sfile));
1749 sfile->file = sym_file->file;
1750 sfile->range.index = sym_file->range.index;
1751 sfile->symbol_size = sym_file->symbol_size;
1752 sfile->lineno_size = sym_file->lineno_size;
1753 *size = sizeof(PDB_SYMBOL_FILE) - 1;
1757 memcpy(sfile, image, sizeof(PDB_SYMBOL_FILE_EX));
1758 *size = sizeof(PDB_SYMBOL_FILE_EX) - 1;
1762 static BOOL CALLBACK pdb_match(char* file, void* user)
1764 /* accept first file that exists */
1765 HANDLE h = CreateFileA(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1766 TRACE("match with %s returns %p\n", file, h);
1767 if (INVALID_HANDLE_VALUE != h) {
1774 static HANDLE open_pdb_file(const struct process* pcs, const char* filename)
1777 char dbg_file_path[MAX_PATH];
1779 h = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
1780 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1781 /* FIXME: should give more bits on the file to look at */
1782 if (h == INVALID_HANDLE_VALUE &&
1783 SymFindFileInPath(pcs->handle, NULL, (char*)filename, NULL, 0, 0, 0,
1784 dbg_file_path, pdb_match, NULL))
1786 h = CreateFileA(dbg_file_path, GENERIC_READ, FILE_SHARE_READ, NULL,
1787 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1788 TRACE("with %s returns %p\n", dbg_file_path, h);
1790 return (h == INVALID_HANDLE_VALUE) ? NULL : h;
1793 static void pdb_process_types(const struct msc_debug_info* msc_dbg,
1794 const char* image, struct pdb_lookup* pdb_lookup)
1796 BYTE* types_image = NULL;
1798 types_image = pdb_read_file(image, pdb_lookup, 2);
1802 pdb_convert_types_header(&types, types_image);
1804 /* Check for unknown versions */
1805 switch (types.version)
1807 case 19950410: /* VC 4.0 */
1809 case 19961031: /* VC 5.0 / 6.0 */
1813 ERR("-Unknown type info version %ld\n", types.version);
1816 /* Read type table */
1817 codeview_parse_type_table(msc_dbg->module, types_image + types.type_offset,
1819 pdb_free(types_image);
1823 static const char PDB_JG_IDENT[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
1824 static const char PDB_DS_IDENT[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
1826 static BOOL pdb_init(struct pdb_lookup* pdb_lookup, const char* image)
1828 /* check the file header, and if ok, load the TOC */
1829 TRACE("PDB(%s): %.40s\n", pdb_lookup->filename, debugstr_an(image, 40));
1830 switch (pdb_lookup->kind)
1833 pdb_lookup->u.jg.toc = NULL;
1834 if (memcmp(image, PDB_JG_IDENT, sizeof(PDB_JG_IDENT)))
1836 FIXME("Couldn't match JG header\n");
1841 const struct PDB_JG_HEADER* pdb = (const struct PDB_JG_HEADER*)image;
1842 struct PDB_JG_ROOT* root;
1844 pdb_lookup->u.jg.toc = pdb_jg_read(pdb, pdb->toc_block, pdb->toc.size);
1845 root = pdb_read_jg_file(pdb, pdb_lookup->u.jg.toc, 1);
1848 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup->filename);
1851 switch (root->Version)
1853 case 19950623: /* VC 4.0 */
1855 case 19960307: /* VC 5.0 */
1856 case 19970604: /* VC 6.0 */
1859 ERR("-Unknown root block version %ld\n", root->Version);
1861 /* Check .PDB time stamp */
1862 if (root->TimeDateStamp != pdb_lookup->u.jg.timestamp)
1864 ERR("-Wrong time stamp of .PDB file %s (0x%08lx, 0x%08lx)\n",
1865 pdb_lookup->filename, root->TimeDateStamp,
1866 pdb_lookup->u.jg.timestamp);
1872 pdb_lookup->u.ds.toc = NULL;
1873 if (memcmp(image, PDB_DS_IDENT, sizeof(PDB_DS_IDENT)))
1875 FIXME("Couldn't match DS header\n");
1880 const struct PDB_DS_HEADER* pdb = (const struct PDB_DS_HEADER*)image;
1881 struct PDB_DS_ROOT* root;
1883 pdb_lookup->u.ds.toc =
1885 (const DWORD*)((const char*)pdb + pdb->toc_page * pdb->block_size),
1887 root = pdb_read_ds_file(pdb, pdb_lookup->u.ds.toc, 1);
1890 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup->filename);
1893 switch (root->Version)
1898 ERR("-Unknown root block version %ld\n", root->Version);
1900 /* Check .PDB time stamp */
1901 if (memcmp(&root->guid, &pdb_lookup->u.ds.guid, sizeof(GUID)))
1903 ERR("-Wrong GUID of .PDB file %s (%s, %s)\n",
1904 pdb_lookup->filename,
1905 wine_dbgstr_guid(&root->guid),
1906 wine_dbgstr_guid(&pdb_lookup->u.ds.guid));
1913 if (0) /* some tool to dump the internal files from a PDB file */
1917 switch (pdb_lookup->kind)
1919 case PDB_JG: num_files = pdb_lookup->u.jg.toc->num_files; break;
1920 case PDB_DS: num_files = pdb_lookup->u.ds.toc->num_files; break;
1923 for (i = 1; i < num_files; i++)
1925 unsigned char* x = pdb_read_file(image, pdb_lookup, i);
1926 FIXME("********************** [%u]: size=%08x\n",
1927 i, pdb_get_file_size(pdb_lookup, i));
1928 dump(x, pdb_get_file_size(pdb_lookup, i));
1935 static BOOL pdb_process_internal(const struct process* pcs,
1936 const struct msc_debug_info* msc_dbg,
1937 struct pdb_lookup* pdb_lookup,
1938 unsigned module_index);
1940 static void pdb_process_symbol_imports(const struct process* pcs,
1941 const struct msc_debug_info* msc_dbg,
1942 PDB_SYMBOLS* symbols,
1943 const void* symbols_image,
1944 char* image, struct pdb_lookup* pdb_lookup,
1945 unsigned module_index)
1947 if (module_index == -1 && symbols && symbols->pdbimport_size)
1949 const PDB_SYMBOL_IMPORT*imp;
1955 imp = (const PDB_SYMBOL_IMPORT*)((const char*)symbols_image + sizeof(PDB_SYMBOLS) +
1956 symbols->module_size + symbols->offset_size +
1957 symbols->hash_size + symbols->srcmodule_size);
1958 first = (const char*)imp;
1959 last = (const char*)imp + symbols->pdbimport_size;
1960 while (imp < (const PDB_SYMBOL_IMPORT*)last)
1962 ptr = (const char*)imp + sizeof(*imp) + strlen(imp->filename);
1963 if (i >= CV_MAX_MODULES) FIXME("Out of bounds !!!\n");
1964 if (!strcasecmp(pdb_lookup->filename, imp->filename))
1966 if (module_index != -1) FIXME("Twice the entry\n");
1967 else module_index = i;
1971 struct pdb_lookup imp_pdb_lookup;
1973 imp_pdb_lookup.filename = imp->filename;
1974 imp_pdb_lookup.kind = PDB_JG;
1975 imp_pdb_lookup.u.jg.timestamp = imp->TimeDateStamp;
1976 pdb_process_internal(pcs, msc_dbg, &imp_pdb_lookup, i);
1979 imp = (const PDB_SYMBOL_IMPORT*)((const char*)first + ((ptr - (const char*)first + strlen(ptr) + 1 + 3) & ~3));
1982 cv_current_module = &cv_zmodules[(module_index == -1) ? 0 : module_index];
1983 if (cv_current_module->allowed) FIXME("Already allowed ??\n");
1984 cv_current_module->allowed = TRUE;
1985 pdb_process_types(msc_dbg, image, pdb_lookup);
1988 static BOOL pdb_process_internal(const struct process* pcs,
1989 const struct msc_debug_info* msc_dbg,
1990 struct pdb_lookup* pdb_lookup,
1991 unsigned module_index)
1994 HANDLE hFile, hMap = NULL;
1996 BYTE* symbols_image = NULL;
1998 TRACE("Processing PDB file %s\n", pdb_lookup->filename);
2000 /* Open and map() .PDB file */
2001 if ((hFile = open_pdb_file(pcs, pdb_lookup->filename)) == NULL ||
2002 ((hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == NULL) ||
2003 ((image = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) == NULL))
2005 WARN("Unable to open .PDB file: %s\n", pdb_lookup->filename);
2008 pdb_init(pdb_lookup, image);
2010 symbols_image = pdb_read_file(image, pdb_lookup, 3);
2013 PDB_SYMBOLS symbols;
2016 int header_size = 0;
2018 pdb_convert_symbols_header(&symbols, &header_size, symbols_image);
2019 switch (symbols.version)
2021 case 0: /* VC 4.0 */
2022 case 19960307: /* VC 5.0 */
2023 case 19970606: /* VC 6.0 */
2027 ERR("-Unknown symbol info version %ld %08lx\n",
2028 symbols.version, symbols.version);
2031 pdb_process_symbol_imports(pcs, msc_dbg, &symbols, symbols_image, image, pdb_lookup, module_index);
2033 /* Read global symbol table */
2034 modimage = pdb_read_file(image, pdb_lookup, symbols.gsym_file);
2037 codeview_snarf(msc_dbg, modimage, 0,
2038 pdb_get_file_size(pdb_lookup, symbols.gsym_file), NULL);
2043 /* Read per-module symbol / linenumber tables */
2044 file = symbols_image + header_size;
2045 while (file - symbols_image < header_size + symbols.module_size)
2047 PDB_SYMBOL_FILE_EX sfile;
2048 const char* file_name;
2051 HeapValidate(GetProcessHeap(), 0, NULL);
2052 pdb_convert_symbol_file(&symbols, &sfile, &size, file);
2054 modimage = pdb_read_file(image, pdb_lookup, sfile.file);
2057 struct codeview_linetab* linetab = NULL;
2059 if (sfile.lineno_size)
2060 linetab = codeview_snarf_linetab(msc_dbg->module,
2061 modimage + sfile.symbol_size,
2063 pdb_lookup->kind == PDB_JG);
2065 if (sfile.symbol_size)
2066 codeview_snarf(msc_dbg, modimage, sizeof(DWORD),
2067 sfile.symbol_size, linetab);
2071 file_name = (const char*)file + size;
2072 file_name += strlen(file_name) + 1;
2073 file = (BYTE*)((DWORD)(file_name + strlen(file_name) + 1 + 3) & ~3);
2077 pdb_process_symbol_imports(pcs, msc_dbg, NULL, NULL, image, pdb_lookup,
2079 msc_dbg->module->module.SymType = SymCv;
2084 if (symbols_image) pdb_free(symbols_image);
2085 pdb_free_lookup(pdb_lookup);
2087 if (image) UnmapViewOfFile(image);
2088 if (hMap) CloseHandle(hMap);
2089 if (hFile) CloseHandle(hFile);
2094 static BOOL pdb_process_file(const struct process* pcs,
2095 const struct msc_debug_info* msc_dbg,
2096 struct pdb_lookup* pdb_lookup)
2100 memset(cv_zmodules, 0, sizeof(cv_zmodules));
2101 codeview_init_basic_types(msc_dbg->module);
2102 ret = pdb_process_internal(pcs, msc_dbg, pdb_lookup, -1);
2103 codeview_clear_type_table();
2107 /*========================================================================
2108 * Process CodeView debug information.
2111 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
2112 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
2113 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
2114 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
2115 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
2117 typedef struct _CODEVIEW_HEADER_NBxx
2121 } CODEVIEW_HEADER_NBxx,* PCODEVIEW_HEADER_NBxx;
2123 typedef struct _CODEVIEW_HEADER_RSDS
2129 } CODEVIEW_HEADER_RSDS,* PCODEVIEW_HEADER_RSDS;
2131 typedef struct _CODEVIEW_PDB_DATA
2136 } CODEVIEW_PDB_DATA, *PCODEVIEW_PDB_DATA;
2138 typedef struct _CV_DIRECTORY_HEADER
2145 } CV_DIRECTORY_HEADER, *PCV_DIRECTORY_HEADER;
2147 typedef struct _CV_DIRECTORY_ENTRY
2153 } CV_DIRECTORY_ENTRY, *PCV_DIRECTORY_ENTRY;
2155 #define sstAlignSym 0x125
2156 #define sstSrcModule 0x127
2158 static BOOL codeview_process_info(const struct process* pcs,
2159 const struct msc_debug_info* msc_dbg)
2161 const CODEVIEW_HEADER_NBxx* cv = (const CODEVIEW_HEADER_NBxx*)msc_dbg->root;
2163 struct pdb_lookup pdb_lookup;
2165 TRACE("Processing signature %.4s\n", (const char*)&cv->dwSignature);
2167 switch (cv->dwSignature)
2169 case CODEVIEW_NB09_SIG:
2170 case CODEVIEW_NB11_SIG:
2172 const CV_DIRECTORY_HEADER* hdr = (const CV_DIRECTORY_HEADER*)(msc_dbg->root + cv->lfoDirectory);
2173 const CV_DIRECTORY_ENTRY* ent;
2174 const CV_DIRECTORY_ENTRY* prev;
2175 const CV_DIRECTORY_ENTRY* next;
2178 codeview_init_basic_types(msc_dbg->module);
2179 ent = (const CV_DIRECTORY_ENTRY*)((const BYTE*)hdr + hdr->cbDirHeader);
2180 for (i = 0; i < hdr->cDir; i++, ent = next)
2182 next = (i == hdr->cDir-1)? NULL :
2183 (const CV_DIRECTORY_ENTRY*)((const BYTE*)ent + hdr->cbDirEntry);
2184 prev = (i == 0)? NULL :
2185 (const CV_DIRECTORY_ENTRY*)((const BYTE*)ent - hdr->cbDirEntry);
2187 if (ent->subsection == sstAlignSym)
2190 * Check the next and previous entry. If either is a
2191 * sstSrcModule, it contains the line number info for
2194 * FIXME: This is not a general solution!
2196 struct codeview_linetab* linetab = NULL;
2198 if (next && next->iMod == ent->iMod &&
2199 next->subsection == sstSrcModule)
2200 linetab = codeview_snarf_linetab(msc_dbg->module,
2201 msc_dbg->root + next->lfo, next->cb,
2204 if (prev && prev->iMod == ent->iMod &&
2205 prev->subsection == sstSrcModule)
2206 linetab = codeview_snarf_linetab(msc_dbg->module,
2207 msc_dbg->root + prev->lfo, prev->cb,
2210 codeview_snarf(msc_dbg, msc_dbg->root + ent->lfo, sizeof(DWORD),
2215 msc_dbg->module->module.SymType = SymCv;
2220 case CODEVIEW_NB10_SIG:
2222 const CODEVIEW_PDB_DATA* pdb = (const CODEVIEW_PDB_DATA*)(cv + 1);
2223 pdb_lookup.filename = pdb->name;
2224 pdb_lookup.kind = PDB_JG;
2225 pdb_lookup.u.jg.timestamp = pdb->timestamp;
2226 pdb_lookup.u.jg.toc = NULL;
2227 ret = pdb_process_file(pcs, msc_dbg, &pdb_lookup);
2230 case CODEVIEW_RSDS_SIG:
2232 const CODEVIEW_HEADER_RSDS* rsds = (const CODEVIEW_HEADER_RSDS*)msc_dbg->root;
2234 TRACE("Got RSDS type of PDB file: guid=%s unk=%08lx name=%s\n",
2235 wine_dbgstr_guid(&rsds->guid), rsds->unknown, rsds->name);
2236 pdb_lookup.filename = rsds->name;
2237 pdb_lookup.kind = PDB_DS;
2238 pdb_lookup.u.ds.guid = rsds->guid;
2239 pdb_lookup.u.ds.toc = NULL;
2240 ret = pdb_process_file(pcs, msc_dbg, &pdb_lookup);
2244 ERR("Unknown CODEVIEW signature %08lX in module %s\n",
2245 cv->dwSignature, msc_dbg->module->module.ModuleName);
2252 /*========================================================================
2253 * Process debug directory.
2255 BOOL pe_load_debug_directory(const struct process* pcs, struct module* module,
2256 const BYTE* mapping,
2257 const IMAGE_SECTION_HEADER* sectp, DWORD nsect,
2258 const IMAGE_DEBUG_DIRECTORY* dbg, int nDbg)
2262 struct msc_debug_info msc_dbg;
2264 msc_dbg.module = module;
2265 msc_dbg.nsect = nsect;
2266 msc_dbg.sectp = sectp;
2268 msc_dbg.omapp = NULL;
2274 /* First, watch out for OMAP data */
2275 for (i = 0; i < nDbg; i++)
2277 if (dbg[i].Type == IMAGE_DEBUG_TYPE_OMAP_FROM_SRC)
2279 msc_dbg.nomap = dbg[i].SizeOfData / sizeof(OMAP_DATA);
2280 msc_dbg.omapp = (const OMAP_DATA*)(mapping + dbg[i].PointerToRawData);
2285 /* Now, try to parse CodeView debug info */
2286 for (i = 0; i < nDbg; i++)
2288 if (dbg[i].Type == IMAGE_DEBUG_TYPE_CODEVIEW)
2290 msc_dbg.root = mapping + dbg[i].PointerToRawData;
2291 if ((ret = codeview_process_info(pcs, &msc_dbg))) goto done;
2295 /* If not found, try to parse COFF debug info */
2296 for (i = 0; i < nDbg; i++)
2298 if (dbg[i].Type == IMAGE_DEBUG_TYPE_COFF)
2300 msc_dbg.root = mapping + dbg[i].PointerToRawData;
2301 if ((ret = coff_process_info(&msc_dbg))) goto done;
2305 /* FIXME: this should be supported... this is the debug information for
2306 * functions compiled without a frame pointer (FPO = frame pointer omission)
2307 * the associated data helps finding out the relevant information
2309 for (i = 0; i < nDbg; i++)
2310 if (dbg[i].Type == IMAGE_DEBUG_TYPE_FPO)
2311 FIXME("This guy has FPO information\n");
2315 #define FRAME_TRAP 1
2318 typedef struct _FPO_DATA
2320 DWORD ulOffStart; /* offset 1st byte of function code */
2321 DWORD cbProcSize; /* # bytes in function */
2322 DWORD cdwLocals; /* # bytes in locals/4 */
2323 WORD cdwParams; /* # bytes in params/4 */
2325 WORD cbProlog : 8; /* # bytes in prolog */
2326 WORD cbRegs : 3; /* # regs saved */
2327 WORD fHasSEH : 1; /* TRUE if SEH in func */
2328 WORD fUseBP : 1; /* TRUE if EBP has been allocated */
2329 WORD reserved : 1; /* reserved for future use */
2330 WORD cbFrame : 2; /* frame type */
2337 ERR("Got a page fault while loading symbols\n");