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 WINE_EXCEPTION_FILTER(page_fault)
71 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
72 return EXCEPTION_EXECUTE_HANDLER;
73 return EXCEPTION_CONTINUE_SEARCH;
76 static void dump(const void* ptr, unsigned len)
80 const char* hexof = "0123456789abcdef";
81 const BYTE* x = (const BYTE*)ptr;
83 for (i = 0; i < len; i += 16)
85 sprintf(msg, "%08x: ", i);
86 memset(msg + 10, ' ', 3 * 16 + 1 + 16);
87 for (j = 0; j < min(16, len - i); j++)
89 msg[10 + 3 * j + 0] = hexof[x[i + j] >> 4];
90 msg[10 + 3 * j + 1] = hexof[x[i + j] & 15];
91 msg[10 + 3 * j + 2] = ' ';
92 msg[10 + 3 * 16 + 1 + j] = (x[i + j] >= 0x20 && x[i + j] < 0x7f) ?
95 msg[10 + 3 * 16] = ' ';
96 msg[10 + 3 * 16 + 1 + 16] = '\0';
101 /*========================================================================
102 * Process CodeView type information.
105 #define MAX_BUILTIN_TYPES 0x0480
106 #define FIRST_DEFINABLE_TYPE 0x1000
108 static struct symt* cv_basic_types[MAX_BUILTIN_TYPES];
110 #define SymTagCVBitField (SymTagMax + 0x100)
111 struct codeview_bitfield
115 unsigned bitposition;
119 struct cv_defined_module
122 unsigned int num_defined_types;
123 struct symt** defined_types;
125 struct codeview_bitfield* bitfields;
126 unsigned num_bitfields;
127 unsigned used_bitfields;
129 /* FIXME: don't make it static */
130 #define CV_MAX_MODULES 32
131 static struct cv_defined_module cv_zmodules[CV_MAX_MODULES];
132 static struct cv_defined_module*cv_current_module;
134 static void codeview_init_basic_types(struct module* module)
137 * These are the common builtin types that are used by VC++.
139 cv_basic_types[T_NOTYPE] = NULL;
140 cv_basic_types[T_ABS] = NULL;
141 cv_basic_types[T_VOID] = &symt_new_basic(module, btVoid, "void", 0)->symt;
142 cv_basic_types[T_CHAR] = &symt_new_basic(module, btChar, "char", 1)->symt;
143 cv_basic_types[T_SHORT] = &symt_new_basic(module, btInt, "short int", 2)->symt;
144 cv_basic_types[T_LONG] = &symt_new_basic(module, btInt, "long int", 4)->symt;
145 cv_basic_types[T_QUAD] = &symt_new_basic(module, btInt, "long long int", 8)->symt;
146 cv_basic_types[T_UCHAR] = &symt_new_basic(module, btUInt, "unsigned char", 1)->symt;
147 cv_basic_types[T_USHORT] = &symt_new_basic(module, btUInt, "unsigned short", 2)->symt;
148 cv_basic_types[T_ULONG] = &symt_new_basic(module, btUInt, "unsigned long", 4)->symt;
149 cv_basic_types[T_UQUAD] = &symt_new_basic(module, btUInt, "unsigned long long", 8)->symt;
150 cv_basic_types[T_REAL32] = &symt_new_basic(module, btFloat, "float", 4)->symt;
151 cv_basic_types[T_REAL64] = &symt_new_basic(module, btFloat, "double", 8)->symt;
152 cv_basic_types[T_RCHAR] = &symt_new_basic(module, btInt, "signed char", 1)->symt;
153 cv_basic_types[T_WCHAR] = &symt_new_basic(module, btWChar, "wchar_t", 2)->symt;
154 cv_basic_types[T_INT4] = &symt_new_basic(module, btInt, "INT4", 4)->symt;
155 cv_basic_types[T_UINT4] = &symt_new_basic(module, btUInt, "UINT4", 4)->symt;
157 cv_basic_types[T_32PVOID] = &symt_new_pointer(module, cv_basic_types[T_VOID])->symt;
158 cv_basic_types[T_32PCHAR] = &symt_new_pointer(module, cv_basic_types[T_CHAR])->symt;
159 cv_basic_types[T_32PSHORT] = &symt_new_pointer(module, cv_basic_types[T_SHORT])->symt;
160 cv_basic_types[T_32PLONG] = &symt_new_pointer(module, cv_basic_types[T_LONG])->symt;
161 cv_basic_types[T_32PQUAD] = &symt_new_pointer(module, cv_basic_types[T_QUAD])->symt;
162 cv_basic_types[T_32PUCHAR] = &symt_new_pointer(module, cv_basic_types[T_UCHAR])->symt;
163 cv_basic_types[T_32PUSHORT] = &symt_new_pointer(module, cv_basic_types[T_USHORT])->symt;
164 cv_basic_types[T_32PULONG] = &symt_new_pointer(module, cv_basic_types[T_ULONG])->symt;
165 cv_basic_types[T_32PUQUAD] = &symt_new_pointer(module, cv_basic_types[T_UQUAD])->symt;
166 cv_basic_types[T_32PREAL32] = &symt_new_pointer(module, cv_basic_types[T_REAL32])->symt;
167 cv_basic_types[T_32PREAL64] = &symt_new_pointer(module, cv_basic_types[T_REAL64])->symt;
168 cv_basic_types[T_32PRCHAR] = &symt_new_pointer(module, cv_basic_types[T_RCHAR])->symt;
169 cv_basic_types[T_32PWCHAR] = &symt_new_pointer(module, cv_basic_types[T_WCHAR])->symt;
170 cv_basic_types[T_32PINT4] = &symt_new_pointer(module, cv_basic_types[T_INT4])->symt;
171 cv_basic_types[T_32PUINT4] = &symt_new_pointer(module, cv_basic_types[T_UINT4])->symt;
174 static int numeric_leaf(int* value, const unsigned short int* leaf)
176 unsigned short int type = *leaf++;
179 if (type < LF_NUMERIC)
189 *value = *(const char*)leaf;
194 *value = *(const short*)leaf;
199 *value = *(const unsigned short*)leaf;
204 *value = *(const int*)leaf;
209 *value = *(const unsigned int*)leaf;
214 FIXME("Unsupported numeric leaf type %04x\n", type);
216 *value = 0; /* FIXME */
220 FIXME("Unsupported numeric leaf type %04x\n", type);
222 *value = 0; /* FIXME */
226 FIXME("Unsupported numeric leaf type %04x\n", type);
228 *value = 0; /* FIXME */
232 FIXME("Unsupported numeric leaf type %04x\n", type);
234 *value = 0; /* FIXME */
238 FIXME("Unsupported numeric leaf type %04x\n", type);
240 *value = 0; /* FIXME */
244 FIXME("Unsupported numeric leaf type %04x\n", type);
246 *value = 0; /* FIXME */
250 FIXME("Unsupported numeric leaf type %04x\n", type);
252 *value = 0; /* FIXME */
256 FIXME("Unsupported numeric leaf type %04x\n", type);
258 *value = 0; /* FIXME */
262 FIXME("Unsupported numeric leaf type %04x\n", type);
264 *value = 0; /* FIXME */
268 FIXME("Unsupported numeric leaf type %04x\n", type);
270 *value = 0; /* FIXME */
274 FIXME("Unsupported numeric leaf type %04x\n", type);
276 *value = 0; /* FIXME */
280 FIXME("Unknown numeric leaf type %04x\n", type);
289 /* convert a pascal string (as stored in debug information) into
290 * a C string (null terminated).
292 static const char* terminate_string(const struct p_string* p_name)
294 static char symname[256];
296 memcpy(symname, p_name->name, p_name->namelen);
297 symname[p_name->namelen] = '\0';
299 return (!*symname || strcmp(symname, "__unnamed") == 0) ? NULL : symname;
302 static struct symt* codeview_get_type(unsigned int typeno, BOOL allow_special)
304 struct symt* symt = NULL;
307 * Convert Codeview type numbers into something we can grok internally.
308 * Numbers < FIRST_DEFINABLE_TYPE are all fixed builtin types.
309 * Numbers from FIRST_DEFINABLE_TYPE and up are all user defined (structs, etc).
311 if (typeno < FIRST_DEFINABLE_TYPE)
313 if (typeno < MAX_BUILTIN_TYPES)
314 symt = cv_basic_types[typeno];
318 unsigned mod_index = typeno >> 24;
319 unsigned mod_typeno = typeno & 0x00FFFFFF;
320 struct cv_defined_module* mod;
322 mod = (mod_index == 0) ? cv_current_module : &cv_zmodules[mod_index];
324 if (mod_index >= CV_MAX_MODULES || !mod->allowed)
325 FIXME("Module of index %d isn't loaded yet (%x)\n", mod_index, typeno);
328 if (mod_typeno - FIRST_DEFINABLE_TYPE < mod->num_defined_types)
329 symt = mod->defined_types[mod_typeno - FIRST_DEFINABLE_TYPE];
332 if (!allow_special && symt && symt->tag == SymTagCVBitField)
333 FIXME("bitfields are only handled for UDTs\n");
334 if (!symt && typeno) FIXME("Returning NULL symt for type-id %x\n", typeno);
338 static int codeview_add_type(unsigned int typeno, struct symt* dt)
340 if (typeno < FIRST_DEFINABLE_TYPE)
341 FIXME("What the heck\n");
342 if (!cv_current_module)
344 FIXME("Adding %x to non allowed module\n", typeno);
347 if ((typeno >> 24) != 0)
348 FIXME("No module index while inserting type-id assumption is wrong %x\n",
350 while (typeno - FIRST_DEFINABLE_TYPE >= cv_current_module->num_defined_types)
352 cv_current_module->num_defined_types += 0x100;
353 if (cv_current_module->defined_types)
354 cv_current_module->defined_types = (struct symt**)
355 HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
356 cv_current_module->defined_types,
357 cv_current_module->num_defined_types * sizeof(struct symt*));
359 cv_current_module->defined_types = (struct symt**)
360 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
361 cv_current_module->num_defined_types * sizeof(struct symt*));
363 if (cv_current_module->defined_types == NULL) return FALSE;
366 cv_current_module->defined_types[typeno - FIRST_DEFINABLE_TYPE] = dt;
370 static void codeview_clear_type_table(void)
374 for (i = 0; i < CV_MAX_MODULES; i++)
376 if (cv_zmodules[i].allowed && cv_zmodules[i].defined_types)
377 HeapFree(GetProcessHeap(), 0, cv_zmodules[i].defined_types);
378 cv_zmodules[i].allowed = FALSE;
379 cv_zmodules[i].defined_types = NULL;
380 cv_zmodules[i].num_defined_types = 0;
381 HeapFree(GetProcessHeap(), 0, cv_zmodules[i].bitfields);
382 cv_zmodules[i].bitfields = NULL;
383 cv_zmodules[i].num_bitfields = cv_zmodules[i].used_bitfields = 0;
385 cv_current_module = NULL;
388 static int codeview_add_type_pointer(struct module* module, unsigned int typeno,
389 unsigned int datatype)
391 struct symt* symt = &symt_new_pointer(module,
392 codeview_get_type(datatype, FALSE))->symt;
393 return codeview_add_type(typeno, symt);
396 static int codeview_add_type_array(struct module* module,
397 unsigned int typeno, const char* name,
398 unsigned int elemtype, unsigned int arr_len)
401 struct symt* elem = codeview_get_type(elemtype, FALSE);
407 symt_get_info(elem, TI_GET_LENGTH, &elem_size);
408 if (elem_size) arr_max = arr_len / elem_size;
410 symt = &symt_new_array(module, 0, arr_max, elem)->symt;
411 return codeview_add_type(typeno, symt);
414 static int codeview_add_type_bitfield(unsigned int typeno, unsigned int bitoff,
415 unsigned int nbits, unsigned int basetype)
417 if (cv_current_module->used_bitfields >= cv_current_module->num_bitfields)
419 if (cv_current_module->bitfields)
421 cv_current_module->num_bitfields *= 2;
422 cv_current_module->bitfields =
423 HeapReAlloc(GetProcessHeap(), 0,
424 cv_current_module->bitfields,
425 cv_current_module->num_bitfields * sizeof(struct codeview_bitfield));
429 cv_current_module->num_bitfields = 64;
430 cv_current_module->bitfields =
431 HeapAlloc(GetProcessHeap(), 0,
432 cv_current_module->num_bitfields * sizeof(struct codeview_bitfield));
434 if (!cv_current_module->bitfields) return 0;
437 cv_current_module->bitfields[cv_current_module->used_bitfields].symt.tag = SymTagCVBitField;
438 cv_current_module->bitfields[cv_current_module->used_bitfields].subtype = basetype;
439 cv_current_module->bitfields[cv_current_module->used_bitfields].bitposition = bitoff;
440 cv_current_module->bitfields[cv_current_module->used_bitfields].bitlength = nbits;
442 return codeview_add_type(typeno, &cv_current_module->bitfields[cv_current_module->used_bitfields++].symt);
445 static int codeview_add_type_enum_field_list(struct module* module,
447 const unsigned char* list, int len)
449 struct symt_enum* symt;
450 const unsigned char* ptr = list;
452 symt = symt_new_enum(module, NULL);
453 while (ptr - list < len)
455 const union codeview_fieldtype* type = (const union codeview_fieldtype*)ptr;
457 if (*ptr >= 0xf0) /* LF_PAD... */
463 switch (type->generic.id)
465 case LF_ENUMERATE_V1:
467 int value, vlen = numeric_leaf(&value, &type->enumerate_v1.value);
468 const struct p_string* p_name = (const struct p_string*)((const unsigned char*)&type->enumerate_v1.value + vlen);
470 symt_add_enum_element(module, symt, terminate_string(p_name), value);
471 ptr += 2 + 2 + vlen + (1 + p_name->namelen);
474 case LF_ENUMERATE_V3:
476 int value, vlen = numeric_leaf(&value, &type->enumerate_v3.value);
477 const char* name = (const char*)&type->enumerate_v3.value + vlen;
479 symt_add_enum_element(module, symt, name, value);
480 ptr += 2 + 2 + vlen + (1 + strlen(name));
485 FIXME("Unsupported type %04x in ENUM field list\n", type->generic.id);
490 return codeview_add_type(typeno, &symt->symt);
493 static int codeview_add_type_struct_field_list(struct module* module,
495 const unsigned char* list, int len)
497 struct symt_udt* symt;
498 const unsigned char* ptr = list;
500 const struct p_string* p_name;
502 struct symt* subtype;
504 symt = symt_new_udt(module, NULL, 0, UdtStruct /* don't care */);
505 while (ptr - list < len)
507 const union codeview_fieldtype* type = (const union codeview_fieldtype*)ptr;
509 if (*ptr >= 0xf0) /* LF_PAD... */
515 switch (type->generic.id)
518 leaf_len = numeric_leaf(&value, &type->bclass_v1.offset);
520 /* FIXME: ignored for now */
522 ptr += 2 + 2 + 2 + leaf_len;
526 leaf_len = numeric_leaf(&value, &type->bclass_v2.offset);
528 /* FIXME: ignored for now */
530 ptr += 2 + 2 + 4 + leaf_len;
536 const unsigned short int* p_vboff;
538 leaf_len = numeric_leaf(&value, &type->vbclass_v1.vbpoff);
539 p_vboff = (const unsigned short int*)((const char*)&type->vbclass_v1.vbpoff + leaf_len);
540 vplen = numeric_leaf(&vpoff, p_vboff);
542 /* FIXME: ignored for now */
544 ptr += 2 + 2 + 2 + 2 + leaf_len + vplen;
551 const unsigned short int* p_vboff;
553 leaf_len = numeric_leaf(&value, &type->vbclass_v2.vbpoff);
554 p_vboff = (const unsigned short int*)((const char*)&type->vbclass_v2.vbpoff + leaf_len);
555 vplen = numeric_leaf(&vpoff, p_vboff);
557 /* FIXME: ignored for now */
559 ptr += 2 + 2 + 4 + 4 + leaf_len + vplen;
564 leaf_len = numeric_leaf(&value, &type->member_v1.offset);
565 p_name = (const struct p_string*)((const char*)&type->member_v1.offset + leaf_len);
566 subtype = codeview_get_type(type->member_v1.type, TRUE);
568 if (!subtype || subtype->tag != SymTagCVBitField)
571 if (subtype) symt_get_info(subtype, TI_GET_LENGTH, &elem_size);
572 symt_add_udt_element(module, symt, terminate_string(p_name),
573 codeview_get_type(type->member_v1.type, TRUE),
574 value << 3, elem_size << 3);
578 struct codeview_bitfield* cvbf = (struct codeview_bitfield*)subtype;
579 symt_add_udt_element(module, symt, terminate_string(p_name),
580 codeview_get_type(cvbf->subtype, FALSE),
581 cvbf->bitposition, cvbf->bitlength);
584 ptr += 2 + 2 + 2 + leaf_len + (1 + p_name->namelen);
588 leaf_len = numeric_leaf(&value, &type->member_v2.offset);
589 p_name = (const struct p_string*)((const unsigned char*)&type->member_v2.offset + leaf_len);
590 subtype = codeview_get_type(type->member_v2.type, TRUE);
592 if (!subtype || subtype->tag != SymTagCVBitField)
595 if (subtype) symt_get_info(subtype, TI_GET_LENGTH, &elem_size);
596 symt_add_udt_element(module, symt, terminate_string(p_name),
597 subtype, value << 3, elem_size << 3);
601 struct codeview_bitfield* cvbf = (struct codeview_bitfield*)subtype;
602 symt_add_udt_element(module, symt, terminate_string(p_name),
603 codeview_get_type(cvbf->subtype, FALSE),
604 cvbf->bitposition, cvbf->bitlength);
607 ptr += 2 + 2 + 4 + leaf_len + (1 + p_name->namelen);
611 leaf_len = numeric_leaf(&value, &type->member_v3.offset);
612 c_name = (const char*)&type->member_v3.offset + leaf_len;
613 subtype = codeview_get_type(type->member_v3.type, TRUE);
615 if (!subtype || subtype->tag != SymTagCVBitField)
618 if (subtype) symt_get_info(subtype, TI_GET_LENGTH, &elem_size);
619 symt_add_udt_element(module, symt, c_name,
620 subtype, value << 3, elem_size << 3);
624 struct codeview_bitfield* cvbf = (struct codeview_bitfield*)subtype;
625 symt_add_udt_element(module, symt, c_name,
626 codeview_get_type(cvbf->subtype, FALSE),
627 cvbf->bitposition, cvbf->bitlength);
630 ptr += 2 + 2 + 4 + leaf_len + (strlen(c_name) + 1);
634 /* FIXME: ignored for now */
635 ptr += 2 + 2 + 2 + (1 + type->stmember_v1.p_name.namelen);
639 /* FIXME: ignored for now */
640 ptr += 2 + 4 + 2 + (1 + type->stmember_v2.p_name.namelen);
644 /* FIXME: ignored for now */
645 ptr += 2 + 2 + 2 + (1 + type->method_v1.p_name.namelen);
649 /* FIXME: ignored for now */
650 ptr += 2 + 2 + 4 + (1 + type->method_v2.p_name.namelen);
654 /* FIXME: ignored for now */
655 ptr += 2 + 2 + (1 + type->nesttype_v1.p_name.namelen);
659 /* FIXME: ignored for now */
660 ptr += 2 + 2 + 4 + (1 + type->nesttype_v2.p_name.namelen);
664 /* FIXME: ignored for now */
669 /* FIXME: ignored for now */
673 case LF_ONEMETHOD_V1:
674 /* FIXME: ignored for now */
675 switch ((type->onemethod_v1.attribute >> 2) & 7)
677 case 4: case 6: /* (pure) introducing virtual method */
678 ptr += 2 + 2 + 2 + 4 + (1 + type->onemethod_virt_v1.p_name.namelen);
682 ptr += 2 + 2 + 2 + (1 + type->onemethod_v1.p_name.namelen);
687 case LF_ONEMETHOD_V2:
688 /* FIXME: ignored for now */
689 switch ((type->onemethod_v2.attribute >> 2) & 7)
691 case 4: case 6: /* (pure) introducing virtual method */
692 ptr += 2 + 2 + 4 + 4 + (1 + type->onemethod_virt_v2.p_name.namelen);
696 ptr += 2 + 2 + 4 + (1 + type->onemethod_v2.p_name.namelen);
702 FIXME("Unsupported type %04x in STRUCT field list\n", type->generic.id);
707 return codeview_add_type(typeno, &symt->symt);
710 static int codeview_add_type_enum(struct module* module, unsigned int typeno,
711 const char* name, unsigned int fieldlist)
713 struct symt_enum* symt = symt_new_enum(module, name);
714 struct symt* list = codeview_get_type(fieldlist, FALSE);
716 /* FIXME: this is rather ugly !!! */
717 if (list) symt->vchildren = ((struct symt_enum*)list)->vchildren;
719 return codeview_add_type(typeno, &symt->symt);
722 static int codeview_add_type_struct(struct module* module, unsigned int typeno,
723 const char* name, int structlen,
724 unsigned int fieldlist, enum UdtKind kind)
726 struct symt_udt* symt = symt_new_udt(module, name, structlen, kind);
727 struct symt* list = codeview_get_type(fieldlist, FALSE);
729 /* FIXME: this is rather ugly !!! */
730 if (list) symt->vchildren = ((struct symt_udt*)list)->vchildren;
732 return codeview_add_type(typeno, &symt->symt);
735 static int codeview_new_func_signature(struct module* module, unsigned typeno,
739 symt = &symt_new_function_signature(module,
740 codeview_get_type(ret_type, FALSE))->symt;
741 return codeview_add_type(typeno, symt);
744 static int codeview_parse_type_table(struct module* module, const char* table,
747 unsigned int curr_type = 0x1000;
748 const char* ptr = table;
750 const union codeview_type* type;
752 const struct p_string* p_name;
755 while (ptr - table < len)
758 type = (const union codeview_type*)ptr;
760 switch (type->generic.id)
763 /* FIXME: we don't handle modifiers,
764 * but readd previous type on the curr_type
766 WARN("Modifier on %x: %s%s%s%s\n",
767 type->modifier_v1.type,
768 type->modifier_v1.attribute & 0x01 ? "const " : "",
769 type->modifier_v1.attribute & 0x02 ? "volatile " : "",
770 type->modifier_v1.attribute & 0x04 ? "unaligned " : "",
771 type->modifier_v1.attribute & ~0x07 ? "unknown " : "");
772 codeview_add_type(curr_type,
773 codeview_get_type(type->modifier_v1.type, FALSE));
776 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
777 WARN("Modifier on %x: %s%s%s%s\n",
778 type->modifier_v2.type,
779 type->modifier_v2.attribute & 0x01 ? "const " : "",
780 type->modifier_v2.attribute & 0x02 ? "volatile " : "",
781 type->modifier_v2.attribute & 0x04 ? "unaligned " : "",
782 type->modifier_v2.attribute & ~0x07 ? "unknown " : "");
783 codeview_add_type(curr_type,
784 codeview_get_type(type->modifier_v2.type, FALSE));
788 retv = codeview_add_type_pointer(module, curr_type,
789 type->pointer_v1.datatype);
792 retv = codeview_add_type_pointer(module, curr_type,
793 type->pointer_v2.datatype);
797 leaf_len = numeric_leaf(&value, &type->array_v1.arrlen);
798 p_name = (const struct p_string*)((const unsigned char*)&type->array_v1.arrlen + leaf_len);
800 retv = codeview_add_type_array(module, curr_type, terminate_string(p_name),
801 type->array_v1.elemtype, value);
804 leaf_len = numeric_leaf(&value, &type->array_v2.arrlen);
805 p_name = (const struct p_string*)((const unsigned char*)&type->array_v2.arrlen + leaf_len);
807 retv = codeview_add_type_array(module, curr_type, terminate_string(p_name),
808 type->array_v2.elemtype, value);
811 leaf_len = numeric_leaf(&value, &type->array_v3.arrlen);
812 c_name = (const char*)&type->array_v3.arrlen + leaf_len;
814 retv = codeview_add_type_array(module, curr_type, c_name,
815 type->array_v3.elemtype, value);
819 /* a bitfield is a CodeView specific data type which represent a bitfield
820 * in a structure or a class. For now, we store it in a SymTag-like type
821 * (so that the rest of the process is seamless), but check at udt
822 * inclusion type for its presence
824 retv = codeview_add_type_bitfield(curr_type, type->bitfield_v1.bitoff,
825 type->bitfield_v1.nbits,
826 type->bitfield_v1.type);
829 retv = codeview_add_type_bitfield(curr_type, type->bitfield_v2.bitoff,
830 type->bitfield_v2.nbits,
831 type->bitfield_v2.type);
833 case LF_FIELDLIST_V1:
834 case LF_FIELDLIST_V2:
837 * A 'field list' is a CodeView-specific data type which doesn't
838 * directly correspond to any high-level data type. It is used
839 * to hold the collection of members of a struct, class, union
840 * or enum type. The actual definition of that type will follow
841 * later, and refer to the field list definition record.
843 * As we don't have a field list type ourselves, we look ahead
844 * in the field list to try to find out whether this field list
845 * will be used for an enum or struct type, and create a dummy
846 * type of the corresponding sort. Later on, the definition of
847 * the 'real' type will copy the member / enumeration data.
849 const char* list = type->fieldlist.list;
850 int len = (ptr + type->generic.len + 2) - list;
852 if (((const union codeview_fieldtype*)list)->generic.id == LF_ENUMERATE_V1 ||
853 ((const union codeview_fieldtype*)list)->generic.id == LF_ENUMERATE_V3)
854 retv = codeview_add_type_enum_field_list(module, curr_type, list, len);
856 retv = codeview_add_type_struct_field_list(module, curr_type, list, len);
860 case LF_STRUCTURE_V1:
862 leaf_len = numeric_leaf(&value, &type->struct_v1.structlen);
863 p_name = (const struct p_string*)((const unsigned char*)&type->struct_v1.structlen + leaf_len);
865 retv = codeview_add_type_struct(module, curr_type, terminate_string(p_name),
866 value, type->struct_v1.fieldlist,
867 type->generic.id == LF_CLASS_V1 ? UdtClass : UdtStruct);
870 case LF_STRUCTURE_V2:
872 leaf_len = numeric_leaf(&value, &type->struct_v2.structlen);
873 p_name = (const struct p_string*)((const unsigned char*)&type->struct_v2.structlen + leaf_len);
875 retv = codeview_add_type_struct(module, curr_type, terminate_string(p_name),
876 value, type->struct_v2.fieldlist,
877 type->generic.id == LF_CLASS_V2 ? UdtClass : UdtStruct);
880 case LF_STRUCTURE_V3:
882 leaf_len = numeric_leaf(&value, &type->struct_v3.structlen);
883 c_name = (const char*)&type->struct_v3.structlen + leaf_len;
885 retv = codeview_add_type_struct(module, curr_type, c_name,
886 value, type->struct_v3.fieldlist,
887 type->generic.id == LF_CLASS_V3 ? UdtClass : UdtStruct);
891 leaf_len = numeric_leaf(&value, &type->union_v1.un_len);
892 p_name = (const struct p_string*)((const unsigned char*)&type->union_v1.un_len + leaf_len);
894 retv = codeview_add_type_struct(module, curr_type, terminate_string(p_name),
895 value, type->union_v1.fieldlist, UdtUnion);
898 leaf_len = numeric_leaf(&value, &type->union_v2.un_len);
899 p_name = (const struct p_string*)((const unsigned char*)&type->union_v2.un_len + leaf_len);
901 retv = codeview_add_type_struct(module, curr_type, terminate_string(p_name),
902 value, type->union_v2.fieldlist, UdtUnion);
905 leaf_len = numeric_leaf(&value, &type->union_v3.un_len);
906 c_name = (const char*)&type->union_v3.un_len + leaf_len;
908 retv = codeview_add_type_struct(module, curr_type, c_name,
909 value, type->union_v3.fieldlist, UdtUnion);
912 retv = codeview_add_type_enum(module, curr_type, terminate_string(&type->enumeration_v1.p_name),
913 type->enumeration_v1.field);
917 retv = codeview_add_type_enum(module, curr_type, terminate_string(&type->enumeration_v2.p_name),
918 type->enumeration_v2.field);
921 retv = codeview_add_type_enum(module, curr_type, type->enumeration_v3.name,
922 type->enumeration_v3.field);
924 case LF_PROCEDURE_V1:
925 retv = codeview_new_func_signature(module, curr_type,
926 type->procedure_v1.rvtype);
928 case LF_PROCEDURE_V2:
929 retv = codeview_new_func_signature(module, curr_type,
930 type->procedure_v2.rvtype);
932 case LF_MFUNCTION_V1:
933 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
934 * nor class information, this would just do for now
936 retv = codeview_new_func_signature(module, curr_type,
937 type->mfunction_v1.rvtype);
939 case LF_MFUNCTION_V2:
940 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
941 * nor class information, this would just do for now
943 retv = codeview_new_func_signature(module, curr_type,
944 type->mfunction_v2.rvtype);
951 FIXME("Not adding parameters' types to function signature\n");
956 FIXME("Unsupported type-id leaf %x\n", type->generic.id);
957 dump(type, 2 + type->generic.len);
960 if (!retv) return FALSE;
962 ptr += type->generic.len + 2;
968 /*========================================================================
969 * Process CodeView line number information.
972 static struct codeview_linetab* codeview_snarf_linetab(struct module* module,
973 const char* linetab, int size,
977 char filename[PATH_MAX];
978 const unsigned int* filetab;
979 const struct p_string* p_fn;
982 struct codeview_linetab* lt_hdr;
983 const unsigned int* lt_ptr;
988 const struct startend* start;
990 struct symt_compiland* compiland;
993 * Now get the important bits.
999 filetab = (const unsigned int*) pnt.c;
1002 * Now count up the number of segments in the file.
1005 for (i = 0; i < nfile; i++)
1007 pnt2.c = linetab + filetab[i];
1012 * Next allocate the header we will be returning.
1013 * There is one header for each segment, so that we can reach in
1014 * and pull bits as required.
1016 lt_hdr = (struct codeview_linetab*)
1017 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nseg + 1) * sizeof(*lt_hdr));
1024 * Now fill the header we will be returning, one for each segment.
1025 * Note that this will basically just contain pointers into the existing
1026 * line table, and we do not actually copy any additional information
1027 * or allocate any additional memory.
1031 for (i = 0; i < nfile; i++)
1034 * Get the pointer into the segment information.
1036 pnt2.c = linetab + filetab[i];
1037 file_segcount = *pnt2.s;
1040 lt_ptr = (const unsigned int*) pnt2.c;
1041 start = (const struct startend*)(lt_ptr + file_segcount);
1044 * Now snarf the filename for all of the segments for this file.
1048 p_fn = (const struct p_string*)(start + file_segcount);
1049 memset(filename, 0, sizeof(filename));
1050 memcpy(filename, p_fn->name, p_fn->namelen);
1051 compiland = symt_new_compiland(module, filename);
1054 compiland = symt_new_compiland(module, (const char*)(start + file_segcount));
1056 for (k = 0; k < file_segcount; k++, this_seg++)
1058 pnt2.c = linetab + lt_ptr[k];
1059 lt_hdr[this_seg].start = start[k].start;
1060 lt_hdr[this_seg].end = start[k].end;
1061 lt_hdr[this_seg].compiland = compiland;
1062 lt_hdr[this_seg].segno = *pnt2.s++;
1063 lt_hdr[this_seg].nline = *pnt2.s++;
1064 lt_hdr[this_seg].offtab = pnt2.ui;
1065 lt_hdr[this_seg].linetab = (const unsigned short*)(pnt2.ui + lt_hdr[this_seg].nline);
1075 /*========================================================================
1076 * Process CodeView symbol information.
1079 static unsigned int codeview_map_offset(const struct msc_debug_info* msc_dbg,
1080 unsigned int offset)
1082 int nomap = msc_dbg->nomap;
1083 const OMAP_DATA* omapp = msc_dbg->omapp;
1086 if (!nomap || !omapp) return offset;
1088 /* FIXME: use binary search */
1089 for (i = 0; i < nomap - 1; i++)
1090 if (omapp[i].from <= offset && omapp[i+1].from > offset)
1091 return !omapp[i].to ? 0 : omapp[i].to + (offset - omapp[i].from);
1096 static const struct codeview_linetab*
1097 codeview_get_linetab(const struct codeview_linetab* linetab,
1098 unsigned seg, unsigned offset)
1101 * Check whether we have line number information
1105 for (; linetab->linetab; linetab++)
1106 if (linetab->segno == seg &&
1107 linetab->start <= offset && linetab->end > offset)
1109 if (!linetab->linetab) linetab = NULL;
1114 static unsigned codeview_get_address(const struct msc_debug_info* msc_dbg,
1115 unsigned seg, unsigned offset)
1117 int nsect = msc_dbg->nsect;
1118 const IMAGE_SECTION_HEADER* sectp = msc_dbg->sectp;
1120 if (!seg || seg > nsect) return 0;
1121 return msc_dbg->module->module.BaseOfImage +
1122 codeview_map_offset(msc_dbg, sectp[seg-1].VirtualAddress + offset);
1125 static void codeview_add_func_linenum(struct module* module,
1126 struct symt_function* func,
1127 const struct codeview_linetab* linetab,
1128 unsigned offset, unsigned size)
1132 if (!linetab) return;
1133 for (i = 0; i < linetab->nline; i++)
1135 if (linetab->offtab[i] >= offset && linetab->offtab[i] < offset + size)
1137 symt_add_func_line(module, func, linetab->compiland->source,
1138 linetab->linetab[i], linetab->offtab[i] - offset);
1143 static int codeview_snarf(const struct msc_debug_info* msc_dbg, const BYTE* root,
1144 int offset, int size,
1145 struct codeview_linetab* linetab)
1147 struct symt_function* curr_func = NULL;
1149 const struct codeview_linetab* flt;
1150 struct symt_block* block = NULL;
1155 * Loop over the different types of records and whenever we
1156 * find something we are interested in, record it and move on.
1158 for (i = offset; i < size; i += length)
1160 const union codeview_symbol* sym = (const union codeview_symbol*)(root + i);
1161 length = sym->generic.len + 2;
1162 if (i + length > size) break;
1163 if (length & 3) FIXME("unpadded len %u\n", length);
1165 switch (sym->generic.id)
1168 * Global and local data symbols. We don't associate these
1169 * with any given source file.
1173 flt = codeview_get_linetab(linetab, sym->data_v1.segment, sym->data_v1.offset);
1174 symt_new_global_variable(msc_dbg->module,
1175 flt ? flt->compiland : NULL,
1176 terminate_string(&sym->data_v1.p_name), sym->generic.id == S_LDATA_V1,
1177 codeview_get_address(msc_dbg, sym->data_v1.segment, sym->data_v1.offset),
1179 codeview_get_type(sym->data_v1.symtype, FALSE));
1183 flt = codeview_get_linetab(linetab, sym->data_v2.segment, sym->data_v2.offset);
1184 name = terminate_string(&sym->data_v2.p_name);
1186 symt_new_global_variable(msc_dbg->module, flt ? flt->compiland : NULL,
1187 name, sym->generic.id == S_LDATA_V2,
1188 codeview_get_address(msc_dbg, sym->data_v2.segment, sym->data_v2.offset),
1190 codeview_get_type(sym->data_v2.symtype, FALSE));
1194 flt = codeview_get_linetab(linetab, sym->data_v3.segment, sym->data_v3.offset);
1195 if (*sym->data_v3.name)
1196 symt_new_global_variable(msc_dbg->module, flt ? flt->compiland : NULL,
1198 sym->generic.id == S_LDATA_V3,
1199 codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset),
1201 codeview_get_type(sym->data_v3.symtype, FALSE));
1204 case S_PUB_V1: /* FIXME is this really a 'data_v1' structure ?? */
1205 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1207 flt = codeview_get_linetab(linetab, sym->data_v1.segment, sym->data_v1.offset);
1208 symt_new_public(msc_dbg->module, flt ? flt->compiland : NULL,
1209 terminate_string(&sym->data_v1.p_name),
1210 codeview_get_address(msc_dbg, sym->data_v1.segment, sym->data_v1.offset),
1211 0, TRUE /* FIXME */, TRUE /* FIXME */);
1214 case S_PUB_V2: /* FIXME is this really a 'data_v2' structure ?? */
1215 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1217 flt = codeview_get_linetab(linetab, sym->data_v2.segment, sym->data_v2.offset);
1218 symt_new_public(msc_dbg->module, flt ? flt->compiland : NULL,
1219 terminate_string(&sym->data_v2.p_name),
1220 codeview_get_address(msc_dbg, sym->data_v2.segment, sym->data_v2.offset),
1221 0, TRUE /* FIXME */, TRUE /* FIXME */);
1226 * Sort of like a global function, but it just points
1227 * to a thunk, which is a stupid name for what amounts to
1228 * a PLT slot in the normal jargon that everyone else uses.
1231 flt = codeview_get_linetab(linetab, sym->thunk_v1.segment, sym->thunk_v1.offset);
1232 symt_new_thunk(msc_dbg->module, flt ? flt->compiland : NULL,
1233 terminate_string(&sym->thunk_v1.p_name), sym->thunk_v1.thtype,
1234 codeview_get_address(msc_dbg, sym->thunk_v1.segment, sym->thunk_v1.offset),
1235 sym->thunk_v1.thunk_len);
1238 flt = codeview_get_linetab(linetab, sym->thunk_v3.segment, sym->thunk_v3.offset);
1239 symt_new_thunk(msc_dbg->module, flt ? flt->compiland : NULL,
1240 sym->thunk_v3.name, sym->thunk_v3.thtype,
1241 codeview_get_address(msc_dbg, sym->thunk_v3.segment, sym->thunk_v3.offset),
1242 sym->thunk_v3.thunk_len);
1246 * Global and static functions.
1250 flt = codeview_get_linetab(linetab, sym->proc_v1.segment, sym->proc_v1.offset);
1251 if (curr_func) FIXME("nested function\n");
1252 curr_func = symt_new_function(msc_dbg->module,
1253 flt ? flt->compiland : NULL,
1254 terminate_string(&sym->proc_v1.p_name),
1255 codeview_get_address(msc_dbg, sym->proc_v1.segment, sym->proc_v1.offset),
1256 sym->proc_v1.proc_len,
1257 codeview_get_type(sym->proc_v1.proctype, FALSE));
1258 codeview_add_func_linenum(msc_dbg->module, curr_func, flt,
1259 sym->proc_v1.offset, sym->proc_v1.proc_len);
1260 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugStart, sym->proc_v1.debug_start, NULL);
1261 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugEnd, sym->proc_v1.debug_end, NULL);
1265 flt = codeview_get_linetab(linetab, sym->proc_v2.segment, sym->proc_v2.offset);
1266 if (curr_func) FIXME("nested function\n");
1267 curr_func = symt_new_function(msc_dbg->module,
1268 flt ? flt->compiland : NULL,
1269 terminate_string(&sym->proc_v2.p_name),
1270 codeview_get_address(msc_dbg, sym->proc_v2.segment, sym->proc_v2.offset),
1271 sym->proc_v2.proc_len,
1272 codeview_get_type(sym->proc_v2.proctype, FALSE));
1273 codeview_add_func_linenum(msc_dbg->module, curr_func, flt,
1274 sym->proc_v2.offset, sym->proc_v2.proc_len);
1275 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugStart, sym->proc_v2.debug_start, NULL);
1276 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugEnd, sym->proc_v2.debug_end, NULL);
1280 flt = codeview_get_linetab(linetab, sym->proc_v3.segment, sym->proc_v3.offset);
1281 if (curr_func) FIXME("nested function\n");
1282 curr_func = symt_new_function(msc_dbg->module,
1283 flt ? flt->compiland : NULL,
1285 codeview_get_address(msc_dbg, sym->proc_v3.segment, sym->proc_v3.offset),
1286 sym->proc_v3.proc_len,
1287 codeview_get_type(sym->proc_v3.proctype, FALSE));
1288 codeview_add_func_linenum(msc_dbg->module, curr_func, flt,
1289 sym->proc_v3.offset, sym->proc_v3.proc_len);
1290 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugStart, sym->proc_v3.debug_start, NULL);
1291 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugEnd, sym->proc_v3.debug_end, NULL);
1294 * Function parameters and stack variables.
1297 symt_add_func_local(msc_dbg->module, curr_func, 0, sym->stack_v1.offset,
1298 block, codeview_get_type(sym->stack_v1.symtype, FALSE),
1299 terminate_string(&sym->stack_v1.p_name));
1302 symt_add_func_local(msc_dbg->module, curr_func, 0, sym->stack_v2.offset,
1303 block, codeview_get_type(sym->stack_v2.symtype, FALSE),
1304 terminate_string(&sym->stack_v2.p_name));
1307 symt_add_func_local(msc_dbg->module, curr_func, 0, sym->stack_v3.offset,
1308 block, codeview_get_type(sym->stack_v3.symtype, FALSE),
1309 sym->stack_v3.name);
1313 symt_add_func_local(msc_dbg->module, curr_func, 0, sym->register_v1.reg,
1314 block, codeview_get_type(sym->register_v1.type, FALSE),
1315 terminate_string(&sym->register_v1.p_name));
1318 symt_add_func_local(msc_dbg->module, curr_func, 0, sym->register_v2.reg,
1319 block, codeview_get_type(sym->register_v2.type, FALSE),
1320 terminate_string(&sym->register_v2.p_name));
1324 block = symt_open_func_block(msc_dbg->module, curr_func, block,
1325 codeview_get_address(msc_dbg, sym->block_v1.segment, sym->block_v1.offset),
1326 sym->block_v1.length);
1329 block = symt_open_func_block(msc_dbg->module, curr_func, block,
1330 codeview_get_address(msc_dbg, sym->block_v3.segment, sym->block_v3.offset),
1331 sym->block_v3.length);
1337 block = symt_close_func_block(msc_dbg->module, curr_func, block, 0);
1341 symt_normalize_function(msc_dbg->module, curr_func);
1346 /* FIXME: we should use this as a compiland, instead of guessing it on the fly */
1347 case S_COMPILAND_V1:
1348 TRACE("S-Compiland-V1e %x %s\n",
1349 sym->compiland_v1.unknown,
1350 terminate_string(&sym->compiland_v1.p_name));
1353 case S_COMPILAND_V2:
1354 TRACE("S-Compiland-V2 %s\n",
1355 terminate_string(&sym->compiland_v2.p_name));
1356 if (TRACE_ON(dbghelp_msc))
1358 const char* ptr1 = sym->compiland_v2.p_name.name + sym->compiland_v2.p_name.namelen;
1362 ptr2 = ptr1 + strlen(ptr1) + 1;
1363 TRACE("\t%s => %s\n", ptr1, ptr2);
1364 ptr1 = ptr2 + strlen(ptr2) + 1;
1368 case S_COMPILAND_V3:
1369 TRACE("S-Compiland-V3 %s\n", sym->compiland_v3.name);
1370 if (TRACE_ON(dbghelp_msc))
1372 const char* ptr1 = sym->compiland_v3.name + strlen(sym->compiland_v3.name);
1376 ptr2 = ptr1 + strlen(ptr1) + 1;
1377 TRACE("\t%s => %s\n", ptr1, ptr2);
1378 ptr1 = ptr2 + strlen(ptr2) + 1;
1384 TRACE("S-ObjName %.*s\n", ((const BYTE*)sym)[8], (const BYTE*)sym + 9);
1390 symt_add_function_point(msc_dbg->module, curr_func, SymTagLabel,
1391 codeview_get_address(msc_dbg, sym->label_v1.segment, sym->label_v1.offset) - curr_func->address,
1392 terminate_string(&sym->label_v1.p_name));
1395 FIXME("No current function for label %s\n",
1396 terminate_string(&sym->label_v1.p_name));
1401 symt_add_function_point(msc_dbg->module, curr_func, SymTagLabel,
1402 codeview_get_address(msc_dbg, sym->label_v3.segment, sym->label_v3.offset) - curr_func->address,
1403 sym->label_v3.name);
1406 FIXME("No current function for label %s\n", sym->label_v3.name);
1412 const struct p_string* name;
1416 vlen = numeric_leaf(&val, &sym->constant_v1.cvalue);
1417 name = (const struct p_string*)((const char*)&sym->constant_v1.cvalue + vlen);
1418 se = codeview_get_type(sym->constant_v1.type, FALSE);
1420 else if (se->tag == SymTagEnum) x = ((struct symt_enum*)se)->name;
1423 TRACE("S-Constant-V1 %u %s %x (%s)\n",
1424 val, terminate_string(name), sym->constant_v1.type, x);
1425 /* FIXME: we should add this as a constant value */
1431 const struct p_string* name;
1435 vlen = numeric_leaf(&val, &sym->constant_v2.cvalue);
1436 name = (const struct p_string*)((const char*)&sym->constant_v2.cvalue + vlen);
1437 se = codeview_get_type(sym->constant_v2.type, FALSE);
1439 else if (se->tag == SymTagEnum) x = ((struct symt_enum*)se)->name;
1442 TRACE("S-Constant-V2 %u %s %x (%s)\n",
1443 val, terminate_string(name), sym->constant_v2.type, x);
1444 /* FIXME: we should add this as a constant value */
1454 vlen = numeric_leaf(&val, &sym->constant_v3.cvalue);
1455 name = (const char*)&sym->constant_v3.cvalue + vlen;
1456 se = codeview_get_type(sym->constant_v3.type, FALSE);
1458 else if (se->tag == SymTagEnum) x = ((struct symt_enum*)se)->name;
1461 TRACE("S-Constant-V3 %u %s %x (%s)\n",
1462 val, name, sym->constant_v3.type, x);
1463 /* FIXME: we should add this as a constant value */
1468 if (sym->udt_v1.type)
1470 if ((symt = codeview_get_type(sym->udt_v1.type, FALSE)))
1471 symt_new_typedef(msc_dbg->module, symt,
1472 terminate_string(&sym->udt_v1.p_name));
1474 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1475 terminate_string(&sym->udt_v1.p_name), sym->udt_v1.type);
1479 if (sym->udt_v2.type)
1481 if ((symt = codeview_get_type(sym->udt_v2.type, FALSE)))
1482 symt_new_typedef(msc_dbg->module, symt,
1483 terminate_string(&sym->udt_v2.p_name));
1485 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1486 terminate_string(&sym->udt_v2.p_name), sym->udt_v2.type);
1490 if (sym->udt_v3.type)
1492 if ((symt = codeview_get_type(sym->udt_v3.type, FALSE)))
1493 symt_new_typedef(msc_dbg->module, symt, sym->udt_v3.name);
1495 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1496 sym->udt_v3.name, sym->udt_v3.type);
1501 * These are special, in that they are always followed by an
1502 * additional length-prefixed string which is *not* included
1503 * into the symbol length count. We need to skip it.
1508 name = (const char*)sym + length;
1509 length += (*name + 1 + 3) & ~3;
1513 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1515 flt = codeview_get_linetab(linetab, sym->data_v3.segment, sym->data_v3.offset);
1516 symt_new_public(msc_dbg->module,
1517 flt ? flt->compiland : NULL,
1519 codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset),
1520 0, FALSE /* FIXME */, FALSE);
1523 case S_PUB_FUNC1_V3:
1524 case S_PUB_FUNC2_V3: /* using a data_v3 isn't what we'd expect */
1525 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1527 flt = codeview_get_linetab(linetab, sym->data_v3.segment, sym->data_v3.offset);
1528 symt_new_public(msc_dbg->module,
1529 flt ? flt->compiland : NULL,
1531 codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset),
1532 0, TRUE /* FIXME */, TRUE);
1536 case S_MSTOOL_V3: /* just to silence a few warnings */
1540 FIXME("Unsupported symbol id %x\n", sym->generic.id);
1541 dump(sym, 2 + sym->generic.len);
1546 if (curr_func) symt_normalize_function(msc_dbg->module, curr_func);
1548 HeapFree(GetProcessHeap(), 0, linetab);
1552 /*========================================================================
1558 const char* filename;
1559 enum {PDB_JG, PDB_DS} kind;
1565 struct PDB_JG_TOC* toc;
1570 struct PDB_DS_TOC* toc;
1575 static void* pdb_jg_read(const struct PDB_JG_HEADER* pdb, const WORD* block_list,
1581 if (!size) return NULL;
1583 num_blocks = (size + pdb->block_size - 1) / pdb->block_size;
1584 buffer = HeapAlloc(GetProcessHeap(), 0, num_blocks * pdb->block_size);
1586 for (i = 0; i < num_blocks; i++)
1587 memcpy(buffer + i * pdb->block_size,
1588 (const char*)pdb + block_list[i] * pdb->block_size, pdb->block_size);
1593 static void* pdb_ds_read(const struct PDB_DS_HEADER* pdb, const DWORD* block_list,
1599 if (!size) return NULL;
1601 num_blocks = (size + pdb->block_size - 1) / pdb->block_size;
1602 buffer = HeapAlloc(GetProcessHeap(), 0, num_blocks * pdb->block_size);
1604 for (i = 0; i < num_blocks; i++)
1605 memcpy(buffer + i * pdb->block_size,
1606 (const char*)pdb + block_list[i] * pdb->block_size, pdb->block_size);
1611 static void* pdb_read_jg_file(const struct PDB_JG_HEADER* pdb,
1612 const struct PDB_JG_TOC* toc, DWORD file_nr)
1614 const WORD* block_list;
1617 if (!toc || file_nr >= toc->num_files) return NULL;
1619 block_list = (const WORD*) &toc->file[toc->num_files];
1620 for (i = 0; i < file_nr; i++)
1621 block_list += (toc->file[i].size + pdb->block_size - 1) / pdb->block_size;
1623 return pdb_jg_read(pdb, block_list, toc->file[file_nr].size);
1626 static void* pdb_read_ds_file(const struct PDB_DS_HEADER* pdb,
1627 const struct PDB_DS_TOC* toc, DWORD file_nr)
1629 const DWORD* block_list;
1632 if (!toc || file_nr >= toc->num_files) return NULL;
1634 if (toc->file_size[file_nr] == 0 || toc->file_size[file_nr] == 0xFFFFFFFF)
1636 FIXME(">>> requesting NULL stream (%lu)\n", file_nr);
1639 block_list = &toc->file_size[toc->num_files];
1640 for (i = 0; i < file_nr; i++)
1641 block_list += (toc->file_size[i] + pdb->block_size - 1) / pdb->block_size;
1643 return pdb_ds_read(pdb, block_list, toc->file_size[file_nr]);
1646 static void* pdb_read_file(const BYTE* image, const struct pdb_lookup* pdb_lookup,
1649 switch (pdb_lookup->kind)
1652 return pdb_read_jg_file((const struct PDB_JG_HEADER*)image,
1653 pdb_lookup->u.jg.toc, file_nr);
1655 return pdb_read_ds_file((const struct PDB_DS_HEADER*)image,
1656 pdb_lookup->u.ds.toc, file_nr);
1661 static unsigned pdb_get_file_size(const struct pdb_lookup* pdb_lookup, DWORD file_nr)
1663 switch (pdb_lookup->kind)
1665 case PDB_JG: return pdb_lookup->u.jg.toc->file[file_nr].size;
1666 case PDB_DS: return pdb_lookup->u.ds.toc->file_size[file_nr];
1671 static void pdb_free(void* buffer)
1673 HeapFree(GetProcessHeap(), 0, buffer);
1676 static void pdb_free_lookup(const struct pdb_lookup* pdb_lookup)
1678 switch (pdb_lookup->kind)
1681 if (pdb_lookup->u.jg.toc) pdb_free(pdb_lookup->u.jg.toc);
1684 if (pdb_lookup->u.ds.toc) pdb_free(pdb_lookup->u.ds.toc);
1689 static void pdb_convert_types_header(PDB_TYPES* types, const BYTE* image)
1691 memset(types, 0, sizeof(PDB_TYPES));
1694 if (*(const DWORD*)image < 19960000) /* FIXME: correct version? */
1696 /* Old version of the types record header */
1697 const PDB_TYPES_OLD* old = (const PDB_TYPES_OLD*)image;
1698 types->version = old->version;
1699 types->type_offset = sizeof(PDB_TYPES_OLD);
1700 types->type_size = old->type_size;
1701 types->first_index = old->first_index;
1702 types->last_index = old->last_index;
1703 types->file = old->file;
1707 /* New version of the types record header */
1708 *types = *(const PDB_TYPES*)image;
1712 static void pdb_convert_symbols_header(PDB_SYMBOLS* symbols,
1713 int* header_size, const BYTE* image)
1715 memset(symbols, 0, sizeof(PDB_SYMBOLS));
1718 if (*(const DWORD*)image != 0xffffffff)
1720 /* Old version of the symbols record header */
1721 const PDB_SYMBOLS_OLD* old = (const PDB_SYMBOLS_OLD*)image;
1722 symbols->version = 0;
1723 symbols->module_size = old->module_size;
1724 symbols->offset_size = old->offset_size;
1725 symbols->hash_size = old->hash_size;
1726 symbols->srcmodule_size = old->srcmodule_size;
1727 symbols->pdbimport_size = 0;
1728 symbols->hash1_file = old->hash1_file;
1729 symbols->hash2_file = old->hash2_file;
1730 symbols->gsym_file = old->gsym_file;
1732 *header_size = sizeof(PDB_SYMBOLS_OLD);
1736 /* New version of the symbols record header */
1737 *symbols = *(const PDB_SYMBOLS*)image;
1738 *header_size = sizeof(PDB_SYMBOLS);
1742 static void pdb_convert_symbol_file(const PDB_SYMBOLS* symbols,
1743 PDB_SYMBOL_FILE_EX* sfile,
1744 unsigned* size, const void* image)
1747 if (symbols->version < 19970000)
1749 const PDB_SYMBOL_FILE *sym_file = (const PDB_SYMBOL_FILE*)image;
1750 memset(sfile, 0, sizeof(*sfile));
1751 sfile->file = sym_file->file;
1752 sfile->range.index = sym_file->range.index;
1753 sfile->symbol_size = sym_file->symbol_size;
1754 sfile->lineno_size = sym_file->lineno_size;
1755 *size = sizeof(PDB_SYMBOL_FILE) - 1;
1759 memcpy(sfile, image, sizeof(PDB_SYMBOL_FILE_EX));
1760 *size = sizeof(PDB_SYMBOL_FILE_EX) - 1;
1764 static BOOL CALLBACK pdb_match(char* file, void* user)
1766 /* accept first file */
1770 static HANDLE open_pdb_file(const struct process* pcs, const char* filename)
1773 char dbg_file_path[MAX_PATH];
1775 h = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL,
1776 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1777 /* FIXME: should give more bits on the file to look at */
1778 if (h == INVALID_HANDLE_VALUE &&
1779 SymFindFileInPath(pcs->handle, NULL, (char*)filename, NULL, 0, 0, 0,
1780 dbg_file_path, pdb_match, NULL))
1782 h = CreateFileA(dbg_file_path, GENERIC_READ, FILE_SHARE_READ, NULL,
1783 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1785 return (h == INVALID_HANDLE_VALUE) ? NULL : h;
1788 static void pdb_process_types(const struct msc_debug_info* msc_dbg,
1789 const char* image, struct pdb_lookup* pdb_lookup)
1791 char* types_image = NULL;
1793 types_image = pdb_read_file(image, pdb_lookup, 2);
1797 pdb_convert_types_header(&types, types_image);
1799 /* Check for unknown versions */
1800 switch (types.version)
1802 case 19950410: /* VC 4.0 */
1804 case 19961031: /* VC 5.0 / 6.0 */
1808 ERR("-Unknown type info version %ld\n", types.version);
1811 /* Read type table */
1812 codeview_parse_type_table(msc_dbg->module, types_image + types.type_offset,
1814 pdb_free(types_image);
1818 static const char PDB_JG_IDENT[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
1819 static const char PDB_DS_IDENT[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
1821 static BOOL pdb_init(struct pdb_lookup* pdb_lookup, const char* image)
1823 /* check the file header, and if ok, load the TOC */
1824 TRACE("PDB(%s): %.40s\n", pdb_lookup->filename, debugstr_an(image, 40));
1825 switch (pdb_lookup->kind)
1828 pdb_lookup->u.jg.toc = NULL;
1829 if (memcmp(image, PDB_JG_IDENT, sizeof(PDB_JG_IDENT)))
1831 FIXME("Couldn't match JG header\n");
1836 const struct PDB_JG_HEADER* pdb = (const struct PDB_JG_HEADER*)image;
1837 struct PDB_JG_ROOT* root;
1839 pdb_lookup->u.jg.toc = pdb_jg_read(pdb, pdb->toc_block, pdb->toc.size);
1840 root = pdb_read_jg_file(pdb, pdb_lookup->u.jg.toc, 1);
1843 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup->filename);
1846 switch (root->Version)
1848 case 19950623: /* VC 4.0 */
1850 case 19960307: /* VC 5.0 */
1851 case 19970604: /* VC 6.0 */
1854 ERR("-Unknown root block version %ld\n", root->Version);
1856 /* Check .PDB time stamp */
1857 if (root->TimeDateStamp != pdb_lookup->u.jg.timestamp)
1859 ERR("-Wrong time stamp of .PDB file %s (0x%08lx, 0x%08lx)\n",
1860 pdb_lookup->filename, root->TimeDateStamp,
1861 pdb_lookup->u.jg.timestamp);
1867 pdb_lookup->u.ds.toc = NULL;
1868 if (memcmp(image, PDB_DS_IDENT, sizeof(PDB_DS_IDENT)))
1870 FIXME("Couldn't match DS header\n");
1875 const struct PDB_DS_HEADER* pdb = (const struct PDB_DS_HEADER*)image;
1876 struct PDB_DS_ROOT* root;
1878 pdb_lookup->u.ds.toc =
1880 (const DWORD*)((const char*)pdb + pdb->toc_page * pdb->block_size),
1882 root = pdb_read_ds_file(pdb, pdb_lookup->u.ds.toc, 1);
1885 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup->filename);
1888 switch (root->Version)
1893 ERR("-Unknown root block version %ld\n", root->Version);
1895 /* Check .PDB time stamp */
1896 if (memcmp(&root->guid, &pdb_lookup->u.ds.guid, sizeof(GUID)))
1898 ERR("-Wrong GUID of .PDB file %s (%s, %s)\n",
1899 pdb_lookup->filename,
1900 wine_dbgstr_guid(&root->guid),
1901 wine_dbgstr_guid(&pdb_lookup->u.ds.guid));
1908 if (0) /* some tool to dump the internal files from a PDB file */
1912 switch (pdb_lookup->kind)
1914 case PDB_JG: num_files = pdb_lookup->u.jg.toc->num_files; break;
1915 case PDB_DS: num_files = pdb_lookup->u.ds.toc->num_files; break;
1918 for (i = 1; i < num_files; i++)
1920 unsigned char* x = pdb_read_file(image, pdb_lookup, i);
1921 FIXME("********************** [%u]: size=%08x\n",
1922 i, pdb_get_file_size(pdb_lookup, i));
1923 dump(x, pdb_get_file_size(pdb_lookup, i));
1930 static BOOL pdb_process_internal(const struct process* pcs,
1931 const struct msc_debug_info* msc_dbg,
1932 struct pdb_lookup* pdb_lookup,
1933 unsigned module_index);
1935 static void pdb_process_symbol_imports(const struct process* pcs,
1936 const struct msc_debug_info* msc_dbg,
1937 PDB_SYMBOLS* symbols,
1938 const void* symbols_image,
1939 char* image, struct pdb_lookup* pdb_lookup,
1940 unsigned module_index)
1942 if (module_index == -1 && symbols && symbols->pdbimport_size)
1944 const PDB_SYMBOL_IMPORT*imp;
1950 imp = (const PDB_SYMBOL_IMPORT*)((const char*)symbols_image + sizeof(PDB_SYMBOLS) +
1951 symbols->module_size + symbols->offset_size +
1952 symbols->hash_size + symbols->srcmodule_size);
1953 first = (const char*)imp;
1954 last = (const char*)imp + symbols->pdbimport_size;
1955 while (imp < (const PDB_SYMBOL_IMPORT*)last)
1957 ptr = (const char*)imp + sizeof(*imp) + strlen(imp->filename);
1958 if (i >= CV_MAX_MODULES) FIXME("Out of bounds !!!\n");
1959 if (!strcasecmp(pdb_lookup->filename, imp->filename))
1961 if (module_index != -1) FIXME("Twice the entry\n");
1962 else module_index = i;
1966 struct pdb_lookup imp_pdb_lookup;
1968 imp_pdb_lookup.filename = imp->filename;
1969 imp_pdb_lookup.kind = PDB_JG;
1970 imp_pdb_lookup.u.jg.timestamp = imp->TimeDateStamp;
1971 pdb_process_internal(pcs, msc_dbg, &imp_pdb_lookup, i);
1974 imp = (const PDB_SYMBOL_IMPORT*)((const char*)first + ((ptr - (const char*)first + strlen(ptr) + 1 + 3) & ~3));
1977 cv_current_module = &cv_zmodules[(module_index == -1) ? 0 : module_index];
1978 if (cv_current_module->allowed) FIXME("Already allowed ??\n");
1979 cv_current_module->allowed = TRUE;
1980 pdb_process_types(msc_dbg, image, pdb_lookup);
1983 static BOOL pdb_process_internal(const struct process* pcs,
1984 const struct msc_debug_info* msc_dbg,
1985 struct pdb_lookup* pdb_lookup,
1986 unsigned module_index)
1989 HANDLE hFile, hMap = NULL;
1991 char* symbols_image = NULL;
1993 TRACE("Processing PDB file %s\n", pdb_lookup->filename);
1995 /* Open and map() .PDB file */
1996 if ((hFile = open_pdb_file(pcs, pdb_lookup->filename)) == NULL ||
1997 ((hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == NULL) ||
1998 ((image = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) == NULL))
2000 WARN("Unable to open .PDB file: %s\n", pdb_lookup->filename);
2003 pdb_init(pdb_lookup, image);
2005 symbols_image = pdb_read_file(image, pdb_lookup, 3);
2008 PDB_SYMBOLS symbols;
2011 int header_size = 0;
2013 pdb_convert_symbols_header(&symbols, &header_size, symbols_image);
2014 switch (symbols.version)
2016 case 0: /* VC 4.0 */
2017 case 19960307: /* VC 5.0 */
2018 case 19970606: /* VC 6.0 */
2022 ERR("-Unknown symbol info version %ld %08lx\n",
2023 symbols.version, symbols.version);
2026 pdb_process_symbol_imports(pcs, msc_dbg, &symbols, symbols_image, image, pdb_lookup, module_index);
2028 /* Read global symbol table */
2029 modimage = pdb_read_file(image, pdb_lookup, symbols.gsym_file);
2032 codeview_snarf(msc_dbg, modimage, 0,
2033 pdb_get_file_size(pdb_lookup, symbols.gsym_file), NULL);
2038 /* Read per-module symbol / linenumber tables */
2039 file = symbols_image + header_size;
2040 while (file - symbols_image < header_size + symbols.module_size)
2042 PDB_SYMBOL_FILE_EX sfile;
2043 const char* file_name;
2046 HeapValidate(GetProcessHeap(), 0, NULL);
2047 pdb_convert_symbol_file(&symbols, &sfile, &size, file);
2049 modimage = pdb_read_file(image, pdb_lookup, sfile.file);
2052 struct codeview_linetab* linetab = NULL;
2054 if (sfile.lineno_size)
2055 linetab = codeview_snarf_linetab(msc_dbg->module,
2056 modimage + sfile.symbol_size,
2058 pdb_lookup->kind == PDB_JG);
2060 if (sfile.symbol_size)
2061 codeview_snarf(msc_dbg, modimage, sizeof(DWORD),
2062 sfile.symbol_size, linetab);
2066 file_name = (const char*)file + size;
2067 file_name += strlen(file_name) + 1;
2068 file = (char*)((DWORD)(file_name + strlen(file_name) + 1 + 3) & ~3);
2072 pdb_process_symbol_imports(pcs, msc_dbg, NULL, NULL, image, pdb_lookup,
2074 msc_dbg->module->module.SymType = SymCv;
2079 if (symbols_image) pdb_free(symbols_image);
2080 pdb_free_lookup(pdb_lookup);
2082 if (image) UnmapViewOfFile(image);
2083 if (hMap) CloseHandle(hMap);
2084 if (hFile) CloseHandle(hFile);
2089 static BOOL pdb_process_file(const struct process* pcs,
2090 const struct msc_debug_info* msc_dbg,
2091 struct pdb_lookup* pdb_lookup)
2095 memset(cv_zmodules, 0, sizeof(cv_zmodules));
2096 codeview_init_basic_types(msc_dbg->module);
2097 ret = pdb_process_internal(pcs, msc_dbg, pdb_lookup, -1);
2098 codeview_clear_type_table();
2102 /*========================================================================
2103 * Process CodeView debug information.
2106 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
2107 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
2108 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
2109 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
2110 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
2112 typedef struct _CODEVIEW_HEADER_NBxx
2116 } CODEVIEW_HEADER_NBxx,* PCODEVIEW_HEADER_NBxx;
2118 typedef struct _CODEVIEW_HEADER_RSDS
2124 } CODEVIEW_HEADER_RSDS,* PCODEVIEW_HEADER_RSDS;
2126 typedef struct _CODEVIEW_PDB_DATA
2131 } CODEVIEW_PDB_DATA, *PCODEVIEW_PDB_DATA;
2133 typedef struct _CV_DIRECTORY_HEADER
2140 } CV_DIRECTORY_HEADER, *PCV_DIRECTORY_HEADER;
2142 typedef struct _CV_DIRECTORY_ENTRY
2148 } CV_DIRECTORY_ENTRY, *PCV_DIRECTORY_ENTRY;
2150 #define sstAlignSym 0x125
2151 #define sstSrcModule 0x127
2153 static BOOL codeview_process_info(const struct process* pcs,
2154 const struct msc_debug_info* msc_dbg)
2156 const CODEVIEW_HEADER_NBxx* cv = (const CODEVIEW_HEADER_NBxx*)msc_dbg->root;
2158 struct pdb_lookup pdb_lookup;
2160 TRACE("Processing signature %.4s\n", (const char*)&cv->dwSignature);
2162 switch (cv->dwSignature)
2164 case CODEVIEW_NB09_SIG:
2165 case CODEVIEW_NB11_SIG:
2167 const CV_DIRECTORY_HEADER* hdr = (const CV_DIRECTORY_HEADER*)(msc_dbg->root + cv->lfoDirectory);
2168 const CV_DIRECTORY_ENTRY* ent;
2169 const CV_DIRECTORY_ENTRY* prev;
2170 const CV_DIRECTORY_ENTRY* next;
2173 codeview_init_basic_types(msc_dbg->module);
2174 ent = (const CV_DIRECTORY_ENTRY*)((const BYTE*)hdr + hdr->cbDirHeader);
2175 for (i = 0; i < hdr->cDir; i++, ent = next)
2177 next = (i == hdr->cDir-1)? NULL :
2178 (const CV_DIRECTORY_ENTRY*)((const BYTE*)ent + hdr->cbDirEntry);
2179 prev = (i == 0)? NULL :
2180 (const CV_DIRECTORY_ENTRY*)((const BYTE*)ent - hdr->cbDirEntry);
2182 if (ent->subsection == sstAlignSym)
2185 * Check the next and previous entry. If either is a
2186 * sstSrcModule, it contains the line number info for
2189 * FIXME: This is not a general solution!
2191 struct codeview_linetab* linetab = NULL;
2193 if (next && next->iMod == ent->iMod &&
2194 next->subsection == sstSrcModule)
2195 linetab = codeview_snarf_linetab(msc_dbg->module,
2196 msc_dbg->root + next->lfo, next->cb,
2199 if (prev && prev->iMod == ent->iMod &&
2200 prev->subsection == sstSrcModule)
2201 linetab = codeview_snarf_linetab(msc_dbg->module,
2202 msc_dbg->root + prev->lfo, prev->cb,
2205 codeview_snarf(msc_dbg, msc_dbg->root + ent->lfo, sizeof(DWORD),
2210 msc_dbg->module->module.SymType = SymCv;
2215 case CODEVIEW_NB10_SIG:
2217 const CODEVIEW_PDB_DATA* pdb = (const CODEVIEW_PDB_DATA*)(cv + 1);
2218 pdb_lookup.filename = pdb->name;
2219 pdb_lookup.kind = PDB_JG;
2220 pdb_lookup.u.jg.timestamp = pdb->timestamp;
2221 pdb_lookup.u.jg.toc = NULL;
2222 ret = pdb_process_file(pcs, msc_dbg, &pdb_lookup);
2225 case CODEVIEW_RSDS_SIG:
2227 const CODEVIEW_HEADER_RSDS* rsds = (const CODEVIEW_HEADER_RSDS*)msc_dbg->root;
2229 TRACE("Got RSDS type of PDB file: guid=%s unk=%08lx name=%s\n",
2230 wine_dbgstr_guid(&rsds->guid), rsds->unknown, rsds->name);
2231 pdb_lookup.filename = rsds->name;
2232 pdb_lookup.kind = PDB_DS;
2233 pdb_lookup.u.ds.guid = rsds->guid;
2234 pdb_lookup.u.ds.toc = NULL;
2235 ret = pdb_process_file(pcs, msc_dbg, &pdb_lookup);
2239 ERR("Unknown CODEVIEW signature %08lX in module %s\n",
2240 cv->dwSignature, msc_dbg->module->module.ModuleName);
2247 /*========================================================================
2248 * Process debug directory.
2250 BOOL pe_load_debug_directory(const struct process* pcs, struct module* module,
2251 const BYTE* mapping,
2252 const IMAGE_SECTION_HEADER* sectp, DWORD nsect,
2253 const IMAGE_DEBUG_DIRECTORY* dbg, int nDbg)
2257 struct msc_debug_info msc_dbg;
2259 msc_dbg.module = module;
2260 msc_dbg.nsect = nsect;
2261 msc_dbg.sectp = sectp;
2263 msc_dbg.omapp = NULL;
2269 /* First, watch out for OMAP data */
2270 for (i = 0; i < nDbg; i++)
2272 if (dbg[i].Type == IMAGE_DEBUG_TYPE_OMAP_FROM_SRC)
2274 msc_dbg.nomap = dbg[i].SizeOfData / sizeof(OMAP_DATA);
2275 msc_dbg.omapp = (const OMAP_DATA*)(mapping + dbg[i].PointerToRawData);
2280 /* Now, try to parse CodeView debug info */
2281 for (i = 0; i < nDbg; i++)
2283 if (dbg[i].Type == IMAGE_DEBUG_TYPE_CODEVIEW)
2285 msc_dbg.root = mapping + dbg[i].PointerToRawData;
2286 if ((ret = codeview_process_info(pcs, &msc_dbg))) goto done;
2290 /* If not found, try to parse COFF debug info */
2291 for (i = 0; i < nDbg; i++)
2293 if (dbg[i].Type == IMAGE_DEBUG_TYPE_COFF)
2295 msc_dbg.root = mapping + dbg[i].PointerToRawData;
2296 if ((ret = coff_process_info(&msc_dbg))) goto done;
2300 /* FIXME: this should be supported... this is the debug information for
2301 * functions compiled without a frame pointer (FPO = frame pointer omission)
2302 * the associated data helps finding out the relevant information
2304 for (i = 0; i < nDbg; i++)
2305 if (dbg[i].Type == IMAGE_DEBUG_TYPE_FPO)
2306 FIXME("This guy has FPO information\n");
2310 #define FRAME_TRAP 1
2313 typedef struct _FPO_DATA
2315 DWORD ulOffStart; /* offset 1st byte of function code */
2316 DWORD cbProcSize; /* # bytes in function */
2317 DWORD cdwLocals; /* # bytes in locals/4 */
2318 WORD cdwParams; /* # bytes in params/4 */
2320 WORD cbProlog : 8; /* # bytes in prolog */
2321 WORD cbRegs : 3; /* # regs saved */
2322 WORD fHasSEH : 1; /* TRUE if SEH in func */
2323 WORD fUseBP : 1; /* TRUE if EBP has been allocated */
2324 WORD reserved : 1; /* reserved for future use */
2325 WORD cbFrame : 2; /* frame type */
2330 __EXCEPT(page_fault)
2332 ERR("Got a page fault while loading symbols\n");