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-2006, 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
54 #include "wine/exception.h"
55 #include "wine/debug.h"
56 #include "dbghelp_private.h"
57 #include "wine/mscvpdb.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp_msc);
61 #define MAX_PATHNAME_LEN 1024
63 /*========================================================================
64 * Debug file access helper routines
67 static void dump(const void* ptr, unsigned len)
71 const char* hexof = "0123456789abcdef";
72 const BYTE* x = (const BYTE*)ptr;
74 for (i = 0; i < len; i += 16)
76 sprintf(msg, "%08x: ", i);
77 memset(msg + 10, ' ', 3 * 16 + 1 + 16);
78 for (j = 0; j < min(16, len - i); j++)
80 msg[10 + 3 * j + 0] = hexof[x[i + j] >> 4];
81 msg[10 + 3 * j + 1] = hexof[x[i + j] & 15];
82 msg[10 + 3 * j + 2] = ' ';
83 msg[10 + 3 * 16 + 1 + j] = (x[i + j] >= 0x20 && x[i + j] < 0x7f) ?
86 msg[10 + 3 * 16] = ' ';
87 msg[10 + 3 * 16 + 1 + 16] = '\0';
92 /*========================================================================
93 * Process CodeView type information.
96 #define MAX_BUILTIN_TYPES 0x0480
97 #define FIRST_DEFINABLE_TYPE 0x1000
99 static struct symt* cv_basic_types[MAX_BUILTIN_TYPES];
101 struct cv_defined_module
104 unsigned int num_defined_types;
105 struct symt** defined_types;
107 /* FIXME: don't make it static */
108 #define CV_MAX_MODULES 32
109 static struct cv_defined_module cv_zmodules[CV_MAX_MODULES];
110 static struct cv_defined_module*cv_current_module;
112 static void codeview_init_basic_types(struct module* module)
115 * These are the common builtin types that are used by VC++.
117 cv_basic_types[T_NOTYPE] = NULL;
118 cv_basic_types[T_ABS] = NULL;
119 cv_basic_types[T_VOID] = &symt_new_basic(module, btVoid, "void", 0)->symt;
120 cv_basic_types[T_CHAR] = &symt_new_basic(module, btChar, "char", 1)->symt;
121 cv_basic_types[T_SHORT] = &symt_new_basic(module, btInt, "short int", 2)->symt;
122 cv_basic_types[T_LONG] = &symt_new_basic(module, btInt, "long int", 4)->symt;
123 cv_basic_types[T_QUAD] = &symt_new_basic(module, btInt, "long long int", 8)->symt;
124 cv_basic_types[T_UCHAR] = &symt_new_basic(module, btUInt, "unsigned char", 1)->symt;
125 cv_basic_types[T_USHORT] = &symt_new_basic(module, btUInt, "unsigned short", 2)->symt;
126 cv_basic_types[T_ULONG] = &symt_new_basic(module, btUInt, "unsigned long", 4)->symt;
127 cv_basic_types[T_UQUAD] = &symt_new_basic(module, btUInt, "unsigned long long", 8)->symt;
128 cv_basic_types[T_REAL32] = &symt_new_basic(module, btFloat, "float", 4)->symt;
129 cv_basic_types[T_REAL64] = &symt_new_basic(module, btFloat, "double", 8)->symt;
130 cv_basic_types[T_RCHAR] = &symt_new_basic(module, btInt, "signed char", 1)->symt;
131 cv_basic_types[T_WCHAR] = &symt_new_basic(module, btWChar, "wchar_t", 2)->symt;
132 cv_basic_types[T_INT4] = &symt_new_basic(module, btInt, "INT4", 4)->symt;
133 cv_basic_types[T_UINT4] = &symt_new_basic(module, btUInt, "UINT4", 4)->symt;
135 cv_basic_types[T_32PVOID] = &symt_new_pointer(module, cv_basic_types[T_VOID])->symt;
136 cv_basic_types[T_32PCHAR] = &symt_new_pointer(module, cv_basic_types[T_CHAR])->symt;
137 cv_basic_types[T_32PSHORT] = &symt_new_pointer(module, cv_basic_types[T_SHORT])->symt;
138 cv_basic_types[T_32PLONG] = &symt_new_pointer(module, cv_basic_types[T_LONG])->symt;
139 cv_basic_types[T_32PQUAD] = &symt_new_pointer(module, cv_basic_types[T_QUAD])->symt;
140 cv_basic_types[T_32PUCHAR] = &symt_new_pointer(module, cv_basic_types[T_UCHAR])->symt;
141 cv_basic_types[T_32PUSHORT] = &symt_new_pointer(module, cv_basic_types[T_USHORT])->symt;
142 cv_basic_types[T_32PULONG] = &symt_new_pointer(module, cv_basic_types[T_ULONG])->symt;
143 cv_basic_types[T_32PUQUAD] = &symt_new_pointer(module, cv_basic_types[T_UQUAD])->symt;
144 cv_basic_types[T_32PREAL32] = &symt_new_pointer(module, cv_basic_types[T_REAL32])->symt;
145 cv_basic_types[T_32PREAL64] = &symt_new_pointer(module, cv_basic_types[T_REAL64])->symt;
146 cv_basic_types[T_32PRCHAR] = &symt_new_pointer(module, cv_basic_types[T_RCHAR])->symt;
147 cv_basic_types[T_32PWCHAR] = &symt_new_pointer(module, cv_basic_types[T_WCHAR])->symt;
148 cv_basic_types[T_32PINT4] = &symt_new_pointer(module, cv_basic_types[T_INT4])->symt;
149 cv_basic_types[T_32PUINT4] = &symt_new_pointer(module, cv_basic_types[T_UINT4])->symt;
152 static int numeric_leaf(int* value, const unsigned short int* leaf)
154 unsigned short int type = *leaf++;
157 if (type < LF_NUMERIC)
167 *value = *(const char*)leaf;
172 *value = *(const short*)leaf;
177 *value = *(const unsigned short*)leaf;
182 *value = *(const int*)leaf;
187 *value = *(const unsigned int*)leaf;
192 FIXME("Unsupported numeric leaf type %04x\n", type);
194 *value = 0; /* FIXME */
198 FIXME("Unsupported numeric leaf type %04x\n", type);
200 *value = 0; /* FIXME */
204 FIXME("Unsupported numeric leaf type %04x\n", type);
206 *value = 0; /* FIXME */
210 FIXME("Unsupported numeric leaf type %04x\n", type);
212 *value = 0; /* FIXME */
216 FIXME("Unsupported numeric leaf type %04x\n", type);
218 *value = 0; /* FIXME */
222 FIXME("Unsupported numeric leaf type %04x\n", type);
224 *value = 0; /* FIXME */
228 FIXME("Unsupported numeric leaf type %04x\n", type);
230 *value = 0; /* FIXME */
234 FIXME("Unsupported numeric leaf type %04x\n", type);
236 *value = 0; /* FIXME */
240 FIXME("Unsupported numeric leaf type %04x\n", type);
242 *value = 0; /* FIXME */
246 FIXME("Unsupported numeric leaf type %04x\n", type);
248 *value = 0; /* FIXME */
252 FIXME("Unsupported numeric leaf type %04x\n", type);
254 *value = 0; /* FIXME */
258 FIXME("Unknown numeric leaf type %04x\n", type);
267 /* convert a pascal string (as stored in debug information) into
268 * a C string (null terminated).
270 static const char* terminate_string(const struct p_string* p_name)
272 static char symname[256];
274 memcpy(symname, p_name->name, p_name->namelen);
275 symname[p_name->namelen] = '\0';
277 return (!*symname || strcmp(symname, "__unnamed") == 0) ? NULL : symname;
280 static struct symt* codeview_get_type(unsigned int typeno, BOOL quiet)
282 struct symt* symt = NULL;
285 * Convert Codeview type numbers into something we can grok internally.
286 * Numbers < FIRST_DEFINABLE_TYPE are all fixed builtin types.
287 * Numbers from FIRST_DEFINABLE_TYPE and up are all user defined (structs, etc).
289 if (typeno < FIRST_DEFINABLE_TYPE)
291 if (typeno < MAX_BUILTIN_TYPES)
292 symt = cv_basic_types[typeno];
296 unsigned mod_index = typeno >> 24;
297 unsigned mod_typeno = typeno & 0x00FFFFFF;
298 struct cv_defined_module* mod;
300 mod = (mod_index == 0) ? cv_current_module : &cv_zmodules[mod_index];
302 if (mod_index >= CV_MAX_MODULES || !mod->allowed)
303 FIXME("Module of index %d isn't loaded yet (%x)\n", mod_index, typeno);
306 if (mod_typeno - FIRST_DEFINABLE_TYPE < mod->num_defined_types)
307 symt = mod->defined_types[mod_typeno - FIRST_DEFINABLE_TYPE];
310 if (!quiet && !symt && typeno) FIXME("Returning NULL symt for type-id %x\n", typeno);
314 struct codeview_type_parse
316 struct module* module;
322 static inline const void* codeview_jump_to_type(const struct codeview_type_parse* ctp, DWORD idx)
324 if (idx < FIRST_DEFINABLE_TYPE) return NULL;
325 idx -= FIRST_DEFINABLE_TYPE;
326 return (idx >= ctp->num) ? NULL : (ctp->table + ctp->offset[idx]);
329 static int codeview_add_type(unsigned int typeno, struct symt* dt)
331 if (typeno < FIRST_DEFINABLE_TYPE)
332 FIXME("What the heck\n");
333 if (!cv_current_module)
335 FIXME("Adding %x to non allowed module\n", typeno);
338 if ((typeno >> 24) != 0)
339 FIXME("No module index while inserting type-id assumption is wrong %x\n",
341 while (typeno - FIRST_DEFINABLE_TYPE >= cv_current_module->num_defined_types)
343 cv_current_module->num_defined_types += 0x100;
344 if (cv_current_module->defined_types)
345 cv_current_module->defined_types = (struct symt**)
346 HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
347 cv_current_module->defined_types,
348 cv_current_module->num_defined_types * sizeof(struct symt*));
350 cv_current_module->defined_types = (struct symt**)
351 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
352 cv_current_module->num_defined_types * sizeof(struct symt*));
354 if (cv_current_module->defined_types == NULL) return FALSE;
356 if (cv_current_module->defined_types[typeno - FIRST_DEFINABLE_TYPE])
358 if (cv_current_module->defined_types[typeno - FIRST_DEFINABLE_TYPE] != dt)
359 FIXME("Overwritting at %x\n", typeno);
361 cv_current_module->defined_types[typeno - FIRST_DEFINABLE_TYPE] = dt;
365 static void codeview_clear_type_table(void)
369 for (i = 0; i < CV_MAX_MODULES; i++)
371 if (cv_zmodules[i].allowed)
372 HeapFree(GetProcessHeap(), 0, cv_zmodules[i].defined_types);
373 cv_zmodules[i].allowed = FALSE;
374 cv_zmodules[i].defined_types = NULL;
375 cv_zmodules[i].num_defined_types = 0;
377 cv_current_module = NULL;
380 static struct symt* codeview_parse_one_type(struct codeview_type_parse* ctp,
382 const union codeview_type* type, BOOL details);
384 static void* codeview_cast_symt(struct symt* symt, enum SymTagEnum tag)
386 if (symt->tag != tag)
388 FIXME("Bad tag. Expected %d, but got %d\n", tag, symt->tag);
394 static struct symt* codeview_fetch_type(struct codeview_type_parse* ctp,
398 const union codeview_type* p;
400 if (!typeno) return NULL;
401 if ((symt = codeview_get_type(typeno, TRUE))) return symt;
403 /* forward declaration */
404 if (!(p = codeview_jump_to_type(ctp, typeno)))
406 FIXME("Cannot locate type %x\n", typeno);
409 symt = codeview_parse_one_type(ctp, typeno, p, FALSE);
410 if (!symt) FIXME("Couldn't load forward type %x\n", typeno);
414 static struct symt* codeview_add_type_pointer(struct codeview_type_parse* ctp,
415 struct symt* existing,
416 unsigned int pointee_type)
418 struct symt* pointee;
422 existing = codeview_cast_symt(existing, SymTagPointerType);
425 pointee = codeview_fetch_type(ctp, pointee_type);
426 return &symt_new_pointer(ctp->module, pointee)->symt;
429 static struct symt* codeview_add_type_array(struct codeview_type_parse* ctp,
431 unsigned int elemtype,
432 unsigned int indextype,
433 unsigned int arr_len)
435 struct symt* elem = codeview_fetch_type(ctp, elemtype);
436 struct symt* index = codeview_fetch_type(ctp, indextype);
442 symt_get_info(elem, TI_GET_LENGTH, &elem_size);
443 if (elem_size) arr_max = arr_len / (DWORD)elem_size;
445 return &symt_new_array(ctp->module, 0, arr_max, elem, index)->symt;
448 static int codeview_add_type_enum_field_list(struct module* module,
449 struct symt_enum* symt,
450 const union codeview_reftype* ref_type)
452 const unsigned char* ptr = ref_type->fieldlist.list;
453 const unsigned char* last = (const BYTE*)ref_type + ref_type->generic.len + 2;
454 const union codeview_fieldtype* type;
458 if (*ptr >= 0xf0) /* LF_PAD... */
464 type = (const union codeview_fieldtype*)ptr;
466 switch (type->generic.id)
468 case LF_ENUMERATE_V1:
470 int value, vlen = numeric_leaf(&value, &type->enumerate_v1.value);
471 const struct p_string* p_name = (const struct p_string*)((const unsigned char*)&type->enumerate_v1.value + vlen);
473 symt_add_enum_element(module, symt, terminate_string(p_name), value);
474 ptr += 2 + 2 + vlen + (1 + p_name->namelen);
477 case LF_ENUMERATE_V3:
479 int value, vlen = numeric_leaf(&value, &type->enumerate_v3.value);
480 const char* name = (const char*)&type->enumerate_v3.value + vlen;
482 symt_add_enum_element(module, symt, name, value);
483 ptr += 2 + 2 + vlen + (1 + strlen(name));
488 FIXME("Unsupported type %04x in ENUM field list\n", type->generic.id);
495 static void codeview_add_udt_element(struct codeview_type_parse* ctp,
496 struct symt_udt* symt, const char* name,
497 int value, unsigned type)
499 struct symt* subtype;
500 const union codeview_reftype*cv_type;
502 if ((cv_type = codeview_jump_to_type(ctp, type)))
504 switch (cv_type->generic.id)
507 symt_add_udt_element(ctp->module, symt, name,
508 codeview_fetch_type(ctp, cv_type->bitfield_v1.type),
509 cv_type->bitfield_v1.bitoff,
510 cv_type->bitfield_v1.nbits);
513 symt_add_udt_element(ctp->module, symt, name,
514 codeview_fetch_type(ctp, cv_type->bitfield_v2.type),
515 cv_type->bitfield_v2.bitoff,
516 cv_type->bitfield_v2.nbits);
520 subtype = codeview_fetch_type(ctp, type);
524 DWORD64 elem_size = 0;
525 symt_get_info(subtype, TI_GET_LENGTH, &elem_size);
526 symt_add_udt_element(ctp->module, symt, name, subtype,
527 value << 3, (DWORD)elem_size << 3);
531 static int codeview_add_type_struct_field_list(struct codeview_type_parse* ctp,
532 struct symt_udt* symt,
533 unsigned fieldlistno)
535 const unsigned char* ptr;
536 const unsigned char* last;
538 const struct p_string* p_name;
540 const union codeview_reftype*type_ref;
541 const union codeview_fieldtype* type;
543 if (!fieldlistno) return TRUE;
544 type_ref = codeview_jump_to_type(ctp, fieldlistno);
545 ptr = type_ref->fieldlist.list;
546 last = (const BYTE*)type_ref + type_ref->generic.len + 2;
550 if (*ptr >= 0xf0) /* LF_PAD... */
556 type = (const union codeview_fieldtype*)ptr;
558 switch (type->generic.id)
561 leaf_len = numeric_leaf(&value, &type->bclass_v1.offset);
563 /* FIXME: ignored for now */
565 ptr += 2 + 2 + 2 + leaf_len;
569 leaf_len = numeric_leaf(&value, &type->bclass_v2.offset);
571 /* FIXME: ignored for now */
573 ptr += 2 + 2 + 4 + leaf_len;
579 const unsigned short int* p_vboff;
581 leaf_len = numeric_leaf(&value, &type->vbclass_v1.vbpoff);
582 p_vboff = (const unsigned short int*)((const char*)&type->vbclass_v1.vbpoff + leaf_len);
583 vplen = numeric_leaf(&vpoff, p_vboff);
585 /* FIXME: ignored for now */
587 ptr += 2 + 2 + 2 + 2 + leaf_len + vplen;
594 const unsigned short int* p_vboff;
596 leaf_len = numeric_leaf(&value, &type->vbclass_v2.vbpoff);
597 p_vboff = (const unsigned short int*)((const char*)&type->vbclass_v2.vbpoff + leaf_len);
598 vplen = numeric_leaf(&vpoff, p_vboff);
600 /* FIXME: ignored for now */
602 ptr += 2 + 2 + 4 + 4 + leaf_len + vplen;
607 leaf_len = numeric_leaf(&value, &type->member_v1.offset);
608 p_name = (const struct p_string*)((const char*)&type->member_v1.offset + leaf_len);
610 codeview_add_udt_element(ctp, symt, terminate_string(p_name), value,
611 type->member_v1.type);
613 ptr += 2 + 2 + 2 + leaf_len + (1 + p_name->namelen);
617 leaf_len = numeric_leaf(&value, &type->member_v2.offset);
618 p_name = (const struct p_string*)((const unsigned char*)&type->member_v2.offset + leaf_len);
620 codeview_add_udt_element(ctp, symt, terminate_string(p_name), value,
621 type->member_v2.type);
623 ptr += 2 + 2 + 4 + leaf_len + (1 + p_name->namelen);
627 leaf_len = numeric_leaf(&value, &type->member_v3.offset);
628 c_name = (const char*)&type->member_v3.offset + leaf_len;
630 codeview_add_udt_element(ctp, symt, c_name, value, type->member_v3.type);
632 ptr += 2 + 2 + 4 + leaf_len + (strlen(c_name) + 1);
636 /* FIXME: ignored for now */
637 ptr += 2 + 2 + 2 + (1 + type->stmember_v1.p_name.namelen);
641 /* FIXME: ignored for now */
642 ptr += 2 + 4 + 2 + (1 + type->stmember_v2.p_name.namelen);
646 /* FIXME: ignored for now */
647 ptr += 2 + 2 + 2 + (1 + type->method_v1.p_name.namelen);
651 /* FIXME: ignored for now */
652 ptr += 2 + 2 + 4 + (1 + type->method_v2.p_name.namelen);
656 /* FIXME: ignored for now */
657 ptr += 2 + 2 + (1 + type->nesttype_v1.p_name.namelen);
661 /* FIXME: ignored for now */
662 ptr += 2 + 2 + 4 + (1 + type->nesttype_v2.p_name.namelen);
666 /* FIXME: ignored for now */
671 /* FIXME: ignored for now */
675 case LF_ONEMETHOD_V1:
676 /* FIXME: ignored for now */
677 switch ((type->onemethod_v1.attribute >> 2) & 7)
679 case 4: case 6: /* (pure) introducing virtual method */
680 ptr += 2 + 2 + 2 + 4 + (1 + type->onemethod_virt_v1.p_name.namelen);
684 ptr += 2 + 2 + 2 + (1 + type->onemethod_v1.p_name.namelen);
689 case LF_ONEMETHOD_V2:
690 /* FIXME: ignored for now */
691 switch ((type->onemethod_v2.attribute >> 2) & 7)
693 case 4: case 6: /* (pure) introducing virtual method */
694 ptr += 2 + 2 + 4 + 4 + (1 + type->onemethod_virt_v2.p_name.namelen);
698 ptr += 2 + 2 + 4 + (1 + type->onemethod_v2.p_name.namelen);
704 FIXME("Unsupported type %04x in STRUCT field list\n", type->generic.id);
712 static struct symt* codeview_add_type_enum(struct codeview_type_parse* ctp,
713 struct symt* existing,
715 unsigned fieldlistno)
717 struct symt_enum* symt;
721 if (!(symt = codeview_cast_symt(existing, SymTagEnum))) return NULL;
722 /* should also check that all fields are the same */
726 symt = symt_new_enum(ctp->module, name);
729 const union codeview_reftype* fieldlist;
730 fieldlist = codeview_jump_to_type(ctp, fieldlistno);
731 codeview_add_type_enum_field_list(ctp->module, symt, fieldlist);
737 static struct symt* codeview_add_type_struct(struct codeview_type_parse* ctp,
738 struct symt* existing,
739 const char* name, int structlen,
742 struct symt_udt* symt;
746 if (!(symt = codeview_cast_symt(existing, SymTagUDT))) return NULL;
747 /* should also check that all fields are the same */
749 else symt = symt_new_udt(ctp->module, name, structlen, kind);
754 static struct symt* codeview_new_func_signature(struct codeview_type_parse* ctp,
755 struct symt* existing,
756 enum CV_call_e call_conv)
758 struct symt_function_signature* sym;
762 sym = codeview_cast_symt(existing, SymTagFunctionType);
763 if (!sym) return NULL;
767 sym = symt_new_function_signature(ctp->module, NULL, call_conv);
772 static void codeview_add_func_signature_args(struct codeview_type_parse* ctp,
773 struct symt_function_signature* sym,
777 const union codeview_reftype* reftype;
779 sym->rettype = codeview_fetch_type(ctp, ret_type);
780 if (args_list && (reftype = codeview_jump_to_type(ctp, args_list)))
783 switch (reftype->generic.id)
786 for (i = 0; i < reftype->arglist_v1.num; i++)
787 symt_add_function_signature_parameter(ctp->module, sym,
788 codeview_fetch_type(ctp, reftype->arglist_v1.args[i]));
791 for (i = 0; i < reftype->arglist_v2.num; i++)
792 symt_add_function_signature_parameter(ctp->module, sym,
793 codeview_fetch_type(ctp, reftype->arglist_v2.args[i]));
796 FIXME("Unexpected leaf %x for signature's pmt\n", reftype->generic.id);
801 static struct symt* codeview_parse_one_type(struct codeview_type_parse* ctp,
803 const union codeview_type* type, BOOL details)
807 const struct p_string* p_name;
809 struct symt* existing;
811 existing = codeview_get_type(curr_type, TRUE);
813 switch (type->generic.id)
816 /* FIXME: we don't handle modifiers,
817 * but readd previous type on the curr_type
819 WARN("Modifier on %x: %s%s%s%s\n",
820 type->modifier_v1.type,
821 type->modifier_v1.attribute & 0x01 ? "const " : "",
822 type->modifier_v1.attribute & 0x02 ? "volatile " : "",
823 type->modifier_v1.attribute & 0x04 ? "unaligned " : "",
824 type->modifier_v1.attribute & ~0x07 ? "unknown " : "");
825 if (!(symt = codeview_get_type(type->modifier_v1.type, TRUE)))
826 symt = codeview_parse_one_type(ctp, type->modifier_v1.type,
827 codeview_jump_to_type(ctp, type->modifier_v1.type), details);
830 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
831 WARN("Modifier on %x: %s%s%s%s\n",
832 type->modifier_v2.type,
833 type->modifier_v2.attribute & 0x01 ? "const " : "",
834 type->modifier_v2.attribute & 0x02 ? "volatile " : "",
835 type->modifier_v2.attribute & 0x04 ? "unaligned " : "",
836 type->modifier_v2.attribute & ~0x07 ? "unknown " : "");
837 if (!(symt = codeview_get_type(type->modifier_v2.type, TRUE)))
838 symt = codeview_parse_one_type(ctp, type->modifier_v2.type,
839 codeview_jump_to_type(ctp, type->modifier_v2.type), details);
843 symt = codeview_add_type_pointer(ctp, existing, type->pointer_v1.datatype);
846 symt = codeview_add_type_pointer(ctp, existing, type->pointer_v2.datatype);
850 if (existing) symt = codeview_cast_symt(existing, SymTagArrayType);
853 leaf_len = numeric_leaf(&value, &type->array_v1.arrlen);
854 p_name = (const struct p_string*)((const unsigned char*)&type->array_v1.arrlen + leaf_len);
855 symt = codeview_add_type_array(ctp, terminate_string(p_name),
856 type->array_v1.elemtype,
857 type->array_v1.idxtype, value);
861 if (existing) symt = codeview_cast_symt(existing, SymTagArrayType);
864 leaf_len = numeric_leaf(&value, &type->array_v2.arrlen);
865 p_name = (const struct p_string*)((const unsigned char*)&type->array_v2.arrlen + leaf_len);
867 symt = codeview_add_type_array(ctp, terminate_string(p_name),
868 type->array_v2.elemtype,
869 type->array_v2.idxtype, value);
873 if (existing) symt = codeview_cast_symt(existing, SymTagArrayType);
876 leaf_len = numeric_leaf(&value, &type->array_v3.arrlen);
877 c_name = (const char*)&type->array_v3.arrlen + leaf_len;
879 symt = codeview_add_type_array(ctp, c_name,
880 type->array_v3.elemtype,
881 type->array_v3.idxtype, value);
885 case LF_STRUCTURE_V1:
887 leaf_len = numeric_leaf(&value, &type->struct_v1.structlen);
888 p_name = (const struct p_string*)((const unsigned char*)&type->struct_v1.structlen + leaf_len);
889 symt = codeview_add_type_struct(ctp, existing, terminate_string(p_name), value,
890 type->generic.id == LF_CLASS_V1 ? UdtClass : UdtStruct);
893 codeview_add_type(curr_type, symt);
894 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
895 type->struct_v1.fieldlist);
899 case LF_STRUCTURE_V2:
901 leaf_len = numeric_leaf(&value, &type->struct_v2.structlen);
902 p_name = (const struct p_string*)((const unsigned char*)&type->struct_v2.structlen + leaf_len);
903 symt = codeview_add_type_struct(ctp, existing, terminate_string(p_name), value,
904 type->generic.id == LF_CLASS_V2 ? UdtClass : UdtStruct);
907 codeview_add_type(curr_type, symt);
908 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
909 type->struct_v2.fieldlist);
913 case LF_STRUCTURE_V3:
915 leaf_len = numeric_leaf(&value, &type->struct_v3.structlen);
916 c_name = (const char*)&type->struct_v3.structlen + leaf_len;
917 symt = codeview_add_type_struct(ctp, existing, c_name, value,
918 type->generic.id == LF_CLASS_V3 ? UdtClass : UdtStruct);
921 codeview_add_type(curr_type, symt);
922 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
923 type->struct_v3.fieldlist);
928 leaf_len = numeric_leaf(&value, &type->union_v1.un_len);
929 p_name = (const struct p_string*)((const unsigned char*)&type->union_v1.un_len + leaf_len);
930 symt = codeview_add_type_struct(ctp, existing, terminate_string(p_name),
934 codeview_add_type(curr_type, symt);
935 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
936 type->union_v1.fieldlist);
941 leaf_len = numeric_leaf(&value, &type->union_v2.un_len);
942 p_name = (const struct p_string*)((const unsigned char*)&type->union_v2.un_len + leaf_len);
943 symt = codeview_add_type_struct(ctp, existing, terminate_string(p_name),
947 codeview_add_type(curr_type, symt);
948 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
949 type->union_v2.fieldlist);
954 leaf_len = numeric_leaf(&value, &type->union_v3.un_len);
955 c_name = (const char*)&type->union_v3.un_len + leaf_len;
956 symt = codeview_add_type_struct(ctp, existing, c_name,
960 codeview_add_type(curr_type, symt);
961 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
962 type->union_v3.fieldlist);
967 symt = codeview_add_type_enum(ctp, existing,
968 terminate_string(&type->enumeration_v1.p_name),
969 type->enumeration_v1.fieldlist);
973 symt = codeview_add_type_enum(ctp, existing,
974 terminate_string(&type->enumeration_v2.p_name),
975 type->enumeration_v2.fieldlist);
979 symt = codeview_add_type_enum(ctp, existing, type->enumeration_v3.name,
980 type->enumeration_v3.fieldlist);
983 case LF_PROCEDURE_V1:
984 symt = codeview_new_func_signature(ctp, existing, type->procedure_v1.call);
987 codeview_add_type(curr_type, symt);
988 codeview_add_func_signature_args(ctp,
989 (struct symt_function_signature*)symt,
990 type->procedure_v1.rvtype,
991 type->procedure_v1.arglist);
994 case LF_PROCEDURE_V2:
995 symt = codeview_new_func_signature(ctp, existing,type->procedure_v2.call);
998 codeview_add_type(curr_type, symt);
999 codeview_add_func_signature_args(ctp,
1000 (struct symt_function_signature*)symt,
1001 type->procedure_v2.rvtype,
1002 type->procedure_v2.arglist);
1006 case LF_MFUNCTION_V1:
1007 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1008 * nor class information, this would just do for now
1010 symt = codeview_new_func_signature(ctp, existing, type->mfunction_v1.call);
1013 codeview_add_type(curr_type, symt);
1014 codeview_add_func_signature_args(ctp,
1015 (struct symt_function_signature*)symt,
1016 type->mfunction_v1.rvtype,
1017 type->mfunction_v1.arglist);
1020 case LF_MFUNCTION_V2:
1021 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1022 * nor class information, this would just do for now
1024 symt = codeview_new_func_signature(ctp, existing, type->mfunction_v2.call);
1027 codeview_add_type(curr_type, symt);
1028 codeview_add_func_signature_args(ctp,
1029 (struct symt_function_signature*)symt,
1030 type->mfunction_v2.rvtype,
1031 type->mfunction_v2.arglist);
1036 /* this is an ugly hack... FIXME when we have C++ support */
1037 if (!(symt = existing))
1040 snprintf(buf, sizeof(buf), "__internal_vt_shape_%x\n", curr_type);
1041 symt = &symt_new_udt(ctp->module, buf, 0, UdtStruct)->symt;
1045 FIXME("Unsupported type-id leaf %x\n", type->generic.id);
1046 dump(type, 2 + type->generic.len);
1049 return codeview_add_type(curr_type, symt) ? symt : NULL;
1052 static int codeview_parse_type_table(struct codeview_type_parse* ctp)
1054 unsigned int curr_type = FIRST_DEFINABLE_TYPE;
1055 const union codeview_type* type;
1057 for (curr_type = FIRST_DEFINABLE_TYPE; curr_type < FIRST_DEFINABLE_TYPE + ctp->num; curr_type++)
1059 type = codeview_jump_to_type(ctp, curr_type);
1061 /* type records we're interested in are the ones referenced by symbols
1062 * The known ranges are (X mark the ones we want):
1063 * X 0000-0016 for V1 types
1064 * 0200-020c for V1 types referenced by other types
1065 * 0400-040f for V1 types (complex lists & sets)
1066 * X 1000-100f for V2 types
1067 * 1200-120c for V2 types referenced by other types
1068 * 1400-140f for V1 types (complex lists & sets)
1069 * X 1500-150d for V3 types
1070 * 8000-8010 for numeric leafes
1072 if (type->generic.id & 0x8600) continue;
1073 codeview_parse_one_type(ctp, curr_type, type, TRUE);
1079 /*========================================================================
1080 * Process CodeView line number information.
1083 static struct codeview_linetab* codeview_snarf_linetab(struct module* module,
1084 const BYTE* linetab, int size,
1088 char filename[PATH_MAX];
1089 const unsigned int* filetab;
1090 const struct p_string* p_fn;
1093 struct codeview_linetab* lt_hdr;
1094 const unsigned int* lt_ptr;
1098 union any_size pnt2;
1099 const struct startend* start;
1104 * Now get the important bits.
1110 filetab = (const unsigned int*) pnt.c;
1113 * Now count up the number of segments in the file.
1116 for (i = 0; i < nfile; i++)
1118 pnt2.uc = linetab + filetab[i];
1123 * Next allocate the header we will be returning.
1124 * There is one header for each segment, so that we can reach in
1125 * and pull bits as required.
1127 lt_hdr = (struct codeview_linetab*)
1128 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (nseg + 1) * sizeof(*lt_hdr));
1135 * Now fill the header we will be returning, one for each segment.
1136 * Note that this will basically just contain pointers into the existing
1137 * line table, and we do not actually copy any additional information
1138 * or allocate any additional memory.
1142 for (i = 0; i < nfile; i++)
1145 * Get the pointer into the segment information.
1147 pnt2.uc = linetab + filetab[i];
1148 file_segcount = *pnt2.s;
1151 lt_ptr = (const unsigned int*) pnt2.c;
1152 start = (const struct startend*)(lt_ptr + file_segcount);
1155 * Now snarf the filename for all of the segments for this file.
1159 p_fn = (const struct p_string*)(start + file_segcount);
1160 memset(filename, 0, sizeof(filename));
1161 memcpy(filename, p_fn->name, p_fn->namelen);
1162 source = source_new(module, NULL, filename);
1165 source = source_new(module, NULL, (const char*)(start + file_segcount));
1167 for (k = 0; k < file_segcount; k++, this_seg++)
1169 pnt2.uc = linetab + lt_ptr[k];
1170 lt_hdr[this_seg].start = start[k].start;
1171 lt_hdr[this_seg].end = start[k].end;
1172 lt_hdr[this_seg].source = source;
1173 lt_hdr[this_seg].segno = *pnt2.s++;
1174 lt_hdr[this_seg].nline = *pnt2.s++;
1175 lt_hdr[this_seg].offtab = pnt2.ui;
1176 lt_hdr[this_seg].linetab = (const unsigned short*)(pnt2.ui + lt_hdr[this_seg].nline);
1186 /*========================================================================
1187 * Process CodeView symbol information.
1190 static unsigned int codeview_map_offset(const struct msc_debug_info* msc_dbg,
1191 unsigned int offset)
1193 int nomap = msc_dbg->nomap;
1194 const OMAP_DATA* omapp = msc_dbg->omapp;
1197 if (!nomap || !omapp) return offset;
1199 /* FIXME: use binary search */
1200 for (i = 0; i < nomap - 1; i++)
1201 if (omapp[i].from <= offset && omapp[i+1].from > offset)
1202 return !omapp[i].to ? 0 : omapp[i].to + (offset - omapp[i].from);
1207 static const struct codeview_linetab*
1208 codeview_get_linetab(const struct codeview_linetab* linetab,
1209 unsigned seg, unsigned offset)
1212 * Check whether we have line number information
1216 for (; linetab->linetab; linetab++)
1217 if (linetab->segno == seg &&
1218 linetab->start <= offset && linetab->end > offset)
1220 if (!linetab->linetab) linetab = NULL;
1225 static unsigned codeview_get_address(const struct msc_debug_info* msc_dbg,
1226 unsigned seg, unsigned offset)
1228 int nsect = msc_dbg->nsect;
1229 const IMAGE_SECTION_HEADER* sectp = msc_dbg->sectp;
1231 if (!seg || seg > nsect) return 0;
1232 return msc_dbg->module->module.BaseOfImage +
1233 codeview_map_offset(msc_dbg, sectp[seg-1].VirtualAddress + offset);
1236 static void codeview_add_func_linenum(struct module* module,
1237 struct symt_function* func,
1238 const struct codeview_linetab* linetab,
1239 unsigned offset, unsigned size)
1243 if (!linetab) return;
1244 for (i = 0; i < linetab->nline; i++)
1246 if (linetab->offtab[i] >= offset && linetab->offtab[i] < offset + size)
1248 symt_add_func_line(module, func, linetab->source,
1249 linetab->linetab[i], linetab->offtab[i] - offset);
1254 static int codeview_snarf(const struct msc_debug_info* msc_dbg, const BYTE* root,
1255 int offset, int size,
1256 struct codeview_linetab* linetab)
1258 struct symt_function* curr_func = NULL;
1260 const struct codeview_linetab* flt;
1261 struct symt_block* block = NULL;
1264 struct symt_compiland* compiland = NULL;
1265 struct location loc;
1268 * Loop over the different types of records and whenever we
1269 * find something we are interested in, record it and move on.
1271 for (i = offset; i < size; i += length)
1273 const union codeview_symbol* sym = (const union codeview_symbol*)(root + i);
1274 length = sym->generic.len + 2;
1275 if (i + length > size) break;
1276 if (length & 3) FIXME("unpadded len %u\n", length);
1278 switch (sym->generic.id)
1281 * Global and local data symbols. We don't associate these
1282 * with any given source file.
1286 symt_new_global_variable(msc_dbg->module, compiland,
1287 terminate_string(&sym->data_v1.p_name), sym->generic.id == S_LDATA_V1,
1288 codeview_get_address(msc_dbg, sym->data_v1.segment, sym->data_v1.offset),
1290 codeview_get_type(sym->data_v1.symtype, FALSE));
1294 name = terminate_string(&sym->data_v2.p_name);
1296 symt_new_global_variable(msc_dbg->module, compiland,
1297 name, sym->generic.id == S_LDATA_V2,
1298 codeview_get_address(msc_dbg, sym->data_v2.segment, sym->data_v2.offset),
1300 codeview_get_type(sym->data_v2.symtype, FALSE));
1304 if (*sym->data_v3.name)
1305 symt_new_global_variable(msc_dbg->module, compiland,
1307 sym->generic.id == S_LDATA_V3,
1308 codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset),
1310 codeview_get_type(sym->data_v3.symtype, FALSE));
1313 case S_PUB_V1: /* FIXME is this really a 'data_v1' structure ?? */
1314 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1316 symt_new_public(msc_dbg->module, compiland,
1317 terminate_string(&sym->data_v1.p_name),
1318 codeview_get_address(msc_dbg, sym->data_v1.segment, sym->data_v1.offset),
1319 1, TRUE /* FIXME */, TRUE /* FIXME */);
1322 case S_PUB_V2: /* FIXME is this really a 'data_v2' structure ?? */
1323 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1325 symt_new_public(msc_dbg->module, compiland,
1326 terminate_string(&sym->data_v2.p_name),
1327 codeview_get_address(msc_dbg, sym->data_v2.segment, sym->data_v2.offset),
1328 1, TRUE /* FIXME */, TRUE /* FIXME */);
1333 * Sort of like a global function, but it just points
1334 * to a thunk, which is a stupid name for what amounts to
1335 * a PLT slot in the normal jargon that everyone else uses.
1338 symt_new_thunk(msc_dbg->module, compiland,
1339 terminate_string(&sym->thunk_v1.p_name), sym->thunk_v1.thtype,
1340 codeview_get_address(msc_dbg, sym->thunk_v1.segment, sym->thunk_v1.offset),
1341 sym->thunk_v1.thunk_len);
1344 symt_new_thunk(msc_dbg->module, compiland,
1345 sym->thunk_v3.name, sym->thunk_v3.thtype,
1346 codeview_get_address(msc_dbg, sym->thunk_v3.segment, sym->thunk_v3.offset),
1347 sym->thunk_v3.thunk_len);
1351 * Global and static functions.
1355 flt = codeview_get_linetab(linetab, sym->proc_v1.segment, sym->proc_v1.offset);
1356 if (curr_func) FIXME("nested function\n");
1357 curr_func = symt_new_function(msc_dbg->module, compiland,
1358 terminate_string(&sym->proc_v1.p_name),
1359 codeview_get_address(msc_dbg, sym->proc_v1.segment, sym->proc_v1.offset),
1360 sym->proc_v1.proc_len,
1361 codeview_get_type(sym->proc_v1.proctype, FALSE));
1362 codeview_add_func_linenum(msc_dbg->module, curr_func, flt,
1363 sym->proc_v1.offset, sym->proc_v1.proc_len);
1364 loc.kind = loc_absolute;
1365 loc.offset = sym->proc_v1.debug_start;
1366 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugStart, &loc, NULL);
1367 loc.offset = sym->proc_v1.debug_end;
1368 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugEnd, &loc, NULL);
1372 flt = codeview_get_linetab(linetab, sym->proc_v2.segment, sym->proc_v2.offset);
1373 if (curr_func) FIXME("nested function\n");
1374 curr_func = symt_new_function(msc_dbg->module, compiland,
1375 terminate_string(&sym->proc_v2.p_name),
1376 codeview_get_address(msc_dbg, sym->proc_v2.segment, sym->proc_v2.offset),
1377 sym->proc_v2.proc_len,
1378 codeview_get_type(sym->proc_v2.proctype, FALSE));
1379 codeview_add_func_linenum(msc_dbg->module, curr_func, flt,
1380 sym->proc_v2.offset, sym->proc_v2.proc_len);
1381 loc.kind = loc_absolute;
1382 loc.offset = sym->proc_v2.debug_start;
1383 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugStart, &loc, NULL);
1384 loc.offset = sym->proc_v2.debug_end;
1385 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugEnd, &loc, NULL);
1389 flt = codeview_get_linetab(linetab, sym->proc_v3.segment, sym->proc_v3.offset);
1390 if (curr_func) FIXME("nested function\n");
1391 curr_func = symt_new_function(msc_dbg->module, compiland,
1393 codeview_get_address(msc_dbg, sym->proc_v3.segment, sym->proc_v3.offset),
1394 sym->proc_v3.proc_len,
1395 codeview_get_type(sym->proc_v3.proctype, FALSE));
1396 codeview_add_func_linenum(msc_dbg->module, curr_func, flt,
1397 sym->proc_v3.offset, sym->proc_v3.proc_len);
1398 loc.kind = loc_absolute;
1399 loc.offset = sym->proc_v3.debug_start;
1400 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugStart, &loc, NULL);
1401 loc.offset = sym->proc_v3.debug_end;
1402 symt_add_function_point(msc_dbg->module, curr_func, SymTagFuncDebugEnd, &loc, NULL);
1405 * Function parameters and stack variables.
1408 loc.kind = loc_regrel;
1409 loc.reg = 0; /* FIXME */
1410 loc.offset = sym->stack_v1.offset;
1411 symt_add_func_local(msc_dbg->module, curr_func,
1412 sym->stack_v1.offset > 0 ? DataIsParam : DataIsLocal,
1414 codeview_get_type(sym->stack_v1.symtype, FALSE),
1415 terminate_string(&sym->stack_v1.p_name));
1418 loc.kind = loc_regrel;
1419 loc.reg = 0; /* FIXME */
1420 loc.offset = sym->stack_v2.offset;
1421 symt_add_func_local(msc_dbg->module, curr_func,
1422 sym->stack_v2.offset > 0 ? DataIsParam : DataIsLocal,
1424 codeview_get_type(sym->stack_v2.symtype, FALSE),
1425 terminate_string(&sym->stack_v2.p_name));
1428 loc.kind = loc_regrel;
1429 loc.reg = 0; /* FIXME */
1430 loc.offset = sym->stack_v3.offset;
1431 symt_add_func_local(msc_dbg->module, curr_func,
1432 sym->stack_v3.offset > 0 ? DataIsParam : DataIsLocal,
1434 codeview_get_type(sym->stack_v3.symtype, FALSE),
1435 sym->stack_v3.name);
1439 loc.kind = loc_register;
1440 loc.reg = sym->register_v1.reg;
1442 symt_add_func_local(msc_dbg->module, curr_func,
1444 block, codeview_get_type(sym->register_v1.type, FALSE),
1445 terminate_string(&sym->register_v1.p_name));
1448 loc.kind = loc_register;
1449 loc.reg = sym->register_v2.reg;
1451 symt_add_func_local(msc_dbg->module, curr_func,
1453 block, codeview_get_type(sym->register_v2.type, FALSE),
1454 terminate_string(&sym->register_v2.p_name));
1458 block = symt_open_func_block(msc_dbg->module, curr_func, block,
1459 codeview_get_address(msc_dbg, sym->block_v1.segment, sym->block_v1.offset),
1460 sym->block_v1.length);
1463 block = symt_open_func_block(msc_dbg->module, curr_func, block,
1464 codeview_get_address(msc_dbg, sym->block_v3.segment, sym->block_v3.offset),
1465 sym->block_v3.length);
1471 block = symt_close_func_block(msc_dbg->module, curr_func, block, 0);
1475 symt_normalize_function(msc_dbg->module, curr_func);
1480 case S_COMPILAND_V1:
1481 TRACE("S-Compiland-V1 %x %s\n",
1482 sym->compiland_v1.unknown, terminate_string(&sym->compiland_v1.p_name));
1485 case S_COMPILAND_V2:
1486 TRACE("S-Compiland-V2 %s\n", terminate_string(&sym->compiland_v2.p_name));
1487 if (TRACE_ON(dbghelp_msc))
1489 const char* ptr1 = sym->compiland_v2.p_name.name + sym->compiland_v2.p_name.namelen;
1493 ptr2 = ptr1 + strlen(ptr1) + 1;
1494 TRACE("\t%s => %s\n", ptr1, ptr2);
1495 ptr1 = ptr2 + strlen(ptr2) + 1;
1499 case S_COMPILAND_V3:
1500 TRACE("S-Compiland-V3 %s\n", sym->compiland_v3.name);
1501 if (TRACE_ON(dbghelp_msc))
1503 const char* ptr1 = sym->compiland_v3.name + strlen(sym->compiland_v3.name);
1507 ptr2 = ptr1 + strlen(ptr1) + 1;
1508 TRACE("\t%s => %s\n", ptr1, ptr2);
1509 ptr1 = ptr2 + strlen(ptr2) + 1;
1515 TRACE("S-ObjName %s\n", terminate_string(&sym->objname_v1.p_name));
1516 compiland = symt_new_compiland(msc_dbg->module, 0 /* FIXME */,
1517 source_new(msc_dbg->module, NULL,
1518 terminate_string(&sym->objname_v1.p_name)));
1524 loc.kind = loc_absolute;
1525 loc.offset = codeview_get_address(msc_dbg, sym->label_v1.segment, sym->label_v1.offset) - curr_func->address;
1526 symt_add_function_point(msc_dbg->module, curr_func, SymTagLabel, &loc,
1527 terminate_string(&sym->label_v1.p_name));
1530 FIXME("No current function for label %s\n",
1531 terminate_string(&sym->label_v1.p_name));
1536 loc.kind = loc_absolute;
1537 loc.offset = codeview_get_address(msc_dbg, sym->label_v3.segment, sym->label_v3.offset) - curr_func->address;
1538 symt_add_function_point(msc_dbg->module, curr_func, SymTagLabel,
1539 &loc, sym->label_v3.name);
1542 FIXME("No current function for label %s\n", sym->label_v3.name);
1548 const struct p_string* name;
1553 vlen = numeric_leaf(&v.n1.n2.n3.intVal, &sym->constant_v1.cvalue);
1554 name = (const struct p_string*)((const char*)&sym->constant_v1.cvalue + vlen);
1555 se = codeview_get_type(sym->constant_v1.type, FALSE);
1557 TRACE("S-Constant-V1 %u %s %x\n",
1558 v.n1.n2.n3.intVal, terminate_string(name), sym->constant_v1.type);
1559 symt_new_constant(msc_dbg->module, compiland, terminate_string(name),
1566 const struct p_string* name;
1571 vlen = numeric_leaf(&v.n1.n2.n3.intVal, &sym->constant_v2.cvalue);
1572 name = (const struct p_string*)((const char*)&sym->constant_v2.cvalue + vlen);
1573 se = codeview_get_type(sym->constant_v2.type, FALSE);
1575 TRACE("S-Constant-V2 %u %s %x\n",
1576 v.n1.n2.n3.intVal, terminate_string(name), sym->constant_v2.type);
1577 symt_new_constant(msc_dbg->module, compiland, terminate_string(name),
1589 vlen = numeric_leaf(&v.n1.n2.n3.intVal, &sym->constant_v3.cvalue);
1590 name = (const char*)&sym->constant_v3.cvalue + vlen;
1591 se = codeview_get_type(sym->constant_v3.type, FALSE);
1593 TRACE("S-Constant-V3 %u %s %x\n",
1594 v.n1.n2.n3.intVal, name, sym->constant_v3.type);
1595 /* FIXME: we should add this as a constant value */
1600 if (sym->udt_v1.type)
1602 if ((symt = codeview_get_type(sym->udt_v1.type, FALSE)))
1603 symt_new_typedef(msc_dbg->module, symt,
1604 terminate_string(&sym->udt_v1.p_name));
1606 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1607 terminate_string(&sym->udt_v1.p_name), sym->udt_v1.type);
1611 if (sym->udt_v2.type)
1613 if ((symt = codeview_get_type(sym->udt_v2.type, FALSE)))
1614 symt_new_typedef(msc_dbg->module, symt,
1615 terminate_string(&sym->udt_v2.p_name));
1617 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1618 terminate_string(&sym->udt_v2.p_name), sym->udt_v2.type);
1622 if (sym->udt_v3.type)
1624 if ((symt = codeview_get_type(sym->udt_v3.type, FALSE)))
1625 symt_new_typedef(msc_dbg->module, symt, sym->udt_v3.name);
1627 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1628 sym->udt_v3.name, sym->udt_v3.type);
1633 * These are special, in that they are always followed by an
1634 * additional length-prefixed string which is *not* included
1635 * into the symbol length count. We need to skip it.
1640 name = (const char*)sym + length;
1641 length += (*name + 1 + 3) & ~3;
1645 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1647 symt_new_public(msc_dbg->module, compiland,
1649 codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset),
1650 1, FALSE /* FIXME */, FALSE);
1653 case S_PUB_FUNC1_V3:
1654 case S_PUB_FUNC2_V3: /* using a data_v3 isn't what we'd expect */
1655 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1657 symt_new_public(msc_dbg->module, compiland,
1659 codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset),
1660 1, TRUE /* FIXME */, TRUE);
1664 case S_MSTOOL_V3: /* just to silence a few warnings */
1668 TRACE("Start search: seg=0x%x at offset 0x%08x\n",
1669 sym->ssearch_v1.segment, sym->ssearch_v1.offset);
1673 TRACE("S-Align V1\n");
1677 FIXME("Unsupported symbol id %x\n", sym->generic.id);
1678 dump(sym, 2 + sym->generic.len);
1683 if (curr_func) symt_normalize_function(msc_dbg->module, curr_func);
1685 HeapFree(GetProcessHeap(), 0, linetab);
1689 /*========================================================================
1693 static void* pdb_jg_read(const struct PDB_JG_HEADER* pdb, const WORD* block_list,
1699 if (!size) return NULL;
1701 num_blocks = (size + pdb->block_size - 1) / pdb->block_size;
1702 buffer = HeapAlloc(GetProcessHeap(), 0, num_blocks * pdb->block_size);
1704 for (i = 0; i < num_blocks; i++)
1705 memcpy(buffer + i * pdb->block_size,
1706 (const char*)pdb + block_list[i] * pdb->block_size, pdb->block_size);
1711 static void* pdb_ds_read(const struct PDB_DS_HEADER* pdb, const DWORD* block_list,
1717 if (!size) return NULL;
1719 num_blocks = (size + pdb->block_size - 1) / pdb->block_size;
1720 buffer = HeapAlloc(GetProcessHeap(), 0, num_blocks * pdb->block_size);
1722 for (i = 0; i < num_blocks; i++)
1723 memcpy(buffer + i * pdb->block_size,
1724 (const char*)pdb + block_list[i] * pdb->block_size, pdb->block_size);
1729 static void* pdb_read_jg_file(const struct PDB_JG_HEADER* pdb,
1730 const struct PDB_JG_TOC* toc, DWORD file_nr)
1732 const WORD* block_list;
1735 if (!toc || file_nr >= toc->num_files) return NULL;
1737 block_list = (const WORD*) &toc->file[toc->num_files];
1738 for (i = 0; i < file_nr; i++)
1739 block_list += (toc->file[i].size + pdb->block_size - 1) / pdb->block_size;
1741 return pdb_jg_read(pdb, block_list, toc->file[file_nr].size);
1744 static void* pdb_read_ds_file(const struct PDB_DS_HEADER* pdb,
1745 const struct PDB_DS_TOC* toc, DWORD file_nr)
1747 const DWORD* block_list;
1750 if (!toc || file_nr >= toc->num_files) return NULL;
1752 if (toc->file_size[file_nr] == 0 || toc->file_size[file_nr] == 0xFFFFFFFF)
1754 FIXME(">>> requesting NULL stream (%u)\n", file_nr);
1757 block_list = &toc->file_size[toc->num_files];
1758 for (i = 0; i < file_nr; i++)
1759 block_list += (toc->file_size[i] + pdb->block_size - 1) / pdb->block_size;
1761 return pdb_ds_read(pdb, block_list, toc->file_size[file_nr]);
1764 static void* pdb_read_file(const char* image, const struct pdb_lookup* pdb_lookup,
1767 switch (pdb_lookup->kind)
1770 return pdb_read_jg_file((const struct PDB_JG_HEADER*)image,
1771 pdb_lookup->u.jg.toc, file_nr);
1773 return pdb_read_ds_file((const struct PDB_DS_HEADER*)image,
1774 pdb_lookup->u.ds.toc, file_nr);
1779 static unsigned pdb_get_file_size(const struct pdb_lookup* pdb_lookup, DWORD file_nr)
1781 switch (pdb_lookup->kind)
1783 case PDB_JG: return pdb_lookup->u.jg.toc->file[file_nr].size;
1784 case PDB_DS: return pdb_lookup->u.ds.toc->file_size[file_nr];
1789 static void pdb_free(void* buffer)
1791 HeapFree(GetProcessHeap(), 0, buffer);
1794 static void pdb_free_lookup(const struct pdb_lookup* pdb_lookup)
1796 switch (pdb_lookup->kind)
1799 pdb_free(pdb_lookup->u.jg.toc);
1802 pdb_free(pdb_lookup->u.ds.toc);
1807 static void pdb_convert_types_header(PDB_TYPES* types, const BYTE* image)
1809 memset(types, 0, sizeof(PDB_TYPES));
1812 if (*(const DWORD*)image < 19960000) /* FIXME: correct version? */
1814 /* Old version of the types record header */
1815 const PDB_TYPES_OLD* old = (const PDB_TYPES_OLD*)image;
1816 types->version = old->version;
1817 types->type_offset = sizeof(PDB_TYPES_OLD);
1818 types->type_size = old->type_size;
1819 types->first_index = old->first_index;
1820 types->last_index = old->last_index;
1821 types->file = old->file;
1825 /* New version of the types record header */
1826 *types = *(const PDB_TYPES*)image;
1830 static void pdb_convert_symbols_header(PDB_SYMBOLS* symbols,
1831 int* header_size, const BYTE* image)
1833 memset(symbols, 0, sizeof(PDB_SYMBOLS));
1836 if (*(const DWORD*)image != 0xffffffff)
1838 /* Old version of the symbols record header */
1839 const PDB_SYMBOLS_OLD* old = (const PDB_SYMBOLS_OLD*)image;
1840 symbols->version = 0;
1841 symbols->module_size = old->module_size;
1842 symbols->offset_size = old->offset_size;
1843 symbols->hash_size = old->hash_size;
1844 symbols->srcmodule_size = old->srcmodule_size;
1845 symbols->pdbimport_size = 0;
1846 symbols->hash1_file = old->hash1_file;
1847 symbols->hash2_file = old->hash2_file;
1848 symbols->gsym_file = old->gsym_file;
1850 *header_size = sizeof(PDB_SYMBOLS_OLD);
1854 /* New version of the symbols record header */
1855 *symbols = *(const PDB_SYMBOLS*)image;
1856 *header_size = sizeof(PDB_SYMBOLS);
1860 static void pdb_convert_symbol_file(const PDB_SYMBOLS* symbols,
1861 PDB_SYMBOL_FILE_EX* sfile,
1862 unsigned* size, const void* image)
1865 if (symbols->version < 19970000)
1867 const PDB_SYMBOL_FILE *sym_file = (const PDB_SYMBOL_FILE*)image;
1868 memset(sfile, 0, sizeof(*sfile));
1869 sfile->file = sym_file->file;
1870 sfile->range.index = sym_file->range.index;
1871 sfile->symbol_size = sym_file->symbol_size;
1872 sfile->lineno_size = sym_file->lineno_size;
1873 *size = sizeof(PDB_SYMBOL_FILE) - 1;
1877 memcpy(sfile, image, sizeof(PDB_SYMBOL_FILE_EX));
1878 *size = sizeof(PDB_SYMBOL_FILE_EX) - 1;
1882 static BOOL CALLBACK pdb_match(const char* file, void* user)
1884 /* accept first file that exists */
1885 HANDLE h = CreateFileA(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1886 TRACE("match with %s returns %p\n", file, h);
1887 if (INVALID_HANDLE_VALUE != h) {
1894 static HANDLE open_pdb_file(const struct process* pcs,
1895 const struct pdb_lookup* lookup)
1898 char dbg_file_path[MAX_PATH];
1901 switch (lookup->kind)
1904 ret = SymFindFileInPath(pcs->handle, NULL, lookup->filename,
1905 (PVOID)(DWORD_PTR)lookup->u.jg.timestamp,
1906 lookup->age, 0, SSRVOPT_DWORD,
1907 dbg_file_path, pdb_match, NULL);
1910 ret = SymFindFileInPath(pcs->handle, NULL, lookup->filename,
1911 (PVOID)&lookup->u.ds.guid, lookup->age, 0,
1912 SSRVOPT_GUIDPTR, dbg_file_path, pdb_match, NULL);
1917 WARN("\tCouldn't find %s\n", lookup->filename);
1920 h = CreateFileA(dbg_file_path, GENERIC_READ, FILE_SHARE_READ, NULL,
1921 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
1922 TRACE("%s: %s returns %p\n", lookup->filename, dbg_file_path, h);
1923 return (h == INVALID_HANDLE_VALUE) ? NULL : h;
1926 static void pdb_process_types(const struct msc_debug_info* msc_dbg,
1927 const char* image, const struct pdb_lookup* pdb_lookup)
1929 BYTE* types_image = NULL;
1931 types_image = pdb_read_file(image, pdb_lookup, 2);
1935 struct codeview_type_parse ctp;
1940 pdb_convert_types_header(&types, types_image);
1942 /* Check for unknown versions */
1943 switch (types.version)
1945 case 19950410: /* VC 4.0 */
1947 case 19961031: /* VC 5.0 / 6.0 */
1951 ERR("-Unknown type info version %d\n", types.version);
1954 ctp.module = msc_dbg->module;
1955 /* reconstruct the types offset...
1956 * FIXME: maybe it's present in the newest PDB_TYPES structures
1958 total = types.last_index - types.first_index + 1;
1959 offset = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) * total);
1960 ctp.table = ptr = types_image + types.type_offset;
1962 while (ptr < ctp.table + types.type_size && ctp.num < total)
1964 offset[ctp.num++] = ptr - ctp.table;
1965 ptr += ((const union codeview_type*)ptr)->generic.len + 2;
1967 ctp.offset = offset;
1969 /* Read type table */
1970 codeview_parse_type_table(&ctp);
1971 HeapFree(GetProcessHeap(), 0, offset);
1972 pdb_free(types_image);
1976 static const char PDB_JG_IDENT[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
1977 static const char PDB_DS_IDENT[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
1979 /******************************************************************
1982 * Tries to load a pdb file
1983 * if do_fill is TRUE, then it just fills pdb_lookup with the information of the
1985 * if do_fill is FALSE, then it just checks that the kind of PDB (stored in
1986 * pdb_lookup) matches what's really in the file
1988 static BOOL pdb_init(struct pdb_lookup* pdb_lookup, const char* image, BOOL do_fill)
1992 /* check the file header, and if ok, load the TOC */
1993 TRACE("PDB(%s): %.40s\n", pdb_lookup->filename, debugstr_an(image, 40));
1995 if (!memcmp(image, PDB_JG_IDENT, sizeof(PDB_JG_IDENT)))
1997 const struct PDB_JG_HEADER* pdb = (const struct PDB_JG_HEADER*)image;
1998 struct PDB_JG_ROOT* root;
2000 pdb_lookup->u.jg.toc = pdb_jg_read(pdb, pdb->toc_block, pdb->toc.size);
2001 root = pdb_read_jg_file(pdb, pdb_lookup->u.jg.toc, 1);
2004 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup->filename);
2007 switch (root->Version)
2009 case 19950623: /* VC 4.0 */
2011 case 19960307: /* VC 5.0 */
2012 case 19970604: /* VC 6.0 */
2015 ERR("-Unknown root block version %d\n", root->Version);
2019 pdb_lookup->kind = PDB_JG;
2020 pdb_lookup->u.jg.timestamp = root->TimeDateStamp;
2021 pdb_lookup->age = root->Age;
2023 else if (pdb_lookup->kind != PDB_JG ||
2024 pdb_lookup->u.jg.timestamp != root->TimeDateStamp ||
2025 pdb_lookup->age != root->Age)
2027 TRACE("found JG/%c for %s: age=%x timestamp=%x\n",
2028 do_fill ? 'f' : '-', pdb_lookup->filename, root->Age,
2029 root->TimeDateStamp);
2032 else if (!memcmp(image, PDB_DS_IDENT, sizeof(PDB_DS_IDENT)))
2034 const struct PDB_DS_HEADER* pdb = (const struct PDB_DS_HEADER*)image;
2035 struct PDB_DS_ROOT* root;
2037 pdb_lookup->u.ds.toc =
2039 (const DWORD*)((const char*)pdb + pdb->toc_page * pdb->block_size),
2041 root = pdb_read_ds_file(pdb, pdb_lookup->u.ds.toc, 1);
2044 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup->filename);
2047 switch (root->Version)
2052 ERR("-Unknown root block version %d\n", root->Version);
2056 pdb_lookup->kind = PDB_DS;
2057 pdb_lookup->u.ds.guid = root->guid;
2058 pdb_lookup->age = root->Age;
2060 else if (pdb_lookup->kind != PDB_DS ||
2061 memcmp(&pdb_lookup->u.ds.guid, &root->guid, sizeof(GUID)) ||
2062 pdb_lookup->age != root->Age)
2064 TRACE("found DS/%c for %s: age=%x guid=%s\n",
2065 do_fill ? 'f' : '-', pdb_lookup->filename, root->Age,
2066 debugstr_guid(&root->guid));
2070 if (0) /* some tool to dump the internal files from a PDB file */
2074 switch (pdb_lookup->kind)
2076 case PDB_JG: num_files = pdb_lookup->u.jg.toc->num_files; break;
2077 case PDB_DS: num_files = pdb_lookup->u.ds.toc->num_files; break;
2080 for (i = 1; i < num_files; i++)
2082 unsigned char* x = pdb_read_file(image, pdb_lookup, i);
2083 FIXME("********************** [%u]: size=%08x\n",
2084 i, pdb_get_file_size(pdb_lookup, i));
2085 dump(x, pdb_get_file_size(pdb_lookup, i));
2092 static BOOL pdb_process_internal(const struct process* pcs,
2093 const struct msc_debug_info* msc_dbg,
2094 struct pdb_lookup* pdb_lookup,
2095 unsigned module_index);
2097 static void pdb_process_symbol_imports(const struct process* pcs,
2098 const struct msc_debug_info* msc_dbg,
2099 const PDB_SYMBOLS* symbols,
2100 const void* symbols_image,
2102 const struct pdb_lookup* pdb_lookup,
2103 unsigned module_index)
2105 if (module_index == -1 && symbols && symbols->pdbimport_size)
2107 const PDB_SYMBOL_IMPORT*imp;
2113 imp = (const PDB_SYMBOL_IMPORT*)((const char*)symbols_image + sizeof(PDB_SYMBOLS) +
2114 symbols->module_size + symbols->offset_size +
2115 symbols->hash_size + symbols->srcmodule_size);
2116 first = (const char*)imp;
2117 last = (const char*)imp + symbols->pdbimport_size;
2118 while (imp < (const PDB_SYMBOL_IMPORT*)last)
2120 ptr = (const char*)imp + sizeof(*imp) + strlen(imp->filename);
2121 if (i >= CV_MAX_MODULES) FIXME("Out of bounds !!!\n");
2122 if (!strcasecmp(pdb_lookup->filename, imp->filename))
2124 if (module_index != -1) FIXME("Twice the entry\n");
2125 else module_index = i;
2129 struct pdb_lookup imp_pdb_lookup;
2131 /* FIXME: this is an import of a JG PDB file
2132 * how's a DS PDB handled ?
2134 imp_pdb_lookup.filename = imp->filename;
2135 imp_pdb_lookup.kind = PDB_JG;
2136 imp_pdb_lookup.u.jg.timestamp = imp->TimeDateStamp;
2137 imp_pdb_lookup.age = imp->Age;
2138 TRACE("got for %s: age=%u ts=%x\n",
2139 imp->filename, imp->Age, imp->TimeDateStamp);
2140 pdb_process_internal(pcs, msc_dbg, &imp_pdb_lookup, i);
2143 imp = (const PDB_SYMBOL_IMPORT*)((const char*)first + ((ptr - (const char*)first + strlen(ptr) + 1 + 3) & ~3));
2146 cv_current_module = &cv_zmodules[(module_index == -1) ? 0 : module_index];
2147 if (cv_current_module->allowed) FIXME("Already allowed ??\n");
2148 cv_current_module->allowed = TRUE;
2149 pdb_process_types(msc_dbg, image, pdb_lookup);
2152 static BOOL pdb_process_internal(const struct process* pcs,
2153 const struct msc_debug_info* msc_dbg,
2154 struct pdb_lookup* pdb_lookup,
2155 unsigned module_index)
2158 HANDLE hFile, hMap = NULL;
2160 BYTE* symbols_image = NULL;
2162 TRACE("Processing PDB file %s\n", pdb_lookup->filename);
2164 /* Open and map() .PDB file */
2165 if ((hFile = open_pdb_file(pcs, pdb_lookup)) == NULL ||
2166 ((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == NULL) ||
2167 ((image = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) == NULL))
2169 WARN("Unable to open .PDB file: %s\n", pdb_lookup->filename);
2172 pdb_init(pdb_lookup, image, FALSE);
2174 symbols_image = pdb_read_file(image, pdb_lookup, 3);
2177 PDB_SYMBOLS symbols;
2180 int header_size = 0;
2182 pdb_convert_symbols_header(&symbols, &header_size, symbols_image);
2183 switch (symbols.version)
2185 case 0: /* VC 4.0 */
2186 case 19960307: /* VC 5.0 */
2187 case 19970606: /* VC 6.0 */
2191 ERR("-Unknown symbol info version %d %08x\n",
2192 symbols.version, symbols.version);
2195 pdb_process_symbol_imports(pcs, msc_dbg, &symbols, symbols_image, image, pdb_lookup, module_index);
2197 /* Read global symbol table */
2198 modimage = pdb_read_file(image, pdb_lookup, symbols.gsym_file);
2201 codeview_snarf(msc_dbg, modimage, 0,
2202 pdb_get_file_size(pdb_lookup, symbols.gsym_file), NULL);
2207 /* Read per-module symbol / linenumber tables */
2208 file = symbols_image + header_size;
2209 while (file - symbols_image < header_size + symbols.module_size)
2211 PDB_SYMBOL_FILE_EX sfile;
2212 const char* file_name;
2215 HeapValidate(GetProcessHeap(), 0, NULL);
2216 pdb_convert_symbol_file(&symbols, &sfile, &size, file);
2218 modimage = pdb_read_file(image, pdb_lookup, sfile.file);
2221 struct codeview_linetab* linetab = NULL;
2223 if (sfile.lineno_size)
2224 linetab = codeview_snarf_linetab(msc_dbg->module,
2225 modimage + sfile.symbol_size,
2227 pdb_lookup->kind == PDB_JG);
2229 if (sfile.symbol_size)
2230 codeview_snarf(msc_dbg, modimage, sizeof(DWORD),
2231 sfile.symbol_size, linetab);
2235 file_name = (const char*)file + size;
2236 file_name += strlen(file_name) + 1;
2237 file = (BYTE*)((DWORD)(file_name + strlen(file_name) + 1 + 3) & ~3);
2241 pdb_process_symbol_imports(pcs, msc_dbg, NULL, NULL, image, pdb_lookup,
2247 pdb_free(symbols_image);
2248 pdb_free_lookup(pdb_lookup);
2250 if (image) UnmapViewOfFile(image);
2251 if (hMap) CloseHandle(hMap);
2252 if (hFile) CloseHandle(hFile);
2257 static BOOL pdb_process_file(const struct process* pcs,
2258 const struct msc_debug_info* msc_dbg,
2259 struct pdb_lookup* pdb_lookup)
2263 memset(cv_zmodules, 0, sizeof(cv_zmodules));
2264 codeview_init_basic_types(msc_dbg->module);
2265 ret = pdb_process_internal(pcs, msc_dbg, pdb_lookup, -1);
2266 codeview_clear_type_table();
2269 msc_dbg->module->module.SymType = SymCv;
2270 if (pdb_lookup->kind == PDB_JG)
2271 msc_dbg->module->module.PdbSig = pdb_lookup->u.jg.timestamp;
2273 msc_dbg->module->module.PdbSig70 = pdb_lookup->u.ds.guid;
2274 msc_dbg->module->module.PdbAge = pdb_lookup->age;
2275 MultiByteToWideChar(CP_ACP, 0, pdb_lookup->filename, -1,
2276 msc_dbg->module->module.LoadedPdbName,
2277 sizeof(msc_dbg->module->module.LoadedPdbName) / sizeof(WCHAR));
2278 /* FIXME: we could have a finer grain here */
2279 msc_dbg->module->module.LineNumbers = TRUE;
2280 msc_dbg->module->module.GlobalSymbols = TRUE;
2281 msc_dbg->module->module.TypeInfo = TRUE;
2282 msc_dbg->module->module.SourceIndexed = TRUE;
2283 msc_dbg->module->module.Publics = TRUE;
2288 BOOL pdb_fetch_file_info(struct pdb_lookup* pdb_lookup)
2290 HANDLE hFile, hMap = NULL;
2294 if ((hFile = CreateFileA(pdb_lookup->filename, GENERIC_READ, FILE_SHARE_READ, NULL,
2295 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE ||
2296 ((hMap = CreateFileMappingW(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) == NULL) ||
2297 ((image = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) == NULL))
2299 WARN("Unable to open .PDB file: %s\n", pdb_lookup->filename);
2304 pdb_init(pdb_lookup, image, TRUE);
2305 pdb_free_lookup(pdb_lookup);
2308 if (image) UnmapViewOfFile(image);
2309 if (hMap) CloseHandle(hMap);
2310 if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile);
2315 /*========================================================================
2316 * Process CodeView debug information.
2319 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
2320 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
2321 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
2322 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
2323 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
2325 static BOOL codeview_process_info(const struct process* pcs,
2326 const struct msc_debug_info* msc_dbg)
2328 const DWORD* signature = (const DWORD*)msc_dbg->root;
2330 struct pdb_lookup pdb_lookup;
2332 TRACE("Processing signature %.4s\n", (const char*)signature);
2336 case CODEVIEW_NB09_SIG:
2337 case CODEVIEW_NB11_SIG:
2339 const OMFSignature* cv = (const OMFSignature*)msc_dbg->root;
2340 const OMFDirHeader* hdr = (const OMFDirHeader*)(msc_dbg->root + cv->filepos);
2341 const OMFDirEntry* ent;
2342 const OMFDirEntry* prev;
2343 const OMFDirEntry* next;
2346 codeview_init_basic_types(msc_dbg->module);
2348 for (i = 0; i < hdr->cDir; i++)
2350 ent = (const OMFDirEntry*)((const BYTE*)hdr + hdr->cbDirHeader + i * hdr->cbDirEntry);
2351 if (ent->SubSection == sstGlobalTypes)
2353 const OMFGlobalTypes* types;
2354 struct codeview_type_parse ctp;
2356 types = (const OMFGlobalTypes*)(msc_dbg->root + ent->lfo);
2357 ctp.module = msc_dbg->module;
2358 ctp.offset = (const DWORD*)(types + 1);
2359 ctp.num = types->cTypes;
2360 ctp.table = (const BYTE*)(ctp.offset + types->cTypes);
2362 cv_current_module = &cv_zmodules[0];
2363 if (cv_current_module->allowed) FIXME("Already allowed ??\n");
2364 cv_current_module->allowed = TRUE;
2366 codeview_parse_type_table(&ctp);
2371 ent = (const OMFDirEntry*)((const BYTE*)hdr + hdr->cbDirHeader);
2372 for (i = 0; i < hdr->cDir; i++, ent = next)
2374 next = (i == hdr->cDir-1) ? NULL :
2375 (const OMFDirEntry*)((const BYTE*)ent + hdr->cbDirEntry);
2376 prev = (i == 0) ? NULL :
2377 (const OMFDirEntry*)((const BYTE*)ent - hdr->cbDirEntry);
2379 if (ent->SubSection == sstAlignSym)
2382 * Check the next and previous entry. If either is a
2383 * sstSrcModule, it contains the line number info for
2386 * FIXME: This is not a general solution!
2388 struct codeview_linetab* linetab = NULL;
2390 if (next && next->iMod == ent->iMod &&
2391 next->SubSection == sstSrcModule)
2392 linetab = codeview_snarf_linetab(msc_dbg->module,
2393 msc_dbg->root + next->lfo, next->cb,
2396 if (prev && prev->iMod == ent->iMod &&
2397 prev->SubSection == sstSrcModule)
2398 linetab = codeview_snarf_linetab(msc_dbg->module,
2399 msc_dbg->root + prev->lfo, prev->cb,
2402 codeview_snarf(msc_dbg, msc_dbg->root + ent->lfo, sizeof(DWORD),
2407 msc_dbg->module->module.SymType = SymCv;
2408 /* FIXME: we could have a finer grain here */
2409 msc_dbg->module->module.LineNumbers = TRUE;
2410 msc_dbg->module->module.GlobalSymbols = TRUE;
2411 msc_dbg->module->module.TypeInfo = TRUE;
2412 msc_dbg->module->module.SourceIndexed = TRUE;
2413 msc_dbg->module->module.Publics = TRUE;
2414 codeview_clear_type_table();
2419 case CODEVIEW_NB10_SIG:
2421 const CODEVIEW_PDB_DATA* pdb = (const CODEVIEW_PDB_DATA*)msc_dbg->root;
2422 pdb_lookup.filename = pdb->name;
2423 pdb_lookup.kind = PDB_JG;
2424 pdb_lookup.u.jg.timestamp = pdb->timestamp;
2425 pdb_lookup.u.jg.toc = NULL;
2426 pdb_lookup.age = pdb->unknown;
2427 ret = pdb_process_file(pcs, msc_dbg, &pdb_lookup);
2430 case CODEVIEW_RSDS_SIG:
2432 const OMFSignatureRSDS* rsds = (const OMFSignatureRSDS*)msc_dbg->root;
2434 TRACE("Got RSDS type of PDB file: guid=%s unk=%08x name=%s\n",
2435 wine_dbgstr_guid(&rsds->guid), rsds->unknown, rsds->name);
2436 pdb_lookup.filename = rsds->name;
2437 pdb_lookup.kind = PDB_DS;
2438 pdb_lookup.u.ds.guid = rsds->guid;
2439 pdb_lookup.u.ds.toc = NULL;
2440 pdb_lookup.age = rsds->unknown;
2441 ret = pdb_process_file(pcs, msc_dbg, &pdb_lookup);
2445 ERR("Unknown CODEVIEW signature %08x in module %s\n",
2446 *signature, debugstr_w(msc_dbg->module->module.ModuleName));
2451 msc_dbg->module->module.CVSig = *signature;
2452 memcpy(msc_dbg->module->module.CVData, msc_dbg->root,
2453 sizeof(msc_dbg->module->module.CVData));
2458 /*========================================================================
2459 * Process debug directory.
2461 BOOL pe_load_debug_directory(const struct process* pcs, struct module* module,
2462 const BYTE* mapping,
2463 const IMAGE_SECTION_HEADER* sectp, DWORD nsect,
2464 const IMAGE_DEBUG_DIRECTORY* dbg, int nDbg)
2468 struct msc_debug_info msc_dbg;
2470 msc_dbg.module = module;
2471 msc_dbg.nsect = nsect;
2472 msc_dbg.sectp = sectp;
2474 msc_dbg.omapp = NULL;
2480 /* First, watch out for OMAP data */
2481 for (i = 0; i < nDbg; i++)
2483 if (dbg[i].Type == IMAGE_DEBUG_TYPE_OMAP_FROM_SRC)
2485 msc_dbg.nomap = dbg[i].SizeOfData / sizeof(OMAP_DATA);
2486 msc_dbg.omapp = (const OMAP_DATA*)(mapping + dbg[i].PointerToRawData);
2491 /* Now, try to parse CodeView debug info */
2492 for (i = 0; i < nDbg; i++)
2494 if (dbg[i].Type == IMAGE_DEBUG_TYPE_CODEVIEW)
2496 msc_dbg.root = mapping + dbg[i].PointerToRawData;
2497 if ((ret = codeview_process_info(pcs, &msc_dbg))) goto done;
2501 /* If not found, try to parse COFF debug info */
2502 for (i = 0; i < nDbg; i++)
2504 if (dbg[i].Type == IMAGE_DEBUG_TYPE_COFF)
2506 msc_dbg.root = mapping + dbg[i].PointerToRawData;
2507 if ((ret = coff_process_info(&msc_dbg))) goto done;
2511 /* FIXME: this should be supported... this is the debug information for
2512 * functions compiled without a frame pointer (FPO = frame pointer omission)
2513 * the associated data helps finding out the relevant information
2515 for (i = 0; i < nDbg; i++)
2516 if (dbg[i].Type == IMAGE_DEBUG_TYPE_FPO)
2517 FIXME("This guy has FPO information\n");
2521 #define FRAME_TRAP 1
2524 typedef struct _FPO_DATA
2526 DWORD ulOffStart; /* offset 1st byte of function code */
2527 DWORD cbProcSize; /* # bytes in function */
2528 DWORD cdwLocals; /* # bytes in locals/4 */
2529 WORD cdwParams; /* # bytes in params/4 */
2531 WORD cbProlog : 8; /* # bytes in prolog */
2532 WORD cbRegs : 3; /* # regs saved */
2533 WORD fHasSEH : 1; /* TRUE if SEH in func */
2534 WORD fUseBP : 1; /* TRUE if EBP has been allocated */
2535 WORD reserved : 1; /* reserved for future use */
2536 WORD cbFrame : 2; /* frame type */
2543 ERR("Got a page fault while loading symbols\n");