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
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 void dump(const void* ptr
, unsigned len
)
73 const char* hexof
= "0123456789abcdef";
74 const BYTE
* x
= (const BYTE
*)ptr
;
76 for (i
= 0; i
< len
; i
+= 16)
78 sprintf(msg
, "%08x: ", i
);
79 memset(msg
+ 10, ' ', 3 * 16 + 1 + 16);
80 for (j
= 0; j
< min(16, len
- i
); j
++)
82 msg
[10 + 3 * j
+ 0] = hexof
[x
[i
+ j
] >> 4];
83 msg
[10 + 3 * j
+ 1] = hexof
[x
[i
+ j
] & 15];
84 msg
[10 + 3 * j
+ 2] = ' ';
85 msg
[10 + 3 * 16 + 1 + j
] = (x
[i
+ j
] >= 0x20 && x
[i
+ j
] < 0x7f) ?
88 msg
[10 + 3 * 16] = ' ';
89 msg
[10 + 3 * 16 + 1 + 16] = '\0';
94 /*========================================================================
95 * Process CodeView type information.
98 #define MAX_BUILTIN_TYPES 0x0480
99 #define FIRST_DEFINABLE_TYPE 0x1000
101 static struct symt
* cv_basic_types
[MAX_BUILTIN_TYPES
];
103 struct cv_defined_module
106 unsigned int num_defined_types
;
107 struct symt
** defined_types
;
109 /* FIXME: don't make it static */
110 #define CV_MAX_MODULES 32
111 static struct cv_defined_module cv_zmodules
[CV_MAX_MODULES
];
112 static struct cv_defined_module
*cv_current_module
;
114 static void codeview_init_basic_types(struct module
* module
)
117 * These are the common builtin types that are used by VC++.
119 cv_basic_types
[T_NOTYPE
] = NULL
;
120 cv_basic_types
[T_ABS
] = NULL
;
121 cv_basic_types
[T_VOID
] = &symt_new_basic(module
, btVoid
, "void", 0)->symt
;
122 cv_basic_types
[T_CHAR
] = &symt_new_basic(module
, btChar
, "char", 1)->symt
;
123 cv_basic_types
[T_SHORT
] = &symt_new_basic(module
, btInt
, "short int", 2)->symt
;
124 cv_basic_types
[T_LONG
] = &symt_new_basic(module
, btInt
, "long int", 4)->symt
;
125 cv_basic_types
[T_QUAD
] = &symt_new_basic(module
, btInt
, "long long int", 8)->symt
;
126 cv_basic_types
[T_UCHAR
] = &symt_new_basic(module
, btUInt
, "unsigned char", 1)->symt
;
127 cv_basic_types
[T_USHORT
] = &symt_new_basic(module
, btUInt
, "unsigned short", 2)->symt
;
128 cv_basic_types
[T_ULONG
] = &symt_new_basic(module
, btUInt
, "unsigned long", 4)->symt
;
129 cv_basic_types
[T_UQUAD
] = &symt_new_basic(module
, btUInt
, "unsigned long long", 8)->symt
;
130 cv_basic_types
[T_REAL32
] = &symt_new_basic(module
, btFloat
, "float", 4)->symt
;
131 cv_basic_types
[T_REAL64
] = &symt_new_basic(module
, btFloat
, "double", 8)->symt
;
132 cv_basic_types
[T_RCHAR
] = &symt_new_basic(module
, btInt
, "signed char", 1)->symt
;
133 cv_basic_types
[T_WCHAR
] = &symt_new_basic(module
, btWChar
, "wchar_t", 2)->symt
;
134 cv_basic_types
[T_INT4
] = &symt_new_basic(module
, btInt
, "INT4", 4)->symt
;
135 cv_basic_types
[T_UINT4
] = &symt_new_basic(module
, btUInt
, "UINT4", 4)->symt
;
137 cv_basic_types
[T_32PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
])->symt
;
138 cv_basic_types
[T_32PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
])->symt
;
139 cv_basic_types
[T_32PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
])->symt
;
140 cv_basic_types
[T_32PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
])->symt
;
141 cv_basic_types
[T_32PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
])->symt
;
142 cv_basic_types
[T_32PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
])->symt
;
143 cv_basic_types
[T_32PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
])->symt
;
144 cv_basic_types
[T_32PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
])->symt
;
145 cv_basic_types
[T_32PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
])->symt
;
146 cv_basic_types
[T_32PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
])->symt
;
147 cv_basic_types
[T_32PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
])->symt
;
148 cv_basic_types
[T_32PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
])->symt
;
149 cv_basic_types
[T_32PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
])->symt
;
150 cv_basic_types
[T_32PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
])->symt
;
151 cv_basic_types
[T_32PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
])->symt
;
154 static int numeric_leaf(int* value
, const unsigned short int* leaf
)
156 unsigned short int type
= *leaf
++;
159 if (type
< LF_NUMERIC
)
169 *value
= *(const char*)leaf
;
174 *value
= *(const short*)leaf
;
179 *value
= *(const unsigned short*)leaf
;
184 *value
= *(const int*)leaf
;
189 *value
= *(const unsigned int*)leaf
;
194 FIXME("Unsupported numeric leaf type %04x\n", type
);
196 *value
= 0; /* FIXME */
200 FIXME("Unsupported numeric leaf type %04x\n", type
);
202 *value
= 0; /* FIXME */
206 FIXME("Unsupported numeric leaf type %04x\n", type
);
208 *value
= 0; /* FIXME */
212 FIXME("Unsupported numeric leaf type %04x\n", type
);
214 *value
= 0; /* FIXME */
218 FIXME("Unsupported numeric leaf type %04x\n", type
);
220 *value
= 0; /* FIXME */
224 FIXME("Unsupported numeric leaf type %04x\n", type
);
226 *value
= 0; /* FIXME */
230 FIXME("Unsupported numeric leaf type %04x\n", type
);
232 *value
= 0; /* FIXME */
236 FIXME("Unsupported numeric leaf type %04x\n", type
);
238 *value
= 0; /* FIXME */
242 FIXME("Unsupported numeric leaf type %04x\n", type
);
244 *value
= 0; /* FIXME */
248 FIXME("Unsupported numeric leaf type %04x\n", type
);
250 *value
= 0; /* FIXME */
254 FIXME("Unsupported numeric leaf type %04x\n", type
);
256 *value
= 0; /* FIXME */
260 FIXME("Unknown numeric leaf type %04x\n", type
);
269 /* convert a pascal string (as stored in debug information) into
270 * a C string (null terminated).
272 static const char* terminate_string(const struct p_string
* p_name
)
274 static char symname
[256];
276 memcpy(symname
, p_name
->name
, p_name
->namelen
);
277 symname
[p_name
->namelen
] = '\0';
279 return (!*symname
|| strcmp(symname
, "__unnamed") == 0) ? NULL
: symname
;
282 static struct symt
* codeview_get_type(unsigned int typeno
, BOOL quiet
)
284 struct symt
* symt
= NULL
;
287 * Convert Codeview type numbers into something we can grok internally.
288 * Numbers < FIRST_DEFINABLE_TYPE are all fixed builtin types.
289 * Numbers from FIRST_DEFINABLE_TYPE and up are all user defined (structs, etc).
291 if (typeno
< FIRST_DEFINABLE_TYPE
)
293 if (typeno
< MAX_BUILTIN_TYPES
)
294 symt
= cv_basic_types
[typeno
];
298 unsigned mod_index
= typeno
>> 24;
299 unsigned mod_typeno
= typeno
& 0x00FFFFFF;
300 struct cv_defined_module
* mod
;
302 mod
= (mod_index
== 0) ? cv_current_module
: &cv_zmodules
[mod_index
];
304 if (mod_index
>= CV_MAX_MODULES
|| !mod
->allowed
)
305 FIXME("Module of index %d isn't loaded yet (%x)\n", mod_index
, typeno
);
308 if (mod_typeno
- FIRST_DEFINABLE_TYPE
< mod
->num_defined_types
)
309 symt
= mod
->defined_types
[mod_typeno
- FIRST_DEFINABLE_TYPE
];
312 if (!quiet
&& !symt
&& typeno
) FIXME("Returning NULL symt for type-id %x\n", typeno
);
316 struct codeview_type_parse
318 struct module
* module
;
324 static inline const void* codeview_jump_to_type(struct codeview_type_parse
* ctp
, DWORD idx
)
326 if (idx
< FIRST_DEFINABLE_TYPE
) return NULL
;
327 idx
-= FIRST_DEFINABLE_TYPE
;
328 return (idx
>= ctp
->num
) ? NULL
: (ctp
->table
+ ctp
->offset
[idx
]);
331 static int codeview_add_type(unsigned int typeno
, struct symt
* dt
)
333 if (typeno
< FIRST_DEFINABLE_TYPE
)
334 FIXME("What the heck\n");
335 if (!cv_current_module
)
337 FIXME("Adding %x to non allowed module\n", typeno
);
340 if ((typeno
>> 24) != 0)
341 FIXME("No module index while inserting type-id assumption is wrong %x\n",
343 while (typeno
- FIRST_DEFINABLE_TYPE
>= cv_current_module
->num_defined_types
)
345 cv_current_module
->num_defined_types
+= 0x100;
346 if (cv_current_module
->defined_types
)
347 cv_current_module
->defined_types
= (struct symt
**)
348 HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
349 cv_current_module
->defined_types
,
350 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
352 cv_current_module
->defined_types
= (struct symt
**)
353 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
354 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
356 if (cv_current_module
->defined_types
== NULL
) return FALSE
;
358 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
])
360 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] != dt
)
361 FIXME("Overwritting at %x\n", typeno
);
363 cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] = dt
;
367 static void codeview_clear_type_table(void)
371 for (i
= 0; i
< CV_MAX_MODULES
; i
++)
373 if (cv_zmodules
[i
].allowed
)
374 HeapFree(GetProcessHeap(), 0, cv_zmodules
[i
].defined_types
);
375 cv_zmodules
[i
].allowed
= FALSE
;
376 cv_zmodules
[i
].defined_types
= NULL
;
377 cv_zmodules
[i
].num_defined_types
= 0;
379 cv_current_module
= NULL
;
382 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
384 const union codeview_type
* type
, BOOL details
);
386 static void* codeview_cast_symt(struct symt
* symt
, enum SymTagEnum tag
)
388 if (symt
->tag
!= tag
)
390 FIXME("Bad tag. Expected %d, but got %d\n", tag
, symt
->tag
);
396 static struct symt
* codeview_fetch_type(struct codeview_type_parse
* ctp
,
400 const union codeview_type
* p
;
402 if (!typeno
) return NULL
;
403 if ((symt
= codeview_get_type(typeno
, TRUE
))) return symt
;
405 /* forward declaration */
406 if (!(p
= codeview_jump_to_type(ctp
, typeno
)))
408 FIXME("Cannot locate type %x\n", typeno
);
411 symt
= codeview_parse_one_type(ctp
, typeno
, p
, FALSE
);
412 if (!symt
) FIXME("Couldn't load forward type %x\n", typeno
);
416 static struct symt
* codeview_add_type_pointer(struct codeview_type_parse
* ctp
,
417 struct symt
* existing
,
418 unsigned int pointee_type
)
420 struct symt
* pointee
;
424 existing
= codeview_cast_symt(existing
, SymTagPointerType
);
427 pointee
= codeview_fetch_type(ctp
, pointee_type
);
428 return &symt_new_pointer(ctp
->module
, pointee
)->symt
;
431 static struct symt
* codeview_add_type_array(struct codeview_type_parse
* ctp
,
433 unsigned int elemtype
,
434 unsigned int indextype
,
435 unsigned int arr_len
)
437 struct symt
* elem
= codeview_fetch_type(ctp
, elemtype
);
438 struct symt
* index
= codeview_fetch_type(ctp
, indextype
);
444 symt_get_info(elem
, TI_GET_LENGTH
, &elem_size
);
445 if (elem_size
) arr_max
= arr_len
/ (DWORD
)elem_size
;
447 return &symt_new_array(ctp
->module
, 0, arr_max
, elem
, index
)->symt
;
450 static int codeview_add_type_enum_field_list(struct module
* module
,
451 struct symt_enum
* symt
,
452 const union codeview_reftype
* ref_type
)
454 const unsigned char* ptr
= ref_type
->fieldlist
.list
;
455 const unsigned char* last
= (const BYTE
*)ref_type
+ ref_type
->generic
.len
+ 2;
456 const union codeview_fieldtype
* type
;
460 if (*ptr
>= 0xf0) /* LF_PAD... */
466 type
= (const union codeview_fieldtype
*)ptr
;
468 switch (type
->generic
.id
)
470 case LF_ENUMERATE_V1
:
472 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v1
.value
);
473 const struct p_string
* p_name
= (const struct p_string
*)((const unsigned char*)&type
->enumerate_v1
.value
+ vlen
);
475 symt_add_enum_element(module
, symt
, terminate_string(p_name
), value
);
476 ptr
+= 2 + 2 + vlen
+ (1 + p_name
->namelen
);
479 case LF_ENUMERATE_V3
:
481 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v3
.value
);
482 const char* name
= (const char*)&type
->enumerate_v3
.value
+ vlen
;
484 symt_add_enum_element(module
, symt
, name
, value
);
485 ptr
+= 2 + 2 + vlen
+ (1 + strlen(name
));
490 FIXME("Unsupported type %04x in ENUM field list\n", type
->generic
.id
);
497 static void codeview_add_udt_element(struct codeview_type_parse
* ctp
,
498 struct symt_udt
* symt
, const char* name
,
499 int value
, unsigned type
)
501 struct symt
* subtype
;
502 const union codeview_reftype
*cv_type
;
504 if ((cv_type
= codeview_jump_to_type(ctp
, type
)))
506 switch (cv_type
->generic
.id
)
509 symt_add_udt_element(ctp
->module
, symt
, name
,
510 codeview_fetch_type(ctp
, cv_type
->bitfield_v1
.type
),
511 cv_type
->bitfield_v1
.bitoff
,
512 cv_type
->bitfield_v1
.nbits
);
515 symt_add_udt_element(ctp
->module
, symt
, name
,
516 codeview_fetch_type(ctp
, cv_type
->bitfield_v2
.type
),
517 cv_type
->bitfield_v2
.bitoff
,
518 cv_type
->bitfield_v2
.nbits
);
522 subtype
= codeview_fetch_type(ctp
, type
);
526 DWORD64 elem_size
= 0;
527 symt_get_info(subtype
, TI_GET_LENGTH
, &elem_size
);
528 symt_add_udt_element(ctp
->module
, symt
, name
, subtype
,
529 value
<< 3, (DWORD
)elem_size
<< 3);
533 static int codeview_add_type_struct_field_list(struct codeview_type_parse
* ctp
,
534 struct symt_udt
* symt
,
535 unsigned fieldlistno
)
537 const unsigned char* ptr
;
538 const unsigned char* last
;
540 const struct p_string
* p_name
;
542 const union codeview_reftype
*type_ref
;
543 const union codeview_fieldtype
* type
;
545 if (!fieldlistno
) return TRUE
;
546 type_ref
= codeview_jump_to_type(ctp
, fieldlistno
);
547 ptr
= type_ref
->fieldlist
.list
;
548 last
= (const BYTE
*)type_ref
+ type_ref
->generic
.len
+ 2;
552 if (*ptr
>= 0xf0) /* LF_PAD... */
558 type
= (const union codeview_fieldtype
*)ptr
;
560 switch (type
->generic
.id
)
563 leaf_len
= numeric_leaf(&value
, &type
->bclass_v1
.offset
);
565 /* FIXME: ignored for now */
567 ptr
+= 2 + 2 + 2 + leaf_len
;
571 leaf_len
= numeric_leaf(&value
, &type
->bclass_v2
.offset
);
573 /* FIXME: ignored for now */
575 ptr
+= 2 + 2 + 4 + leaf_len
;
581 const unsigned short int* p_vboff
;
583 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v1
.vbpoff
);
584 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v1
.vbpoff
+ leaf_len
);
585 vplen
= numeric_leaf(&vpoff
, p_vboff
);
587 /* FIXME: ignored for now */
589 ptr
+= 2 + 2 + 2 + 2 + leaf_len
+ vplen
;
596 const unsigned short int* p_vboff
;
598 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v2
.vbpoff
);
599 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v2
.vbpoff
+ leaf_len
);
600 vplen
= numeric_leaf(&vpoff
, p_vboff
);
602 /* FIXME: ignored for now */
604 ptr
+= 2 + 2 + 4 + 4 + leaf_len
+ vplen
;
609 leaf_len
= numeric_leaf(&value
, &type
->member_v1
.offset
);
610 p_name
= (const struct p_string
*)((const char*)&type
->member_v1
.offset
+ leaf_len
);
612 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
613 type
->member_v1
.type
);
615 ptr
+= 2 + 2 + 2 + leaf_len
+ (1 + p_name
->namelen
);
619 leaf_len
= numeric_leaf(&value
, &type
->member_v2
.offset
);
620 p_name
= (const struct p_string
*)((const unsigned char*)&type
->member_v2
.offset
+ leaf_len
);
622 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
623 type
->member_v2
.type
);
625 ptr
+= 2 + 2 + 4 + leaf_len
+ (1 + p_name
->namelen
);
629 leaf_len
= numeric_leaf(&value
, &type
->member_v3
.offset
);
630 c_name
= (const char*)&type
->member_v3
.offset
+ leaf_len
;
632 codeview_add_udt_element(ctp
, symt
, c_name
, value
, type
->member_v3
.type
);
634 ptr
+= 2 + 2 + 4 + leaf_len
+ (strlen(c_name
) + 1);
638 /* FIXME: ignored for now */
639 ptr
+= 2 + 2 + 2 + (1 + type
->stmember_v1
.p_name
.namelen
);
643 /* FIXME: ignored for now */
644 ptr
+= 2 + 4 + 2 + (1 + type
->stmember_v2
.p_name
.namelen
);
648 /* FIXME: ignored for now */
649 ptr
+= 2 + 2 + 2 + (1 + type
->method_v1
.p_name
.namelen
);
653 /* FIXME: ignored for now */
654 ptr
+= 2 + 2 + 4 + (1 + type
->method_v2
.p_name
.namelen
);
658 /* FIXME: ignored for now */
659 ptr
+= 2 + 2 + (1 + type
->nesttype_v1
.p_name
.namelen
);
663 /* FIXME: ignored for now */
664 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype_v2
.p_name
.namelen
);
668 /* FIXME: ignored for now */
673 /* FIXME: ignored for now */
677 case LF_ONEMETHOD_V1
:
678 /* FIXME: ignored for now */
679 switch ((type
->onemethod_v1
.attribute
>> 2) & 7)
681 case 4: case 6: /* (pure) introducing virtual method */
682 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt_v1
.p_name
.namelen
);
686 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod_v1
.p_name
.namelen
);
691 case LF_ONEMETHOD_V2
:
692 /* FIXME: ignored for now */
693 switch ((type
->onemethod_v2
.attribute
>> 2) & 7)
695 case 4: case 6: /* (pure) introducing virtual method */
696 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod_virt_v2
.p_name
.namelen
);
700 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod_v2
.p_name
.namelen
);
706 FIXME("Unsupported type %04x in STRUCT field list\n", type
->generic
.id
);
714 static struct symt
* codeview_add_type_enum(struct codeview_type_parse
* ctp
,
715 struct symt
* existing
,
717 unsigned fieldlistno
)
719 struct symt_enum
* symt
;
723 if (!(symt
= codeview_cast_symt(existing
, SymTagEnum
))) return NULL
;
724 /* should also check that all fields are the same */
728 symt
= symt_new_enum(ctp
->module
, name
);
731 const union codeview_reftype
* fieldlist
;
732 fieldlist
= codeview_jump_to_type(ctp
, fieldlistno
);
733 codeview_add_type_enum_field_list(ctp
->module
, symt
, fieldlist
);
739 static struct symt
* codeview_add_type_struct(struct codeview_type_parse
* ctp
,
740 struct symt
* existing
,
741 const char* name
, int structlen
,
744 struct symt_udt
* symt
;
748 if (!(symt
= codeview_cast_symt(existing
, SymTagUDT
))) return NULL
;
749 /* should also check that all fields are the same */
751 else symt
= symt_new_udt(ctp
->module
, name
, structlen
, kind
);
756 static struct symt
* codeview_new_func_signature(struct codeview_type_parse
* ctp
,
757 struct symt
* existing
,
760 enum CV_call_e call_conv
)
762 struct symt_function_signature
* sym
;
763 const union codeview_reftype
* reftype
;
767 sym
= codeview_cast_symt(existing
, SymTagFunctionType
);
768 if (!sym
) return NULL
;
772 sym
= symt_new_function_signature(ctp
->module
,
773 codeview_fetch_type(ctp
, ret_type
),
776 if (args_list
&& (reftype
= codeview_jump_to_type(ctp
, args_list
)))
779 switch (reftype
->generic
.id
)
782 for (i
= 0; i
< reftype
->arglist_v1
.num
; i
++)
783 symt_add_function_signature_parameter(ctp
->module
, sym
,
784 codeview_fetch_type(ctp
, reftype
->arglist_v1
.args
[i
]));
787 for (i
= 0; i
< reftype
->arglist_v2
.num
; i
++)
788 symt_add_function_signature_parameter(ctp
->module
, sym
,
789 codeview_fetch_type(ctp
, reftype
->arglist_v2
.args
[i
]));
792 FIXME("Unexpected leaf %x for signature's pmt\n", reftype
->generic
.id
);
799 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
801 const union codeview_type
* type
, BOOL details
)
805 const struct p_string
* p_name
;
807 struct symt
* existing
;
809 existing
= codeview_get_type(curr_type
, TRUE
);
811 switch (type
->generic
.id
)
814 /* FIXME: we don't handle modifiers,
815 * but readd previous type on the curr_type
817 WARN("Modifier on %x: %s%s%s%s\n",
818 type
->modifier_v1
.type
,
819 type
->modifier_v1
.attribute
& 0x01 ? "const " : "",
820 type
->modifier_v1
.attribute
& 0x02 ? "volatile " : "",
821 type
->modifier_v1
.attribute
& 0x04 ? "unaligned " : "",
822 type
->modifier_v1
.attribute
& ~0x07 ? "unknown " : "");
823 if (!(symt
= codeview_get_type(type
->modifier_v1
.type
, TRUE
)))
824 symt
= codeview_parse_one_type(ctp
, type
->modifier_v1
.type
,
825 codeview_jump_to_type(ctp
, type
->modifier_v1
.type
), details
);
828 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
829 WARN("Modifier on %x: %s%s%s%s\n",
830 type
->modifier_v2
.type
,
831 type
->modifier_v2
.attribute
& 0x01 ? "const " : "",
832 type
->modifier_v2
.attribute
& 0x02 ? "volatile " : "",
833 type
->modifier_v2
.attribute
& 0x04 ? "unaligned " : "",
834 type
->modifier_v2
.attribute
& ~0x07 ? "unknown " : "");
835 if (!(symt
= codeview_get_type(type
->modifier_v2
.type
, TRUE
)))
836 symt
= codeview_parse_one_type(ctp
, type
->modifier_v2
.type
,
837 codeview_jump_to_type(ctp
, type
->modifier_v2
.type
), details
);
841 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v1
.datatype
);
844 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v2
.datatype
);
848 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
851 leaf_len
= numeric_leaf(&value
, &type
->array_v1
.arrlen
);
852 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v1
.arrlen
+ leaf_len
);
853 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
854 type
->array_v1
.elemtype
,
855 type
->array_v1
.idxtype
, value
);
859 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
862 leaf_len
= numeric_leaf(&value
, &type
->array_v2
.arrlen
);
863 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v2
.arrlen
+ leaf_len
);
865 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
866 type
->array_v2
.elemtype
,
867 type
->array_v2
.idxtype
, value
);
871 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
874 leaf_len
= numeric_leaf(&value
, &type
->array_v3
.arrlen
);
875 c_name
= (const char*)&type
->array_v3
.arrlen
+ leaf_len
;
877 symt
= codeview_add_type_array(ctp
, c_name
,
878 type
->array_v3
.elemtype
,
879 type
->array_v3
.idxtype
, value
);
883 case LF_STRUCTURE_V1
:
885 leaf_len
= numeric_leaf(&value
, &type
->struct_v1
.structlen
);
886 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v1
.structlen
+ leaf_len
);
887 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
888 type
->generic
.id
== LF_CLASS_V1
? UdtClass
: UdtStruct
);
891 codeview_add_type(curr_type
, symt
);
892 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
893 type
->struct_v1
.fieldlist
);
897 case LF_STRUCTURE_V2
:
899 leaf_len
= numeric_leaf(&value
, &type
->struct_v2
.structlen
);
900 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v2
.structlen
+ leaf_len
);
901 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
902 type
->generic
.id
== LF_CLASS_V2
? UdtClass
: UdtStruct
);
905 codeview_add_type(curr_type
, symt
);
906 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
907 type
->struct_v2
.fieldlist
);
911 case LF_STRUCTURE_V3
:
913 leaf_len
= numeric_leaf(&value
, &type
->struct_v3
.structlen
);
914 c_name
= (const char*)&type
->struct_v3
.structlen
+ leaf_len
;
915 symt
= codeview_add_type_struct(ctp
, existing
, c_name
, value
,
916 type
->generic
.id
== LF_CLASS_V3
? UdtClass
: UdtStruct
);
919 codeview_add_type(curr_type
, symt
);
920 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
921 type
->struct_v3
.fieldlist
);
926 leaf_len
= numeric_leaf(&value
, &type
->union_v1
.un_len
);
927 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v1
.un_len
+ leaf_len
);
928 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
932 codeview_add_type(curr_type
, symt
);
933 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
934 type
->union_v1
.fieldlist
);
939 leaf_len
= numeric_leaf(&value
, &type
->union_v2
.un_len
);
940 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v2
.un_len
+ leaf_len
);
941 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
945 codeview_add_type(curr_type
, symt
);
946 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
947 type
->union_v2
.fieldlist
);
952 leaf_len
= numeric_leaf(&value
, &type
->union_v3
.un_len
);
953 c_name
= (const char*)&type
->union_v3
.un_len
+ leaf_len
;
954 symt
= codeview_add_type_struct(ctp
, existing
, c_name
,
958 codeview_add_type(curr_type
, symt
);
959 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
960 type
->union_v3
.fieldlist
);
965 symt
= codeview_add_type_enum(ctp
, existing
,
966 terminate_string(&type
->enumeration_v1
.p_name
),
967 type
->enumeration_v1
.fieldlist
);
971 symt
= codeview_add_type_enum(ctp
, existing
,
972 terminate_string(&type
->enumeration_v2
.p_name
),
973 type
->enumeration_v2
.fieldlist
);
977 symt
= codeview_add_type_enum(ctp
, existing
, type
->enumeration_v3
.name
,
978 type
->enumeration_v3
.fieldlist
);
981 case LF_PROCEDURE_V1
:
982 symt
= codeview_new_func_signature(ctp
, existing
,
983 type
->procedure_v1
.rvtype
,
984 details
? type
->procedure_v1
.arglist
: 0,
985 type
->procedure_v1
.call
);
987 case LF_PROCEDURE_V2
:
988 symt
= codeview_new_func_signature(ctp
, existing
,
989 type
->procedure_v2
.rvtype
,
990 details
? type
->procedure_v2
.arglist
: 0,
991 type
->procedure_v2
.call
);
993 case LF_MFUNCTION_V1
:
994 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
995 * nor class information, this would just do for now
997 symt
= codeview_new_func_signature(ctp
, existing
,
998 type
->mfunction_v1
.rvtype
,
999 details
? type
->mfunction_v1
.arglist
: 0,
1000 type
->mfunction_v1
.call
);
1002 case LF_MFUNCTION_V2
:
1003 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1004 * nor class information, this would just do for now
1006 symt
= codeview_new_func_signature(ctp
, existing
,
1007 type
->mfunction_v2
.rvtype
,
1008 details
? type
->mfunction_v2
.arglist
: 0,
1009 type
->mfunction_v2
.call
);
1013 /* this is an ugly hack... FIXME when we have C++ support */
1014 if (!(symt
= existing
))
1017 snprintf(buf
, sizeof(buf
), "__internal_vt_shape_%x\n", curr_type
);
1018 symt
= &symt_new_udt(ctp
->module
, buf
, 0, UdtStruct
)->symt
;
1022 FIXME("Unsupported type-id leaf %x\n", type
->generic
.id
);
1023 dump(type
, 2 + type
->generic
.len
);
1026 return codeview_add_type(curr_type
, symt
) ? symt
: NULL
;
1029 static int codeview_parse_type_table(struct codeview_type_parse
* ctp
)
1031 unsigned int curr_type
= FIRST_DEFINABLE_TYPE
;
1032 const union codeview_type
* type
;
1034 for (curr_type
= FIRST_DEFINABLE_TYPE
; curr_type
< FIRST_DEFINABLE_TYPE
+ ctp
->num
; curr_type
++)
1036 type
= codeview_jump_to_type(ctp
, curr_type
);
1038 /* type records we're interested in are the ones referenced by symbols
1039 * The known ranges are (X mark the ones we want):
1040 * X 0000-0016 for V1 types
1041 * 0200-020c for V1 types referenced by other types
1042 * 0400-040f for V1 types (complex lists & sets)
1043 * X 1000-100f for V2 types
1044 * 1200-120c for V2 types referenced by other types
1045 * 1400-140f for V1 types (complex lists & sets)
1046 * X 1500-150d for V3 types
1047 * 8000-8010 for numeric leafes
1049 if (type
->generic
.id
& 0x8600) continue;
1050 codeview_parse_one_type(ctp
, curr_type
, type
, TRUE
);
1056 /*========================================================================
1057 * Process CodeView line number information.
1060 static struct codeview_linetab
* codeview_snarf_linetab(struct module
* module
,
1061 const BYTE
* linetab
, int size
,
1065 char filename
[PATH_MAX
];
1066 const unsigned int* filetab
;
1067 const struct p_string
* p_fn
;
1070 struct codeview_linetab
* lt_hdr
;
1071 const unsigned int* lt_ptr
;
1075 union any_size pnt2
;
1076 const struct startend
* start
;
1081 * Now get the important bits.
1087 filetab
= (const unsigned int*) pnt
.c
;
1090 * Now count up the number of segments in the file.
1093 for (i
= 0; i
< nfile
; i
++)
1095 pnt2
.uc
= linetab
+ filetab
[i
];
1100 * Next allocate the header we will be returning.
1101 * There is one header for each segment, so that we can reach in
1102 * and pull bits as required.
1104 lt_hdr
= (struct codeview_linetab
*)
1105 HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (nseg
+ 1) * sizeof(*lt_hdr
));
1112 * Now fill the header we will be returning, one for each segment.
1113 * Note that this will basically just contain pointers into the existing
1114 * line table, and we do not actually copy any additional information
1115 * or allocate any additional memory.
1119 for (i
= 0; i
< nfile
; i
++)
1122 * Get the pointer into the segment information.
1124 pnt2
.uc
= linetab
+ filetab
[i
];
1125 file_segcount
= *pnt2
.s
;
1128 lt_ptr
= (const unsigned int*) pnt2
.c
;
1129 start
= (const struct startend
*)(lt_ptr
+ file_segcount
);
1132 * Now snarf the filename for all of the segments for this file.
1136 p_fn
= (const struct p_string
*)(start
+ file_segcount
);
1137 memset(filename
, 0, sizeof(filename
));
1138 memcpy(filename
, p_fn
->name
, p_fn
->namelen
);
1139 source
= source_new(module
, NULL
, filename
);
1142 source
= source_new(module
, NULL
, (const char*)(start
+ file_segcount
));
1144 for (k
= 0; k
< file_segcount
; k
++, this_seg
++)
1146 pnt2
.uc
= linetab
+ lt_ptr
[k
];
1147 lt_hdr
[this_seg
].start
= start
[k
].start
;
1148 lt_hdr
[this_seg
].end
= start
[k
].end
;
1149 lt_hdr
[this_seg
].source
= source
;
1150 lt_hdr
[this_seg
].segno
= *pnt2
.s
++;
1151 lt_hdr
[this_seg
].nline
= *pnt2
.s
++;
1152 lt_hdr
[this_seg
].offtab
= pnt2
.ui
;
1153 lt_hdr
[this_seg
].linetab
= (const unsigned short*)(pnt2
.ui
+ lt_hdr
[this_seg
].nline
);
1163 /*========================================================================
1164 * Process CodeView symbol information.
1167 static unsigned int codeview_map_offset(const struct msc_debug_info
* msc_dbg
,
1168 unsigned int offset
)
1170 int nomap
= msc_dbg
->nomap
;
1171 const OMAP_DATA
* omapp
= msc_dbg
->omapp
;
1174 if (!nomap
|| !omapp
) return offset
;
1176 /* FIXME: use binary search */
1177 for (i
= 0; i
< nomap
- 1; i
++)
1178 if (omapp
[i
].from
<= offset
&& omapp
[i
+1].from
> offset
)
1179 return !omapp
[i
].to
? 0 : omapp
[i
].to
+ (offset
- omapp
[i
].from
);
1184 static const struct codeview_linetab
*
1185 codeview_get_linetab(const struct codeview_linetab
* linetab
,
1186 unsigned seg
, unsigned offset
)
1189 * Check whether we have line number information
1193 for (; linetab
->linetab
; linetab
++)
1194 if (linetab
->segno
== seg
&&
1195 linetab
->start
<= offset
&& linetab
->end
> offset
)
1197 if (!linetab
->linetab
) linetab
= NULL
;
1202 static unsigned codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1203 unsigned seg
, unsigned offset
)
1205 int nsect
= msc_dbg
->nsect
;
1206 const IMAGE_SECTION_HEADER
* sectp
= msc_dbg
->sectp
;
1208 if (!seg
|| seg
> nsect
) return 0;
1209 return msc_dbg
->module
->module
.BaseOfImage
+
1210 codeview_map_offset(msc_dbg
, sectp
[seg
-1].VirtualAddress
+ offset
);
1213 static void codeview_add_func_linenum(struct module
* module
,
1214 struct symt_function
* func
,
1215 const struct codeview_linetab
* linetab
,
1216 unsigned offset
, unsigned size
)
1220 if (!linetab
) return;
1221 for (i
= 0; i
< linetab
->nline
; i
++)
1223 if (linetab
->offtab
[i
] >= offset
&& linetab
->offtab
[i
] < offset
+ size
)
1225 symt_add_func_line(module
, func
, linetab
->source
,
1226 linetab
->linetab
[i
], linetab
->offtab
[i
] - offset
);
1231 static int codeview_snarf(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1232 int offset
, int size
,
1233 struct codeview_linetab
* linetab
)
1235 struct symt_function
* curr_func
= NULL
;
1237 const struct codeview_linetab
* flt
;
1238 struct symt_block
* block
= NULL
;
1241 struct symt_compiland
* compiland
= NULL
;
1244 * Loop over the different types of records and whenever we
1245 * find something we are interested in, record it and move on.
1247 for (i
= offset
; i
< size
; i
+= length
)
1249 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1250 length
= sym
->generic
.len
+ 2;
1251 if (i
+ length
> size
) break;
1252 if (length
& 3) FIXME("unpadded len %u\n", length
);
1254 switch (sym
->generic
.id
)
1257 * Global and local data symbols. We don't associate these
1258 * with any given source file.
1262 symt_new_global_variable(msc_dbg
->module
, compiland
,
1263 terminate_string(&sym
->data_v1
.p_name
), sym
->generic
.id
== S_LDATA_V1
,
1264 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
),
1266 codeview_get_type(sym
->data_v1
.symtype
, FALSE
));
1270 name
= terminate_string(&sym
->data_v2
.p_name
);
1272 symt_new_global_variable(msc_dbg
->module
, compiland
,
1273 name
, sym
->generic
.id
== S_LDATA_V2
,
1274 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
),
1276 codeview_get_type(sym
->data_v2
.symtype
, FALSE
));
1280 if (*sym
->data_v3
.name
)
1281 symt_new_global_variable(msc_dbg
->module
, compiland
,
1283 sym
->generic
.id
== S_LDATA_V3
,
1284 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1286 codeview_get_type(sym
->data_v3
.symtype
, FALSE
));
1289 case S_PUB_V1
: /* FIXME is this really a 'data_v1' structure ?? */
1290 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1292 symt_new_public(msc_dbg
->module
, compiland
,
1293 terminate_string(&sym
->data_v1
.p_name
),
1294 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
),
1295 1, TRUE
/* FIXME */, TRUE
/* FIXME */);
1298 case S_PUB_V2
: /* FIXME is this really a 'data_v2' structure ?? */
1299 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1301 symt_new_public(msc_dbg
->module
, compiland
,
1302 terminate_string(&sym
->data_v2
.p_name
),
1303 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
),
1304 1, TRUE
/* FIXME */, TRUE
/* FIXME */);
1309 * Sort of like a global function, but it just points
1310 * to a thunk, which is a stupid name for what amounts to
1311 * a PLT slot in the normal jargon that everyone else uses.
1314 symt_new_thunk(msc_dbg
->module
, compiland
,
1315 terminate_string(&sym
->thunk_v1
.p_name
), sym
->thunk_v1
.thtype
,
1316 codeview_get_address(msc_dbg
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
),
1317 sym
->thunk_v1
.thunk_len
);
1320 symt_new_thunk(msc_dbg
->module
, compiland
,
1321 sym
->thunk_v3
.name
, sym
->thunk_v3
.thtype
,
1322 codeview_get_address(msc_dbg
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
),
1323 sym
->thunk_v3
.thunk_len
);
1327 * Global and static functions.
1331 flt
= codeview_get_linetab(linetab
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
);
1332 if (curr_func
) FIXME("nested function\n");
1333 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1334 terminate_string(&sym
->proc_v1
.p_name
),
1335 codeview_get_address(msc_dbg
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
),
1336 sym
->proc_v1
.proc_len
,
1337 codeview_get_type(sym
->proc_v1
.proctype
, FALSE
));
1338 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1339 sym
->proc_v1
.offset
, sym
->proc_v1
.proc_len
);
1340 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, sym
->proc_v1
.debug_start
, NULL
);
1341 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, sym
->proc_v1
.debug_end
, NULL
);
1345 flt
= codeview_get_linetab(linetab
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
);
1346 if (curr_func
) FIXME("nested function\n");
1347 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1348 terminate_string(&sym
->proc_v2
.p_name
),
1349 codeview_get_address(msc_dbg
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
),
1350 sym
->proc_v2
.proc_len
,
1351 codeview_get_type(sym
->proc_v2
.proctype
, FALSE
));
1352 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1353 sym
->proc_v2
.offset
, sym
->proc_v2
.proc_len
);
1354 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, sym
->proc_v2
.debug_start
, NULL
);
1355 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, sym
->proc_v2
.debug_end
, NULL
);
1359 flt
= codeview_get_linetab(linetab
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
);
1360 if (curr_func
) FIXME("nested function\n");
1361 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1363 codeview_get_address(msc_dbg
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
),
1364 sym
->proc_v3
.proc_len
,
1365 codeview_get_type(sym
->proc_v3
.proctype
, FALSE
));
1366 codeview_add_func_linenum(msc_dbg
->module
, curr_func
, flt
,
1367 sym
->proc_v3
.offset
, sym
->proc_v3
.proc_len
);
1368 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, sym
->proc_v3
.debug_start
, NULL
);
1369 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, sym
->proc_v3
.debug_end
, NULL
);
1372 * Function parameters and stack variables.
1375 symt_add_func_local(msc_dbg
->module
, curr_func
,
1376 sym
->stack_v1
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1377 0, sym
->stack_v1
.offset
, block
,
1378 codeview_get_type(sym
->stack_v1
.symtype
, FALSE
),
1379 terminate_string(&sym
->stack_v1
.p_name
));
1382 symt_add_func_local(msc_dbg
->module
, curr_func
,
1383 sym
->stack_v2
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1384 0, sym
->stack_v2
.offset
, block
,
1385 codeview_get_type(sym
->stack_v2
.symtype
, FALSE
),
1386 terminate_string(&sym
->stack_v2
.p_name
));
1389 symt_add_func_local(msc_dbg
->module
, curr_func
,
1390 sym
->stack_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1391 0, sym
->stack_v3
.offset
, block
,
1392 codeview_get_type(sym
->stack_v3
.symtype
, FALSE
),
1393 sym
->stack_v3
.name
);
1397 symt_add_func_local(msc_dbg
->module
, curr_func
,
1398 DataIsLocal
, sym
->register_v1
.reg
, 0,
1399 block
, codeview_get_type(sym
->register_v1
.type
, FALSE
),
1400 terminate_string(&sym
->register_v1
.p_name
));
1403 symt_add_func_local(msc_dbg
->module
, curr_func
,
1404 DataIsLocal
, sym
->register_v2
.reg
, 0,
1405 block
, codeview_get_type(sym
->register_v2
.type
, FALSE
),
1406 terminate_string(&sym
->register_v2
.p_name
));
1410 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1411 codeview_get_address(msc_dbg
, sym
->block_v1
.segment
, sym
->block_v1
.offset
),
1412 sym
->block_v1
.length
);
1415 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1416 codeview_get_address(msc_dbg
, sym
->block_v3
.segment
, sym
->block_v3
.offset
),
1417 sym
->block_v3
.length
);
1423 block
= symt_close_func_block(msc_dbg
->module
, curr_func
, block
, 0);
1427 symt_normalize_function(msc_dbg
->module
, curr_func
);
1433 TRACE("S-Compile-V1 %x %s\n",
1434 sym
->compile_v1
.unknown
, terminate_string(&sym
->compile_v1
.p_name
));
1438 TRACE("S-Compile-V2 %s\n", terminate_string(&sym
->compile_v2
.p_name
));
1439 if (TRACE_ON(dbghelp_msc
))
1441 const char* ptr1
= sym
->compile_v2
.p_name
.name
+ sym
->compile_v2
.p_name
.namelen
;
1445 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1446 TRACE("\t%s => %s\n", ptr1
, ptr2
);
1447 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1452 TRACE("S-Compile-V3 %s\n", sym
->compile_v3
.name
);
1453 if (TRACE_ON(dbghelp_msc
))
1455 const char* ptr1
= sym
->compile_v3
.name
+ strlen(sym
->compile_v3
.name
);
1459 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1460 TRACE("\t%s => %s\n", ptr1
, ptr2
);
1461 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1467 TRACE("S-ObjName %s\n", terminate_string(&sym
->objname_v1
.p_name
));
1468 compiland
= symt_new_compiland(msc_dbg
->module
,
1469 source_new(msc_dbg
->module
, NULL
,
1470 terminate_string(&sym
->objname_v1
.p_name
)));
1476 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1477 codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
) - curr_func
->address
,
1478 terminate_string(&sym
->label_v1
.p_name
));
1481 FIXME("No current function for label %s\n",
1482 terminate_string(&sym
->label_v1
.p_name
));
1487 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1488 codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
) - curr_func
->address
,
1489 sym
->label_v3
.name
);
1492 FIXME("No current function for label %s\n", sym
->label_v3
.name
);
1498 const struct p_string
* name
;
1502 vlen
= numeric_leaf(&val
, &sym
->constant_v1
.cvalue
);
1503 name
= (const struct p_string
*)((const char*)&sym
->constant_v1
.cvalue
+ vlen
);
1504 se
= codeview_get_type(sym
->constant_v1
.type
, FALSE
);
1506 else if (se
->tag
== SymTagEnum
) x
= ((struct symt_enum
*)se
)->name
;
1509 TRACE("S-Constant-V1 %u %s %x (%s)\n",
1510 val
, terminate_string(name
), sym
->constant_v1
.type
, x
);
1511 /* FIXME: we should add this as a constant value */
1517 const struct p_string
* name
;
1521 vlen
= numeric_leaf(&val
, &sym
->constant_v2
.cvalue
);
1522 name
= (const struct p_string
*)((const char*)&sym
->constant_v2
.cvalue
+ vlen
);
1523 se
= codeview_get_type(sym
->constant_v2
.type
, FALSE
);
1525 else if (se
->tag
== SymTagEnum
) x
= ((struct symt_enum
*)se
)->name
;
1528 TRACE("S-Constant-V2 %u %s %x (%s)\n",
1529 val
, terminate_string(name
), sym
->constant_v2
.type
, x
);
1530 /* FIXME: we should add this as a constant value */
1540 vlen
= numeric_leaf(&val
, &sym
->constant_v3
.cvalue
);
1541 name
= (const char*)&sym
->constant_v3
.cvalue
+ vlen
;
1542 se
= codeview_get_type(sym
->constant_v3
.type
, FALSE
);
1544 else if (se
->tag
== SymTagEnum
) x
= ((struct symt_enum
*)se
)->name
;
1547 TRACE("S-Constant-V3 %u %s %x (%s)\n",
1548 val
, name
, sym
->constant_v3
.type
, x
);
1549 /* FIXME: we should add this as a constant value */
1554 if (sym
->udt_v1
.type
)
1556 if ((symt
= codeview_get_type(sym
->udt_v1
.type
, FALSE
)))
1557 symt_new_typedef(msc_dbg
->module
, symt
,
1558 terminate_string(&sym
->udt_v1
.p_name
));
1560 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1561 terminate_string(&sym
->udt_v1
.p_name
), sym
->udt_v1
.type
);
1565 if (sym
->udt_v2
.type
)
1567 if ((symt
= codeview_get_type(sym
->udt_v2
.type
, FALSE
)))
1568 symt_new_typedef(msc_dbg
->module
, symt
,
1569 terminate_string(&sym
->udt_v2
.p_name
));
1571 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1572 terminate_string(&sym
->udt_v2
.p_name
), sym
->udt_v2
.type
);
1576 if (sym
->udt_v3
.type
)
1578 if ((symt
= codeview_get_type(sym
->udt_v3
.type
, FALSE
)))
1579 symt_new_typedef(msc_dbg
->module
, symt
, sym
->udt_v3
.name
);
1581 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1582 sym
->udt_v3
.name
, sym
->udt_v3
.type
);
1587 * These are special, in that they are always followed by an
1588 * additional length-prefixed string which is *not* included
1589 * into the symbol length count. We need to skip it.
1594 name
= (const char*)sym
+ length
;
1595 length
+= (*name
+ 1 + 3) & ~3;
1599 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1601 symt_new_public(msc_dbg
->module
, compiland
,
1603 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1604 1, FALSE
/* FIXME */, FALSE
);
1607 case S_PUB_FUNC1_V3
:
1608 case S_PUB_FUNC2_V3
: /* using a data_v3 isn't what we'd expect */
1609 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1611 symt_new_public(msc_dbg
->module
, compiland
,
1613 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
),
1614 1, TRUE
/* FIXME */, TRUE
);
1618 case S_MSTOOL_V3
: /* just to silence a few warnings */
1622 TRACE("Start search: seg=0x%x at offset 0x%08x\n",
1623 sym
->ssearch_v1
.segment
, sym
->ssearch_v1
.offset
);
1627 FIXME("Unsupported symbol id %x\n", sym
->generic
.id
);
1628 dump(sym
, 2 + sym
->generic
.len
);
1633 if (curr_func
) symt_normalize_function(msc_dbg
->module
, curr_func
);
1635 HeapFree(GetProcessHeap(), 0, linetab
);
1639 /*========================================================================
1643 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
,
1649 if (!size
) return NULL
;
1651 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1652 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
1654 for (i
= 0; i
< num_blocks
; i
++)
1655 memcpy(buffer
+ i
* pdb
->block_size
,
1656 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
1661 static void* pdb_ds_read(const struct PDB_DS_HEADER
* pdb
, const DWORD
* block_list
,
1667 if (!size
) return NULL
;
1669 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1670 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
1672 for (i
= 0; i
< num_blocks
; i
++)
1673 memcpy(buffer
+ i
* pdb
->block_size
,
1674 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
1679 static void* pdb_read_jg_file(const struct PDB_JG_HEADER
* pdb
,
1680 const struct PDB_JG_TOC
* toc
, DWORD file_nr
)
1682 const WORD
* block_list
;
1685 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
1687 block_list
= (const WORD
*) &toc
->file
[toc
->num_files
];
1688 for (i
= 0; i
< file_nr
; i
++)
1689 block_list
+= (toc
->file
[i
].size
+ pdb
->block_size
- 1) / pdb
->block_size
;
1691 return pdb_jg_read(pdb
, block_list
, toc
->file
[file_nr
].size
);
1694 static void* pdb_read_ds_file(const struct PDB_DS_HEADER
* pdb
,
1695 const struct PDB_DS_TOC
* toc
, DWORD file_nr
)
1697 const DWORD
* block_list
;
1700 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
1702 if (toc
->file_size
[file_nr
] == 0 || toc
->file_size
[file_nr
] == 0xFFFFFFFF)
1704 FIXME(">>> requesting NULL stream (%lu)\n", file_nr
);
1707 block_list
= &toc
->file_size
[toc
->num_files
];
1708 for (i
= 0; i
< file_nr
; i
++)
1709 block_list
+= (toc
->file_size
[i
] + pdb
->block_size
- 1) / pdb
->block_size
;
1711 return pdb_ds_read(pdb
, block_list
, toc
->file_size
[file_nr
]);
1714 static void* pdb_read_file(const char* image
, const struct pdb_lookup
* pdb_lookup
,
1717 switch (pdb_lookup
->kind
)
1720 return pdb_read_jg_file((const struct PDB_JG_HEADER
*)image
,
1721 pdb_lookup
->u
.jg
.toc
, file_nr
);
1723 return pdb_read_ds_file((const struct PDB_DS_HEADER
*)image
,
1724 pdb_lookup
->u
.ds
.toc
, file_nr
);
1729 static unsigned pdb_get_file_size(const struct pdb_lookup
* pdb_lookup
, DWORD file_nr
)
1731 switch (pdb_lookup
->kind
)
1733 case PDB_JG
: return pdb_lookup
->u
.jg
.toc
->file
[file_nr
].size
;
1734 case PDB_DS
: return pdb_lookup
->u
.ds
.toc
->file_size
[file_nr
];
1739 static void pdb_free(void* buffer
)
1741 HeapFree(GetProcessHeap(), 0, buffer
);
1744 static void pdb_free_lookup(const struct pdb_lookup
* pdb_lookup
)
1746 switch (pdb_lookup
->kind
)
1749 if (pdb_lookup
->u
.jg
.toc
) pdb_free(pdb_lookup
->u
.jg
.toc
);
1752 if (pdb_lookup
->u
.ds
.toc
) pdb_free(pdb_lookup
->u
.ds
.toc
);
1757 static void pdb_convert_types_header(PDB_TYPES
* types
, const BYTE
* image
)
1759 memset(types
, 0, sizeof(PDB_TYPES
));
1762 if (*(const DWORD
*)image
< 19960000) /* FIXME: correct version? */
1764 /* Old version of the types record header */
1765 const PDB_TYPES_OLD
* old
= (const PDB_TYPES_OLD
*)image
;
1766 types
->version
= old
->version
;
1767 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
1768 types
->type_size
= old
->type_size
;
1769 types
->first_index
= old
->first_index
;
1770 types
->last_index
= old
->last_index
;
1771 types
->file
= old
->file
;
1775 /* New version of the types record header */
1776 *types
= *(const PDB_TYPES
*)image
;
1780 static void pdb_convert_symbols_header(PDB_SYMBOLS
* symbols
,
1781 int* header_size
, const BYTE
* image
)
1783 memset(symbols
, 0, sizeof(PDB_SYMBOLS
));
1786 if (*(const DWORD
*)image
!= 0xffffffff)
1788 /* Old version of the symbols record header */
1789 const PDB_SYMBOLS_OLD
* old
= (const PDB_SYMBOLS_OLD
*)image
;
1790 symbols
->version
= 0;
1791 symbols
->module_size
= old
->module_size
;
1792 symbols
->offset_size
= old
->offset_size
;
1793 symbols
->hash_size
= old
->hash_size
;
1794 symbols
->srcmodule_size
= old
->srcmodule_size
;
1795 symbols
->pdbimport_size
= 0;
1796 symbols
->hash1_file
= old
->hash1_file
;
1797 symbols
->hash2_file
= old
->hash2_file
;
1798 symbols
->gsym_file
= old
->gsym_file
;
1800 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
1804 /* New version of the symbols record header */
1805 *symbols
= *(const PDB_SYMBOLS
*)image
;
1806 *header_size
= sizeof(PDB_SYMBOLS
);
1810 static void pdb_convert_symbol_file(const PDB_SYMBOLS
* symbols
,
1811 PDB_SYMBOL_FILE_EX
* sfile
,
1812 unsigned* size
, const void* image
)
1815 if (symbols
->version
< 19970000)
1817 const PDB_SYMBOL_FILE
*sym_file
= (const PDB_SYMBOL_FILE
*)image
;
1818 memset(sfile
, 0, sizeof(*sfile
));
1819 sfile
->file
= sym_file
->file
;
1820 sfile
->range
.index
= sym_file
->range
.index
;
1821 sfile
->symbol_size
= sym_file
->symbol_size
;
1822 sfile
->lineno_size
= sym_file
->lineno_size
;
1823 *size
= sizeof(PDB_SYMBOL_FILE
) - 1;
1827 memcpy(sfile
, image
, sizeof(PDB_SYMBOL_FILE_EX
));
1828 *size
= sizeof(PDB_SYMBOL_FILE_EX
) - 1;
1832 static BOOL CALLBACK
pdb_match(char* file
, void* user
)
1834 /* accept first file that exists */
1835 HANDLE h
= CreateFileA(file
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1836 TRACE("match with %s returns %p\n", file
, h
);
1837 if (INVALID_HANDLE_VALUE
!= h
) {
1844 static HANDLE
open_pdb_file(const struct process
* pcs
,
1845 const struct pdb_lookup
* lookup
)
1848 char dbg_file_path
[MAX_PATH
];
1851 switch (lookup
->kind
)
1854 ret
= SymFindFileInPath(pcs
->handle
, NULL
, lookup
->filename
,
1855 (PVOID
)(DWORD_PTR
)lookup
->u
.jg
.timestamp
,
1856 lookup
->age
, 0, SSRVOPT_DWORD
,
1857 dbg_file_path
, pdb_match
, NULL
);
1860 ret
= SymFindFileInPath(pcs
->handle
, NULL
, lookup
->filename
,
1861 (PVOID
)&lookup
->u
.ds
.guid
, lookup
->age
, 0,
1862 SSRVOPT_GUIDPTR
, dbg_file_path
, pdb_match
, NULL
);
1867 WARN("\tCouldn't find %s\n", lookup
->filename
);
1870 h
= CreateFileA(dbg_file_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
1871 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1872 TRACE("%s: %s returns %p\n", lookup
->filename
, dbg_file_path
, h
);
1873 return (h
== INVALID_HANDLE_VALUE
) ? NULL
: h
;
1876 static void pdb_process_types(const struct msc_debug_info
* msc_dbg
,
1877 const char* image
, struct pdb_lookup
* pdb_lookup
)
1879 BYTE
* types_image
= NULL
;
1881 types_image
= pdb_read_file(image
, pdb_lookup
, 2);
1885 struct codeview_type_parse ctp
;
1890 pdb_convert_types_header(&types
, types_image
);
1892 /* Check for unknown versions */
1893 switch (types
.version
)
1895 case 19950410: /* VC 4.0 */
1897 case 19961031: /* VC 5.0 / 6.0 */
1901 ERR("-Unknown type info version %ld\n", types
.version
);
1904 ctp
.module
= msc_dbg
->module
;
1905 /* reconstruct the types offset...
1906 * FIXME: maybe it's present in the newest PDB_TYPES structures
1908 total
= types
.last_index
- types
.first_index
+ 1;
1909 offset
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD
) * total
);
1910 ctp
.table
= ptr
= types_image
+ types
.type_offset
;
1912 while (ptr
< ctp
.table
+ types
.type_size
&& ctp
.num
< total
)
1914 offset
[ctp
.num
++] = ptr
- ctp
.table
;
1915 ptr
+= ((const union codeview_type
*)ptr
)->generic
.len
+ 2;
1917 ctp
.offset
= offset
;
1919 /* Read type table */
1920 codeview_parse_type_table(&ctp
);
1921 HeapFree(GetProcessHeap(), 0, offset
);
1922 pdb_free(types_image
);
1926 static const char PDB_JG_IDENT
[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
1927 static const char PDB_DS_IDENT
[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
1929 /******************************************************************
1932 * Tries to load a pdb file
1933 * if do_fill is TRUE, then it just fills pdb_lookup with the information of the
1935 * if do_fill is FALSE, then it just checks that the kind of PDB (stored in
1936 * pdb_lookup) matches what's really in the file
1938 static BOOL
pdb_init(struct pdb_lookup
* pdb_lookup
, const char* image
, BOOL do_fill
)
1942 /* check the file header, and if ok, load the TOC */
1943 TRACE("PDB(%s): %.40s\n", pdb_lookup
->filename
, debugstr_an(image
, 40));
1945 if (!memcmp(image
, PDB_JG_IDENT
, sizeof(PDB_JG_IDENT
)))
1947 const struct PDB_JG_HEADER
* pdb
= (const struct PDB_JG_HEADER
*)image
;
1948 struct PDB_JG_ROOT
* root
;
1950 pdb_lookup
->u
.jg
.toc
= pdb_jg_read(pdb
, pdb
->toc_block
, pdb
->toc
.size
);
1951 root
= pdb_read_jg_file(pdb
, pdb_lookup
->u
.jg
.toc
, 1);
1954 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
1957 switch (root
->Version
)
1959 case 19950623: /* VC 4.0 */
1961 case 19960307: /* VC 5.0 */
1962 case 19970604: /* VC 6.0 */
1965 ERR("-Unknown root block version %ld\n", root
->Version
);
1969 pdb_lookup
->kind
= PDB_JG
;
1970 pdb_lookup
->u
.jg
.timestamp
= root
->TimeDateStamp
;
1971 pdb_lookup
->age
= root
->Age
;
1973 else if (pdb_lookup
->kind
!= PDB_JG
||
1974 pdb_lookup
->u
.jg
.timestamp
!= root
->TimeDateStamp
||
1975 pdb_lookup
->age
!= root
->Age
)
1977 TRACE("found JG/%c for %s: age=%lx timestamp=%lx\n",
1978 do_fill
? 'f' : '-', pdb_lookup
->filename
, root
->Age
,
1979 root
->TimeDateStamp
);
1982 else if (!memcmp(image
, PDB_DS_IDENT
, sizeof(PDB_DS_IDENT
)))
1984 const struct PDB_DS_HEADER
* pdb
= (const struct PDB_DS_HEADER
*)image
;
1985 struct PDB_DS_ROOT
* root
;
1987 pdb_lookup
->u
.ds
.toc
=
1989 (const DWORD
*)((const char*)pdb
+ pdb
->toc_page
* pdb
->block_size
),
1991 root
= pdb_read_ds_file(pdb
, pdb_lookup
->u
.ds
.toc
, 1);
1994 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
1997 switch (root
->Version
)
2002 ERR("-Unknown root block version %ld\n", root
->Version
);
2006 pdb_lookup
->kind
= PDB_DS
;
2007 pdb_lookup
->u
.ds
.guid
= root
->guid
;
2008 pdb_lookup
->age
= root
->Age
;
2010 else if (pdb_lookup
->kind
!= PDB_DS
||
2011 memcmp(&pdb_lookup
->u
.ds
.guid
, &root
->guid
, sizeof(GUID
)) ||
2012 pdb_lookup
->age
!= root
->Age
)
2014 TRACE("found DS/%c for %s: age=%lx guid=%s\n",
2015 do_fill
? 'f' : '-', pdb_lookup
->filename
, root
->Age
,
2016 debugstr_guid(&root
->guid
));
2020 if (0) /* some tool to dump the internal files from a PDB file */
2024 switch (pdb_lookup
->kind
)
2026 case PDB_JG
: num_files
= pdb_lookup
->u
.jg
.toc
->num_files
; break;
2027 case PDB_DS
: num_files
= pdb_lookup
->u
.ds
.toc
->num_files
; break;
2030 for (i
= 1; i
< num_files
; i
++)
2032 unsigned char* x
= pdb_read_file(image
, pdb_lookup
, i
);
2033 FIXME("********************** [%u]: size=%08x\n",
2034 i
, pdb_get_file_size(pdb_lookup
, i
));
2035 dump(x
, pdb_get_file_size(pdb_lookup
, i
));
2042 static BOOL
pdb_process_internal(const struct process
* pcs
,
2043 const struct msc_debug_info
* msc_dbg
,
2044 struct pdb_lookup
* pdb_lookup
,
2045 unsigned module_index
);
2047 static void pdb_process_symbol_imports(const struct process
* pcs
,
2048 const struct msc_debug_info
* msc_dbg
,
2049 PDB_SYMBOLS
* symbols
,
2050 const void* symbols_image
,
2051 char* image
, struct pdb_lookup
* pdb_lookup
,
2052 unsigned module_index
)
2054 if (module_index
== -1 && symbols
&& symbols
->pdbimport_size
)
2056 const PDB_SYMBOL_IMPORT
*imp
;
2062 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2063 symbols
->module_size
+ symbols
->offset_size
+
2064 symbols
->hash_size
+ symbols
->srcmodule_size
);
2065 first
= (const char*)imp
;
2066 last
= (const char*)imp
+ symbols
->pdbimport_size
;
2067 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
2069 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
2070 if (i
>= CV_MAX_MODULES
) FIXME("Out of bounds !!!\n");
2071 if (!strcasecmp(pdb_lookup
->filename
, imp
->filename
))
2073 if (module_index
!= -1) FIXME("Twice the entry\n");
2074 else module_index
= i
;
2078 struct pdb_lookup imp_pdb_lookup
;
2080 /* FIXME: this is an import of a JG PDB file
2081 * how's a DS PDB handled ?
2083 imp_pdb_lookup
.filename
= imp
->filename
;
2084 imp_pdb_lookup
.kind
= PDB_JG
;
2085 imp_pdb_lookup
.u
.jg
.timestamp
= imp
->TimeDateStamp
;
2086 imp_pdb_lookup
.age
= imp
->Age
;
2087 TRACE("got for %s: age=%lu ts=%lx\n",
2088 imp
->filename
, imp
->Age
, imp
->TimeDateStamp
);
2089 pdb_process_internal(pcs
, msc_dbg
, &imp_pdb_lookup
, i
);
2092 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)first
+ ((ptr
- (const char*)first
+ strlen(ptr
) + 1 + 3) & ~3));
2095 cv_current_module
= &cv_zmodules
[(module_index
== -1) ? 0 : module_index
];
2096 if (cv_current_module
->allowed
) FIXME("Already allowed ??\n");
2097 cv_current_module
->allowed
= TRUE
;
2098 pdb_process_types(msc_dbg
, image
, pdb_lookup
);
2101 static BOOL
pdb_process_internal(const struct process
* pcs
,
2102 const struct msc_debug_info
* msc_dbg
,
2103 struct pdb_lookup
* pdb_lookup
,
2104 unsigned module_index
)
2107 HANDLE hFile
, hMap
= NULL
;
2109 BYTE
* symbols_image
= NULL
;
2111 TRACE("Processing PDB file %s\n", pdb_lookup
->filename
);
2113 /* Open and map() .PDB file */
2114 if ((hFile
= open_pdb_file(pcs
, pdb_lookup
)) == NULL
||
2115 ((hMap
= CreateFileMappingA(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
2116 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2118 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2121 pdb_init(pdb_lookup
, image
, FALSE
);
2123 symbols_image
= pdb_read_file(image
, pdb_lookup
, 3);
2126 PDB_SYMBOLS symbols
;
2129 int header_size
= 0;
2131 pdb_convert_symbols_header(&symbols
, &header_size
, symbols_image
);
2132 switch (symbols
.version
)
2134 case 0: /* VC 4.0 */
2135 case 19960307: /* VC 5.0 */
2136 case 19970606: /* VC 6.0 */
2140 ERR("-Unknown symbol info version %ld %08lx\n",
2141 symbols
.version
, symbols
.version
);
2144 pdb_process_symbol_imports(pcs
, msc_dbg
, &symbols
, symbols_image
, image
, pdb_lookup
, module_index
);
2146 /* Read global symbol table */
2147 modimage
= pdb_read_file(image
, pdb_lookup
, symbols
.gsym_file
);
2150 codeview_snarf(msc_dbg
, modimage
, 0,
2151 pdb_get_file_size(pdb_lookup
, symbols
.gsym_file
), NULL
);
2156 /* Read per-module symbol / linenumber tables */
2157 file
= symbols_image
+ header_size
;
2158 while (file
- symbols_image
< header_size
+ symbols
.module_size
)
2160 PDB_SYMBOL_FILE_EX sfile
;
2161 const char* file_name
;
2164 HeapValidate(GetProcessHeap(), 0, NULL
);
2165 pdb_convert_symbol_file(&symbols
, &sfile
, &size
, file
);
2167 modimage
= pdb_read_file(image
, pdb_lookup
, sfile
.file
);
2170 struct codeview_linetab
* linetab
= NULL
;
2172 if (sfile
.lineno_size
)
2173 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2174 modimage
+ sfile
.symbol_size
,
2176 pdb_lookup
->kind
== PDB_JG
);
2178 if (sfile
.symbol_size
)
2179 codeview_snarf(msc_dbg
, modimage
, sizeof(DWORD
),
2180 sfile
.symbol_size
, linetab
);
2184 file_name
= (const char*)file
+ size
;
2185 file_name
+= strlen(file_name
) + 1;
2186 file
= (BYTE
*)((DWORD
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3);
2190 pdb_process_symbol_imports(pcs
, msc_dbg
, NULL
, NULL
, image
, pdb_lookup
,
2196 if (symbols_image
) pdb_free(symbols_image
);
2197 pdb_free_lookup(pdb_lookup
);
2199 if (image
) UnmapViewOfFile(image
);
2200 if (hMap
) CloseHandle(hMap
);
2201 if (hFile
) CloseHandle(hFile
);
2206 static BOOL
pdb_process_file(const struct process
* pcs
,
2207 const struct msc_debug_info
* msc_dbg
,
2208 struct pdb_lookup
* pdb_lookup
)
2212 memset(cv_zmodules
, 0, sizeof(cv_zmodules
));
2213 codeview_init_basic_types(msc_dbg
->module
);
2214 ret
= pdb_process_internal(pcs
, msc_dbg
, pdb_lookup
, -1);
2215 codeview_clear_type_table();
2218 msc_dbg
->module
->module
.SymType
= SymCv
;
2219 if (pdb_lookup
->kind
== PDB_JG
)
2220 msc_dbg
->module
->module
.PdbSig
= pdb_lookup
->u
.jg
.timestamp
;
2222 msc_dbg
->module
->module
.PdbSig70
= pdb_lookup
->u
.ds
.guid
;
2223 msc_dbg
->module
->module
.PdbAge
= pdb_lookup
->age
;
2224 strcpy(msc_dbg
->module
->module
.LoadedPdbName
, pdb_lookup
->filename
);
2225 /* FIXME: we could have a finer grain here */
2226 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
2227 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
2228 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
2229 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
2230 msc_dbg
->module
->module
.Publics
= TRUE
;
2235 BOOL
pdb_fetch_file_info(struct pdb_lookup
* pdb_lookup
)
2237 HANDLE hFile
, hMap
= NULL
;
2241 if ((hFile
= CreateFileA(pdb_lookup
->filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2242 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) == INVALID_HANDLE_VALUE
||
2243 ((hMap
= CreateFileMappingA(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
2244 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2246 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2251 pdb_init(pdb_lookup
, image
, TRUE
);
2252 pdb_free_lookup(pdb_lookup
);
2255 if (image
) UnmapViewOfFile(image
);
2256 if (hMap
) CloseHandle(hMap
);
2257 if (hFile
) CloseHandle(hFile
);
2262 /*========================================================================
2263 * Process CodeView debug information.
2266 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
2267 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
2268 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
2269 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
2270 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
2272 static BOOL
codeview_process_info(const struct process
* pcs
,
2273 const struct msc_debug_info
* msc_dbg
)
2275 const CODEVIEW_HEADER_NBxx
* cv
= (const CODEVIEW_HEADER_NBxx
*)msc_dbg
->root
;
2277 struct pdb_lookup pdb_lookup
;
2279 TRACE("Processing signature %.4s\n", (const char*)&cv
->dwSignature
);
2281 switch (cv
->dwSignature
)
2283 case CODEVIEW_NB09_SIG
:
2284 case CODEVIEW_NB11_SIG
:
2286 const CV_DIRECTORY_HEADER
* hdr
= (const CV_DIRECTORY_HEADER
*)(msc_dbg
->root
+ cv
->lfoDirectory
);
2287 const CV_DIRECTORY_ENTRY
* ent
;
2288 const CV_DIRECTORY_ENTRY
* prev
;
2289 const CV_DIRECTORY_ENTRY
* next
;
2292 codeview_init_basic_types(msc_dbg
->module
);
2294 for (i
= 0; i
< hdr
->cDir
; i
++)
2296 ent
= (const CV_DIRECTORY_ENTRY
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
+ i
* hdr
->cbDirEntry
);
2297 if (ent
->subsection
== sstGlobalTypes
)
2299 const CV_ENTRY_GLOBAL_TYPES
* types
;
2300 struct codeview_type_parse ctp
;
2302 types
= (const CV_ENTRY_GLOBAL_TYPES
*)(msc_dbg
->root
+ ent
->lfo
);
2303 ctp
.module
= msc_dbg
->module
;
2304 ctp
.offset
= (const DWORD
*)(types
+ 1);
2305 ctp
.num
= types
->cTypes
;
2306 ctp
.table
= (const BYTE
*)(ctp
.offset
+ types
->cTypes
);
2308 cv_current_module
= &cv_zmodules
[0];
2309 if (cv_current_module
->allowed
) FIXME("Already allowed ??\n");
2310 cv_current_module
->allowed
= TRUE
;
2312 codeview_parse_type_table(&ctp
);
2317 ent
= (const CV_DIRECTORY_ENTRY
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
);
2318 for (i
= 0; i
< hdr
->cDir
; i
++, ent
= next
)
2320 next
= (i
== hdr
->cDir
-1) ? NULL
:
2321 (const CV_DIRECTORY_ENTRY
*)((const BYTE
*)ent
+ hdr
->cbDirEntry
);
2322 prev
= (i
== 0) ? NULL
:
2323 (const CV_DIRECTORY_ENTRY
*)((const BYTE
*)ent
- hdr
->cbDirEntry
);
2325 if (ent
->subsection
== sstAlignSym
)
2328 * Check the next and previous entry. If either is a
2329 * sstSrcModule, it contains the line number info for
2332 * FIXME: This is not a general solution!
2334 struct codeview_linetab
* linetab
= NULL
;
2336 if (next
&& next
->iMod
== ent
->iMod
&&
2337 next
->subsection
== sstSrcModule
)
2338 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2339 msc_dbg
->root
+ next
->lfo
, next
->cb
,
2342 if (prev
&& prev
->iMod
== ent
->iMod
&&
2343 prev
->subsection
== sstSrcModule
)
2344 linetab
= codeview_snarf_linetab(msc_dbg
->module
,
2345 msc_dbg
->root
+ prev
->lfo
, prev
->cb
,
2348 codeview_snarf(msc_dbg
, msc_dbg
->root
+ ent
->lfo
, sizeof(DWORD
),
2353 msc_dbg
->module
->module
.SymType
= SymCv
;
2354 /* FIXME: we could have a finer grain here */
2355 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
2356 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
2357 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
2358 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
2359 msc_dbg
->module
->module
.Publics
= TRUE
;
2360 codeview_clear_type_table();
2365 case CODEVIEW_NB10_SIG
:
2367 const CODEVIEW_PDB_DATA
* pdb
= (const CODEVIEW_PDB_DATA
*)(cv
+ 1);
2368 pdb_lookup
.filename
= pdb
->name
;
2369 pdb_lookup
.kind
= PDB_JG
;
2370 pdb_lookup
.u
.jg
.timestamp
= pdb
->timestamp
;
2371 pdb_lookup
.u
.jg
.toc
= NULL
;
2372 pdb_lookup
.age
= pdb
->unknown
;
2373 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
2376 case CODEVIEW_RSDS_SIG
:
2378 const CODEVIEW_HEADER_RSDS
* rsds
= (const CODEVIEW_HEADER_RSDS
*)msc_dbg
->root
;
2380 TRACE("Got RSDS type of PDB file: guid=%s unk=%08lx name=%s\n",
2381 wine_dbgstr_guid(&rsds
->guid
), rsds
->unknown
, rsds
->name
);
2382 pdb_lookup
.filename
= rsds
->name
;
2383 pdb_lookup
.kind
= PDB_DS
;
2384 pdb_lookup
.u
.ds
.guid
= rsds
->guid
;
2385 pdb_lookup
.u
.ds
.toc
= NULL
;
2386 pdb_lookup
.age
= rsds
->unknown
;
2387 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
2391 ERR("Unknown CODEVIEW signature %08lX in module %s\n",
2392 cv
->dwSignature
, msc_dbg
->module
->module
.ModuleName
);
2397 msc_dbg
->module
->module
.CVSig
= cv
->dwSignature
;
2398 memcpy(msc_dbg
->module
->module
.CVData
, cv
,
2399 sizeof(msc_dbg
->module
->module
.CVData
));
2404 /*========================================================================
2405 * Process debug directory.
2407 BOOL
pe_load_debug_directory(const struct process
* pcs
, struct module
* module
,
2408 const BYTE
* mapping
,
2409 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
2410 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
)
2414 struct msc_debug_info msc_dbg
;
2416 msc_dbg
.module
= module
;
2417 msc_dbg
.nsect
= nsect
;
2418 msc_dbg
.sectp
= sectp
;
2420 msc_dbg
.omapp
= NULL
;
2426 /* First, watch out for OMAP data */
2427 for (i
= 0; i
< nDbg
; i
++)
2429 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
)
2431 msc_dbg
.nomap
= dbg
[i
].SizeOfData
/ sizeof(OMAP_DATA
);
2432 msc_dbg
.omapp
= (const OMAP_DATA
*)(mapping
+ dbg
[i
].PointerToRawData
);
2437 /* Now, try to parse CodeView debug info */
2438 for (i
= 0; i
< nDbg
; i
++)
2440 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_CODEVIEW
)
2442 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
2443 if ((ret
= codeview_process_info(pcs
, &msc_dbg
))) goto done
;
2447 /* If not found, try to parse COFF debug info */
2448 for (i
= 0; i
< nDbg
; i
++)
2450 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_COFF
)
2452 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
2453 if ((ret
= coff_process_info(&msc_dbg
))) goto done
;
2457 /* FIXME: this should be supported... this is the debug information for
2458 * functions compiled without a frame pointer (FPO = frame pointer omission)
2459 * the associated data helps finding out the relevant information
2461 for (i
= 0; i
< nDbg
; i
++)
2462 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_FPO
)
2463 FIXME("This guy has FPO information\n");
2467 #define FRAME_TRAP 1
2470 typedef struct _FPO_DATA
2472 DWORD ulOffStart
; /* offset 1st byte of function code */
2473 DWORD cbProcSize
; /* # bytes in function */
2474 DWORD cdwLocals
; /* # bytes in locals/4 */
2475 WORD cdwParams
; /* # bytes in params/4 */
2477 WORD cbProlog
: 8; /* # bytes in prolog */
2478 WORD cbRegs
: 3; /* # regs saved */
2479 WORD fHasSEH
: 1; /* TRUE if SEH in func */
2480 WORD fUseBP
: 1; /* TRUE if EBP has been allocated */
2481 WORD reserved
: 1; /* reserved for future use */
2482 WORD cbFrame
: 2; /* frame type */
2489 ERR("Got a page fault while loading symbols\n");