push 88671f85dcf7a7cd89c63d6e9f34ad6b6ad2ae64
[wine/hacks.git] / dlls / dbghelp / msc.c
blobaf09f1fd072727ef8ff7b7a345af3299f56ee586
1 /*
2 * File msc.c - read VC++ debug information from COFF and eventually
3 * from PDB files.
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.
30 * TODO:
31 * Get 16 bit CV stuff working.
32 * Add symbol size to internal symbol table.
35 #include "config.h"
36 #include "wine/port.h"
38 #include <assert.h>
39 #include <stdio.h>
40 #include <stdlib.h>
42 #include <string.h>
43 #ifdef HAVE_UNISTD_H
44 # include <unistd.h>
45 #endif
46 #ifndef PATH_MAX
47 #define PATH_MAX MAX_PATH
48 #endif
49 #include <stdarg.h>
50 #include "windef.h"
51 #include "winbase.h"
52 #include "winternl.h"
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)
69 int i, j;
70 char msg[128];
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) ?
84 x[i + j] : '.';
86 msg[10 + 3 * 16] = ' ';
87 msg[10 + 3 * 16 + 1 + 16] = '\0';
88 FIXME("%s\n", msg);
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
103 BOOL allowed;
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++;
173 int length = 2;
175 if (type < LF_NUMERIC)
177 *value = type;
179 else
181 switch (type)
183 case LF_CHAR:
184 length += 1;
185 *value = *(const char*)leaf;
186 break;
188 case LF_SHORT:
189 length += 2;
190 *value = *(const short*)leaf;
191 break;
193 case LF_USHORT:
194 length += 2;
195 *value = *leaf;
196 break;
198 case LF_LONG:
199 length += 4;
200 *value = *(const int*)leaf;
201 break;
203 case LF_ULONG:
204 length += 4;
205 *value = *(const unsigned int*)leaf;
206 break;
208 case LF_QUADWORD:
209 case LF_UQUADWORD:
210 FIXME("Unsupported numeric leaf type %04x\n", type);
211 length += 8;
212 *value = 0; /* FIXME */
213 break;
215 case LF_REAL32:
216 FIXME("Unsupported numeric leaf type %04x\n", type);
217 length += 4;
218 *value = 0; /* FIXME */
219 break;
221 case LF_REAL48:
222 FIXME("Unsupported numeric leaf type %04x\n", type);
223 length += 6;
224 *value = 0; /* FIXME */
225 break;
227 case LF_REAL64:
228 FIXME("Unsupported numeric leaf type %04x\n", type);
229 length += 8;
230 *value = 0; /* FIXME */
231 break;
233 case LF_REAL80:
234 FIXME("Unsupported numeric leaf type %04x\n", type);
235 length += 10;
236 *value = 0; /* FIXME */
237 break;
239 case LF_REAL128:
240 FIXME("Unsupported numeric leaf type %04x\n", type);
241 length += 16;
242 *value = 0; /* FIXME */
243 break;
245 case LF_COMPLEX32:
246 FIXME("Unsupported numeric leaf type %04x\n", type);
247 length += 4;
248 *value = 0; /* FIXME */
249 break;
251 case LF_COMPLEX64:
252 FIXME("Unsupported numeric leaf type %04x\n", type);
253 length += 8;
254 *value = 0; /* FIXME */
255 break;
257 case LF_COMPLEX80:
258 FIXME("Unsupported numeric leaf type %04x\n", type);
259 length += 10;
260 *value = 0; /* FIXME */
261 break;
263 case LF_COMPLEX128:
264 FIXME("Unsupported numeric leaf type %04x\n", type);
265 length += 16;
266 *value = 0; /* FIXME */
267 break;
269 case LF_VARSTRING:
270 FIXME("Unsupported numeric leaf type %04x\n", type);
271 length += 2 + *leaf;
272 *value = 0; /* FIXME */
273 break;
275 default:
276 FIXME("Unknown numeric leaf type %04x\n", type);
277 *value = 0;
278 break;
282 return length;
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];
312 else
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);
322 else
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);
329 return symt;
332 struct codeview_type_parse
334 struct module* module;
335 const BYTE* table;
336 const DWORD* offset;
337 DWORD num;
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);
354 return FALSE;
356 if ((typeno >> 24) != 0)
357 FIXME("No module index while inserting type-id assumption is wrong %x\n",
358 typeno);
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*));
366 else
367 cv_current_module->defined_types = HeapAlloc(GetProcessHeap(),
368 HEAP_ZERO_MEMORY,
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;
379 return TRUE;
382 static void codeview_clear_type_table(void)
384 int i;
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,
398 unsigned curr_type,
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);
406 return NULL;
408 return symt;
411 static struct symt* codeview_fetch_type(struct codeview_type_parse* ctp,
412 unsigned typeno, BOOL details)
414 struct symt* symt;
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);
424 return NULL;
426 symt = codeview_parse_one_type(ctp, typeno, p, details);
427 if (!symt) FIXME("Couldn't load forward type %x\n", typeno);
428 return symt;
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;
437 if (existing)
439 existing = codeview_cast_symt(existing, SymTagPointerType);
440 return existing;
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,
447 const char* name,
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);
454 DWORD arr_max = 0;
456 if (elem)
458 DWORD64 elem_size;
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;
473 while (ptr < last)
475 if (*ptr >= 0xf0) /* LF_PAD... */
477 ptr += *ptr & 0x0f;
478 continue;
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);
492 break;
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));
501 break;
504 default:
505 FIXME("Unsupported type %04x in ENUM field list\n", type->generic.id);
506 return FALSE;
509 return TRUE;
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)
523 case LF_BITFIELD_V1:
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);
528 return;
529 case LF_BITFIELD_V2:
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);
534 return;
537 subtype = codeview_fetch_type(ctp, type, FALSE);
539 if (subtype)
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;
554 int value, leaf_len;
555 const struct p_string* p_name;
556 const char* c_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;
565 while (ptr < last)
567 if (*ptr >= 0xf0) /* LF_PAD... */
569 ptr += *ptr & 0x0f;
570 continue;
573 type = (const union codeview_fieldtype*)ptr;
575 switch (type->generic.id)
577 case LF_BCLASS_V1:
578 leaf_len = numeric_leaf(&value, &type->bclass_v1.offset);
580 /* FIXME: ignored for now */
582 ptr += 2 + 2 + 2 + leaf_len;
583 break;
585 case LF_BCLASS_V2:
586 leaf_len = numeric_leaf(&value, &type->bclass_v2.offset);
588 /* FIXME: ignored for now */
590 ptr += 2 + 2 + 4 + leaf_len;
591 break;
593 case LF_VBCLASS_V1:
594 case LF_IVBCLASS_V1:
596 const unsigned short int* p_vboff;
597 int vpoff, vplen;
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;
606 break;
608 case LF_VBCLASS_V2:
609 case LF_IVBCLASS_V2:
611 const unsigned short int* p_vboff;
612 int vpoff, vplen;
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;
621 break;
623 case LF_MEMBER_V1:
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);
631 break;
633 case LF_MEMBER_V2:
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);
641 break;
643 case LF_MEMBER_V3:
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);
650 break;
652 case LF_STMEMBER_V1:
653 /* FIXME: ignored for now */
654 ptr += 2 + 2 + 2 + (1 + type->stmember_v1.p_name.namelen);
655 break;
657 case LF_STMEMBER_V2:
658 /* FIXME: ignored for now */
659 ptr += 2 + 4 + 2 + (1 + type->stmember_v2.p_name.namelen);
660 break;
662 case LF_STMEMBER_V3:
663 /* FIXME: ignored for now */
664 ptr += 2 + 4 + 2 + (strlen(type->stmember_v3.name) + 1);
665 break;
667 case LF_METHOD_V1:
668 /* FIXME: ignored for now */
669 ptr += 2 + 2 + 2 + (1 + type->method_v1.p_name.namelen);
670 break;
672 case LF_METHOD_V2:
673 /* FIXME: ignored for now */
674 ptr += 2 + 2 + 4 + (1 + type->method_v2.p_name.namelen);
675 break;
677 case LF_METHOD_V3:
678 /* FIXME: ignored for now */
679 ptr += 2 + 2 + 4 + (strlen(type->method_v3.name) + 1);
680 break;
682 case LF_NESTTYPE_V1:
683 /* FIXME: ignored for now */
684 ptr += 2 + 2 + (1 + type->nesttype_v1.p_name.namelen);
685 break;
687 case LF_NESTTYPE_V2:
688 /* FIXME: ignored for now */
689 ptr += 2 + 2 + 4 + (1 + type->nesttype_v2.p_name.namelen);
690 break;
692 case LF_NESTTYPE_V3:
693 /* FIXME: ignored for now */
694 ptr += 2 + 2 + 4 + (strlen(type->nesttype_v3.name) + 1);
695 break;
697 case LF_VFUNCTAB_V1:
698 /* FIXME: ignored for now */
699 ptr += 2 + 2;
700 break;
702 case LF_VFUNCTAB_V2:
703 /* FIXME: ignored for now */
704 ptr += 2 + 2 + 4;
705 break;
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);
713 break;
715 default:
716 ptr += 2 + 2 + 2 + (1 + type->onemethod_v1.p_name.namelen);
717 break;
719 break;
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);
727 break;
729 default:
730 ptr += 2 + 2 + 4 + (1 + type->onemethod_v2.p_name.namelen);
731 break;
733 break;
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);
741 break;
743 default:
744 ptr += 2 + 2 + 4 + (strlen(type->onemethod_v3.name) + 1);
745 break;
747 break;
749 default:
750 FIXME("Unsupported type %04x in STRUCT field list\n", type->generic.id);
751 return FALSE;
755 return TRUE;
758 static struct symt* codeview_add_type_enum(struct codeview_type_parse* ctp,
759 struct symt* existing,
760 const char* name,
761 unsigned fieldlistno,
762 unsigned basetype)
764 struct symt_enum* symt;
766 if (existing)
768 if (!(symt = codeview_cast_symt(existing, SymTagEnum))) return NULL;
769 /* should also check that all fields are the same */
771 else
773 symt = symt_new_enum(ctp->module, name,
774 codeview_fetch_type(ctp, basetype, FALSE));
775 if (fieldlistno)
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);
782 return &symt->symt;
785 static struct symt* codeview_add_type_struct(struct codeview_type_parse* ctp,
786 struct symt* existing,
787 const char* name, int structlen,
788 enum UdtKind kind)
790 struct symt_udt* symt;
792 if (existing)
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);
799 return &symt->symt;
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;
808 if (existing)
810 sym = codeview_cast_symt(existing, SymTagFunctionType);
811 if (!sym) return NULL;
813 else
815 sym = symt_new_function_signature(ctp->module, NULL, call_conv);
817 return &sym->symt;
820 static void codeview_add_func_signature_args(struct codeview_type_parse* ctp,
821 struct symt_function_signature* sym,
822 unsigned ret_type,
823 unsigned args_list)
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)))
830 int i;
831 switch (reftype->generic.id)
833 case LF_ARGLIST_V1:
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));
837 break;
838 case LF_ARGLIST_V2:
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));
842 break;
843 default:
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,
850 unsigned curr_type,
851 const union codeview_type* type, BOOL details)
853 struct symt* symt;
854 int value, leaf_len;
855 const struct p_string* p_name;
856 const char* c_name;
857 struct symt* existing;
859 existing = codeview_get_type(curr_type, TRUE);
861 switch (type->generic.id)
863 case LF_MODIFIER_V1:
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);
874 break;
875 case LF_MODIFIER_V2:
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);
884 break;
886 case LF_POINTER_V1:
887 symt = codeview_add_type_pointer(ctp, existing, type->pointer_v1.datatype);
888 break;
889 case LF_POINTER_V2:
890 symt = codeview_add_type_pointer(ctp, existing, type->pointer_v2.datatype);
891 break;
893 case LF_ARRAY_V1:
894 if (existing) symt = codeview_cast_symt(existing, SymTagArrayType);
895 else
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);
903 break;
904 case LF_ARRAY_V2:
905 if (existing) symt = codeview_cast_symt(existing, SymTagArrayType);
906 else
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);
915 break;
916 case LF_ARRAY_V3:
917 if (existing) symt = codeview_cast_symt(existing, SymTagArrayType);
918 else
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);
927 break;
929 case LF_STRUCTURE_V1:
930 case LF_CLASS_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);
935 if (details)
937 codeview_add_type(curr_type, symt);
938 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
939 type->struct_v1.fieldlist);
941 break;
943 case LF_STRUCTURE_V2:
944 case LF_CLASS_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);
949 if (details)
951 codeview_add_type(curr_type, symt);
952 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
953 type->struct_v2.fieldlist);
955 break;
957 case LF_STRUCTURE_V3:
958 case LF_CLASS_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);
963 if (details)
965 codeview_add_type(curr_type, symt);
966 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
967 type->struct_v3.fieldlist);
969 break;
971 case LF_UNION_V1:
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),
975 value, UdtUnion);
976 if (details)
978 codeview_add_type(curr_type, symt);
979 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
980 type->union_v1.fieldlist);
982 break;
984 case LF_UNION_V2:
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),
988 value, UdtUnion);
989 if (details)
991 codeview_add_type(curr_type, symt);
992 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
993 type->union_v2.fieldlist);
995 break;
997 case LF_UNION_V3:
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,
1001 value, UdtUnion);
1002 if (details)
1004 codeview_add_type(curr_type, symt);
1005 codeview_add_type_struct_field_list(ctp, (struct symt_udt*)symt,
1006 type->union_v3.fieldlist);
1008 break;
1010 case LF_ENUM_V1:
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);
1015 break;
1017 case LF_ENUM_V2:
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);
1022 break;
1024 case LF_ENUM_V3:
1025 symt = codeview_add_type_enum(ctp, existing, type->enumeration_v3.name,
1026 type->enumeration_v3.fieldlist,
1027 type->enumeration_v3.type);
1028 break;
1030 case LF_PROCEDURE_V1:
1031 symt = codeview_new_func_signature(ctp, existing, type->procedure_v1.call);
1032 if (details)
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);
1040 break;
1041 case LF_PROCEDURE_V2:
1042 symt = codeview_new_func_signature(ctp, existing,type->procedure_v2.call);
1043 if (details)
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);
1051 break;
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);
1058 if (details)
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);
1066 break;
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);
1072 if (details)
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);
1080 break;
1082 case LF_VTSHAPE_V1:
1083 /* this is an ugly hack... FIXME when we have C++ support */
1084 if (!(symt = existing))
1086 char buf[128];
1087 snprintf(buf, sizeof(buf), "__internal_vt_shape_%x\n", curr_type);
1088 symt = &symt_new_udt(ctp->module, buf, 0, UdtStruct)->symt;
1090 break;
1091 default:
1092 FIXME("Unsupported type-id leaf %x\n", type->generic.id);
1093 dump(type, 2 + type->generic.len);
1094 return FALSE;
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);
1123 return 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,
1132 BOOL pascal_str)
1134 int file_segcount;
1135 char filename[PATH_MAX];
1136 const unsigned int* filetab;
1137 const struct p_string* p_fn;
1138 int i;
1139 int k;
1140 struct codeview_linetab* lt_hdr;
1141 const unsigned int* lt_ptr;
1142 int nfile;
1143 int nseg;
1144 union any_size pnt;
1145 union any_size pnt2;
1146 const struct startend* start;
1147 int this_seg;
1148 unsigned source;
1151 * Now get the important bits.
1153 pnt.uc = linetab;
1154 nfile = *pnt.s++;
1155 nseg = *pnt.s++;
1157 filetab = (const unsigned int*) pnt.c;
1160 * Now count up the number of segments in the file.
1162 nseg = 0;
1163 for (i = 0; i < nfile; i++)
1165 pnt2.uc = linetab + filetab[i];
1166 nseg += *pnt2.s;
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));
1176 if (lt_hdr == NULL)
1178 goto leave;
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.
1188 this_seg = 0;
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;
1197 pnt2.ui++;
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.
1204 if (pascal_str)
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);
1211 else
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);
1227 leave:
1229 return lt_hdr;
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;
1242 int i;
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);
1251 return 0;
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
1261 if (linetab)
1263 for (; linetab->linetab; linetab++)
1264 if (linetab->segno == seg &&
1265 linetab->start <= offset && linetab->end > offset)
1266 break;
1267 if (!linetab->linetab) linetab = NULL;
1269 return linetab;
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)
1288 unsigned int i;
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;
1306 int i, length;
1307 const struct codeview_linetab* flt;
1308 struct symt_block* block = NULL;
1309 struct symt* symt;
1310 const char* name;
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.
1331 case S_GDATA_V1:
1332 case S_LDATA_V1:
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));
1338 break;
1339 case S_GDATA_V2:
1340 case S_LDATA_V2:
1341 name = terminate_string(&sym->data_v2.p_name);
1342 if (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));
1348 break;
1349 case S_GDATA_V3:
1350 case S_LDATA_V3:
1351 if (*sym->data_v3.name)
1352 symt_new_global_variable(msc_dbg->module, compiland,
1353 sym->data_v3.name,
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));
1358 break;
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 */);
1368 break;
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 */);
1377 break;
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.
1384 case S_THUNK_V1:
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);
1389 break;
1390 case S_THUNK_V3:
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);
1395 break;
1398 * Global and static functions.
1400 case S_GPROC_V1:
1401 case S_LPROC_V1:
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);
1416 break;
1417 case S_GPROC_V2:
1418 case S_LPROC_V2:
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);
1433 break;
1434 case S_GPROC_V3:
1435 case S_LPROC_V3:
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,
1439 sym->proc_v3.name,
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);
1450 break;
1452 * Function parameters and stack variables.
1454 case S_BPREL_V1:
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,
1460 &loc, block,
1461 codeview_get_type(sym->stack_v1.symtype, FALSE),
1462 terminate_string(&sym->stack_v1.p_name));
1463 break;
1464 case S_BPREL_V2:
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,
1470 &loc, block,
1471 codeview_get_type(sym->stack_v2.symtype, FALSE),
1472 terminate_string(&sym->stack_v2.p_name));
1473 break;
1474 case S_BPREL_V3:
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,
1480 &loc, block,
1481 codeview_get_type(sym->stack_v3.symtype, FALSE),
1482 sym->stack_v3.name);
1483 break;
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,
1491 &loc, block,
1492 codeview_get_type(sym->stack_xxxx_v3.symtype, FALSE),
1493 sym->stack_xxxx_v3.name);
1494 break;
1496 case S_REGISTER_V1:
1497 loc.kind = loc_register;
1498 loc.reg = sym->register_v1.reg;
1499 loc.offset = 0;
1500 symt_add_func_local(msc_dbg->module, curr_func,
1501 DataIsLocal, &loc,
1502 block, codeview_get_type(sym->register_v1.type, FALSE),
1503 terminate_string(&sym->register_v1.p_name));
1504 break;
1505 case S_REGISTER_V2:
1506 loc.kind = loc_register;
1507 loc.reg = sym->register_v2.reg;
1508 loc.offset = 0;
1509 symt_add_func_local(msc_dbg->module, curr_func,
1510 DataIsLocal, &loc,
1511 block, codeview_get_type(sym->register_v2.type, FALSE),
1512 terminate_string(&sym->register_v2.p_name));
1513 break;
1514 case S_REGISTER_V3:
1515 loc.kind = loc_register;
1516 loc.reg = sym->register_v3.reg;
1517 loc.offset = 0;
1518 symt_add_func_local(msc_dbg->module, curr_func,
1519 DataIsLocal, &loc,
1520 block, codeview_get_type(sym->register_v3.type, FALSE),
1521 sym->register_v3.name);
1522 break;
1524 case S_BLOCK_V1:
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);
1528 break;
1529 case S_BLOCK_V3:
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);
1533 break;
1535 case S_END_V1:
1536 if (block)
1538 block = symt_close_func_block(msc_dbg->module, curr_func, block, 0);
1540 else if (curr_func)
1542 symt_normalize_function(msc_dbg->module, curr_func);
1543 curr_func = NULL;
1545 break;
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));
1550 break;
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;
1557 const char* ptr2;
1558 while (*ptr1)
1560 ptr2 = ptr1 + strlen(ptr1) + 1;
1561 TRACE("\t%s => %s\n", ptr1, ptr2);
1562 ptr1 = ptr2 + strlen(ptr2) + 1;
1565 break;
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);
1571 const char* ptr2;
1572 while (*ptr1)
1574 ptr2 = ptr1 + strlen(ptr1) + 1;
1575 TRACE("\t%s => %s\n", ptr1, ptr2);
1576 ptr1 = ptr2 + strlen(ptr2) + 1;
1579 break;
1581 case S_OBJNAME_V1:
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)));
1586 break;
1588 case S_LABEL_V1:
1589 if (curr_func)
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));
1599 break;
1600 case S_LABEL_V3:
1601 if (curr_func)
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));
1610 break;
1612 case S_CONSTANT_V1:
1614 int vlen;
1615 const struct p_string* name;
1616 struct symt* se;
1617 VARIANT v;
1619 v.n1.n2.vt = VT_I4;
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),
1627 se, &v);
1629 break;
1630 case S_CONSTANT_V2:
1632 int vlen;
1633 const struct p_string* name;
1634 struct symt* se;
1635 VARIANT v;
1637 v.n1.n2.vt = VT_I4;
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),
1645 se, &v);
1647 break;
1648 case S_CONSTANT_V3:
1650 int vlen;
1651 const char* name;
1652 struct symt* se;
1653 VARIANT v;
1655 v.n1.n2.vt = VT_I4;
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 */
1664 break;
1666 case S_UDT_V1:
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));
1672 else
1673 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1674 terminate_string(&sym->udt_v1.p_name), sym->udt_v1.type);
1676 break;
1677 case S_UDT_V2:
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));
1683 else
1684 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1685 terminate_string(&sym->udt_v2.p_name), sym->udt_v2.type);
1687 break;
1688 case S_UDT_V3:
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);
1693 else
1694 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1695 sym->udt_v3.name, sym->udt_v3.type);
1697 break;
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.
1704 case S_PROCREF_V1:
1705 case S_DATAREF_V1:
1706 case S_LPROCREF_V1:
1707 name = (const char*)sym + length;
1708 length += (*name + 1 + 3) & ~3;
1709 break;
1711 case S_PUB_V3:
1712 if (!(dbghelp_options & SYMOPT_NO_PUBLICS))
1714 symt_new_public(msc_dbg->module, compiland,
1715 sym->data_v3.name,
1716 codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset),
1717 1, FALSE /* FIXME */, FALSE);
1719 break;
1720 case S_PUB_FUNC1_V3:
1721 case S_PUB_FUNC2_V3: /* using a data_v3 isn't what we'd expect */
1722 #if 0
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,
1727 sym->data_v3.name,
1728 codeview_get_address(msc_dbg, sym->data_v3.segment, sym->data_v3.offset),
1729 1, TRUE /* FIXME */, TRUE);
1731 #endif
1732 break;
1734 case S_MSTOOL_V3: /* just to silence a few warnings */
1735 break;
1737 case S_SSEARCH_V1:
1738 TRACE("Start search: seg=0x%x at offset 0x%08x\n",
1739 sym->ssearch_v1.segment, sym->ssearch_v1.offset);
1740 break;
1742 case S_ALIGN_V1:
1743 TRACE("S-Align V1\n");
1744 break;
1746 default:
1747 FIXME("Unsupported symbol id %x\n", sym->generic.id);
1748 dump(sym, 2 + sym->generic.len);
1749 break;
1753 if (curr_func) symt_normalize_function(msc_dbg->module, curr_func);
1755 HeapFree(GetProcessHeap(), 0, linetab);
1756 return TRUE;
1759 /*========================================================================
1760 * Process PDB file.
1763 static void* pdb_jg_read(const struct PDB_JG_HEADER* pdb, const WORD* block_list,
1764 int size)
1766 int i, num_blocks;
1767 BYTE* buffer;
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);
1778 return buffer;
1781 static void* pdb_ds_read(const struct PDB_DS_HEADER* pdb, const DWORD* block_list,
1782 int size)
1784 int i, num_blocks;
1785 BYTE* buffer;
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);
1796 return buffer;
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;
1803 DWORD i;
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;
1818 DWORD i;
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);
1825 return NULL;
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,
1835 DWORD file_nr)
1837 switch (pdb_lookup->kind)
1839 case PDB_JG:
1840 return pdb_read_jg_file((const struct PDB_JG_HEADER*)image,
1841 pdb_lookup->u.jg.toc, file_nr);
1842 case PDB_DS:
1843 return pdb_read_ds_file((const struct PDB_DS_HEADER*)image,
1844 pdb_lookup->u.ds.toc, file_nr);
1846 return NULL;
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];
1856 return 0;
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)
1868 case PDB_JG:
1869 pdb_free(pdb_lookup->u.jg.toc);
1870 break;
1871 case PDB_DS:
1872 pdb_free(pdb_lookup->u.ds.toc);
1873 break;
1877 static void pdb_convert_types_header(PDB_TYPES* types, const BYTE* image)
1879 memset(types, 0, sizeof(PDB_TYPES));
1880 if (!image) return;
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;
1893 else
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));
1904 if (!image) return;
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);
1922 else
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;
1945 else
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) {
1958 CloseHandle(h);
1959 return FALSE;
1961 return TRUE;
1964 static HANDLE open_pdb_file(const struct process* pcs,
1965 const struct pdb_lookup* lookup)
1967 HANDLE h;
1968 char dbg_file_path[MAX_PATH];
1969 BOOL ret = FALSE;
1971 switch (lookup->kind)
1973 case PDB_JG:
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);
1978 break;
1979 case PDB_DS:
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);
1983 break;
1985 if (!ret)
1987 WARN("\tCouldn't find %s\n", lookup->filename);
1988 return NULL;
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);
2002 if (types_image)
2004 PDB_TYPES types;
2005 struct codeview_type_parse ctp;
2006 DWORD total;
2007 const BYTE* ptr;
2008 DWORD* offset;
2010 pdb_convert_types_header(&types, types_image);
2012 /* Check for unknown versions */
2013 switch (types.version)
2015 case 19950410: /* VC 4.0 */
2016 case 19951122:
2017 case 19961031: /* VC 5.0 / 6.0 */
2018 case 19990903:
2019 break;
2020 default:
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;
2031 ctp.num = 0;
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 /******************************************************************
2050 * pdb_init
2052 * Tries to load a pdb file
2053 * if do_fill is TRUE, then it just fills pdb_lookup with the information of the
2054 * file
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)
2060 BOOL ret = TRUE;
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);
2072 if (!root)
2074 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup->filename);
2075 return FALSE;
2077 switch (root->Version)
2079 case 19950623: /* VC 4.0 */
2080 case 19950814:
2081 case 19960307: /* VC 5.0 */
2082 case 19970604: /* VC 6.0 */
2083 break;
2084 default:
2085 ERR("-Unknown root block version %d\n", root->Version);
2087 if (do_fill)
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)
2096 ret = FALSE;
2097 TRACE("found JG/%c for %s: age=%x timestamp=%x\n",
2098 do_fill ? 'f' : '-', pdb_lookup->filename, root->Age,
2099 root->TimeDateStamp);
2100 pdb_free(root);
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 =
2108 pdb_ds_read(pdb,
2109 (const DWORD*)((const char*)pdb + pdb->toc_page * pdb->block_size),
2110 pdb->toc_size);
2111 root = pdb_read_ds_file(pdb, pdb_lookup->u.ds.toc, 1);
2112 if (!root)
2114 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup->filename);
2115 return FALSE;
2117 switch (root->Version)
2119 case 20000404:
2120 break;
2121 default:
2122 ERR("-Unknown root block version %d\n", root->Version);
2124 if (do_fill)
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)
2133 ret = FALSE;
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));
2137 pdb_free(root);
2140 if (0) /* some tool to dump the internal files from a PDB file */
2142 int i, num_files;
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));
2156 pdb_free(x);
2159 return ret;
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,
2171 const char* 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;
2178 const void* first;
2179 const void* last;
2180 const char* ptr;
2181 int i = 0;
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;
2197 else
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);
2212 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)
2227 BOOL ret = FALSE;
2228 HANDLE hFile, hMap = NULL;
2229 char* image = 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);
2240 goto leave;
2242 pdb_init(pdb_lookup, image, FALSE);
2244 symbols_image = pdb_read_file(image, pdb_lookup, 3);
2245 if (symbols_image)
2247 PDB_SYMBOLS symbols;
2248 BYTE* modimage;
2249 BYTE* file;
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 */
2258 case 19990903:
2259 break;
2260 default:
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);
2269 if (modimage)
2271 codeview_snarf(msc_dbg, modimage, 0,
2272 pdb_get_file_size(pdb_lookup, symbols.gsym_file), NULL);
2274 pdb_free(modimage);
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;
2283 unsigned size;
2285 HeapValidate(GetProcessHeap(), 0, NULL);
2286 pdb_convert_symbol_file(&symbols, &sfile, &size, file);
2288 modimage = pdb_read_file(image, pdb_lookup, sfile.file);
2289 if (modimage)
2291 struct codeview_linetab* linetab = NULL;
2293 if (sfile.lineno_size)
2294 linetab = codeview_snarf_linetab(msc_dbg->module,
2295 modimage + sfile.symbol_size,
2296 sfile.lineno_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);
2303 pdb_free(modimage);
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);
2310 else
2311 pdb_process_symbol_imports(pcs, msc_dbg, NULL, NULL, image, pdb_lookup,
2312 module_index);
2313 ret = TRUE;
2315 leave:
2316 /* Cleanup */
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);
2324 return ret;
2327 static BOOL pdb_process_file(const struct process* pcs,
2328 const struct msc_debug_info* msc_dbg,
2329 struct pdb_lookup* pdb_lookup)
2331 BOOL ret;
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();
2337 if (ret)
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;
2342 else
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;
2355 return ret;
2358 BOOL pdb_fetch_file_info(struct pdb_lookup* pdb_lookup)
2360 HANDLE hFile, hMap = NULL;
2361 char* image = NULL;
2362 BOOL ret = TRUE;
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);
2370 ret = FALSE;
2372 else
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);
2382 return ret;
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;
2399 BOOL ret = FALSE;
2400 struct pdb_lookup pdb_lookup;
2402 TRACE("Processing signature %.4s\n", (const char*)signature);
2404 switch (*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;
2414 unsigned int i;
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);
2437 break;
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
2454 * this file.
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,
2464 TRUE);
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,
2470 TRUE);
2472 codeview_snarf(msc_dbg, msc_dbg->root + ent->lfo, sizeof(DWORD),
2473 ent->cb, linetab);
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();
2485 ret = TRUE;
2486 break;
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);
2498 break;
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);
2512 break;
2514 default:
2515 ERR("Unknown CODEVIEW signature %08x in module %s\n",
2516 *signature, debugstr_w(msc_dbg->module->module.ModuleName));
2517 break;
2519 if (ret)
2521 msc_dbg->module->module.CVSig = *signature;
2522 memcpy(msc_dbg->module->module.CVData, msc_dbg->root,
2523 sizeof(msc_dbg->module->module.CVData));
2525 return ret;
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)
2536 BOOL ret;
2537 int i;
2538 struct msc_debug_info msc_dbg;
2540 msc_dbg.module = module;
2541 msc_dbg.nsect = nsect;
2542 msc_dbg.sectp = sectp;
2543 msc_dbg.nomap = 0;
2544 msc_dbg.omapp = NULL;
2546 __TRY
2548 ret = FALSE;
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);
2557 break;
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;
2580 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");
2588 #if 0
2590 #define FRAME_FPO 0
2591 #define FRAME_TRAP 1
2592 #define FRAME_TSS 2
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 */
2607 } FPO_DATA;
2608 #endif
2611 __EXCEPT_PAGE_FAULT
2613 ERR("Got a page fault while loading symbols\n");
2614 ret = FALSE;
2616 __ENDTRY
2617 return ret;