2 * File msc.c - read VC++ debug information from COFF and eventually
5 * Copyright (C) 1996, Eric Youngdale.
6 * Copyright (C) 1999-2000, Ulrich Weigand.
7 * Copyright (C) 2004-2006, Eric Pouech.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * Note - this handles reading debug information for 32 bit applications
26 * that run under Windows-NT for example. I doubt that this would work well
27 * for 16 bit applications, but I don't think it really matters since the
28 * file format is different, and we should never get in here in such cases.
31 * Get 16 bit CV stuff working.
32 * Add symbol size to internal symbol table.
36 #include "wine/port.h"
47 #define PATH_MAX MAX_PATH
54 #include "wine/exception.h"
55 #include "wine/debug.h"
56 #include "dbghelp_private.h"
57 #include "wine/mscvpdb.h"
59 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp_msc
);
61 #define MAX_PATHNAME_LEN 1024
63 /*========================================================================
64 * Debug file access helper routines
67 static void dump(const void* ptr
, unsigned len
)
71 const char* hexof
= "0123456789abcdef";
72 const BYTE
* x
= (const BYTE
*)ptr
;
74 for (i
= 0; i
< len
; i
+= 16)
76 sprintf(msg
, "%08x: ", i
);
77 memset(msg
+ 10, ' ', 3 * 16 + 1 + 16);
78 for (j
= 0; j
< min(16, len
- i
); j
++)
80 msg
[10 + 3 * j
+ 0] = hexof
[x
[i
+ j
] >> 4];
81 msg
[10 + 3 * j
+ 1] = hexof
[x
[i
+ j
] & 15];
82 msg
[10 + 3 * j
+ 2] = ' ';
83 msg
[10 + 3 * 16 + 1 + j
] = (x
[i
+ j
] >= 0x20 && x
[i
+ j
] < 0x7f) ?
86 msg
[10 + 3 * 16] = ' ';
87 msg
[10 + 3 * 16 + 1 + 16] = '\0';
92 /*========================================================================
93 * Process CodeView type information.
96 #define MAX_BUILTIN_TYPES 0x0480
97 #define FIRST_DEFINABLE_TYPE 0x1000
99 static struct symt
* cv_basic_types
[MAX_BUILTIN_TYPES
];
101 struct cv_defined_module
104 unsigned int num_defined_types
;
105 struct symt
** defined_types
;
107 /* FIXME: don't make it static */
108 #define CV_MAX_MODULES 32
109 static struct cv_defined_module cv_zmodules
[CV_MAX_MODULES
];
110 static struct cv_defined_module
*cv_current_module
;
112 static void codeview_init_basic_types(struct module
* module
)
115 * These are the common builtin types that are used by VC++.
117 cv_basic_types
[T_NOTYPE
] = NULL
;
118 cv_basic_types
[T_ABS
] = NULL
;
119 cv_basic_types
[T_VOID
] = &symt_new_basic(module
, btVoid
, "void", 0)->symt
;
120 cv_basic_types
[T_CHAR
] = &symt_new_basic(module
, btChar
, "char", 1)->symt
;
121 cv_basic_types
[T_SHORT
] = &symt_new_basic(module
, btInt
, "short int", 2)->symt
;
122 cv_basic_types
[T_LONG
] = &symt_new_basic(module
, btInt
, "long int", 4)->symt
;
123 cv_basic_types
[T_QUAD
] = &symt_new_basic(module
, btInt
, "long long int", 8)->symt
;
124 cv_basic_types
[T_UCHAR
] = &symt_new_basic(module
, btUInt
, "unsigned char", 1)->symt
;
125 cv_basic_types
[T_USHORT
] = &symt_new_basic(module
, btUInt
, "unsigned short", 2)->symt
;
126 cv_basic_types
[T_ULONG
] = &symt_new_basic(module
, btUInt
, "unsigned long", 4)->symt
;
127 cv_basic_types
[T_UQUAD
] = &symt_new_basic(module
, btUInt
, "unsigned long long", 8)->symt
;
128 cv_basic_types
[T_BOOL08
] = &symt_new_basic(module
, btBool
, "BOOL08", 1)->symt
;
129 cv_basic_types
[T_BOOL16
] = &symt_new_basic(module
, btBool
, "BOOL16", 2)->symt
;
130 cv_basic_types
[T_BOOL32
] = &symt_new_basic(module
, btBool
, "BOOL32", 4)->symt
;
131 cv_basic_types
[T_BOOL64
] = &symt_new_basic(module
, btBool
, "BOOL64", 8)->symt
;
132 cv_basic_types
[T_REAL32
] = &symt_new_basic(module
, btFloat
, "float", 4)->symt
;
133 cv_basic_types
[T_REAL64
] = &symt_new_basic(module
, btFloat
, "double", 8)->symt
;
134 cv_basic_types
[T_RCHAR
] = &symt_new_basic(module
, btInt
, "signed char", 1)->symt
;
135 cv_basic_types
[T_WCHAR
] = &symt_new_basic(module
, btWChar
, "wchar_t", 2)->symt
;
136 cv_basic_types
[T_INT2
] = &symt_new_basic(module
, btInt
, "INT2", 2)->symt
;
137 cv_basic_types
[T_UINT2
] = &symt_new_basic(module
, btUInt
, "UINT2", 2)->symt
;
138 cv_basic_types
[T_INT4
] = &symt_new_basic(module
, btInt
, "INT4", 4)->symt
;
139 cv_basic_types
[T_UINT4
] = &symt_new_basic(module
, btUInt
, "UINT4", 4)->symt
;
140 cv_basic_types
[T_INT8
] = &symt_new_basic(module
, btInt
, "INT8", 8)->symt
;
141 cv_basic_types
[T_UINT8
] = &symt_new_basic(module
, btUInt
, "UINT8", 8)->symt
;
142 cv_basic_types
[T_HRESULT
]= &symt_new_basic(module
, btUInt
, "HRESULT", 4)->symt
;
144 cv_basic_types
[T_32PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
])->symt
;
145 cv_basic_types
[T_32PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
])->symt
;
146 cv_basic_types
[T_32PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
])->symt
;
147 cv_basic_types
[T_32PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
])->symt
;
148 cv_basic_types
[T_32PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
])->symt
;
149 cv_basic_types
[T_32PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
])->symt
;
150 cv_basic_types
[T_32PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
])->symt
;
151 cv_basic_types
[T_32PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
])->symt
;
152 cv_basic_types
[T_32PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
])->symt
;
153 cv_basic_types
[T_32PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
])->symt
;
154 cv_basic_types
[T_32PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
])->symt
;
155 cv_basic_types
[T_32PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
])->symt
;
156 cv_basic_types
[T_32PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
])->symt
;
157 cv_basic_types
[T_32PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
])->symt
;
158 cv_basic_types
[T_32PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
])->symt
;
159 cv_basic_types
[T_32PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
])->symt
;
160 cv_basic_types
[T_32PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
])->symt
;
161 cv_basic_types
[T_32PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
])->symt
;
162 cv_basic_types
[T_32PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
])->symt
;
163 cv_basic_types
[T_32PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
])->symt
;
164 cv_basic_types
[T_32PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
])->symt
;
165 cv_basic_types
[T_32PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
])->symt
;
166 cv_basic_types
[T_32PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
])->symt
;
167 cv_basic_types
[T_32PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
])->symt
;
170 static int numeric_leaf(int* value
, const unsigned short int* leaf
)
172 unsigned short int type
= *leaf
++;
175 if (type
< LF_NUMERIC
)
185 *value
= *(const char*)leaf
;
190 *value
= *(const short*)leaf
;
200 *value
= *(const int*)leaf
;
205 *value
= *(const unsigned int*)leaf
;
210 FIXME("Unsupported numeric leaf type %04x\n", type
);
212 *value
= 0; /* FIXME */
216 FIXME("Unsupported numeric leaf type %04x\n", type
);
218 *value
= 0; /* FIXME */
222 FIXME("Unsupported numeric leaf type %04x\n", type
);
224 *value
= 0; /* FIXME */
228 FIXME("Unsupported numeric leaf type %04x\n", type
);
230 *value
= 0; /* FIXME */
234 FIXME("Unsupported numeric leaf type %04x\n", type
);
236 *value
= 0; /* FIXME */
240 FIXME("Unsupported numeric leaf type %04x\n", type
);
242 *value
= 0; /* FIXME */
246 FIXME("Unsupported numeric leaf type %04x\n", type
);
248 *value
= 0; /* FIXME */
252 FIXME("Unsupported numeric leaf type %04x\n", type
);
254 *value
= 0; /* FIXME */
258 FIXME("Unsupported numeric leaf type %04x\n", type
);
260 *value
= 0; /* FIXME */
264 FIXME("Unsupported numeric leaf type %04x\n", type
);
266 *value
= 0; /* FIXME */
270 FIXME("Unsupported numeric leaf type %04x\n", type
);
272 *value
= 0; /* FIXME */
276 FIXME("Unknown numeric leaf type %04x\n", type
);
285 /* convert a pascal string (as stored in debug information) into
286 * a C string (null terminated).
288 static const char* terminate_string(const struct p_string
* p_name
)
290 static char symname
[256];
292 memcpy(symname
, p_name
->name
, p_name
->namelen
);
293 symname
[p_name
->namelen
] = '\0';
295 return (!*symname
|| strcmp(symname
, "__unnamed") == 0) ? NULL
: symname
;
298 static struct symt
* codeview_get_type(unsigned int typeno
, BOOL quiet
)
300 struct symt
* symt
= NULL
;
303 * Convert Codeview type numbers into something we can grok internally.
304 * Numbers < FIRST_DEFINABLE_TYPE are all fixed builtin types.
305 * Numbers from FIRST_DEFINABLE_TYPE and up are all user defined (structs, etc).
307 if (typeno
< FIRST_DEFINABLE_TYPE
)
309 if (typeno
< MAX_BUILTIN_TYPES
)
310 symt
= cv_basic_types
[typeno
];
314 unsigned mod_index
= typeno
>> 24;
315 unsigned mod_typeno
= typeno
& 0x00FFFFFF;
316 struct cv_defined_module
* mod
;
318 mod
= (mod_index
== 0) ? cv_current_module
: &cv_zmodules
[mod_index
];
320 if (mod_index
>= CV_MAX_MODULES
|| !mod
->allowed
)
321 FIXME("Module of index %d isn't loaded yet (%x)\n", mod_index
, typeno
);
324 if (mod_typeno
- FIRST_DEFINABLE_TYPE
< mod
->num_defined_types
)
325 symt
= mod
->defined_types
[mod_typeno
- FIRST_DEFINABLE_TYPE
];
328 if (!quiet
&& !symt
&& typeno
) FIXME("Returning NULL symt for type-id %x\n", typeno
);
332 struct codeview_type_parse
334 struct module
* module
;
340 static inline const void* codeview_jump_to_type(const struct codeview_type_parse
* ctp
, DWORD idx
)
342 if (idx
< FIRST_DEFINABLE_TYPE
) return NULL
;
343 idx
-= FIRST_DEFINABLE_TYPE
;
344 return (idx
>= ctp
->num
) ? NULL
: (ctp
->table
+ ctp
->offset
[idx
]);
347 static int codeview_add_type(unsigned int typeno
, struct symt
* dt
)
349 if (typeno
< FIRST_DEFINABLE_TYPE
)
350 FIXME("What the heck\n");
351 if (!cv_current_module
)
353 FIXME("Adding %x to non allowed module\n", typeno
);
356 if ((typeno
>> 24) != 0)
357 FIXME("No module index while inserting type-id assumption is wrong %x\n",
359 while (typeno
- FIRST_DEFINABLE_TYPE
>= cv_current_module
->num_defined_types
)
361 cv_current_module
->num_defined_types
+= 0x100;
362 if (cv_current_module
->defined_types
)
363 cv_current_module
->defined_types
= HeapReAlloc(GetProcessHeap(),
364 HEAP_ZERO_MEMORY
, cv_current_module
->defined_types
,
365 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
367 cv_current_module
->defined_types
= HeapAlloc(GetProcessHeap(),
369 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
371 if (cv_current_module
->defined_types
== NULL
) return FALSE
;
373 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
])
375 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] != dt
)
376 FIXME("Overwriting at %x\n", typeno
);
378 cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] = dt
;
382 static void codeview_clear_type_table(void)
386 for (i
= 0; i
< CV_MAX_MODULES
; i
++)
388 if (cv_zmodules
[i
].allowed
)
389 HeapFree(GetProcessHeap(), 0, cv_zmodules
[i
].defined_types
);
390 cv_zmodules
[i
].allowed
= FALSE
;
391 cv_zmodules
[i
].defined_types
= NULL
;
392 cv_zmodules
[i
].num_defined_types
= 0;
394 cv_current_module
= NULL
;
397 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
399 const union codeview_type
* type
, BOOL details
);
401 static void* codeview_cast_symt(struct symt
* symt
, enum SymTagEnum tag
)
403 if (symt
->tag
!= tag
)
405 FIXME("Bad tag. Expected %d, but got %d\n", tag
, symt
->tag
);
411 static struct symt
* codeview_fetch_type(struct codeview_type_parse
* ctp
,
412 unsigned typeno
, BOOL details
)
415 const union codeview_type
* p
;
417 if (!typeno
) return NULL
;
418 if ((symt
= codeview_get_type(typeno
, TRUE
))) return symt
;
420 /* forward declaration */
421 if (!(p
= codeview_jump_to_type(ctp
, typeno
)))
423 FIXME("Cannot locate type %x\n", typeno
);
426 symt
= codeview_parse_one_type(ctp
, typeno
, p
, details
);
427 if (!symt
) FIXME("Couldn't load forward type %x\n", typeno
);
431 static struct symt
* codeview_add_type_pointer(struct codeview_type_parse
* ctp
,
432 struct symt
* existing
,
433 unsigned int pointee_type
)
435 struct symt
* pointee
;
439 existing
= codeview_cast_symt(existing
, SymTagPointerType
);
442 pointee
= codeview_fetch_type(ctp
, pointee_type
, FALSE
);
443 return &symt_new_pointer(ctp
->module
, pointee
)->symt
;
446 static struct symt
* codeview_add_type_array(struct codeview_type_parse
* ctp
,
448 unsigned int elemtype
,
449 unsigned int indextype
,
450 unsigned int arr_len
)
452 struct symt
* elem
= codeview_fetch_type(ctp
, elemtype
, FALSE
);
453 struct symt
* index
= codeview_fetch_type(ctp
, indextype
, FALSE
);
459 symt_get_info(elem
, TI_GET_LENGTH
, &elem_size
);
460 if (elem_size
) arr_max
= arr_len
/ (DWORD
)elem_size
;
462 return &symt_new_array(ctp
->module
, 0, arr_max
, elem
, index
)->symt
;
465 static int codeview_add_type_enum_field_list(struct module
* module
,
466 struct symt_enum
* symt
,
467 const union codeview_reftype
* ref_type
)
469 const unsigned char* ptr
= ref_type
->fieldlist
.list
;
470 const unsigned char* last
= (const BYTE
*)ref_type
+ ref_type
->generic
.len
+ 2;
471 const union codeview_fieldtype
* type
;
475 if (*ptr
>= 0xf0) /* LF_PAD... */
481 type
= (const union codeview_fieldtype
*)ptr
;
483 switch (type
->generic
.id
)
485 case LF_ENUMERATE_V1
:
487 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v1
.value
);
488 const struct p_string
* p_name
= (const struct p_string
*)((const unsigned char*)&type
->enumerate_v1
.value
+ vlen
);
490 symt_add_enum_element(module
, symt
, terminate_string(p_name
), value
);
491 ptr
+= 2 + 2 + vlen
+ (1 + p_name
->namelen
);
494 case LF_ENUMERATE_V3
:
496 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v3
.value
);
497 const char* name
= (const char*)&type
->enumerate_v3
.value
+ vlen
;
499 symt_add_enum_element(module
, symt
, name
, value
);
500 ptr
+= 2 + 2 + vlen
+ (1 + strlen(name
));
505 FIXME("Unsupported type %04x in ENUM field list\n", type
->generic
.id
);
512 static void codeview_add_udt_element(struct codeview_type_parse
* ctp
,
513 struct symt_udt
* symt
, const char* name
,
514 int value
, unsigned type
)
516 struct symt
* subtype
;
517 const union codeview_reftype
*cv_type
;
519 if ((cv_type
= codeview_jump_to_type(ctp
, type
)))
521 switch (cv_type
->generic
.id
)
524 symt_add_udt_element(ctp
->module
, symt
, name
,
525 codeview_fetch_type(ctp
, cv_type
->bitfield_v1
.type
, FALSE
),
526 cv_type
->bitfield_v1
.bitoff
,
527 cv_type
->bitfield_v1
.nbits
);
530 symt_add_udt_element(ctp
->module
, symt
, name
,
531 codeview_fetch_type(ctp
, cv_type
->bitfield_v2
.type
, FALSE
),
532 cv_type
->bitfield_v2
.bitoff
,
533 cv_type
->bitfield_v2
.nbits
);
537 subtype
= codeview_fetch_type(ctp
, type
, FALSE
);
541 DWORD64 elem_size
= 0;
542 symt_get_info(subtype
, TI_GET_LENGTH
, &elem_size
);
543 symt_add_udt_element(ctp
->module
, symt
, name
, subtype
,
544 value
<< 3, (DWORD
)elem_size
<< 3);
548 static int codeview_add_type_struct_field_list(struct codeview_type_parse
* ctp
,
549 struct symt_udt
* symt
,
550 unsigned fieldlistno
)
552 const unsigned char* ptr
;
553 const unsigned char* last
;
555 const struct p_string
* p_name
;
557 const union codeview_reftype
*type_ref
;
558 const union codeview_fieldtype
* type
;
560 if (!fieldlistno
) return TRUE
;
561 type_ref
= codeview_jump_to_type(ctp
, fieldlistno
);
562 ptr
= type_ref
->fieldlist
.list
;
563 last
= (const BYTE
*)type_ref
+ type_ref
->generic
.len
+ 2;
567 if (*ptr
>= 0xf0) /* LF_PAD... */
573 type
= (const union codeview_fieldtype
*)ptr
;
575 switch (type
->generic
.id
)
578 leaf_len
= numeric_leaf(&value
, &type
->bclass_v1
.offset
);
580 /* FIXME: ignored for now */
582 ptr
+= 2 + 2 + 2 + leaf_len
;
586 leaf_len
= numeric_leaf(&value
, &type
->bclass_v2
.offset
);
588 /* FIXME: ignored for now */
590 ptr
+= 2 + 2 + 4 + leaf_len
;
596 const unsigned short int* p_vboff
;
598 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v1
.vbpoff
);
599 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v1
.vbpoff
+ leaf_len
);
600 vplen
= numeric_leaf(&vpoff
, p_vboff
);
602 /* FIXME: ignored for now */
604 ptr
+= 2 + 2 + 2 + 2 + leaf_len
+ vplen
;
611 const unsigned short int* p_vboff
;
613 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v2
.vbpoff
);
614 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v2
.vbpoff
+ leaf_len
);
615 vplen
= numeric_leaf(&vpoff
, p_vboff
);
617 /* FIXME: ignored for now */
619 ptr
+= 2 + 2 + 4 + 4 + leaf_len
+ vplen
;
624 leaf_len
= numeric_leaf(&value
, &type
->member_v1
.offset
);
625 p_name
= (const struct p_string
*)((const char*)&type
->member_v1
.offset
+ leaf_len
);
627 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
628 type
->member_v1
.type
);
630 ptr
+= 2 + 2 + 2 + leaf_len
+ (1 + p_name
->namelen
);
634 leaf_len
= numeric_leaf(&value
, &type
->member_v2
.offset
);
635 p_name
= (const struct p_string
*)((const unsigned char*)&type
->member_v2
.offset
+ leaf_len
);
637 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
638 type
->member_v2
.type
);
640 ptr
+= 2 + 2 + 4 + leaf_len
+ (1 + p_name
->namelen
);
644 leaf_len
= numeric_leaf(&value
, &type
->member_v3
.offset
);
645 c_name
= (const char*)&type
->member_v3
.offset
+ leaf_len
;
647 codeview_add_udt_element(ctp
, symt
, c_name
, value
, type
->member_v3
.type
);
649 ptr
+= 2 + 2 + 4 + leaf_len
+ (strlen(c_name
) + 1);
653 /* FIXME: ignored for now */
654 ptr
+= 2 + 2 + 2 + (1 + type
->stmember_v1
.p_name
.namelen
);
658 /* FIXME: ignored for now */
659 ptr
+= 2 + 4 + 2 + (1 + type
->stmember_v2
.p_name
.namelen
);
663 /* FIXME: ignored for now */
664 ptr
+= 2 + 4 + 2 + (strlen(type
->stmember_v3
.name
) + 1);
668 /* FIXME: ignored for now */
669 ptr
+= 2 + 2 + 2 + (1 + type
->method_v1
.p_name
.namelen
);
673 /* FIXME: ignored for now */
674 ptr
+= 2 + 2 + 4 + (1 + type
->method_v2
.p_name
.namelen
);
678 /* FIXME: ignored for now */
679 ptr
+= 2 + 2 + 4 + (strlen(type
->method_v3
.name
) + 1);
683 /* FIXME: ignored for now */
684 ptr
+= 2 + 2 + (1 + type
->nesttype_v1
.p_name
.namelen
);
688 /* FIXME: ignored for now */
689 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype_v2
.p_name
.namelen
);
693 /* FIXME: ignored for now */
694 ptr
+= 2 + 2 + 4 + (strlen(type
->nesttype_v3
.name
) + 1);
698 /* FIXME: ignored for now */
703 /* FIXME: ignored for now */
707 case LF_ONEMETHOD_V1
:
708 /* FIXME: ignored for now */
709 switch ((type
->onemethod_v1
.attribute
>> 2) & 7)
711 case 4: case 6: /* (pure) introducing virtual method */
712 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt_v1
.p_name
.namelen
);
716 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod_v1
.p_name
.namelen
);
721 case LF_ONEMETHOD_V2
:
722 /* FIXME: ignored for now */
723 switch ((type
->onemethod_v2
.attribute
>> 2) & 7)
725 case 4: case 6: /* (pure) introducing virtual method */
726 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod_virt_v2
.p_name
.namelen
);
730 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod_v2
.p_name
.namelen
);
735 case LF_ONEMETHOD_V3
:
736 /* FIXME: ignored for now */
737 switch ((type
->onemethod_v3
.attribute
>> 2) & 7)
739 case 4: case 6: /* (pure) introducing virtual method */
740 ptr
+= 2 + 2 + 4 + 4 + (strlen(type
->onemethod_virt_v3
.name
) + 1);
744 ptr
+= 2 + 2 + 4 + (strlen(type
->onemethod_v3
.name
) + 1);
750 FIXME("Unsupported type %04x in STRUCT field list\n", type
->generic
.id
);
758 static struct symt
* codeview_add_type_enum(struct codeview_type_parse
* ctp
,
759 struct symt
* existing
,
761 unsigned fieldlistno
,
764 struct symt_enum
* symt
;
768 if (!(symt
= codeview_cast_symt(existing
, SymTagEnum
))) return NULL
;
769 /* should also check that all fields are the same */
773 symt
= symt_new_enum(ctp
->module
, name
,
774 codeview_fetch_type(ctp
, basetype
, FALSE
));
777 const union codeview_reftype
* fieldlist
;
778 fieldlist
= codeview_jump_to_type(ctp
, fieldlistno
);
779 codeview_add_type_enum_field_list(ctp
->module
, symt
, fieldlist
);
785 static struct symt
* codeview_add_type_struct(struct codeview_type_parse
* ctp
,
786 struct symt
* existing
,
787 const char* name
, int structlen
,
790 struct symt_udt
* symt
;
794 if (!(symt
= codeview_cast_symt(existing
, SymTagUDT
))) return NULL
;
795 /* should also check that all fields are the same */
797 else symt
= symt_new_udt(ctp
->module
, name
, structlen
, kind
);
802 static struct symt
* codeview_new_func_signature(struct codeview_type_parse
* ctp
,
803 struct symt
* existing
,
804 enum CV_call_e call_conv
)
806 struct symt_function_signature
* sym
;
810 sym
= codeview_cast_symt(existing
, SymTagFunctionType
);
811 if (!sym
) return NULL
;
815 sym
= symt_new_function_signature(ctp
->module
, NULL
, call_conv
);
820 static void codeview_add_func_signature_args(struct codeview_type_parse
* ctp
,
821 struct symt_function_signature
* sym
,
825 const union codeview_reftype
* reftype
;
827 sym
->rettype
= codeview_fetch_type(ctp
, ret_type
, FALSE
);
828 if (args_list
&& (reftype
= codeview_jump_to_type(ctp
, args_list
)))
831 switch (reftype
->generic
.id
)
834 for (i
= 0; i
< reftype
->arglist_v1
.num
; i
++)
835 symt_add_function_signature_parameter(ctp
->module
, sym
,
836 codeview_fetch_type(ctp
, reftype
->arglist_v1
.args
[i
], FALSE
));
839 for (i
= 0; i
< reftype
->arglist_v2
.num
; i
++)
840 symt_add_function_signature_parameter(ctp
->module
, sym
,
841 codeview_fetch_type(ctp
, reftype
->arglist_v2
.args
[i
], FALSE
));
844 FIXME("Unexpected leaf %x for signature's pmt\n", reftype
->generic
.id
);
849 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
851 const union codeview_type
* type
, BOOL details
)
855 const struct p_string
* p_name
;
857 struct symt
* existing
;
859 existing
= codeview_get_type(curr_type
, TRUE
);
861 switch (type
->generic
.id
)
864 /* FIXME: we don't handle modifiers,
865 * but read previous type on the curr_type
867 WARN("Modifier on %x: %s%s%s%s\n",
868 type
->modifier_v1
.type
,
869 type
->modifier_v1
.attribute
& 0x01 ? "const " : "",
870 type
->modifier_v1
.attribute
& 0x02 ? "volatile " : "",
871 type
->modifier_v1
.attribute
& 0x04 ? "unaligned " : "",
872 type
->modifier_v1
.attribute
& ~0x07 ? "unknown " : "");
873 symt
= codeview_fetch_type(ctp
, type
->modifier_v1
.type
, details
);
876 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
877 WARN("Modifier on %x: %s%s%s%s\n",
878 type
->modifier_v2
.type
,
879 type
->modifier_v2
.attribute
& 0x01 ? "const " : "",
880 type
->modifier_v2
.attribute
& 0x02 ? "volatile " : "",
881 type
->modifier_v2
.attribute
& 0x04 ? "unaligned " : "",
882 type
->modifier_v2
.attribute
& ~0x07 ? "unknown " : "");
883 symt
= codeview_fetch_type(ctp
, type
->modifier_v2
.type
, details
);
887 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v1
.datatype
);
890 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v2
.datatype
);
894 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
897 leaf_len
= numeric_leaf(&value
, &type
->array_v1
.arrlen
);
898 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v1
.arrlen
+ leaf_len
);
899 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
900 type
->array_v1
.elemtype
,
901 type
->array_v1
.idxtype
, value
);
905 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
908 leaf_len
= numeric_leaf(&value
, &type
->array_v2
.arrlen
);
909 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v2
.arrlen
+ leaf_len
);
911 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
912 type
->array_v2
.elemtype
,
913 type
->array_v2
.idxtype
, value
);
917 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
920 leaf_len
= numeric_leaf(&value
, &type
->array_v3
.arrlen
);
921 c_name
= (const char*)&type
->array_v3
.arrlen
+ leaf_len
;
923 symt
= codeview_add_type_array(ctp
, c_name
,
924 type
->array_v3
.elemtype
,
925 type
->array_v3
.idxtype
, value
);
929 case LF_STRUCTURE_V1
:
931 leaf_len
= numeric_leaf(&value
, &type
->struct_v1
.structlen
);
932 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v1
.structlen
+ leaf_len
);
933 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
934 type
->generic
.id
== LF_CLASS_V1
? UdtClass
: UdtStruct
);
937 codeview_add_type(curr_type
, symt
);
938 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
939 type
->struct_v1
.fieldlist
);
943 case LF_STRUCTURE_V2
:
945 leaf_len
= numeric_leaf(&value
, &type
->struct_v2
.structlen
);
946 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v2
.structlen
+ leaf_len
);
947 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
948 type
->generic
.id
== LF_CLASS_V2
? UdtClass
: UdtStruct
);
951 codeview_add_type(curr_type
, symt
);
952 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
953 type
->struct_v2
.fieldlist
);
957 case LF_STRUCTURE_V3
:
959 leaf_len
= numeric_leaf(&value
, &type
->struct_v3
.structlen
);
960 c_name
= (const char*)&type
->struct_v3
.structlen
+ leaf_len
;
961 symt
= codeview_add_type_struct(ctp
, existing
, c_name
, value
,
962 type
->generic
.id
== LF_CLASS_V3
? UdtClass
: UdtStruct
);
965 codeview_add_type(curr_type
, symt
);
966 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
967 type
->struct_v3
.fieldlist
);
972 leaf_len
= numeric_leaf(&value
, &type
->union_v1
.un_len
);
973 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v1
.un_len
+ leaf_len
);
974 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
978 codeview_add_type(curr_type
, symt
);
979 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
980 type
->union_v1
.fieldlist
);
985 leaf_len
= numeric_leaf(&value
, &type
->union_v2
.un_len
);
986 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v2
.un_len
+ leaf_len
);
987 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
991 codeview_add_type(curr_type
, symt
);
992 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
993 type
->union_v2
.fieldlist
);
998 leaf_len
= numeric_leaf(&value
, &type
->union_v3
.un_len
);
999 c_name
= (const char*)&type
->union_v3
.un_len
+ leaf_len
;
1000 symt
= codeview_add_type_struct(ctp
, existing
, c_name
,
1004 codeview_add_type(curr_type
, symt
);
1005 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1006 type
->union_v3
.fieldlist
);
1011 symt
= codeview_add_type_enum(ctp
, existing
,
1012 terminate_string(&type
->enumeration_v1
.p_name
),
1013 type
->enumeration_v1
.fieldlist
,
1014 type
->enumeration_v1
.type
);
1018 symt
= codeview_add_type_enum(ctp
, existing
,
1019 terminate_string(&type
->enumeration_v2
.p_name
),
1020 type
->enumeration_v2
.fieldlist
,
1021 type
->enumeration_v2
.type
);
1025 symt
= codeview_add_type_enum(ctp
, existing
, type
->enumeration_v3
.name
,
1026 type
->enumeration_v3
.fieldlist
,
1027 type
->enumeration_v3
.type
);
1030 case LF_PROCEDURE_V1
:
1031 symt
= codeview_new_func_signature(ctp
, existing
, type
->procedure_v1
.call
);
1034 codeview_add_type(curr_type
, symt
);
1035 codeview_add_func_signature_args(ctp
,
1036 (struct symt_function_signature
*)symt
,
1037 type
->procedure_v1
.rvtype
,
1038 type
->procedure_v1
.arglist
);
1041 case LF_PROCEDURE_V2
:
1042 symt
= codeview_new_func_signature(ctp
, existing
,type
->procedure_v2
.call
);
1045 codeview_add_type(curr_type
, symt
);
1046 codeview_add_func_signature_args(ctp
,
1047 (struct symt_function_signature
*)symt
,
1048 type
->procedure_v2
.rvtype
,
1049 type
->procedure_v2
.arglist
);
1053 case LF_MFUNCTION_V1
:
1054 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1055 * nor class information, this would just do for now
1057 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v1
.call
);
1060 codeview_add_type(curr_type
, symt
);
1061 codeview_add_func_signature_args(ctp
,
1062 (struct symt_function_signature
*)symt
,
1063 type
->mfunction_v1
.rvtype
,
1064 type
->mfunction_v1
.arglist
);
1067 case LF_MFUNCTION_V2
:
1068 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1069 * nor class information, this would just do for now
1071 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v2
.call
);
1074 codeview_add_type(curr_type
, symt
);
1075 codeview_add_func_signature_args(ctp
,
1076 (struct symt_function_signature
*)symt
,
1077 type
->mfunction_v2
.rvtype
,
1078 type
->mfunction_v2
.arglist
);
1083 /* this is an ugly hack... FIXME when we have C++ support */
1084 if (!(symt
= existing
))
1087 snprintf(buf
, sizeof(buf
), "__internal_vt_shape_%x\n", curr_type
);
1088 symt
= &symt_new_udt(ctp
->module
, buf
, 0, UdtStruct
)->symt
;
1092 FIXME("Unsupported type-id leaf %x\n", type
->generic
.id
);
1093 dump(type
, 2 + type
->generic
.len
);
1096 return codeview_add_type(curr_type
, symt
) ? symt
: NULL
;
1099 static int codeview_parse_type_table(struct codeview_type_parse
* ctp
)
1101 unsigned int curr_type
= FIRST_DEFINABLE_TYPE
;
1102 const union codeview_type
* type
;
1104 for (curr_type
= FIRST_DEFINABLE_TYPE
; curr_type
< FIRST_DEFINABLE_TYPE
+ ctp
->num
; curr_type
++)
1106 type
= codeview_jump_to_type(ctp
, curr_type
);
1108 /* type records we're interested in are the ones referenced by symbols
1109 * The known ranges are (X mark the ones we want):
1110 * X 0000-0016 for V1 types
1111 * 0200-020c for V1 types referenced by other types
1112 * 0400-040f for V1 types (complex lists & sets)
1113 * X 1000-100f for V2 types
1114 * 1200-120c for V2 types referenced by other types
1115 * 1400-140f for V1 types (complex lists & sets)
1116 * X 1500-150d for V3 types
1117 * 8000-8010 for numeric leafes
1119 if (!(type
->generic
.id
& 0x8600) || (type
->generic
.id
& 0x0100))
1120 codeview_parse_one_type(ctp
, curr_type
, type
, TRUE
);
1126 /*========================================================================
1127 * Process CodeView line number information.
1130 static struct codeview_linetab
* codeview_snarf_linetab(struct module
* module
,
1131 const BYTE
* linetab
, int size
,
1135 char filename
[PATH_MAX
];
1136 const unsigned int* filetab
;
1137 const struct p_string
* p_fn
;
1140 struct codeview_linetab
* lt_hdr
;
1141 const unsigned int* lt_ptr
;
1145 union any_size pnt2
;
1146 const struct startend
* start
;
1151 * Now get the important bits.
1157 filetab
= (const unsigned int*) pnt
.c
;
1160 * Now count up the number of segments in the file.
1163 for (i
= 0; i
< nfile
; i
++)
1165 pnt2
.uc
= linetab
+ filetab
[i
];
1170 * Next allocate the header we will be returning.
1171 * There is one header for each segment, so that we can reach in
1172 * and pull bits as required.
1174 lt_hdr
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
1175 (nseg
+ 1) * sizeof(*lt_hdr
));
1182 * Now fill the header we will be returning, one for each segment.
1183 * Note that this will basically just contain pointers into the existing
1184 * line table, and we do not actually copy any additional information
1185 * or allocate any additional memory.
1189 for (i
= 0; i
< nfile
; i
++)
1192 * Get the pointer into the segment information.
1194 pnt2
.uc
= linetab
+ filetab
[i
];
1195 file_segcount
= *pnt2
.s
;
1198 lt_ptr
= (const unsigned int*) pnt2
.c
;
1199 start
= (const struct startend
*)(lt_ptr
+ file_segcount
);
1202 * Now snarf the filename for all of the segments for this file.
1206 p_fn
= (const struct p_string
*)(start
+ file_segcount
);
1207 memset(filename
, 0, sizeof(filename
));
1208 memcpy(filename
, p_fn
->name
, p_fn
->namelen
);
1209 source
= source_new(module
, NULL
, filename
);
1212 source
= source_new(module
, NULL
, (const char*)(start
+ file_segcount
));
1214 for (k
= 0; k
< file_segcount
; k
++, this_seg
++)
1216 pnt2
.uc
= linetab
+ lt_ptr
[k
];
1217 lt_hdr
[this_seg
].start
= start
[k
].start
;
1218 lt_hdr
[this_seg
].end
= start
[k
].end
;
1219 lt_hdr
[this_seg
].source
= source
;
1220 lt_hdr
[this_seg
].segno
= *pnt2
.s
++;
1221 lt_hdr
[this_seg
].nline
= *pnt2
.s
++;
1222 lt_hdr
[this_seg
].offtab
= pnt2
.ui
;
1223 lt_hdr
[this_seg
].linetab
= (const unsigned short*)(pnt2
.ui
+ lt_hdr
[this_seg
].nline
);
1233 /*========================================================================
1234 * Process CodeView symbol information.
1237 static unsigned int codeview_map_offset(const struct msc_debug_info
* msc_dbg
,
1238 unsigned int offset
)
1240 int nomap
= msc_dbg
->nomap
;
1241 const OMAP_DATA
* omapp
= msc_dbg
->omapp
;
1244 if (!nomap
|| !omapp
) return offset
;
1246 /* FIXME: use binary search */
1247 for (i
= 0; i
< nomap
- 1; i
++)
1248 if (omapp
[i
].from
<= offset
&& omapp
[i
+1].from
> offset
)
1249 return !omapp
[i
].to
? 0 : omapp
[i
].to
+ (offset
- omapp
[i
].from
);
1254 static const struct codeview_linetab
*
1255 codeview_get_linetab(const struct codeview_linetab
* linetab
,
1256 unsigned seg
, unsigned offset
)
1259 * Check whether we have line number information
1263 for (; linetab
->linetab
; linetab
++)
1264 if (linetab
->segno
== seg
&&
1265 linetab
->start
<= offset
&& linetab
->end
> offset
)
1267 if (!linetab
->linetab
) linetab
= NULL
;
1272 static unsigned codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1273 unsigned seg
, unsigned offset
)
1275 int nsect
= msc_dbg
->nsect
;
1276 const IMAGE_SECTION_HEADER
* sectp
= msc_dbg
->sectp
;
1278 if (!seg
|| seg
> nsect
) return 0;
1279 return msc_dbg
->module
->module
.BaseOfImage
+
1280 codeview_map_offset(msc_dbg
, sectp
[seg
-1].VirtualAddress
+ offset
);
1283 static void codeview_add_func_linenum(struct module
* module
,
1284 struct symt_function
* func
,
1285 const struct codeview_linetab
* linetab
,
1286 unsigned offset
, unsigned size
)
1290 if (!linetab
) return;
1291 for (i
= 0; i
< linetab
->nline
; i
++)
1293 if (linetab
->offtab
[i
] >= offset
&& linetab
->offtab
[i
] < offset
+ size
)
1295 symt_add_func_line(module
, func
, linetab
->source
,
1296 linetab
->linetab
[i
], linetab
->offtab
[i
] - offset
);
1301 static int codeview_snarf(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1302 int offset
, int size
,
1303 struct codeview_linetab
* linetab
)
1305 struct symt_function
* curr_func
= NULL
;
1307 const struct codeview_linetab
* flt
;
1308 struct symt_block
* block
= NULL
;
1311 struct symt_compiland
* compiland
= NULL
;
1312 struct location loc
;
1315 * Loop over the different types of records and whenever we
1316 * find something we are interested in, record it and move on.
1318 for (i
= offset
; i
< size
; i
+= length
)
1320 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1321 length
= sym
->generic
.len
+ 2;
1322 if (i
+ length
> size
) break;
1323 if (length
& 3) FIXME("unpadded len %u\n", length
);
1325 switch (sym
->generic
.id
)
1328 * Global and local data symbols. We don't associate these
1329 * with any given source file.
1333 symt_new_global_variable(msc_dbg
->module
, compiland
,
1334 terminate_string(&sym
->data_v1
.p_name
), sym
->generic
.id
== S_LDATA_V1
,
1335 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
),
1337 codeview_get_type(sym
->data_v1
.symtype
, FALSE
));
1341 name
= terminate_string(&sym
->data_v2
.p_name
);
1343 symt_new_global_variable(msc_dbg
->module
, compiland
,
1344 name
, sym
->generic
.id
== S_LDATA_V2
,
1345 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
),
1347 codeview_get_type(sym
->data_v2
.symtype
, FALSE
));
1351 if (*sym
->data_v3
.name
)
1352 symt_new_global_variable(msc_dbg
->module
, compiland
,
1354 sym
->generic
.id
== S_LDATA_V3
,
1355 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1357 codeview_get_type(sym
->data_v3
.symtype
, FALSE
));
1360 case S_PUB_V1
: /* FIXME is this really a 'data_v1' structure ?? */
1361 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1363 symt_new_public(msc_dbg
->module
, compiland
,
1364 terminate_string(&sym
->data_v1
.p_name
),
1365 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
),
1366 1, TRUE
/* FIXME */, TRUE
/* FIXME */);
1369 case S_PUB_V2
: /* FIXME is this really a 'data_v2' structure ?? */
1370 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1372 symt_new_public(msc_dbg
->module
, compiland
,
1373 terminate_string(&sym
->data_v2
.p_name
),
1374 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
),
1375 1, TRUE
/* FIXME */, TRUE
/* FIXME */);
1380 * Sort of like a global function, but it just points
1381 * to a thunk, which is a stupid name for what amounts to
1382 * a PLT slot in the normal jargon that everyone else uses.
1385 symt_new_thunk(msc_dbg
->module
, compiland
,
1386 terminate_string(&sym
->thunk_v1
.p_name
), sym
->thunk_v1
.thtype
,
1387 codeview_get_address(msc_dbg
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
),
1388 sym
->thunk_v1
.thunk_len
);
1391 symt_new_thunk(msc_dbg
->module
, compiland
,
1392 sym
->thunk_v3
.name
, sym
->thunk_v3
.thtype
,
1393 codeview_get_address(msc_dbg
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
),
1394 sym
->thunk_v3
.thunk_len
);
1398 * Global and static functions.
1402 flt
= codeview_get_linetab(linetab
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
);
1403 if (curr_func
) FIXME("nested function\n");
1404 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1405 terminate_string(&sym
->proc_v1
.p_name
),
1406 codeview_get_address(msc_dbg
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
),
1407 sym
->proc_v1
.proc_len
,
1408 codeview_get_type(sym
->proc_v1
.proctype
, FALSE
));
1409 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1410 sym
->proc_v1
.offset
, sym
->proc_v1
.proc_len
);
1411 loc
.kind
= loc_absolute
;
1412 loc
.offset
= sym
->proc_v1
.debug_start
;
1413 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1414 loc
.offset
= sym
->proc_v1
.debug_end
;
1415 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1419 flt
= codeview_get_linetab(linetab
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
);
1420 if (curr_func
) FIXME("nested function\n");
1421 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1422 terminate_string(&sym
->proc_v2
.p_name
),
1423 codeview_get_address(msc_dbg
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
),
1424 sym
->proc_v2
.proc_len
,
1425 codeview_get_type(sym
->proc_v2
.proctype
, FALSE
));
1426 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1427 sym
->proc_v2
.offset
, sym
->proc_v2
.proc_len
);
1428 loc
.kind
= loc_absolute
;
1429 loc
.offset
= sym
->proc_v2
.debug_start
;
1430 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1431 loc
.offset
= sym
->proc_v2
.debug_end
;
1432 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1436 flt
= codeview_get_linetab(linetab
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
);
1437 if (curr_func
) FIXME("nested function\n");
1438 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1440 codeview_get_address(msc_dbg
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
),
1441 sym
->proc_v3
.proc_len
,
1442 codeview_get_type(sym
->proc_v3
.proctype
, FALSE
));
1443 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1444 sym
->proc_v3
.offset
, sym
->proc_v3
.proc_len
);
1445 loc
.kind
= loc_absolute
;
1446 loc
.offset
= sym
->proc_v3
.debug_start
;
1447 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1448 loc
.offset
= sym
->proc_v3
.debug_end
;
1449 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1452 * Function parameters and stack variables.
1455 loc
.kind
= loc_regrel
;
1456 loc
.reg
= 0; /* FIXME */
1457 loc
.offset
= sym
->stack_v1
.offset
;
1458 symt_add_func_local(msc_dbg
->module
, curr_func
,
1459 sym
->stack_v1
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1461 codeview_get_type(sym
->stack_v1
.symtype
, FALSE
),
1462 terminate_string(&sym
->stack_v1
.p_name
));
1465 loc
.kind
= loc_regrel
;
1466 loc
.reg
= 0; /* FIXME */
1467 loc
.offset
= sym
->stack_v2
.offset
;
1468 symt_add_func_local(msc_dbg
->module
, curr_func
,
1469 sym
->stack_v2
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1471 codeview_get_type(sym
->stack_v2
.symtype
, FALSE
),
1472 terminate_string(&sym
->stack_v2
.p_name
));
1475 loc
.kind
= loc_regrel
;
1476 loc
.reg
= 0; /* FIXME */
1477 loc
.offset
= sym
->stack_v3
.offset
;
1478 symt_add_func_local(msc_dbg
->module
, curr_func
,
1479 sym
->stack_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1481 codeview_get_type(sym
->stack_v3
.symtype
, FALSE
),
1482 sym
->stack_v3
.name
);
1484 case S_BPREL_XXXX_V3
:
1485 loc
.kind
= loc_regrel
;
1486 loc
.reg
= 0; /* FIXME */
1487 loc
.offset
= sym
->stack_xxxx_v3
.offset
;
1488 WARN("Supposed stack variable %s (%d)\n", sym
->stack_xxxx_v3
.name
, sym
->stack_xxxx_v3
.unknown
);
1489 symt_add_func_local(msc_dbg
->module
, curr_func
,
1490 sym
->stack_xxxx_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1492 codeview_get_type(sym
->stack_xxxx_v3
.symtype
, FALSE
),
1493 sym
->stack_xxxx_v3
.name
);
1497 loc
.kind
= loc_register
;
1498 loc
.reg
= sym
->register_v1
.reg
;
1500 symt_add_func_local(msc_dbg
->module
, curr_func
,
1502 block
, codeview_get_type(sym
->register_v1
.type
, FALSE
),
1503 terminate_string(&sym
->register_v1
.p_name
));
1506 loc
.kind
= loc_register
;
1507 loc
.reg
= sym
->register_v2
.reg
;
1509 symt_add_func_local(msc_dbg
->module
, curr_func
,
1511 block
, codeview_get_type(sym
->register_v2
.type
, FALSE
),
1512 terminate_string(&sym
->register_v2
.p_name
));
1515 loc
.kind
= loc_register
;
1516 loc
.reg
= sym
->register_v3
.reg
;
1518 symt_add_func_local(msc_dbg
->module
, curr_func
,
1520 block
, codeview_get_type(sym
->register_v3
.type
, FALSE
),
1521 sym
->register_v3
.name
);
1525 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1526 codeview_get_address(msc_dbg
, sym
->block_v1
.segment
, sym
->block_v1
.offset
),
1527 sym
->block_v1
.length
);
1530 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1531 codeview_get_address(msc_dbg
, sym
->block_v3
.segment
, sym
->block_v3
.offset
),
1532 sym
->block_v3
.length
);
1538 block
= symt_close_func_block(msc_dbg
->module
, curr_func
, block
, 0);
1542 symt_normalize_function(msc_dbg
->module
, curr_func
);
1547 case S_COMPILAND_V1
:
1548 TRACE("S-Compiland-V1 %x %s\n",
1549 sym
->compiland_v1
.unknown
, terminate_string(&sym
->compiland_v1
.p_name
));
1552 case S_COMPILAND_V2
:
1553 TRACE("S-Compiland-V2 %s\n", terminate_string(&sym
->compiland_v2
.p_name
));
1554 if (TRACE_ON(dbghelp_msc
))
1556 const char* ptr1
= sym
->compiland_v2
.p_name
.name
+ sym
->compiland_v2
.p_name
.namelen
;
1560 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1561 TRACE("\t%s => %s\n", ptr1
, ptr2
);
1562 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1566 case S_COMPILAND_V3
:
1567 TRACE("S-Compiland-V3 %s\n", sym
->compiland_v3
.name
);
1568 if (TRACE_ON(dbghelp_msc
))
1570 const char* ptr1
= sym
->compiland_v3
.name
+ strlen(sym
->compiland_v3
.name
);
1574 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1575 TRACE("\t%s => %s\n", ptr1
, ptr2
);
1576 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1582 TRACE("S-ObjName %s\n", terminate_string(&sym
->objname_v1
.p_name
));
1583 compiland
= symt_new_compiland(msc_dbg
->module
, 0 /* FIXME */,
1584 source_new(msc_dbg
->module
, NULL
,
1585 terminate_string(&sym
->objname_v1
.p_name
)));
1591 loc
.kind
= loc_absolute
;
1592 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
) - curr_func
->address
;
1593 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
, &loc
,
1594 terminate_string(&sym
->label_v1
.p_name
));
1596 else symt_new_label(msc_dbg
->module
, compiland
,
1597 terminate_string(&sym
->label_v1
.p_name
),
1598 codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
));
1603 loc
.kind
= loc_absolute
;
1604 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
) - curr_func
->address
;
1605 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1606 &loc
, sym
->label_v3
.name
);
1608 else symt_new_label(msc_dbg
->module
, compiland
, sym
->label_v3
.name
,
1609 codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
));
1615 const struct p_string
* name
;
1620 vlen
= numeric_leaf(&v
.n1
.n2
.n3
.intVal
, &sym
->constant_v1
.cvalue
);
1621 name
= (const struct p_string
*)((const char*)&sym
->constant_v1
.cvalue
+ vlen
);
1622 se
= codeview_get_type(sym
->constant_v1
.type
, FALSE
);
1624 TRACE("S-Constant-V1 %u %s %x\n",
1625 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v1
.type
);
1626 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1633 const struct p_string
* name
;
1638 vlen
= numeric_leaf(&v
.n1
.n2
.n3
.intVal
, &sym
->constant_v2
.cvalue
);
1639 name
= (const struct p_string
*)((const char*)&sym
->constant_v2
.cvalue
+ vlen
);
1640 se
= codeview_get_type(sym
->constant_v2
.type
, FALSE
);
1642 TRACE("S-Constant-V2 %u %s %x\n",
1643 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v2
.type
);
1644 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1656 vlen
= numeric_leaf(&v
.n1
.n2
.n3
.intVal
, &sym
->constant_v3
.cvalue
);
1657 name
= (const char*)&sym
->constant_v3
.cvalue
+ vlen
;
1658 se
= codeview_get_type(sym
->constant_v3
.type
, FALSE
);
1660 TRACE("S-Constant-V3 %u %s %x\n",
1661 v
.n1
.n2
.n3
.intVal
, name
, sym
->constant_v3
.type
);
1662 /* FIXME: we should add this as a constant value */
1667 if (sym
->udt_v1
.type
)
1669 if ((symt
= codeview_get_type(sym
->udt_v1
.type
, FALSE
)))
1670 symt_new_typedef(msc_dbg
->module
, symt
,
1671 terminate_string(&sym
->udt_v1
.p_name
));
1673 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1674 terminate_string(&sym
->udt_v1
.p_name
), sym
->udt_v1
.type
);
1678 if (sym
->udt_v2
.type
)
1680 if ((symt
= codeview_get_type(sym
->udt_v2
.type
, FALSE
)))
1681 symt_new_typedef(msc_dbg
->module
, symt
,
1682 terminate_string(&sym
->udt_v2
.p_name
));
1684 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1685 terminate_string(&sym
->udt_v2
.p_name
), sym
->udt_v2
.type
);
1689 if (sym
->udt_v3
.type
)
1691 if ((symt
= codeview_get_type(sym
->udt_v3
.type
, FALSE
)))
1692 symt_new_typedef(msc_dbg
->module
, symt
, sym
->udt_v3
.name
);
1694 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1695 sym
->udt_v3
.name
, sym
->udt_v3
.type
);
1700 * These are special, in that they are always followed by an
1701 * additional length-prefixed string which is *not* included
1702 * into the symbol length count. We need to skip it.
1707 name
= (const char*)sym
+ length
;
1708 length
+= (*name
+ 1 + 3) & ~3;
1712 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1714 symt_new_public(msc_dbg
->module
, compiland
,
1716 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1717 1, FALSE
/* FIXME */, FALSE
);
1720 case S_PUB_FUNC1_V3
:
1721 case S_PUB_FUNC2_V3
: /* using a data_v3 isn't what we'd expect */
1723 /* FIXME: this is plain wrong (from a simple test) */
1724 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1726 symt_new_public(msc_dbg
->module
, compiland
,
1728 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1729 1, TRUE
/* FIXME */, TRUE
);
1734 case S_MSTOOL_V3
: /* just to silence a few warnings */
1738 TRACE("Start search: seg=0x%x at offset 0x%08x\n",
1739 sym
->ssearch_v1
.segment
, sym
->ssearch_v1
.offset
);
1743 TRACE("S-Align V1\n");
1747 FIXME("Unsupported symbol id %x\n", sym
->generic
.id
);
1748 dump(sym
, 2 + sym
->generic
.len
);
1753 if (curr_func
) symt_normalize_function(msc_dbg
->module
, curr_func
);
1755 HeapFree(GetProcessHeap(), 0, linetab
);
1759 /*========================================================================
1763 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
,
1769 if (!size
) return NULL
;
1771 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1772 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
1774 for (i
= 0; i
< num_blocks
; i
++)
1775 memcpy(buffer
+ i
* pdb
->block_size
,
1776 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
1781 static void* pdb_ds_read(const struct PDB_DS_HEADER
* pdb
, const DWORD
* block_list
,
1787 if (!size
) return NULL
;
1789 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1790 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
1792 for (i
= 0; i
< num_blocks
; i
++)
1793 memcpy(buffer
+ i
* pdb
->block_size
,
1794 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
1799 static void* pdb_read_jg_file(const struct PDB_JG_HEADER
* pdb
,
1800 const struct PDB_JG_TOC
* toc
, DWORD file_nr
)
1802 const WORD
* block_list
;
1805 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
1807 block_list
= (const WORD
*) &toc
->file
[toc
->num_files
];
1808 for (i
= 0; i
< file_nr
; i
++)
1809 block_list
+= (toc
->file
[i
].size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1811 return pdb_jg_read(pdb
, block_list
, toc
->file
[file_nr
].size
);
1814 static void* pdb_read_ds_file(const struct PDB_DS_HEADER
* pdb
,
1815 const struct PDB_DS_TOC
* toc
, DWORD file_nr
)
1817 const DWORD
* block_list
;
1820 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
1822 if (toc
->file_size
[file_nr
] == 0 || toc
->file_size
[file_nr
] == 0xFFFFFFFF)
1824 FIXME(">>> requesting NULL stream (%u)\n", file_nr
);
1827 block_list
= &toc
->file_size
[toc
->num_files
];
1828 for (i
= 0; i
< file_nr
; i
++)
1829 block_list
+= (toc
->file_size
[i
] + pdb
->block_size
- 1) / pdb
->block_size
;
1831 return pdb_ds_read(pdb
, block_list
, toc
->file_size
[file_nr
]);
1834 static void* pdb_read_file(const char* image
, const struct pdb_lookup
* pdb_lookup
,
1837 switch (pdb_lookup
->kind
)
1840 return pdb_read_jg_file((const struct PDB_JG_HEADER
*)image
,
1841 pdb_lookup
->u
.jg
.toc
, file_nr
);
1843 return pdb_read_ds_file((const struct PDB_DS_HEADER
*)image
,
1844 pdb_lookup
->u
.ds
.toc
, file_nr
);
1849 static unsigned pdb_get_file_size(const struct pdb_lookup
* pdb_lookup
, DWORD file_nr
)
1851 switch (pdb_lookup
->kind
)
1853 case PDB_JG
: return pdb_lookup
->u
.jg
.toc
->file
[file_nr
].size
;
1854 case PDB_DS
: return pdb_lookup
->u
.ds
.toc
->file_size
[file_nr
];
1859 static void pdb_free(void* buffer
)
1861 HeapFree(GetProcessHeap(), 0, buffer
);
1864 static void pdb_free_lookup(const struct pdb_lookup
* pdb_lookup
)
1866 switch (pdb_lookup
->kind
)
1869 pdb_free(pdb_lookup
->u
.jg
.toc
);
1872 pdb_free(pdb_lookup
->u
.ds
.toc
);
1877 static void pdb_convert_types_header(PDB_TYPES
* types
, const BYTE
* image
)
1879 memset(types
, 0, sizeof(PDB_TYPES
));
1882 if (*(const DWORD
*)image
< 19960000) /* FIXME: correct version? */
1884 /* Old version of the types record header */
1885 const PDB_TYPES_OLD
* old
= (const PDB_TYPES_OLD
*)image
;
1886 types
->version
= old
->version
;
1887 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
1888 types
->type_size
= old
->type_size
;
1889 types
->first_index
= old
->first_index
;
1890 types
->last_index
= old
->last_index
;
1891 types
->file
= old
->file
;
1895 /* New version of the types record header */
1896 *types
= *(const PDB_TYPES
*)image
;
1900 static void pdb_convert_symbols_header(PDB_SYMBOLS
* symbols
,
1901 int* header_size
, const BYTE
* image
)
1903 memset(symbols
, 0, sizeof(PDB_SYMBOLS
));
1906 if (*(const DWORD
*)image
!= 0xffffffff)
1908 /* Old version of the symbols record header */
1909 const PDB_SYMBOLS_OLD
* old
= (const PDB_SYMBOLS_OLD
*)image
;
1910 symbols
->version
= 0;
1911 symbols
->module_size
= old
->module_size
;
1912 symbols
->offset_size
= old
->offset_size
;
1913 symbols
->hash_size
= old
->hash_size
;
1914 symbols
->srcmodule_size
= old
->srcmodule_size
;
1915 symbols
->pdbimport_size
= 0;
1916 symbols
->hash1_file
= old
->hash1_file
;
1917 symbols
->hash2_file
= old
->hash2_file
;
1918 symbols
->gsym_file
= old
->gsym_file
;
1920 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
1924 /* New version of the symbols record header */
1925 *symbols
= *(const PDB_SYMBOLS
*)image
;
1926 *header_size
= sizeof(PDB_SYMBOLS
);
1930 static void pdb_convert_symbol_file(const PDB_SYMBOLS
* symbols
,
1931 PDB_SYMBOL_FILE_EX
* sfile
,
1932 unsigned* size
, const void* image
)
1935 if (symbols
->version
< 19970000)
1937 const PDB_SYMBOL_FILE
*sym_file
= (const PDB_SYMBOL_FILE
*)image
;
1938 memset(sfile
, 0, sizeof(*sfile
));
1939 sfile
->file
= sym_file
->file
;
1940 sfile
->range
.index
= sym_file
->range
.index
;
1941 sfile
->symbol_size
= sym_file
->symbol_size
;
1942 sfile
->lineno_size
= sym_file
->lineno_size
;
1943 *size
= sizeof(PDB_SYMBOL_FILE
) - 1;
1947 memcpy(sfile
, image
, sizeof(PDB_SYMBOL_FILE_EX
));
1948 *size
= sizeof(PDB_SYMBOL_FILE_EX
) - 1;
1952 static BOOL CALLBACK
pdb_match(const char* file
, void* user
)
1954 /* accept first file that exists */
1955 HANDLE h
= CreateFileA(file
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1956 TRACE("match with %s returns %p\n", file
, h
);
1957 if (INVALID_HANDLE_VALUE
!= h
) {
1964 static HANDLE
open_pdb_file(const struct process
* pcs
,
1965 const struct pdb_lookup
* lookup
)
1968 char dbg_file_path
[MAX_PATH
];
1971 switch (lookup
->kind
)
1974 ret
= SymFindFileInPath(pcs
->handle
, NULL
, lookup
->filename
,
1975 (PVOID
)(DWORD_PTR
)lookup
->u
.jg
.timestamp
,
1976 lookup
->age
, 0, SSRVOPT_DWORD
,
1977 dbg_file_path
, pdb_match
, NULL
);
1980 ret
= SymFindFileInPath(pcs
->handle
, NULL
, lookup
->filename
,
1981 (PVOID
)&lookup
->u
.ds
.guid
, lookup
->age
, 0,
1982 SSRVOPT_GUIDPTR
, dbg_file_path
, pdb_match
, NULL
);
1987 WARN("\tCouldn't find %s\n", lookup
->filename
);
1990 h
= CreateFileA(dbg_file_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
1991 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1992 TRACE("%s: %s returns %p\n", lookup
->filename
, dbg_file_path
, h
);
1993 return (h
== INVALID_HANDLE_VALUE
) ? NULL
: h
;
1996 static void pdb_process_types(const struct msc_debug_info
* msc_dbg
,
1997 const char* image
, const struct pdb_lookup
* pdb_lookup
)
1999 BYTE
* types_image
= NULL
;
2001 types_image
= pdb_read_file(image
, pdb_lookup
, 2);
2005 struct codeview_type_parse ctp
;
2010 pdb_convert_types_header(&types
, types_image
);
2012 /* Check for unknown versions */
2013 switch (types
.version
)
2015 case 19950410: /* VC 4.0 */
2017 case 19961031: /* VC 5.0 / 6.0 */
2021 ERR("-Unknown type info version %d\n", types
.version
);
2024 ctp
.module
= msc_dbg
->module
;
2025 /* reconstruct the types offset...
2026 * FIXME: maybe it's present in the newest PDB_TYPES structures
2028 total
= types
.last_index
- types
.first_index
+ 1;
2029 offset
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD
) * total
);
2030 ctp
.table
= ptr
= types_image
+ types
.type_offset
;
2032 while (ptr
< ctp
.table
+ types
.type_size
&& ctp
.num
< total
)
2034 offset
[ctp
.num
++] = ptr
- ctp
.table
;
2035 ptr
+= ((const union codeview_type
*)ptr
)->generic
.len
+ 2;
2037 ctp
.offset
= offset
;
2039 /* Read type table */
2040 codeview_parse_type_table(&ctp
);
2041 HeapFree(GetProcessHeap(), 0, offset
);
2042 pdb_free(types_image
);
2046 static const char PDB_JG_IDENT
[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
2047 static const char PDB_DS_IDENT
[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
2049 /******************************************************************
2052 * Tries to load a pdb file
2053 * if do_fill is TRUE, then it just fills pdb_lookup with the information of the
2055 * if do_fill is FALSE, then it just checks that the kind of PDB (stored in
2056 * pdb_lookup) matches what's really in the file
2058 static BOOL
pdb_init(struct pdb_lookup
* pdb_lookup
, const char* image
, BOOL do_fill
)
2062 /* check the file header, and if ok, load the TOC */
2063 TRACE("PDB(%s): %.40s\n", pdb_lookup
->filename
, debugstr_an(image
, 40));
2065 if (!memcmp(image
, PDB_JG_IDENT
, sizeof(PDB_JG_IDENT
)))
2067 const struct PDB_JG_HEADER
* pdb
= (const struct PDB_JG_HEADER
*)image
;
2068 struct PDB_JG_ROOT
* root
;
2070 pdb_lookup
->u
.jg
.toc
= pdb_jg_read(pdb
, pdb
->toc_block
, pdb
->toc
.size
);
2071 root
= pdb_read_jg_file(pdb
, pdb_lookup
->u
.jg
.toc
, 1);
2074 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2077 switch (root
->Version
)
2079 case 19950623: /* VC 4.0 */
2081 case 19960307: /* VC 5.0 */
2082 case 19970604: /* VC 6.0 */
2085 ERR("-Unknown root block version %d\n", root
->Version
);
2089 pdb_lookup
->kind
= PDB_JG
;
2090 pdb_lookup
->u
.jg
.timestamp
= root
->TimeDateStamp
;
2091 pdb_lookup
->age
= root
->Age
;
2093 else if (pdb_lookup
->kind
!= PDB_JG
||
2094 pdb_lookup
->u
.jg
.timestamp
!= root
->TimeDateStamp
||
2095 pdb_lookup
->age
!= root
->Age
)
2097 TRACE("found JG/%c for %s: age=%x timestamp=%x\n",
2098 do_fill
? 'f' : '-', pdb_lookup
->filename
, root
->Age
,
2099 root
->TimeDateStamp
);
2102 else if (!memcmp(image
, PDB_DS_IDENT
, sizeof(PDB_DS_IDENT
)))
2104 const struct PDB_DS_HEADER
* pdb
= (const struct PDB_DS_HEADER
*)image
;
2105 struct PDB_DS_ROOT
* root
;
2107 pdb_lookup
->u
.ds
.toc
=
2109 (const DWORD
*)((const char*)pdb
+ pdb
->toc_page
* pdb
->block_size
),
2111 root
= pdb_read_ds_file(pdb
, pdb_lookup
->u
.ds
.toc
, 1);
2114 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2117 switch (root
->Version
)
2122 ERR("-Unknown root block version %d\n", root
->Version
);
2126 pdb_lookup
->kind
= PDB_DS
;
2127 pdb_lookup
->u
.ds
.guid
= root
->guid
;
2128 pdb_lookup
->age
= root
->Age
;
2130 else if (pdb_lookup
->kind
!= PDB_DS
||
2131 memcmp(&pdb_lookup
->u
.ds
.guid
, &root
->guid
, sizeof(GUID
)) ||
2132 pdb_lookup
->age
!= root
->Age
)
2134 TRACE("found DS/%c for %s: age=%x guid=%s\n",
2135 do_fill
? 'f' : '-', pdb_lookup
->filename
, root
->Age
,
2136 debugstr_guid(&root
->guid
));
2140 if (0) /* some tool to dump the internal files from a PDB file */
2144 switch (pdb_lookup
->kind
)
2146 case PDB_JG
: num_files
= pdb_lookup
->u
.jg
.toc
->num_files
; break;
2147 case PDB_DS
: num_files
= pdb_lookup
->u
.ds
.toc
->num_files
; break;
2150 for (i
= 1; i
< num_files
; i
++)
2152 unsigned char* x
= pdb_read_file(image
, pdb_lookup
, i
);
2153 FIXME("********************** [%u]: size=%08x\n",
2154 i
, pdb_get_file_size(pdb_lookup
, i
));
2155 dump(x
, pdb_get_file_size(pdb_lookup
, i
));
2162 static BOOL
pdb_process_internal(const struct process
* pcs
,
2163 const struct msc_debug_info
* msc_dbg
,
2164 struct pdb_lookup
* pdb_lookup
,
2165 unsigned module_index
);
2167 static void pdb_process_symbol_imports(const struct process
* pcs
,
2168 const struct msc_debug_info
* msc_dbg
,
2169 const PDB_SYMBOLS
* symbols
,
2170 const void* symbols_image
,
2172 const struct pdb_lookup
* pdb_lookup
,
2173 unsigned module_index
)
2175 if (module_index
== -1 && symbols
&& symbols
->pdbimport_size
)
2177 const PDB_SYMBOL_IMPORT
*imp
;
2183 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2184 symbols
->module_size
+ symbols
->offset_size
+
2185 symbols
->hash_size
+ symbols
->srcmodule_size
);
2186 first
= (const char*)imp
;
2187 last
= (const char*)imp
+ symbols
->pdbimport_size
;
2188 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
2190 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
2191 if (i
>= CV_MAX_MODULES
) FIXME("Out of bounds !!!\n");
2192 if (!strcasecmp(pdb_lookup
->filename
, imp
->filename
))
2194 if (module_index
!= -1) FIXME("Twice the entry\n");
2195 else module_index
= i
;
2199 struct pdb_lookup imp_pdb_lookup
;
2201 /* FIXME: this is an import of a JG PDB file
2202 * how's a DS PDB handled ?
2204 imp_pdb_lookup
.filename
= imp
->filename
;
2205 imp_pdb_lookup
.kind
= PDB_JG
;
2206 imp_pdb_lookup
.u
.jg
.timestamp
= imp
->TimeDateStamp
;
2207 imp_pdb_lookup
.age
= imp
->Age
;
2208 TRACE("got for %s: age=%u ts=%x\n",
2209 imp
->filename
, imp
->Age
, imp
->TimeDateStamp
);
2210 pdb_process_internal(pcs
, msc_dbg
, &imp_pdb_lookup
, i
);
2213 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)first
+ ((ptr
- (const char*)first
+ strlen(ptr
) + 1 + 3) & ~3));
2216 cv_current_module
= &cv_zmodules
[(module_index
== -1) ? 0 : module_index
];
2217 if (cv_current_module
->allowed
) FIXME("Already allowed ??\n");
2218 cv_current_module
->allowed
= TRUE
;
2219 pdb_process_types(msc_dbg
, image
, pdb_lookup
);
2222 static BOOL
pdb_process_internal(const struct process
* pcs
,
2223 const struct msc_debug_info
* msc_dbg
,
2224 struct pdb_lookup
* pdb_lookup
,
2225 unsigned module_index
)
2228 HANDLE hFile
, hMap
= NULL
;
2230 BYTE
* symbols_image
= NULL
;
2232 TRACE("Processing PDB file %s\n", pdb_lookup
->filename
);
2234 /* Open and map() .PDB file */
2235 if ((hFile
= open_pdb_file(pcs
, pdb_lookup
)) == NULL
||
2236 ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
2237 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2239 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2242 pdb_init(pdb_lookup
, image
, FALSE
);
2244 symbols_image
= pdb_read_file(image
, pdb_lookup
, 3);
2247 PDB_SYMBOLS symbols
;
2250 int header_size
= 0;
2252 pdb_convert_symbols_header(&symbols
, &header_size
, symbols_image
);
2253 switch (symbols
.version
)
2255 case 0: /* VC 4.0 */
2256 case 19960307: /* VC 5.0 */
2257 case 19970606: /* VC 6.0 */
2261 ERR("-Unknown symbol info version %d %08x\n",
2262 symbols
.version
, symbols
.version
);
2265 pdb_process_symbol_imports(pcs
, msc_dbg
, &symbols
, symbols_image
, image
, pdb_lookup
, module_index
);
2267 /* Read global symbol table */
2268 modimage
= pdb_read_file(image
, pdb_lookup
, symbols
.gsym_file
);
2271 codeview_snarf(msc_dbg
, modimage
, 0,
2272 pdb_get_file_size(pdb_lookup
, symbols
.gsym_file
), NULL
);
2277 /* Read per-module symbol / linenumber tables */
2278 file
= symbols_image
+ header_size
;
2279 while (file
- symbols_image
< header_size
+ symbols
.module_size
)
2281 PDB_SYMBOL_FILE_EX sfile
;
2282 const char* file_name
;
2285 HeapValidate(GetProcessHeap(), 0, NULL
);
2286 pdb_convert_symbol_file(&symbols
, &sfile
, &size
, file
);
2288 modimage
= pdb_read_file(image
, pdb_lookup
, sfile
.file
);
2291 struct codeview_linetab
* linetab
= NULL
;
2293 if (sfile
.lineno_size
)
2294 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2295 modimage
+ sfile
.symbol_size
,
2297 pdb_lookup
->kind
== PDB_JG
);
2299 if (sfile
.symbol_size
)
2300 codeview_snarf(msc_dbg
, modimage
, sizeof(DWORD
),
2301 sfile
.symbol_size
, linetab
);
2305 file_name
= (const char*)file
+ size
;
2306 file_name
+= strlen(file_name
) + 1;
2307 file
= (BYTE
*)((DWORD
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3);
2311 pdb_process_symbol_imports(pcs
, msc_dbg
, NULL
, NULL
, image
, pdb_lookup
,
2317 pdb_free(symbols_image
);
2318 pdb_free_lookup(pdb_lookup
);
2320 if (image
) UnmapViewOfFile(image
);
2321 if (hMap
) CloseHandle(hMap
);
2322 if (hFile
) CloseHandle(hFile
);
2327 static BOOL
pdb_process_file(const struct process
* pcs
,
2328 const struct msc_debug_info
* msc_dbg
,
2329 struct pdb_lookup
* pdb_lookup
)
2333 memset(cv_zmodules
, 0, sizeof(cv_zmodules
));
2334 codeview_init_basic_types(msc_dbg
->module
);
2335 ret
= pdb_process_internal(pcs
, msc_dbg
, pdb_lookup
, -1);
2336 codeview_clear_type_table();
2339 msc_dbg
->module
->module
.SymType
= SymCv
;
2340 if (pdb_lookup
->kind
== PDB_JG
)
2341 msc_dbg
->module
->module
.PdbSig
= pdb_lookup
->u
.jg
.timestamp
;
2343 msc_dbg
->module
->module
.PdbSig70
= pdb_lookup
->u
.ds
.guid
;
2344 msc_dbg
->module
->module
.PdbAge
= pdb_lookup
->age
;
2345 MultiByteToWideChar(CP_ACP
, 0, pdb_lookup
->filename
, -1,
2346 msc_dbg
->module
->module
.LoadedPdbName
,
2347 sizeof(msc_dbg
->module
->module
.LoadedPdbName
) / sizeof(WCHAR
));
2348 /* FIXME: we could have a finer grain here */
2349 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
2350 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
2351 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
2352 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
2353 msc_dbg
->module
->module
.Publics
= TRUE
;
2358 BOOL
pdb_fetch_file_info(struct pdb_lookup
* pdb_lookup
)
2360 HANDLE hFile
, hMap
= NULL
;
2364 if ((hFile
= CreateFileA(pdb_lookup
->filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2365 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) == INVALID_HANDLE_VALUE
||
2366 ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
2367 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2369 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2374 pdb_init(pdb_lookup
, image
, TRUE
);
2375 pdb_free_lookup(pdb_lookup
);
2378 if (image
) UnmapViewOfFile(image
);
2379 if (hMap
) CloseHandle(hMap
);
2380 if (hFile
!= INVALID_HANDLE_VALUE
) CloseHandle(hFile
);
2385 /*========================================================================
2386 * Process CodeView debug information.
2389 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
2390 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
2391 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
2392 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
2393 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
2395 static BOOL
codeview_process_info(const struct process
* pcs
,
2396 const struct msc_debug_info
* msc_dbg
)
2398 const DWORD
* signature
= (const DWORD
*)msc_dbg
->root
;
2400 struct pdb_lookup pdb_lookup
;
2402 TRACE("Processing signature %.4s\n", (const char*)signature
);
2406 case CODEVIEW_NB09_SIG
:
2407 case CODEVIEW_NB11_SIG
:
2409 const OMFSignature
* cv
= (const OMFSignature
*)msc_dbg
->root
;
2410 const OMFDirHeader
* hdr
= (const OMFDirHeader
*)(msc_dbg
->root
+ cv
->filepos
);
2411 const OMFDirEntry
* ent
;
2412 const OMFDirEntry
* prev
;
2413 const OMFDirEntry
* next
;
2416 codeview_init_basic_types(msc_dbg
->module
);
2418 for (i
= 0; i
< hdr
->cDir
; i
++)
2420 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
+ i
* hdr
->cbDirEntry
);
2421 if (ent
->SubSection
== sstGlobalTypes
)
2423 const OMFGlobalTypes
* types
;
2424 struct codeview_type_parse ctp
;
2426 types
= (const OMFGlobalTypes
*)(msc_dbg
->root
+ ent
->lfo
);
2427 ctp
.module
= msc_dbg
->module
;
2428 ctp
.offset
= (const DWORD
*)(types
+ 1);
2429 ctp
.num
= types
->cTypes
;
2430 ctp
.table
= (const BYTE
*)(ctp
.offset
+ types
->cTypes
);
2432 cv_current_module
= &cv_zmodules
[0];
2433 if (cv_current_module
->allowed
) FIXME("Already allowed ??\n");
2434 cv_current_module
->allowed
= TRUE
;
2436 codeview_parse_type_table(&ctp
);
2441 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
);
2442 for (i
= 0; i
< hdr
->cDir
; i
++, ent
= next
)
2444 next
= (i
== hdr
->cDir
-1) ? NULL
:
2445 (const OMFDirEntry
*)((const BYTE
*)ent
+ hdr
->cbDirEntry
);
2446 prev
= (i
== 0) ? NULL
:
2447 (const OMFDirEntry
*)((const BYTE
*)ent
- hdr
->cbDirEntry
);
2449 if (ent
->SubSection
== sstAlignSym
)
2452 * Check the next and previous entry. If either is a
2453 * sstSrcModule, it contains the line number info for
2456 * FIXME: This is not a general solution!
2458 struct codeview_linetab
* linetab
= NULL
;
2460 if (next
&& next
->iMod
== ent
->iMod
&&
2461 next
->SubSection
== sstSrcModule
)
2462 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2463 msc_dbg
->root
+ next
->lfo
, next
->cb
,
2466 if (prev
&& prev
->iMod
== ent
->iMod
&&
2467 prev
->SubSection
== sstSrcModule
)
2468 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2469 msc_dbg
->root
+ prev
->lfo
, prev
->cb
,
2472 codeview_snarf(msc_dbg
, msc_dbg
->root
+ ent
->lfo
, sizeof(DWORD
),
2477 msc_dbg
->module
->module
.SymType
= SymCv
;
2478 /* FIXME: we could have a finer grain here */
2479 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
2480 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
2481 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
2482 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
2483 msc_dbg
->module
->module
.Publics
= TRUE
;
2484 codeview_clear_type_table();
2489 case CODEVIEW_NB10_SIG
:
2491 const CODEVIEW_PDB_DATA
* pdb
= (const CODEVIEW_PDB_DATA
*)msc_dbg
->root
;
2492 pdb_lookup
.filename
= pdb
->name
;
2493 pdb_lookup
.kind
= PDB_JG
;
2494 pdb_lookup
.u
.jg
.timestamp
= pdb
->timestamp
;
2495 pdb_lookup
.u
.jg
.toc
= NULL
;
2496 pdb_lookup
.age
= pdb
->unknown
;
2497 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
2500 case CODEVIEW_RSDS_SIG
:
2502 const OMFSignatureRSDS
* rsds
= (const OMFSignatureRSDS
*)msc_dbg
->root
;
2504 TRACE("Got RSDS type of PDB file: guid=%s unk=%08x name=%s\n",
2505 wine_dbgstr_guid(&rsds
->guid
), rsds
->unknown
, rsds
->name
);
2506 pdb_lookup
.filename
= rsds
->name
;
2507 pdb_lookup
.kind
= PDB_DS
;
2508 pdb_lookup
.u
.ds
.guid
= rsds
->guid
;
2509 pdb_lookup
.u
.ds
.toc
= NULL
;
2510 pdb_lookup
.age
= rsds
->unknown
;
2511 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
2515 ERR("Unknown CODEVIEW signature %08x in module %s\n",
2516 *signature
, debugstr_w(msc_dbg
->module
->module
.ModuleName
));
2521 msc_dbg
->module
->module
.CVSig
= *signature
;
2522 memcpy(msc_dbg
->module
->module
.CVData
, msc_dbg
->root
,
2523 sizeof(msc_dbg
->module
->module
.CVData
));
2528 /*========================================================================
2529 * Process debug directory.
2531 BOOL
pe_load_debug_directory(const struct process
* pcs
, struct module
* module
,
2532 const BYTE
* mapping
,
2533 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
2534 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
)
2538 struct msc_debug_info msc_dbg
;
2540 msc_dbg
.module
= module
;
2541 msc_dbg
.nsect
= nsect
;
2542 msc_dbg
.sectp
= sectp
;
2544 msc_dbg
.omapp
= NULL
;
2550 /* First, watch out for OMAP data */
2551 for (i
= 0; i
< nDbg
; i
++)
2553 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
)
2555 msc_dbg
.nomap
= dbg
[i
].SizeOfData
/ sizeof(OMAP_DATA
);
2556 msc_dbg
.omapp
= (const OMAP_DATA
*)(mapping
+ dbg
[i
].PointerToRawData
);
2561 /* Now, try to parse CodeView debug info */
2562 for (i
= 0; i
< nDbg
; i
++)
2564 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_CODEVIEW
)
2566 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
2567 if ((ret
= codeview_process_info(pcs
, &msc_dbg
))) goto done
;
2571 /* If not found, try to parse COFF debug info */
2572 for (i
= 0; i
< nDbg
; i
++)
2574 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_COFF
)
2576 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
2577 if ((ret
= coff_process_info(&msc_dbg
))) goto done
;
2581 /* FIXME: this should be supported... this is the debug information for
2582 * functions compiled without a frame pointer (FPO = frame pointer omission)
2583 * the associated data helps finding out the relevant information
2585 for (i
= 0; i
< nDbg
; i
++)
2586 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_FPO
)
2587 FIXME("This guy has FPO information\n");
2591 #define FRAME_TRAP 1
2594 typedef struct _FPO_DATA
2596 DWORD ulOffStart
; /* offset 1st byte of function code */
2597 DWORD cbProcSize
; /* # bytes in function */
2598 DWORD cdwLocals
; /* # bytes in locals/4 */
2599 WORD cdwParams
; /* # bytes in params/4 */
2601 WORD cbProlog
: 8; /* # bytes in prolog */
2602 WORD cbRegs
: 3; /* # regs saved */
2603 WORD fHasSEH
: 1; /* TRUE if SEH in func */
2604 WORD fUseBP
: 1; /* TRUE if EBP has been allocated */
2605 WORD reserved
: 1; /* reserved for future use */
2606 WORD cbFrame
: 2; /* frame type */
2613 ERR("Got a page fault while loading symbols\n");