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 if (cv_zmodules
[i
].bitfields
)
382 HeapFree(GetProcessHeap(), 0, cv_zmodules
[i
].bitfields
);
383 cv_zmodules
[i
].bitfields
= NULL
;
384 cv_zmodules
[i
].num_bitfields
= cv_zmodules
[i
].used_bitfields
= 0;
386 cv_current_module
= NULL
;
389 static int codeview_add_type_pointer(struct module
* module
, unsigned int typeno
,
390 unsigned int datatype
)
392 struct symt
* symt
= &symt_new_pointer(module
,
393 codeview_get_type(datatype
, FALSE
))->symt
;
394 return codeview_add_type(typeno
, symt
);
397 static int codeview_add_type_array(struct module
* module
,
398 unsigned int typeno
, const char* name
,
399 unsigned int elemtype
, unsigned int arr_len
)
402 struct symt
* elem
= codeview_get_type(elemtype
, FALSE
);
408 symt_get_info(elem
, TI_GET_LENGTH
, &elem_size
);
409 if (elem_size
) arr_max
= arr_len
/ elem_size
;
411 symt
= &symt_new_array(module
, 0, arr_max
, elem
)->symt
;
412 return codeview_add_type(typeno
, symt
);
415 static int codeview_add_type_bitfield(unsigned int typeno
, unsigned int bitoff
,
416 unsigned int nbits
, unsigned int basetype
)
418 if (cv_current_module
->used_bitfields
>= cv_current_module
->num_bitfields
)
420 if (cv_current_module
->bitfields
)
422 cv_current_module
->num_bitfields
*= 2;
423 cv_current_module
->bitfields
=
424 HeapReAlloc(GetProcessHeap(), 0,
425 cv_current_module
->bitfields
,
426 cv_current_module
->num_bitfields
* sizeof(struct codeview_bitfield
));
430 cv_current_module
->num_bitfields
= 64;
431 cv_current_module
->bitfields
=
432 HeapAlloc(GetProcessHeap(), 0,
433 cv_current_module
->num_bitfields
* sizeof(struct codeview_bitfield
));
435 if (!cv_current_module
->bitfields
) return 0;
438 cv_current_module
->bitfields
[cv_current_module
->used_bitfields
].symt
.tag
= SymTagCVBitField
;
439 cv_current_module
->bitfields
[cv_current_module
->used_bitfields
].subtype
= basetype
;
440 cv_current_module
->bitfields
[cv_current_module
->used_bitfields
].bitposition
= bitoff
;
441 cv_current_module
->bitfields
[cv_current_module
->used_bitfields
].bitlength
= nbits
;
443 return codeview_add_type(typeno
, &cv_current_module
->bitfields
[cv_current_module
->used_bitfields
++].symt
);
446 static int codeview_add_type_enum_field_list(struct module
* module
,
448 const unsigned char* list
, int len
)
450 struct symt_enum
* symt
;
451 const unsigned char* ptr
= list
;
453 symt
= symt_new_enum(module
, NULL
);
454 while (ptr
- list
< len
)
456 const union codeview_fieldtype
* type
= (const union codeview_fieldtype
*)ptr
;
458 if (*ptr
>= 0xf0) /* LF_PAD... */
464 switch (type
->generic
.id
)
466 case LF_ENUMERATE_V1
:
468 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v1
.value
);
469 const struct p_string
* p_name
= (const struct p_string
*)((const unsigned char*)&type
->enumerate_v1
.value
+ vlen
);
471 symt_add_enum_element(module
, symt
, terminate_string(p_name
), value
);
472 ptr
+= 2 + 2 + vlen
+ (1 + p_name
->namelen
);
475 case LF_ENUMERATE_V3
:
477 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v3
.value
);
478 const char* name
= (const char*)&type
->enumerate_v3
.value
+ vlen
;
480 symt_add_enum_element(module
, symt
, name
, value
);
481 ptr
+= 2 + 2 + vlen
+ (1 + strlen(name
));
486 FIXME("Unsupported type %04x in ENUM field list\n", type
->generic
.id
);
491 return codeview_add_type(typeno
, &symt
->symt
);
494 static int codeview_add_type_struct_field_list(struct module
* module
,
496 const unsigned char* list
, int len
)
498 struct symt_udt
* symt
;
499 const unsigned char* ptr
= list
;
500 int value
, leaf_len
, vpoff
, vplen
;
501 const struct p_string
* p_name
;
503 struct symt
* subtype
;
504 const unsigned short int* p_vboff
;
506 symt
= symt_new_udt(module
, NULL
, 0, UdtStruct
/* don't care */);
507 while (ptr
- list
< len
)
509 const union codeview_fieldtype
* type
= (const union codeview_fieldtype
*)ptr
;
511 if (*ptr
>= 0xf0) /* LF_PAD... */
517 switch (type
->generic
.id
)
520 leaf_len
= numeric_leaf(&value
, &type
->bclass_v1
.offset
);
522 /* FIXME: ignored for now */
524 ptr
+= 2 + 2 + 2 + leaf_len
;
528 leaf_len
= numeric_leaf(&value
, &type
->bclass_v2
.offset
);
530 /* FIXME: ignored for now */
532 ptr
+= 2 + 2 + 4 + leaf_len
;
538 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v1
.vbpoff
);
539 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v1
.vbpoff
+ leaf_len
);
540 vplen
= numeric_leaf(&vpoff
, p_vboff
);
542 /* FIXME: ignored for now */
544 ptr
+= 2 + 2 + 2 + 2 + leaf_len
+ vplen
;
551 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v2
.vbpoff
);
552 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v2
.vbpoff
+ leaf_len
);
553 vplen
= numeric_leaf(&vpoff
, p_vboff
);
555 /* FIXME: ignored for now */
557 ptr
+= 2 + 2 + 4 + 4 + leaf_len
+ vplen
;
562 leaf_len
= numeric_leaf(&value
, &type
->member_v1
.offset
);
563 p_name
= (const struct p_string
*)((const char*)&type
->member_v1
.offset
+ leaf_len
);
564 subtype
= codeview_get_type(type
->member_v1
.type
, TRUE
);
566 if (!subtype
|| subtype
->tag
!= SymTagCVBitField
)
569 if (subtype
) symt_get_info(subtype
, TI_GET_LENGTH
, &elem_size
);
570 symt_add_udt_element(module
, symt
, terminate_string(p_name
),
571 codeview_get_type(type
->member_v1
.type
, TRUE
),
572 value
<< 3, elem_size
<< 3);
576 struct codeview_bitfield
* cvbf
= (struct codeview_bitfield
*)subtype
;
577 symt_add_udt_element(module
, symt
, terminate_string(p_name
),
578 codeview_get_type(cvbf
->subtype
, FALSE
),
579 cvbf
->bitposition
, cvbf
->bitlength
);
582 ptr
+= 2 + 2 + 2 + leaf_len
+ (1 + p_name
->namelen
);
586 leaf_len
= numeric_leaf(&value
, &type
->member_v2
.offset
);
587 p_name
= (const struct p_string
*)((const unsigned char*)&type
->member_v2
.offset
+ leaf_len
);
588 subtype
= codeview_get_type(type
->member_v2
.type
, TRUE
);
590 if (!subtype
|| subtype
->tag
!= SymTagCVBitField
)
593 if (subtype
) symt_get_info(subtype
, TI_GET_LENGTH
, &elem_size
);
594 symt_add_udt_element(module
, symt
, terminate_string(p_name
),
595 subtype
, value
<< 3, elem_size
<< 3);
599 struct codeview_bitfield
* cvbf
= (struct codeview_bitfield
*)subtype
;
600 symt_add_udt_element(module
, symt
, terminate_string(p_name
),
601 codeview_get_type(cvbf
->subtype
, FALSE
),
602 cvbf
->bitposition
, cvbf
->bitlength
);
605 ptr
+= 2 + 2 + 4 + leaf_len
+ (1 + p_name
->namelen
);
609 leaf_len
= numeric_leaf(&value
, &type
->member_v3
.offset
);
610 c_name
= (const char*)&type
->member_v3
.offset
+ leaf_len
;
611 subtype
= codeview_get_type(type
->member_v3
.type
, TRUE
);
613 if (!subtype
|| subtype
->tag
!= SymTagCVBitField
)
616 if (subtype
) symt_get_info(subtype
, TI_GET_LENGTH
, &elem_size
);
617 symt_add_udt_element(module
, symt
, c_name
,
618 subtype
, value
<< 3, elem_size
<< 3);
622 struct codeview_bitfield
* cvbf
= (struct codeview_bitfield
*)subtype
;
623 symt_add_udt_element(module
, symt
, c_name
,
624 codeview_get_type(cvbf
->subtype
, FALSE
),
625 cvbf
->bitposition
, cvbf
->bitlength
);
628 ptr
+= 2 + 2 + 4 + leaf_len
+ (strlen(c_name
) + 1);
632 /* FIXME: ignored for now */
633 ptr
+= 2 + 2 + 2 + (1 + type
->stmember_v1
.p_name
.namelen
);
637 /* FIXME: ignored for now */
638 ptr
+= 2 + 4 + 2 + (1 + type
->stmember_v2
.p_name
.namelen
);
642 /* FIXME: ignored for now */
643 ptr
+= 2 + 2 + 2 + (1 + type
->method_v1
.p_name
.namelen
);
647 /* FIXME: ignored for now */
648 ptr
+= 2 + 2 + 4 + (1 + type
->method_v2
.p_name
.namelen
);
652 /* FIXME: ignored for now */
653 ptr
+= 2 + 2 + (1 + type
->nesttype_v1
.p_name
.namelen
);
657 /* FIXME: ignored for now */
658 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype_v2
.p_name
.namelen
);
662 /* FIXME: ignored for now */
667 /* FIXME: ignored for now */
671 case LF_ONEMETHOD_V1
:
672 /* FIXME: ignored for now */
673 switch ((type
->onemethod_v1
.attribute
>> 2) & 7)
675 case 4: case 6: /* (pure) introducing virtual method */
676 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt_v1
.p_name
.namelen
);
680 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod_v1
.p_name
.namelen
);
685 case LF_ONEMETHOD_V2
:
686 /* FIXME: ignored for now */
687 switch ((type
->onemethod_v2
.attribute
>> 2) & 7)
689 case 4: case 6: /* (pure) introducing virtual method */
690 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod_virt_v2
.p_name
.namelen
);
694 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod_v2
.p_name
.namelen
);
700 FIXME("Unsupported type %04x in STRUCT field list\n", type
->generic
.id
);
705 return codeview_add_type(typeno
, &symt
->symt
);
708 static int codeview_add_type_enum(struct module
* module
, unsigned int typeno
,
709 const char* name
, unsigned int fieldlist
)
711 struct symt_enum
* symt
= symt_new_enum(module
, name
);
712 struct symt
* list
= codeview_get_type(fieldlist
, FALSE
);
714 /* FIXME: this is rather ugly !!! */
715 if (list
) symt
->vchildren
= ((struct symt_enum
*)list
)->vchildren
;
717 return codeview_add_type(typeno
, &symt
->symt
);
720 static int codeview_add_type_struct(struct module
* module
, unsigned int typeno
,
721 const char* name
, int structlen
,
722 unsigned int fieldlist
, enum UdtKind kind
)
724 struct symt_udt
* symt
= symt_new_udt(module
, name
, structlen
, kind
);
725 struct symt
* list
= codeview_get_type(fieldlist
, FALSE
);
727 /* FIXME: this is rather ugly !!! */
728 if (list
) symt
->vchildren
= ((struct symt_udt
*)list
)->vchildren
;
730 return codeview_add_type(typeno
, &symt
->symt
);
733 static int codeview_new_func_signature(struct module
* module
, unsigned typeno
,
737 symt
= &symt_new_function_signature(module
,
738 codeview_get_type(ret_type
, FALSE
))->symt
;
739 return codeview_add_type(typeno
, symt
);
742 static int codeview_parse_type_table(struct module
* module
, const char* table
,
745 unsigned int curr_type
= 0x1000;
746 const char* ptr
= table
;
748 const union codeview_type
* type
;
750 const struct p_string
* p_name
;
753 while (ptr
- table
< len
)
756 type
= (const union codeview_type
*)ptr
;
758 switch (type
->generic
.id
)
761 /* FIXME: we don't handle modifiers,
762 * but readd previous type on the curr_type
764 WARN("Modifier on %x: %s%s%s%s\n",
765 type
->modifier_v1
.type
,
766 type
->modifier_v1
.attribute
& 0x01 ? "const " : "",
767 type
->modifier_v1
.attribute
& 0x02 ? "volatile " : "",
768 type
->modifier_v1
.attribute
& 0x04 ? "unaligned " : "",
769 type
->modifier_v1
.attribute
& ~0x07 ? "unknown " : "");
770 codeview_add_type(curr_type
,
771 codeview_get_type(type
->modifier_v1
.type
, FALSE
));
774 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
775 WARN("Modifier on %x: %s%s%s%s\n",
776 type
->modifier_v2
.type
,
777 type
->modifier_v2
.attribute
& 0x01 ? "const " : "",
778 type
->modifier_v2
.attribute
& 0x02 ? "volatile " : "",
779 type
->modifier_v2
.attribute
& 0x04 ? "unaligned " : "",
780 type
->modifier_v2
.attribute
& ~0x07 ? "unknown " : "");
781 codeview_add_type(curr_type
,
782 codeview_get_type(type
->modifier_v2
.type
, FALSE
));
786 retv
= codeview_add_type_pointer(module
, curr_type
,
787 type
->pointer_v1
.datatype
);
790 retv
= codeview_add_type_pointer(module
, curr_type
,
791 type
->pointer_v2
.datatype
);
795 leaf_len
= numeric_leaf(&value
, &type
->array_v1
.arrlen
);
796 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v1
.arrlen
+ leaf_len
);
798 retv
= codeview_add_type_array(module
, curr_type
, terminate_string(p_name
),
799 type
->array_v1
.elemtype
, value
);
802 leaf_len
= numeric_leaf(&value
, &type
->array_v2
.arrlen
);
803 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v2
.arrlen
+ leaf_len
);
805 retv
= codeview_add_type_array(module
, curr_type
, terminate_string(p_name
),
806 type
->array_v2
.elemtype
, value
);
809 leaf_len
= numeric_leaf(&value
, &type
->array_v3
.arrlen
);
810 c_name
= (const char*)&type
->array_v3
.arrlen
+ leaf_len
;
812 retv
= codeview_add_type_array(module
, curr_type
, c_name
,
813 type
->array_v3
.elemtype
, value
);
817 /* a bitfield is a CodeView specific data type which represent a bitfield
818 * in a structure or a class. For now, we store it in a SymTag-like type
819 * (so that the rest of the process is seamless), but check at udt
820 * inclusion type for its presence
822 retv
= codeview_add_type_bitfield(curr_type
, type
->bitfield_v1
.bitoff
,
823 type
->bitfield_v1
.nbits
,
824 type
->bitfield_v1
.type
);
827 retv
= codeview_add_type_bitfield(curr_type
, type
->bitfield_v2
.bitoff
,
828 type
->bitfield_v2
.nbits
,
829 type
->bitfield_v2
.type
);
831 case LF_FIELDLIST_V1
:
832 case LF_FIELDLIST_V2
:
835 * A 'field list' is a CodeView-specific data type which doesn't
836 * directly correspond to any high-level data type. It is used
837 * to hold the collection of members of a struct, class, union
838 * or enum type. The actual definition of that type will follow
839 * later, and refer to the field list definition record.
841 * As we don't have a field list type ourselves, we look ahead
842 * in the field list to try to find out whether this field list
843 * will be used for an enum or struct type, and create a dummy
844 * type of the corresponding sort. Later on, the definition of
845 * the 'real' type will copy the member / enumeration data.
847 const char* list
= type
->fieldlist
.list
;
848 int len
= (ptr
+ type
->generic
.len
+ 2) - list
;
850 if (((const union codeview_fieldtype
*)list
)->generic
.id
== LF_ENUMERATE_V1
||
851 ((const union codeview_fieldtype
*)list
)->generic
.id
== LF_ENUMERATE_V3
)
852 retv
= codeview_add_type_enum_field_list(module
, curr_type
, list
, len
);
854 retv
= codeview_add_type_struct_field_list(module
, curr_type
, list
, len
);
858 case LF_STRUCTURE_V1
:
860 leaf_len
= numeric_leaf(&value
, &type
->struct_v1
.structlen
);
861 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v1
.structlen
+ leaf_len
);
863 retv
= codeview_add_type_struct(module
, curr_type
, terminate_string(p_name
),
864 value
, type
->struct_v1
.fieldlist
,
865 type
->generic
.id
== LF_CLASS_V1
? UdtClass
: UdtStruct
);
868 case LF_STRUCTURE_V2
:
870 leaf_len
= numeric_leaf(&value
, &type
->struct_v2
.structlen
);
871 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v2
.structlen
+ leaf_len
);
873 retv
= codeview_add_type_struct(module
, curr_type
, terminate_string(p_name
),
874 value
, type
->struct_v2
.fieldlist
,
875 type
->generic
.id
== LF_CLASS_V2
? UdtClass
: UdtStruct
);
878 case LF_STRUCTURE_V3
:
880 leaf_len
= numeric_leaf(&value
, &type
->struct_v3
.structlen
);
881 c_name
= (const char*)&type
->struct_v3
.structlen
+ leaf_len
;
883 retv
= codeview_add_type_struct(module
, curr_type
, c_name
,
884 value
, type
->struct_v3
.fieldlist
,
885 type
->generic
.id
== LF_CLASS_V3
? UdtClass
: UdtStruct
);
889 leaf_len
= numeric_leaf(&value
, &type
->union_v1
.un_len
);
890 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v1
.un_len
+ leaf_len
);
892 retv
= codeview_add_type_struct(module
, curr_type
, terminate_string(p_name
),
893 value
, type
->union_v1
.fieldlist
, UdtUnion
);
896 leaf_len
= numeric_leaf(&value
, &type
->union_v2
.un_len
);
897 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v2
.un_len
+ leaf_len
);
899 retv
= codeview_add_type_struct(module
, curr_type
, terminate_string(p_name
),
900 value
, type
->union_v2
.fieldlist
, UdtUnion
);
903 leaf_len
= numeric_leaf(&value
, &type
->union_v3
.un_len
);
904 c_name
= (const char*)&type
->union_v3
.un_len
+ leaf_len
;
906 retv
= codeview_add_type_struct(module
, curr_type
, c_name
,
907 value
, type
->union_v3
.fieldlist
, UdtUnion
);
910 retv
= codeview_add_type_enum(module
, curr_type
, terminate_string(&type
->enumeration_v1
.p_name
),
911 type
->enumeration_v1
.field
);
915 retv
= codeview_add_type_enum(module
, curr_type
, terminate_string(&type
->enumeration_v2
.p_name
),
916 type
->enumeration_v2
.field
);
919 retv
= codeview_add_type_enum(module
, curr_type
, type
->enumeration_v3
.name
,
920 type
->enumeration_v3
.field
);
922 case LF_PROCEDURE_V1
:
923 retv
= codeview_new_func_signature(module
, curr_type
,
924 type
->procedure_v1
.rvtype
);
926 case LF_PROCEDURE_V2
:
927 retv
= codeview_new_func_signature(module
, curr_type
,
928 type
->procedure_v2
.rvtype
);
930 case LF_MFUNCTION_V1
:
931 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
932 * nor class information, this would just do for now
934 retv
= codeview_new_func_signature(module
, curr_type
,
935 type
->mfunction_v1
.rvtype
);
937 case LF_MFUNCTION_V2
:
938 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
939 * nor class information, this would just do for now
941 retv
= codeview_new_func_signature(module
, curr_type
,
942 type
->mfunction_v2
.rvtype
);
949 FIXME("Not adding parameters' types to function signature\n");
954 FIXME("Unsupported type-id leaf %x\n", type
->generic
.id
);
955 dump(type
, 2 + type
->generic
.len
);
958 if (!retv
) return FALSE
;
960 ptr
+= type
->generic
.len
+ 2;
966 /*========================================================================
967 * Process CodeView line number information.
970 static struct codeview_linetab
* codeview_snarf_linetab(struct module
* module
,
971 const char* linetab
, int size
,
975 char filename
[PATH_MAX
];
976 const unsigned int* filetab
;
977 const struct p_string
* p_fn
;
980 struct codeview_linetab
* lt_hdr
;
981 const unsigned int* lt_ptr
;
986 const struct startend
* start
;
988 struct symt_compiland
* compiland
;
991 * Now get the important bits.
997 filetab
= (const unsigned int*) pnt
.c
;
1000 * Now count up the number of segments in the file.
1003 for (i
= 0; i
< nfile
; i
++)
1005 pnt2
.c
= linetab
+ filetab
[i
];
1010 * Next allocate the header we will be returning.
1011 * There is one header for each segment, so that we can reach in
1012 * and pull bits as required.
1014 lt_hdr
= (struct codeview_linetab
*)
1015 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nseg
+ 1) * sizeof(*lt_hdr
));
1022 * Now fill the header we will be returning, one for each segment.
1023 * Note that this will basically just contain pointers into the existing
1024 * line table, and we do not actually copy any additional information
1025 * or allocate any additional memory.
1029 for (i
= 0; i
< nfile
; i
++)
1032 * Get the pointer into the segment information.
1034 pnt2
.c
= linetab
+ filetab
[i
];
1035 file_segcount
= *pnt2
.s
;
1038 lt_ptr
= (const unsigned int*) pnt2
.c
;
1039 start
= (const struct startend
*)(lt_ptr
+ file_segcount
);
1042 * Now snarf the filename for all of the segments for this file.
1046 p_fn
= (const struct p_string
*)(start
+ file_segcount
);
1047 memset(filename
, 0, sizeof(filename
));
1048 memcpy(filename
, p_fn
->name
, p_fn
->namelen
);
1049 compiland
= symt_new_compiland(module
, filename
);
1052 compiland
= symt_new_compiland(module
, (const char*)(start
+ file_segcount
));
1054 for (k
= 0; k
< file_segcount
; k
++, this_seg
++)
1056 pnt2
.c
= linetab
+ lt_ptr
[k
];
1057 lt_hdr
[this_seg
].start
= start
[k
].start
;
1058 lt_hdr
[this_seg
].end
= start
[k
].end
;
1059 lt_hdr
[this_seg
].compiland
= compiland
;
1060 lt_hdr
[this_seg
].segno
= *pnt2
.s
++;
1061 lt_hdr
[this_seg
].nline
= *pnt2
.s
++;
1062 lt_hdr
[this_seg
].offtab
= pnt2
.ui
;
1063 lt_hdr
[this_seg
].linetab
= (const unsigned short*)(pnt2
.ui
+ lt_hdr
[this_seg
].nline
);
1073 /*========================================================================
1074 * Process CodeView symbol information.
1077 static unsigned int codeview_map_offset(const struct msc_debug_info
* msc_dbg
,
1078 unsigned int offset
)
1080 int nomap
= msc_dbg
->nomap
;
1081 const OMAP_DATA
* omapp
= msc_dbg
->omapp
;
1084 if (!nomap
|| !omapp
) return offset
;
1086 /* FIXME: use binary search */
1087 for (i
= 0; i
< nomap
- 1; i
++)
1088 if (omapp
[i
].from
<= offset
&& omapp
[i
+1].from
> offset
)
1089 return !omapp
[i
].to
? 0 : omapp
[i
].to
+ (offset
- omapp
[i
].from
);
1094 static const struct codeview_linetab
*
1095 codeview_get_linetab(const struct codeview_linetab
* linetab
,
1096 unsigned seg
, unsigned offset
)
1099 * Check whether we have line number information
1103 for (; linetab
->linetab
; linetab
++)
1104 if (linetab
->segno
== seg
&&
1105 linetab
->start
<= offset
&& linetab
->end
> offset
)
1107 if (!linetab
->linetab
) linetab
= NULL
;
1112 static unsigned codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1113 unsigned seg
, unsigned offset
)
1115 int nsect
= msc_dbg
->nsect
;
1116 const IMAGE_SECTION_HEADER
* sectp
= msc_dbg
->sectp
;
1118 if (!seg
|| seg
> nsect
) return 0;
1119 return msc_dbg
->module
->module
.BaseOfImage
+
1120 codeview_map_offset(msc_dbg
, sectp
[seg
-1].VirtualAddress
+ offset
);
1123 static void codeview_add_func_linenum(struct module
* module
,
1124 struct symt_function
* func
,
1125 const struct codeview_linetab
* linetab
,
1126 unsigned offset
, unsigned size
)
1130 if (!linetab
) return;
1131 for (i
= 0; i
< linetab
->nline
; i
++)
1133 if (linetab
->offtab
[i
] >= offset
&& linetab
->offtab
[i
] < offset
+ size
)
1135 symt_add_func_line(module
, func
, linetab
->compiland
->source
,
1136 linetab
->linetab
[i
], linetab
->offtab
[i
] - offset
);
1141 static int codeview_snarf(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1142 int offset
, int size
,
1143 struct codeview_linetab
* linetab
)
1145 struct symt_function
* curr_func
= NULL
;
1147 const struct codeview_linetab
* flt
;
1148 struct symt_block
* block
= NULL
;
1153 * Loop over the different types of records and whenever we
1154 * find something we are interested in, record it and move on.
1156 for (i
= offset
; i
< size
; i
+= length
)
1158 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1159 length
= sym
->generic
.len
+ 2;
1160 if (length
& 3) FIXME("unpadded len %u\n", length
+ 2);
1162 switch (sym
->generic
.id
)
1165 * Global and local data symbols. We don't associate these
1166 * with any given source file.
1170 flt
= codeview_get_linetab(linetab
, sym
->data_v1
.segment
, sym
->data_v1
.offset
);
1171 symt_new_global_variable(msc_dbg
->module
,
1172 flt
? flt
->compiland
: NULL
,
1173 terminate_string(&sym
->data_v1
.p_name
), sym
->generic
.id
== S_LDATA_V1
,
1174 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
),
1176 codeview_get_type(sym
->data_v1
.symtype
, FALSE
));
1180 flt
= codeview_get_linetab(linetab
, sym
->data_v2
.segment
, sym
->data_v2
.offset
);
1181 name
= terminate_string(&sym
->data_v2
.p_name
);
1183 symt_new_global_variable(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1184 name
, sym
->generic
.id
== S_LDATA_V2
,
1185 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
),
1187 codeview_get_type(sym
->data_v2
.symtype
, FALSE
));
1191 flt
= codeview_get_linetab(linetab
, sym
->data_v3
.segment
, sym
->data_v3
.offset
);
1192 if (*sym
->data_v3
.name
)
1193 symt_new_global_variable(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1195 sym
->generic
.id
== S_LDATA_V3
,
1196 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1198 codeview_get_type(sym
->data_v3
.symtype
, FALSE
));
1201 case S_PUB_V1
: /* FIXME is this really a 'data_v1' structure ?? */
1202 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1204 flt
= codeview_get_linetab(linetab
, sym
->data_v1
.segment
, sym
->data_v1
.offset
);
1205 symt_new_public(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1206 terminate_string(&sym
->data_v1
.p_name
),
1207 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
),
1208 0, TRUE
/* FIXME */, TRUE
/* FIXME */);
1211 case S_PUB_V2
: /* FIXME is this really a 'data_v2' structure ?? */
1212 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1214 flt
= codeview_get_linetab(linetab
, sym
->data_v2
.segment
, sym
->data_v2
.offset
);
1215 symt_new_public(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1216 terminate_string(&sym
->data_v2
.p_name
),
1217 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
),
1218 0, TRUE
/* FIXME */, TRUE
/* FIXME */);
1223 * Sort of like a global function, but it just points
1224 * to a thunk, which is a stupid name for what amounts to
1225 * a PLT slot in the normal jargon that everyone else uses.
1228 flt
= codeview_get_linetab(linetab
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
);
1229 symt_new_thunk(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1230 terminate_string(&sym
->thunk_v1
.p_name
), sym
->thunk_v1
.thtype
,
1231 codeview_get_address(msc_dbg
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
),
1232 sym
->thunk_v1
.thunk_len
);
1235 flt
= codeview_get_linetab(linetab
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
);
1236 symt_new_thunk(msc_dbg
->module
, flt
? flt
->compiland
: NULL
,
1237 sym
->thunk_v3
.name
, sym
->thunk_v3
.thtype
,
1238 codeview_get_address(msc_dbg
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
),
1239 sym
->thunk_v3
.thunk_len
);
1243 * Global and static functions.
1247 flt
= codeview_get_linetab(linetab
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
);
1248 if (curr_func
) FIXME("nested function\n");
1249 curr_func
= symt_new_function(msc_dbg
->module
,
1250 flt
? flt
->compiland
: NULL
,
1251 terminate_string(&sym
->proc_v1
.p_name
),
1252 codeview_get_address(msc_dbg
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
),
1253 sym
->proc_v1
.proc_len
,
1254 codeview_get_type(sym
->proc_v1
.proctype
, FALSE
));
1255 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1256 sym
->proc_v1
.offset
, sym
->proc_v1
.proc_len
);
1257 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, sym
->proc_v1
.debug_start
, NULL
);
1258 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, sym
->proc_v1
.debug_end
, NULL
);
1262 flt
= codeview_get_linetab(linetab
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
);
1263 if (curr_func
) FIXME("nested function\n");
1264 curr_func
= symt_new_function(msc_dbg
->module
,
1265 flt
? flt
->compiland
: NULL
,
1266 terminate_string(&sym
->proc_v2
.p_name
),
1267 codeview_get_address(msc_dbg
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
),
1268 sym
->proc_v2
.proc_len
,
1269 codeview_get_type(sym
->proc_v2
.proctype
, FALSE
));
1270 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1271 sym
->proc_v2
.offset
, sym
->proc_v2
.proc_len
);
1272 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, sym
->proc_v2
.debug_start
, NULL
);
1273 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, sym
->proc_v2
.debug_end
, NULL
);
1277 flt
= codeview_get_linetab(linetab
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
);
1278 if (curr_func
) FIXME("nested function\n");
1279 curr_func
= symt_new_function(msc_dbg
->module
,
1280 flt
? flt
->compiland
: NULL
,
1282 codeview_get_address(msc_dbg
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
),
1283 sym
->proc_v3
.proc_len
,
1284 codeview_get_type(sym
->proc_v3
.proctype
, FALSE
));
1285 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1286 sym
->proc_v3
.offset
, sym
->proc_v3
.proc_len
);
1287 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, sym
->proc_v3
.debug_start
, NULL
);
1288 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, sym
->proc_v3
.debug_end
, NULL
);
1291 * Function parameters and stack variables.
1294 symt_add_func_local(msc_dbg
->module
, curr_func
, 0, sym
->stack_v1
.offset
,
1295 block
, codeview_get_type(sym
->stack_v1
.symtype
, FALSE
),
1296 terminate_string(&sym
->stack_v1
.p_name
));
1299 symt_add_func_local(msc_dbg
->module
, curr_func
, 0, sym
->stack_v2
.offset
,
1300 block
, codeview_get_type(sym
->stack_v2
.symtype
, FALSE
),
1301 terminate_string(&sym
->stack_v2
.p_name
));
1304 symt_add_func_local(msc_dbg
->module
, curr_func
, 0, sym
->stack_v3
.offset
,
1305 block
, codeview_get_type(sym
->stack_v3
.symtype
, FALSE
),
1306 sym
->stack_v3
.name
);
1310 symt_add_func_local(msc_dbg
->module
, curr_func
, 0, sym
->register_v1
.reg
,
1311 block
, codeview_get_type(sym
->register_v1
.type
, FALSE
),
1312 terminate_string(&sym
->register_v1
.p_name
));
1315 symt_add_func_local(msc_dbg
->module
, curr_func
, 0, sym
->register_v2
.reg
,
1316 block
, codeview_get_type(sym
->register_v2
.type
, FALSE
),
1317 terminate_string(&sym
->register_v2
.p_name
));
1321 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1322 codeview_get_address(msc_dbg
, sym
->block_v1
.segment
, sym
->block_v1
.offset
),
1323 sym
->block_v1
.length
);
1326 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1327 codeview_get_address(msc_dbg
, sym
->block_v3
.segment
, sym
->block_v3
.offset
),
1328 sym
->block_v3
.length
);
1334 block
= symt_close_func_block(msc_dbg
->module
, curr_func
, block
, 0);
1338 symt_normalize_function(msc_dbg
->module
, curr_func
);
1343 /* FIXME: we should use this as a compiland, instead of guessing it on the fly */
1344 case S_COMPILAND_V1
:
1345 TRACE("S-Compiland-V1e %x %s\n",
1346 sym
->compiland_v1
.unknown
,
1347 terminate_string(&sym
->compiland_v1
.p_name
));
1350 case S_COMPILAND_V2
:
1351 TRACE("S-Compiland-V2 %s\n",
1352 terminate_string(&sym
->compiland_v2
.p_name
));
1353 if (TRACE_ON(dbghelp_msc
))
1355 const char* ptr1
= sym
->compiland_v2
.p_name
.name
+ sym
->compiland_v2
.p_name
.namelen
;
1359 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1360 TRACE("\t%s => %s\n", ptr1
, ptr2
);
1361 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1365 case S_COMPILAND_V3
:
1366 TRACE("S-Compiland-V3 %s\n", sym
->compiland_v3
.name
);
1367 if (TRACE_ON(dbghelp_msc
))
1369 const char* ptr1
= sym
->compiland_v3
.name
+ strlen(sym
->compiland_v3
.name
);
1373 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1374 TRACE("\t%s => %s\n", ptr1
, ptr2
);
1375 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1381 TRACE("S-ObjName %.*s\n", ((const BYTE
*)sym
)[8], (const BYTE
*)sym
+ 9);
1387 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1388 codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
) - curr_func
->address
,
1389 terminate_string(&sym
->label_v1
.p_name
));
1392 FIXME("No current function for label %s\n",
1393 terminate_string(&sym
->label_v1
.p_name
));
1398 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1399 codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
) - curr_func
->address
,
1400 sym
->label_v3
.name
);
1403 FIXME("No current function for label %s\n", sym
->label_v3
.name
);
1409 const struct p_string
* name
;
1413 vlen
= numeric_leaf(&val
, &sym
->constant_v1
.cvalue
);
1414 name
= (const struct p_string
*)((const char*)&sym
->constant_v1
.cvalue
+ vlen
);
1415 se
= codeview_get_type(sym
->constant_v1
.type
, FALSE
);
1417 else if (se
->tag
== SymTagEnum
) x
= ((struct symt_enum
*)se
)->name
;
1420 TRACE("S-Constant-V1 %u %s %x (%s)\n",
1421 val
, terminate_string(name
), sym
->constant_v1
.type
, x
);
1422 /* FIXME: we should add this as a constant value */
1428 const struct p_string
* name
;
1432 vlen
= numeric_leaf(&val
, &sym
->constant_v2
.cvalue
);
1433 name
= (const struct p_string
*)((const char*)&sym
->constant_v2
.cvalue
+ vlen
);
1434 se
= codeview_get_type(sym
->constant_v2
.type
, FALSE
);
1436 else if (se
->tag
== SymTagEnum
) x
= ((struct symt_enum
*)se
)->name
;
1439 TRACE("S-Constant-V2 %u %s %x (%s)\n",
1440 val
, terminate_string(name
), sym
->constant_v2
.type
, x
);
1441 /* FIXME: we should add this as a constant value */
1451 vlen
= numeric_leaf(&val
, &sym
->constant_v3
.cvalue
);
1452 name
= (const char*)&sym
->constant_v3
.cvalue
+ vlen
;
1453 se
= codeview_get_type(sym
->constant_v3
.type
, FALSE
);
1455 else if (se
->tag
== SymTagEnum
) x
= ((struct symt_enum
*)se
)->name
;
1458 TRACE("S-Constant-V3 %u %s %x (%s)\n",
1459 val
, name
, sym
->constant_v3
.type
, x
);
1460 /* FIXME: we should add this as a constant value */
1465 if (sym
->udt_v1
.type
)
1467 if ((symt
= codeview_get_type(sym
->udt_v1
.type
, FALSE
)))
1468 symt_new_typedef(msc_dbg
->module
, symt
,
1469 terminate_string(&sym
->udt_v1
.p_name
));
1471 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1472 terminate_string(&sym
->udt_v1
.p_name
), sym
->udt_v1
.type
);
1476 if (sym
->udt_v2
.type
)
1478 if ((symt
= codeview_get_type(sym
->udt_v2
.type
, FALSE
)))
1479 symt_new_typedef(msc_dbg
->module
, symt
,
1480 terminate_string(&sym
->udt_v2
.p_name
));
1482 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1483 terminate_string(&sym
->udt_v2
.p_name
), sym
->udt_v2
.type
);
1487 if (sym
->udt_v3
.type
)
1489 if ((symt
= codeview_get_type(sym
->udt_v3
.type
, FALSE
)))
1490 symt_new_typedef(msc_dbg
->module
, symt
, sym
->udt_v3
.name
);
1492 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1493 sym
->udt_v3
.name
, sym
->udt_v3
.type
);
1498 * These are special, in that they are always followed by an
1499 * additional length-prefixed string which is *not* included
1500 * into the symbol length count. We need to skip it.
1505 name
= (const char*)sym
+ length
;
1506 length
+= (*name
+ 1 + 3) & ~3;
1510 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1512 flt
= codeview_get_linetab(linetab
, sym
->data_v3
.segment
, sym
->data_v3
.offset
);
1513 symt_new_public(msc_dbg
->module
,
1514 flt
? flt
->compiland
: NULL
,
1516 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1517 0, FALSE
/* FIXME */, FALSE
);
1520 case S_PUB_FUNC1_V3
:
1521 case S_PUB_FUNC2_V3
: /* using a data_v3 isn't what we'd expect */
1522 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1524 flt
= codeview_get_linetab(linetab
, sym
->data_v3
.segment
, sym
->data_v3
.offset
);
1525 symt_new_public(msc_dbg
->module
,
1526 flt
? flt
->compiland
: NULL
,
1528 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1529 0, TRUE
/* FIXME */, TRUE
);
1533 case S_MSTOOL_V3
: /* just to silence a few warnings */
1537 FIXME("Unsupported symbol id %x\n", sym
->generic
.id
);
1538 dump(sym
, 2 + sym
->generic
.len
);
1543 if (curr_func
) symt_normalize_function(msc_dbg
->module
, curr_func
);
1545 if (linetab
) HeapFree(GetProcessHeap(), 0, linetab
);
1549 /*========================================================================
1555 const char* filename
;
1556 enum {PDB_JG
, PDB_DS
} kind
;
1562 struct PDB_JG_TOC
* toc
;
1567 struct PDB_DS_TOC
* toc
;
1572 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
,
1578 if (!size
) return NULL
;
1580 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1581 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
1583 for (i
= 0; i
< num_blocks
; i
++)
1584 memcpy(buffer
+ i
* pdb
->block_size
,
1585 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
1590 static void* pdb_ds_read(const struct PDB_DS_HEADER
* pdb
, const DWORD
* block_list
,
1596 if (!size
) return NULL
;
1598 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1599 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
1601 for (i
= 0; i
< num_blocks
; i
++)
1602 memcpy(buffer
+ i
* pdb
->block_size
,
1603 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
1608 static void* pdb_read_jg_file(const struct PDB_JG_HEADER
* pdb
,
1609 const struct PDB_JG_TOC
* toc
, DWORD file_nr
)
1611 const WORD
* block_list
;
1614 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
1616 block_list
= (const WORD
*) &toc
->file
[toc
->num_files
];
1617 for (i
= 0; i
< file_nr
; i
++)
1618 block_list
+= (toc
->file
[i
].size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1620 return pdb_jg_read(pdb
, block_list
, toc
->file
[file_nr
].size
);
1623 static void* pdb_read_ds_file(const struct PDB_DS_HEADER
* pdb
,
1624 const struct PDB_DS_TOC
* toc
, DWORD file_nr
)
1626 const DWORD
* block_list
;
1629 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
1631 if (toc
->file_size
[file_nr
] == 0 || toc
->file_size
[file_nr
] == 0xFFFFFFFF)
1633 FIXME(">>> requesting NULL stream (%lu)\n", file_nr
);
1636 block_list
= &toc
->file_size
[toc
->num_files
];
1637 for (i
= 0; i
< file_nr
; i
++)
1638 block_list
+= (toc
->file_size
[i
] + pdb
->block_size
- 1) / pdb
->block_size
;
1640 return pdb_ds_read(pdb
, block_list
, toc
->file_size
[file_nr
]);
1643 static void* pdb_read_file(const BYTE
* image
, const struct pdb_lookup
* pdb_lookup
,
1646 switch (pdb_lookup
->kind
)
1649 return pdb_read_jg_file((const struct PDB_JG_HEADER
*)image
,
1650 pdb_lookup
->u
.jg
.toc
, file_nr
);
1652 return pdb_read_ds_file((const struct PDB_DS_HEADER
*)image
,
1653 pdb_lookup
->u
.ds
.toc
, file_nr
);
1658 static unsigned pdb_get_file_size(const struct pdb_lookup
* pdb_lookup
, DWORD file_nr
)
1660 switch (pdb_lookup
->kind
)
1662 case PDB_JG
: return pdb_lookup
->u
.jg
.toc
->file
[file_nr
].size
;
1663 case PDB_DS
: return pdb_lookup
->u
.ds
.toc
->file_size
[file_nr
];
1668 static void pdb_free(void* buffer
)
1670 HeapFree(GetProcessHeap(), 0, buffer
);
1673 static void pdb_free_lookup(const struct pdb_lookup
* pdb_lookup
)
1675 switch (pdb_lookup
->kind
)
1678 if (pdb_lookup
->u
.jg
.toc
) pdb_free(pdb_lookup
->u
.jg
.toc
);
1681 if (pdb_lookup
->u
.ds
.toc
) pdb_free(pdb_lookup
->u
.ds
.toc
);
1686 static void pdb_convert_types_header(PDB_TYPES
* types
, const BYTE
* image
)
1688 memset(types
, 0, sizeof(PDB_TYPES
));
1691 if (*(const DWORD
*)image
< 19960000) /* FIXME: correct version? */
1693 /* Old version of the types record header */
1694 const PDB_TYPES_OLD
* old
= (const PDB_TYPES_OLD
*)image
;
1695 types
->version
= old
->version
;
1696 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
1697 types
->type_size
= old
->type_size
;
1698 types
->first_index
= old
->first_index
;
1699 types
->last_index
= old
->last_index
;
1700 types
->file
= old
->file
;
1704 /* New version of the types record header */
1705 *types
= *(const PDB_TYPES
*)image
;
1709 static void pdb_convert_symbols_header(PDB_SYMBOLS
* symbols
,
1710 int* header_size
, const BYTE
* image
)
1712 memset(symbols
, 0, sizeof(PDB_SYMBOLS
));
1715 if (*(const DWORD
*)image
!= 0xffffffff)
1717 /* Old version of the symbols record header */
1718 const PDB_SYMBOLS_OLD
* old
= (const PDB_SYMBOLS_OLD
*)image
;
1719 symbols
->version
= 0;
1720 symbols
->module_size
= old
->module_size
;
1721 symbols
->offset_size
= old
->offset_size
;
1722 symbols
->hash_size
= old
->hash_size
;
1723 symbols
->srcmodule_size
= old
->srcmodule_size
;
1724 symbols
->pdbimport_size
= 0;
1725 symbols
->hash1_file
= old
->hash1_file
;
1726 symbols
->hash2_file
= old
->hash2_file
;
1727 symbols
->gsym_file
= old
->gsym_file
;
1729 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
1733 /* New version of the symbols record header */
1734 *symbols
= *(const PDB_SYMBOLS
*)image
;
1735 *header_size
= sizeof(PDB_SYMBOLS
);
1739 static void pdb_convert_symbol_file(const PDB_SYMBOLS
* symbols
,
1740 PDB_SYMBOL_FILE_EX
* sfile
,
1741 unsigned* size
, const void* image
)
1744 if (symbols
->version
< 19970000)
1746 const PDB_SYMBOL_FILE
*sym_file
= (const PDB_SYMBOL_FILE
*)image
;
1747 memset(sfile
, 0, sizeof(*sfile
));
1748 sfile
->file
= sym_file
->file
;
1749 sfile
->range
.index
= sym_file
->range
.index
;
1750 sfile
->symbol_size
= sym_file
->symbol_size
;
1751 sfile
->lineno_size
= sym_file
->lineno_size
;
1752 *size
= sizeof(PDB_SYMBOL_FILE
) - 1;
1756 memcpy(sfile
, image
, sizeof(PDB_SYMBOL_FILE_EX
));
1757 *size
= sizeof(PDB_SYMBOL_FILE_EX
) - 1;
1761 static BOOL CALLBACK
pdb_match(char* file
, void* user
)
1763 /* accept first file */
1767 static HANDLE
open_pdb_file(const struct process
* pcs
, const char* filename
)
1770 char dbg_file_path
[MAX_PATH
];
1772 h
= CreateFileA(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
1773 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1774 /* FIXME: should give more bits on the file to look at */
1775 if (h
== INVALID_HANDLE_VALUE
&&
1776 SymFindFileInPath(pcs
->handle
, NULL
, (char*)filename
, NULL
, 0, 0, 0,
1777 dbg_file_path
, pdb_match
, NULL
))
1779 h
= CreateFileA(dbg_file_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
1780 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1782 return (h
== INVALID_HANDLE_VALUE
) ? NULL
: h
;
1785 static void pdb_process_types(const struct msc_debug_info
* msc_dbg
,
1786 const char* image
, struct pdb_lookup
* pdb_lookup
)
1788 char* types_image
= NULL
;
1790 types_image
= pdb_read_file(image
, pdb_lookup
, 2);
1794 pdb_convert_types_header(&types
, types_image
);
1796 /* Check for unknown versions */
1797 switch (types
.version
)
1799 case 19950410: /* VC 4.0 */
1801 case 19961031: /* VC 5.0 / 6.0 */
1805 ERR("-Unknown type info version %ld\n", types
.version
);
1808 /* Read type table */
1809 codeview_parse_type_table(msc_dbg
->module
, types_image
+ types
.type_offset
,
1811 pdb_free(types_image
);
1815 static const char PDB_JG_IDENT
[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
1816 static const char PDB_DS_IDENT
[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
1818 static BOOL
pdb_init(struct pdb_lookup
* pdb_lookup
, const char* image
)
1820 /* check the file header, and if ok, load the TOC */
1821 TRACE("PDB(%s): %.40s\n", pdb_lookup
->filename
, debugstr_an(image
, 40));
1822 switch (pdb_lookup
->kind
)
1825 pdb_lookup
->u
.jg
.toc
= NULL
;
1826 if (memcmp(image
, PDB_JG_IDENT
, sizeof(PDB_JG_IDENT
)))
1828 FIXME("Couldn't match JG header\n");
1833 const struct PDB_JG_HEADER
* pdb
= (const struct PDB_JG_HEADER
*)image
;
1834 struct PDB_JG_ROOT
* root
;
1836 pdb_lookup
->u
.jg
.toc
= pdb_jg_read(pdb
, pdb
->toc_block
, pdb
->toc
.size
);
1837 root
= pdb_read_jg_file(pdb
, pdb_lookup
->u
.jg
.toc
, 1);
1840 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
1843 switch (root
->Version
)
1845 case 19950623: /* VC 4.0 */
1847 case 19960307: /* VC 5.0 */
1848 case 19970604: /* VC 6.0 */
1851 ERR("-Unknown root block version %ld\n", root
->Version
);
1853 /* Check .PDB time stamp */
1854 if (root
->TimeDateStamp
!= pdb_lookup
->u
.jg
.timestamp
)
1856 ERR("-Wrong time stamp of .PDB file %s (0x%08lx, 0x%08lx)\n",
1857 pdb_lookup
->filename
, root
->TimeDateStamp
,
1858 pdb_lookup
->u
.jg
.timestamp
);
1864 pdb_lookup
->u
.ds
.toc
= NULL
;
1865 if (memcmp(image
, PDB_DS_IDENT
, sizeof(PDB_DS_IDENT
)))
1867 FIXME("Couldn't match DS header\n");
1872 const struct PDB_DS_HEADER
* pdb
= (const struct PDB_DS_HEADER
*)image
;
1873 struct PDB_DS_ROOT
* root
;
1875 pdb_lookup
->u
.ds
.toc
=
1877 (const DWORD
*)((const char*)pdb
+ pdb
->toc_page
* pdb
->block_size
),
1879 root
= pdb_read_ds_file(pdb
, pdb_lookup
->u
.ds
.toc
, 1);
1882 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
1885 switch (root
->Version
)
1890 ERR("-Unknown root block version %ld\n", root
->Version
);
1892 /* Check .PDB time stamp */
1893 if (memcmp(&root
->guid
, &pdb_lookup
->u
.ds
.guid
, sizeof(GUID
)))
1895 ERR("-Wrong GUID of .PDB file %s (%s, %s)\n",
1896 pdb_lookup
->filename
,
1897 wine_dbgstr_guid(&root
->guid
),
1898 wine_dbgstr_guid(&pdb_lookup
->u
.ds
.guid
));
1905 if (0) /* some tool to dump the internal files from a PDB file */
1909 switch (pdb_lookup
->kind
)
1911 case PDB_JG
: num_files
= pdb_lookup
->u
.jg
.toc
->num_files
; break;
1912 case PDB_DS
: num_files
= pdb_lookup
->u
.ds
.toc
->num_files
; break;
1915 for (i
= 1; i
< num_files
; i
++)
1917 unsigned char* x
= pdb_read_file(image
, pdb_lookup
, i
);
1918 FIXME("********************** [%u]: size=%08x\n",
1919 i
, pdb_get_file_size(pdb_lookup
, i
));
1920 dump(x
, pdb_get_file_size(pdb_lookup
, i
));
1927 static BOOL
pdb_process_internal(const struct process
* pcs
,
1928 const struct msc_debug_info
* msc_dbg
,
1929 struct pdb_lookup
* pdb_lookup
,
1930 unsigned module_index
);
1932 static void pdb_process_symbol_imports(const struct process
* pcs
,
1933 const struct msc_debug_info
* msc_dbg
,
1934 PDB_SYMBOLS
* symbols
,
1935 const void* symbols_image
,
1936 char* image
, struct pdb_lookup
* pdb_lookup
,
1937 unsigned module_index
)
1939 if (module_index
== -1 && symbols
&& symbols
->pdbimport_size
)
1941 const PDB_SYMBOL_IMPORT
*imp
;
1947 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
1948 symbols
->module_size
+ symbols
->offset_size
+
1949 symbols
->hash_size
+ symbols
->srcmodule_size
);
1950 first
= (const char*)imp
;
1951 last
= (const char*)imp
+ symbols
->pdbimport_size
;
1952 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
1954 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
1955 if (i
>= CV_MAX_MODULES
) FIXME("Out of bounds !!!\n");
1956 if (!strcasecmp(pdb_lookup
->filename
, imp
->filename
))
1958 if (module_index
!= -1) FIXME("Twice the entry\n");
1959 else module_index
= i
;
1963 struct pdb_lookup imp_pdb_lookup
;
1965 imp_pdb_lookup
.filename
= imp
->filename
;
1966 imp_pdb_lookup
.kind
= PDB_JG
;
1967 imp_pdb_lookup
.u
.jg
.timestamp
= imp
->TimeDateStamp
;
1968 pdb_process_internal(pcs
, msc_dbg
, &imp_pdb_lookup
, i
);
1971 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)first
+ ((ptr
- (const char*)first
+ strlen(ptr
) + 1 + 3) & ~3));
1974 cv_current_module
= &cv_zmodules
[(module_index
== -1) ? 0 : module_index
];
1975 if (cv_current_module
->allowed
) FIXME("Already allowed ??\n");
1976 cv_current_module
->allowed
= TRUE
;
1977 pdb_process_types(msc_dbg
, image
, pdb_lookup
);
1980 static BOOL
pdb_process_internal(const struct process
* pcs
,
1981 const struct msc_debug_info
* msc_dbg
,
1982 struct pdb_lookup
* pdb_lookup
,
1983 unsigned module_index
)
1986 HANDLE hFile
, hMap
= NULL
;
1988 char* symbols_image
= NULL
;
1990 TRACE("Processing PDB file %s\n", pdb_lookup
->filename
);
1992 /* Open and map() .PDB file */
1993 if ((hFile
= open_pdb_file(pcs
, pdb_lookup
->filename
)) == NULL
||
1994 ((hMap
= CreateFileMappingA(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
1995 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
1997 ERR("-Unable to peruse .PDB file %s\n", pdb_lookup
->filename
);
2000 pdb_init(pdb_lookup
, image
);
2002 symbols_image
= pdb_read_file(image
, pdb_lookup
, 3);
2005 PDB_SYMBOLS symbols
;
2008 int header_size
= 0;
2010 pdb_convert_symbols_header(&symbols
, &header_size
, symbols_image
);
2011 switch (symbols
.version
)
2013 case 0: /* VC 4.0 */
2014 case 19960307: /* VC 5.0 */
2015 case 19970606: /* VC 6.0 */
2019 ERR("-Unknown symbol info version %ld %08lx\n",
2020 symbols
.version
, symbols
.version
);
2023 pdb_process_symbol_imports(pcs
, msc_dbg
, &symbols
, symbols_image
, image
, pdb_lookup
, module_index
);
2025 /* Read global symbol table */
2026 modimage
= pdb_read_file(image
, pdb_lookup
, symbols
.gsym_file
);
2029 codeview_snarf(msc_dbg
, modimage
, 0,
2030 pdb_get_file_size(pdb_lookup
, symbols
.gsym_file
), NULL
);
2035 /* Read per-module symbol / linenumber tables */
2036 file
= symbols_image
+ header_size
;
2037 while (file
- symbols_image
< header_size
+ symbols
.module_size
)
2039 PDB_SYMBOL_FILE_EX sfile
;
2040 const char* file_name
;
2043 HeapValidate(GetProcessHeap(), 0, NULL
);
2044 pdb_convert_symbol_file(&symbols
, &sfile
, &size
, file
);
2046 modimage
= pdb_read_file(image
, pdb_lookup
, sfile
.file
);
2049 struct codeview_linetab
* linetab
= NULL
;
2051 if (sfile
.lineno_size
)
2052 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2053 modimage
+ sfile
.symbol_size
,
2055 pdb_lookup
->kind
== PDB_JG
);
2057 if (sfile
.symbol_size
)
2058 codeview_snarf(msc_dbg
, modimage
, sizeof(DWORD
),
2059 sfile
.symbol_size
, linetab
);
2063 file_name
= (const char*)file
+ size
;
2064 file_name
+= strlen(file_name
) + 1;
2065 file
= (char*)((DWORD
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3);
2069 pdb_process_symbol_imports(pcs
, msc_dbg
, NULL
, NULL
, image
, pdb_lookup
,
2071 msc_dbg
->module
->module
.SymType
= SymCv
;
2076 if (symbols_image
) pdb_free(symbols_image
);
2077 pdb_free_lookup(pdb_lookup
);
2079 if (image
) UnmapViewOfFile(image
);
2080 if (hMap
) CloseHandle(hMap
);
2081 if (hFile
) CloseHandle(hFile
);
2086 static BOOL
pdb_process_file(const struct process
* pcs
,
2087 const struct msc_debug_info
* msc_dbg
,
2088 struct pdb_lookup
* pdb_lookup
)
2092 memset(cv_zmodules
, 0, sizeof(cv_zmodules
));
2093 codeview_init_basic_types(msc_dbg
->module
);
2094 ret
= pdb_process_internal(pcs
, msc_dbg
, pdb_lookup
, -1);
2095 codeview_clear_type_table();
2099 /*========================================================================
2100 * Process CodeView debug information.
2103 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
2104 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
2105 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
2106 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
2107 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
2109 typedef struct _CODEVIEW_HEADER_NBxx
2113 } CODEVIEW_HEADER_NBxx
,* PCODEVIEW_HEADER_NBxx
;
2115 typedef struct _CODEVIEW_HEADER_RSDS
2121 } CODEVIEW_HEADER_RSDS
,* PCODEVIEW_HEADER_RSDS
;
2123 typedef struct _CODEVIEW_PDB_DATA
2128 } CODEVIEW_PDB_DATA
, *PCODEVIEW_PDB_DATA
;
2130 typedef struct _CV_DIRECTORY_HEADER
2137 } CV_DIRECTORY_HEADER
, *PCV_DIRECTORY_HEADER
;
2139 typedef struct _CV_DIRECTORY_ENTRY
2145 } CV_DIRECTORY_ENTRY
, *PCV_DIRECTORY_ENTRY
;
2147 #define sstAlignSym 0x125
2148 #define sstSrcModule 0x127
2150 static BOOL
codeview_process_info(const struct process
* pcs
,
2151 const struct msc_debug_info
* msc_dbg
)
2153 const CODEVIEW_HEADER_NBxx
* cv
= (const CODEVIEW_HEADER_NBxx
*)msc_dbg
->root
;
2155 struct pdb_lookup pdb_lookup
;
2157 TRACE("Processing signature %.4s\n", (const char*)&cv
->dwSignature
);
2159 switch (cv
->dwSignature
)
2161 case CODEVIEW_NB09_SIG
:
2162 case CODEVIEW_NB11_SIG
:
2164 const CV_DIRECTORY_HEADER
* hdr
= (const CV_DIRECTORY_HEADER
*)(msc_dbg
->root
+ cv
->lfoDirectory
);
2165 const CV_DIRECTORY_ENTRY
* ent
;
2166 const CV_DIRECTORY_ENTRY
* prev
;
2167 const CV_DIRECTORY_ENTRY
* next
;
2170 codeview_init_basic_types(msc_dbg
->module
);
2171 ent
= (const CV_DIRECTORY_ENTRY
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
);
2172 for (i
= 0; i
< hdr
->cDir
; i
++, ent
= next
)
2174 next
= (i
== hdr
->cDir
-1)? NULL
:
2175 (const CV_DIRECTORY_ENTRY
*)((const BYTE
*)ent
+ hdr
->cbDirEntry
);
2176 prev
= (i
== 0)? NULL
:
2177 (const CV_DIRECTORY_ENTRY
*)((const BYTE
*)ent
- hdr
->cbDirEntry
);
2179 if (ent
->subsection
== sstAlignSym
)
2182 * Check the next and previous entry. If either is a
2183 * sstSrcModule, it contains the line number info for
2186 * FIXME: This is not a general solution!
2188 struct codeview_linetab
* linetab
= NULL
;
2190 if (next
&& next
->iMod
== ent
->iMod
&&
2191 next
->subsection
== sstSrcModule
)
2192 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2193 msc_dbg
->root
+ next
->lfo
, next
->cb
,
2196 if (prev
&& prev
->iMod
== ent
->iMod
&&
2197 prev
->subsection
== sstSrcModule
)
2198 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2199 msc_dbg
->root
+ prev
->lfo
, prev
->cb
,
2202 codeview_snarf(msc_dbg
, msc_dbg
->root
+ ent
->lfo
, sizeof(DWORD
),
2207 msc_dbg
->module
->module
.SymType
= SymCv
;
2212 case CODEVIEW_NB10_SIG
:
2214 const CODEVIEW_PDB_DATA
* pdb
= (const CODEVIEW_PDB_DATA
*)(cv
+ 1);
2215 pdb_lookup
.filename
= pdb
->name
;
2216 pdb_lookup
.kind
= PDB_JG
;
2217 pdb_lookup
.u
.jg
.timestamp
= pdb
->timestamp
;
2218 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
2221 case CODEVIEW_RSDS_SIG
:
2223 const CODEVIEW_HEADER_RSDS
* rsds
= (const CODEVIEW_HEADER_RSDS
*)msc_dbg
->root
;
2225 TRACE("Got RSDS type of PDB file: guid=%s unk=%08lx name=%s\n",
2226 wine_dbgstr_guid(&rsds
->guid
), rsds
->unknown
, rsds
->name
);
2227 pdb_lookup
.filename
= rsds
->name
;
2228 pdb_lookup
.kind
= PDB_DS
;
2229 pdb_lookup
.u
.ds
.guid
= rsds
->guid
;
2230 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
2234 ERR("Unknown CODEVIEW signature %08lX in module %s\n",
2235 cv
->dwSignature
, msc_dbg
->module
->module
.ModuleName
);
2242 /*========================================================================
2243 * Process debug directory.
2245 BOOL
pe_load_debug_directory(const struct process
* pcs
, struct module
* module
,
2246 const BYTE
* mapping
,
2247 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
2248 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
)
2252 struct msc_debug_info msc_dbg
;
2254 msc_dbg
.module
= module
;
2255 msc_dbg
.nsect
= nsect
;
2256 msc_dbg
.sectp
= sectp
;
2258 msc_dbg
.omapp
= NULL
;
2264 /* First, watch out for OMAP data */
2265 for (i
= 0; i
< nDbg
; i
++)
2267 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
)
2269 msc_dbg
.nomap
= dbg
[i
].SizeOfData
/ sizeof(OMAP_DATA
);
2270 msc_dbg
.omapp
= (const OMAP_DATA
*)(mapping
+ dbg
[i
].PointerToRawData
);
2275 /* Now, try to parse CodeView debug info */
2276 for (i
= 0; i
< nDbg
; i
++)
2278 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_CODEVIEW
)
2280 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
2281 if ((ret
= codeview_process_info(pcs
, &msc_dbg
))) goto done
;
2285 /* If not found, try to parse COFF debug info */
2286 for (i
= 0; i
< nDbg
; i
++)
2288 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_COFF
)
2290 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
2291 if ((ret
= coff_process_info(&msc_dbg
))) goto done
;
2295 /* FIXME: this should be supported... this is the debug information for
2296 * functions compiled without a frame pointer (FPO = frame pointer omission)
2297 * the associated data helps finding out the relevant information
2299 for (i
= 0; i
< nDbg
; i
++)
2300 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_FPO
)
2301 FIXME("This guy has FPO information\n");
2305 #define FRAME_TRAP 1
2308 typedef struct _FPO_DATA
2310 DWORD ulOffStart
; /* offset 1st byte of function code */
2311 DWORD cbProcSize
; /* # bytes in function */
2312 DWORD cdwLocals
; /* # bytes in locals/4 */
2313 WORD cdwParams
; /* # bytes in params/4 */
2315 WORD cbProlog
: 8; /* # bytes in prolog */
2316 WORD cbRegs
: 3; /* # regs saved */
2317 WORD fHasSEH
: 1; /* TRUE if SEH in func */
2318 WORD fUseBP
: 1; /* TRUE if EBP has been allocated */
2319 WORD reserved
: 1; /* reserved for future use */
2320 WORD cbFrame
: 2; /* frame type */
2325 __EXCEPT(page_fault
)
2327 ERR("Got a page fault while loading symbols\n");