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-2009, 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.
35 #define NONAMELESSUNION
38 #include "wine/port.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 struct pdb_stream_name
75 struct pdb_stream_name
* stream_dict
;
76 unsigned fpoext_stream
;
82 struct PDB_JG_TOC
* toc
;
87 struct PDB_DS_TOC
* toc
;
92 /* FIXME: don't make it static */
93 #define CV_MAX_MODULES 32
94 struct pdb_module_info
96 unsigned used_subfiles
;
97 struct pdb_file_info pdb_files
[CV_MAX_MODULES
];
100 /*========================================================================
101 * Debug file access helper routines
104 static void dump(const void* ptr
, unsigned len
)
108 const char* hexof
= "0123456789abcdef";
111 for (i
= 0; i
< len
; i
+= 16)
113 sprintf(msg
, "%08x: ", i
);
114 memset(msg
+ 10, ' ', 3 * 16 + 1 + 16);
115 for (j
= 0; j
< min(16, len
- i
); j
++)
117 msg
[10 + 3 * j
+ 0] = hexof
[x
[i
+ j
] >> 4];
118 msg
[10 + 3 * j
+ 1] = hexof
[x
[i
+ j
] & 15];
119 msg
[10 + 3 * j
+ 2] = ' ';
120 msg
[10 + 3 * 16 + 1 + j
] = (x
[i
+ j
] >= 0x20 && x
[i
+ j
] < 0x7f) ?
123 msg
[10 + 3 * 16] = ' ';
124 msg
[10 + 3 * 16 + 1 + 16] = '\0';
129 /*========================================================================
130 * Process CodeView type information.
133 #define MAX_BUILTIN_TYPES 0x06FF
134 #define FIRST_DEFINABLE_TYPE 0x1000
136 static struct symt
* cv_basic_types
[MAX_BUILTIN_TYPES
];
138 struct cv_defined_module
141 unsigned int num_defined_types
;
142 struct symt
** defined_types
;
144 /* FIXME: don't make it static */
145 #define CV_MAX_MODULES 32
146 static struct cv_defined_module cv_zmodules
[CV_MAX_MODULES
];
147 static struct cv_defined_module
*cv_current_module
;
149 static void codeview_init_basic_types(struct module
* module
)
152 * These are the common builtin types that are used by VC++.
154 cv_basic_types
[T_NOTYPE
] = NULL
;
155 cv_basic_types
[T_ABS
] = NULL
;
156 cv_basic_types
[T_VOID
] = &symt_new_basic(module
, btVoid
, "void", 0)->symt
;
157 cv_basic_types
[T_CHAR
] = &symt_new_basic(module
, btChar
, "char", 1)->symt
;
158 cv_basic_types
[T_SHORT
] = &symt_new_basic(module
, btInt
, "short int", 2)->symt
;
159 cv_basic_types
[T_LONG
] = &symt_new_basic(module
, btInt
, "long int", 4)->symt
;
160 cv_basic_types
[T_QUAD
] = &symt_new_basic(module
, btInt
, "long long int", 8)->symt
;
161 cv_basic_types
[T_UCHAR
] = &symt_new_basic(module
, btUInt
, "unsigned char", 1)->symt
;
162 cv_basic_types
[T_USHORT
] = &symt_new_basic(module
, btUInt
, "unsigned short", 2)->symt
;
163 cv_basic_types
[T_ULONG
] = &symt_new_basic(module
, btUInt
, "unsigned long", 4)->symt
;
164 cv_basic_types
[T_UQUAD
] = &symt_new_basic(module
, btUInt
, "unsigned long long", 8)->symt
;
165 cv_basic_types
[T_BOOL08
] = &symt_new_basic(module
, btBool
, "BOOL08", 1)->symt
;
166 cv_basic_types
[T_BOOL16
] = &symt_new_basic(module
, btBool
, "BOOL16", 2)->symt
;
167 cv_basic_types
[T_BOOL32
] = &symt_new_basic(module
, btBool
, "BOOL32", 4)->symt
;
168 cv_basic_types
[T_BOOL64
] = &symt_new_basic(module
, btBool
, "BOOL64", 8)->symt
;
169 cv_basic_types
[T_REAL32
] = &symt_new_basic(module
, btFloat
, "float", 4)->symt
;
170 cv_basic_types
[T_REAL64
] = &symt_new_basic(module
, btFloat
, "double", 8)->symt
;
171 cv_basic_types
[T_REAL80
] = &symt_new_basic(module
, btFloat
, "long double", 10)->symt
;
172 cv_basic_types
[T_RCHAR
] = &symt_new_basic(module
, btInt
, "signed char", 1)->symt
;
173 cv_basic_types
[T_WCHAR
] = &symt_new_basic(module
, btWChar
, "wchar_t", 2)->symt
;
174 cv_basic_types
[T_INT2
] = &symt_new_basic(module
, btInt
, "INT2", 2)->symt
;
175 cv_basic_types
[T_UINT2
] = &symt_new_basic(module
, btUInt
, "UINT2", 2)->symt
;
176 cv_basic_types
[T_INT4
] = &symt_new_basic(module
, btInt
, "INT4", 4)->symt
;
177 cv_basic_types
[T_UINT4
] = &symt_new_basic(module
, btUInt
, "UINT4", 4)->symt
;
178 cv_basic_types
[T_INT8
] = &symt_new_basic(module
, btInt
, "INT8", 8)->symt
;
179 cv_basic_types
[T_UINT8
] = &symt_new_basic(module
, btUInt
, "UINT8", 8)->symt
;
180 cv_basic_types
[T_HRESULT
]= &symt_new_basic(module
, btUInt
, "HRESULT", 4)->symt
;
182 cv_basic_types
[T_32PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], 4)->symt
;
183 cv_basic_types
[T_32PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], 4)->symt
;
184 cv_basic_types
[T_32PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], 4)->symt
;
185 cv_basic_types
[T_32PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], 4)->symt
;
186 cv_basic_types
[T_32PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], 4)->symt
;
187 cv_basic_types
[T_32PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], 4)->symt
;
188 cv_basic_types
[T_32PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], 4)->symt
;
189 cv_basic_types
[T_32PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], 4)->symt
;
190 cv_basic_types
[T_32PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], 4)->symt
;
191 cv_basic_types
[T_32PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], 4)->symt
;
192 cv_basic_types
[T_32PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], 4)->symt
;
193 cv_basic_types
[T_32PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], 4)->symt
;
194 cv_basic_types
[T_32PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], 4)->symt
;
195 cv_basic_types
[T_32PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], 4)->symt
;
196 cv_basic_types
[T_32PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], 4)->symt
;
197 cv_basic_types
[T_32PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], 4)->symt
;
198 cv_basic_types
[T_32PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], 4)->symt
;
199 cv_basic_types
[T_32PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], 4)->symt
;
200 cv_basic_types
[T_32PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], 4)->symt
;
201 cv_basic_types
[T_32PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], 4)->symt
;
202 cv_basic_types
[T_32PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], 4)->symt
;
203 cv_basic_types
[T_32PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], 4)->symt
;
204 cv_basic_types
[T_32PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], 4)->symt
;
205 cv_basic_types
[T_32PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], 4)->symt
;
206 cv_basic_types
[T_32PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
], 4)->symt
;
208 cv_basic_types
[T_64PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], 8)->symt
;
209 cv_basic_types
[T_64PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], 8)->symt
;
210 cv_basic_types
[T_64PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], 8)->symt
;
211 cv_basic_types
[T_64PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], 8)->symt
;
212 cv_basic_types
[T_64PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], 8)->symt
;
213 cv_basic_types
[T_64PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], 8)->symt
;
214 cv_basic_types
[T_64PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], 8)->symt
;
215 cv_basic_types
[T_64PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], 8)->symt
;
216 cv_basic_types
[T_64PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], 8)->symt
;
217 cv_basic_types
[T_64PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], 8)->symt
;
218 cv_basic_types
[T_64PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], 8)->symt
;
219 cv_basic_types
[T_64PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], 8)->symt
;
220 cv_basic_types
[T_64PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], 8)->symt
;
221 cv_basic_types
[T_64PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], 8)->symt
;
222 cv_basic_types
[T_64PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], 8)->symt
;
223 cv_basic_types
[T_64PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], 8)->symt
;
224 cv_basic_types
[T_64PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], 8)->symt
;
225 cv_basic_types
[T_64PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], 8)->symt
;
226 cv_basic_types
[T_64PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], 8)->symt
;
227 cv_basic_types
[T_64PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], 8)->symt
;
228 cv_basic_types
[T_64PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], 8)->symt
;
229 cv_basic_types
[T_64PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], 8)->symt
;
230 cv_basic_types
[T_64PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], 8)->symt
;
231 cv_basic_types
[T_64PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], 8)->symt
;
232 cv_basic_types
[T_64PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
], 8)->symt
;
235 static int leaf_as_variant(VARIANT
* v
, const unsigned short int* leaf
)
237 unsigned short int type
= *leaf
++;
240 if (type
< LF_NUMERIC
)
242 v
->n1
.n2
.vt
= VT_UINT
;
243 v
->n1
.n2
.n3
.uintVal
= type
;
252 v
->n1
.n2
.n3
.cVal
= *(const char*)leaf
;
258 v
->n1
.n2
.n3
.iVal
= *(const short*)leaf
;
263 v
->n1
.n2
.vt
= VT_UI2
;
264 v
->n1
.n2
.n3
.uiVal
= *leaf
;
270 v
->n1
.n2
.n3
.lVal
= *(const int*)leaf
;
275 v
->n1
.n2
.vt
= VT_UI4
;
276 v
->n1
.n2
.n3
.uiVal
= *(const unsigned int*)leaf
;
282 v
->n1
.n2
.n3
.llVal
= *(const long long int*)leaf
;
287 v
->n1
.n2
.vt
= VT_UI8
;
288 v
->n1
.n2
.n3
.ullVal
= *(const long long unsigned int*)leaf
;
294 v
->n1
.n2
.n3
.fltVal
= *(const float*)leaf
;
298 FIXME("Unsupported numeric leaf type %04x\n", type
);
300 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
306 v
->n1
.n2
.n3
.fltVal
= *(const double*)leaf
;
310 FIXME("Unsupported numeric leaf type %04x\n", type
);
312 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
316 FIXME("Unsupported numeric leaf type %04x\n", type
);
318 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
322 FIXME("Unsupported numeric leaf type %04x\n", type
);
324 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
328 FIXME("Unsupported numeric leaf type %04x\n", type
);
330 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
334 FIXME("Unsupported numeric leaf type %04x\n", type
);
336 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
340 FIXME("Unsupported numeric leaf type %04x\n", type
);
342 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
346 FIXME("Unsupported numeric leaf type %04x\n", type
);
348 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
352 FIXME("Unknown numeric leaf type %04x\n", type
);
353 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
361 static int numeric_leaf(int* value
, const unsigned short int* leaf
)
363 unsigned short int type
= *leaf
++;
366 if (type
< LF_NUMERIC
)
376 *value
= *(const char*)leaf
;
381 *value
= *(const short*)leaf
;
391 *value
= *(const int*)leaf
;
396 *value
= *(const unsigned int*)leaf
;
401 FIXME("Unsupported numeric leaf type %04x\n", type
);
403 *value
= 0; /* FIXME */
407 FIXME("Unsupported numeric leaf type %04x\n", type
);
409 *value
= 0; /* FIXME */
413 FIXME("Unsupported numeric leaf type %04x\n", type
);
415 *value
= 0; /* FIXME */
419 FIXME("Unsupported numeric leaf type %04x\n", type
);
421 *value
= 0; /* FIXME */
425 FIXME("Unsupported numeric leaf type %04x\n", type
);
427 *value
= 0; /* FIXME */
431 FIXME("Unsupported numeric leaf type %04x\n", type
);
433 *value
= 0; /* FIXME */
437 FIXME("Unsupported numeric leaf type %04x\n", type
);
439 *value
= 0; /* FIXME */
443 FIXME("Unsupported numeric leaf type %04x\n", type
);
445 *value
= 0; /* FIXME */
449 FIXME("Unsupported numeric leaf type %04x\n", type
);
451 *value
= 0; /* FIXME */
455 FIXME("Unsupported numeric leaf type %04x\n", type
);
457 *value
= 0; /* FIXME */
461 FIXME("Unsupported numeric leaf type %04x\n", type
);
463 *value
= 0; /* FIXME */
467 FIXME("Unknown numeric leaf type %04x\n", type
);
476 /* convert a pascal string (as stored in debug information) into
477 * a C string (null terminated).
479 static const char* terminate_string(const struct p_string
* p_name
)
481 static char symname
[256];
483 memcpy(symname
, p_name
->name
, p_name
->namelen
);
484 symname
[p_name
->namelen
] = '\0';
486 return (!*symname
|| strcmp(symname
, "__unnamed") == 0) ? NULL
: symname
;
489 static struct symt
* codeview_get_type(unsigned int typeno
, BOOL quiet
)
491 struct symt
* symt
= NULL
;
494 * Convert Codeview type numbers into something we can grok internally.
495 * Numbers < FIRST_DEFINABLE_TYPE are all fixed builtin types.
496 * Numbers from FIRST_DEFINABLE_TYPE and up are all user defined (structs, etc).
498 if (typeno
< FIRST_DEFINABLE_TYPE
)
500 if (typeno
< MAX_BUILTIN_TYPES
)
501 symt
= cv_basic_types
[typeno
];
505 unsigned mod_index
= typeno
>> 24;
506 unsigned mod_typeno
= typeno
& 0x00FFFFFF;
507 struct cv_defined_module
* mod
;
509 mod
= (mod_index
== 0) ? cv_current_module
: &cv_zmodules
[mod_index
];
511 if (mod_index
>= CV_MAX_MODULES
|| !mod
->allowed
)
512 FIXME("Module of index %d isn't loaded yet (%x)\n", mod_index
, typeno
);
515 if (mod_typeno
- FIRST_DEFINABLE_TYPE
< mod
->num_defined_types
)
516 symt
= mod
->defined_types
[mod_typeno
- FIRST_DEFINABLE_TYPE
];
519 if (!quiet
&& !symt
&& typeno
) FIXME("Returning NULL symt for type-id %x\n", typeno
);
523 struct codeview_type_parse
525 struct module
* module
;
531 static inline const void* codeview_jump_to_type(const struct codeview_type_parse
* ctp
, DWORD idx
)
533 if (idx
< FIRST_DEFINABLE_TYPE
) return NULL
;
534 idx
-= FIRST_DEFINABLE_TYPE
;
535 return (idx
>= ctp
->num
) ? NULL
: (ctp
->table
+ ctp
->offset
[idx
]);
538 static int codeview_add_type(unsigned int typeno
, struct symt
* dt
)
540 if (typeno
< FIRST_DEFINABLE_TYPE
)
541 FIXME("What the heck\n");
542 if (!cv_current_module
)
544 FIXME("Adding %x to non allowed module\n", typeno
);
547 if ((typeno
>> 24) != 0)
548 FIXME("No module index while inserting type-id assumption is wrong %x\n",
550 if (typeno
- FIRST_DEFINABLE_TYPE
>= cv_current_module
->num_defined_types
)
552 if (cv_current_module
->defined_types
)
554 cv_current_module
->num_defined_types
= max( cv_current_module
->num_defined_types
* 2,
555 typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
556 cv_current_module
->defined_types
= HeapReAlloc(GetProcessHeap(),
557 HEAP_ZERO_MEMORY
, cv_current_module
->defined_types
,
558 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
562 cv_current_module
->num_defined_types
= max( 256, typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
563 cv_current_module
->defined_types
= HeapAlloc(GetProcessHeap(),
565 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
567 if (cv_current_module
->defined_types
== NULL
) return FALSE
;
569 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
])
571 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] != dt
)
572 FIXME("Overwriting at %x\n", typeno
);
574 cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] = dt
;
578 static void codeview_clear_type_table(void)
582 for (i
= 0; i
< CV_MAX_MODULES
; i
++)
584 if (cv_zmodules
[i
].allowed
)
585 HeapFree(GetProcessHeap(), 0, cv_zmodules
[i
].defined_types
);
586 cv_zmodules
[i
].allowed
= FALSE
;
587 cv_zmodules
[i
].defined_types
= NULL
;
588 cv_zmodules
[i
].num_defined_types
= 0;
590 cv_current_module
= NULL
;
593 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
595 const union codeview_type
* type
, BOOL details
);
597 static void* codeview_cast_symt(struct symt
* symt
, enum SymTagEnum tag
)
599 if (symt
->tag
!= tag
)
601 FIXME("Bad tag. Expected %d, but got %d\n", tag
, symt
->tag
);
607 static struct symt
* codeview_fetch_type(struct codeview_type_parse
* ctp
,
608 unsigned typeno
, BOOL details
)
611 const union codeview_type
* p
;
613 if (!typeno
) return NULL
;
614 if ((symt
= codeview_get_type(typeno
, TRUE
))) return symt
;
616 /* forward declaration */
617 if (!(p
= codeview_jump_to_type(ctp
, typeno
)))
619 FIXME("Cannot locate type %x\n", typeno
);
622 symt
= codeview_parse_one_type(ctp
, typeno
, p
, details
);
623 if (!symt
) FIXME("Couldn't load forward type %x\n", typeno
);
627 static struct symt
* codeview_add_type_pointer(struct codeview_type_parse
* ctp
,
628 struct symt
* existing
,
629 unsigned int pointee_type
)
631 struct symt
* pointee
;
635 existing
= codeview_cast_symt(existing
, SymTagPointerType
);
638 pointee
= codeview_fetch_type(ctp
, pointee_type
, FALSE
);
639 return &symt_new_pointer(ctp
->module
, pointee
, sizeof(void *))->symt
;
642 static struct symt
* codeview_add_type_array(struct codeview_type_parse
* ctp
,
644 unsigned int elemtype
,
645 unsigned int indextype
,
646 unsigned int arr_len
)
648 struct symt
* elem
= codeview_fetch_type(ctp
, elemtype
, FALSE
);
649 struct symt
* index
= codeview_fetch_type(ctp
, indextype
, FALSE
);
651 return &symt_new_array(ctp
->module
, 0, -arr_len
, elem
, index
)->symt
;
654 static BOOL
codeview_add_type_enum_field_list(struct module
* module
,
655 struct symt_enum
* symt
,
656 const union codeview_reftype
* ref_type
)
658 const unsigned char* ptr
= ref_type
->fieldlist
.list
;
659 const unsigned char* last
= (const BYTE
*)ref_type
+ ref_type
->generic
.len
+ 2;
660 const union codeview_fieldtype
* type
;
664 if (*ptr
>= 0xf0) /* LF_PAD... */
670 type
= (const union codeview_fieldtype
*)ptr
;
672 switch (type
->generic
.id
)
674 case LF_ENUMERATE_V1
:
676 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v1
.value
);
677 const struct p_string
* p_name
= (const struct p_string
*)((const unsigned char*)&type
->enumerate_v1
.value
+ vlen
);
679 symt_add_enum_element(module
, symt
, terminate_string(p_name
), value
);
680 ptr
+= 2 + 2 + vlen
+ (1 + p_name
->namelen
);
683 case LF_ENUMERATE_V3
:
685 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v3
.value
);
686 const char* name
= (const char*)&type
->enumerate_v3
.value
+ vlen
;
688 symt_add_enum_element(module
, symt
, name
, value
);
689 ptr
+= 2 + 2 + vlen
+ (1 + strlen(name
));
694 FIXME("Unsupported type %04x in ENUM field list\n", type
->generic
.id
);
701 static void codeview_add_udt_element(struct codeview_type_parse
* ctp
,
702 struct symt_udt
* symt
, const char* name
,
703 int value
, unsigned type
)
705 struct symt
* subtype
;
706 const union codeview_reftype
*cv_type
;
708 if ((cv_type
= codeview_jump_to_type(ctp
, type
)))
710 switch (cv_type
->generic
.id
)
713 symt_add_udt_element(ctp
->module
, symt
, name
,
714 codeview_fetch_type(ctp
, cv_type
->bitfield_v1
.type
, FALSE
),
715 (value
<< 3) + cv_type
->bitfield_v1
.bitoff
,
716 cv_type
->bitfield_v1
.nbits
);
719 symt_add_udt_element(ctp
->module
, symt
, name
,
720 codeview_fetch_type(ctp
, cv_type
->bitfield_v2
.type
, FALSE
),
721 (value
<< 3) + cv_type
->bitfield_v2
.bitoff
,
722 cv_type
->bitfield_v2
.nbits
);
726 subtype
= codeview_fetch_type(ctp
, type
, FALSE
);
730 DWORD64 elem_size
= 0;
731 symt_get_info(ctp
->module
, subtype
, TI_GET_LENGTH
, &elem_size
);
732 symt_add_udt_element(ctp
->module
, symt
, name
, subtype
,
733 value
<< 3, (DWORD
)elem_size
<< 3);
737 static int codeview_add_type_struct_field_list(struct codeview_type_parse
* ctp
,
738 struct symt_udt
* symt
,
739 unsigned fieldlistno
)
741 const unsigned char* ptr
;
742 const unsigned char* last
;
744 const struct p_string
* p_name
;
746 const union codeview_reftype
*type_ref
;
747 const union codeview_fieldtype
* type
;
749 if (!fieldlistno
) return TRUE
;
750 type_ref
= codeview_jump_to_type(ctp
, fieldlistno
);
751 ptr
= type_ref
->fieldlist
.list
;
752 last
= (const BYTE
*)type_ref
+ type_ref
->generic
.len
+ 2;
756 if (*ptr
>= 0xf0) /* LF_PAD... */
762 type
= (const union codeview_fieldtype
*)ptr
;
764 switch (type
->generic
.id
)
767 leaf_len
= numeric_leaf(&value
, &type
->bclass_v1
.offset
);
769 /* FIXME: ignored for now */
771 ptr
+= 2 + 2 + 2 + leaf_len
;
775 leaf_len
= numeric_leaf(&value
, &type
->bclass_v2
.offset
);
777 /* FIXME: ignored for now */
779 ptr
+= 2 + 2 + 4 + leaf_len
;
785 const unsigned short int* p_vboff
;
787 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v1
.vbpoff
);
788 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v1
.vbpoff
+ leaf_len
);
789 vplen
= numeric_leaf(&vpoff
, p_vboff
);
791 /* FIXME: ignored for now */
793 ptr
+= 2 + 2 + 2 + 2 + leaf_len
+ vplen
;
800 const unsigned short int* p_vboff
;
802 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v2
.vbpoff
);
803 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v2
.vbpoff
+ leaf_len
);
804 vplen
= numeric_leaf(&vpoff
, p_vboff
);
806 /* FIXME: ignored for now */
808 ptr
+= 2 + 2 + 4 + 4 + leaf_len
+ vplen
;
813 leaf_len
= numeric_leaf(&value
, &type
->member_v1
.offset
);
814 p_name
= (const struct p_string
*)((const char*)&type
->member_v1
.offset
+ leaf_len
);
816 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
817 type
->member_v1
.type
);
819 ptr
+= 2 + 2 + 2 + leaf_len
+ (1 + p_name
->namelen
);
823 leaf_len
= numeric_leaf(&value
, &type
->member_v2
.offset
);
824 p_name
= (const struct p_string
*)((const unsigned char*)&type
->member_v2
.offset
+ leaf_len
);
826 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
827 type
->member_v2
.type
);
829 ptr
+= 2 + 2 + 4 + leaf_len
+ (1 + p_name
->namelen
);
833 leaf_len
= numeric_leaf(&value
, &type
->member_v3
.offset
);
834 c_name
= (const char*)&type
->member_v3
.offset
+ leaf_len
;
836 codeview_add_udt_element(ctp
, symt
, c_name
, value
, type
->member_v3
.type
);
838 ptr
+= 2 + 2 + 4 + leaf_len
+ (strlen(c_name
) + 1);
842 /* FIXME: ignored for now */
843 ptr
+= 2 + 2 + 2 + (1 + type
->stmember_v1
.p_name
.namelen
);
847 /* FIXME: ignored for now */
848 ptr
+= 2 + 4 + 2 + (1 + type
->stmember_v2
.p_name
.namelen
);
852 /* FIXME: ignored for now */
853 ptr
+= 2 + 4 + 2 + (strlen(type
->stmember_v3
.name
) + 1);
857 /* FIXME: ignored for now */
858 ptr
+= 2 + 2 + 2 + (1 + type
->method_v1
.p_name
.namelen
);
862 /* FIXME: ignored for now */
863 ptr
+= 2 + 2 + 4 + (1 + type
->method_v2
.p_name
.namelen
);
867 /* FIXME: ignored for now */
868 ptr
+= 2 + 2 + 4 + (strlen(type
->method_v3
.name
) + 1);
872 /* FIXME: ignored for now */
873 ptr
+= 2 + 2 + (1 + type
->nesttype_v1
.p_name
.namelen
);
877 /* FIXME: ignored for now */
878 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype_v2
.p_name
.namelen
);
882 /* FIXME: ignored for now */
883 ptr
+= 2 + 2 + 4 + (strlen(type
->nesttype_v3
.name
) + 1);
887 /* FIXME: ignored for now */
892 /* FIXME: ignored for now */
896 case LF_ONEMETHOD_V1
:
897 /* FIXME: ignored for now */
898 switch ((type
->onemethod_v1
.attribute
>> 2) & 7)
900 case 4: case 6: /* (pure) introducing virtual method */
901 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt_v1
.p_name
.namelen
);
905 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod_v1
.p_name
.namelen
);
910 case LF_ONEMETHOD_V2
:
911 /* FIXME: ignored for now */
912 switch ((type
->onemethod_v2
.attribute
>> 2) & 7)
914 case 4: case 6: /* (pure) introducing virtual method */
915 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod_virt_v2
.p_name
.namelen
);
919 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod_v2
.p_name
.namelen
);
924 case LF_ONEMETHOD_V3
:
925 /* FIXME: ignored for now */
926 switch ((type
->onemethod_v3
.attribute
>> 2) & 7)
928 case 4: case 6: /* (pure) introducing virtual method */
929 ptr
+= 2 + 2 + 4 + 4 + (strlen(type
->onemethod_virt_v3
.name
) + 1);
933 ptr
+= 2 + 2 + 4 + (strlen(type
->onemethod_v3
.name
) + 1);
939 if (!codeview_add_type_struct_field_list(ctp
, symt
, type
->index_v1
.ref
))
945 if (!codeview_add_type_struct_field_list(ctp
, symt
, type
->index_v2
.ref
))
951 FIXME("Unsupported type %04x in STRUCT field list\n", type
->generic
.id
);
959 static struct symt
* codeview_add_type_enum(struct codeview_type_parse
* ctp
,
960 struct symt
* existing
,
962 unsigned fieldlistno
,
965 struct symt_enum
* symt
;
969 if (!(symt
= codeview_cast_symt(existing
, SymTagEnum
))) return NULL
;
970 /* should also check that all fields are the same */
974 symt
= symt_new_enum(ctp
->module
, name
,
975 codeview_fetch_type(ctp
, basetype
, FALSE
));
978 const union codeview_reftype
* fieldlist
;
979 fieldlist
= codeview_jump_to_type(ctp
, fieldlistno
);
980 codeview_add_type_enum_field_list(ctp
->module
, symt
, fieldlist
);
986 static struct symt
* codeview_add_type_struct(struct codeview_type_parse
* ctp
,
987 struct symt
* existing
,
988 const char* name
, int structlen
,
989 enum UdtKind kind
, unsigned property
)
991 struct symt_udt
* symt
;
993 /* if we don't have an existing type, try to find one with same name
994 * FIXME: what to do when several types in different CUs have same name ?
999 struct symt_ht
* type
;
1000 struct hash_table_iter hti
;
1002 hash_table_iter_init(&ctp
->module
->ht_types
, &hti
, name
);
1003 while ((ptr
= hash_table_iter_up(&hti
)))
1005 type
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
1007 if (type
->symt
.tag
== SymTagUDT
&&
1008 type
->hash_elt
.name
&& !strcmp(type
->hash_elt
.name
, name
))
1010 existing
= &type
->symt
;
1017 if (!(symt
= codeview_cast_symt(existing
, SymTagUDT
))) return NULL
;
1018 /* should also check that all fields are the same */
1019 if (!(property
& 0x80)) /* 0x80 = forward declaration */
1021 if (!symt
->size
) /* likely prior forward declaration, set UDT size */
1022 symt_set_udt_size(ctp
->module
, symt
, structlen
);
1023 else /* different UDT with same name, create a new type */
1027 if (!existing
) symt
= symt_new_udt(ctp
->module
, name
, structlen
, kind
);
1032 static struct symt
* codeview_new_func_signature(struct codeview_type_parse
* ctp
,
1033 struct symt
* existing
,
1034 enum CV_call_e call_conv
)
1036 struct symt_function_signature
* sym
;
1040 sym
= codeview_cast_symt(existing
, SymTagFunctionType
);
1041 if (!sym
) return NULL
;
1045 sym
= symt_new_function_signature(ctp
->module
, NULL
, call_conv
);
1050 static void codeview_add_func_signature_args(struct codeview_type_parse
* ctp
,
1051 struct symt_function_signature
* sym
,
1055 const union codeview_reftype
* reftype
;
1057 sym
->rettype
= codeview_fetch_type(ctp
, ret_type
, FALSE
);
1058 if (args_list
&& (reftype
= codeview_jump_to_type(ctp
, args_list
)))
1061 switch (reftype
->generic
.id
)
1064 for (i
= 0; i
< reftype
->arglist_v1
.num
; i
++)
1065 symt_add_function_signature_parameter(ctp
->module
, sym
,
1066 codeview_fetch_type(ctp
, reftype
->arglist_v1
.args
[i
], FALSE
));
1069 for (i
= 0; i
< reftype
->arglist_v2
.num
; i
++)
1070 symt_add_function_signature_parameter(ctp
->module
, sym
,
1071 codeview_fetch_type(ctp
, reftype
->arglist_v2
.args
[i
], FALSE
));
1074 FIXME("Unexpected leaf %x for signature's pmt\n", reftype
->generic
.id
);
1079 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
1081 const union codeview_type
* type
, BOOL details
)
1084 int value
, leaf_len
;
1085 const struct p_string
* p_name
;
1087 struct symt
* existing
;
1089 existing
= codeview_get_type(curr_type
, TRUE
);
1091 switch (type
->generic
.id
)
1093 case LF_MODIFIER_V1
:
1094 /* FIXME: we don't handle modifiers,
1095 * but read previous type on the curr_type
1097 WARN("Modifier on %x: %s%s%s%s\n",
1098 type
->modifier_v1
.type
,
1099 type
->modifier_v1
.attribute
& 0x01 ? "const " : "",
1100 type
->modifier_v1
.attribute
& 0x02 ? "volatile " : "",
1101 type
->modifier_v1
.attribute
& 0x04 ? "unaligned " : "",
1102 type
->modifier_v1
.attribute
& ~0x07 ? "unknown " : "");
1103 symt
= codeview_fetch_type(ctp
, type
->modifier_v1
.type
, details
);
1105 case LF_MODIFIER_V2
:
1106 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
1107 WARN("Modifier on %x: %s%s%s%s\n",
1108 type
->modifier_v2
.type
,
1109 type
->modifier_v2
.attribute
& 0x01 ? "const " : "",
1110 type
->modifier_v2
.attribute
& 0x02 ? "volatile " : "",
1111 type
->modifier_v2
.attribute
& 0x04 ? "unaligned " : "",
1112 type
->modifier_v2
.attribute
& ~0x07 ? "unknown " : "");
1113 symt
= codeview_fetch_type(ctp
, type
->modifier_v2
.type
, details
);
1117 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v1
.datatype
);
1120 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v2
.datatype
);
1124 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1127 leaf_len
= numeric_leaf(&value
, &type
->array_v1
.arrlen
);
1128 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v1
.arrlen
+ leaf_len
);
1129 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1130 type
->array_v1
.elemtype
,
1131 type
->array_v1
.idxtype
, value
);
1135 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1138 leaf_len
= numeric_leaf(&value
, &type
->array_v2
.arrlen
);
1139 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v2
.arrlen
+ leaf_len
);
1141 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1142 type
->array_v2
.elemtype
,
1143 type
->array_v2
.idxtype
, value
);
1147 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1150 leaf_len
= numeric_leaf(&value
, &type
->array_v3
.arrlen
);
1151 c_name
= (const char*)&type
->array_v3
.arrlen
+ leaf_len
;
1153 symt
= codeview_add_type_array(ctp
, c_name
,
1154 type
->array_v3
.elemtype
,
1155 type
->array_v3
.idxtype
, value
);
1159 case LF_STRUCTURE_V1
:
1161 leaf_len
= numeric_leaf(&value
, &type
->struct_v1
.structlen
);
1162 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v1
.structlen
+ leaf_len
);
1163 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1164 type
->generic
.id
== LF_CLASS_V1
? UdtClass
: UdtStruct
,
1165 type
->struct_v1
.property
);
1168 codeview_add_type(curr_type
, symt
);
1169 if (!(type
->struct_v1
.property
& 0x80)) /* 0x80 = forward declaration */
1170 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1171 type
->struct_v1
.fieldlist
);
1175 case LF_STRUCTURE_V2
:
1177 leaf_len
= numeric_leaf(&value
, &type
->struct_v2
.structlen
);
1178 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v2
.structlen
+ leaf_len
);
1179 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1180 type
->generic
.id
== LF_CLASS_V2
? UdtClass
: UdtStruct
,
1181 type
->struct_v2
.property
);
1184 codeview_add_type(curr_type
, symt
);
1185 if (!(type
->struct_v2
.property
& 0x80)) /* 0x80 = forward declaration */
1186 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1187 type
->struct_v2
.fieldlist
);
1191 case LF_STRUCTURE_V3
:
1193 leaf_len
= numeric_leaf(&value
, &type
->struct_v3
.structlen
);
1194 c_name
= (const char*)&type
->struct_v3
.structlen
+ leaf_len
;
1195 symt
= codeview_add_type_struct(ctp
, existing
, c_name
, value
,
1196 type
->generic
.id
== LF_CLASS_V3
? UdtClass
: UdtStruct
,
1197 type
->struct_v3
.property
);
1200 codeview_add_type(curr_type
, symt
);
1201 if (!(type
->struct_v3
.property
& 0x80)) /* 0x80 = forward declaration */
1202 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1203 type
->struct_v3
.fieldlist
);
1208 leaf_len
= numeric_leaf(&value
, &type
->union_v1
.un_len
);
1209 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v1
.un_len
+ leaf_len
);
1210 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1211 value
, UdtUnion
, type
->union_v1
.property
);
1214 codeview_add_type(curr_type
, symt
);
1215 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1216 type
->union_v1
.fieldlist
);
1221 leaf_len
= numeric_leaf(&value
, &type
->union_v2
.un_len
);
1222 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v2
.un_len
+ leaf_len
);
1223 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1224 value
, UdtUnion
, type
->union_v2
.property
);
1227 codeview_add_type(curr_type
, symt
);
1228 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1229 type
->union_v2
.fieldlist
);
1234 leaf_len
= numeric_leaf(&value
, &type
->union_v3
.un_len
);
1235 c_name
= (const char*)&type
->union_v3
.un_len
+ leaf_len
;
1236 symt
= codeview_add_type_struct(ctp
, existing
, c_name
,
1237 value
, UdtUnion
, type
->union_v3
.property
);
1240 codeview_add_type(curr_type
, symt
);
1241 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1242 type
->union_v3
.fieldlist
);
1247 symt
= codeview_add_type_enum(ctp
, existing
,
1248 terminate_string(&type
->enumeration_v1
.p_name
),
1249 type
->enumeration_v1
.fieldlist
,
1250 type
->enumeration_v1
.type
);
1254 symt
= codeview_add_type_enum(ctp
, existing
,
1255 terminate_string(&type
->enumeration_v2
.p_name
),
1256 type
->enumeration_v2
.fieldlist
,
1257 type
->enumeration_v2
.type
);
1261 symt
= codeview_add_type_enum(ctp
, existing
, type
->enumeration_v3
.name
,
1262 type
->enumeration_v3
.fieldlist
,
1263 type
->enumeration_v3
.type
);
1266 case LF_PROCEDURE_V1
:
1267 symt
= codeview_new_func_signature(ctp
, existing
, type
->procedure_v1
.call
);
1270 codeview_add_type(curr_type
, symt
);
1271 codeview_add_func_signature_args(ctp
,
1272 (struct symt_function_signature
*)symt
,
1273 type
->procedure_v1
.rvtype
,
1274 type
->procedure_v1
.arglist
);
1277 case LF_PROCEDURE_V2
:
1278 symt
= codeview_new_func_signature(ctp
, existing
,type
->procedure_v2
.call
);
1281 codeview_add_type(curr_type
, symt
);
1282 codeview_add_func_signature_args(ctp
,
1283 (struct symt_function_signature
*)symt
,
1284 type
->procedure_v2
.rvtype
,
1285 type
->procedure_v2
.arglist
);
1289 case LF_MFUNCTION_V1
:
1290 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1291 * nor class information, this would just do for now
1293 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v1
.call
);
1296 codeview_add_type(curr_type
, symt
);
1297 codeview_add_func_signature_args(ctp
,
1298 (struct symt_function_signature
*)symt
,
1299 type
->mfunction_v1
.rvtype
,
1300 type
->mfunction_v1
.arglist
);
1303 case LF_MFUNCTION_V2
:
1304 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1305 * nor class information, this would just do for now
1307 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v2
.call
);
1310 codeview_add_type(curr_type
, symt
);
1311 codeview_add_func_signature_args(ctp
,
1312 (struct symt_function_signature
*)symt
,
1313 type
->mfunction_v2
.rvtype
,
1314 type
->mfunction_v2
.arglist
);
1319 /* this is an ugly hack... FIXME when we have C++ support */
1320 if (!(symt
= existing
))
1323 snprintf(buf
, sizeof(buf
), "__internal_vt_shape_%x\n", curr_type
);
1324 symt
= &symt_new_udt(ctp
->module
, buf
, 0, UdtStruct
)->symt
;
1328 FIXME("Unsupported type-id leaf %x\n", type
->generic
.id
);
1329 dump(type
, 2 + type
->generic
.len
);
1332 return codeview_add_type(curr_type
, symt
) ? symt
: NULL
;
1335 static BOOL
codeview_parse_type_table(struct codeview_type_parse
* ctp
)
1337 unsigned int curr_type
= FIRST_DEFINABLE_TYPE
;
1338 const union codeview_type
* type
;
1340 for (curr_type
= FIRST_DEFINABLE_TYPE
; curr_type
< FIRST_DEFINABLE_TYPE
+ ctp
->num
; curr_type
++)
1342 type
= codeview_jump_to_type(ctp
, curr_type
);
1344 /* type records we're interested in are the ones referenced by symbols
1345 * The known ranges are (X mark the ones we want):
1346 * X 0000-0016 for V1 types
1347 * 0200-020c for V1 types referenced by other types
1348 * 0400-040f for V1 types (complex lists & sets)
1349 * X 1000-100f for V2 types
1350 * 1200-120c for V2 types referenced by other types
1351 * 1400-140f for V1 types (complex lists & sets)
1352 * X 1500-150d for V3 types
1353 * 8000-8010 for numeric leafes
1355 if (!(type
->generic
.id
& 0x8600) || (type
->generic
.id
& 0x0100))
1356 codeview_parse_one_type(ctp
, curr_type
, type
, TRUE
);
1362 /*========================================================================
1363 * Process CodeView line number information.
1365 static unsigned long codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1366 unsigned seg
, unsigned offset
);
1368 static void codeview_snarf_linetab(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
,
1369 int size
, BOOL pascal_str
)
1371 const BYTE
* ptr
= linetab
;
1375 const unsigned int* filetab
;
1376 const unsigned int* lt_ptr
;
1377 const unsigned short* linenos
;
1378 const struct startend
* start
;
1380 unsigned long addr
, func_addr0
;
1381 struct symt_function
* func
;
1382 const struct codeview_linetab_block
* ltb
;
1384 nfile
= *(const short*)linetab
;
1385 filetab
= (const unsigned int*)(linetab
+ 2 * sizeof(short));
1387 for (i
= 0; i
< nfile
; i
++)
1389 ptr
= linetab
+ filetab
[i
];
1390 nseg
= *(const short*)ptr
;
1391 lt_ptr
= (const unsigned int*)(ptr
+ 2 * sizeof(short));
1392 start
= (const struct startend
*)(lt_ptr
+ nseg
);
1395 * Now snarf the filename for all of the segments for this file.
1398 source
= source_new(msc_dbg
->module
, NULL
, terminate_string((const struct p_string
*)(start
+ nseg
)));
1400 source
= source_new(msc_dbg
->module
, NULL
, (const char*)(start
+ nseg
));
1402 for (j
= 0; j
< nseg
; j
++)
1404 ltb
= (const struct codeview_linetab_block
*)(linetab
+ *lt_ptr
++);
1405 linenos
= (const unsigned short*)<b
->offsets
[ltb
->num_lines
];
1406 func_addr0
= codeview_get_address(msc_dbg
, ltb
->seg
, start
[j
].start
);
1407 if (!func_addr0
) continue;
1408 for (func
= NULL
, k
= 0; k
< ltb
->num_lines
; k
++)
1410 /* now locate function (if any) */
1411 addr
= func_addr0
+ ltb
->offsets
[k
] - start
[j
].start
;
1412 /* unfortunately, we can have several functions in the same block, if there's no
1413 * gap between them... find the new function if needed
1415 if (!func
|| addr
>= func
->address
+ func
->size
)
1417 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1418 /* FIXME: at least labels support line numbers */
1419 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1421 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1422 ltb
->seg
, ltb
->offsets
[k
], addr
, func
? func
->symt
.tag
: -1);
1427 symt_add_func_line(msc_dbg
->module
, func
, source
,
1428 linenos
[k
], addr
- func
->address
);
1434 static void codeview_snarf_linetab2(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
, DWORD size
,
1435 const char* strimage
, DWORD strsize
)
1439 const struct codeview_linetab2
* lt2
;
1440 const struct codeview_linetab2
* lt2_files
= NULL
;
1441 const struct codeview_lt2blk_lines
* lines_blk
;
1442 const struct codeview_linetab2_file
*fd
;
1444 struct symt_function
* func
;
1446 /* locate LT2_FILES_BLOCK (if any) */
1447 lt2
= (const struct codeview_linetab2
*)linetab
;
1448 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1450 if (lt2
->header
== LT2_FILES_BLOCK
)
1455 lt2
= codeview_linetab2_next_block(lt2
);
1459 TRACE("No LT2_FILES_BLOCK found\n");
1463 lt2
= (const struct codeview_linetab2
*)linetab
;
1464 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1466 /* FIXME: should also check that whole lines_blk fits in linetab + size */
1467 switch (lt2
->header
)
1469 case LT2_LINES_BLOCK
:
1470 /* Skip blocks that are too small - Intel C Compiler generates these. */
1471 if (lt2
->size_of_block
< sizeof (struct codeview_lt2blk_lines
)) break;
1472 lines_blk
= (const struct codeview_lt2blk_lines
*)lt2
;
1473 /* FIXME: should check that file_offset is within the LT2_FILES_BLOCK we've seen */
1474 addr
= codeview_get_address(msc_dbg
, lines_blk
->seg
, lines_blk
->start
);
1475 TRACE("block from %04x:%08x #%x (%x lines)\n",
1476 lines_blk
->seg
, lines_blk
->start
, lines_blk
->size
, lines_blk
->nlines
);
1477 fd
= (const struct codeview_linetab2_file
*)((const char*)lt2_files
+ 8 + lines_blk
->file_offset
);
1478 /* FIXME: should check that string is within strimage + strsize */
1479 source
= source_new(msc_dbg
->module
, NULL
, strimage
+ fd
->offset
);
1480 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1481 /* FIXME: at least labels support line numbers */
1482 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1484 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1485 lines_blk
->seg
, lines_blk
->start
, addr
, func
? func
->symt
.tag
: -1);
1488 for (i
= 0; i
< lines_blk
->nlines
; i
++)
1490 symt_add_func_line(msc_dbg
->module
, func
, source
,
1491 lines_blk
->l
[i
].lineno
^ 0x80000000,
1492 lines_blk
->l
[i
].offset
);
1495 case LT2_FILES_BLOCK
: /* skip */
1498 TRACE("Block end %x\n", lt2
->header
);
1499 lt2
= (const struct codeview_linetab2
*)((const char*)linetab
+ size
);
1502 lt2
= codeview_linetab2_next_block(lt2
);
1506 /*========================================================================
1507 * Process CodeView symbol information.
1510 static unsigned int codeview_map_offset(const struct msc_debug_info
* msc_dbg
,
1511 unsigned int offset
)
1513 int nomap
= msc_dbg
->nomap
;
1514 const OMAP_DATA
* omapp
= msc_dbg
->omapp
;
1517 if (!nomap
|| !omapp
) return offset
;
1519 /* FIXME: use binary search */
1520 for (i
= 0; i
< nomap
- 1; i
++)
1521 if (omapp
[i
].from
<= offset
&& omapp
[i
+1].from
> offset
)
1522 return !omapp
[i
].to
? 0 : omapp
[i
].to
+ (offset
- omapp
[i
].from
);
1527 static unsigned long codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1528 unsigned seg
, unsigned offset
)
1530 int nsect
= msc_dbg
->nsect
;
1531 const IMAGE_SECTION_HEADER
* sectp
= msc_dbg
->sectp
;
1533 if (!seg
|| seg
> nsect
) return 0;
1534 return msc_dbg
->module
->module
.BaseOfImage
+
1535 codeview_map_offset(msc_dbg
, sectp
[seg
-1].VirtualAddress
+ offset
);
1538 static inline void codeview_add_variable(const struct msc_debug_info
* msc_dbg
,
1539 struct symt_compiland
* compiland
,
1541 unsigned segment
, unsigned offset
,
1542 unsigned symtype
, BOOL is_local
, BOOL in_tls
, BOOL force
)
1546 struct location loc
;
1548 loc
.kind
= in_tls
? loc_tlsrel
: loc_absolute
;
1550 loc
.offset
= in_tls
? offset
: codeview_get_address(msc_dbg
, segment
, offset
);
1551 if (force
|| in_tls
|| !symt_find_nearest(msc_dbg
->module
, loc
.offset
))
1553 symt_new_global_variable(msc_dbg
->module
, compiland
,
1554 name
, is_local
, loc
, 0,
1555 codeview_get_type(symtype
, FALSE
));
1560 static BOOL
codeview_snarf(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1561 int offset
, int size
, BOOL do_globals
)
1563 struct symt_function
* curr_func
= NULL
;
1565 struct symt_block
* block
= NULL
;
1567 struct symt_compiland
* compiland
= NULL
;
1568 struct location loc
;
1571 * Loop over the different types of records and whenever we
1572 * find something we are interested in, record it and move on.
1574 for (i
= offset
; i
< size
; i
+= length
)
1576 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1577 length
= sym
->generic
.len
+ 2;
1578 if (i
+ length
> size
) break;
1579 if (!sym
->generic
.id
|| length
< 4) break;
1580 if (length
& 3) FIXME("unpadded len %u\n", length
);
1582 switch (sym
->generic
.id
)
1585 * Global and local data symbols. We don't associate these
1586 * with any given source file.
1591 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
1592 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
1593 sym
->generic
.id
== S_LDATA_V1
, FALSE
, TRUE
);
1598 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
1599 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
1600 sym
->generic
.id
== S_LDATA_V2
, FALSE
, TRUE
);
1605 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
1606 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
1607 sym
->generic
.id
== S_LDATA_V3
, FALSE
, TRUE
);
1610 /* variables with thread storage */
1614 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v1
.p_name
),
1615 sym
->thread_v1
.segment
, sym
->thread_v1
.offset
, sym
->thread_v1
.symtype
,
1616 sym
->generic
.id
== S_LTHREAD_V1
, TRUE
, TRUE
);
1621 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v2
.p_name
),
1622 sym
->thread_v2
.segment
, sym
->thread_v2
.offset
, sym
->thread_v2
.symtype
,
1623 sym
->generic
.id
== S_LTHREAD_V2
, TRUE
, TRUE
);
1628 codeview_add_variable(msc_dbg
, compiland
, sym
->thread_v3
.name
,
1629 sym
->thread_v3
.segment
, sym
->thread_v3
.offset
, sym
->thread_v3
.symtype
,
1630 sym
->generic
.id
== S_LTHREAD_V3
, TRUE
, TRUE
);
1633 /* Public symbols */
1637 case S_PUB_FUNC1_V3
:
1638 case S_PUB_FUNC2_V3
:
1639 /* will be handled later on in codeview_snarf_public */
1643 * Sort of like a global function, but it just points
1644 * to a thunk, which is a stupid name for what amounts to
1645 * a PLT slot in the normal jargon that everyone else uses.
1648 symt_new_thunk(msc_dbg
->module
, compiland
,
1649 terminate_string(&sym
->thunk_v1
.p_name
), sym
->thunk_v1
.thtype
,
1650 codeview_get_address(msc_dbg
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
),
1651 sym
->thunk_v1
.thunk_len
);
1654 symt_new_thunk(msc_dbg
->module
, compiland
,
1655 sym
->thunk_v3
.name
, sym
->thunk_v3
.thtype
,
1656 codeview_get_address(msc_dbg
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
),
1657 sym
->thunk_v3
.thunk_len
);
1661 * Global and static functions.
1665 if (curr_func
) FIXME("nested function\n");
1666 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1667 terminate_string(&sym
->proc_v1
.p_name
),
1668 codeview_get_address(msc_dbg
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
),
1669 sym
->proc_v1
.proc_len
,
1670 codeview_get_type(sym
->proc_v1
.proctype
, FALSE
));
1671 loc
.kind
= loc_absolute
;
1672 loc
.offset
= sym
->proc_v1
.debug_start
;
1673 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1674 loc
.offset
= sym
->proc_v1
.debug_end
;
1675 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1679 if (curr_func
) FIXME("nested function\n");
1680 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1681 terminate_string(&sym
->proc_v2
.p_name
),
1682 codeview_get_address(msc_dbg
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
),
1683 sym
->proc_v2
.proc_len
,
1684 codeview_get_type(sym
->proc_v2
.proctype
, FALSE
));
1685 loc
.kind
= loc_absolute
;
1686 loc
.offset
= sym
->proc_v2
.debug_start
;
1687 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1688 loc
.offset
= sym
->proc_v2
.debug_end
;
1689 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1693 if (curr_func
) FIXME("nested function\n");
1694 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1696 codeview_get_address(msc_dbg
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
),
1697 sym
->proc_v3
.proc_len
,
1698 codeview_get_type(sym
->proc_v3
.proctype
, FALSE
));
1699 loc
.kind
= loc_absolute
;
1700 loc
.offset
= sym
->proc_v3
.debug_start
;
1701 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1702 loc
.offset
= sym
->proc_v3
.debug_end
;
1703 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1706 * Function parameters and stack variables.
1709 loc
.kind
= loc_regrel
;
1710 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1711 loc
.reg
= CV_REG_EBP
;
1712 loc
.offset
= sym
->stack_v1
.offset
;
1713 symt_add_func_local(msc_dbg
->module
, curr_func
,
1714 sym
->stack_v1
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1716 codeview_get_type(sym
->stack_v1
.symtype
, FALSE
),
1717 terminate_string(&sym
->stack_v1
.p_name
));
1720 loc
.kind
= loc_regrel
;
1721 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1722 loc
.reg
= CV_REG_EBP
;
1723 loc
.offset
= sym
->stack_v2
.offset
;
1724 symt_add_func_local(msc_dbg
->module
, curr_func
,
1725 sym
->stack_v2
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1727 codeview_get_type(sym
->stack_v2
.symtype
, FALSE
),
1728 terminate_string(&sym
->stack_v2
.p_name
));
1731 loc
.kind
= loc_regrel
;
1732 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1733 loc
.reg
= CV_REG_EBP
;
1734 loc
.offset
= sym
->stack_v3
.offset
;
1735 symt_add_func_local(msc_dbg
->module
, curr_func
,
1736 sym
->stack_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1738 codeview_get_type(sym
->stack_v3
.symtype
, FALSE
),
1739 sym
->stack_v3
.name
);
1742 loc
.kind
= loc_regrel
;
1743 loc
.reg
= sym
->regrel_v3
.reg
;
1744 loc
.offset
= sym
->regrel_v3
.offset
;
1745 symt_add_func_local(msc_dbg
->module
, curr_func
,
1746 /* FIXME this is wrong !!! */
1747 sym
->regrel_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1749 codeview_get_type(sym
->regrel_v3
.symtype
, FALSE
),
1750 sym
->regrel_v3
.name
);
1754 loc
.kind
= loc_register
;
1755 loc
.reg
= sym
->register_v1
.reg
;
1757 symt_add_func_local(msc_dbg
->module
, curr_func
,
1759 block
, codeview_get_type(sym
->register_v1
.type
, FALSE
),
1760 terminate_string(&sym
->register_v1
.p_name
));
1763 loc
.kind
= loc_register
;
1764 loc
.reg
= sym
->register_v2
.reg
;
1766 symt_add_func_local(msc_dbg
->module
, curr_func
,
1768 block
, codeview_get_type(sym
->register_v2
.type
, FALSE
),
1769 terminate_string(&sym
->register_v2
.p_name
));
1772 loc
.kind
= loc_register
;
1773 loc
.reg
= sym
->register_v3
.reg
;
1775 symt_add_func_local(msc_dbg
->module
, curr_func
,
1777 block
, codeview_get_type(sym
->register_v3
.type
, FALSE
),
1778 sym
->register_v3
.name
);
1782 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1783 codeview_get_address(msc_dbg
, sym
->block_v1
.segment
, sym
->block_v1
.offset
),
1784 sym
->block_v1
.length
);
1787 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1788 codeview_get_address(msc_dbg
, sym
->block_v3
.segment
, sym
->block_v3
.offset
),
1789 sym
->block_v3
.length
);
1795 block
= symt_close_func_block(msc_dbg
->module
, curr_func
, block
, 0);
1799 symt_normalize_function(msc_dbg
->module
, curr_func
);
1804 case S_COMPILAND_V1
:
1805 TRACE("S-Compiland-V1 %x %s\n",
1806 sym
->compiland_v1
.unknown
, terminate_string(&sym
->compiland_v1
.p_name
));
1809 case S_COMPILAND_V2
:
1810 TRACE("S-Compiland-V2 %s\n", terminate_string(&sym
->compiland_v2
.p_name
));
1811 if (TRACE_ON(dbghelp_msc
))
1813 const char* ptr1
= sym
->compiland_v2
.p_name
.name
+ sym
->compiland_v2
.p_name
.namelen
;
1817 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1818 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1819 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1823 case S_COMPILAND_V3
:
1824 TRACE("S-Compiland-V3 %s\n", sym
->compiland_v3
.name
);
1825 if (TRACE_ON(dbghelp_msc
))
1827 const char* ptr1
= sym
->compiland_v3
.name
+ strlen(sym
->compiland_v3
.name
);
1831 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1832 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1833 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1839 TRACE("S-ObjName %s\n", terminate_string(&sym
->objname_v1
.p_name
));
1840 compiland
= symt_new_compiland(msc_dbg
->module
, 0 /* FIXME */,
1841 source_new(msc_dbg
->module
, NULL
,
1842 terminate_string(&sym
->objname_v1
.p_name
)));
1848 loc
.kind
= loc_absolute
;
1849 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
) - curr_func
->address
;
1850 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
, &loc
,
1851 terminate_string(&sym
->label_v1
.p_name
));
1853 else symt_new_label(msc_dbg
->module
, compiland
,
1854 terminate_string(&sym
->label_v1
.p_name
),
1855 codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
));
1860 loc
.kind
= loc_absolute
;
1861 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
) - curr_func
->address
;
1862 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1863 &loc
, sym
->label_v3
.name
);
1865 else symt_new_label(msc_dbg
->module
, compiland
, sym
->label_v3
.name
,
1866 codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
));
1872 const struct p_string
* name
;
1876 vlen
= leaf_as_variant(&v
, &sym
->constant_v1
.cvalue
);
1877 name
= (const struct p_string
*)((const char*)&sym
->constant_v1
.cvalue
+ vlen
);
1878 se
= codeview_get_type(sym
->constant_v1
.type
, FALSE
);
1880 TRACE("S-Constant-V1 %u %s %x\n",
1881 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v1
.type
);
1882 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1889 const struct p_string
* name
;
1893 vlen
= leaf_as_variant(&v
, &sym
->constant_v2
.cvalue
);
1894 name
= (const struct p_string
*)((const char*)&sym
->constant_v2
.cvalue
+ vlen
);
1895 se
= codeview_get_type(sym
->constant_v2
.type
, FALSE
);
1897 TRACE("S-Constant-V2 %u %s %x\n",
1898 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v2
.type
);
1899 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1910 vlen
= leaf_as_variant(&v
, &sym
->constant_v3
.cvalue
);
1911 name
= (const char*)&sym
->constant_v3
.cvalue
+ vlen
;
1912 se
= codeview_get_type(sym
->constant_v3
.type
, FALSE
);
1914 TRACE("S-Constant-V3 %u %s %x\n",
1915 v
.n1
.n2
.n3
.intVal
, name
, sym
->constant_v3
.type
);
1916 /* FIXME: we should add this as a constant value */
1917 symt_new_constant(msc_dbg
->module
, compiland
, name
, se
, &v
);
1922 if (sym
->udt_v1
.type
)
1924 if ((symt
= codeview_get_type(sym
->udt_v1
.type
, FALSE
)))
1925 symt_new_typedef(msc_dbg
->module
, symt
,
1926 terminate_string(&sym
->udt_v1
.p_name
));
1928 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1929 terminate_string(&sym
->udt_v1
.p_name
), sym
->udt_v1
.type
);
1933 if (sym
->udt_v2
.type
)
1935 if ((symt
= codeview_get_type(sym
->udt_v2
.type
, FALSE
)))
1936 symt_new_typedef(msc_dbg
->module
, symt
,
1937 terminate_string(&sym
->udt_v2
.p_name
));
1939 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1940 terminate_string(&sym
->udt_v2
.p_name
), sym
->udt_v2
.type
);
1944 if (sym
->udt_v3
.type
)
1946 if ((symt
= codeview_get_type(sym
->udt_v3
.type
, FALSE
)))
1947 symt_new_typedef(msc_dbg
->module
, symt
, sym
->udt_v3
.name
);
1949 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1950 sym
->udt_v3
.name
, sym
->udt_v3
.type
);
1955 * These are special, in that they are always followed by an
1956 * additional length-prefixed string which is *not* included
1957 * into the symbol length count. We need to skip it.
1965 name
= (const char*)sym
+ length
;
1966 length
+= (*name
+ 1 + 3) & ~3;
1970 case S_MSTOOL_V3
: /* just to silence a few warnings */
1971 case S_MSTOOLINFO_V3
:
1972 case S_MSTOOLENV_V3
:
1976 TRACE("Start search: seg=0x%x at offset 0x%08x\n",
1977 sym
->ssearch_v1
.segment
, sym
->ssearch_v1
.offset
);
1981 TRACE("S-Align V1\n");
1984 /* the symbols we can safely ignore for now */
1986 case S_FRAMEINFO_V2
:
1987 case S_SECUCOOKIE_V3
:
1989 case S_SUBSECTINFO_V3
:
1990 case S_ENTRYPOINT_V3
:
1997 TRACE("Unsupported symbol id %x\n", sym
->generic
.id
);
2001 FIXME("Unsupported symbol id %x\n", sym
->generic
.id
);
2002 dump(sym
, 2 + sym
->generic
.len
);
2007 if (curr_func
) symt_normalize_function(msc_dbg
->module
, curr_func
);
2012 static BOOL
codeview_snarf_public(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
2013 int offset
, int size
)
2017 struct symt_compiland
* compiland
= NULL
;
2020 * Loop over the different types of records and whenever we
2021 * find something we are interested in, record it and move on.
2023 for (i
= offset
; i
< size
; i
+= length
)
2025 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
2026 length
= sym
->generic
.len
+ 2;
2027 if (i
+ length
> size
) break;
2028 if (!sym
->generic
.id
|| length
< 4) break;
2029 if (length
& 3) FIXME("unpadded len %u\n", length
);
2031 switch (sym
->generic
.id
)
2033 case S_PUB_V1
: /* FIXME is this really a 'data_v1' structure ?? */
2034 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2036 symt_new_public(msc_dbg
->module
, compiland
,
2037 terminate_string(&sym
->data_v1
.p_name
),
2038 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
), 1);
2041 case S_PUB_V2
: /* FIXME is this really a 'data_v2' structure ?? */
2042 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2044 symt_new_public(msc_dbg
->module
, compiland
,
2045 terminate_string(&sym
->data_v2
.p_name
),
2046 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
), 1);
2051 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2053 symt_new_public(msc_dbg
->module
, compiland
,
2055 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
), 1);
2058 case S_PUB_FUNC1_V3
:
2059 case S_PUB_FUNC2_V3
: /* using a data_v3 isn't what we'd expect */
2061 /* FIXME: this is plain wrong (from a simple test) */
2062 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2064 symt_new_public(msc_dbg
->module
, compiland
,
2066 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
), 1);
2071 * Global and local data symbols. We don't associate these
2072 * with any given source file.
2076 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
2077 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
2078 sym
->generic
.id
== S_LDATA_V1
, FALSE
, FALSE
);
2082 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
2083 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
2084 sym
->generic
.id
== S_LDATA_V2
, FALSE
, FALSE
);
2088 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
2089 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
2090 sym
->generic
.id
== S_LDATA_V3
, FALSE
, FALSE
);
2093 /* variables with thread storage */
2096 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v1
.p_name
),
2097 sym
->thread_v1
.segment
, sym
->thread_v1
.offset
, sym
->thread_v1
.symtype
,
2098 sym
->generic
.id
== S_LTHREAD_V1
, TRUE
, FALSE
);
2102 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v2
.p_name
),
2103 sym
->thread_v2
.segment
, sym
->thread_v2
.offset
, sym
->thread_v2
.symtype
,
2104 sym
->generic
.id
== S_LTHREAD_V2
, TRUE
, FALSE
);
2108 codeview_add_variable(msc_dbg
, compiland
, sym
->thread_v3
.name
,
2109 sym
->thread_v3
.segment
, sym
->thread_v3
.offset
, sym
->thread_v3
.symtype
,
2110 sym
->generic
.id
== S_LTHREAD_V3
, TRUE
, FALSE
);
2114 * These are special, in that they are always followed by an
2115 * additional length-prefixed string which is *not* included
2116 * into the symbol length count. We need to skip it.
2121 length
+= (((const char*)sym
)[length
] + 1 + 3) & ~3;
2124 msc_dbg
->module
->sortlist_valid
= TRUE
;
2126 msc_dbg
->module
->sortlist_valid
= FALSE
;
2130 /*========================================================================
2134 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
,
2140 if (!size
) return NULL
;
2142 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2143 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2145 for (i
= 0; i
< num_blocks
; i
++)
2146 memcpy(buffer
+ i
* pdb
->block_size
,
2147 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2152 static void* pdb_ds_read(const struct PDB_DS_HEADER
* pdb
, const DWORD
* block_list
,
2158 if (!size
) return NULL
;
2160 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2161 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2163 for (i
= 0; i
< num_blocks
; i
++)
2164 memcpy(buffer
+ i
* pdb
->block_size
,
2165 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2170 static void* pdb_read_jg_file(const struct PDB_JG_HEADER
* pdb
,
2171 const struct PDB_JG_TOC
* toc
, DWORD file_nr
)
2173 const WORD
* block_list
;
2176 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2178 block_list
= (const WORD
*) &toc
->file
[toc
->num_files
];
2179 for (i
= 0; i
< file_nr
; i
++)
2180 block_list
+= (toc
->file
[i
].size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2182 return pdb_jg_read(pdb
, block_list
, toc
->file
[file_nr
].size
);
2185 static void* pdb_read_ds_file(const struct PDB_DS_HEADER
* pdb
,
2186 const struct PDB_DS_TOC
* toc
, DWORD file_nr
)
2188 const DWORD
* block_list
;
2191 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2192 if (toc
->file_size
[file_nr
] == 0 || toc
->file_size
[file_nr
] == 0xFFFFFFFF) return NULL
;
2194 block_list
= &toc
->file_size
[toc
->num_files
];
2195 for (i
= 0; i
< file_nr
; i
++)
2196 block_list
+= (toc
->file_size
[i
] + pdb
->block_size
- 1) / pdb
->block_size
;
2198 return pdb_ds_read(pdb
, block_list
, toc
->file_size
[file_nr
]);
2201 static void* pdb_read_file(const struct pdb_file_info
* pdb_file
,
2204 switch (pdb_file
->kind
)
2207 return pdb_read_jg_file((const struct PDB_JG_HEADER
*)pdb_file
->image
,
2208 pdb_file
->u
.jg
.toc
, file_nr
);
2210 return pdb_read_ds_file((const struct PDB_DS_HEADER
*)pdb_file
->image
,
2211 pdb_file
->u
.ds
.toc
, file_nr
);
2216 static unsigned pdb_get_file_size(const struct pdb_file_info
* pdb_file
, DWORD file_nr
)
2218 switch (pdb_file
->kind
)
2220 case PDB_JG
: return pdb_file
->u
.jg
.toc
->file
[file_nr
].size
;
2221 case PDB_DS
: return pdb_file
->u
.ds
.toc
->file_size
[file_nr
];
2226 static void pdb_free(void* buffer
)
2228 HeapFree(GetProcessHeap(), 0, buffer
);
2231 static void pdb_free_file(struct pdb_file_info
* pdb_file
)
2233 switch (pdb_file
->kind
)
2236 pdb_free(pdb_file
->u
.jg
.toc
);
2237 pdb_file
->u
.jg
.toc
= NULL
;
2240 pdb_free(pdb_file
->u
.ds
.toc
);
2241 pdb_file
->u
.ds
.toc
= NULL
;
2244 HeapFree(GetProcessHeap(), 0, pdb_file
->stream_dict
);
2247 static void pdb_load_stream_name_table(struct pdb_file_info
* pdb_file
, const char* str
, unsigned cb
)
2255 pdw
= (DWORD
*)(str
+ cb
);
2259 pdb_file
->stream_dict
= HeapAlloc(GetProcessHeap(), 0, (numok
+ 1) * sizeof(struct pdb_stream_name
) + cb
);
2260 if (!pdb_file
->stream_dict
) return;
2261 cpstr
= (char*)(pdb_file
->stream_dict
+ numok
+ 1);
2262 memcpy(cpstr
, str
, cb
);
2264 /* bitfield: first dword is len (in dword), then data */
2266 pdw
+= *ok_bits
++ + 1;
2269 FIXME("unexpected value\n");
2273 for (i
= j
= 0; i
< count
; i
++)
2275 if (ok_bits
[i
/ 32] & (1 << (i
% 32)))
2277 if (j
>= numok
) break;
2278 pdb_file
->stream_dict
[j
].name
= &cpstr
[*pdw
++];
2279 pdb_file
->stream_dict
[j
].index
= *pdw
++;
2284 pdb_file
->stream_dict
[numok
].name
= NULL
;
2285 pdb_file
->fpoext_stream
= -1;
2288 static unsigned pdb_get_stream_by_name(const struct pdb_file_info
* pdb_file
, const char* name
)
2290 struct pdb_stream_name
* psn
;
2292 for (psn
= pdb_file
->stream_dict
; psn
&& psn
->name
; psn
++)
2294 if (!strcmp(psn
->name
, name
)) return psn
->index
;
2299 static void* pdb_read_strings(const struct pdb_file_info
* pdb_file
)
2304 idx
= pdb_get_stream_by_name(pdb_file
, "/names");
2307 ret
= pdb_read_file( pdb_file
, idx
);
2308 if (ret
&& *(const DWORD
*)ret
== 0xeffeeffe) return ret
;
2311 WARN("string table not found\n");
2315 static void pdb_module_remove(struct process
* pcsn
, struct module_format
* modfmt
)
2319 for (i
= 0; i
< modfmt
->u
.pdb_info
->used_subfiles
; i
++)
2321 pdb_free_file(&modfmt
->u
.pdb_info
->pdb_files
[i
]);
2322 if (modfmt
->u
.pdb_info
->pdb_files
[i
].image
)
2323 UnmapViewOfFile(modfmt
->u
.pdb_info
->pdb_files
[i
].image
);
2324 if (modfmt
->u
.pdb_info
->pdb_files
[i
].hMap
)
2325 CloseHandle(modfmt
->u
.pdb_info
->pdb_files
[i
].hMap
);
2327 HeapFree(GetProcessHeap(), 0, modfmt
);
2330 static void pdb_convert_types_header(PDB_TYPES
* types
, const BYTE
* image
)
2332 memset(types
, 0, sizeof(PDB_TYPES
));
2335 if (*(const DWORD
*)image
< 19960000) /* FIXME: correct version? */
2337 /* Old version of the types record header */
2338 const PDB_TYPES_OLD
* old
= (const PDB_TYPES_OLD
*)image
;
2339 types
->version
= old
->version
;
2340 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
2341 types
->type_size
= old
->type_size
;
2342 types
->first_index
= old
->first_index
;
2343 types
->last_index
= old
->last_index
;
2344 types
->file
= old
->file
;
2348 /* New version of the types record header */
2349 *types
= *(const PDB_TYPES
*)image
;
2353 static void pdb_convert_symbols_header(PDB_SYMBOLS
* symbols
,
2354 int* header_size
, const BYTE
* image
)
2356 memset(symbols
, 0, sizeof(PDB_SYMBOLS
));
2359 if (*(const DWORD
*)image
!= 0xffffffff)
2361 /* Old version of the symbols record header */
2362 const PDB_SYMBOLS_OLD
* old
= (const PDB_SYMBOLS_OLD
*)image
;
2363 symbols
->version
= 0;
2364 symbols
->module_size
= old
->module_size
;
2365 symbols
->offset_size
= old
->offset_size
;
2366 symbols
->hash_size
= old
->hash_size
;
2367 symbols
->srcmodule_size
= old
->srcmodule_size
;
2368 symbols
->pdbimport_size
= 0;
2369 symbols
->hash1_file
= old
->hash1_file
;
2370 symbols
->hash2_file
= old
->hash2_file
;
2371 symbols
->gsym_file
= old
->gsym_file
;
2373 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
2377 /* New version of the symbols record header */
2378 *symbols
= *(const PDB_SYMBOLS
*)image
;
2379 *header_size
= sizeof(PDB_SYMBOLS
);
2383 static void pdb_convert_symbol_file(const PDB_SYMBOLS
* symbols
,
2384 PDB_SYMBOL_FILE_EX
* sfile
,
2385 unsigned* size
, const void* image
)
2388 if (symbols
->version
< 19970000)
2390 const PDB_SYMBOL_FILE
*sym_file
= image
;
2391 memset(sfile
, 0, sizeof(*sfile
));
2392 sfile
->file
= sym_file
->file
;
2393 sfile
->range
.index
= sym_file
->range
.index
;
2394 sfile
->symbol_size
= sym_file
->symbol_size
;
2395 sfile
->lineno_size
= sym_file
->lineno_size
;
2396 *size
= sizeof(PDB_SYMBOL_FILE
) - 1;
2400 memcpy(sfile
, image
, sizeof(PDB_SYMBOL_FILE_EX
));
2401 *size
= sizeof(PDB_SYMBOL_FILE_EX
) - 1;
2405 static HANDLE
map_pdb_file(const struct process
* pcs
,
2406 const struct pdb_lookup
* lookup
,
2407 struct module
* module
)
2409 HANDLE hFile
, hMap
= NULL
;
2410 char dbg_file_path
[MAX_PATH
];
2413 switch (lookup
->kind
)
2416 ret
= path_find_symbol_file(pcs
, lookup
->filename
, NULL
, lookup
->timestamp
,
2417 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2420 ret
= path_find_symbol_file(pcs
, lookup
->filename
, &lookup
->guid
, 0,
2421 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2426 WARN("\tCouldn't find %s\n", lookup
->filename
);
2429 if ((hFile
= CreateFileA(dbg_file_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2430 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) != INVALID_HANDLE_VALUE
)
2432 hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
2438 static void pdb_process_types(const struct msc_debug_info
* msc_dbg
,
2439 const struct pdb_file_info
* pdb_file
)
2441 BYTE
* types_image
= NULL
;
2443 types_image
= pdb_read_file(pdb_file
, 2);
2447 struct codeview_type_parse ctp
;
2452 pdb_convert_types_header(&types
, types_image
);
2454 /* Check for unknown versions */
2455 switch (types
.version
)
2457 case 19950410: /* VC 4.0 */
2459 case 19961031: /* VC 5.0 / 6.0 */
2460 case 19990903: /* VC 7.0 */
2461 case 20040203: /* VC 8.0 */
2464 ERR("-Unknown type info version %d\n", types
.version
);
2467 ctp
.module
= msc_dbg
->module
;
2468 /* reconstruct the types offset...
2469 * FIXME: maybe it's present in the newest PDB_TYPES structures
2471 total
= types
.last_index
- types
.first_index
+ 1;
2472 offset
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD
) * total
);
2473 ctp
.table
= ptr
= types_image
+ types
.type_offset
;
2475 while (ptr
< ctp
.table
+ types
.type_size
&& ctp
.num
< total
)
2477 offset
[ctp
.num
++] = ptr
- ctp
.table
;
2478 ptr
+= ((const union codeview_type
*)ptr
)->generic
.len
+ 2;
2480 ctp
.offset
= offset
;
2482 /* Read type table */
2483 codeview_parse_type_table(&ctp
);
2484 HeapFree(GetProcessHeap(), 0, offset
);
2485 pdb_free(types_image
);
2489 static const char PDB_JG_IDENT
[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
2490 static const char PDB_DS_IDENT
[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
2492 /******************************************************************
2495 * Tries to load a pdb file
2496 * 'matched' is filled with the number of correct matches for this file:
2497 * - age counts for one
2498 * - timestamp or guid depending on kind counts for one
2499 * a wrong kind of file returns FALSE (FIXME ?)
2501 static BOOL
pdb_init(const struct pdb_lookup
* pdb_lookup
, struct pdb_file_info
* pdb_file
,
2502 const char* image
, unsigned* matched
)
2506 /* check the file header, and if ok, load the TOC */
2507 TRACE("PDB(%s): %.40s\n", pdb_lookup
->filename
, debugstr_an(image
, 40));
2510 if (!memcmp(image
, PDB_JG_IDENT
, sizeof(PDB_JG_IDENT
)))
2512 const struct PDB_JG_HEADER
* pdb
= (const struct PDB_JG_HEADER
*)image
;
2513 struct PDB_JG_ROOT
* root
;
2515 pdb_file
->u
.jg
.toc
= pdb_jg_read(pdb
, pdb
->toc_block
, pdb
->toc
.size
);
2516 root
= pdb_read_jg_file(pdb
, pdb_file
->u
.jg
.toc
, 1);
2519 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2522 switch (root
->Version
)
2524 case 19950623: /* VC 4.0 */
2526 case 19960307: /* VC 5.0 */
2527 case 19970604: /* VC 6.0 */
2530 ERR("-Unknown root block version %d\n", root
->Version
);
2532 if (pdb_lookup
->kind
!= PDB_JG
)
2534 WARN("Found %s, but wrong PDB kind\n", pdb_lookup
->filename
);
2538 pdb_file
->kind
= PDB_JG
;
2539 pdb_file
->u
.jg
.timestamp
= root
->TimeDateStamp
;
2540 pdb_file
->age
= root
->Age
;
2541 if (root
->TimeDateStamp
== pdb_lookup
->timestamp
) (*matched
)++;
2542 else WARN("Found %s, but wrong signature: %08x %08x\n",
2543 pdb_lookup
->filename
, root
->TimeDateStamp
, pdb_lookup
->timestamp
);
2544 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2545 else WARN("Found %s, but wrong age: %08x %08x\n",
2546 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2547 TRACE("found JG for %s: age=%x timestamp=%x\n",
2548 pdb_lookup
->filename
, root
->Age
, root
->TimeDateStamp
);
2549 pdb_load_stream_name_table(pdb_file
, &root
->names
[0], root
->cbNames
);
2553 else if (!memcmp(image
, PDB_DS_IDENT
, sizeof(PDB_DS_IDENT
)))
2555 const struct PDB_DS_HEADER
* pdb
= (const struct PDB_DS_HEADER
*)image
;
2556 struct PDB_DS_ROOT
* root
;
2558 pdb_file
->u
.ds
.toc
=
2560 (const DWORD
*)((const char*)pdb
+ pdb
->toc_page
* pdb
->block_size
),
2562 root
= pdb_read_ds_file(pdb
, pdb_file
->u
.ds
.toc
, 1);
2565 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2568 switch (root
->Version
)
2573 ERR("-Unknown root block version %d\n", root
->Version
);
2575 pdb_file
->kind
= PDB_DS
;
2576 pdb_file
->u
.ds
.guid
= root
->guid
;
2577 pdb_file
->age
= root
->Age
;
2578 if (!memcmp(&root
->guid
, &pdb_lookup
->guid
, sizeof(GUID
))) (*matched
)++;
2579 else WARN("Found %s, but wrong GUID: %s %s\n",
2580 pdb_lookup
->filename
, debugstr_guid(&root
->guid
),
2581 debugstr_guid(&pdb_lookup
->guid
));
2582 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2583 else WARN("Found %s, but wrong age: %08x %08x\n",
2584 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2585 TRACE("found DS for %s: age=%x guid=%s\n",
2586 pdb_lookup
->filename
, root
->Age
, debugstr_guid(&root
->guid
));
2587 pdb_load_stream_name_table(pdb_file
, &root
->names
[0], root
->cbNames
);
2592 if (0) /* some tool to dump the internal files from a PDB file */
2596 switch (pdb_file
->kind
)
2598 case PDB_JG
: num_files
= pdb_file
->u
.jg
.toc
->num_files
; break;
2599 case PDB_DS
: num_files
= pdb_file
->u
.ds
.toc
->num_files
; break;
2602 for (i
= 1; i
< num_files
; i
++)
2604 unsigned char* x
= pdb_read_file(pdb_file
, i
);
2605 FIXME("********************** [%u]: size=%08x\n",
2606 i
, pdb_get_file_size(pdb_file
, i
));
2607 dump(x
, pdb_get_file_size(pdb_file
, i
));
2614 static BOOL
pdb_process_internal(const struct process
* pcs
,
2615 const struct msc_debug_info
* msc_dbg
,
2616 const struct pdb_lookup
* pdb_lookup
,
2617 struct pdb_module_info
* pdb_module_info
,
2618 unsigned module_index
);
2620 static void pdb_process_symbol_imports(const struct process
* pcs
,
2621 const struct msc_debug_info
* msc_dbg
,
2622 const PDB_SYMBOLS
* symbols
,
2623 const void* symbols_image
,
2625 const struct pdb_lookup
* pdb_lookup
,
2626 struct pdb_module_info
* pdb_module_info
,
2627 unsigned module_index
)
2629 if (module_index
== -1 && symbols
&& symbols
->pdbimport_size
)
2631 const PDB_SYMBOL_IMPORT
*imp
;
2636 struct pdb_file_info sf0
= pdb_module_info
->pdb_files
[0];
2638 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2639 symbols
->module_size
+ symbols
->offset_size
+
2640 symbols
->hash_size
+ symbols
->srcmodule_size
);
2642 last
= (const char*)imp
+ symbols
->pdbimport_size
;
2643 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
2645 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
2646 if (i
>= CV_MAX_MODULES
) FIXME("Out of bounds!!!\n");
2647 if (!strcasecmp(pdb_lookup
->filename
, imp
->filename
))
2649 if (module_index
!= -1) FIXME("Twice the entry\n");
2650 else module_index
= i
;
2651 pdb_module_info
->pdb_files
[i
] = sf0
;
2655 struct pdb_lookup imp_pdb_lookup
;
2657 /* FIXME: this is an import of a JG PDB file
2658 * how's a DS PDB handled ?
2660 imp_pdb_lookup
.filename
= imp
->filename
;
2661 imp_pdb_lookup
.kind
= PDB_JG
;
2662 imp_pdb_lookup
.timestamp
= imp
->TimeDateStamp
;
2663 imp_pdb_lookup
.age
= imp
->Age
;
2664 TRACE("got for %s: age=%u ts=%x\n",
2665 imp
->filename
, imp
->Age
, imp
->TimeDateStamp
);
2666 pdb_process_internal(pcs
, msc_dbg
, &imp_pdb_lookup
, pdb_module_info
, i
);
2669 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)first
+ ((ptr
- (const char*)first
+ strlen(ptr
) + 1 + 3) & ~3));
2671 pdb_module_info
->used_subfiles
= i
;
2673 if (module_index
== -1)
2676 pdb_module_info
->used_subfiles
= 1;
2678 cv_current_module
= &cv_zmodules
[module_index
];
2679 if (cv_current_module
->allowed
) FIXME("Already allowed??\n");
2680 cv_current_module
->allowed
= TRUE
;
2683 static BOOL
pdb_process_internal(const struct process
* pcs
,
2684 const struct msc_debug_info
* msc_dbg
,
2685 const struct pdb_lookup
* pdb_lookup
,
2686 struct pdb_module_info
* pdb_module_info
,
2687 unsigned module_index
)
2691 BYTE
* symbols_image
= NULL
;
2692 char* files_image
= NULL
;
2693 DWORD files_size
= 0;
2695 struct pdb_file_info
* pdb_file
;
2697 TRACE("Processing PDB file %s\n", pdb_lookup
->filename
);
2699 pdb_file
= &pdb_module_info
->pdb_files
[module_index
== -1 ? 0 : module_index
];
2700 /* Open and map() .PDB file */
2701 if ((hMap
= map_pdb_file(pcs
, pdb_lookup
, msc_dbg
->module
)) == NULL
||
2702 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2704 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2708 if (!pdb_init(pdb_lookup
, pdb_file
, image
, &matched
) || matched
!= 2)
2711 UnmapViewOfFile(image
);
2715 pdb_file
->hMap
= hMap
;
2716 pdb_file
->image
= image
;
2717 symbols_image
= pdb_read_file(pdb_file
, 3);
2720 PDB_SYMBOLS symbols
;
2724 int header_size
= 0;
2725 PDB_STREAM_INDEXES
* psi
;
2727 pdb_convert_symbols_header(&symbols
, &header_size
, symbols_image
);
2728 switch (symbols
.version
)
2730 case 0: /* VC 4.0 */
2731 case 19960307: /* VC 5.0 */
2732 case 19970606: /* VC 6.0 */
2736 ERR("-Unknown symbol info version %d %08x\n",
2737 symbols
.version
, symbols
.version
);
2740 switch (symbols
.stream_index_size
)
2743 case sizeof(PDB_STREAM_INDEXES_OLD
):
2744 /* no fpo ext stream in this case */
2746 case sizeof(PDB_STREAM_INDEXES
):
2747 psi
= (PDB_STREAM_INDEXES
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2748 symbols
.module_size
+ symbols
.offset_size
+
2749 symbols
.hash_size
+ symbols
.srcmodule_size
+
2750 symbols
.pdbimport_size
+ symbols
.unknown2_size
);
2751 pdb_file
->fpoext_stream
= psi
->FPO_EXT
;
2754 FIXME("Unknown PDB_STREAM_INDEXES size (%d)\n", symbols
.stream_index_size
);
2757 files_image
= pdb_read_strings(pdb_file
);
2758 if (files_image
) files_size
= *(const DWORD
*)(files_image
+ 8);
2760 pdb_process_symbol_imports(pcs
, msc_dbg
, &symbols
, symbols_image
, image
,
2761 pdb_lookup
, pdb_module_info
, module_index
);
2762 pdb_process_types(msc_dbg
, pdb_file
);
2764 /* Read global symbol table */
2765 globalimage
= pdb_read_file(pdb_file
, symbols
.gsym_file
);
2768 codeview_snarf(msc_dbg
, globalimage
, 0,
2769 pdb_get_file_size(pdb_file
, symbols
.gsym_file
), FALSE
);
2772 /* Read per-module symbols' tables */
2773 file
= symbols_image
+ header_size
;
2774 while (file
- symbols_image
< header_size
+ symbols
.module_size
)
2776 PDB_SYMBOL_FILE_EX sfile
;
2777 const char* file_name
;
2780 HeapValidate(GetProcessHeap(), 0, NULL
);
2781 pdb_convert_symbol_file(&symbols
, &sfile
, &size
, file
);
2783 modimage
= pdb_read_file(pdb_file
, sfile
.file
);
2786 if (sfile
.symbol_size
)
2787 codeview_snarf(msc_dbg
, modimage
, sizeof(DWORD
),
2788 sfile
.symbol_size
, TRUE
);
2790 if (sfile
.lineno_size
)
2791 codeview_snarf_linetab(msc_dbg
,
2792 modimage
+ sfile
.symbol_size
,
2794 pdb_file
->kind
== PDB_JG
);
2796 codeview_snarf_linetab2(msc_dbg
, modimage
+ sfile
.symbol_size
+ sfile
.lineno_size
,
2797 pdb_get_file_size(pdb_file
, sfile
.file
) - sfile
.symbol_size
- sfile
.lineno_size
,
2798 files_image
+ 12, files_size
);
2802 file_name
= (const char*)file
+ size
;
2803 file_name
+= strlen(file_name
) + 1;
2804 file
= (BYTE
*)((DWORD_PTR
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3);
2806 /* finish the remaining public and global information */
2809 codeview_snarf_public(msc_dbg
, globalimage
, 0,
2810 pdb_get_file_size(pdb_file
, symbols
.gsym_file
));
2811 pdb_free(globalimage
);
2815 pdb_process_symbol_imports(pcs
, msc_dbg
, NULL
, NULL
, image
,
2816 pdb_lookup
, pdb_module_info
, module_index
);
2818 pdb_free(symbols_image
);
2819 pdb_free(files_image
);
2824 static BOOL
pdb_process_file(const struct process
* pcs
,
2825 const struct msc_debug_info
* msc_dbg
,
2826 struct pdb_lookup
* pdb_lookup
)
2829 struct module_format
* modfmt
;
2830 struct pdb_module_info
* pdb_module_info
;
2832 modfmt
= HeapAlloc(GetProcessHeap(), 0,
2833 sizeof(struct module_format
) + sizeof(struct pdb_module_info
));
2834 if (!modfmt
) return FALSE
;
2836 pdb_module_info
= (void*)(modfmt
+ 1);
2837 msc_dbg
->module
->format_info
[DFI_PDB
] = modfmt
;
2838 modfmt
->module
= msc_dbg
->module
;
2839 modfmt
->remove
= pdb_module_remove
;
2840 modfmt
->loc_compute
= NULL
;
2841 modfmt
->u
.pdb_info
= pdb_module_info
;
2843 memset(cv_zmodules
, 0, sizeof(cv_zmodules
));
2844 codeview_init_basic_types(msc_dbg
->module
);
2845 ret
= pdb_process_internal(pcs
, msc_dbg
, pdb_lookup
,
2846 msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
, -1);
2847 codeview_clear_type_table();
2850 struct pdb_module_info
* pdb_info
= msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
;
2851 msc_dbg
->module
->module
.SymType
= SymCv
;
2852 if (pdb_info
->pdb_files
[0].kind
== PDB_JG
)
2853 msc_dbg
->module
->module
.PdbSig
= pdb_info
->pdb_files
[0].u
.jg
.timestamp
;
2855 msc_dbg
->module
->module
.PdbSig70
= pdb_info
->pdb_files
[0].u
.ds
.guid
;
2856 msc_dbg
->module
->module
.PdbAge
= pdb_info
->pdb_files
[0].age
;
2857 MultiByteToWideChar(CP_ACP
, 0, pdb_lookup
->filename
, -1,
2858 msc_dbg
->module
->module
.LoadedPdbName
,
2859 sizeof(msc_dbg
->module
->module
.LoadedPdbName
) / sizeof(WCHAR
));
2860 /* FIXME: we could have a finer grain here */
2861 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
2862 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
2863 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
2864 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
2865 msc_dbg
->module
->module
.Publics
= TRUE
;
2869 msc_dbg
->module
->format_info
[DFI_PDB
] = NULL
;
2870 HeapFree(GetProcessHeap(), 0, modfmt
);
2875 BOOL
pdb_fetch_file_info(const struct pdb_lookup
* pdb_lookup
, unsigned* matched
)
2877 HANDLE hFile
, hMap
= NULL
;
2880 struct pdb_file_info pdb_file
;
2882 if ((hFile
= CreateFileA(pdb_lookup
->filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2883 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) == INVALID_HANDLE_VALUE
||
2884 ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
2885 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2887 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2892 ret
= pdb_init(pdb_lookup
, &pdb_file
, image
, matched
);
2893 pdb_free_file(&pdb_file
);
2896 if (image
) UnmapViewOfFile(image
);
2897 if (hMap
) CloseHandle(hMap
);
2898 if (hFile
!= INVALID_HANDLE_VALUE
) CloseHandle(hFile
);
2903 /*========================================================================
2904 * FPO unwinding code
2907 /* Stack unwinding is based on postfixed operations.
2908 * Let's define our Postfix EValuator
2910 #define PEV_MAX_LEN 32
2913 struct cpu_stack_walk
* csw
;
2915 struct vector stack
;
2917 struct hash_table values
;
2924 struct hash_table_elt elt
;
2927 #define PEV_ERROR(pev, msg) snprintf((pev)->error, sizeof((pev)->error), "%s", (msg))
2928 #define PEV_ERROR1(pev, msg, pmt) snprintf((pev)->error, sizeof((pev)->error), (msg), (pmt))
2931 static void pev_dump_stack(struct pevaluator
* pev
)
2934 FIXME("stack #%d\n", pev
->stk_index
);
2935 for (i
= 0; i
< pev
->stk_index
; i
++)
2937 FIXME("\t%d) %s\n", i
, *(char**)vector_at(&pev
->stack
, i
));
2942 /* get the value out of an operand (variable or literal) */
2943 static BOOL
pev_get_val(struct pevaluator
* pev
, const char* str
, DWORD_PTR
* val
)
2946 struct hash_table_iter hti
;
2953 hash_table_iter_init(&pev
->values
, &hti
, str
);
2954 while ((ptr
= hash_table_iter_up(&hti
)))
2956 if (!strcmp(GET_ENTRY(ptr
, struct zvalue
, elt
)->elt
.name
, str
))
2958 *val
= GET_ENTRY(ptr
, struct zvalue
, elt
)->value
;
2962 return PEV_ERROR1(pev
, "get_zvalue: no value found (%s)", str
);
2964 *val
= strtol(str
, &n
, 10);
2965 if (n
== str
|| *n
!= '\0')
2966 return PEV_ERROR1(pev
, "get_val: not a literal (%s)", str
);
2971 /* push an operand onto the stack */
2972 static BOOL
pev_push(struct pevaluator
* pev
, const char* elt
)
2975 if (pev
->stk_index
< vector_length(&pev
->stack
))
2976 at
= vector_at(&pev
->stack
, pev
->stk_index
);
2978 at
= vector_add(&pev
->stack
, &pev
->pool
);
2979 if (!at
) return PEV_ERROR(pev
, "push: out of memory");
2980 *at
= pool_strdup(&pev
->pool
, elt
);
2985 /* pop an operand from the stack */
2986 static BOOL
pev_pop(struct pevaluator
* pev
, char* elt
)
2988 char** at
= vector_at(&pev
->stack
, --pev
->stk_index
);
2989 if (!at
) return PEV_ERROR(pev
, "pop: stack empty");
2994 /* pop an operand from the stack, and gets its value */
2995 static BOOL
pev_pop_val(struct pevaluator
* pev
, DWORD_PTR
* val
)
2997 char p
[PEV_MAX_LEN
];
2999 return pev_pop(pev
, p
) && pev_get_val(pev
, p
, val
);
3002 /* set var 'name' a new value (creates the var if it doesn't exist) */
3003 static BOOL
pev_set_value(struct pevaluator
* pev
, const char* name
, DWORD_PTR val
)
3005 struct hash_table_iter hti
;
3008 hash_table_iter_init(&pev
->values
, &hti
, name
);
3009 while ((ptr
= hash_table_iter_up(&hti
)))
3011 if (!strcmp(GET_ENTRY(ptr
, struct zvalue
, elt
)->elt
.name
, name
))
3013 GET_ENTRY(ptr
, struct zvalue
, elt
)->value
= val
;
3019 struct zvalue
* zv
= pool_alloc(&pev
->pool
, sizeof(*zv
));
3020 if (!zv
) return PEV_ERROR(pev
, "set_value: out of memory");
3023 zv
->elt
.name
= pool_strdup(&pev
->pool
, name
);
3024 hash_table_add(&pev
->values
, &zv
->elt
);
3029 /* execute a binary operand from the two top most values on the stack.
3030 * puts result on top of the stack */
3031 static BOOL
pev_binop(struct pevaluator
* pev
, char op
)
3033 char res
[PEV_MAX_LEN
];
3034 DWORD_PTR v1
, v2
, c
;
3036 if (!pev_pop_val(pev
, &v1
) || !pev_pop_val(pev
, &v2
)) return FALSE
;
3039 case '+': c
= v1
+ v2
; break;
3040 case '-': c
= v1
- v2
; break;
3041 case '*': c
= v1
* v2
; break;
3042 case '/': c
= v1
/ v2
; break;
3043 case '%': c
= v1
% v2
; break;
3044 default: return PEV_ERROR1(pev
, "binop: unknown op (%c)", op
);
3046 snprintf(res
, sizeof(res
), "%ld", c
);
3051 /* pops top most operand, dereference it, on pushes the result on top of the stack */
3052 static BOOL
pev_deref(struct pevaluator
* pev
)
3054 char res
[PEV_MAX_LEN
];
3057 if (!pev_pop_val(pev
, &v1
)) return FALSE
;
3058 if (!sw_read_mem(pev
->csw
, v1
, &v2
, sizeof(v2
)))
3059 return PEV_ERROR1(pev
, "deref: cannot read mem at %lx\n", v1
);
3060 snprintf(res
, sizeof(res
), "%ld", v2
);
3065 /* assign value to variable (from two top most operands) */
3066 static BOOL
pev_assign(struct pevaluator
* pev
)
3068 char p2
[PEV_MAX_LEN
];
3071 if (!pev_pop_val(pev
, &v1
) || !pev_pop(pev
, p2
)) return FALSE
;
3072 if (p2
[0] != '$') return PEV_ERROR1(pev
, "assign: %s isn't a variable", p2
);
3073 pev_set_value(pev
, p2
, v1
);
3078 /* initializes the postfix evaluator */
3079 static void pev_init(struct pevaluator
* pev
, struct cpu_stack_walk
* csw
,
3080 PDB_FPO_DATA
* fpoext
, struct pdb_cmd_pair
* cpair
)
3083 pool_init(&pev
->pool
, 512);
3084 vector_init(&pev
->stack
, sizeof(char*), 8);
3086 hash_table_init(&pev
->pool
, &pev
->values
, 8);
3087 pev
->error
[0] = '\0';
3088 for (; cpair
->name
; cpair
++)
3089 pev_set_value(pev
, cpair
->name
, *cpair
->pvalue
);
3090 pev_set_value(pev
, ".raSearchStart", fpoext
->start
);
3091 pev_set_value(pev
, ".cbLocals", fpoext
->locals_size
);
3092 pev_set_value(pev
, ".cbParams", fpoext
->params_size
);
3093 pev_set_value(pev
, ".cbSavedRegs", fpoext
->savedregs_size
);
3096 static BOOL
pev_free(struct pevaluator
* pev
, struct pdb_cmd_pair
* cpair
)
3100 if (cpair
) for (; cpair
->name
; cpair
++)
3102 if (pev_get_val(pev
, cpair
->name
, &val
))
3103 *cpair
->pvalue
= val
;
3105 pool_destroy(&pev
->pool
);
3109 static BOOL
pdb_parse_cmd_string(struct cpu_stack_walk
* csw
, PDB_FPO_DATA
* fpoext
,
3110 const char* cmd
, struct pdb_cmd_pair
* cpair
)
3112 char token
[PEV_MAX_LEN
];
3116 struct pevaluator pev
;
3118 pev_init(&pev
, csw
, fpoext
, cpair
);
3119 for (ptr
= cmd
; !over
; ptr
++)
3121 if (*ptr
== ' ' || (over
= *ptr
== '\0'))
3125 if (!strcmp(token
, "+") || !strcmp(token
, "-") || !strcmp(token
, "*") ||
3126 !strcmp(token
, "/") || !strcmp(token
, "%"))
3128 if (!pev_binop(&pev
, token
[0])) goto done
;
3130 else if (!strcmp(token
, "^"))
3132 if (!pev_deref(&pev
)) goto done
;
3134 else if (!strcmp(token
, "="))
3136 if (!pev_assign(&pev
)) goto done
;
3140 if (!pev_push(&pev
, token
)) goto done
;
3146 if (ptok
- token
>= PEV_MAX_LEN
- 1)
3148 PEV_ERROR1(&pev
, "parse: token too long (%s)", ptr
- (ptok
- token
));
3154 pev_free(&pev
, cpair
);
3157 FIXME("Couldn't evaluate %s => %s\n", wine_dbgstr_a(cmd
), pev
.error
);
3158 pev_free(&pev
, NULL
);
3162 BOOL
pdb_virtual_unwind(struct cpu_stack_walk
* csw
, DWORD_PTR ip
,
3163 CONTEXT
* context
, struct pdb_cmd_pair
* cpair
)
3165 struct module_pair pair
;
3166 struct pdb_module_info
* pdb_info
;
3167 PDB_FPO_DATA
* fpoext
;
3168 unsigned i
, size
, strsize
;
3172 if (!(pair
.pcs
= process_find_by_handle(csw
->hProcess
)) ||
3173 !(pair
.requested
= module_find_by_addr(pair
.pcs
, ip
, DMT_UNKNOWN
)) ||
3174 !module_get_debug(&pair
))
3176 if (!pair
.effective
->format_info
[DFI_PDB
]) return FALSE
;
3177 pdb_info
= pair
.effective
->format_info
[DFI_PDB
]->u
.pdb_info
;
3178 TRACE("searching %lx => %lx\n", ip
, ip
- (DWORD_PTR
)pair
.effective
->module
.BaseOfImage
);
3179 ip
-= (DWORD_PTR
)pair
.effective
->module
.BaseOfImage
;
3181 strbase
= pdb_read_strings(&pdb_info
->pdb_files
[0]);
3182 if (!strbase
) return FALSE
;
3183 strsize
= *(const DWORD
*)(strbase
+ 8);
3184 fpoext
= pdb_read_file(&pdb_info
->pdb_files
[0], pdb_info
->pdb_files
[0].fpoext_stream
);
3185 size
= pdb_get_file_size(&pdb_info
->pdb_files
[0], pdb_info
->pdb_files
[0].fpoext_stream
);
3186 if (fpoext
&& (size
% sizeof(*fpoext
)) == 0)
3188 size
/= sizeof(*fpoext
);
3189 for (i
= 0; i
< size
; i
++)
3191 if (fpoext
[i
].start
<= ip
&& ip
< fpoext
[i
].start
+ fpoext
[i
].func_size
)
3193 TRACE("\t%08x %08x %8x %8x %4x %4x %4x %08x %s\n",
3194 fpoext
[i
].start
, fpoext
[i
].func_size
, fpoext
[i
].locals_size
,
3195 fpoext
[i
].params_size
, fpoext
[i
].maxstack_size
, fpoext
[i
].prolog_size
,
3196 fpoext
[i
].savedregs_size
, fpoext
[i
].flags
,
3197 fpoext
[i
].str_offset
< strsize
?
3198 wine_dbgstr_a(strbase
+ 12 + fpoext
[i
].str_offset
) : "<out of bounds>");
3199 if (fpoext
[i
].str_offset
< strsize
)
3200 ret
= pdb_parse_cmd_string(csw
, &fpoext
[i
], strbase
+ 12 + fpoext
[i
].str_offset
, cpair
);
3214 /*========================================================================
3215 * Process CodeView debug information.
3218 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
3219 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
3220 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
3221 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
3222 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
3224 static BOOL
codeview_process_info(const struct process
* pcs
,
3225 const struct msc_debug_info
* msc_dbg
)
3227 const DWORD
* signature
= (const DWORD
*)msc_dbg
->root
;
3229 struct pdb_lookup pdb_lookup
;
3231 TRACE("Processing signature %.4s\n", (const char*)signature
);
3235 case CODEVIEW_NB09_SIG
:
3236 case CODEVIEW_NB11_SIG
:
3238 const OMFSignature
* cv
= (const OMFSignature
*)msc_dbg
->root
;
3239 const OMFDirHeader
* hdr
= (const OMFDirHeader
*)(msc_dbg
->root
+ cv
->filepos
);
3240 const OMFDirEntry
* ent
;
3241 const OMFDirEntry
* prev
;
3242 const OMFDirEntry
* next
;
3245 codeview_init_basic_types(msc_dbg
->module
);
3247 for (i
= 0; i
< hdr
->cDir
; i
++)
3249 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
+ i
* hdr
->cbDirEntry
);
3250 if (ent
->SubSection
== sstGlobalTypes
)
3252 const OMFGlobalTypes
* types
;
3253 struct codeview_type_parse ctp
;
3255 types
= (const OMFGlobalTypes
*)(msc_dbg
->root
+ ent
->lfo
);
3256 ctp
.module
= msc_dbg
->module
;
3257 ctp
.offset
= (const DWORD
*)(types
+ 1);
3258 ctp
.num
= types
->cTypes
;
3259 ctp
.table
= (const BYTE
*)(ctp
.offset
+ types
->cTypes
);
3261 cv_current_module
= &cv_zmodules
[0];
3262 if (cv_current_module
->allowed
) FIXME("Already allowed??\n");
3263 cv_current_module
->allowed
= TRUE
;
3265 codeview_parse_type_table(&ctp
);
3270 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
);
3271 for (i
= 0; i
< hdr
->cDir
; i
++, ent
= next
)
3273 next
= (i
== hdr
->cDir
-1) ? NULL
:
3274 (const OMFDirEntry
*)((const BYTE
*)ent
+ hdr
->cbDirEntry
);
3275 prev
= (i
== 0) ? NULL
:
3276 (const OMFDirEntry
*)((const BYTE
*)ent
- hdr
->cbDirEntry
);
3278 if (ent
->SubSection
== sstAlignSym
)
3280 codeview_snarf(msc_dbg
, msc_dbg
->root
+ ent
->lfo
, sizeof(DWORD
),
3284 * Check the next and previous entry. If either is a
3285 * sstSrcModule, it contains the line number info for
3288 * FIXME: This is not a general solution!
3290 if (next
&& next
->iMod
== ent
->iMod
&& next
->SubSection
== sstSrcModule
)
3291 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ next
->lfo
,
3294 if (prev
&& prev
->iMod
== ent
->iMod
&& prev
->SubSection
== sstSrcModule
)
3295 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ prev
->lfo
,
3301 msc_dbg
->module
->module
.SymType
= SymCv
;
3302 /* FIXME: we could have a finer grain here */
3303 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
3304 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
3305 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
3306 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
3307 msc_dbg
->module
->module
.Publics
= TRUE
;
3308 codeview_clear_type_table();
3313 case CODEVIEW_NB10_SIG
:
3315 const CODEVIEW_PDB_DATA
* pdb
= (const CODEVIEW_PDB_DATA
*)msc_dbg
->root
;
3316 pdb_lookup
.filename
= pdb
->name
;
3317 pdb_lookup
.kind
= PDB_JG
;
3318 pdb_lookup
.timestamp
= pdb
->timestamp
;
3319 pdb_lookup
.age
= pdb
->age
;
3320 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
3323 case CODEVIEW_RSDS_SIG
:
3325 const OMFSignatureRSDS
* rsds
= (const OMFSignatureRSDS
*)msc_dbg
->root
;
3327 TRACE("Got RSDS type of PDB file: guid=%s age=%08x name=%s\n",
3328 wine_dbgstr_guid(&rsds
->guid
), rsds
->age
, rsds
->name
);
3329 pdb_lookup
.filename
= rsds
->name
;
3330 pdb_lookup
.kind
= PDB_DS
;
3331 pdb_lookup
.guid
= rsds
->guid
;
3332 pdb_lookup
.age
= rsds
->age
;
3333 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
3337 ERR("Unknown CODEVIEW signature %08x in module %s\n",
3338 *signature
, debugstr_w(msc_dbg
->module
->module
.ModuleName
));
3343 msc_dbg
->module
->module
.CVSig
= *signature
;
3344 memcpy(msc_dbg
->module
->module
.CVData
, msc_dbg
->root
,
3345 sizeof(msc_dbg
->module
->module
.CVData
));
3350 /*========================================================================
3351 * Process debug directory.
3353 BOOL
pe_load_debug_directory(const struct process
* pcs
, struct module
* module
,
3354 const BYTE
* mapping
,
3355 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
3356 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
)
3360 struct msc_debug_info msc_dbg
;
3362 msc_dbg
.module
= module
;
3363 msc_dbg
.nsect
= nsect
;
3364 msc_dbg
.sectp
= sectp
;
3366 msc_dbg
.omapp
= NULL
;
3372 /* First, watch out for OMAP data */
3373 for (i
= 0; i
< nDbg
; i
++)
3375 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
)
3377 msc_dbg
.nomap
= dbg
[i
].SizeOfData
/ sizeof(OMAP_DATA
);
3378 msc_dbg
.omapp
= (const OMAP_DATA
*)(mapping
+ dbg
[i
].PointerToRawData
);
3383 /* Now, try to parse CodeView debug info */
3384 for (i
= 0; i
< nDbg
; i
++)
3386 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_CODEVIEW
)
3388 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
3389 if ((ret
= codeview_process_info(pcs
, &msc_dbg
))) goto done
;
3393 /* If not found, try to parse COFF debug info */
3394 for (i
= 0; i
< nDbg
; i
++)
3396 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_COFF
)
3398 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
3399 if ((ret
= coff_process_info(&msc_dbg
))) goto done
;
3403 /* FIXME: this should be supported... this is the debug information for
3404 * functions compiled without a frame pointer (FPO = frame pointer omission)
3405 * the associated data helps finding out the relevant information
3407 for (i
= 0; i
< nDbg
; i
++)
3408 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_FPO
)
3409 FIXME("This guy has FPO information\n");
3413 #define FRAME_TRAP 1
3416 typedef struct _FPO_DATA
3418 DWORD ulOffStart
; /* offset 1st byte of function code */
3419 DWORD cbProcSize
; /* # bytes in function */
3420 DWORD cdwLocals
; /* # bytes in locals/4 */
3421 WORD cdwParams
; /* # bytes in params/4 */
3423 WORD cbProlog
: 8; /* # bytes in prolog */
3424 WORD cbRegs
: 3; /* # regs saved */
3425 WORD fHasSEH
: 1; /* TRUE if SEH in func */
3426 WORD fUseBP
: 1; /* TRUE if EBP has been allocated */
3427 WORD reserved
: 1; /* reserved for future use */
3428 WORD cbFrame
: 2; /* frame type */
3435 ERR("Got a page fault while loading symbols\n");