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 struct pdb_stream_name
73 struct pdb_stream_name
* stream_dict
;
74 unsigned fpoext_stream
;
80 struct PDB_JG_TOC
* toc
;
85 struct PDB_DS_TOC
* toc
;
90 /* FIXME: don't make it static */
91 #define CV_MAX_MODULES 32
92 struct pdb_module_info
94 unsigned used_subfiles
;
95 struct pdb_file_info pdb_files
[CV_MAX_MODULES
];
98 /*========================================================================
99 * Debug file access helper routines
102 static void dump(const void* ptr
, unsigned len
)
106 const char* hexof
= "0123456789abcdef";
109 for (i
= 0; i
< len
; i
+= 16)
111 sprintf(msg
, "%08x: ", i
);
112 memset(msg
+ 10, ' ', 3 * 16 + 1 + 16);
113 for (j
= 0; j
< min(16, len
- i
); j
++)
115 msg
[10 + 3 * j
+ 0] = hexof
[x
[i
+ j
] >> 4];
116 msg
[10 + 3 * j
+ 1] = hexof
[x
[i
+ j
] & 15];
117 msg
[10 + 3 * j
+ 2] = ' ';
118 msg
[10 + 3 * 16 + 1 + j
] = (x
[i
+ j
] >= 0x20 && x
[i
+ j
] < 0x7f) ?
121 msg
[10 + 3 * 16] = ' ';
122 msg
[10 + 3 * 16 + 1 + 16] = '\0';
127 /*========================================================================
128 * Process CodeView type information.
131 #define MAX_BUILTIN_TYPES 0x06FF
132 #define FIRST_DEFINABLE_TYPE 0x1000
134 static struct symt
* cv_basic_types
[MAX_BUILTIN_TYPES
];
136 struct cv_defined_module
139 unsigned int num_defined_types
;
140 struct symt
** defined_types
;
142 /* FIXME: don't make it static */
143 #define CV_MAX_MODULES 32
144 static struct cv_defined_module cv_zmodules
[CV_MAX_MODULES
];
145 static struct cv_defined_module
*cv_current_module
;
147 static void codeview_init_basic_types(struct module
* module
)
150 * These are the common builtin types that are used by VC++.
152 cv_basic_types
[T_NOTYPE
] = NULL
;
153 cv_basic_types
[T_ABS
] = NULL
;
154 cv_basic_types
[T_VOID
] = &symt_new_basic(module
, btVoid
, "void", 0)->symt
;
155 cv_basic_types
[T_CHAR
] = &symt_new_basic(module
, btChar
, "char", 1)->symt
;
156 cv_basic_types
[T_SHORT
] = &symt_new_basic(module
, btInt
, "short int", 2)->symt
;
157 cv_basic_types
[T_LONG
] = &symt_new_basic(module
, btInt
, "long int", 4)->symt
;
158 cv_basic_types
[T_QUAD
] = &symt_new_basic(module
, btInt
, "long long int", 8)->symt
;
159 cv_basic_types
[T_UCHAR
] = &symt_new_basic(module
, btUInt
, "unsigned char", 1)->symt
;
160 cv_basic_types
[T_USHORT
] = &symt_new_basic(module
, btUInt
, "unsigned short", 2)->symt
;
161 cv_basic_types
[T_ULONG
] = &symt_new_basic(module
, btUInt
, "unsigned long", 4)->symt
;
162 cv_basic_types
[T_UQUAD
] = &symt_new_basic(module
, btUInt
, "unsigned long long", 8)->symt
;
163 cv_basic_types
[T_BOOL08
] = &symt_new_basic(module
, btBool
, "BOOL08", 1)->symt
;
164 cv_basic_types
[T_BOOL16
] = &symt_new_basic(module
, btBool
, "BOOL16", 2)->symt
;
165 cv_basic_types
[T_BOOL32
] = &symt_new_basic(module
, btBool
, "BOOL32", 4)->symt
;
166 cv_basic_types
[T_BOOL64
] = &symt_new_basic(module
, btBool
, "BOOL64", 8)->symt
;
167 cv_basic_types
[T_REAL32
] = &symt_new_basic(module
, btFloat
, "float", 4)->symt
;
168 cv_basic_types
[T_REAL64
] = &symt_new_basic(module
, btFloat
, "double", 8)->symt
;
169 cv_basic_types
[T_REAL80
] = &symt_new_basic(module
, btFloat
, "long double", 10)->symt
;
170 cv_basic_types
[T_RCHAR
] = &symt_new_basic(module
, btInt
, "signed char", 1)->symt
;
171 cv_basic_types
[T_WCHAR
] = &symt_new_basic(module
, btWChar
, "wchar_t", 2)->symt
;
172 cv_basic_types
[T_INT2
] = &symt_new_basic(module
, btInt
, "INT2", 2)->symt
;
173 cv_basic_types
[T_UINT2
] = &symt_new_basic(module
, btUInt
, "UINT2", 2)->symt
;
174 cv_basic_types
[T_INT4
] = &symt_new_basic(module
, btInt
, "INT4", 4)->symt
;
175 cv_basic_types
[T_UINT4
] = &symt_new_basic(module
, btUInt
, "UINT4", 4)->symt
;
176 cv_basic_types
[T_INT8
] = &symt_new_basic(module
, btInt
, "INT8", 8)->symt
;
177 cv_basic_types
[T_UINT8
] = &symt_new_basic(module
, btUInt
, "UINT8", 8)->symt
;
178 cv_basic_types
[T_HRESULT
]= &symt_new_basic(module
, btUInt
, "HRESULT", 4)->symt
;
180 cv_basic_types
[T_32PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], 4)->symt
;
181 cv_basic_types
[T_32PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], 4)->symt
;
182 cv_basic_types
[T_32PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], 4)->symt
;
183 cv_basic_types
[T_32PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], 4)->symt
;
184 cv_basic_types
[T_32PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], 4)->symt
;
185 cv_basic_types
[T_32PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], 4)->symt
;
186 cv_basic_types
[T_32PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], 4)->symt
;
187 cv_basic_types
[T_32PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], 4)->symt
;
188 cv_basic_types
[T_32PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], 4)->symt
;
189 cv_basic_types
[T_32PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], 4)->symt
;
190 cv_basic_types
[T_32PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], 4)->symt
;
191 cv_basic_types
[T_32PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], 4)->symt
;
192 cv_basic_types
[T_32PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], 4)->symt
;
193 cv_basic_types
[T_32PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], 4)->symt
;
194 cv_basic_types
[T_32PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], 4)->symt
;
195 cv_basic_types
[T_32PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], 4)->symt
;
196 cv_basic_types
[T_32PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], 4)->symt
;
197 cv_basic_types
[T_32PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], 4)->symt
;
198 cv_basic_types
[T_32PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], 4)->symt
;
199 cv_basic_types
[T_32PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], 4)->symt
;
200 cv_basic_types
[T_32PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], 4)->symt
;
201 cv_basic_types
[T_32PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], 4)->symt
;
202 cv_basic_types
[T_32PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], 4)->symt
;
203 cv_basic_types
[T_32PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], 4)->symt
;
204 cv_basic_types
[T_32PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
], 4)->symt
;
206 cv_basic_types
[T_64PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], 8)->symt
;
207 cv_basic_types
[T_64PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], 8)->symt
;
208 cv_basic_types
[T_64PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], 8)->symt
;
209 cv_basic_types
[T_64PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], 8)->symt
;
210 cv_basic_types
[T_64PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], 8)->symt
;
211 cv_basic_types
[T_64PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], 8)->symt
;
212 cv_basic_types
[T_64PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], 8)->symt
;
213 cv_basic_types
[T_64PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], 8)->symt
;
214 cv_basic_types
[T_64PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], 8)->symt
;
215 cv_basic_types
[T_64PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], 8)->symt
;
216 cv_basic_types
[T_64PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], 8)->symt
;
217 cv_basic_types
[T_64PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], 8)->symt
;
218 cv_basic_types
[T_64PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], 8)->symt
;
219 cv_basic_types
[T_64PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], 8)->symt
;
220 cv_basic_types
[T_64PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], 8)->symt
;
221 cv_basic_types
[T_64PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], 8)->symt
;
222 cv_basic_types
[T_64PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], 8)->symt
;
223 cv_basic_types
[T_64PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], 8)->symt
;
224 cv_basic_types
[T_64PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], 8)->symt
;
225 cv_basic_types
[T_64PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], 8)->symt
;
226 cv_basic_types
[T_64PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], 8)->symt
;
227 cv_basic_types
[T_64PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], 8)->symt
;
228 cv_basic_types
[T_64PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], 8)->symt
;
229 cv_basic_types
[T_64PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], 8)->symt
;
230 cv_basic_types
[T_64PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
], 8)->symt
;
232 cv_basic_types
[T_PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], sizeof(void*))->symt
;
233 cv_basic_types
[T_PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], sizeof(void*))->symt
;
234 cv_basic_types
[T_PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], sizeof(void*))->symt
;
235 cv_basic_types
[T_PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], sizeof(void*))->symt
;
236 cv_basic_types
[T_PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], sizeof(void*))->symt
;
237 cv_basic_types
[T_PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], sizeof(void*))->symt
;
238 cv_basic_types
[T_PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], sizeof(void*))->symt
;
239 cv_basic_types
[T_PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], sizeof(void*))->symt
;
240 cv_basic_types
[T_PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], sizeof(void*))->symt
;
241 cv_basic_types
[T_PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], sizeof(void*))->symt
;
242 cv_basic_types
[T_PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], sizeof(void*))->symt
;
243 cv_basic_types
[T_PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], sizeof(void*))->symt
;
244 cv_basic_types
[T_PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], sizeof(void*))->symt
;
245 cv_basic_types
[T_PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], sizeof(void*))->symt
;
246 cv_basic_types
[T_PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], sizeof(void*))->symt
;
247 cv_basic_types
[T_PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], sizeof(void*))->symt
;
248 cv_basic_types
[T_PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], sizeof(void*))->symt
;
249 cv_basic_types
[T_PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], sizeof(void*))->symt
;
250 cv_basic_types
[T_PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], sizeof(void*))->symt
;
251 cv_basic_types
[T_PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], sizeof(void*))->symt
;
252 cv_basic_types
[T_PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], sizeof(void*))->symt
;
253 cv_basic_types
[T_PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], sizeof(void*))->symt
;
254 cv_basic_types
[T_PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], sizeof(void*))->symt
;
255 cv_basic_types
[T_PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], sizeof(void*))->symt
;
258 static int leaf_as_variant(VARIANT
* v
, const unsigned short int* leaf
)
260 unsigned short int type
= *leaf
++;
263 if (type
< LF_NUMERIC
)
265 v
->n1
.n2
.vt
= VT_UINT
;
266 v
->n1
.n2
.n3
.uintVal
= type
;
275 v
->n1
.n2
.n3
.cVal
= *(const char*)leaf
;
281 v
->n1
.n2
.n3
.iVal
= *(const short*)leaf
;
286 v
->n1
.n2
.vt
= VT_UI2
;
287 v
->n1
.n2
.n3
.uiVal
= *leaf
;
293 v
->n1
.n2
.n3
.lVal
= *(const int*)leaf
;
298 v
->n1
.n2
.vt
= VT_UI4
;
299 v
->n1
.n2
.n3
.uiVal
= *(const unsigned int*)leaf
;
305 v
->n1
.n2
.n3
.llVal
= *(const long long int*)leaf
;
310 v
->n1
.n2
.vt
= VT_UI8
;
311 v
->n1
.n2
.n3
.ullVal
= *(const long long unsigned int*)leaf
;
317 v
->n1
.n2
.n3
.fltVal
= *(const float*)leaf
;
321 FIXME("Unsupported numeric leaf type %04x\n", type
);
323 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
329 v
->n1
.n2
.n3
.fltVal
= *(const double*)leaf
;
333 FIXME("Unsupported numeric leaf type %04x\n", type
);
335 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
339 FIXME("Unsupported numeric leaf type %04x\n", type
);
341 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
345 FIXME("Unsupported numeric leaf type %04x\n", type
);
347 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
351 FIXME("Unsupported numeric leaf type %04x\n", type
);
353 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
357 FIXME("Unsupported numeric leaf type %04x\n", type
);
359 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
363 FIXME("Unsupported numeric leaf type %04x\n", type
);
365 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
369 FIXME("Unsupported numeric leaf type %04x\n", type
);
371 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
375 FIXME("Unknown numeric leaf type %04x\n", type
);
376 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
384 static int numeric_leaf(int* value
, const unsigned short int* leaf
)
386 unsigned short int type
= *leaf
++;
389 if (type
< LF_NUMERIC
)
399 *value
= *(const char*)leaf
;
404 *value
= *(const short*)leaf
;
414 *value
= *(const int*)leaf
;
419 *value
= *(const unsigned int*)leaf
;
424 FIXME("Unsupported numeric leaf type %04x\n", type
);
426 *value
= 0; /* FIXME */
430 FIXME("Unsupported numeric leaf type %04x\n", type
);
432 *value
= 0; /* FIXME */
436 FIXME("Unsupported numeric leaf type %04x\n", type
);
438 *value
= 0; /* FIXME */
442 FIXME("Unsupported numeric leaf type %04x\n", type
);
444 *value
= 0; /* FIXME */
448 FIXME("Unsupported numeric leaf type %04x\n", type
);
450 *value
= 0; /* FIXME */
454 FIXME("Unsupported numeric leaf type %04x\n", type
);
456 *value
= 0; /* FIXME */
460 FIXME("Unsupported numeric leaf type %04x\n", type
);
462 *value
= 0; /* FIXME */
466 FIXME("Unsupported numeric leaf type %04x\n", type
);
468 *value
= 0; /* FIXME */
472 FIXME("Unsupported numeric leaf type %04x\n", type
);
474 *value
= 0; /* FIXME */
478 FIXME("Unsupported numeric leaf type %04x\n", type
);
480 *value
= 0; /* FIXME */
484 FIXME("Unsupported numeric leaf type %04x\n", type
);
486 *value
= 0; /* FIXME */
490 FIXME("Unknown numeric leaf type %04x\n", type
);
499 /* convert a pascal string (as stored in debug information) into
500 * a C string (null terminated).
502 static const char* terminate_string(const struct p_string
* p_name
)
504 static char symname
[256];
506 memcpy(symname
, p_name
->name
, p_name
->namelen
);
507 symname
[p_name
->namelen
] = '\0';
509 return (!*symname
|| strcmp(symname
, "__unnamed") == 0) ? NULL
: symname
;
512 static struct symt
* codeview_get_type(unsigned int typeno
, BOOL quiet
)
514 struct symt
* symt
= NULL
;
517 * Convert Codeview type numbers into something we can grok internally.
518 * Numbers < FIRST_DEFINABLE_TYPE are all fixed builtin types.
519 * Numbers from FIRST_DEFINABLE_TYPE and up are all user defined (structs, etc).
521 if (typeno
< FIRST_DEFINABLE_TYPE
)
523 if (typeno
< MAX_BUILTIN_TYPES
)
524 symt
= cv_basic_types
[typeno
];
528 unsigned mod_index
= typeno
>> 24;
529 unsigned mod_typeno
= typeno
& 0x00FFFFFF;
530 struct cv_defined_module
* mod
;
532 mod
= (mod_index
== 0) ? cv_current_module
: &cv_zmodules
[mod_index
];
534 if (mod_index
>= CV_MAX_MODULES
|| !mod
->allowed
)
535 FIXME("Module of index %d isn't loaded yet (%x)\n", mod_index
, typeno
);
538 if (mod_typeno
- FIRST_DEFINABLE_TYPE
< mod
->num_defined_types
)
539 symt
= mod
->defined_types
[mod_typeno
- FIRST_DEFINABLE_TYPE
];
542 if (!quiet
&& !symt
&& typeno
) FIXME("Returning NULL symt for type-id %x\n", typeno
);
546 struct codeview_type_parse
548 struct module
* module
;
554 static inline const void* codeview_jump_to_type(const struct codeview_type_parse
* ctp
, DWORD idx
)
556 if (idx
< FIRST_DEFINABLE_TYPE
) return NULL
;
557 idx
-= FIRST_DEFINABLE_TYPE
;
558 return (idx
>= ctp
->num
) ? NULL
: (ctp
->table
+ ctp
->offset
[idx
]);
561 static int codeview_add_type(unsigned int typeno
, struct symt
* dt
)
563 if (typeno
< FIRST_DEFINABLE_TYPE
)
564 FIXME("What the heck\n");
565 if (!cv_current_module
)
567 FIXME("Adding %x to non allowed module\n", typeno
);
570 if ((typeno
>> 24) != 0)
571 FIXME("No module index while inserting type-id assumption is wrong %x\n",
573 if (typeno
- FIRST_DEFINABLE_TYPE
>= cv_current_module
->num_defined_types
)
575 if (cv_current_module
->defined_types
)
577 cv_current_module
->num_defined_types
= max( cv_current_module
->num_defined_types
* 2,
578 typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
579 cv_current_module
->defined_types
= HeapReAlloc(GetProcessHeap(),
580 HEAP_ZERO_MEMORY
, cv_current_module
->defined_types
,
581 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
585 cv_current_module
->num_defined_types
= max( 256, typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
586 cv_current_module
->defined_types
= HeapAlloc(GetProcessHeap(),
588 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
590 if (cv_current_module
->defined_types
== NULL
) return FALSE
;
592 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
])
594 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] != dt
)
595 FIXME("Overwriting at %x\n", typeno
);
597 cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] = dt
;
601 static void codeview_clear_type_table(void)
605 for (i
= 0; i
< CV_MAX_MODULES
; i
++)
607 if (cv_zmodules
[i
].allowed
)
608 HeapFree(GetProcessHeap(), 0, cv_zmodules
[i
].defined_types
);
609 cv_zmodules
[i
].allowed
= FALSE
;
610 cv_zmodules
[i
].defined_types
= NULL
;
611 cv_zmodules
[i
].num_defined_types
= 0;
613 cv_current_module
= NULL
;
616 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
618 const union codeview_type
* type
, BOOL details
);
620 static void* codeview_cast_symt(struct symt
* symt
, enum SymTagEnum tag
)
622 if (symt
->tag
!= tag
)
624 FIXME("Bad tag. Expected %d, but got %d\n", tag
, symt
->tag
);
630 static struct symt
* codeview_fetch_type(struct codeview_type_parse
* ctp
,
631 unsigned typeno
, BOOL details
)
634 const union codeview_type
* p
;
636 if (!typeno
) return NULL
;
637 if ((symt
= codeview_get_type(typeno
, TRUE
))) return symt
;
639 /* forward declaration */
640 if (!(p
= codeview_jump_to_type(ctp
, typeno
)))
642 FIXME("Cannot locate type %x\n", typeno
);
645 symt
= codeview_parse_one_type(ctp
, typeno
, p
, details
);
646 if (!symt
) FIXME("Couldn't load forward type %x\n", typeno
);
650 static struct symt
* codeview_add_type_pointer(struct codeview_type_parse
* ctp
,
651 struct symt
* existing
,
652 unsigned int pointee_type
)
654 struct symt
* pointee
;
658 existing
= codeview_cast_symt(existing
, SymTagPointerType
);
661 pointee
= codeview_fetch_type(ctp
, pointee_type
, FALSE
);
662 return &symt_new_pointer(ctp
->module
, pointee
, sizeof(void *))->symt
;
665 static struct symt
* codeview_add_type_array(struct codeview_type_parse
* ctp
,
667 unsigned int elemtype
,
668 unsigned int indextype
,
669 unsigned int arr_len
)
671 struct symt
* elem
= codeview_fetch_type(ctp
, elemtype
, FALSE
);
672 struct symt
* index
= codeview_fetch_type(ctp
, indextype
, FALSE
);
674 return &symt_new_array(ctp
->module
, 0, -arr_len
, elem
, index
)->symt
;
677 static BOOL
codeview_add_type_enum_field_list(struct module
* module
,
678 struct symt_enum
* symt
,
679 const union codeview_reftype
* ref_type
)
681 const unsigned char* ptr
= ref_type
->fieldlist
.list
;
682 const unsigned char* last
= (const BYTE
*)ref_type
+ ref_type
->generic
.len
+ 2;
683 const union codeview_fieldtype
* type
;
687 if (*ptr
>= 0xf0) /* LF_PAD... */
693 type
= (const union codeview_fieldtype
*)ptr
;
695 switch (type
->generic
.id
)
697 case LF_ENUMERATE_V1
:
699 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v1
.value
);
700 const struct p_string
* p_name
= (const struct p_string
*)((const unsigned char*)&type
->enumerate_v1
.value
+ vlen
);
702 symt_add_enum_element(module
, symt
, terminate_string(p_name
), value
);
703 ptr
+= 2 + 2 + vlen
+ (1 + p_name
->namelen
);
706 case LF_ENUMERATE_V3
:
708 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v3
.value
);
709 const char* name
= (const char*)&type
->enumerate_v3
.value
+ vlen
;
711 symt_add_enum_element(module
, symt
, name
, value
);
712 ptr
+= 2 + 2 + vlen
+ (1 + strlen(name
));
717 FIXME("Unsupported type %04x in ENUM field list\n", type
->generic
.id
);
724 static void codeview_add_udt_element(struct codeview_type_parse
* ctp
,
725 struct symt_udt
* symt
, const char* name
,
726 int value
, unsigned type
)
728 struct symt
* subtype
;
729 const union codeview_reftype
*cv_type
;
731 if ((cv_type
= codeview_jump_to_type(ctp
, type
)))
733 switch (cv_type
->generic
.id
)
736 symt_add_udt_element(ctp
->module
, symt
, name
,
737 codeview_fetch_type(ctp
, cv_type
->bitfield_v1
.type
, FALSE
),
738 (value
<< 3) + cv_type
->bitfield_v1
.bitoff
,
739 cv_type
->bitfield_v1
.nbits
);
742 symt_add_udt_element(ctp
->module
, symt
, name
,
743 codeview_fetch_type(ctp
, cv_type
->bitfield_v2
.type
, FALSE
),
744 (value
<< 3) + cv_type
->bitfield_v2
.bitoff
,
745 cv_type
->bitfield_v2
.nbits
);
749 subtype
= codeview_fetch_type(ctp
, type
, FALSE
);
753 DWORD64 elem_size
= 0;
754 symt_get_info(ctp
->module
, subtype
, TI_GET_LENGTH
, &elem_size
);
755 symt_add_udt_element(ctp
->module
, symt
, name
, subtype
,
756 value
<< 3, (DWORD
)elem_size
<< 3);
760 static int codeview_add_type_struct_field_list(struct codeview_type_parse
* ctp
,
761 struct symt_udt
* symt
,
762 unsigned fieldlistno
)
764 const unsigned char* ptr
;
765 const unsigned char* last
;
767 const struct p_string
* p_name
;
769 const union codeview_reftype
*type_ref
;
770 const union codeview_fieldtype
* type
;
772 if (!fieldlistno
) return TRUE
;
773 type_ref
= codeview_jump_to_type(ctp
, fieldlistno
);
774 ptr
= type_ref
->fieldlist
.list
;
775 last
= (const BYTE
*)type_ref
+ type_ref
->generic
.len
+ 2;
779 if (*ptr
>= 0xf0) /* LF_PAD... */
785 type
= (const union codeview_fieldtype
*)ptr
;
787 switch (type
->generic
.id
)
790 leaf_len
= numeric_leaf(&value
, &type
->bclass_v1
.offset
);
792 /* FIXME: ignored for now */
794 ptr
+= 2 + 2 + 2 + leaf_len
;
798 leaf_len
= numeric_leaf(&value
, &type
->bclass_v2
.offset
);
800 /* FIXME: ignored for now */
802 ptr
+= 2 + 2 + 4 + leaf_len
;
808 const unsigned short int* p_vboff
;
810 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v1
.vbpoff
);
811 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v1
.vbpoff
+ leaf_len
);
812 vplen
= numeric_leaf(&vpoff
, p_vboff
);
814 /* FIXME: ignored for now */
816 ptr
+= 2 + 2 + 2 + 2 + leaf_len
+ vplen
;
823 const unsigned short int* p_vboff
;
825 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v2
.vbpoff
);
826 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v2
.vbpoff
+ leaf_len
);
827 vplen
= numeric_leaf(&vpoff
, p_vboff
);
829 /* FIXME: ignored for now */
831 ptr
+= 2 + 2 + 4 + 4 + leaf_len
+ vplen
;
836 leaf_len
= numeric_leaf(&value
, &type
->member_v1
.offset
);
837 p_name
= (const struct p_string
*)((const char*)&type
->member_v1
.offset
+ leaf_len
);
839 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
840 type
->member_v1
.type
);
842 ptr
+= 2 + 2 + 2 + leaf_len
+ (1 + p_name
->namelen
);
846 leaf_len
= numeric_leaf(&value
, &type
->member_v2
.offset
);
847 p_name
= (const struct p_string
*)((const unsigned char*)&type
->member_v2
.offset
+ leaf_len
);
849 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
850 type
->member_v2
.type
);
852 ptr
+= 2 + 2 + 4 + leaf_len
+ (1 + p_name
->namelen
);
856 leaf_len
= numeric_leaf(&value
, &type
->member_v3
.offset
);
857 c_name
= (const char*)&type
->member_v3
.offset
+ leaf_len
;
859 codeview_add_udt_element(ctp
, symt
, c_name
, value
, type
->member_v3
.type
);
861 ptr
+= 2 + 2 + 4 + leaf_len
+ (strlen(c_name
) + 1);
865 /* FIXME: ignored for now */
866 ptr
+= 2 + 2 + 2 + (1 + type
->stmember_v1
.p_name
.namelen
);
870 /* FIXME: ignored for now */
871 ptr
+= 2 + 4 + 2 + (1 + type
->stmember_v2
.p_name
.namelen
);
875 /* FIXME: ignored for now */
876 ptr
+= 2 + 4 + 2 + (strlen(type
->stmember_v3
.name
) + 1);
880 /* FIXME: ignored for now */
881 ptr
+= 2 + 2 + 2 + (1 + type
->method_v1
.p_name
.namelen
);
885 /* FIXME: ignored for now */
886 ptr
+= 2 + 2 + 4 + (1 + type
->method_v2
.p_name
.namelen
);
890 /* FIXME: ignored for now */
891 ptr
+= 2 + 2 + 4 + (strlen(type
->method_v3
.name
) + 1);
895 /* FIXME: ignored for now */
896 ptr
+= 2 + 2 + (1 + type
->nesttype_v1
.p_name
.namelen
);
900 /* FIXME: ignored for now */
901 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype_v2
.p_name
.namelen
);
905 /* FIXME: ignored for now */
906 ptr
+= 2 + 2 + 4 + (strlen(type
->nesttype_v3
.name
) + 1);
910 /* FIXME: ignored for now */
915 /* FIXME: ignored for now */
919 case LF_ONEMETHOD_V1
:
920 /* FIXME: ignored for now */
921 switch ((type
->onemethod_v1
.attribute
>> 2) & 7)
923 case 4: case 6: /* (pure) introducing virtual method */
924 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt_v1
.p_name
.namelen
);
928 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod_v1
.p_name
.namelen
);
933 case LF_ONEMETHOD_V2
:
934 /* FIXME: ignored for now */
935 switch ((type
->onemethod_v2
.attribute
>> 2) & 7)
937 case 4: case 6: /* (pure) introducing virtual method */
938 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod_virt_v2
.p_name
.namelen
);
942 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod_v2
.p_name
.namelen
);
947 case LF_ONEMETHOD_V3
:
948 /* FIXME: ignored for now */
949 switch ((type
->onemethod_v3
.attribute
>> 2) & 7)
951 case 4: case 6: /* (pure) introducing virtual method */
952 ptr
+= 2 + 2 + 4 + 4 + (strlen(type
->onemethod_virt_v3
.name
) + 1);
956 ptr
+= 2 + 2 + 4 + (strlen(type
->onemethod_v3
.name
) + 1);
962 if (!codeview_add_type_struct_field_list(ctp
, symt
, type
->index_v1
.ref
))
968 if (!codeview_add_type_struct_field_list(ctp
, symt
, type
->index_v2
.ref
))
974 FIXME("Unsupported type %04x in STRUCT field list\n", type
->generic
.id
);
982 static struct symt
* codeview_add_type_enum(struct codeview_type_parse
* ctp
,
983 struct symt
* existing
,
985 unsigned fieldlistno
,
988 struct symt_enum
* symt
;
992 if (!(symt
= codeview_cast_symt(existing
, SymTagEnum
))) return NULL
;
993 /* should also check that all fields are the same */
997 symt
= symt_new_enum(ctp
->module
, name
,
998 codeview_fetch_type(ctp
, basetype
, FALSE
));
1001 const union codeview_reftype
* fieldlist
;
1002 fieldlist
= codeview_jump_to_type(ctp
, fieldlistno
);
1003 codeview_add_type_enum_field_list(ctp
->module
, symt
, fieldlist
);
1009 static struct symt
* codeview_add_type_struct(struct codeview_type_parse
* ctp
,
1010 struct symt
* existing
,
1011 const char* name
, int structlen
,
1012 enum UdtKind kind
, unsigned property
)
1014 struct symt_udt
* symt
;
1016 /* if we don't have an existing type, try to find one with same name
1017 * FIXME: what to do when several types in different CUs have same name ?
1022 struct symt_ht
* type
;
1023 struct hash_table_iter hti
;
1025 hash_table_iter_init(&ctp
->module
->ht_types
, &hti
, name
);
1026 while ((ptr
= hash_table_iter_up(&hti
)))
1028 type
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
1030 if (type
->symt
.tag
== SymTagUDT
&&
1031 type
->hash_elt
.name
&& !strcmp(type
->hash_elt
.name
, name
))
1033 existing
= &type
->symt
;
1040 if (!(symt
= codeview_cast_symt(existing
, SymTagUDT
))) return NULL
;
1041 /* should also check that all fields are the same */
1042 if (!(property
& 0x80)) /* 0x80 = forward declaration */
1044 if (!symt
->size
) /* likely prior forward declaration, set UDT size */
1045 symt_set_udt_size(ctp
->module
, symt
, structlen
);
1046 else /* different UDT with same name, create a new type */
1050 if (!existing
) symt
= symt_new_udt(ctp
->module
, name
, structlen
, kind
);
1055 static struct symt
* codeview_new_func_signature(struct codeview_type_parse
* ctp
,
1056 struct symt
* existing
,
1057 enum CV_call_e call_conv
)
1059 struct symt_function_signature
* sym
;
1063 sym
= codeview_cast_symt(existing
, SymTagFunctionType
);
1064 if (!sym
) return NULL
;
1068 sym
= symt_new_function_signature(ctp
->module
, NULL
, call_conv
);
1073 static void codeview_add_func_signature_args(struct codeview_type_parse
* ctp
,
1074 struct symt_function_signature
* sym
,
1078 const union codeview_reftype
* reftype
;
1080 sym
->rettype
= codeview_fetch_type(ctp
, ret_type
, FALSE
);
1081 if (args_list
&& (reftype
= codeview_jump_to_type(ctp
, args_list
)))
1084 switch (reftype
->generic
.id
)
1087 for (i
= 0; i
< reftype
->arglist_v1
.num
; i
++)
1088 symt_add_function_signature_parameter(ctp
->module
, sym
,
1089 codeview_fetch_type(ctp
, reftype
->arglist_v1
.args
[i
], FALSE
));
1092 for (i
= 0; i
< reftype
->arglist_v2
.num
; i
++)
1093 symt_add_function_signature_parameter(ctp
->module
, sym
,
1094 codeview_fetch_type(ctp
, reftype
->arglist_v2
.args
[i
], FALSE
));
1097 FIXME("Unexpected leaf %x for signature's pmt\n", reftype
->generic
.id
);
1102 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
1104 const union codeview_type
* type
, BOOL details
)
1107 int value
, leaf_len
;
1108 const struct p_string
* p_name
;
1110 struct symt
* existing
;
1112 existing
= codeview_get_type(curr_type
, TRUE
);
1114 switch (type
->generic
.id
)
1116 case LF_MODIFIER_V1
:
1117 /* FIXME: we don't handle modifiers,
1118 * but read previous type on the curr_type
1120 WARN("Modifier on %x: %s%s%s%s\n",
1121 type
->modifier_v1
.type
,
1122 type
->modifier_v1
.attribute
& 0x01 ? "const " : "",
1123 type
->modifier_v1
.attribute
& 0x02 ? "volatile " : "",
1124 type
->modifier_v1
.attribute
& 0x04 ? "unaligned " : "",
1125 type
->modifier_v1
.attribute
& ~0x07 ? "unknown " : "");
1126 symt
= codeview_fetch_type(ctp
, type
->modifier_v1
.type
, details
);
1128 case LF_MODIFIER_V2
:
1129 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
1130 WARN("Modifier on %x: %s%s%s%s\n",
1131 type
->modifier_v2
.type
,
1132 type
->modifier_v2
.attribute
& 0x01 ? "const " : "",
1133 type
->modifier_v2
.attribute
& 0x02 ? "volatile " : "",
1134 type
->modifier_v2
.attribute
& 0x04 ? "unaligned " : "",
1135 type
->modifier_v2
.attribute
& ~0x07 ? "unknown " : "");
1136 symt
= codeview_fetch_type(ctp
, type
->modifier_v2
.type
, details
);
1140 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v1
.datatype
);
1143 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v2
.datatype
);
1147 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1150 leaf_len
= numeric_leaf(&value
, &type
->array_v1
.arrlen
);
1151 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v1
.arrlen
+ leaf_len
);
1152 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1153 type
->array_v1
.elemtype
,
1154 type
->array_v1
.idxtype
, value
);
1158 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1161 leaf_len
= numeric_leaf(&value
, &type
->array_v2
.arrlen
);
1162 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v2
.arrlen
+ leaf_len
);
1164 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1165 type
->array_v2
.elemtype
,
1166 type
->array_v2
.idxtype
, value
);
1170 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1173 leaf_len
= numeric_leaf(&value
, &type
->array_v3
.arrlen
);
1174 c_name
= (const char*)&type
->array_v3
.arrlen
+ leaf_len
;
1176 symt
= codeview_add_type_array(ctp
, c_name
,
1177 type
->array_v3
.elemtype
,
1178 type
->array_v3
.idxtype
, value
);
1182 case LF_STRUCTURE_V1
:
1184 leaf_len
= numeric_leaf(&value
, &type
->struct_v1
.structlen
);
1185 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v1
.structlen
+ leaf_len
);
1186 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1187 type
->generic
.id
== LF_CLASS_V1
? UdtClass
: UdtStruct
,
1188 type
->struct_v1
.property
);
1191 codeview_add_type(curr_type
, symt
);
1192 if (!(type
->struct_v1
.property
& 0x80)) /* 0x80 = forward declaration */
1193 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1194 type
->struct_v1
.fieldlist
);
1198 case LF_STRUCTURE_V2
:
1200 leaf_len
= numeric_leaf(&value
, &type
->struct_v2
.structlen
);
1201 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v2
.structlen
+ leaf_len
);
1202 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1203 type
->generic
.id
== LF_CLASS_V2
? UdtClass
: UdtStruct
,
1204 type
->struct_v2
.property
);
1207 codeview_add_type(curr_type
, symt
);
1208 if (!(type
->struct_v2
.property
& 0x80)) /* 0x80 = forward declaration */
1209 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1210 type
->struct_v2
.fieldlist
);
1214 case LF_STRUCTURE_V3
:
1216 leaf_len
= numeric_leaf(&value
, &type
->struct_v3
.structlen
);
1217 c_name
= (const char*)&type
->struct_v3
.structlen
+ leaf_len
;
1218 symt
= codeview_add_type_struct(ctp
, existing
, c_name
, value
,
1219 type
->generic
.id
== LF_CLASS_V3
? UdtClass
: UdtStruct
,
1220 type
->struct_v3
.property
);
1223 codeview_add_type(curr_type
, symt
);
1224 if (!(type
->struct_v3
.property
& 0x80)) /* 0x80 = forward declaration */
1225 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1226 type
->struct_v3
.fieldlist
);
1231 leaf_len
= numeric_leaf(&value
, &type
->union_v1
.un_len
);
1232 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v1
.un_len
+ leaf_len
);
1233 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1234 value
, UdtUnion
, type
->union_v1
.property
);
1237 codeview_add_type(curr_type
, symt
);
1238 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1239 type
->union_v1
.fieldlist
);
1244 leaf_len
= numeric_leaf(&value
, &type
->union_v2
.un_len
);
1245 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v2
.un_len
+ leaf_len
);
1246 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1247 value
, UdtUnion
, type
->union_v2
.property
);
1250 codeview_add_type(curr_type
, symt
);
1251 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1252 type
->union_v2
.fieldlist
);
1257 leaf_len
= numeric_leaf(&value
, &type
->union_v3
.un_len
);
1258 c_name
= (const char*)&type
->union_v3
.un_len
+ leaf_len
;
1259 symt
= codeview_add_type_struct(ctp
, existing
, c_name
,
1260 value
, UdtUnion
, type
->union_v3
.property
);
1263 codeview_add_type(curr_type
, symt
);
1264 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1265 type
->union_v3
.fieldlist
);
1270 symt
= codeview_add_type_enum(ctp
, existing
,
1271 terminate_string(&type
->enumeration_v1
.p_name
),
1272 type
->enumeration_v1
.fieldlist
,
1273 type
->enumeration_v1
.type
);
1277 symt
= codeview_add_type_enum(ctp
, existing
,
1278 terminate_string(&type
->enumeration_v2
.p_name
),
1279 type
->enumeration_v2
.fieldlist
,
1280 type
->enumeration_v2
.type
);
1284 symt
= codeview_add_type_enum(ctp
, existing
, type
->enumeration_v3
.name
,
1285 type
->enumeration_v3
.fieldlist
,
1286 type
->enumeration_v3
.type
);
1289 case LF_PROCEDURE_V1
:
1290 symt
= codeview_new_func_signature(ctp
, existing
, type
->procedure_v1
.call
);
1293 codeview_add_type(curr_type
, symt
);
1294 codeview_add_func_signature_args(ctp
,
1295 (struct symt_function_signature
*)symt
,
1296 type
->procedure_v1
.rvtype
,
1297 type
->procedure_v1
.arglist
);
1300 case LF_PROCEDURE_V2
:
1301 symt
= codeview_new_func_signature(ctp
, existing
,type
->procedure_v2
.call
);
1304 codeview_add_type(curr_type
, symt
);
1305 codeview_add_func_signature_args(ctp
,
1306 (struct symt_function_signature
*)symt
,
1307 type
->procedure_v2
.rvtype
,
1308 type
->procedure_v2
.arglist
);
1312 case LF_MFUNCTION_V1
:
1313 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1314 * nor class information, this would just do for now
1316 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v1
.call
);
1319 codeview_add_type(curr_type
, symt
);
1320 codeview_add_func_signature_args(ctp
,
1321 (struct symt_function_signature
*)symt
,
1322 type
->mfunction_v1
.rvtype
,
1323 type
->mfunction_v1
.arglist
);
1326 case LF_MFUNCTION_V2
:
1327 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1328 * nor class information, this would just do for now
1330 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v2
.call
);
1333 codeview_add_type(curr_type
, symt
);
1334 codeview_add_func_signature_args(ctp
,
1335 (struct symt_function_signature
*)symt
,
1336 type
->mfunction_v2
.rvtype
,
1337 type
->mfunction_v2
.arglist
);
1342 /* this is an ugly hack... FIXME when we have C++ support */
1343 if (!(symt
= existing
))
1346 snprintf(buf
, sizeof(buf
), "__internal_vt_shape_%x\n", curr_type
);
1347 symt
= &symt_new_udt(ctp
->module
, buf
, 0, UdtStruct
)->symt
;
1351 FIXME("Unsupported type-id leaf %x\n", type
->generic
.id
);
1352 dump(type
, 2 + type
->generic
.len
);
1355 return codeview_add_type(curr_type
, symt
) ? symt
: NULL
;
1358 static BOOL
codeview_parse_type_table(struct codeview_type_parse
* ctp
)
1360 unsigned int curr_type
= FIRST_DEFINABLE_TYPE
;
1361 const union codeview_type
* type
;
1363 for (curr_type
= FIRST_DEFINABLE_TYPE
; curr_type
< FIRST_DEFINABLE_TYPE
+ ctp
->num
; curr_type
++)
1365 type
= codeview_jump_to_type(ctp
, curr_type
);
1367 /* type records we're interested in are the ones referenced by symbols
1368 * The known ranges are (X mark the ones we want):
1369 * X 0000-0016 for V1 types
1370 * 0200-020c for V1 types referenced by other types
1371 * 0400-040f for V1 types (complex lists & sets)
1372 * X 1000-100f for V2 types
1373 * 1200-120c for V2 types referenced by other types
1374 * 1400-140f for V1 types (complex lists & sets)
1375 * X 1500-150d for V3 types
1376 * 8000-8010 for numeric leafes
1378 if (!(type
->generic
.id
& 0x8600) || (type
->generic
.id
& 0x0100))
1379 codeview_parse_one_type(ctp
, curr_type
, type
, TRUE
);
1385 /*========================================================================
1386 * Process CodeView line number information.
1388 static unsigned long codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1389 unsigned seg
, unsigned offset
);
1391 static void codeview_snarf_linetab(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
,
1392 int size
, BOOL pascal_str
)
1394 const BYTE
* ptr
= linetab
;
1398 const unsigned int* filetab
;
1399 const unsigned int* lt_ptr
;
1400 const unsigned short* linenos
;
1401 const struct startend
* start
;
1403 unsigned long addr
, func_addr0
;
1404 struct symt_function
* func
;
1405 const struct codeview_linetab_block
* ltb
;
1407 nfile
= *(const short*)linetab
;
1408 filetab
= (const unsigned int*)(linetab
+ 2 * sizeof(short));
1410 for (i
= 0; i
< nfile
; i
++)
1412 ptr
= linetab
+ filetab
[i
];
1413 nseg
= *(const short*)ptr
;
1414 lt_ptr
= (const unsigned int*)(ptr
+ 2 * sizeof(short));
1415 start
= (const struct startend
*)(lt_ptr
+ nseg
);
1418 * Now snarf the filename for all of the segments for this file.
1421 source
= source_new(msc_dbg
->module
, NULL
, terminate_string((const struct p_string
*)(start
+ nseg
)));
1423 source
= source_new(msc_dbg
->module
, NULL
, (const char*)(start
+ nseg
));
1425 for (j
= 0; j
< nseg
; j
++)
1427 ltb
= (const struct codeview_linetab_block
*)(linetab
+ *lt_ptr
++);
1428 linenos
= (const unsigned short*)<b
->offsets
[ltb
->num_lines
];
1429 func_addr0
= codeview_get_address(msc_dbg
, ltb
->seg
, start
[j
].start
);
1430 if (!func_addr0
) continue;
1431 for (func
= NULL
, k
= 0; k
< ltb
->num_lines
; k
++)
1433 /* now locate function (if any) */
1434 addr
= func_addr0
+ ltb
->offsets
[k
] - start
[j
].start
;
1435 /* unfortunately, we can have several functions in the same block, if there's no
1436 * gap between them... find the new function if needed
1438 if (!func
|| addr
>= func
->address
+ func
->size
)
1440 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1441 /* FIXME: at least labels support line numbers */
1442 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1444 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1445 ltb
->seg
, ltb
->offsets
[k
], addr
, func
? func
->symt
.tag
: -1);
1450 symt_add_func_line(msc_dbg
->module
, func
, source
,
1451 linenos
[k
], addr
- func
->address
);
1457 static void codeview_snarf_linetab2(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
, DWORD size
,
1458 const char* strimage
, DWORD strsize
)
1462 const struct codeview_linetab2
* lt2
;
1463 const struct codeview_linetab2
* lt2_files
= NULL
;
1464 const struct codeview_lt2blk_lines
* lines_blk
;
1465 const struct codeview_linetab2_file
*fd
;
1467 struct symt_function
* func
;
1469 /* locate LT2_FILES_BLOCK (if any) */
1470 lt2
= (const struct codeview_linetab2
*)linetab
;
1471 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1473 if (lt2
->header
== LT2_FILES_BLOCK
)
1478 lt2
= codeview_linetab2_next_block(lt2
);
1482 TRACE("No LT2_FILES_BLOCK found\n");
1486 lt2
= (const struct codeview_linetab2
*)linetab
;
1487 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1489 /* FIXME: should also check that whole lines_blk fits in linetab + size */
1490 switch (lt2
->header
)
1492 case LT2_LINES_BLOCK
:
1493 /* Skip blocks that are too small - Intel C Compiler generates these. */
1494 if (lt2
->size_of_block
< sizeof (struct codeview_lt2blk_lines
)) break;
1495 lines_blk
= (const struct codeview_lt2blk_lines
*)lt2
;
1496 /* FIXME: should check that file_offset is within the LT2_FILES_BLOCK we've seen */
1497 addr
= codeview_get_address(msc_dbg
, lines_blk
->seg
, lines_blk
->start
);
1498 TRACE("block from %04x:%08x #%x (%x lines)\n",
1499 lines_blk
->seg
, lines_blk
->start
, lines_blk
->size
, lines_blk
->nlines
);
1500 fd
= (const struct codeview_linetab2_file
*)((const char*)lt2_files
+ 8 + lines_blk
->file_offset
);
1501 /* FIXME: should check that string is within strimage + strsize */
1502 source
= source_new(msc_dbg
->module
, NULL
, strimage
+ fd
->offset
);
1503 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1504 /* FIXME: at least labels support line numbers */
1505 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1507 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1508 lines_blk
->seg
, lines_blk
->start
, addr
, func
? func
->symt
.tag
: -1);
1511 for (i
= 0; i
< lines_blk
->nlines
; i
++)
1513 symt_add_func_line(msc_dbg
->module
, func
, source
,
1514 lines_blk
->l
[i
].lineno
^ 0x80000000,
1515 lines_blk
->l
[i
].offset
);
1518 case LT2_FILES_BLOCK
: /* skip */
1521 TRACE("Block end %x\n", lt2
->header
);
1522 lt2
= (const struct codeview_linetab2
*)((const char*)linetab
+ size
);
1525 lt2
= codeview_linetab2_next_block(lt2
);
1529 /*========================================================================
1530 * Process CodeView symbol information.
1533 static unsigned int codeview_map_offset(const struct msc_debug_info
* msc_dbg
,
1534 unsigned int offset
)
1536 int nomap
= msc_dbg
->nomap
;
1537 const OMAP_DATA
* omapp
= msc_dbg
->omapp
;
1540 if (!nomap
|| !omapp
) return offset
;
1542 /* FIXME: use binary search */
1543 for (i
= 0; i
< nomap
- 1; i
++)
1544 if (omapp
[i
].from
<= offset
&& omapp
[i
+1].from
> offset
)
1545 return !omapp
[i
].to
? 0 : omapp
[i
].to
+ (offset
- omapp
[i
].from
);
1550 static unsigned long codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1551 unsigned seg
, unsigned offset
)
1553 int nsect
= msc_dbg
->nsect
;
1554 const IMAGE_SECTION_HEADER
* sectp
= msc_dbg
->sectp
;
1556 if (!seg
|| seg
> nsect
) return 0;
1557 return msc_dbg
->module
->module
.BaseOfImage
+
1558 codeview_map_offset(msc_dbg
, sectp
[seg
-1].VirtualAddress
+ offset
);
1561 static inline void codeview_add_variable(const struct msc_debug_info
* msc_dbg
,
1562 struct symt_compiland
* compiland
,
1564 unsigned segment
, unsigned offset
,
1565 unsigned symtype
, BOOL is_local
, BOOL in_tls
, BOOL force
)
1569 struct location loc
;
1571 loc
.kind
= in_tls
? loc_tlsrel
: loc_absolute
;
1573 loc
.offset
= in_tls
? offset
: codeview_get_address(msc_dbg
, segment
, offset
);
1574 if (force
|| in_tls
|| !symt_find_nearest(msc_dbg
->module
, loc
.offset
))
1576 symt_new_global_variable(msc_dbg
->module
, compiland
,
1577 name
, is_local
, loc
, 0,
1578 codeview_get_type(symtype
, FALSE
));
1583 static BOOL
codeview_snarf(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1584 int offset
, int size
, BOOL do_globals
)
1586 struct symt_function
* curr_func
= NULL
;
1588 struct symt_block
* block
= NULL
;
1590 struct symt_compiland
* compiland
= NULL
;
1591 struct location loc
;
1594 * Loop over the different types of records and whenever we
1595 * find something we are interested in, record it and move on.
1597 for (i
= offset
; i
< size
; i
+= length
)
1599 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1600 length
= sym
->generic
.len
+ 2;
1601 if (i
+ length
> size
) break;
1602 if (!sym
->generic
.id
|| length
< 4) break;
1603 if (length
& 3) FIXME("unpadded len %u\n", length
);
1605 switch (sym
->generic
.id
)
1608 * Global and local data symbols. We don't associate these
1609 * with any given source file.
1614 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
1615 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
1616 sym
->generic
.id
== S_LDATA_V1
, FALSE
, TRUE
);
1621 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
1622 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
1623 sym
->generic
.id
== S_LDATA_V2
, FALSE
, TRUE
);
1628 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
1629 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
1630 sym
->generic
.id
== S_LDATA_V3
, FALSE
, TRUE
);
1633 /* variables with thread storage */
1637 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v1
.p_name
),
1638 sym
->thread_v1
.segment
, sym
->thread_v1
.offset
, sym
->thread_v1
.symtype
,
1639 sym
->generic
.id
== S_LTHREAD_V1
, TRUE
, TRUE
);
1644 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v2
.p_name
),
1645 sym
->thread_v2
.segment
, sym
->thread_v2
.offset
, sym
->thread_v2
.symtype
,
1646 sym
->generic
.id
== S_LTHREAD_V2
, TRUE
, TRUE
);
1651 codeview_add_variable(msc_dbg
, compiland
, sym
->thread_v3
.name
,
1652 sym
->thread_v3
.segment
, sym
->thread_v3
.offset
, sym
->thread_v3
.symtype
,
1653 sym
->generic
.id
== S_LTHREAD_V3
, TRUE
, TRUE
);
1656 /* Public symbols */
1660 case S_PUB_FUNC1_V3
:
1661 case S_PUB_FUNC2_V3
:
1662 /* will be handled later on in codeview_snarf_public */
1666 * Sort of like a global function, but it just points
1667 * to a thunk, which is a stupid name for what amounts to
1668 * a PLT slot in the normal jargon that everyone else uses.
1671 symt_new_thunk(msc_dbg
->module
, compiland
,
1672 terminate_string(&sym
->thunk_v1
.p_name
), sym
->thunk_v1
.thtype
,
1673 codeview_get_address(msc_dbg
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
),
1674 sym
->thunk_v1
.thunk_len
);
1677 symt_new_thunk(msc_dbg
->module
, compiland
,
1678 sym
->thunk_v3
.name
, sym
->thunk_v3
.thtype
,
1679 codeview_get_address(msc_dbg
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
),
1680 sym
->thunk_v3
.thunk_len
);
1684 * Global and static functions.
1688 if (curr_func
) FIXME("nested function\n");
1689 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1690 terminate_string(&sym
->proc_v1
.p_name
),
1691 codeview_get_address(msc_dbg
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
),
1692 sym
->proc_v1
.proc_len
,
1693 codeview_get_type(sym
->proc_v1
.proctype
, FALSE
));
1694 loc
.kind
= loc_absolute
;
1695 loc
.offset
= sym
->proc_v1
.debug_start
;
1696 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1697 loc
.offset
= sym
->proc_v1
.debug_end
;
1698 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1702 if (curr_func
) FIXME("nested function\n");
1703 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1704 terminate_string(&sym
->proc_v2
.p_name
),
1705 codeview_get_address(msc_dbg
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
),
1706 sym
->proc_v2
.proc_len
,
1707 codeview_get_type(sym
->proc_v2
.proctype
, FALSE
));
1708 loc
.kind
= loc_absolute
;
1709 loc
.offset
= sym
->proc_v2
.debug_start
;
1710 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1711 loc
.offset
= sym
->proc_v2
.debug_end
;
1712 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1716 if (curr_func
) FIXME("nested function\n");
1717 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1719 codeview_get_address(msc_dbg
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
),
1720 sym
->proc_v3
.proc_len
,
1721 codeview_get_type(sym
->proc_v3
.proctype
, FALSE
));
1722 loc
.kind
= loc_absolute
;
1723 loc
.offset
= sym
->proc_v3
.debug_start
;
1724 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1725 loc
.offset
= sym
->proc_v3
.debug_end
;
1726 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1729 * Function parameters and stack variables.
1732 loc
.kind
= loc_regrel
;
1733 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1734 loc
.reg
= CV_REG_EBP
;
1735 loc
.offset
= sym
->stack_v1
.offset
;
1736 symt_add_func_local(msc_dbg
->module
, curr_func
,
1737 sym
->stack_v1
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1739 codeview_get_type(sym
->stack_v1
.symtype
, FALSE
),
1740 terminate_string(&sym
->stack_v1
.p_name
));
1743 loc
.kind
= loc_regrel
;
1744 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1745 loc
.reg
= CV_REG_EBP
;
1746 loc
.offset
= sym
->stack_v2
.offset
;
1747 symt_add_func_local(msc_dbg
->module
, curr_func
,
1748 sym
->stack_v2
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1750 codeview_get_type(sym
->stack_v2
.symtype
, FALSE
),
1751 terminate_string(&sym
->stack_v2
.p_name
));
1754 loc
.kind
= loc_regrel
;
1755 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1756 loc
.reg
= CV_REG_EBP
;
1757 loc
.offset
= sym
->stack_v3
.offset
;
1758 symt_add_func_local(msc_dbg
->module
, curr_func
,
1759 sym
->stack_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1761 codeview_get_type(sym
->stack_v3
.symtype
, FALSE
),
1762 sym
->stack_v3
.name
);
1765 loc
.kind
= loc_regrel
;
1766 loc
.reg
= sym
->regrel_v3
.reg
;
1767 loc
.offset
= sym
->regrel_v3
.offset
;
1768 symt_add_func_local(msc_dbg
->module
, curr_func
,
1769 /* FIXME this is wrong !!! */
1770 sym
->regrel_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1772 codeview_get_type(sym
->regrel_v3
.symtype
, FALSE
),
1773 sym
->regrel_v3
.name
);
1777 loc
.kind
= loc_register
;
1778 loc
.reg
= sym
->register_v1
.reg
;
1780 symt_add_func_local(msc_dbg
->module
, curr_func
,
1782 block
, codeview_get_type(sym
->register_v1
.type
, FALSE
),
1783 terminate_string(&sym
->register_v1
.p_name
));
1786 loc
.kind
= loc_register
;
1787 loc
.reg
= sym
->register_v2
.reg
;
1789 symt_add_func_local(msc_dbg
->module
, curr_func
,
1791 block
, codeview_get_type(sym
->register_v2
.type
, FALSE
),
1792 terminate_string(&sym
->register_v2
.p_name
));
1795 loc
.kind
= loc_register
;
1796 loc
.reg
= sym
->register_v3
.reg
;
1798 symt_add_func_local(msc_dbg
->module
, curr_func
,
1800 block
, codeview_get_type(sym
->register_v3
.type
, FALSE
),
1801 sym
->register_v3
.name
);
1805 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1806 codeview_get_address(msc_dbg
, sym
->block_v1
.segment
, sym
->block_v1
.offset
),
1807 sym
->block_v1
.length
);
1810 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1811 codeview_get_address(msc_dbg
, sym
->block_v3
.segment
, sym
->block_v3
.offset
),
1812 sym
->block_v3
.length
);
1818 block
= symt_close_func_block(msc_dbg
->module
, curr_func
, block
, 0);
1822 symt_normalize_function(msc_dbg
->module
, curr_func
);
1827 case S_COMPILAND_V1
:
1828 TRACE("S-Compiland-V1 %x %s\n",
1829 sym
->compiland_v1
.unknown
, terminate_string(&sym
->compiland_v1
.p_name
));
1832 case S_COMPILAND_V2
:
1833 TRACE("S-Compiland-V2 %s\n", terminate_string(&sym
->compiland_v2
.p_name
));
1834 if (TRACE_ON(dbghelp_msc
))
1836 const char* ptr1
= sym
->compiland_v2
.p_name
.name
+ sym
->compiland_v2
.p_name
.namelen
;
1840 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1841 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1842 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1846 case S_COMPILAND_V3
:
1847 TRACE("S-Compiland-V3 %s\n", sym
->compiland_v3
.name
);
1848 if (TRACE_ON(dbghelp_msc
))
1850 const char* ptr1
= sym
->compiland_v3
.name
+ strlen(sym
->compiland_v3
.name
);
1854 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1855 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1856 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1862 TRACE("S-ObjName %s\n", terminate_string(&sym
->objname_v1
.p_name
));
1863 compiland
= symt_new_compiland(msc_dbg
->module
, 0 /* FIXME */,
1864 source_new(msc_dbg
->module
, NULL
,
1865 terminate_string(&sym
->objname_v1
.p_name
)));
1871 loc
.kind
= loc_absolute
;
1872 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
) - curr_func
->address
;
1873 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
, &loc
,
1874 terminate_string(&sym
->label_v1
.p_name
));
1876 else symt_new_label(msc_dbg
->module
, compiland
,
1877 terminate_string(&sym
->label_v1
.p_name
),
1878 codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
));
1883 loc
.kind
= loc_absolute
;
1884 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
) - curr_func
->address
;
1885 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1886 &loc
, sym
->label_v3
.name
);
1888 else symt_new_label(msc_dbg
->module
, compiland
, sym
->label_v3
.name
,
1889 codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
));
1895 const struct p_string
* name
;
1899 vlen
= leaf_as_variant(&v
, &sym
->constant_v1
.cvalue
);
1900 name
= (const struct p_string
*)((const char*)&sym
->constant_v1
.cvalue
+ vlen
);
1901 se
= codeview_get_type(sym
->constant_v1
.type
, FALSE
);
1903 TRACE("S-Constant-V1 %u %s %x\n",
1904 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v1
.type
);
1905 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1912 const struct p_string
* name
;
1916 vlen
= leaf_as_variant(&v
, &sym
->constant_v2
.cvalue
);
1917 name
= (const struct p_string
*)((const char*)&sym
->constant_v2
.cvalue
+ vlen
);
1918 se
= codeview_get_type(sym
->constant_v2
.type
, FALSE
);
1920 TRACE("S-Constant-V2 %u %s %x\n",
1921 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v2
.type
);
1922 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1933 vlen
= leaf_as_variant(&v
, &sym
->constant_v3
.cvalue
);
1934 name
= (const char*)&sym
->constant_v3
.cvalue
+ vlen
;
1935 se
= codeview_get_type(sym
->constant_v3
.type
, FALSE
);
1937 TRACE("S-Constant-V3 %u %s %x\n",
1938 v
.n1
.n2
.n3
.intVal
, name
, sym
->constant_v3
.type
);
1939 /* FIXME: we should add this as a constant value */
1940 symt_new_constant(msc_dbg
->module
, compiland
, name
, se
, &v
);
1945 if (sym
->udt_v1
.type
)
1947 if ((symt
= codeview_get_type(sym
->udt_v1
.type
, FALSE
)))
1948 symt_new_typedef(msc_dbg
->module
, symt
,
1949 terminate_string(&sym
->udt_v1
.p_name
));
1951 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1952 terminate_string(&sym
->udt_v1
.p_name
), sym
->udt_v1
.type
);
1956 if (sym
->udt_v2
.type
)
1958 if ((symt
= codeview_get_type(sym
->udt_v2
.type
, FALSE
)))
1959 symt_new_typedef(msc_dbg
->module
, symt
,
1960 terminate_string(&sym
->udt_v2
.p_name
));
1962 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1963 terminate_string(&sym
->udt_v2
.p_name
), sym
->udt_v2
.type
);
1967 if (sym
->udt_v3
.type
)
1969 if ((symt
= codeview_get_type(sym
->udt_v3
.type
, FALSE
)))
1970 symt_new_typedef(msc_dbg
->module
, symt
, sym
->udt_v3
.name
);
1972 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1973 sym
->udt_v3
.name
, sym
->udt_v3
.type
);
1978 * These are special, in that they are always followed by an
1979 * additional length-prefixed string which is *not* included
1980 * into the symbol length count. We need to skip it.
1988 name
= (const char*)sym
+ length
;
1989 length
+= (*name
+ 1 + 3) & ~3;
1993 case S_MSTOOL_V3
: /* just to silence a few warnings */
1994 case S_MSTOOLINFO_V3
:
1995 case S_MSTOOLENV_V3
:
1999 TRACE("Start search: seg=0x%x at offset 0x%08x\n",
2000 sym
->ssearch_v1
.segment
, sym
->ssearch_v1
.offset
);
2004 TRACE("S-Align V1\n");
2007 /* the symbols we can safely ignore for now */
2009 case S_FRAMEINFO_V2
:
2010 case S_SECUCOOKIE_V3
:
2012 case S_SUBSECTINFO_V3
:
2013 case S_ENTRYPOINT_V3
:
2014 case S_LOCAL_VS2013
:
2015 case S_CALLSITEINFO
:
2016 case S_DEFRANGE_REGISTER
:
2017 case S_DEFRANGE_FRAMEPOINTER_REL
:
2018 case S_DEFRANGE_SUBFIELD_REGISTER
:
2019 case S_FPOFF_VS2013
:
2020 case S_DEFRANGE_REGISTER_REL
:
2023 case S_INLINESITE_END
:
2026 TRACE("Unsupported symbol id %x\n", sym
->generic
.id
);
2030 FIXME("Unsupported symbol id %x\n", sym
->generic
.id
);
2031 dump(sym
, 2 + sym
->generic
.len
);
2036 if (curr_func
) symt_normalize_function(msc_dbg
->module
, curr_func
);
2041 static BOOL
codeview_snarf_public(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
2042 int offset
, int size
)
2046 struct symt_compiland
* compiland
= NULL
;
2049 * Loop over the different types of records and whenever we
2050 * find something we are interested in, record it and move on.
2052 for (i
= offset
; i
< size
; i
+= length
)
2054 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
2055 length
= sym
->generic
.len
+ 2;
2056 if (i
+ length
> size
) break;
2057 if (!sym
->generic
.id
|| length
< 4) break;
2058 if (length
& 3) FIXME("unpadded len %u\n", length
);
2060 switch (sym
->generic
.id
)
2062 case S_PUB_V1
: /* FIXME is this really a 'data_v1' structure ?? */
2063 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2065 symt_new_public(msc_dbg
->module
, compiland
,
2066 terminate_string(&sym
->data_v1
.p_name
),
2067 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
), 1);
2070 case S_PUB_V2
: /* FIXME is this really a 'data_v2' structure ?? */
2071 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2073 symt_new_public(msc_dbg
->module
, compiland
,
2074 terminate_string(&sym
->data_v2
.p_name
),
2075 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
), 1);
2080 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2082 symt_new_public(msc_dbg
->module
, compiland
,
2084 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
), 1);
2087 case S_PUB_FUNC1_V3
:
2088 case S_PUB_FUNC2_V3
: /* using a data_v3 isn't what we'd expect */
2090 /* FIXME: this is plain wrong (from a simple test) */
2091 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2093 symt_new_public(msc_dbg
->module
, compiland
,
2095 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
), 1);
2100 * Global and local data symbols. We don't associate these
2101 * with any given source file.
2105 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
2106 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
2107 sym
->generic
.id
== S_LDATA_V1
, FALSE
, FALSE
);
2111 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
2112 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
2113 sym
->generic
.id
== S_LDATA_V2
, FALSE
, FALSE
);
2117 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
2118 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
2119 sym
->generic
.id
== S_LDATA_V3
, FALSE
, FALSE
);
2122 /* variables with thread storage */
2125 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v1
.p_name
),
2126 sym
->thread_v1
.segment
, sym
->thread_v1
.offset
, sym
->thread_v1
.symtype
,
2127 sym
->generic
.id
== S_LTHREAD_V1
, TRUE
, FALSE
);
2131 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v2
.p_name
),
2132 sym
->thread_v2
.segment
, sym
->thread_v2
.offset
, sym
->thread_v2
.symtype
,
2133 sym
->generic
.id
== S_LTHREAD_V2
, TRUE
, FALSE
);
2137 codeview_add_variable(msc_dbg
, compiland
, sym
->thread_v3
.name
,
2138 sym
->thread_v3
.segment
, sym
->thread_v3
.offset
, sym
->thread_v3
.symtype
,
2139 sym
->generic
.id
== S_LTHREAD_V3
, TRUE
, FALSE
);
2143 * These are special, in that they are always followed by an
2144 * additional length-prefixed string which is *not* included
2145 * into the symbol length count. We need to skip it.
2150 length
+= (((const char*)sym
)[length
] + 1 + 3) & ~3;
2153 msc_dbg
->module
->sortlist_valid
= TRUE
;
2155 msc_dbg
->module
->sortlist_valid
= FALSE
;
2159 /*========================================================================
2163 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
,
2169 if (!size
) return NULL
;
2171 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2172 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2174 for (i
= 0; i
< num_blocks
; i
++)
2175 memcpy(buffer
+ i
* pdb
->block_size
,
2176 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2181 static void* pdb_ds_read(const struct PDB_DS_HEADER
* pdb
, const DWORD
* block_list
,
2187 if (!size
) return NULL
;
2189 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2190 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2192 for (i
= 0; i
< num_blocks
; i
++)
2193 memcpy(buffer
+ i
* pdb
->block_size
,
2194 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2199 static void* pdb_read_jg_file(const struct PDB_JG_HEADER
* pdb
,
2200 const struct PDB_JG_TOC
* toc
, DWORD file_nr
)
2202 const WORD
* block_list
;
2205 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2207 block_list
= (const WORD
*) &toc
->file
[toc
->num_files
];
2208 for (i
= 0; i
< file_nr
; i
++)
2209 block_list
+= (toc
->file
[i
].size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2211 return pdb_jg_read(pdb
, block_list
, toc
->file
[file_nr
].size
);
2214 static void* pdb_read_ds_file(const struct PDB_DS_HEADER
* pdb
,
2215 const struct PDB_DS_TOC
* toc
, DWORD file_nr
)
2217 const DWORD
* block_list
;
2220 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2221 if (toc
->file_size
[file_nr
] == 0 || toc
->file_size
[file_nr
] == 0xFFFFFFFF) return NULL
;
2223 block_list
= &toc
->file_size
[toc
->num_files
];
2224 for (i
= 0; i
< file_nr
; i
++)
2225 block_list
+= (toc
->file_size
[i
] + pdb
->block_size
- 1) / pdb
->block_size
;
2227 return pdb_ds_read(pdb
, block_list
, toc
->file_size
[file_nr
]);
2230 static void* pdb_read_file(const struct pdb_file_info
* pdb_file
,
2233 switch (pdb_file
->kind
)
2236 return pdb_read_jg_file((const struct PDB_JG_HEADER
*)pdb_file
->image
,
2237 pdb_file
->u
.jg
.toc
, file_nr
);
2239 return pdb_read_ds_file((const struct PDB_DS_HEADER
*)pdb_file
->image
,
2240 pdb_file
->u
.ds
.toc
, file_nr
);
2245 static unsigned pdb_get_file_size(const struct pdb_file_info
* pdb_file
, DWORD file_nr
)
2247 switch (pdb_file
->kind
)
2249 case PDB_JG
: return pdb_file
->u
.jg
.toc
->file
[file_nr
].size
;
2250 case PDB_DS
: return pdb_file
->u
.ds
.toc
->file_size
[file_nr
];
2255 static void pdb_free(void* buffer
)
2257 HeapFree(GetProcessHeap(), 0, buffer
);
2260 static void pdb_free_file(struct pdb_file_info
* pdb_file
)
2262 switch (pdb_file
->kind
)
2265 pdb_free(pdb_file
->u
.jg
.toc
);
2266 pdb_file
->u
.jg
.toc
= NULL
;
2269 pdb_free(pdb_file
->u
.ds
.toc
);
2270 pdb_file
->u
.ds
.toc
= NULL
;
2273 HeapFree(GetProcessHeap(), 0, pdb_file
->stream_dict
);
2276 static void pdb_load_stream_name_table(struct pdb_file_info
* pdb_file
, const char* str
, unsigned cb
)
2284 pdw
= (DWORD
*)(str
+ cb
);
2288 pdb_file
->stream_dict
= HeapAlloc(GetProcessHeap(), 0, (numok
+ 1) * sizeof(struct pdb_stream_name
) + cb
);
2289 if (!pdb_file
->stream_dict
) return;
2290 cpstr
= (char*)(pdb_file
->stream_dict
+ numok
+ 1);
2291 memcpy(cpstr
, str
, cb
);
2293 /* bitfield: first dword is len (in dword), then data */
2295 pdw
+= *ok_bits
++ + 1;
2298 FIXME("unexpected value\n");
2302 for (i
= j
= 0; i
< count
; i
++)
2304 if (ok_bits
[i
/ 32] & (1 << (i
% 32)))
2306 if (j
>= numok
) break;
2307 pdb_file
->stream_dict
[j
].name
= &cpstr
[*pdw
++];
2308 pdb_file
->stream_dict
[j
].index
= *pdw
++;
2313 pdb_file
->stream_dict
[numok
].name
= NULL
;
2314 pdb_file
->fpoext_stream
= -1;
2317 static unsigned pdb_get_stream_by_name(const struct pdb_file_info
* pdb_file
, const char* name
)
2319 struct pdb_stream_name
* psn
;
2321 for (psn
= pdb_file
->stream_dict
; psn
&& psn
->name
; psn
++)
2323 if (!strcmp(psn
->name
, name
)) return psn
->index
;
2328 static void* pdb_read_strings(const struct pdb_file_info
* pdb_file
)
2333 idx
= pdb_get_stream_by_name(pdb_file
, "/names");
2336 ret
= pdb_read_file( pdb_file
, idx
);
2337 if (ret
&& *(const DWORD
*)ret
== 0xeffeeffe) return ret
;
2340 WARN("string table not found\n");
2344 static void pdb_module_remove(struct process
* pcsn
, struct module_format
* modfmt
)
2348 for (i
= 0; i
< modfmt
->u
.pdb_info
->used_subfiles
; i
++)
2350 pdb_free_file(&modfmt
->u
.pdb_info
->pdb_files
[i
]);
2351 if (modfmt
->u
.pdb_info
->pdb_files
[i
].image
)
2352 UnmapViewOfFile(modfmt
->u
.pdb_info
->pdb_files
[i
].image
);
2353 if (modfmt
->u
.pdb_info
->pdb_files
[i
].hMap
)
2354 CloseHandle(modfmt
->u
.pdb_info
->pdb_files
[i
].hMap
);
2356 HeapFree(GetProcessHeap(), 0, modfmt
);
2359 static void pdb_convert_types_header(PDB_TYPES
* types
, const BYTE
* image
)
2361 memset(types
, 0, sizeof(PDB_TYPES
));
2364 if (*(const DWORD
*)image
< 19960000) /* FIXME: correct version? */
2366 /* Old version of the types record header */
2367 const PDB_TYPES_OLD
* old
= (const PDB_TYPES_OLD
*)image
;
2368 types
->version
= old
->version
;
2369 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
2370 types
->type_size
= old
->type_size
;
2371 types
->first_index
= old
->first_index
;
2372 types
->last_index
= old
->last_index
;
2373 types
->file
= old
->file
;
2377 /* New version of the types record header */
2378 *types
= *(const PDB_TYPES
*)image
;
2382 static void pdb_convert_symbols_header(PDB_SYMBOLS
* symbols
,
2383 int* header_size
, const BYTE
* image
)
2385 memset(symbols
, 0, sizeof(PDB_SYMBOLS
));
2388 if (*(const DWORD
*)image
!= 0xffffffff)
2390 /* Old version of the symbols record header */
2391 const PDB_SYMBOLS_OLD
* old
= (const PDB_SYMBOLS_OLD
*)image
;
2392 symbols
->version
= 0;
2393 symbols
->module_size
= old
->module_size
;
2394 symbols
->offset_size
= old
->offset_size
;
2395 symbols
->hash_size
= old
->hash_size
;
2396 symbols
->srcmodule_size
= old
->srcmodule_size
;
2397 symbols
->pdbimport_size
= 0;
2398 symbols
->hash1_file
= old
->hash1_file
;
2399 symbols
->hash2_file
= old
->hash2_file
;
2400 symbols
->gsym_file
= old
->gsym_file
;
2402 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
2406 /* New version of the symbols record header */
2407 *symbols
= *(const PDB_SYMBOLS
*)image
;
2408 *header_size
= sizeof(PDB_SYMBOLS
);
2412 static void pdb_convert_symbol_file(const PDB_SYMBOLS
* symbols
,
2413 PDB_SYMBOL_FILE_EX
* sfile
,
2414 unsigned* size
, const void* image
)
2417 if (symbols
->version
< 19970000)
2419 const PDB_SYMBOL_FILE
*sym_file
= image
;
2420 memset(sfile
, 0, sizeof(*sfile
));
2421 sfile
->file
= sym_file
->file
;
2422 sfile
->range
.index
= sym_file
->range
.index
;
2423 sfile
->symbol_size
= sym_file
->symbol_size
;
2424 sfile
->lineno_size
= sym_file
->lineno_size
;
2425 *size
= sizeof(PDB_SYMBOL_FILE
) - 1;
2429 memcpy(sfile
, image
, sizeof(PDB_SYMBOL_FILE_EX
));
2430 *size
= sizeof(PDB_SYMBOL_FILE_EX
) - 1;
2434 static HANDLE
map_pdb_file(const struct process
* pcs
,
2435 const struct pdb_lookup
* lookup
,
2436 struct module
* module
)
2438 HANDLE hFile
, hMap
= NULL
;
2439 char dbg_file_path
[MAX_PATH
];
2442 switch (lookup
->kind
)
2445 ret
= path_find_symbol_file(pcs
, lookup
->filename
, NULL
, lookup
->timestamp
,
2446 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2449 ret
= path_find_symbol_file(pcs
, lookup
->filename
, &lookup
->guid
, 0,
2450 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2455 WARN("\tCouldn't find %s\n", lookup
->filename
);
2458 if ((hFile
= CreateFileA(dbg_file_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2459 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) != INVALID_HANDLE_VALUE
)
2461 hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
2467 static void pdb_process_types(const struct msc_debug_info
* msc_dbg
,
2468 const struct pdb_file_info
* pdb_file
)
2470 BYTE
* types_image
= NULL
;
2472 types_image
= pdb_read_file(pdb_file
, 2);
2476 struct codeview_type_parse ctp
;
2481 pdb_convert_types_header(&types
, types_image
);
2483 /* Check for unknown versions */
2484 switch (types
.version
)
2486 case 19950410: /* VC 4.0 */
2488 case 19961031: /* VC 5.0 / 6.0 */
2489 case 19990903: /* VC 7.0 */
2490 case 20040203: /* VC 8.0 */
2493 ERR("-Unknown type info version %d\n", types
.version
);
2496 ctp
.module
= msc_dbg
->module
;
2497 /* reconstruct the types offset...
2498 * FIXME: maybe it's present in the newest PDB_TYPES structures
2500 total
= types
.last_index
- types
.first_index
+ 1;
2501 offset
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD
) * total
);
2502 ctp
.table
= ptr
= types_image
+ types
.type_offset
;
2504 while (ptr
< ctp
.table
+ types
.type_size
&& ctp
.num
< total
)
2506 offset
[ctp
.num
++] = ptr
- ctp
.table
;
2507 ptr
+= ((const union codeview_type
*)ptr
)->generic
.len
+ 2;
2509 ctp
.offset
= offset
;
2511 /* Read type table */
2512 codeview_parse_type_table(&ctp
);
2513 HeapFree(GetProcessHeap(), 0, offset
);
2514 pdb_free(types_image
);
2518 static const char PDB_JG_IDENT
[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
2519 static const char PDB_DS_IDENT
[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
2521 /******************************************************************
2524 * Tries to load a pdb file
2525 * 'matched' is filled with the number of correct matches for this file:
2526 * - age counts for one
2527 * - timestamp or guid depending on kind counts for one
2528 * a wrong kind of file returns FALSE (FIXME ?)
2530 static BOOL
pdb_init(const struct pdb_lookup
* pdb_lookup
, struct pdb_file_info
* pdb_file
,
2531 const char* image
, unsigned* matched
)
2535 /* check the file header, and if ok, load the TOC */
2536 TRACE("PDB(%s): %.40s\n", pdb_lookup
->filename
, debugstr_an(image
, 40));
2539 if (!memcmp(image
, PDB_JG_IDENT
, sizeof(PDB_JG_IDENT
)))
2541 const struct PDB_JG_HEADER
* pdb
= (const struct PDB_JG_HEADER
*)image
;
2542 struct PDB_JG_ROOT
* root
;
2544 pdb_file
->u
.jg
.toc
= pdb_jg_read(pdb
, pdb
->toc_block
, pdb
->toc
.size
);
2545 root
= pdb_read_jg_file(pdb
, pdb_file
->u
.jg
.toc
, 1);
2548 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2551 switch (root
->Version
)
2553 case 19950623: /* VC 4.0 */
2555 case 19960307: /* VC 5.0 */
2556 case 19970604: /* VC 6.0 */
2559 ERR("-Unknown root block version %d\n", root
->Version
);
2561 if (pdb_lookup
->kind
!= PDB_JG
)
2563 WARN("Found %s, but wrong PDB kind\n", pdb_lookup
->filename
);
2567 pdb_file
->kind
= PDB_JG
;
2568 pdb_file
->u
.jg
.timestamp
= root
->TimeDateStamp
;
2569 pdb_file
->age
= root
->Age
;
2570 if (root
->TimeDateStamp
== pdb_lookup
->timestamp
) (*matched
)++;
2571 else WARN("Found %s, but wrong signature: %08x %08x\n",
2572 pdb_lookup
->filename
, root
->TimeDateStamp
, pdb_lookup
->timestamp
);
2573 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2574 else WARN("Found %s, but wrong age: %08x %08x\n",
2575 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2576 TRACE("found JG for %s: age=%x timestamp=%x\n",
2577 pdb_lookup
->filename
, root
->Age
, root
->TimeDateStamp
);
2578 pdb_load_stream_name_table(pdb_file
, &root
->names
[0], root
->cbNames
);
2582 else if (!memcmp(image
, PDB_DS_IDENT
, sizeof(PDB_DS_IDENT
)))
2584 const struct PDB_DS_HEADER
* pdb
= (const struct PDB_DS_HEADER
*)image
;
2585 struct PDB_DS_ROOT
* root
;
2587 pdb_file
->u
.ds
.toc
=
2589 (const DWORD
*)((const char*)pdb
+ pdb
->toc_page
* pdb
->block_size
),
2591 root
= pdb_read_ds_file(pdb
, pdb_file
->u
.ds
.toc
, 1);
2594 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2597 switch (root
->Version
)
2602 ERR("-Unknown root block version %d\n", root
->Version
);
2604 pdb_file
->kind
= PDB_DS
;
2605 pdb_file
->u
.ds
.guid
= root
->guid
;
2606 pdb_file
->age
= root
->Age
;
2607 if (!memcmp(&root
->guid
, &pdb_lookup
->guid
, sizeof(GUID
))) (*matched
)++;
2608 else WARN("Found %s, but wrong GUID: %s %s\n",
2609 pdb_lookup
->filename
, debugstr_guid(&root
->guid
),
2610 debugstr_guid(&pdb_lookup
->guid
));
2611 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2612 else WARN("Found %s, but wrong age: %08x %08x\n",
2613 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2614 TRACE("found DS for %s: age=%x guid=%s\n",
2615 pdb_lookup
->filename
, root
->Age
, debugstr_guid(&root
->guid
));
2616 pdb_load_stream_name_table(pdb_file
, &root
->names
[0], root
->cbNames
);
2621 if (0) /* some tool to dump the internal files from a PDB file */
2625 switch (pdb_file
->kind
)
2627 case PDB_JG
: num_files
= pdb_file
->u
.jg
.toc
->num_files
; break;
2628 case PDB_DS
: num_files
= pdb_file
->u
.ds
.toc
->num_files
; break;
2631 for (i
= 1; i
< num_files
; i
++)
2633 unsigned char* x
= pdb_read_file(pdb_file
, i
);
2634 FIXME("********************** [%u]: size=%08x\n",
2635 i
, pdb_get_file_size(pdb_file
, i
));
2636 dump(x
, pdb_get_file_size(pdb_file
, i
));
2643 static BOOL
pdb_process_internal(const struct process
* pcs
,
2644 const struct msc_debug_info
* msc_dbg
,
2645 const struct pdb_lookup
* pdb_lookup
,
2646 struct pdb_module_info
* pdb_module_info
,
2647 unsigned module_index
);
2649 static void pdb_process_symbol_imports(const struct process
* pcs
,
2650 const struct msc_debug_info
* msc_dbg
,
2651 const PDB_SYMBOLS
* symbols
,
2652 const void* symbols_image
,
2654 const struct pdb_lookup
* pdb_lookup
,
2655 struct pdb_module_info
* pdb_module_info
,
2656 unsigned module_index
)
2658 if (module_index
== -1 && symbols
&& symbols
->pdbimport_size
)
2660 const PDB_SYMBOL_IMPORT
*imp
;
2665 struct pdb_file_info sf0
= pdb_module_info
->pdb_files
[0];
2667 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2668 symbols
->module_size
+ symbols
->offset_size
+
2669 symbols
->hash_size
+ symbols
->srcmodule_size
);
2671 last
= (const char*)imp
+ symbols
->pdbimport_size
;
2672 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
2674 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
2675 if (i
>= CV_MAX_MODULES
) FIXME("Out of bounds!!!\n");
2676 if (!strcasecmp(pdb_lookup
->filename
, imp
->filename
))
2678 if (module_index
!= -1) FIXME("Twice the entry\n");
2679 else module_index
= i
;
2680 pdb_module_info
->pdb_files
[i
] = sf0
;
2684 struct pdb_lookup imp_pdb_lookup
;
2686 /* FIXME: this is an import of a JG PDB file
2687 * how's a DS PDB handled ?
2689 imp_pdb_lookup
.filename
= imp
->filename
;
2690 imp_pdb_lookup
.kind
= PDB_JG
;
2691 imp_pdb_lookup
.timestamp
= imp
->TimeDateStamp
;
2692 imp_pdb_lookup
.age
= imp
->Age
;
2693 TRACE("got for %s: age=%u ts=%x\n",
2694 imp
->filename
, imp
->Age
, imp
->TimeDateStamp
);
2695 pdb_process_internal(pcs
, msc_dbg
, &imp_pdb_lookup
, pdb_module_info
, i
);
2698 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)first
+ ((ptr
- (const char*)first
+ strlen(ptr
) + 1 + 3) & ~3));
2700 pdb_module_info
->used_subfiles
= i
;
2702 if (module_index
== -1)
2705 pdb_module_info
->used_subfiles
= 1;
2707 cv_current_module
= &cv_zmodules
[module_index
];
2708 if (cv_current_module
->allowed
) FIXME("Already allowed??\n");
2709 cv_current_module
->allowed
= TRUE
;
2712 static BOOL
pdb_process_internal(const struct process
* pcs
,
2713 const struct msc_debug_info
* msc_dbg
,
2714 const struct pdb_lookup
* pdb_lookup
,
2715 struct pdb_module_info
* pdb_module_info
,
2716 unsigned module_index
)
2720 BYTE
* symbols_image
= NULL
;
2721 char* files_image
= NULL
;
2722 DWORD files_size
= 0;
2724 struct pdb_file_info
* pdb_file
;
2726 TRACE("Processing PDB file %s\n", pdb_lookup
->filename
);
2728 pdb_file
= &pdb_module_info
->pdb_files
[module_index
== -1 ? 0 : module_index
];
2729 /* Open and map() .PDB file */
2730 if ((hMap
= map_pdb_file(pcs
, pdb_lookup
, msc_dbg
->module
)) == NULL
||
2731 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2733 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2737 if (!pdb_init(pdb_lookup
, pdb_file
, image
, &matched
) || matched
!= 2)
2740 UnmapViewOfFile(image
);
2744 pdb_file
->hMap
= hMap
;
2745 pdb_file
->image
= image
;
2746 symbols_image
= pdb_read_file(pdb_file
, 3);
2749 PDB_SYMBOLS symbols
;
2753 int header_size
= 0;
2754 PDB_STREAM_INDEXES
* psi
;
2756 pdb_convert_symbols_header(&symbols
, &header_size
, symbols_image
);
2757 switch (symbols
.version
)
2759 case 0: /* VC 4.0 */
2760 case 19960307: /* VC 5.0 */
2761 case 19970606: /* VC 6.0 */
2765 ERR("-Unknown symbol info version %d %08x\n",
2766 symbols
.version
, symbols
.version
);
2769 switch (symbols
.stream_index_size
)
2772 case sizeof(PDB_STREAM_INDEXES_OLD
):
2773 /* no fpo ext stream in this case */
2775 case sizeof(PDB_STREAM_INDEXES
):
2776 psi
= (PDB_STREAM_INDEXES
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2777 symbols
.module_size
+ symbols
.offset_size
+
2778 symbols
.hash_size
+ symbols
.srcmodule_size
+
2779 symbols
.pdbimport_size
+ symbols
.unknown2_size
);
2780 pdb_file
->fpoext_stream
= psi
->FPO_EXT
;
2783 FIXME("Unknown PDB_STREAM_INDEXES size (%d)\n", symbols
.stream_index_size
);
2786 files_image
= pdb_read_strings(pdb_file
);
2787 if (files_image
) files_size
= *(const DWORD
*)(files_image
+ 8);
2789 pdb_process_symbol_imports(pcs
, msc_dbg
, &symbols
, symbols_image
, image
,
2790 pdb_lookup
, pdb_module_info
, module_index
);
2791 pdb_process_types(msc_dbg
, pdb_file
);
2793 /* Read global symbol table */
2794 globalimage
= pdb_read_file(pdb_file
, symbols
.gsym_file
);
2797 codeview_snarf(msc_dbg
, globalimage
, 0,
2798 pdb_get_file_size(pdb_file
, symbols
.gsym_file
), FALSE
);
2801 /* Read per-module symbols' tables */
2802 file
= symbols_image
+ header_size
;
2803 while (file
- symbols_image
< header_size
+ symbols
.module_size
)
2805 PDB_SYMBOL_FILE_EX sfile
;
2806 const char* file_name
;
2809 HeapValidate(GetProcessHeap(), 0, NULL
);
2810 pdb_convert_symbol_file(&symbols
, &sfile
, &size
, file
);
2812 modimage
= pdb_read_file(pdb_file
, sfile
.file
);
2815 if (sfile
.symbol_size
)
2816 codeview_snarf(msc_dbg
, modimage
, sizeof(DWORD
),
2817 sfile
.symbol_size
, TRUE
);
2819 if (sfile
.lineno_size
)
2820 codeview_snarf_linetab(msc_dbg
,
2821 modimage
+ sfile
.symbol_size
,
2823 pdb_file
->kind
== PDB_JG
);
2825 codeview_snarf_linetab2(msc_dbg
, modimage
+ sfile
.symbol_size
+ sfile
.lineno_size
,
2826 pdb_get_file_size(pdb_file
, sfile
.file
) - sfile
.symbol_size
- sfile
.lineno_size
,
2827 files_image
+ 12, files_size
);
2831 file_name
= (const char*)file
+ size
;
2832 file_name
+= strlen(file_name
) + 1;
2833 file
= (BYTE
*)((DWORD_PTR
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3);
2835 /* finish the remaining public and global information */
2838 codeview_snarf_public(msc_dbg
, globalimage
, 0,
2839 pdb_get_file_size(pdb_file
, symbols
.gsym_file
));
2840 pdb_free(globalimage
);
2844 pdb_process_symbol_imports(pcs
, msc_dbg
, NULL
, NULL
, image
,
2845 pdb_lookup
, pdb_module_info
, module_index
);
2847 pdb_free(symbols_image
);
2848 pdb_free(files_image
);
2853 static BOOL
pdb_process_file(const struct process
* pcs
,
2854 const struct msc_debug_info
* msc_dbg
,
2855 struct pdb_lookup
* pdb_lookup
)
2858 struct module_format
* modfmt
;
2859 struct pdb_module_info
* pdb_module_info
;
2861 modfmt
= HeapAlloc(GetProcessHeap(), 0,
2862 sizeof(struct module_format
) + sizeof(struct pdb_module_info
));
2863 if (!modfmt
) return FALSE
;
2865 pdb_module_info
= (void*)(modfmt
+ 1);
2866 msc_dbg
->module
->format_info
[DFI_PDB
] = modfmt
;
2867 modfmt
->module
= msc_dbg
->module
;
2868 modfmt
->remove
= pdb_module_remove
;
2869 modfmt
->loc_compute
= NULL
;
2870 modfmt
->u
.pdb_info
= pdb_module_info
;
2872 memset(cv_zmodules
, 0, sizeof(cv_zmodules
));
2873 codeview_init_basic_types(msc_dbg
->module
);
2874 ret
= pdb_process_internal(pcs
, msc_dbg
, pdb_lookup
,
2875 msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
, -1);
2876 codeview_clear_type_table();
2879 struct pdb_module_info
* pdb_info
= msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
;
2880 msc_dbg
->module
->module
.SymType
= SymCv
;
2881 if (pdb_info
->pdb_files
[0].kind
== PDB_JG
)
2882 msc_dbg
->module
->module
.PdbSig
= pdb_info
->pdb_files
[0].u
.jg
.timestamp
;
2884 msc_dbg
->module
->module
.PdbSig70
= pdb_info
->pdb_files
[0].u
.ds
.guid
;
2885 msc_dbg
->module
->module
.PdbAge
= pdb_info
->pdb_files
[0].age
;
2886 MultiByteToWideChar(CP_ACP
, 0, pdb_lookup
->filename
, -1,
2887 msc_dbg
->module
->module
.LoadedPdbName
,
2888 sizeof(msc_dbg
->module
->module
.LoadedPdbName
) / sizeof(WCHAR
));
2889 /* FIXME: we could have a finer grain here */
2890 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
2891 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
2892 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
2893 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
2894 msc_dbg
->module
->module
.Publics
= TRUE
;
2898 msc_dbg
->module
->format_info
[DFI_PDB
] = NULL
;
2899 HeapFree(GetProcessHeap(), 0, modfmt
);
2904 BOOL
pdb_fetch_file_info(const struct pdb_lookup
* pdb_lookup
, unsigned* matched
)
2906 HANDLE hFile
, hMap
= NULL
;
2909 struct pdb_file_info pdb_file
;
2911 if ((hFile
= CreateFileA(pdb_lookup
->filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2912 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) == INVALID_HANDLE_VALUE
||
2913 ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
2914 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2916 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2921 ret
= pdb_init(pdb_lookup
, &pdb_file
, image
, matched
);
2922 pdb_free_file(&pdb_file
);
2925 if (image
) UnmapViewOfFile(image
);
2926 if (hMap
) CloseHandle(hMap
);
2927 if (hFile
!= INVALID_HANDLE_VALUE
) CloseHandle(hFile
);
2932 /*========================================================================
2933 * FPO unwinding code
2936 /* Stack unwinding is based on postfixed operations.
2937 * Let's define our Postfix EValuator
2939 #define PEV_MAX_LEN 32
2942 struct cpu_stack_walk
* csw
;
2944 struct vector stack
;
2946 struct hash_table values
;
2953 struct hash_table_elt elt
;
2956 #define PEV_ERROR(pev, msg) snprintf((pev)->error, sizeof((pev)->error), "%s", (msg))
2957 #define PEV_ERROR1(pev, msg, pmt) snprintf((pev)->error, sizeof((pev)->error), (msg), (pmt))
2960 static void pev_dump_stack(struct pevaluator
* pev
)
2963 FIXME("stack #%d\n", pev
->stk_index
);
2964 for (i
= 0; i
< pev
->stk_index
; i
++)
2966 FIXME("\t%d) %s\n", i
, *(char**)vector_at(&pev
->stack
, i
));
2971 /* get the value out of an operand (variable or literal) */
2972 static BOOL
pev_get_val(struct pevaluator
* pev
, const char* str
, DWORD_PTR
* val
)
2975 struct hash_table_iter hti
;
2982 hash_table_iter_init(&pev
->values
, &hti
, str
);
2983 while ((ptr
= hash_table_iter_up(&hti
)))
2985 if (!strcmp(GET_ENTRY(ptr
, struct zvalue
, elt
)->elt
.name
, str
))
2987 *val
= GET_ENTRY(ptr
, struct zvalue
, elt
)->value
;
2991 return PEV_ERROR1(pev
, "get_zvalue: no value found (%s)", str
);
2993 *val
= strtol(str
, &n
, 10);
2994 if (n
== str
|| *n
!= '\0')
2995 return PEV_ERROR1(pev
, "get_val: not a literal (%s)", str
);
3000 /* push an operand onto the stack */
3001 static BOOL
pev_push(struct pevaluator
* pev
, const char* elt
)
3004 if (pev
->stk_index
< vector_length(&pev
->stack
))
3005 at
= vector_at(&pev
->stack
, pev
->stk_index
);
3007 at
= vector_add(&pev
->stack
, &pev
->pool
);
3008 if (!at
) return PEV_ERROR(pev
, "push: out of memory");
3009 *at
= pool_strdup(&pev
->pool
, elt
);
3014 /* pop an operand from the stack */
3015 static BOOL
pev_pop(struct pevaluator
* pev
, char* elt
)
3017 char** at
= vector_at(&pev
->stack
, --pev
->stk_index
);
3018 if (!at
) return PEV_ERROR(pev
, "pop: stack empty");
3023 /* pop an operand from the stack, and gets its value */
3024 static BOOL
pev_pop_val(struct pevaluator
* pev
, DWORD_PTR
* val
)
3026 char p
[PEV_MAX_LEN
];
3028 return pev_pop(pev
, p
) && pev_get_val(pev
, p
, val
);
3031 /* set var 'name' a new value (creates the var if it doesn't exist) */
3032 static BOOL
pev_set_value(struct pevaluator
* pev
, const char* name
, DWORD_PTR val
)
3034 struct hash_table_iter hti
;
3037 hash_table_iter_init(&pev
->values
, &hti
, name
);
3038 while ((ptr
= hash_table_iter_up(&hti
)))
3040 if (!strcmp(GET_ENTRY(ptr
, struct zvalue
, elt
)->elt
.name
, name
))
3042 GET_ENTRY(ptr
, struct zvalue
, elt
)->value
= val
;
3048 struct zvalue
* zv
= pool_alloc(&pev
->pool
, sizeof(*zv
));
3049 if (!zv
) return PEV_ERROR(pev
, "set_value: out of memory");
3052 zv
->elt
.name
= pool_strdup(&pev
->pool
, name
);
3053 hash_table_add(&pev
->values
, &zv
->elt
);
3058 /* execute a binary operand from the two top most values on the stack.
3059 * puts result on top of the stack */
3060 static BOOL
pev_binop(struct pevaluator
* pev
, char op
)
3062 char res
[PEV_MAX_LEN
];
3063 DWORD_PTR v1
, v2
, c
;
3065 if (!pev_pop_val(pev
, &v1
) || !pev_pop_val(pev
, &v2
)) return FALSE
;
3068 case '+': c
= v1
+ v2
; break;
3069 case '-': c
= v1
- v2
; break;
3070 case '*': c
= v1
* v2
; break;
3071 case '/': c
= v1
/ v2
; break;
3072 case '%': c
= v1
% v2
; break;
3073 default: return PEV_ERROR1(pev
, "binop: unknown op (%c)", op
);
3075 snprintf(res
, sizeof(res
), "%ld", c
);
3080 /* pops top most operand, dereference it, on pushes the result on top of the stack */
3081 static BOOL
pev_deref(struct pevaluator
* pev
)
3083 char res
[PEV_MAX_LEN
];
3086 if (!pev_pop_val(pev
, &v1
)) return FALSE
;
3087 if (!sw_read_mem(pev
->csw
, v1
, &v2
, sizeof(v2
)))
3088 return PEV_ERROR1(pev
, "deref: cannot read mem at %lx\n", v1
);
3089 snprintf(res
, sizeof(res
), "%ld", v2
);
3094 /* assign value to variable (from two top most operands) */
3095 static BOOL
pev_assign(struct pevaluator
* pev
)
3097 char p2
[PEV_MAX_LEN
];
3100 if (!pev_pop_val(pev
, &v1
) || !pev_pop(pev
, p2
)) return FALSE
;
3101 if (p2
[0] != '$') return PEV_ERROR1(pev
, "assign: %s isn't a variable", p2
);
3102 pev_set_value(pev
, p2
, v1
);
3107 /* initializes the postfix evaluator */
3108 static void pev_init(struct pevaluator
* pev
, struct cpu_stack_walk
* csw
,
3109 PDB_FPO_DATA
* fpoext
, struct pdb_cmd_pair
* cpair
)
3112 pool_init(&pev
->pool
, 512);
3113 vector_init(&pev
->stack
, sizeof(char*), 8);
3115 hash_table_init(&pev
->pool
, &pev
->values
, 8);
3116 pev
->error
[0] = '\0';
3117 for (; cpair
->name
; cpair
++)
3118 pev_set_value(pev
, cpair
->name
, *cpair
->pvalue
);
3119 pev_set_value(pev
, ".raSearchStart", fpoext
->start
);
3120 pev_set_value(pev
, ".cbLocals", fpoext
->locals_size
);
3121 pev_set_value(pev
, ".cbParams", fpoext
->params_size
);
3122 pev_set_value(pev
, ".cbSavedRegs", fpoext
->savedregs_size
);
3125 static BOOL
pev_free(struct pevaluator
* pev
, struct pdb_cmd_pair
* cpair
)
3129 if (cpair
) for (; cpair
->name
; cpair
++)
3131 if (pev_get_val(pev
, cpair
->name
, &val
))
3132 *cpair
->pvalue
= val
;
3134 pool_destroy(&pev
->pool
);
3138 static BOOL
pdb_parse_cmd_string(struct cpu_stack_walk
* csw
, PDB_FPO_DATA
* fpoext
,
3139 const char* cmd
, struct pdb_cmd_pair
* cpair
)
3141 char token
[PEV_MAX_LEN
];
3145 struct pevaluator pev
;
3147 pev_init(&pev
, csw
, fpoext
, cpair
);
3148 for (ptr
= cmd
; !over
; ptr
++)
3150 if (*ptr
== ' ' || (over
= *ptr
== '\0'))
3154 if (!strcmp(token
, "+") || !strcmp(token
, "-") || !strcmp(token
, "*") ||
3155 !strcmp(token
, "/") || !strcmp(token
, "%"))
3157 if (!pev_binop(&pev
, token
[0])) goto done
;
3159 else if (!strcmp(token
, "^"))
3161 if (!pev_deref(&pev
)) goto done
;
3163 else if (!strcmp(token
, "="))
3165 if (!pev_assign(&pev
)) goto done
;
3169 if (!pev_push(&pev
, token
)) goto done
;
3175 if (ptok
- token
>= PEV_MAX_LEN
- 1)
3177 PEV_ERROR1(&pev
, "parse: token too long (%s)", ptr
- (ptok
- token
));
3183 pev_free(&pev
, cpair
);
3186 FIXME("Couldn't evaluate %s => %s\n", wine_dbgstr_a(cmd
), pev
.error
);
3187 pev_free(&pev
, NULL
);
3191 BOOL
pdb_virtual_unwind(struct cpu_stack_walk
* csw
, DWORD_PTR ip
,
3192 CONTEXT
* context
, struct pdb_cmd_pair
* cpair
)
3194 struct module_pair pair
;
3195 struct pdb_module_info
* pdb_info
;
3196 PDB_FPO_DATA
* fpoext
;
3197 unsigned i
, size
, strsize
;
3201 if (!(pair
.pcs
= process_find_by_handle(csw
->hProcess
)) ||
3202 !(pair
.requested
= module_find_by_addr(pair
.pcs
, ip
, DMT_UNKNOWN
)) ||
3203 !module_get_debug(&pair
))
3205 if (!pair
.effective
->format_info
[DFI_PDB
]) return FALSE
;
3206 pdb_info
= pair
.effective
->format_info
[DFI_PDB
]->u
.pdb_info
;
3207 TRACE("searching %lx => %lx\n", ip
, ip
- (DWORD_PTR
)pair
.effective
->module
.BaseOfImage
);
3208 ip
-= (DWORD_PTR
)pair
.effective
->module
.BaseOfImage
;
3210 strbase
= pdb_read_strings(&pdb_info
->pdb_files
[0]);
3211 if (!strbase
) return FALSE
;
3212 strsize
= *(const DWORD
*)(strbase
+ 8);
3213 fpoext
= pdb_read_file(&pdb_info
->pdb_files
[0], pdb_info
->pdb_files
[0].fpoext_stream
);
3214 size
= pdb_get_file_size(&pdb_info
->pdb_files
[0], pdb_info
->pdb_files
[0].fpoext_stream
);
3215 if (fpoext
&& (size
% sizeof(*fpoext
)) == 0)
3217 size
/= sizeof(*fpoext
);
3218 for (i
= 0; i
< size
; i
++)
3220 if (fpoext
[i
].start
<= ip
&& ip
< fpoext
[i
].start
+ fpoext
[i
].func_size
)
3222 TRACE("\t%08x %08x %8x %8x %4x %4x %4x %08x %s\n",
3223 fpoext
[i
].start
, fpoext
[i
].func_size
, fpoext
[i
].locals_size
,
3224 fpoext
[i
].params_size
, fpoext
[i
].maxstack_size
, fpoext
[i
].prolog_size
,
3225 fpoext
[i
].savedregs_size
, fpoext
[i
].flags
,
3226 fpoext
[i
].str_offset
< strsize
?
3227 wine_dbgstr_a(strbase
+ 12 + fpoext
[i
].str_offset
) : "<out of bounds>");
3228 if (fpoext
[i
].str_offset
< strsize
)
3229 ret
= pdb_parse_cmd_string(csw
, &fpoext
[i
], strbase
+ 12 + fpoext
[i
].str_offset
, cpair
);
3243 /*========================================================================
3244 * Process CodeView debug information.
3247 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
3248 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
3249 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
3250 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
3251 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
3253 static BOOL
codeview_process_info(const struct process
* pcs
,
3254 const struct msc_debug_info
* msc_dbg
)
3256 const DWORD
* signature
= (const DWORD
*)msc_dbg
->root
;
3258 struct pdb_lookup pdb_lookup
;
3260 TRACE("Processing signature %.4s\n", (const char*)signature
);
3264 case CODEVIEW_NB09_SIG
:
3265 case CODEVIEW_NB11_SIG
:
3267 const OMFSignature
* cv
= (const OMFSignature
*)msc_dbg
->root
;
3268 const OMFDirHeader
* hdr
= (const OMFDirHeader
*)(msc_dbg
->root
+ cv
->filepos
);
3269 const OMFDirEntry
* ent
;
3270 const OMFDirEntry
* prev
;
3271 const OMFDirEntry
* next
;
3274 codeview_init_basic_types(msc_dbg
->module
);
3276 for (i
= 0; i
< hdr
->cDir
; i
++)
3278 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
+ i
* hdr
->cbDirEntry
);
3279 if (ent
->SubSection
== sstGlobalTypes
)
3281 const OMFGlobalTypes
* types
;
3282 struct codeview_type_parse ctp
;
3284 types
= (const OMFGlobalTypes
*)(msc_dbg
->root
+ ent
->lfo
);
3285 ctp
.module
= msc_dbg
->module
;
3286 ctp
.offset
= (const DWORD
*)(types
+ 1);
3287 ctp
.num
= types
->cTypes
;
3288 ctp
.table
= (const BYTE
*)(ctp
.offset
+ types
->cTypes
);
3290 cv_current_module
= &cv_zmodules
[0];
3291 if (cv_current_module
->allowed
) FIXME("Already allowed??\n");
3292 cv_current_module
->allowed
= TRUE
;
3294 codeview_parse_type_table(&ctp
);
3299 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
);
3300 for (i
= 0; i
< hdr
->cDir
; i
++, ent
= next
)
3302 next
= (i
== hdr
->cDir
-1) ? NULL
:
3303 (const OMFDirEntry
*)((const BYTE
*)ent
+ hdr
->cbDirEntry
);
3304 prev
= (i
== 0) ? NULL
:
3305 (const OMFDirEntry
*)((const BYTE
*)ent
- hdr
->cbDirEntry
);
3307 if (ent
->SubSection
== sstAlignSym
)
3309 codeview_snarf(msc_dbg
, msc_dbg
->root
+ ent
->lfo
, sizeof(DWORD
),
3313 * Check the next and previous entry. If either is a
3314 * sstSrcModule, it contains the line number info for
3317 * FIXME: This is not a general solution!
3319 if (next
&& next
->iMod
== ent
->iMod
&& next
->SubSection
== sstSrcModule
)
3320 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ next
->lfo
,
3323 if (prev
&& prev
->iMod
== ent
->iMod
&& prev
->SubSection
== sstSrcModule
)
3324 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ prev
->lfo
,
3330 msc_dbg
->module
->module
.SymType
= SymCv
;
3331 /* FIXME: we could have a finer grain here */
3332 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
3333 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
3334 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
3335 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
3336 msc_dbg
->module
->module
.Publics
= TRUE
;
3337 codeview_clear_type_table();
3342 case CODEVIEW_NB10_SIG
:
3344 const CODEVIEW_PDB_DATA
* pdb
= (const CODEVIEW_PDB_DATA
*)msc_dbg
->root
;
3345 pdb_lookup
.filename
= pdb
->name
;
3346 pdb_lookup
.kind
= PDB_JG
;
3347 pdb_lookup
.timestamp
= pdb
->timestamp
;
3348 pdb_lookup
.age
= pdb
->age
;
3349 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
3352 case CODEVIEW_RSDS_SIG
:
3354 const OMFSignatureRSDS
* rsds
= (const OMFSignatureRSDS
*)msc_dbg
->root
;
3356 TRACE("Got RSDS type of PDB file: guid=%s age=%08x name=%s\n",
3357 wine_dbgstr_guid(&rsds
->guid
), rsds
->age
, rsds
->name
);
3358 pdb_lookup
.filename
= rsds
->name
;
3359 pdb_lookup
.kind
= PDB_DS
;
3360 pdb_lookup
.guid
= rsds
->guid
;
3361 pdb_lookup
.age
= rsds
->age
;
3362 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
3366 ERR("Unknown CODEVIEW signature %08x in module %s\n",
3367 *signature
, debugstr_w(msc_dbg
->module
->module
.ModuleName
));
3372 msc_dbg
->module
->module
.CVSig
= *signature
;
3373 memcpy(msc_dbg
->module
->module
.CVData
, msc_dbg
->root
,
3374 sizeof(msc_dbg
->module
->module
.CVData
));
3379 /*========================================================================
3380 * Process debug directory.
3382 BOOL
pe_load_debug_directory(const struct process
* pcs
, struct module
* module
,
3383 const BYTE
* mapping
,
3384 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
3385 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
)
3389 struct msc_debug_info msc_dbg
;
3391 msc_dbg
.module
= module
;
3392 msc_dbg
.nsect
= nsect
;
3393 msc_dbg
.sectp
= sectp
;
3395 msc_dbg
.omapp
= NULL
;
3401 /* First, watch out for OMAP data */
3402 for (i
= 0; i
< nDbg
; i
++)
3404 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
)
3406 msc_dbg
.nomap
= dbg
[i
].SizeOfData
/ sizeof(OMAP_DATA
);
3407 msc_dbg
.omapp
= (const OMAP_DATA
*)(mapping
+ dbg
[i
].PointerToRawData
);
3412 /* Now, try to parse CodeView debug info */
3413 for (i
= 0; i
< nDbg
; i
++)
3415 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_CODEVIEW
)
3417 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
3418 if ((ret
= codeview_process_info(pcs
, &msc_dbg
))) goto done
;
3422 /* If not found, try to parse COFF debug info */
3423 for (i
= 0; i
< nDbg
; i
++)
3425 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_COFF
)
3427 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
3428 if ((ret
= coff_process_info(&msc_dbg
))) goto done
;
3432 /* FIXME: this should be supported... this is the debug information for
3433 * functions compiled without a frame pointer (FPO = frame pointer omission)
3434 * the associated data helps finding out the relevant information
3436 for (i
= 0; i
< nDbg
; i
++)
3437 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_FPO
)
3438 FIXME("This guy has FPO information\n");
3442 #define FRAME_TRAP 1
3445 typedef struct _FPO_DATA
3447 DWORD ulOffStart
; /* offset 1st byte of function code */
3448 DWORD cbProcSize
; /* # bytes in function */
3449 DWORD cdwLocals
; /* # bytes in locals/4 */
3450 WORD cdwParams
; /* # bytes in params/4 */
3452 WORD cbProlog
: 8; /* # bytes in prolog */
3453 WORD cbRegs
: 3; /* # regs saved */
3454 WORD fHasSEH
: 1; /* TRUE if SEH in func */
3455 WORD fUseBP
: 1; /* TRUE if EBP has been allocated */
3456 WORD reserved
: 1; /* reserved for future use */
3457 WORD cbFrame
: 2; /* frame type */
3464 ERR("Got a page fault while loading symbols\n");