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, 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
;
499 int value
, leaf_len
, vpoff
, vplen
;
500 const struct p_string
* p_name
;
502 struct symt
* subtype
;
503 const unsigned short int* p_vboff
;
505 symt
= symt_new_udt(module
, NULL
, 0, UdtStruct
/* don't care */);
506 while (ptr
- list
< len
)
508 const union codeview_fieldtype
* type
= (const union codeview_fieldtype
*)ptr
;
510 if (*ptr
>= 0xf0) /* LF_PAD... */
516 switch (type
->generic
.id
)
519 leaf_len
= numeric_leaf(&value
, &type
->bclass_v1
.offset
);
521 /* FIXME: ignored for now */
523 ptr
+= 2 + 2 + 2 + leaf_len
;
527 leaf_len
= numeric_leaf(&value
, &type
->bclass_v2
.offset
);
529 /* FIXME: ignored for now */
531 ptr
+= 2 + 2 + 4 + leaf_len
;
537 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v1
.vbpoff
);
538 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v1
.vbpoff
+ leaf_len
);
539 vplen
= numeric_leaf(&vpoff
, p_vboff
);
541 /* FIXME: ignored for now */
543 ptr
+= 2 + 2 + 2 + 2 + leaf_len
+ vplen
;
550 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v2
.vbpoff
);
551 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v2
.vbpoff
+ leaf_len
);
552 vplen
= numeric_leaf(&vpoff
, p_vboff
);
554 /* FIXME: ignored for now */
556 ptr
+= 2 + 2 + 4 + 4 + leaf_len
+ vplen
;
561 leaf_len
= numeric_leaf(&value
, &type
->member_v1
.offset
);
562 p_name
= (const struct p_string
*)((const char*)&type
->member_v1
.offset
+ leaf_len
);
563 subtype
= codeview_get_type(type
->member_v1
.type
, TRUE
);
565 if (!subtype
|| subtype
->tag
!= SymTagCVBitField
)
568 if (subtype
) symt_get_info(subtype
, TI_GET_LENGTH
, &elem_size
);
569 symt_add_udt_element(module
, symt
, terminate_string(p_name
),
570 codeview_get_type(type
->member_v1
.type
, TRUE
),
571 value
<< 3, elem_size
<< 3);
575 struct codeview_bitfield
* cvbf
= (struct codeview_bitfield
*)subtype
;
576 symt_add_udt_element(module
, symt
, terminate_string(p_name
),
577 codeview_get_type(cvbf
->subtype
, FALSE
),
578 cvbf
->bitposition
, cvbf
->bitlength
);
581 ptr
+= 2 + 2 + 2 + leaf_len
+ (1 + p_name
->namelen
);
585 leaf_len
= numeric_leaf(&value
, &type
->member_v2
.offset
);
586 p_name
= (const struct p_string
*)((const unsigned char*)&type
->member_v2
.offset
+ leaf_len
);
587 subtype
= codeview_get_type(type
->member_v2
.type
, TRUE
);
589 if (!subtype
|| subtype
->tag
!= SymTagCVBitField
)
592 if (subtype
) symt_get_info(subtype
, TI_GET_LENGTH
, &elem_size
);
593 symt_add_udt_element(module
, symt
, terminate_string(p_name
),
594 subtype
, value
<< 3, elem_size
<< 3);
598 struct codeview_bitfield
* cvbf
= (struct codeview_bitfield
*)subtype
;
599 symt_add_udt_element(module
, symt
, terminate_string(p_name
),
600 codeview_get_type(cvbf
->subtype
, FALSE
),
601 cvbf
->bitposition
, cvbf
->bitlength
);
604 ptr
+= 2 + 2 + 4 + leaf_len
+ (1 + p_name
->namelen
);
608 leaf_len
= numeric_leaf(&value
, &type
->member_v3
.offset
);
609 c_name
= (const char*)&type
->member_v3
.offset
+ leaf_len
;
610 subtype
= codeview_get_type(type
->member_v3
.type
, TRUE
);
612 if (!subtype
|| subtype
->tag
!= SymTagCVBitField
)
615 if (subtype
) symt_get_info(subtype
, TI_GET_LENGTH
, &elem_size
);
616 symt_add_udt_element(module
, symt
, c_name
,
617 subtype
, value
<< 3, elem_size
<< 3);
621 struct codeview_bitfield
* cvbf
= (struct codeview_bitfield
*)subtype
;
622 symt_add_udt_element(module
, symt
, c_name
,
623 codeview_get_type(cvbf
->subtype
, FALSE
),
624 cvbf
->bitposition
, cvbf
->bitlength
);
627 ptr
+= 2 + 2 + 4 + leaf_len
+ (strlen(c_name
) + 1);
631 /* FIXME: ignored for now */
632 ptr
+= 2 + 2 + 2 + (1 + type
->stmember_v1
.p_name
.namelen
);
636 /* FIXME: ignored for now */
637 ptr
+= 2 + 4 + 2 + (1 + type
->stmember_v2
.p_name
.namelen
);
641 /* FIXME: ignored for now */
642 ptr
+= 2 + 2 + 2 + (1 + type
->method_v1
.p_name
.namelen
);
646 /* FIXME: ignored for now */
647 ptr
+= 2 + 2 + 4 + (1 + type
->method_v2
.p_name
.namelen
);
651 /* FIXME: ignored for now */
652 ptr
+= 2 + 2 + (1 + type
->nesttype_v1
.p_name
.namelen
);
656 /* FIXME: ignored for now */
657 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype_v2
.p_name
.namelen
);
661 /* FIXME: ignored for now */
666 /* FIXME: ignored for now */
670 case LF_ONEMETHOD_V1
:
671 /* FIXME: ignored for now */
672 switch ((type
->onemethod_v1
.attribute
>> 2) & 7)
674 case 4: case 6: /* (pure) introducing virtual method */
675 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt_v1
.p_name
.namelen
);
679 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod_v1
.p_name
.namelen
);
684 case LF_ONEMETHOD_V2
:
685 /* FIXME: ignored for now */
686 switch ((type
->onemethod_v2
.attribute
>> 2) & 7)
688 case 4: case 6: /* (pure) introducing virtual method */
689 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod_virt_v2
.p_name
.namelen
);
693 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod_v2
.p_name
.namelen
);
699 FIXME("Unsupported type %04x in STRUCT field list\n", type
->generic
.id
);
704 return codeview_add_type(typeno
, &symt
->symt
);
707 static int codeview_add_type_enum(struct module
* module
, unsigned int typeno
,
708 const char* name
, unsigned int fieldlist
)
710 struct symt_enum
* symt
= symt_new_enum(module
, name
);
711 struct symt
* list
= codeview_get_type(fieldlist
, FALSE
);
713 /* FIXME: this is rather ugly !!! */
714 if (list
) symt
->vchildren
= ((struct symt_enum
*)list
)->vchildren
;
716 return codeview_add_type(typeno
, &symt
->symt
);
719 static int codeview_add_type_struct(struct module
* module
, unsigned int typeno
,
720 const char* name
, int structlen
,
721 unsigned int fieldlist
, enum UdtKind kind
)
723 struct symt_udt
* symt
= symt_new_udt(module
, name
, structlen
, kind
);
724 struct symt
* list
= codeview_get_type(fieldlist
, FALSE
);
726 /* FIXME: this is rather ugly !!! */
727 if (list
) symt
->vchildren
= ((struct symt_udt
*)list
)->vchildren
;
729 return codeview_add_type(typeno
, &symt
->symt
);
732 static int codeview_new_func_signature(struct module
* module
, unsigned typeno
,
736 symt
= &symt_new_function_signature(module
,
737 codeview_get_type(ret_type
, FALSE
))->symt
;
738 return codeview_add_type(typeno
, symt
);
741 static int codeview_parse_type_table(struct module
* module
, const char* table
,
744 unsigned int curr_type
= 0x1000;
745 const char* ptr
= table
;
747 const union codeview_type
* type
;
749 const struct p_string
* p_name
;
752 while (ptr
- table
< len
)
755 type
= (const union codeview_type
*)ptr
;
757 switch (type
->generic
.id
)
760 /* FIXME: we don't handle modifiers,
761 * but readd previous type on the curr_type
763 WARN("Modifier on %x: %s%s%s%s\n",
764 type
->modifier_v1
.type
,
765 type
->modifier_v1
.attribute
& 0x01 ? "const " : "",
766 type
->modifier_v1
.attribute
& 0x02 ? "volatile " : "",
767 type
->modifier_v1
.attribute
& 0x04 ? "unaligned " : "",
768 type
->modifier_v1
.attribute
& ~0x07 ? "unknown " : "");
769 codeview_add_type(curr_type
,
770 codeview_get_type(type
->modifier_v1
.type
, FALSE
));
773 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
774 WARN("Modifier on %x: %s%s%s%s\n",
775 type
->modifier_v2
.type
,
776 type
->modifier_v2
.attribute
& 0x01 ? "const " : "",
777 type
->modifier_v2
.attribute
& 0x02 ? "volatile " : "",
778 type
->modifier_v2
.attribute
& 0x04 ? "unaligned " : "",
779 type
->modifier_v2
.attribute
& ~0x07 ? "unknown " : "");
780 codeview_add_type(curr_type
,
781 codeview_get_type(type
->modifier_v2
.type
, FALSE
));
785 retv
= codeview_add_type_pointer(module
, curr_type
,
786 type
->pointer_v1
.datatype
);
789 retv
= codeview_add_type_pointer(module
, curr_type
,
790 type
->pointer_v2
.datatype
);
794 leaf_len
= numeric_leaf(&value
, &type
->array_v1
.arrlen
);
795 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v1
.arrlen
+ leaf_len
);
797 retv
= codeview_add_type_array(module
, curr_type
, terminate_string(p_name
),
798 type
->array_v1
.elemtype
, value
);
801 leaf_len
= numeric_leaf(&value
, &type
->array_v2
.arrlen
);
802 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v2
.arrlen
+ leaf_len
);
804 retv
= codeview_add_type_array(module
, curr_type
, terminate_string(p_name
),
805 type
->array_v2
.elemtype
, value
);
808 leaf_len
= numeric_leaf(&value
, &type
->array_v3
.arrlen
);
809 c_name
= (const char*)&type
->array_v3
.arrlen
+ leaf_len
;
811 retv
= codeview_add_type_array(module
, curr_type
, c_name
,
812 type
->array_v3
.elemtype
, value
);
816 /* a bitfield is a CodeView specific data type which represent a bitfield
817 * in a structure or a class. For now, we store it in a SymTag-like type
818 * (so that the rest of the process is seamless), but check at udt
819 * inclusion type for its presence
821 retv
= codeview_add_type_bitfield(curr_type
, type
->bitfield_v1
.bitoff
,
822 type
->bitfield_v1
.nbits
,
823 type
->bitfield_v1
.type
);
826 retv
= codeview_add_type_bitfield(curr_type
, type
->bitfield_v2
.bitoff
,
827 type
->bitfield_v2
.nbits
,
828 type
->bitfield_v2
.type
);
830 case LF_FIELDLIST_V1
:
831 case LF_FIELDLIST_V2
:
834 * A 'field list' is a CodeView-specific data type which doesn't
835 * directly correspond to any high-level data type. It is used
836 * to hold the collection of members of a struct, class, union
837 * or enum type. The actual definition of that type will follow
838 * later, and refer to the field list definition record.
840 * As we don't have a field list type ourselves, we look ahead
841 * in the field list to try to find out whether this field list
842 * will be used for an enum or struct type, and create a dummy
843 * type of the corresponding sort. Later on, the definition of
844 * the 'real' type will copy the member / enumeration data.
846 const char* list
= type
->fieldlist
.list
;
847 int len
= (ptr
+ type
->generic
.len
+ 2) - list
;
849 if (((const union codeview_fieldtype
*)list
)->generic
.id
== LF_ENUMERATE_V1
||
850 ((const union codeview_fieldtype
*)list
)->generic
.id
== LF_ENUMERATE_V3
)
851 retv
= codeview_add_type_enum_field_list(module
, curr_type
, list
, len
);
853 retv
= codeview_add_type_struct_field_list(module
, curr_type
, list
, len
);
857 case LF_STRUCTURE_V1
:
859 leaf_len
= numeric_leaf(&value
, &type
->struct_v1
.structlen
);
860 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v1
.structlen
+ leaf_len
);
862 retv
= codeview_add_type_struct(module
, curr_type
, terminate_string(p_name
),
863 value
, type
->struct_v1
.fieldlist
,
864 type
->generic
.id
== LF_CLASS_V1
? UdtClass
: UdtStruct
);
867 case LF_STRUCTURE_V2
:
869 leaf_len
= numeric_leaf(&value
, &type
->struct_v2
.structlen
);
870 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v2
.structlen
+ leaf_len
);
872 retv
= codeview_add_type_struct(module
, curr_type
, terminate_string(p_name
),
873 value
, type
->struct_v2
.fieldlist
,
874 type
->generic
.id
== LF_CLASS_V2
? UdtClass
: UdtStruct
);
877 case LF_STRUCTURE_V3
:
879 leaf_len
= numeric_leaf(&value
, &type
->struct_v3
.structlen
);
880 c_name
= (const char*)&type
->struct_v3
.structlen
+ leaf_len
;
882 retv
= codeview_add_type_struct(module
, curr_type
, c_name
,
883 value
, type
->struct_v3
.fieldlist
,
884 type
->generic
.id
== LF_CLASS_V3
? UdtClass
: UdtStruct
);
888 leaf_len
= numeric_leaf(&value
, &type
->union_v1
.un_len
);
889 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v1
.un_len
+ leaf_len
);
891 retv
= codeview_add_type_struct(module
, curr_type
, terminate_string(p_name
),
892 value
, type
->union_v1
.fieldlist
, UdtUnion
);
895 leaf_len
= numeric_leaf(&value
, &type
->union_v2
.un_len
);
896 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v2
.un_len
+ leaf_len
);
898 retv
= codeview_add_type_struct(module
, curr_type
, terminate_string(p_name
),
899 value
, type
->union_v2
.fieldlist
, UdtUnion
);
902 leaf_len
= numeric_leaf(&value
, &type
->union_v3
.un_len
);
903 c_name
= (const char*)&type
->union_v3
.un_len
+ leaf_len
;
905 retv
= codeview_add_type_struct(module
, curr_type
, c_name
,
906 value
, type
->union_v3
.fieldlist
, UdtUnion
);
909 retv
= codeview_add_type_enum(module
, curr_type
, terminate_string(&type
->enumeration_v1
.p_name
),
910 type
->enumeration_v1
.field
);
914 retv
= codeview_add_type_enum(module
, curr_type
, terminate_string(&type
->enumeration_v2
.p_name
),
915 type
->enumeration_v2
.field
);
918 retv
= codeview_add_type_enum(module
, curr_type
, type
->enumeration_v3
.name
,
919 type
->enumeration_v3
.field
);
921 case LF_PROCEDURE_V1
:
922 retv
= codeview_new_func_signature(module
, curr_type
,
923 type
->procedure_v1
.rvtype
);
925 case LF_PROCEDURE_V2
:
926 retv
= codeview_new_func_signature(module
, curr_type
,
927 type
->procedure_v2
.rvtype
);
929 case LF_MFUNCTION_V1
:
930 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
931 * nor class information, this would just do for now
933 retv
= codeview_new_func_signature(module
, curr_type
,
934 type
->mfunction_v1
.rvtype
);
936 case LF_MFUNCTION_V2
:
937 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
938 * nor class information, this would just do for now
940 retv
= codeview_new_func_signature(module
, curr_type
,
941 type
->mfunction_v2
.rvtype
);
948 FIXME("Not adding parameters' types to function signature\n");
953 FIXME("Unsupported type-id leaf %x\n", type
->generic
.id
);
954 dump(type
, 2 + type
->generic
.len
);
957 if (!retv
) return FALSE
;
959 ptr
+= type
->generic
.len
+ 2;
965 /*========================================================================
966 * Process CodeView line number information.
969 static struct codeview_linetab
* codeview_snarf_linetab(struct module
* module
,
970 const char* linetab
, int size
,
974 char filename
[PATH_MAX
];
975 const unsigned int* filetab
;
976 const struct p_string
* p_fn
;
979 struct codeview_linetab
* lt_hdr
;
980 const unsigned int* lt_ptr
;
985 const struct startend
* start
;
987 struct symt_compiland
* compiland
;
990 * Now get the important bits.
996 filetab
= (const unsigned int*) pnt
.c
;
999 * Now count up the number of segments in the file.
1002 for (i
= 0; i
< nfile
; i
++)
1004 pnt2
.c
= linetab
+ filetab
[i
];
1009 * Next allocate the header we will be returning.
1010 * There is one header for each segment, so that we can reach in
1011 * and pull bits as required.
1013 lt_hdr
= (struct codeview_linetab
*)
1014 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nseg
+ 1) * sizeof(*lt_hdr
));
1021 * Now fill the header we will be returning, one for each segment.
1022 * Note that this will basically just contain pointers into the existing
1023 * line table, and we do not actually copy any additional information
1024 * or allocate any additional memory.
1028 for (i
= 0; i
< nfile
; i
++)
1031 * Get the pointer into the segment information.
1033 pnt2
.c
= linetab
+ filetab
[i
];
1034 file_segcount
= *pnt2
.s
;
1037 lt_ptr
= (const unsigned int*) pnt2
.c
;
1038 start
= (const struct startend
*)(lt_ptr
+ file_segcount
);
1041 * Now snarf the filename for all of the segments for this file.
1045 p_fn
= (const struct p_string
*)(start
+ file_segcount
);
1046 memset(filename
, 0, sizeof(filename
));
1047 memcpy(filename
, p_fn
->name
, p_fn
->namelen
);
1048 compiland
= symt_new_compiland(module
, filename
);
1051 compiland
= symt_new_compiland(module
, (const char*)(start
+ file_segcount
));
1053 for (k
= 0; k
< file_segcount
; k
++, this_seg
++)
1055 pnt2
.c
= linetab
+ lt_ptr
[k
];
1056 lt_hdr
[this_seg
].start
= start
[k
].start
;
1057 lt_hdr
[this_seg
].end
= start
[k
].end
;
1058 lt_hdr
[this_seg
].compiland
= compiland
;
1059 lt_hdr
[this_seg
].segno
= *pnt2
.s
++;
1060 lt_hdr
[this_seg
].nline
= *pnt2
.s
++;
1061 lt_hdr
[this_seg
].offtab
= pnt2
.ui
;
1062 lt_hdr
[this_seg
].linetab
= (const unsigned short*)(pnt2
.ui
+ lt_hdr
[this_seg
].nline
);
1072 /*========================================================================
1073 * Process CodeView symbol information.
1076 static unsigned int codeview_map_offset(const struct msc_debug_info
* msc_dbg
,
1077 unsigned int offset
)
1079 int nomap
= msc_dbg
->nomap
;
1080 const OMAP_DATA
* omapp
= msc_dbg
->omapp
;
1083 if (!nomap
|| !omapp
) return offset
;
1085 /* FIXME: use binary search */
1086 for (i
= 0; i
< nomap
- 1; i
++)
1087 if (omapp
[i
].from
<= offset
&& omapp
[i
+1].from
> offset
)
1088 return !omapp
[i
].to
? 0 : omapp
[i
].to
+ (offset
- omapp
[i
].from
);
1093 static const struct codeview_linetab
*
1094 codeview_get_linetab(const struct codeview_linetab
* linetab
,
1095 unsigned seg
, unsigned offset
)
1098 * Check whether we have line number information
1102 for (; linetab
->linetab
; linetab
++)
1103 if (linetab
->segno
== seg
&&
1104 linetab
->start
<= offset
&& linetab
->end
> offset
)
1106 if (!linetab
->linetab
) linetab
= NULL
;
1111 static unsigned codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1112 unsigned seg
, unsigned offset
)
1114 int nsect
= msc_dbg
->nsect
;
1115 const IMAGE_SECTION_HEADER
* sectp
= msc_dbg
->sectp
;
1117 if (!seg
|| seg
> nsect
) return 0;
1118 return msc_dbg
->module
->module
.BaseOfImage
+
1119 codeview_map_offset(msc_dbg
, sectp
[seg
-1].VirtualAddress
+ offset
);
1122 static void codeview_add_func_linenum(struct module
* module
,
1123 struct symt_function
* func
,
1124 const struct codeview_linetab
* linetab
,
1125 unsigned offset
, unsigned size
)
1129 if (!linetab
) return;
1130 for (i
= 0; i
< linetab
->nline
; i
++)
1132 if (linetab
->offtab
[i
] >= offset
&& linetab
->offtab
[i
] < offset
+ size
)
1134 symt_add_func_line(module
, func
, linetab
->compiland
->source
,
1135 linetab
->linetab
[i
], linetab
->offtab
[i
] - offset
);
1140 static int codeview_snarf(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1141 int offset
, int size
,
1142 struct codeview_linetab
* linetab
)
1144 struct symt_function
* curr_func
= NULL
;
1146 const struct codeview_linetab
* flt
;
1147 struct symt_block
* block
= NULL
;
1152 * Loop over the different types of records and whenever we
1153 * find something we are interested in, record it and move on.
1155 for (i
= offset
; i
< size
; i
+= length
)
1157 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1158 length
= sym
->generic
.len
+ 2;
1159 if (length
& 3) FIXME("unpadded len %u\n", length
+ 2);
1161 switch (sym
->generic
.id
)
1164 * Global and local data symbols. We don't associate these
1165 * with any given source file.
1169 flt
= codeview_get_linetab(linetab
, sym
->data_v1
.segment
, sym
->data_v1
.offset
);
1170 symt_new_global_variable(msc_dbg
->module
,
1171 flt
? flt
->compiland
: NULL
,
1172 terminate_string(&sym
->data_v1
.p_name
), sym
->generic
.id
== S_LDATA_V1
,
1173 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
),
1175 codeview_get_type(sym
->data_v1
.symtype
, FALSE
));
1179 flt
= codeview_get_linetab(linetab
, sym
->data_v2
.segment
, sym
->data_v2
.offset
);
1180 name
= terminate_string(&sym
->data_v2
.p_name
);
1182 symt_new_global_variable(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1183 name
, sym
->generic
.id
== S_LDATA_V2
,
1184 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
),
1186 codeview_get_type(sym
->data_v2
.symtype
, FALSE
));
1190 flt
= codeview_get_linetab(linetab
, sym
->data_v3
.segment
, sym
->data_v3
.offset
);
1191 if (*sym
->data_v3
.name
)
1192 symt_new_global_variable(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1194 sym
->generic
.id
== S_LDATA_V3
,
1195 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1197 codeview_get_type(sym
->data_v3
.symtype
, FALSE
));
1200 case S_PUB_V1
: /* FIXME is this really a 'data_v1' structure ?? */
1201 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1203 flt
= codeview_get_linetab(linetab
, sym
->data_v1
.segment
, sym
->data_v1
.offset
);
1204 symt_new_public(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1205 terminate_string(&sym
->data_v1
.p_name
),
1206 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
),
1207 0, TRUE
/* FIXME */, TRUE
/* FIXME */);
1210 case S_PUB_V2
: /* FIXME is this really a 'data_v2' structure ?? */
1211 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1213 flt
= codeview_get_linetab(linetab
, sym
->data_v2
.segment
, sym
->data_v2
.offset
);
1214 symt_new_public(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1215 terminate_string(&sym
->data_v2
.p_name
),
1216 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
),
1217 0, TRUE
/* FIXME */, TRUE
/* FIXME */);
1222 * Sort of like a global function, but it just points
1223 * to a thunk, which is a stupid name for what amounts to
1224 * a PLT slot in the normal jargon that everyone else uses.
1227 flt
= codeview_get_linetab(linetab
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
);
1228 symt_new_thunk(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1229 terminate_string(&sym
->thunk_v1
.p_name
), sym
->thunk_v1
.thtype
,
1230 codeview_get_address(msc_dbg
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
),
1231 sym
->thunk_v1
.thunk_len
);
1234 flt
= codeview_get_linetab(linetab
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
);
1235 symt_new_thunk(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1236 sym
->thunk_v3
.name
, sym
->thunk_v3
.thtype
,
1237 codeview_get_address(msc_dbg
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
),
1238 sym
->thunk_v3
.thunk_len
);
1242 * Global and static functions.
1246 flt
= codeview_get_linetab(linetab
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
);
1247 if (curr_func
) FIXME("nested function\n");
1248 curr_func
= symt_new_function(msc_dbg
->module
,
1249 flt
? flt
->compiland
: NULL
,
1250 terminate_string(&sym
->proc_v1
.p_name
),
1251 codeview_get_address(msc_dbg
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
),
1252 sym
->proc_v1
.proc_len
,
1253 codeview_get_type(sym
->proc_v1
.proctype
, FALSE
));
1254 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1255 sym
->proc_v1
.offset
, sym
->proc_v1
.proc_len
);
1256 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, sym
->proc_v1
.debug_start
, NULL
);
1257 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, sym
->proc_v1
.debug_end
, NULL
);
1261 flt
= codeview_get_linetab(linetab
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
);
1262 if (curr_func
) FIXME("nested function\n");
1263 curr_func
= symt_new_function(msc_dbg
->module
,
1264 flt
? flt
->compiland
: NULL
,
1265 terminate_string(&sym
->proc_v2
.p_name
),
1266 codeview_get_address(msc_dbg
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
),
1267 sym
->proc_v2
.proc_len
,
1268 codeview_get_type(sym
->proc_v2
.proctype
, FALSE
));
1269 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1270 sym
->proc_v2
.offset
, sym
->proc_v2
.proc_len
);
1271 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, sym
->proc_v2
.debug_start
, NULL
);
1272 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, sym
->proc_v2
.debug_end
, NULL
);
1276 flt
= codeview_get_linetab(linetab
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
);
1277 if (curr_func
) FIXME("nested function\n");
1278 curr_func
= symt_new_function(msc_dbg
->module
,
1279 flt
? flt
->compiland
: NULL
,
1281 codeview_get_address(msc_dbg
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
),
1282 sym
->proc_v3
.proc_len
,
1283 codeview_get_type(sym
->proc_v3
.proctype
, FALSE
));
1284 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1285 sym
->proc_v3
.offset
, sym
->proc_v3
.proc_len
);
1286 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, sym
->proc_v3
.debug_start
, NULL
);
1287 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, sym
->proc_v3
.debug_end
, NULL
);
1290 * Function parameters and stack variables.
1293 symt_add_func_local(msc_dbg
->module
, curr_func
, 0, sym
->stack_v1
.offset
,
1294 block
, codeview_get_type(sym
->stack_v1
.symtype
, FALSE
),
1295 terminate_string(&sym
->stack_v1
.p_name
));
1298 symt_add_func_local(msc_dbg
->module
, curr_func
, 0, sym
->stack_v2
.offset
,
1299 block
, codeview_get_type(sym
->stack_v2
.symtype
, FALSE
),
1300 terminate_string(&sym
->stack_v2
.p_name
));
1303 symt_add_func_local(msc_dbg
->module
, curr_func
, 0, sym
->stack_v3
.offset
,
1304 block
, codeview_get_type(sym
->stack_v3
.symtype
, FALSE
),
1305 sym
->stack_v3
.name
);
1309 symt_add_func_local(msc_dbg
->module
, curr_func
, 0, sym
->register_v1
.reg
,
1310 block
, codeview_get_type(sym
->register_v1
.type
, FALSE
),
1311 terminate_string(&sym
->register_v1
.p_name
));
1314 symt_add_func_local(msc_dbg
->module
, curr_func
, 0, sym
->register_v2
.reg
,
1315 block
, codeview_get_type(sym
->register_v2
.type
, FALSE
),
1316 terminate_string(&sym
->register_v2
.p_name
));
1320 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1321 codeview_get_address(msc_dbg
, sym
->block_v1
.segment
, sym
->block_v1
.offset
),
1322 sym
->block_v1
.length
);
1325 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1326 codeview_get_address(msc_dbg
, sym
->block_v3
.segment
, sym
->block_v3
.offset
),
1327 sym
->block_v3
.length
);
1333 block
= symt_close_func_block(msc_dbg
->module
, curr_func
, block
, 0);
1337 symt_normalize_function(msc_dbg
->module
, curr_func
);
1342 /* FIXME: we should use this as a compiland, instead of guessing it on the fly */
1343 case S_COMPILAND_V1
:
1344 TRACE("S-Compiland-V1e %x %s\n",
1345 sym
->compiland_v1
.unknown
,
1346 terminate_string(&sym
->compiland_v1
.p_name
));
1349 case S_COMPILAND_V2
:
1350 TRACE("S-Compiland-V2 %s\n",
1351 terminate_string(&sym
->compiland_v2
.p_name
));
1352 if (TRACE_ON(dbghelp_msc
))
1354 const char* ptr1
= sym
->compiland_v2
.p_name
.name
+ sym
->compiland_v2
.p_name
.namelen
;
1358 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1359 TRACE("\t%s => %s\n", ptr1
, ptr2
);
1360 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1364 case S_COMPILAND_V3
:
1365 TRACE("S-Compiland-V3 %s\n", sym
->compiland_v3
.name
);
1366 if (TRACE_ON(dbghelp_msc
))
1368 const char* ptr1
= sym
->compiland_v3
.name
+ strlen(sym
->compiland_v3
.name
);
1372 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1373 TRACE("\t%s => %s\n", ptr1
, ptr2
);
1374 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1380 TRACE("S-ObjName %.*s\n", ((const BYTE
*)sym
)[8], (const BYTE
*)sym
+ 9);
1386 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1387 codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
) - curr_func
->address
,
1388 terminate_string(&sym
->label_v1
.p_name
));
1391 FIXME("No current function for label %s\n",
1392 terminate_string(&sym
->label_v1
.p_name
));
1397 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1398 codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
) - curr_func
->address
,
1399 sym
->label_v3
.name
);
1402 FIXME("No current function for label %s\n", sym
->label_v3
.name
);
1408 const struct p_string
* name
;
1412 vlen
= numeric_leaf(&val
, &sym
->constant_v1
.cvalue
);
1413 name
= (const struct p_string
*)((const char*)&sym
->constant_v1
.cvalue
+ vlen
);
1414 se
= codeview_get_type(sym
->constant_v1
.type
, FALSE
);
1416 else if (se
->tag
== SymTagEnum
) x
= ((struct symt_enum
*)se
)->name
;
1419 TRACE("S-Constant-V1 %u %s %x (%s)\n",
1420 val
, terminate_string(name
), sym
->constant_v1
.type
, x
);
1421 /* FIXME: we should add this as a constant value */
1427 const struct p_string
* name
;
1431 vlen
= numeric_leaf(&val
, &sym
->constant_v2
.cvalue
);
1432 name
= (const struct p_string
*)((const char*)&sym
->constant_v2
.cvalue
+ vlen
);
1433 se
= codeview_get_type(sym
->constant_v2
.type
, FALSE
);
1435 else if (se
->tag
== SymTagEnum
) x
= ((struct symt_enum
*)se
)->name
;
1438 TRACE("S-Constant-V2 %u %s %x (%s)\n",
1439 val
, terminate_string(name
), sym
->constant_v2
.type
, x
);
1440 /* FIXME: we should add this as a constant value */
1450 vlen
= numeric_leaf(&val
, &sym
->constant_v3
.cvalue
);
1451 name
= (const char*)&sym
->constant_v3
.cvalue
+ vlen
;
1452 se
= codeview_get_type(sym
->constant_v3
.type
, FALSE
);
1454 else if (se
->tag
== SymTagEnum
) x
= ((struct symt_enum
*)se
)->name
;
1457 TRACE("S-Constant-V3 %u %s %x (%s)\n",
1458 val
, name
, sym
->constant_v3
.type
, x
);
1459 /* FIXME: we should add this as a constant value */
1464 if (sym
->udt_v1
.type
)
1466 if ((symt
= codeview_get_type(sym
->udt_v1
.type
, FALSE
)))
1467 symt_new_typedef(msc_dbg
->module
, symt
,
1468 terminate_string(&sym
->udt_v1
.p_name
));
1470 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1471 terminate_string(&sym
->udt_v1
.p_name
), sym
->udt_v1
.type
);
1475 if (sym
->udt_v2
.type
)
1477 if ((symt
= codeview_get_type(sym
->udt_v2
.type
, FALSE
)))
1478 symt_new_typedef(msc_dbg
->module
, symt
,
1479 terminate_string(&sym
->udt_v2
.p_name
));
1481 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1482 terminate_string(&sym
->udt_v2
.p_name
), sym
->udt_v2
.type
);
1486 if (sym
->udt_v3
.type
)
1488 if ((symt
= codeview_get_type(sym
->udt_v3
.type
, FALSE
)))
1489 symt_new_typedef(msc_dbg
->module
, symt
, sym
->udt_v3
.name
);
1491 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1492 sym
->udt_v3
.name
, sym
->udt_v3
.type
);
1497 * These are special, in that they are always followed by an
1498 * additional length-prefixed string which is *not* included
1499 * into the symbol length count. We need to skip it.
1504 name
= (const char*)sym
+ length
;
1505 length
+= (*name
+ 1 + 3) & ~3;
1509 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1511 flt
= codeview_get_linetab(linetab
, sym
->data_v3
.segment
, sym
->data_v3
.offset
);
1512 symt_new_public(msc_dbg
->module
,
1513 flt
? flt
->compiland
: NULL
,
1515 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1516 0, FALSE
/* FIXME */, FALSE
);
1519 case S_PUB_FUNC1_V3
:
1520 case S_PUB_FUNC2_V3
: /* using a data_v3 isn't what we'd expect */
1521 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1523 flt
= codeview_get_linetab(linetab
, sym
->data_v3
.segment
, sym
->data_v3
.offset
);
1524 symt_new_public(msc_dbg
->module
,
1525 flt
? flt
->compiland
: NULL
,
1527 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1528 0, TRUE
/* FIXME */, TRUE
);
1532 case S_MSTOOL_V3
: /* just to silence a few warnings */
1536 FIXME("Unsupported symbol id %x\n", sym
->generic
.id
);
1537 dump(sym
, 2 + sym
->generic
.len
);
1542 if (curr_func
) symt_normalize_function(msc_dbg
->module
, curr_func
);
1544 HeapFree(GetProcessHeap(), 0, linetab
);
1548 /*========================================================================
1554 const char* filename
;
1555 enum {PDB_JG
, PDB_DS
} kind
;
1561 struct PDB_JG_TOC
* toc
;
1566 struct PDB_DS_TOC
* toc
;
1571 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
,
1577 if (!size
) return NULL
;
1579 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1580 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
1582 for (i
= 0; i
< num_blocks
; i
++)
1583 memcpy(buffer
+ i
* pdb
->block_size
,
1584 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
1589 static void* pdb_ds_read(const struct PDB_DS_HEADER
* pdb
, const DWORD
* block_list
,
1595 if (!size
) return NULL
;
1597 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1598 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
1600 for (i
= 0; i
< num_blocks
; i
++)
1601 memcpy(buffer
+ i
* pdb
->block_size
,
1602 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
1607 static void* pdb_read_jg_file(const struct PDB_JG_HEADER
* pdb
,
1608 const struct PDB_JG_TOC
* toc
, DWORD file_nr
)
1610 const WORD
* block_list
;
1613 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
1615 block_list
= (const WORD
*) &toc
->file
[toc
->num_files
];
1616 for (i
= 0; i
< file_nr
; i
++)
1617 block_list
+= (toc
->file
[i
].size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1619 return pdb_jg_read(pdb
, block_list
, toc
->file
[file_nr
].size
);
1622 static void* pdb_read_ds_file(const struct PDB_DS_HEADER
* pdb
,
1623 const struct PDB_DS_TOC
* toc
, DWORD file_nr
)
1625 const DWORD
* block_list
;
1628 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
1630 if (toc
->file_size
[file_nr
] == 0 || toc
->file_size
[file_nr
] == 0xFFFFFFFF)
1632 FIXME(">>> requesting NULL stream (%lu)\n", file_nr
);
1635 block_list
= &toc
->file_size
[toc
->num_files
];
1636 for (i
= 0; i
< file_nr
; i
++)
1637 block_list
+= (toc
->file_size
[i
] + pdb
->block_size
- 1) / pdb
->block_size
;
1639 return pdb_ds_read(pdb
, block_list
, toc
->file_size
[file_nr
]);
1642 static void* pdb_read_file(const BYTE
* image
, const struct pdb_lookup
* pdb_lookup
,
1645 switch (pdb_lookup
->kind
)
1648 return pdb_read_jg_file((const struct PDB_JG_HEADER
*)image
,
1649 pdb_lookup
->u
.jg
.toc
, file_nr
);
1651 return pdb_read_ds_file((const struct PDB_DS_HEADER
*)image
,
1652 pdb_lookup
->u
.ds
.toc
, file_nr
);
1657 static unsigned pdb_get_file_size(const struct pdb_lookup
* pdb_lookup
, DWORD file_nr
)
1659 switch (pdb_lookup
->kind
)
1661 case PDB_JG
: return pdb_lookup
->u
.jg
.toc
->file
[file_nr
].size
;
1662 case PDB_DS
: return pdb_lookup
->u
.ds
.toc
->file_size
[file_nr
];
1667 static void pdb_free(void* buffer
)
1669 HeapFree(GetProcessHeap(), 0, buffer
);
1672 static void pdb_free_lookup(const struct pdb_lookup
* pdb_lookup
)
1674 switch (pdb_lookup
->kind
)
1677 if (pdb_lookup
->u
.jg
.toc
) pdb_free(pdb_lookup
->u
.jg
.toc
);
1680 if (pdb_lookup
->u
.ds
.toc
) pdb_free(pdb_lookup
->u
.ds
.toc
);
1685 static void pdb_convert_types_header(PDB_TYPES
* types
, const BYTE
* image
)
1687 memset(types
, 0, sizeof(PDB_TYPES
));
1690 if (*(const DWORD
*)image
< 19960000) /* FIXME: correct version? */
1692 /* Old version of the types record header */
1693 const PDB_TYPES_OLD
* old
= (const PDB_TYPES_OLD
*)image
;
1694 types
->version
= old
->version
;
1695 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
1696 types
->type_size
= old
->type_size
;
1697 types
->first_index
= old
->first_index
;
1698 types
->last_index
= old
->last_index
;
1699 types
->file
= old
->file
;
1703 /* New version of the types record header */
1704 *types
= *(const PDB_TYPES
*)image
;
1708 static void pdb_convert_symbols_header(PDB_SYMBOLS
* symbols
,
1709 int* header_size
, const BYTE
* image
)
1711 memset(symbols
, 0, sizeof(PDB_SYMBOLS
));
1714 if (*(const DWORD
*)image
!= 0xffffffff)
1716 /* Old version of the symbols record header */
1717 const PDB_SYMBOLS_OLD
* old
= (const PDB_SYMBOLS_OLD
*)image
;
1718 symbols
->version
= 0;
1719 symbols
->module_size
= old
->module_size
;
1720 symbols
->offset_size
= old
->offset_size
;
1721 symbols
->hash_size
= old
->hash_size
;
1722 symbols
->srcmodule_size
= old
->srcmodule_size
;
1723 symbols
->pdbimport_size
= 0;
1724 symbols
->hash1_file
= old
->hash1_file
;
1725 symbols
->hash2_file
= old
->hash2_file
;
1726 symbols
->gsym_file
= old
->gsym_file
;
1728 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
1732 /* New version of the symbols record header */
1733 *symbols
= *(const PDB_SYMBOLS
*)image
;
1734 *header_size
= sizeof(PDB_SYMBOLS
);
1738 static void pdb_convert_symbol_file(const PDB_SYMBOLS
* symbols
,
1739 PDB_SYMBOL_FILE_EX
* sfile
,
1740 unsigned* size
, const void* image
)
1743 if (symbols
->version
< 19970000)
1745 const PDB_SYMBOL_FILE
*sym_file
= (const PDB_SYMBOL_FILE
*)image
;
1746 memset(sfile
, 0, sizeof(*sfile
));
1747 sfile
->file
= sym_file
->file
;
1748 sfile
->range
.index
= sym_file
->range
.index
;
1749 sfile
->symbol_size
= sym_file
->symbol_size
;
1750 sfile
->lineno_size
= sym_file
->lineno_size
;
1751 *size
= sizeof(PDB_SYMBOL_FILE
) - 1;
1755 memcpy(sfile
, image
, sizeof(PDB_SYMBOL_FILE_EX
));
1756 *size
= sizeof(PDB_SYMBOL_FILE_EX
) - 1;
1760 static BOOL CALLBACK
pdb_match(char* file
, void* user
)
1762 /* accept first file */
1766 static HANDLE
open_pdb_file(const struct process
* pcs
, const char* filename
)
1769 char dbg_file_path
[MAX_PATH
];
1771 h
= CreateFileA(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
1772 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1773 /* FIXME: should give more bits on the file to look at */
1774 if (h
== INVALID_HANDLE_VALUE
&&
1775 SymFindFileInPath(pcs
->handle
, NULL
, (char*)filename
, NULL
, 0, 0, 0,
1776 dbg_file_path
, pdb_match
, NULL
))
1778 h
= CreateFileA(dbg_file_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
1779 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1781 return (h
== INVALID_HANDLE_VALUE
) ? NULL
: h
;
1784 static void pdb_process_types(const struct msc_debug_info
* msc_dbg
,
1785 const char* image
, struct pdb_lookup
* pdb_lookup
)
1787 char* types_image
= NULL
;
1789 types_image
= pdb_read_file(image
, pdb_lookup
, 2);
1793 pdb_convert_types_header(&types
, types_image
);
1795 /* Check for unknown versions */
1796 switch (types
.version
)
1798 case 19950410: /* VC 4.0 */
1800 case 19961031: /* VC 5.0 / 6.0 */
1804 ERR("-Unknown type info version %ld\n", types
.version
);
1807 /* Read type table */
1808 codeview_parse_type_table(msc_dbg
->module
, types_image
+ types
.type_offset
,
1810 pdb_free(types_image
);
1814 static const char PDB_JG_IDENT
[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
1815 static const char PDB_DS_IDENT
[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
1817 static BOOL
pdb_init(struct pdb_lookup
* pdb_lookup
, const char* image
)
1819 /* check the file header, and if ok, load the TOC */
1820 TRACE("PDB(%s): %.40s\n", pdb_lookup
->filename
, debugstr_an(image
, 40));
1821 switch (pdb_lookup
->kind
)
1824 pdb_lookup
->u
.jg
.toc
= NULL
;
1825 if (memcmp(image
, PDB_JG_IDENT
, sizeof(PDB_JG_IDENT
)))
1827 FIXME("Couldn't match JG header\n");
1832 const struct PDB_JG_HEADER
* pdb
= (const struct PDB_JG_HEADER
*)image
;
1833 struct PDB_JG_ROOT
* root
;
1835 pdb_lookup
->u
.jg
.toc
= pdb_jg_read(pdb
, pdb
->toc_block
, pdb
->toc
.size
);
1836 root
= pdb_read_jg_file(pdb
, pdb_lookup
->u
.jg
.toc
, 1);
1839 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
1842 switch (root
->Version
)
1844 case 19950623: /* VC 4.0 */
1846 case 19960307: /* VC 5.0 */
1847 case 19970604: /* VC 6.0 */
1850 ERR("-Unknown root block version %ld\n", root
->Version
);
1852 /* Check .PDB time stamp */
1853 if (root
->TimeDateStamp
!= pdb_lookup
->u
.jg
.timestamp
)
1855 ERR("-Wrong time stamp of .PDB file %s (0x%08lx, 0x%08lx)\n",
1856 pdb_lookup
->filename
, root
->TimeDateStamp
,
1857 pdb_lookup
->u
.jg
.timestamp
);
1863 pdb_lookup
->u
.ds
.toc
= NULL
;
1864 if (memcmp(image
, PDB_DS_IDENT
, sizeof(PDB_DS_IDENT
)))
1866 FIXME("Couldn't match DS header\n");
1871 const struct PDB_DS_HEADER
* pdb
= (const struct PDB_DS_HEADER
*)image
;
1872 struct PDB_DS_ROOT
* root
;
1874 pdb_lookup
->u
.ds
.toc
=
1876 (const DWORD
*)((const char*)pdb
+ pdb
->toc_page
* pdb
->block_size
),
1878 root
= pdb_read_ds_file(pdb
, pdb_lookup
->u
.ds
.toc
, 1);
1881 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
1884 switch (root
->Version
)
1889 ERR("-Unknown root block version %ld\n", root
->Version
);
1891 /* Check .PDB time stamp */
1892 if (memcmp(&root
->guid
, &pdb_lookup
->u
.ds
.guid
, sizeof(GUID
)))
1894 ERR("-Wrong GUID of .PDB file %s (%s, %s)\n",
1895 pdb_lookup
->filename
,
1896 wine_dbgstr_guid(&root
->guid
),
1897 wine_dbgstr_guid(&pdb_lookup
->u
.ds
.guid
));
1904 if (0) /* some tool to dump the internal files from a PDB file */
1908 switch (pdb_lookup
->kind
)
1910 case PDB_JG
: num_files
= pdb_lookup
->u
.jg
.toc
->num_files
; break;
1911 case PDB_DS
: num_files
= pdb_lookup
->u
.ds
.toc
->num_files
; break;
1914 for (i
= 1; i
< num_files
; i
++)
1916 unsigned char* x
= pdb_read_file(image
, pdb_lookup
, i
);
1917 FIXME("********************** [%u]: size=%08x\n",
1918 i
, pdb_get_file_size(pdb_lookup
, i
));
1919 dump(x
, pdb_get_file_size(pdb_lookup
, i
));
1926 static BOOL
pdb_process_internal(const struct process
* pcs
,
1927 const struct msc_debug_info
* msc_dbg
,
1928 struct pdb_lookup
* pdb_lookup
,
1929 unsigned module_index
);
1931 static void pdb_process_symbol_imports(const struct process
* pcs
,
1932 const struct msc_debug_info
* msc_dbg
,
1933 PDB_SYMBOLS
* symbols
,
1934 const void* symbols_image
,
1935 char* image
, struct pdb_lookup
* pdb_lookup
,
1936 unsigned module_index
)
1938 if (module_index
== -1 && symbols
&& symbols
->pdbimport_size
)
1940 const PDB_SYMBOL_IMPORT
*imp
;
1946 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
1947 symbols
->module_size
+ symbols
->offset_size
+
1948 symbols
->hash_size
+ symbols
->srcmodule_size
);
1949 first
= (const char*)imp
;
1950 last
= (const char*)imp
+ symbols
->pdbimport_size
;
1951 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
1953 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
1954 if (i
>= CV_MAX_MODULES
) FIXME("Out of bounds !!!\n");
1955 if (!strcasecmp(pdb_lookup
->filename
, imp
->filename
))
1957 if (module_index
!= -1) FIXME("Twice the entry\n");
1958 else module_index
= i
;
1962 struct pdb_lookup imp_pdb_lookup
;
1964 imp_pdb_lookup
.filename
= imp
->filename
;
1965 imp_pdb_lookup
.kind
= PDB_JG
;
1966 imp_pdb_lookup
.u
.jg
.timestamp
= imp
->TimeDateStamp
;
1967 pdb_process_internal(pcs
, msc_dbg
, &imp_pdb_lookup
, i
);
1970 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)first
+ ((ptr
- (const char*)first
+ strlen(ptr
) + 1 + 3) & ~3));
1973 cv_current_module
= &cv_zmodules
[(module_index
== -1) ? 0 : module_index
];
1974 if (cv_current_module
->allowed
) FIXME("Already allowed ??\n");
1975 cv_current_module
->allowed
= TRUE
;
1976 pdb_process_types(msc_dbg
, image
, pdb_lookup
);
1979 static BOOL
pdb_process_internal(const struct process
* pcs
,
1980 const struct msc_debug_info
* msc_dbg
,
1981 struct pdb_lookup
* pdb_lookup
,
1982 unsigned module_index
)
1985 HANDLE hFile
, hMap
= NULL
;
1987 char* symbols_image
= NULL
;
1989 TRACE("Processing PDB file %s\n", pdb_lookup
->filename
);
1991 /* Open and map() .PDB file */
1992 if ((hFile
= open_pdb_file(pcs
, pdb_lookup
->filename
)) == NULL
||
1993 ((hMap
= CreateFileMappingA(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
1994 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
1996 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
1999 pdb_init(pdb_lookup
, image
);
2001 symbols_image
= pdb_read_file(image
, pdb_lookup
, 3);
2004 PDB_SYMBOLS symbols
;
2007 int header_size
= 0;
2009 pdb_convert_symbols_header(&symbols
, &header_size
, symbols_image
);
2010 switch (symbols
.version
)
2012 case 0: /* VC 4.0 */
2013 case 19960307: /* VC 5.0 */
2014 case 19970606: /* VC 6.0 */
2018 ERR("-Unknown symbol info version %ld %08lx\n",
2019 symbols
.version
, symbols
.version
);
2022 pdb_process_symbol_imports(pcs
, msc_dbg
, &symbols
, symbols_image
, image
, pdb_lookup
, module_index
);
2024 /* Read global symbol table */
2025 modimage
= pdb_read_file(image
, pdb_lookup
, symbols
.gsym_file
);
2028 codeview_snarf(msc_dbg
, modimage
, 0,
2029 pdb_get_file_size(pdb_lookup
, symbols
.gsym_file
), NULL
);
2034 /* Read per-module symbol / linenumber tables */
2035 file
= symbols_image
+ header_size
;
2036 while (file
- symbols_image
< header_size
+ symbols
.module_size
)
2038 PDB_SYMBOL_FILE_EX sfile
;
2039 const char* file_name
;
2042 HeapValidate(GetProcessHeap(), 0, NULL
);
2043 pdb_convert_symbol_file(&symbols
, &sfile
, &size
, file
);
2045 modimage
= pdb_read_file(image
, pdb_lookup
, sfile
.file
);
2048 struct codeview_linetab
* linetab
= NULL
;
2050 if (sfile
.lineno_size
)
2051 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2052 modimage
+ sfile
.symbol_size
,
2054 pdb_lookup
->kind
== PDB_JG
);
2056 if (sfile
.symbol_size
)
2057 codeview_snarf(msc_dbg
, modimage
, sizeof(DWORD
),
2058 sfile
.symbol_size
, linetab
);
2062 file_name
= (const char*)file
+ size
;
2063 file_name
+= strlen(file_name
) + 1;
2064 file
= (char*)((DWORD
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3);
2068 pdb_process_symbol_imports(pcs
, msc_dbg
, NULL
, NULL
, image
, pdb_lookup
,
2070 msc_dbg
->module
->module
.SymType
= SymCv
;
2075 if (symbols_image
) pdb_free(symbols_image
);
2076 pdb_free_lookup(pdb_lookup
);
2078 if (image
) UnmapViewOfFile(image
);
2079 if (hMap
) CloseHandle(hMap
);
2080 if (hFile
) CloseHandle(hFile
);
2085 static BOOL
pdb_process_file(const struct process
* pcs
,
2086 const struct msc_debug_info
* msc_dbg
,
2087 struct pdb_lookup
* pdb_lookup
)
2091 memset(cv_zmodules
, 0, sizeof(cv_zmodules
));
2092 codeview_init_basic_types(msc_dbg
->module
);
2093 ret
= pdb_process_internal(pcs
, msc_dbg
, pdb_lookup
, -1);
2094 codeview_clear_type_table();
2098 /*========================================================================
2099 * Process CodeView debug information.
2102 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
2103 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
2104 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
2105 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
2106 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
2108 typedef struct _CODEVIEW_HEADER_NBxx
2112 } CODEVIEW_HEADER_NBxx
,* PCODEVIEW_HEADER_NBxx
;
2114 typedef struct _CODEVIEW_HEADER_RSDS
2120 } CODEVIEW_HEADER_RSDS
,* PCODEVIEW_HEADER_RSDS
;
2122 typedef struct _CODEVIEW_PDB_DATA
2127 } CODEVIEW_PDB_DATA
, *PCODEVIEW_PDB_DATA
;
2129 typedef struct _CV_DIRECTORY_HEADER
2136 } CV_DIRECTORY_HEADER
, *PCV_DIRECTORY_HEADER
;
2138 typedef struct _CV_DIRECTORY_ENTRY
2144 } CV_DIRECTORY_ENTRY
, *PCV_DIRECTORY_ENTRY
;
2146 #define sstAlignSym 0x125
2147 #define sstSrcModule 0x127
2149 static BOOL
codeview_process_info(const struct process
* pcs
,
2150 const struct msc_debug_info
* msc_dbg
)
2152 const CODEVIEW_HEADER_NBxx
* cv
= (const CODEVIEW_HEADER_NBxx
*)msc_dbg
->root
;
2154 struct pdb_lookup pdb_lookup
;
2156 TRACE("Processing signature %.4s\n", (const char*)&cv
->dwSignature
);
2158 switch (cv
->dwSignature
)
2160 case CODEVIEW_NB09_SIG
:
2161 case CODEVIEW_NB11_SIG
:
2163 const CV_DIRECTORY_HEADER
* hdr
= (const CV_DIRECTORY_HEADER
*)(msc_dbg
->root
+ cv
->lfoDirectory
);
2164 const CV_DIRECTORY_ENTRY
* ent
;
2165 const CV_DIRECTORY_ENTRY
* prev
;
2166 const CV_DIRECTORY_ENTRY
* next
;
2169 codeview_init_basic_types(msc_dbg
->module
);
2170 ent
= (const CV_DIRECTORY_ENTRY
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
);
2171 for (i
= 0; i
< hdr
->cDir
; i
++, ent
= next
)
2173 next
= (i
== hdr
->cDir
-1)? NULL
:
2174 (const CV_DIRECTORY_ENTRY
*)((const BYTE
*)ent
+ hdr
->cbDirEntry
);
2175 prev
= (i
== 0)? NULL
:
2176 (const CV_DIRECTORY_ENTRY
*)((const BYTE
*)ent
- hdr
->cbDirEntry
);
2178 if (ent
->subsection
== sstAlignSym
)
2181 * Check the next and previous entry. If either is a
2182 * sstSrcModule, it contains the line number info for
2185 * FIXME: This is not a general solution!
2187 struct codeview_linetab
* linetab
= NULL
;
2189 if (next
&& next
->iMod
== ent
->iMod
&&
2190 next
->subsection
== sstSrcModule
)
2191 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2192 msc_dbg
->root
+ next
->lfo
, next
->cb
,
2195 if (prev
&& prev
->iMod
== ent
->iMod
&&
2196 prev
->subsection
== sstSrcModule
)
2197 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2198 msc_dbg
->root
+ prev
->lfo
, prev
->cb
,
2201 codeview_snarf(msc_dbg
, msc_dbg
->root
+ ent
->lfo
, sizeof(DWORD
),
2206 msc_dbg
->module
->module
.SymType
= SymCv
;
2211 case CODEVIEW_NB10_SIG
:
2213 const CODEVIEW_PDB_DATA
* pdb
= (const CODEVIEW_PDB_DATA
*)(cv
+ 1);
2214 pdb_lookup
.filename
= pdb
->name
;
2215 pdb_lookup
.kind
= PDB_JG
;
2216 pdb_lookup
.u
.jg
.timestamp
= pdb
->timestamp
;
2217 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
2220 case CODEVIEW_RSDS_SIG
:
2222 const CODEVIEW_HEADER_RSDS
* rsds
= (const CODEVIEW_HEADER_RSDS
*)msc_dbg
->root
;
2224 TRACE("Got RSDS type of PDB file: guid=%s unk=%08lx name=%s\n",
2225 wine_dbgstr_guid(&rsds
->guid
), rsds
->unknown
, rsds
->name
);
2226 pdb_lookup
.filename
= rsds
->name
;
2227 pdb_lookup
.kind
= PDB_DS
;
2228 pdb_lookup
.u
.ds
.guid
= rsds
->guid
;
2229 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
2233 ERR("Unknown CODEVIEW signature %08lX in module %s\n",
2234 cv
->dwSignature
, msc_dbg
->module
->module
.ModuleName
);
2241 /*========================================================================
2242 * Process debug directory.
2244 BOOL
pe_load_debug_directory(const struct process
* pcs
, struct module
* module
,
2245 const BYTE
* mapping
,
2246 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
2247 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
)
2251 struct msc_debug_info msc_dbg
;
2253 msc_dbg
.module
= module
;
2254 msc_dbg
.nsect
= nsect
;
2255 msc_dbg
.sectp
= sectp
;
2257 msc_dbg
.omapp
= NULL
;
2263 /* First, watch out for OMAP data */
2264 for (i
= 0; i
< nDbg
; i
++)
2266 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
)
2268 msc_dbg
.nomap
= dbg
[i
].SizeOfData
/ sizeof(OMAP_DATA
);
2269 msc_dbg
.omapp
= (const OMAP_DATA
*)(mapping
+ dbg
[i
].PointerToRawData
);
2274 /* Now, try to parse CodeView debug info */
2275 for (i
= 0; i
< nDbg
; i
++)
2277 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_CODEVIEW
)
2279 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
2280 if ((ret
= codeview_process_info(pcs
, &msc_dbg
))) goto done
;
2284 /* If not found, try to parse COFF debug info */
2285 for (i
= 0; i
< nDbg
; i
++)
2287 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_COFF
)
2289 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
2290 if ((ret
= coff_process_info(&msc_dbg
))) goto done
;
2294 /* FIXME: this should be supported... this is the debug information for
2295 * functions compiled without a frame pointer (FPO = frame pointer omission)
2296 * the associated data helps finding out the relevant information
2298 for (i
= 0; i
< nDbg
; i
++)
2299 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_FPO
)
2300 FIXME("This guy has FPO information\n");
2304 #define FRAME_TRAP 1
2307 typedef struct _FPO_DATA
2309 DWORD ulOffStart
; /* offset 1st byte of function code */
2310 DWORD cbProcSize
; /* # bytes in function */
2311 DWORD cdwLocals
; /* # bytes in locals/4 */
2312 WORD cdwParams
; /* # bytes in params/4 */
2314 WORD cbProlog
: 8; /* # bytes in prolog */
2315 WORD cbRegs
: 3; /* # regs saved */
2316 WORD fHasSEH
: 1; /* TRUE if SEH in func */
2317 WORD fUseBP
: 1; /* TRUE if EBP has been allocated */
2318 WORD reserved
: 1; /* reserved for future use */
2319 WORD cbFrame
: 2; /* frame type */
2324 __EXCEPT(page_fault
)
2326 ERR("Got a page fault while loading symbols\n");