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_CHAR16
] = &symt_new_basic(module
, btChar16
,"char16_t", 2)->symt
;
173 cv_basic_types
[T_CHAR32
] = &symt_new_basic(module
, btChar32
,"char32_t", 4)->symt
;
174 cv_basic_types
[T_INT2
] = &symt_new_basic(module
, btInt
, "INT2", 2)->symt
;
175 cv_basic_types
[T_UINT2
] = &symt_new_basic(module
, btUInt
, "UINT2", 2)->symt
;
176 cv_basic_types
[T_INT4
] = &symt_new_basic(module
, btInt
, "INT4", 4)->symt
;
177 cv_basic_types
[T_UINT4
] = &symt_new_basic(module
, btUInt
, "UINT4", 4)->symt
;
178 cv_basic_types
[T_INT8
] = &symt_new_basic(module
, btInt
, "INT8", 8)->symt
;
179 cv_basic_types
[T_UINT8
] = &symt_new_basic(module
, btUInt
, "UINT8", 8)->symt
;
180 cv_basic_types
[T_HRESULT
]= &symt_new_basic(module
, btUInt
, "HRESULT", 4)->symt
;
182 cv_basic_types
[T_32PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], 4)->symt
;
183 cv_basic_types
[T_32PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], 4)->symt
;
184 cv_basic_types
[T_32PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], 4)->symt
;
185 cv_basic_types
[T_32PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], 4)->symt
;
186 cv_basic_types
[T_32PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], 4)->symt
;
187 cv_basic_types
[T_32PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], 4)->symt
;
188 cv_basic_types
[T_32PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], 4)->symt
;
189 cv_basic_types
[T_32PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], 4)->symt
;
190 cv_basic_types
[T_32PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], 4)->symt
;
191 cv_basic_types
[T_32PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], 4)->symt
;
192 cv_basic_types
[T_32PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], 4)->symt
;
193 cv_basic_types
[T_32PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], 4)->symt
;
194 cv_basic_types
[T_32PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], 4)->symt
;
195 cv_basic_types
[T_32PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], 4)->symt
;
196 cv_basic_types
[T_32PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], 4)->symt
;
197 cv_basic_types
[T_32PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], 4)->symt
;
198 cv_basic_types
[T_32PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], 4)->symt
;
199 cv_basic_types
[T_32PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], 4)->symt
;
200 cv_basic_types
[T_32PCHAR16
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR16
], 4)->symt
;
201 cv_basic_types
[T_32PCHAR32
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR32
], 4)->symt
;
202 cv_basic_types
[T_32PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], 4)->symt
;
203 cv_basic_types
[T_32PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], 4)->symt
;
204 cv_basic_types
[T_32PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], 4)->symt
;
205 cv_basic_types
[T_32PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], 4)->symt
;
206 cv_basic_types
[T_32PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], 4)->symt
;
207 cv_basic_types
[T_32PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], 4)->symt
;
208 cv_basic_types
[T_32PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
], 4)->symt
;
210 cv_basic_types
[T_64PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], 8)->symt
;
211 cv_basic_types
[T_64PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], 8)->symt
;
212 cv_basic_types
[T_64PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], 8)->symt
;
213 cv_basic_types
[T_64PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], 8)->symt
;
214 cv_basic_types
[T_64PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], 8)->symt
;
215 cv_basic_types
[T_64PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], 8)->symt
;
216 cv_basic_types
[T_64PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], 8)->symt
;
217 cv_basic_types
[T_64PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], 8)->symt
;
218 cv_basic_types
[T_64PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], 8)->symt
;
219 cv_basic_types
[T_64PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], 8)->symt
;
220 cv_basic_types
[T_64PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], 8)->symt
;
221 cv_basic_types
[T_64PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], 8)->symt
;
222 cv_basic_types
[T_64PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], 8)->symt
;
223 cv_basic_types
[T_64PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], 8)->symt
;
224 cv_basic_types
[T_64PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], 8)->symt
;
225 cv_basic_types
[T_64PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], 8)->symt
;
226 cv_basic_types
[T_64PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], 8)->symt
;
227 cv_basic_types
[T_64PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], 8)->symt
;
228 cv_basic_types
[T_64PCHAR16
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR16
], 8)->symt
;
229 cv_basic_types
[T_64PCHAR32
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR32
], 8)->symt
;
230 cv_basic_types
[T_64PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], 8)->symt
;
231 cv_basic_types
[T_64PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], 8)->symt
;
232 cv_basic_types
[T_64PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], 8)->symt
;
233 cv_basic_types
[T_64PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], 8)->symt
;
234 cv_basic_types
[T_64PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], 8)->symt
;
235 cv_basic_types
[T_64PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], 8)->symt
;
236 cv_basic_types
[T_64PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
], 8)->symt
;
238 cv_basic_types
[T_PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], sizeof(void*))->symt
;
239 cv_basic_types
[T_PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], sizeof(void*))->symt
;
240 cv_basic_types
[T_PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], sizeof(void*))->symt
;
241 cv_basic_types
[T_PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], sizeof(void*))->symt
;
242 cv_basic_types
[T_PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], sizeof(void*))->symt
;
243 cv_basic_types
[T_PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], sizeof(void*))->symt
;
244 cv_basic_types
[T_PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], sizeof(void*))->symt
;
245 cv_basic_types
[T_PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], sizeof(void*))->symt
;
246 cv_basic_types
[T_PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], sizeof(void*))->symt
;
247 cv_basic_types
[T_PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], sizeof(void*))->symt
;
248 cv_basic_types
[T_PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], sizeof(void*))->symt
;
249 cv_basic_types
[T_PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], sizeof(void*))->symt
;
250 cv_basic_types
[T_PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], sizeof(void*))->symt
;
251 cv_basic_types
[T_PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], sizeof(void*))->symt
;
252 cv_basic_types
[T_PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], sizeof(void*))->symt
;
253 cv_basic_types
[T_PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], sizeof(void*))->symt
;
254 cv_basic_types
[T_PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], sizeof(void*))->symt
;
255 cv_basic_types
[T_PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], sizeof(void*))->symt
;
256 cv_basic_types
[T_PCHAR16
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR16
], sizeof(void*))->symt
;
257 cv_basic_types
[T_PCHAR32
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR32
], sizeof(void*))->symt
;
258 cv_basic_types
[T_PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], sizeof(void*))->symt
;
259 cv_basic_types
[T_PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], sizeof(void*))->symt
;
260 cv_basic_types
[T_PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], sizeof(void*))->symt
;
261 cv_basic_types
[T_PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], sizeof(void*))->symt
;
262 cv_basic_types
[T_PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], sizeof(void*))->symt
;
263 cv_basic_types
[T_PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], sizeof(void*))->symt
;
266 static int leaf_as_variant(VARIANT
* v
, const unsigned short int* leaf
)
268 unsigned short int type
= *leaf
++;
271 if (type
< LF_NUMERIC
)
273 v
->n1
.n2
.vt
= VT_UINT
;
274 v
->n1
.n2
.n3
.uintVal
= type
;
283 v
->n1
.n2
.n3
.cVal
= *(const char*)leaf
;
289 v
->n1
.n2
.n3
.iVal
= *(const short*)leaf
;
294 v
->n1
.n2
.vt
= VT_UI2
;
295 v
->n1
.n2
.n3
.uiVal
= *leaf
;
301 v
->n1
.n2
.n3
.lVal
= *(const int*)leaf
;
306 v
->n1
.n2
.vt
= VT_UI4
;
307 v
->n1
.n2
.n3
.uiVal
= *(const unsigned int*)leaf
;
313 v
->n1
.n2
.n3
.llVal
= *(const long long int*)leaf
;
318 v
->n1
.n2
.vt
= VT_UI8
;
319 v
->n1
.n2
.n3
.ullVal
= *(const long long unsigned int*)leaf
;
325 v
->n1
.n2
.n3
.fltVal
= *(const float*)leaf
;
329 FIXME("Unsupported numeric leaf type %04x\n", type
);
331 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
337 v
->n1
.n2
.n3
.fltVal
= *(const double*)leaf
;
341 FIXME("Unsupported numeric leaf type %04x\n", type
);
343 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
347 FIXME("Unsupported numeric leaf type %04x\n", type
);
349 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
353 FIXME("Unsupported numeric leaf type %04x\n", type
);
355 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
359 FIXME("Unsupported numeric leaf type %04x\n", type
);
361 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
365 FIXME("Unsupported numeric leaf type %04x\n", type
);
367 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
371 FIXME("Unsupported numeric leaf type %04x\n", type
);
373 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
377 FIXME("Unsupported numeric leaf type %04x\n", type
);
379 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
383 FIXME("Unknown numeric leaf type %04x\n", type
);
384 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
392 static int numeric_leaf(int* value
, const unsigned short int* leaf
)
394 unsigned short int type
= *leaf
++;
397 if (type
< LF_NUMERIC
)
407 *value
= *(const char*)leaf
;
412 *value
= *(const short*)leaf
;
422 *value
= *(const int*)leaf
;
427 *value
= *(const unsigned int*)leaf
;
432 FIXME("Unsupported numeric leaf type %04x\n", type
);
434 *value
= 0; /* FIXME */
438 FIXME("Unsupported numeric leaf type %04x\n", type
);
440 *value
= 0; /* FIXME */
444 FIXME("Unsupported numeric leaf type %04x\n", type
);
446 *value
= 0; /* FIXME */
450 FIXME("Unsupported numeric leaf type %04x\n", type
);
452 *value
= 0; /* FIXME */
456 FIXME("Unsupported numeric leaf type %04x\n", type
);
458 *value
= 0; /* FIXME */
462 FIXME("Unsupported numeric leaf type %04x\n", type
);
464 *value
= 0; /* FIXME */
468 FIXME("Unsupported numeric leaf type %04x\n", type
);
470 *value
= 0; /* FIXME */
474 FIXME("Unsupported numeric leaf type %04x\n", type
);
476 *value
= 0; /* FIXME */
480 FIXME("Unsupported numeric leaf type %04x\n", type
);
482 *value
= 0; /* FIXME */
486 FIXME("Unsupported numeric leaf type %04x\n", type
);
488 *value
= 0; /* FIXME */
492 FIXME("Unsupported numeric leaf type %04x\n", type
);
494 *value
= 0; /* FIXME */
498 FIXME("Unknown numeric leaf type %04x\n", type
);
507 /* convert a pascal string (as stored in debug information) into
508 * a C string (null terminated).
510 static const char* terminate_string(const struct p_string
* p_name
)
512 static char symname
[256];
514 memcpy(symname
, p_name
->name
, p_name
->namelen
);
515 symname
[p_name
->namelen
] = '\0';
517 return (!*symname
|| strcmp(symname
, "__unnamed") == 0) ? NULL
: symname
;
520 static struct symt
* codeview_get_type(unsigned int typeno
, BOOL quiet
)
522 struct symt
* symt
= NULL
;
525 * Convert Codeview type numbers into something we can grok internally.
526 * Numbers < FIRST_DEFINABLE_TYPE are all fixed builtin types.
527 * Numbers from FIRST_DEFINABLE_TYPE and up are all user defined (structs, etc).
529 if (typeno
< FIRST_DEFINABLE_TYPE
)
531 if (typeno
< MAX_BUILTIN_TYPES
)
532 symt
= cv_basic_types
[typeno
];
536 unsigned mod_index
= typeno
>> 24;
537 unsigned mod_typeno
= typeno
& 0x00FFFFFF;
538 struct cv_defined_module
* mod
;
540 mod
= (mod_index
== 0) ? cv_current_module
: &cv_zmodules
[mod_index
];
542 if (mod_index
>= CV_MAX_MODULES
|| !mod
->allowed
)
543 FIXME("Module of index %d isn't loaded yet (%x)\n", mod_index
, typeno
);
546 if (mod_typeno
- FIRST_DEFINABLE_TYPE
< mod
->num_defined_types
)
547 symt
= mod
->defined_types
[mod_typeno
- FIRST_DEFINABLE_TYPE
];
550 if (!quiet
&& !symt
&& typeno
) FIXME("Returning NULL symt for type-id %x\n", typeno
);
554 struct codeview_type_parse
556 struct module
* module
;
562 static inline const void* codeview_jump_to_type(const struct codeview_type_parse
* ctp
, DWORD idx
)
564 if (idx
< FIRST_DEFINABLE_TYPE
) return NULL
;
565 idx
-= FIRST_DEFINABLE_TYPE
;
566 return (idx
>= ctp
->num
) ? NULL
: (ctp
->table
+ ctp
->offset
[idx
]);
569 static int codeview_add_type(unsigned int typeno
, struct symt
* dt
)
571 if (typeno
< FIRST_DEFINABLE_TYPE
)
572 FIXME("What the heck\n");
573 if (!cv_current_module
)
575 FIXME("Adding %x to non allowed module\n", typeno
);
578 if ((typeno
>> 24) != 0)
579 FIXME("No module index while inserting type-id assumption is wrong %x\n",
581 if (typeno
- FIRST_DEFINABLE_TYPE
>= cv_current_module
->num_defined_types
)
583 if (cv_current_module
->defined_types
)
585 cv_current_module
->num_defined_types
= max( cv_current_module
->num_defined_types
* 2,
586 typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
587 cv_current_module
->defined_types
= HeapReAlloc(GetProcessHeap(),
588 HEAP_ZERO_MEMORY
, cv_current_module
->defined_types
,
589 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
593 cv_current_module
->num_defined_types
= max( 256, typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
594 cv_current_module
->defined_types
= HeapAlloc(GetProcessHeap(),
596 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
598 if (cv_current_module
->defined_types
== NULL
) return FALSE
;
600 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
])
602 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] != dt
)
603 FIXME("Overwriting at %x\n", typeno
);
605 cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] = dt
;
609 static void codeview_clear_type_table(void)
613 for (i
= 0; i
< CV_MAX_MODULES
; i
++)
615 if (cv_zmodules
[i
].allowed
)
616 HeapFree(GetProcessHeap(), 0, cv_zmodules
[i
].defined_types
);
617 cv_zmodules
[i
].allowed
= FALSE
;
618 cv_zmodules
[i
].defined_types
= NULL
;
619 cv_zmodules
[i
].num_defined_types
= 0;
621 cv_current_module
= NULL
;
624 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
626 const union codeview_type
* type
, BOOL details
);
628 static void* codeview_cast_symt(struct symt
* symt
, enum SymTagEnum tag
)
630 if (symt
->tag
!= tag
)
632 FIXME("Bad tag. Expected %d, but got %d\n", tag
, symt
->tag
);
638 static struct symt
* codeview_fetch_type(struct codeview_type_parse
* ctp
,
639 unsigned typeno
, BOOL details
)
642 const union codeview_type
* p
;
644 if (!typeno
) return NULL
;
645 if ((symt
= codeview_get_type(typeno
, TRUE
))) return symt
;
647 /* forward declaration */
648 if (!(p
= codeview_jump_to_type(ctp
, typeno
)))
650 FIXME("Cannot locate type %x\n", typeno
);
653 symt
= codeview_parse_one_type(ctp
, typeno
, p
, details
);
654 if (!symt
) FIXME("Couldn't load forward type %x\n", typeno
);
658 static struct symt
* codeview_add_type_pointer(struct codeview_type_parse
* ctp
,
659 struct symt
* existing
,
660 unsigned int pointee_type
)
662 struct symt
* pointee
;
666 existing
= codeview_cast_symt(existing
, SymTagPointerType
);
669 pointee
= codeview_fetch_type(ctp
, pointee_type
, FALSE
);
670 return &symt_new_pointer(ctp
->module
, pointee
, sizeof(void *))->symt
;
673 static struct symt
* codeview_add_type_array(struct codeview_type_parse
* ctp
,
675 unsigned int elemtype
,
676 unsigned int indextype
,
677 unsigned int arr_len
)
679 struct symt
* elem
= codeview_fetch_type(ctp
, elemtype
, FALSE
);
680 struct symt
* index
= codeview_fetch_type(ctp
, indextype
, FALSE
);
682 return &symt_new_array(ctp
->module
, 0, -arr_len
, elem
, index
)->symt
;
685 static BOOL
codeview_add_type_enum_field_list(struct module
* module
,
686 struct symt_enum
* symt
,
687 const union codeview_reftype
* ref_type
)
689 const unsigned char* ptr
= ref_type
->fieldlist
.list
;
690 const unsigned char* last
= (const BYTE
*)ref_type
+ ref_type
->generic
.len
+ 2;
691 const union codeview_fieldtype
* type
;
695 if (*ptr
>= 0xf0) /* LF_PAD... */
701 type
= (const union codeview_fieldtype
*)ptr
;
703 switch (type
->generic
.id
)
705 case LF_ENUMERATE_V1
:
707 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v1
.value
);
708 const struct p_string
* p_name
= (const struct p_string
*)((const unsigned char*)&type
->enumerate_v1
.value
+ vlen
);
710 symt_add_enum_element(module
, symt
, terminate_string(p_name
), value
);
711 ptr
+= 2 + 2 + vlen
+ (1 + p_name
->namelen
);
714 case LF_ENUMERATE_V3
:
716 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v3
.value
);
717 const char* name
= (const char*)&type
->enumerate_v3
.value
+ vlen
;
719 symt_add_enum_element(module
, symt
, name
, value
);
720 ptr
+= 2 + 2 + vlen
+ (1 + strlen(name
));
725 FIXME("Unsupported type %04x in ENUM field list\n", type
->generic
.id
);
732 static void codeview_add_udt_element(struct codeview_type_parse
* ctp
,
733 struct symt_udt
* symt
, const char* name
,
734 int value
, unsigned type
)
736 struct symt
* subtype
;
737 const union codeview_reftype
*cv_type
;
739 if ((cv_type
= codeview_jump_to_type(ctp
, type
)))
741 switch (cv_type
->generic
.id
)
744 symt_add_udt_element(ctp
->module
, symt
, name
,
745 codeview_fetch_type(ctp
, cv_type
->bitfield_v1
.type
, FALSE
),
746 (value
<< 3) + cv_type
->bitfield_v1
.bitoff
,
747 cv_type
->bitfield_v1
.nbits
);
750 symt_add_udt_element(ctp
->module
, symt
, name
,
751 codeview_fetch_type(ctp
, cv_type
->bitfield_v2
.type
, FALSE
),
752 (value
<< 3) + cv_type
->bitfield_v2
.bitoff
,
753 cv_type
->bitfield_v2
.nbits
);
757 subtype
= codeview_fetch_type(ctp
, type
, FALSE
);
761 DWORD64 elem_size
= 0;
762 symt_get_info(ctp
->module
, subtype
, TI_GET_LENGTH
, &elem_size
);
763 symt_add_udt_element(ctp
->module
, symt
, name
, subtype
,
764 value
<< 3, (DWORD
)elem_size
<< 3);
768 static int codeview_add_type_struct_field_list(struct codeview_type_parse
* ctp
,
769 struct symt_udt
* symt
,
770 unsigned fieldlistno
)
772 const unsigned char* ptr
;
773 const unsigned char* last
;
775 const struct p_string
* p_name
;
777 const union codeview_reftype
*type_ref
;
778 const union codeview_fieldtype
* type
;
780 if (!fieldlistno
) return TRUE
;
781 type_ref
= codeview_jump_to_type(ctp
, fieldlistno
);
782 ptr
= type_ref
->fieldlist
.list
;
783 last
= (const BYTE
*)type_ref
+ type_ref
->generic
.len
+ 2;
787 if (*ptr
>= 0xf0) /* LF_PAD... */
793 type
= (const union codeview_fieldtype
*)ptr
;
795 switch (type
->generic
.id
)
798 leaf_len
= numeric_leaf(&value
, &type
->bclass_v1
.offset
);
800 /* FIXME: ignored for now */
802 ptr
+= 2 + 2 + 2 + leaf_len
;
806 leaf_len
= numeric_leaf(&value
, &type
->bclass_v2
.offset
);
808 /* FIXME: ignored for now */
810 ptr
+= 2 + 2 + 4 + leaf_len
;
816 const unsigned short int* p_vboff
;
818 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v1
.vbpoff
);
819 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v1
.vbpoff
+ leaf_len
);
820 vplen
= numeric_leaf(&vpoff
, p_vboff
);
822 /* FIXME: ignored for now */
824 ptr
+= 2 + 2 + 2 + 2 + leaf_len
+ vplen
;
831 const unsigned short int* p_vboff
;
833 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v2
.vbpoff
);
834 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v2
.vbpoff
+ leaf_len
);
835 vplen
= numeric_leaf(&vpoff
, p_vboff
);
837 /* FIXME: ignored for now */
839 ptr
+= 2 + 2 + 4 + 4 + leaf_len
+ vplen
;
844 leaf_len
= numeric_leaf(&value
, &type
->member_v1
.offset
);
845 p_name
= (const struct p_string
*)((const char*)&type
->member_v1
.offset
+ leaf_len
);
847 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
848 type
->member_v1
.type
);
850 ptr
+= 2 + 2 + 2 + leaf_len
+ (1 + p_name
->namelen
);
854 leaf_len
= numeric_leaf(&value
, &type
->member_v2
.offset
);
855 p_name
= (const struct p_string
*)((const unsigned char*)&type
->member_v2
.offset
+ leaf_len
);
857 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
858 type
->member_v2
.type
);
860 ptr
+= 2 + 2 + 4 + leaf_len
+ (1 + p_name
->namelen
);
864 leaf_len
= numeric_leaf(&value
, &type
->member_v3
.offset
);
865 c_name
= (const char*)&type
->member_v3
.offset
+ leaf_len
;
867 codeview_add_udt_element(ctp
, symt
, c_name
, value
, type
->member_v3
.type
);
869 ptr
+= 2 + 2 + 4 + leaf_len
+ (strlen(c_name
) + 1);
873 /* FIXME: ignored for now */
874 ptr
+= 2 + 2 + 2 + (1 + type
->stmember_v1
.p_name
.namelen
);
878 /* FIXME: ignored for now */
879 ptr
+= 2 + 4 + 2 + (1 + type
->stmember_v2
.p_name
.namelen
);
883 /* FIXME: ignored for now */
884 ptr
+= 2 + 4 + 2 + (strlen(type
->stmember_v3
.name
) + 1);
888 /* FIXME: ignored for now */
889 ptr
+= 2 + 2 + 2 + (1 + type
->method_v1
.p_name
.namelen
);
893 /* FIXME: ignored for now */
894 ptr
+= 2 + 2 + 4 + (1 + type
->method_v2
.p_name
.namelen
);
898 /* FIXME: ignored for now */
899 ptr
+= 2 + 2 + 4 + (strlen(type
->method_v3
.name
) + 1);
903 /* FIXME: ignored for now */
904 ptr
+= 2 + 2 + (1 + type
->nesttype_v1
.p_name
.namelen
);
908 /* FIXME: ignored for now */
909 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype_v2
.p_name
.namelen
);
913 /* FIXME: ignored for now */
914 ptr
+= 2 + 2 + 4 + (strlen(type
->nesttype_v3
.name
) + 1);
918 /* FIXME: ignored for now */
923 /* FIXME: ignored for now */
927 case LF_ONEMETHOD_V1
:
928 /* FIXME: ignored for now */
929 switch ((type
->onemethod_v1
.attribute
>> 2) & 7)
931 case 4: case 6: /* (pure) introducing virtual method */
932 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt_v1
.p_name
.namelen
);
936 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod_v1
.p_name
.namelen
);
941 case LF_ONEMETHOD_V2
:
942 /* FIXME: ignored for now */
943 switch ((type
->onemethod_v2
.attribute
>> 2) & 7)
945 case 4: case 6: /* (pure) introducing virtual method */
946 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod_virt_v2
.p_name
.namelen
);
950 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod_v2
.p_name
.namelen
);
955 case LF_ONEMETHOD_V3
:
956 /* FIXME: ignored for now */
957 switch ((type
->onemethod_v3
.attribute
>> 2) & 7)
959 case 4: case 6: /* (pure) introducing virtual method */
960 ptr
+= 2 + 2 + 4 + 4 + (strlen(type
->onemethod_virt_v3
.name
) + 1);
964 ptr
+= 2 + 2 + 4 + (strlen(type
->onemethod_v3
.name
) + 1);
970 if (!codeview_add_type_struct_field_list(ctp
, symt
, type
->index_v1
.ref
))
976 if (!codeview_add_type_struct_field_list(ctp
, symt
, type
->index_v2
.ref
))
982 FIXME("Unsupported type %04x in STRUCT field list\n", type
->generic
.id
);
990 static struct symt
* codeview_add_type_enum(struct codeview_type_parse
* ctp
,
991 struct symt
* existing
,
993 unsigned fieldlistno
,
996 struct symt_enum
* symt
;
1000 if (!(symt
= codeview_cast_symt(existing
, SymTagEnum
))) return NULL
;
1001 /* should also check that all fields are the same */
1005 symt
= symt_new_enum(ctp
->module
, name
,
1006 codeview_fetch_type(ctp
, basetype
, FALSE
));
1009 const union codeview_reftype
* fieldlist
;
1010 fieldlist
= codeview_jump_to_type(ctp
, fieldlistno
);
1011 codeview_add_type_enum_field_list(ctp
->module
, symt
, fieldlist
);
1017 static struct symt
* codeview_add_type_struct(struct codeview_type_parse
* ctp
,
1018 struct symt
* existing
,
1019 const char* name
, int structlen
,
1020 enum UdtKind kind
, unsigned property
)
1022 struct symt_udt
* symt
;
1024 /* if we don't have an existing type, try to find one with same name
1025 * FIXME: what to do when several types in different CUs have same name ?
1030 struct symt_ht
* type
;
1031 struct hash_table_iter hti
;
1033 hash_table_iter_init(&ctp
->module
->ht_types
, &hti
, name
);
1034 while ((ptr
= hash_table_iter_up(&hti
)))
1036 type
= CONTAINING_RECORD(ptr
, struct symt_ht
, hash_elt
);
1038 if (type
->symt
.tag
== SymTagUDT
&&
1039 type
->hash_elt
.name
&& !strcmp(type
->hash_elt
.name
, name
))
1041 existing
= &type
->symt
;
1048 if (!(symt
= codeview_cast_symt(existing
, SymTagUDT
))) return NULL
;
1049 /* should also check that all fields are the same */
1050 if (!(property
& 0x80)) /* 0x80 = forward declaration */
1052 if (!symt
->size
) /* likely prior forward declaration, set UDT size */
1053 symt_set_udt_size(ctp
->module
, symt
, structlen
);
1054 else /* different UDT with same name, create a new type */
1058 if (!existing
) symt
= symt_new_udt(ctp
->module
, name
, structlen
, kind
);
1063 static struct symt
* codeview_new_func_signature(struct codeview_type_parse
* ctp
,
1064 struct symt
* existing
,
1065 enum CV_call_e call_conv
)
1067 struct symt_function_signature
* sym
;
1071 sym
= codeview_cast_symt(existing
, SymTagFunctionType
);
1072 if (!sym
) return NULL
;
1076 sym
= symt_new_function_signature(ctp
->module
, NULL
, call_conv
);
1081 static void codeview_add_func_signature_args(struct codeview_type_parse
* ctp
,
1082 struct symt_function_signature
* sym
,
1086 const union codeview_reftype
* reftype
;
1088 sym
->rettype
= codeview_fetch_type(ctp
, ret_type
, FALSE
);
1089 if (args_list
&& (reftype
= codeview_jump_to_type(ctp
, args_list
)))
1092 switch (reftype
->generic
.id
)
1095 for (i
= 0; i
< reftype
->arglist_v1
.num
; i
++)
1096 symt_add_function_signature_parameter(ctp
->module
, sym
,
1097 codeview_fetch_type(ctp
, reftype
->arglist_v1
.args
[i
], FALSE
));
1100 for (i
= 0; i
< reftype
->arglist_v2
.num
; i
++)
1101 symt_add_function_signature_parameter(ctp
->module
, sym
,
1102 codeview_fetch_type(ctp
, reftype
->arglist_v2
.args
[i
], FALSE
));
1105 FIXME("Unexpected leaf %x for signature's pmt\n", reftype
->generic
.id
);
1110 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
1112 const union codeview_type
* type
, BOOL details
)
1115 int value
, leaf_len
;
1116 const struct p_string
* p_name
;
1118 struct symt
* existing
;
1120 existing
= codeview_get_type(curr_type
, TRUE
);
1122 switch (type
->generic
.id
)
1124 case LF_MODIFIER_V1
:
1125 /* FIXME: we don't handle modifiers,
1126 * but read previous type on the curr_type
1128 WARN("Modifier on %x: %s%s%s%s\n",
1129 type
->modifier_v1
.type
,
1130 type
->modifier_v1
.attribute
& 0x01 ? "const " : "",
1131 type
->modifier_v1
.attribute
& 0x02 ? "volatile " : "",
1132 type
->modifier_v1
.attribute
& 0x04 ? "unaligned " : "",
1133 type
->modifier_v1
.attribute
& ~0x07 ? "unknown " : "");
1134 symt
= codeview_fetch_type(ctp
, type
->modifier_v1
.type
, details
);
1136 case LF_MODIFIER_V2
:
1137 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
1138 WARN("Modifier on %x: %s%s%s%s\n",
1139 type
->modifier_v2
.type
,
1140 type
->modifier_v2
.attribute
& 0x01 ? "const " : "",
1141 type
->modifier_v2
.attribute
& 0x02 ? "volatile " : "",
1142 type
->modifier_v2
.attribute
& 0x04 ? "unaligned " : "",
1143 type
->modifier_v2
.attribute
& ~0x07 ? "unknown " : "");
1144 symt
= codeview_fetch_type(ctp
, type
->modifier_v2
.type
, details
);
1148 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v1
.datatype
);
1151 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v2
.datatype
);
1155 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1158 leaf_len
= numeric_leaf(&value
, &type
->array_v1
.arrlen
);
1159 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v1
.arrlen
+ leaf_len
);
1160 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1161 type
->array_v1
.elemtype
,
1162 type
->array_v1
.idxtype
, value
);
1166 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1169 leaf_len
= numeric_leaf(&value
, &type
->array_v2
.arrlen
);
1170 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v2
.arrlen
+ leaf_len
);
1172 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1173 type
->array_v2
.elemtype
,
1174 type
->array_v2
.idxtype
, value
);
1178 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1181 leaf_len
= numeric_leaf(&value
, &type
->array_v3
.arrlen
);
1182 c_name
= (const char*)&type
->array_v3
.arrlen
+ leaf_len
;
1184 symt
= codeview_add_type_array(ctp
, c_name
,
1185 type
->array_v3
.elemtype
,
1186 type
->array_v3
.idxtype
, value
);
1190 case LF_STRUCTURE_V1
:
1192 leaf_len
= numeric_leaf(&value
, &type
->struct_v1
.structlen
);
1193 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v1
.structlen
+ leaf_len
);
1194 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1195 type
->generic
.id
== LF_CLASS_V1
? UdtClass
: UdtStruct
,
1196 type
->struct_v1
.property
);
1199 codeview_add_type(curr_type
, symt
);
1200 if (!(type
->struct_v1
.property
& 0x80)) /* 0x80 = forward declaration */
1201 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1202 type
->struct_v1
.fieldlist
);
1206 case LF_STRUCTURE_V2
:
1208 leaf_len
= numeric_leaf(&value
, &type
->struct_v2
.structlen
);
1209 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v2
.structlen
+ leaf_len
);
1210 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1211 type
->generic
.id
== LF_CLASS_V2
? UdtClass
: UdtStruct
,
1212 type
->struct_v2
.property
);
1215 codeview_add_type(curr_type
, symt
);
1216 if (!(type
->struct_v2
.property
& 0x80)) /* 0x80 = forward declaration */
1217 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1218 type
->struct_v2
.fieldlist
);
1222 case LF_STRUCTURE_V3
:
1224 leaf_len
= numeric_leaf(&value
, &type
->struct_v3
.structlen
);
1225 c_name
= (const char*)&type
->struct_v3
.structlen
+ leaf_len
;
1226 symt
= codeview_add_type_struct(ctp
, existing
, c_name
, value
,
1227 type
->generic
.id
== LF_CLASS_V3
? UdtClass
: UdtStruct
,
1228 type
->struct_v3
.property
);
1231 codeview_add_type(curr_type
, symt
);
1232 if (!(type
->struct_v3
.property
& 0x80)) /* 0x80 = forward declaration */
1233 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1234 type
->struct_v3
.fieldlist
);
1239 leaf_len
= numeric_leaf(&value
, &type
->union_v1
.un_len
);
1240 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v1
.un_len
+ leaf_len
);
1241 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1242 value
, UdtUnion
, type
->union_v1
.property
);
1245 codeview_add_type(curr_type
, symt
);
1246 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1247 type
->union_v1
.fieldlist
);
1252 leaf_len
= numeric_leaf(&value
, &type
->union_v2
.un_len
);
1253 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v2
.un_len
+ leaf_len
);
1254 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1255 value
, UdtUnion
, type
->union_v2
.property
);
1258 codeview_add_type(curr_type
, symt
);
1259 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1260 type
->union_v2
.fieldlist
);
1265 leaf_len
= numeric_leaf(&value
, &type
->union_v3
.un_len
);
1266 c_name
= (const char*)&type
->union_v3
.un_len
+ leaf_len
;
1267 symt
= codeview_add_type_struct(ctp
, existing
, c_name
,
1268 value
, UdtUnion
, type
->union_v3
.property
);
1271 codeview_add_type(curr_type
, symt
);
1272 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1273 type
->union_v3
.fieldlist
);
1278 symt
= codeview_add_type_enum(ctp
, existing
,
1279 terminate_string(&type
->enumeration_v1
.p_name
),
1280 type
->enumeration_v1
.fieldlist
,
1281 type
->enumeration_v1
.type
);
1285 symt
= codeview_add_type_enum(ctp
, existing
,
1286 terminate_string(&type
->enumeration_v2
.p_name
),
1287 type
->enumeration_v2
.fieldlist
,
1288 type
->enumeration_v2
.type
);
1292 symt
= codeview_add_type_enum(ctp
, existing
, type
->enumeration_v3
.name
,
1293 type
->enumeration_v3
.fieldlist
,
1294 type
->enumeration_v3
.type
);
1297 case LF_PROCEDURE_V1
:
1298 symt
= codeview_new_func_signature(ctp
, existing
, type
->procedure_v1
.call
);
1301 codeview_add_type(curr_type
, symt
);
1302 codeview_add_func_signature_args(ctp
,
1303 (struct symt_function_signature
*)symt
,
1304 type
->procedure_v1
.rvtype
,
1305 type
->procedure_v1
.arglist
);
1308 case LF_PROCEDURE_V2
:
1309 symt
= codeview_new_func_signature(ctp
, existing
,type
->procedure_v2
.call
);
1312 codeview_add_type(curr_type
, symt
);
1313 codeview_add_func_signature_args(ctp
,
1314 (struct symt_function_signature
*)symt
,
1315 type
->procedure_v2
.rvtype
,
1316 type
->procedure_v2
.arglist
);
1320 case LF_MFUNCTION_V1
:
1321 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1322 * nor class information, this would just do for now
1324 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v1
.call
);
1327 codeview_add_type(curr_type
, symt
);
1328 codeview_add_func_signature_args(ctp
,
1329 (struct symt_function_signature
*)symt
,
1330 type
->mfunction_v1
.rvtype
,
1331 type
->mfunction_v1
.arglist
);
1334 case LF_MFUNCTION_V2
:
1335 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1336 * nor class information, this would just do for now
1338 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v2
.call
);
1341 codeview_add_type(curr_type
, symt
);
1342 codeview_add_func_signature_args(ctp
,
1343 (struct symt_function_signature
*)symt
,
1344 type
->mfunction_v2
.rvtype
,
1345 type
->mfunction_v2
.arglist
);
1350 /* this is an ugly hack... FIXME when we have C++ support */
1351 if (!(symt
= existing
))
1354 snprintf(buf
, sizeof(buf
), "__internal_vt_shape_%x\n", curr_type
);
1355 symt
= &symt_new_udt(ctp
->module
, buf
, 0, UdtStruct
)->symt
;
1359 FIXME("Unsupported type-id leaf %x\n", type
->generic
.id
);
1360 dump(type
, 2 + type
->generic
.len
);
1363 return codeview_add_type(curr_type
, symt
) ? symt
: NULL
;
1366 static BOOL
codeview_parse_type_table(struct codeview_type_parse
* ctp
)
1368 unsigned int curr_type
= FIRST_DEFINABLE_TYPE
;
1369 const union codeview_type
* type
;
1371 for (curr_type
= FIRST_DEFINABLE_TYPE
; curr_type
< FIRST_DEFINABLE_TYPE
+ ctp
->num
; curr_type
++)
1373 type
= codeview_jump_to_type(ctp
, curr_type
);
1375 /* type records we're interested in are the ones referenced by symbols
1376 * The known ranges are (X mark the ones we want):
1377 * X 0000-0016 for V1 types
1378 * 0200-020c for V1 types referenced by other types
1379 * 0400-040f for V1 types (complex lists & sets)
1380 * X 1000-100f for V2 types
1381 * 1200-120c for V2 types referenced by other types
1382 * 1400-140f for V1 types (complex lists & sets)
1383 * X 1500-150d for V3 types
1384 * 8000-8010 for numeric leafes
1386 if (!(type
->generic
.id
& 0x8600) || (type
->generic
.id
& 0x0100))
1387 codeview_parse_one_type(ctp
, curr_type
, type
, TRUE
);
1393 /*========================================================================
1394 * Process CodeView line number information.
1396 static unsigned long codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1397 unsigned seg
, unsigned offset
);
1399 static void codeview_snarf_linetab(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
,
1400 int size
, BOOL pascal_str
)
1402 const BYTE
* ptr
= linetab
;
1406 const unsigned int* filetab
;
1407 const unsigned int* lt_ptr
;
1408 const unsigned short* linenos
;
1409 const struct startend
* start
;
1411 unsigned long addr
, func_addr0
;
1412 struct symt_function
* func
;
1413 const struct codeview_linetab_block
* ltb
;
1415 nfile
= *(const short*)linetab
;
1416 filetab
= (const unsigned int*)(linetab
+ 2 * sizeof(short));
1418 for (i
= 0; i
< nfile
; i
++)
1420 ptr
= linetab
+ filetab
[i
];
1421 nseg
= *(const short*)ptr
;
1422 lt_ptr
= (const unsigned int*)(ptr
+ 2 * sizeof(short));
1423 start
= (const struct startend
*)(lt_ptr
+ nseg
);
1426 * Now snarf the filename for all of the segments for this file.
1429 source
= source_new(msc_dbg
->module
, NULL
, terminate_string((const struct p_string
*)(start
+ nseg
)));
1431 source
= source_new(msc_dbg
->module
, NULL
, (const char*)(start
+ nseg
));
1433 for (j
= 0; j
< nseg
; j
++)
1435 ltb
= (const struct codeview_linetab_block
*)(linetab
+ *lt_ptr
++);
1436 linenos
= (const unsigned short*)<b
->offsets
[ltb
->num_lines
];
1437 func_addr0
= codeview_get_address(msc_dbg
, ltb
->seg
, start
[j
].start
);
1438 if (!func_addr0
) continue;
1439 for (func
= NULL
, k
= 0; k
< ltb
->num_lines
; k
++)
1441 /* now locate function (if any) */
1442 addr
= func_addr0
+ ltb
->offsets
[k
] - start
[j
].start
;
1443 /* unfortunately, we can have several functions in the same block, if there's no
1444 * gap between them... find the new function if needed
1446 if (!func
|| addr
>= func
->address
+ func
->size
)
1448 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1449 /* FIXME: at least labels support line numbers */
1450 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1452 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1453 ltb
->seg
, ltb
->offsets
[k
], addr
, func
? func
->symt
.tag
: -1);
1458 symt_add_func_line(msc_dbg
->module
, func
, source
,
1459 linenos
[k
], addr
- func
->address
);
1465 static void codeview_snarf_linetab2(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
, DWORD size
,
1466 const char* strimage
, DWORD strsize
)
1470 const struct codeview_linetab2
* lt2
;
1471 const struct codeview_linetab2
* lt2_files
= NULL
;
1472 const struct codeview_lt2blk_lines
* lines_blk
;
1473 const struct codeview_linetab2_file
*fd
;
1475 struct symt_function
* func
;
1477 /* locate LT2_FILES_BLOCK (if any) */
1478 lt2
= (const struct codeview_linetab2
*)linetab
;
1479 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1481 if (lt2
->header
== LT2_FILES_BLOCK
)
1486 lt2
= codeview_linetab2_next_block(lt2
);
1490 TRACE("No LT2_FILES_BLOCK found\n");
1494 lt2
= (const struct codeview_linetab2
*)linetab
;
1495 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1497 /* FIXME: should also check that whole lines_blk fits in linetab + size */
1498 switch (lt2
->header
)
1500 case LT2_LINES_BLOCK
:
1501 /* Skip blocks that are too small - Intel C Compiler generates these. */
1502 if (lt2
->size_of_block
< sizeof (struct codeview_lt2blk_lines
)) break;
1503 lines_blk
= (const struct codeview_lt2blk_lines
*)lt2
;
1504 /* FIXME: should check that file_offset is within the LT2_FILES_BLOCK we've seen */
1505 addr
= codeview_get_address(msc_dbg
, lines_blk
->seg
, lines_blk
->start
);
1506 TRACE("block from %04x:%08x #%x (%x lines)\n",
1507 lines_blk
->seg
, lines_blk
->start
, lines_blk
->size
, lines_blk
->nlines
);
1508 fd
= (const struct codeview_linetab2_file
*)((const char*)lt2_files
+ 8 + lines_blk
->file_offset
);
1509 /* FIXME: should check that string is within strimage + strsize */
1510 source
= source_new(msc_dbg
->module
, NULL
, strimage
+ fd
->offset
);
1511 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1512 /* FIXME: at least labels support line numbers */
1513 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1515 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1516 lines_blk
->seg
, lines_blk
->start
, addr
, func
? func
->symt
.tag
: -1);
1519 for (i
= 0; i
< lines_blk
->nlines
; i
++)
1521 symt_add_func_line(msc_dbg
->module
, func
, source
,
1522 lines_blk
->l
[i
].lineno
^ 0x80000000,
1523 lines_blk
->l
[i
].offset
);
1526 case LT2_FILES_BLOCK
: /* skip */
1529 TRACE("Block end %x\n", lt2
->header
);
1530 lt2
= (const struct codeview_linetab2
*)((const char*)linetab
+ size
);
1533 lt2
= codeview_linetab2_next_block(lt2
);
1537 /*========================================================================
1538 * Process CodeView symbol information.
1541 static unsigned int codeview_map_offset(const struct msc_debug_info
* msc_dbg
,
1542 unsigned int offset
)
1544 int nomap
= msc_dbg
->nomap
;
1545 const OMAP_DATA
* omapp
= msc_dbg
->omapp
;
1548 if (!nomap
|| !omapp
) return offset
;
1550 /* FIXME: use binary search */
1551 for (i
= 0; i
< nomap
- 1; i
++)
1552 if (omapp
[i
].from
<= offset
&& omapp
[i
+1].from
> offset
)
1553 return !omapp
[i
].to
? 0 : omapp
[i
].to
+ (offset
- omapp
[i
].from
);
1558 static unsigned long codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1559 unsigned seg
, unsigned offset
)
1561 int nsect
= msc_dbg
->nsect
;
1562 const IMAGE_SECTION_HEADER
* sectp
= msc_dbg
->sectp
;
1564 if (!seg
|| seg
> nsect
) return 0;
1565 return msc_dbg
->module
->module
.BaseOfImage
+
1566 codeview_map_offset(msc_dbg
, sectp
[seg
-1].VirtualAddress
+ offset
);
1569 static inline void codeview_add_variable(const struct msc_debug_info
* msc_dbg
,
1570 struct symt_compiland
* compiland
,
1572 unsigned segment
, unsigned offset
,
1573 unsigned symtype
, BOOL is_local
, BOOL in_tls
, BOOL force
)
1577 struct location loc
;
1579 loc
.kind
= in_tls
? loc_tlsrel
: loc_absolute
;
1581 loc
.offset
= in_tls
? offset
: codeview_get_address(msc_dbg
, segment
, offset
);
1582 if (force
|| in_tls
|| !symt_find_nearest(msc_dbg
->module
, loc
.offset
))
1584 symt_new_global_variable(msc_dbg
->module
, compiland
,
1585 name
, is_local
, loc
, 0,
1586 codeview_get_type(symtype
, FALSE
));
1591 static BOOL
codeview_snarf(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1592 int offset
, int size
, BOOL do_globals
)
1594 struct symt_function
* curr_func
= NULL
;
1596 struct symt_block
* block
= NULL
;
1598 struct symt_compiland
* compiland
= NULL
;
1599 struct location loc
;
1602 * Loop over the different types of records and whenever we
1603 * find something we are interested in, record it and move on.
1605 for (i
= offset
; i
< size
; i
+= length
)
1607 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1608 length
= sym
->generic
.len
+ 2;
1609 if (i
+ length
> size
) break;
1610 if (!sym
->generic
.id
|| length
< 4) break;
1611 if (length
& 3) FIXME("unpadded len %u\n", length
);
1613 switch (sym
->generic
.id
)
1616 * Global and local data symbols. We don't associate these
1617 * with any given source file.
1622 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
1623 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
1624 sym
->generic
.id
== S_LDATA_V1
, FALSE
, TRUE
);
1629 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
1630 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
1631 sym
->generic
.id
== S_LDATA_V2
, FALSE
, TRUE
);
1636 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
1637 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
1638 sym
->generic
.id
== S_LDATA_V3
, FALSE
, TRUE
);
1641 /* variables with thread storage */
1645 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v1
.p_name
),
1646 sym
->thread_v1
.segment
, sym
->thread_v1
.offset
, sym
->thread_v1
.symtype
,
1647 sym
->generic
.id
== S_LTHREAD_V1
, TRUE
, TRUE
);
1652 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v2
.p_name
),
1653 sym
->thread_v2
.segment
, sym
->thread_v2
.offset
, sym
->thread_v2
.symtype
,
1654 sym
->generic
.id
== S_LTHREAD_V2
, TRUE
, TRUE
);
1659 codeview_add_variable(msc_dbg
, compiland
, sym
->thread_v3
.name
,
1660 sym
->thread_v3
.segment
, sym
->thread_v3
.offset
, sym
->thread_v3
.symtype
,
1661 sym
->generic
.id
== S_LTHREAD_V3
, TRUE
, TRUE
);
1664 /* Public symbols */
1668 case S_PUB_FUNC1_V3
:
1669 case S_PUB_FUNC2_V3
:
1670 /* will be handled later on in codeview_snarf_public */
1674 * Sort of like a global function, but it just points
1675 * to a thunk, which is a stupid name for what amounts to
1676 * a PLT slot in the normal jargon that everyone else uses.
1679 symt_new_thunk(msc_dbg
->module
, compiland
,
1680 terminate_string(&sym
->thunk_v1
.p_name
), sym
->thunk_v1
.thtype
,
1681 codeview_get_address(msc_dbg
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
),
1682 sym
->thunk_v1
.thunk_len
);
1685 symt_new_thunk(msc_dbg
->module
, compiland
,
1686 sym
->thunk_v3
.name
, sym
->thunk_v3
.thtype
,
1687 codeview_get_address(msc_dbg
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
),
1688 sym
->thunk_v3
.thunk_len
);
1692 * Global and static functions.
1696 if (curr_func
) FIXME("nested function\n");
1697 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1698 terminate_string(&sym
->proc_v1
.p_name
),
1699 codeview_get_address(msc_dbg
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
),
1700 sym
->proc_v1
.proc_len
,
1701 codeview_get_type(sym
->proc_v1
.proctype
, FALSE
));
1702 loc
.kind
= loc_absolute
;
1703 loc
.offset
= sym
->proc_v1
.debug_start
;
1704 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1705 loc
.offset
= sym
->proc_v1
.debug_end
;
1706 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1710 if (curr_func
) FIXME("nested function\n");
1711 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1712 terminate_string(&sym
->proc_v2
.p_name
),
1713 codeview_get_address(msc_dbg
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
),
1714 sym
->proc_v2
.proc_len
,
1715 codeview_get_type(sym
->proc_v2
.proctype
, FALSE
));
1716 loc
.kind
= loc_absolute
;
1717 loc
.offset
= sym
->proc_v2
.debug_start
;
1718 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1719 loc
.offset
= sym
->proc_v2
.debug_end
;
1720 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1724 if (curr_func
) FIXME("nested function\n");
1725 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1727 codeview_get_address(msc_dbg
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
),
1728 sym
->proc_v3
.proc_len
,
1729 codeview_get_type(sym
->proc_v3
.proctype
, FALSE
));
1730 loc
.kind
= loc_absolute
;
1731 loc
.offset
= sym
->proc_v3
.debug_start
;
1732 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1733 loc
.offset
= sym
->proc_v3
.debug_end
;
1734 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1737 * Function parameters and stack variables.
1740 loc
.kind
= loc_regrel
;
1741 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1742 loc
.reg
= CV_REG_EBP
;
1743 loc
.offset
= sym
->stack_v1
.offset
;
1744 symt_add_func_local(msc_dbg
->module
, curr_func
,
1745 sym
->stack_v1
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1747 codeview_get_type(sym
->stack_v1
.symtype
, FALSE
),
1748 terminate_string(&sym
->stack_v1
.p_name
));
1751 loc
.kind
= loc_regrel
;
1752 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1753 loc
.reg
= CV_REG_EBP
;
1754 loc
.offset
= sym
->stack_v2
.offset
;
1755 symt_add_func_local(msc_dbg
->module
, curr_func
,
1756 sym
->stack_v2
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1758 codeview_get_type(sym
->stack_v2
.symtype
, FALSE
),
1759 terminate_string(&sym
->stack_v2
.p_name
));
1762 loc
.kind
= loc_regrel
;
1763 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1764 loc
.reg
= CV_REG_EBP
;
1765 loc
.offset
= sym
->stack_v3
.offset
;
1766 symt_add_func_local(msc_dbg
->module
, curr_func
,
1767 sym
->stack_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1769 codeview_get_type(sym
->stack_v3
.symtype
, FALSE
),
1770 sym
->stack_v3
.name
);
1773 loc
.kind
= loc_regrel
;
1774 loc
.reg
= sym
->regrel_v3
.reg
;
1775 loc
.offset
= sym
->regrel_v3
.offset
;
1776 symt_add_func_local(msc_dbg
->module
, curr_func
,
1777 /* FIXME this is wrong !!! */
1778 sym
->regrel_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1780 codeview_get_type(sym
->regrel_v3
.symtype
, FALSE
),
1781 sym
->regrel_v3
.name
);
1785 loc
.kind
= loc_register
;
1786 loc
.reg
= sym
->register_v1
.reg
;
1788 symt_add_func_local(msc_dbg
->module
, curr_func
,
1790 block
, codeview_get_type(sym
->register_v1
.type
, FALSE
),
1791 terminate_string(&sym
->register_v1
.p_name
));
1794 loc
.kind
= loc_register
;
1795 loc
.reg
= sym
->register_v2
.reg
;
1797 symt_add_func_local(msc_dbg
->module
, curr_func
,
1799 block
, codeview_get_type(sym
->register_v2
.type
, FALSE
),
1800 terminate_string(&sym
->register_v2
.p_name
));
1803 loc
.kind
= loc_register
;
1804 loc
.reg
= sym
->register_v3
.reg
;
1806 symt_add_func_local(msc_dbg
->module
, curr_func
,
1808 block
, codeview_get_type(sym
->register_v3
.type
, FALSE
),
1809 sym
->register_v3
.name
);
1813 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1814 codeview_get_address(msc_dbg
, sym
->block_v1
.segment
, sym
->block_v1
.offset
),
1815 sym
->block_v1
.length
);
1818 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1819 codeview_get_address(msc_dbg
, sym
->block_v3
.segment
, sym
->block_v3
.offset
),
1820 sym
->block_v3
.length
);
1826 block
= symt_close_func_block(msc_dbg
->module
, curr_func
, block
, 0);
1830 symt_normalize_function(msc_dbg
->module
, curr_func
);
1835 case S_COMPILAND_V1
:
1836 TRACE("S-Compiland-V1 %x %s\n",
1837 sym
->compiland_v1
.unknown
, terminate_string(&sym
->compiland_v1
.p_name
));
1840 case S_COMPILAND_V2
:
1841 TRACE("S-Compiland-V2 %s\n", terminate_string(&sym
->compiland_v2
.p_name
));
1842 if (TRACE_ON(dbghelp_msc
))
1844 const char* ptr1
= sym
->compiland_v2
.p_name
.name
+ sym
->compiland_v2
.p_name
.namelen
;
1848 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1849 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1850 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1854 case S_COMPILAND_V3
:
1855 TRACE("S-Compiland-V3 %s\n", sym
->compiland_v3
.name
);
1856 if (TRACE_ON(dbghelp_msc
))
1858 const char* ptr1
= sym
->compiland_v3
.name
+ strlen(sym
->compiland_v3
.name
);
1862 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1863 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1864 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1870 TRACE("S-ObjName %s\n", terminate_string(&sym
->objname_v1
.p_name
));
1871 compiland
= symt_new_compiland(msc_dbg
->module
, 0 /* FIXME */,
1872 source_new(msc_dbg
->module
, NULL
,
1873 terminate_string(&sym
->objname_v1
.p_name
)));
1879 loc
.kind
= loc_absolute
;
1880 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
) - curr_func
->address
;
1881 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
, &loc
,
1882 terminate_string(&sym
->label_v1
.p_name
));
1884 else symt_new_label(msc_dbg
->module
, compiland
,
1885 terminate_string(&sym
->label_v1
.p_name
),
1886 codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
));
1891 loc
.kind
= loc_absolute
;
1892 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
) - curr_func
->address
;
1893 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1894 &loc
, sym
->label_v3
.name
);
1896 else symt_new_label(msc_dbg
->module
, compiland
, sym
->label_v3
.name
,
1897 codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
));
1903 const struct p_string
* name
;
1907 vlen
= leaf_as_variant(&v
, &sym
->constant_v1
.cvalue
);
1908 name
= (const struct p_string
*)((const char*)&sym
->constant_v1
.cvalue
+ vlen
);
1909 se
= codeview_get_type(sym
->constant_v1
.type
, FALSE
);
1911 TRACE("S-Constant-V1 %u %s %x\n",
1912 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v1
.type
);
1913 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1920 const struct p_string
* name
;
1924 vlen
= leaf_as_variant(&v
, &sym
->constant_v2
.cvalue
);
1925 name
= (const struct p_string
*)((const char*)&sym
->constant_v2
.cvalue
+ vlen
);
1926 se
= codeview_get_type(sym
->constant_v2
.type
, FALSE
);
1928 TRACE("S-Constant-V2 %u %s %x\n",
1929 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v2
.type
);
1930 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1941 vlen
= leaf_as_variant(&v
, &sym
->constant_v3
.cvalue
);
1942 name
= (const char*)&sym
->constant_v3
.cvalue
+ vlen
;
1943 se
= codeview_get_type(sym
->constant_v3
.type
, FALSE
);
1945 TRACE("S-Constant-V3 %u %s %x\n",
1946 v
.n1
.n2
.n3
.intVal
, name
, sym
->constant_v3
.type
);
1947 /* FIXME: we should add this as a constant value */
1948 symt_new_constant(msc_dbg
->module
, compiland
, name
, se
, &v
);
1953 if (sym
->udt_v1
.type
)
1955 if ((symt
= codeview_get_type(sym
->udt_v1
.type
, FALSE
)))
1956 symt_new_typedef(msc_dbg
->module
, symt
,
1957 terminate_string(&sym
->udt_v1
.p_name
));
1959 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1960 terminate_string(&sym
->udt_v1
.p_name
), sym
->udt_v1
.type
);
1964 if (sym
->udt_v2
.type
)
1966 if ((symt
= codeview_get_type(sym
->udt_v2
.type
, FALSE
)))
1967 symt_new_typedef(msc_dbg
->module
, symt
,
1968 terminate_string(&sym
->udt_v2
.p_name
));
1970 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1971 terminate_string(&sym
->udt_v2
.p_name
), sym
->udt_v2
.type
);
1975 if (sym
->udt_v3
.type
)
1977 if ((symt
= codeview_get_type(sym
->udt_v3
.type
, FALSE
)))
1978 symt_new_typedef(msc_dbg
->module
, symt
, sym
->udt_v3
.name
);
1980 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1981 sym
->udt_v3
.name
, sym
->udt_v3
.type
);
1986 * These are special, in that they are always followed by an
1987 * additional length-prefixed string which is *not* included
1988 * into the symbol length count. We need to skip it.
1996 name
= (const char*)sym
+ length
;
1997 length
+= (*name
+ 1 + 3) & ~3;
2001 case S_MSTOOL_V3
: /* just to silence a few warnings */
2002 case S_MSTOOLINFO_V3
:
2003 case S_MSTOOLENV_V3
:
2007 TRACE("Start search: seg=0x%x at offset 0x%08x\n",
2008 sym
->ssearch_v1
.segment
, sym
->ssearch_v1
.offset
);
2012 TRACE("S-Align V1\n");
2015 /* the symbols we can safely ignore for now */
2017 case S_FRAMEINFO_V2
:
2018 case S_SECUCOOKIE_V3
:
2020 case S_SUBSECTINFO_V3
:
2021 case S_ENTRYPOINT_V3
:
2022 case S_LOCAL_VS2013
:
2023 case S_CALLSITEINFO
:
2024 case S_DEFRANGE_REGISTER
:
2025 case S_DEFRANGE_FRAMEPOINTER_REL
:
2026 case S_DEFRANGE_SUBFIELD_REGISTER
:
2027 case S_FPOFF_VS2013
:
2028 case S_DEFRANGE_REGISTER_REL
:
2031 case S_INLINESITE_END
:
2034 TRACE("Unsupported symbol id %x\n", sym
->generic
.id
);
2038 FIXME("Unsupported symbol id %x\n", sym
->generic
.id
);
2039 dump(sym
, 2 + sym
->generic
.len
);
2044 if (curr_func
) symt_normalize_function(msc_dbg
->module
, curr_func
);
2049 static BOOL
codeview_snarf_public(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
2050 int offset
, int size
)
2054 struct symt_compiland
* compiland
= NULL
;
2057 * Loop over the different types of records and whenever we
2058 * find something we are interested in, record it and move on.
2060 for (i
= offset
; i
< size
; i
+= length
)
2062 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
2063 length
= sym
->generic
.len
+ 2;
2064 if (i
+ length
> size
) break;
2065 if (!sym
->generic
.id
|| length
< 4) break;
2066 if (length
& 3) FIXME("unpadded len %u\n", length
);
2068 switch (sym
->generic
.id
)
2070 case S_PUB_V1
: /* FIXME is this really a 'data_v1' structure ?? */
2071 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2073 symt_new_public(msc_dbg
->module
, compiland
,
2074 terminate_string(&sym
->data_v1
.p_name
),
2075 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
), 1);
2078 case S_PUB_V2
: /* FIXME is this really a 'data_v2' structure ?? */
2079 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2081 symt_new_public(msc_dbg
->module
, compiland
,
2082 terminate_string(&sym
->data_v2
.p_name
),
2083 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
), 1);
2088 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2090 symt_new_public(msc_dbg
->module
, compiland
,
2092 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
), 1);
2095 case S_PUB_FUNC1_V3
:
2096 case S_PUB_FUNC2_V3
: /* using a data_v3 isn't what we'd expect */
2098 /* FIXME: this is plain wrong (from a simple test) */
2099 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2101 symt_new_public(msc_dbg
->module
, compiland
,
2103 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
), 1);
2108 * Global and local data symbols. We don't associate these
2109 * with any given source file.
2113 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
2114 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
2115 sym
->generic
.id
== S_LDATA_V1
, FALSE
, FALSE
);
2119 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
2120 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
2121 sym
->generic
.id
== S_LDATA_V2
, FALSE
, FALSE
);
2125 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
2126 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
2127 sym
->generic
.id
== S_LDATA_V3
, FALSE
, FALSE
);
2130 /* variables with thread storage */
2133 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v1
.p_name
),
2134 sym
->thread_v1
.segment
, sym
->thread_v1
.offset
, sym
->thread_v1
.symtype
,
2135 sym
->generic
.id
== S_LTHREAD_V1
, TRUE
, FALSE
);
2139 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v2
.p_name
),
2140 sym
->thread_v2
.segment
, sym
->thread_v2
.offset
, sym
->thread_v2
.symtype
,
2141 sym
->generic
.id
== S_LTHREAD_V2
, TRUE
, FALSE
);
2145 codeview_add_variable(msc_dbg
, compiland
, sym
->thread_v3
.name
,
2146 sym
->thread_v3
.segment
, sym
->thread_v3
.offset
, sym
->thread_v3
.symtype
,
2147 sym
->generic
.id
== S_LTHREAD_V3
, TRUE
, FALSE
);
2151 * These are special, in that they are always followed by an
2152 * additional length-prefixed string which is *not* included
2153 * into the symbol length count. We need to skip it.
2158 length
+= (((const char*)sym
)[length
] + 1 + 3) & ~3;
2161 msc_dbg
->module
->sortlist_valid
= TRUE
;
2163 msc_dbg
->module
->sortlist_valid
= FALSE
;
2167 /*========================================================================
2171 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
,
2177 if (!size
) return NULL
;
2179 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2180 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2182 for (i
= 0; i
< num_blocks
; i
++)
2183 memcpy(buffer
+ i
* pdb
->block_size
,
2184 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2189 static void* pdb_ds_read(const struct PDB_DS_HEADER
* pdb
, const DWORD
* block_list
,
2195 if (!size
) return NULL
;
2197 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2198 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2200 for (i
= 0; i
< num_blocks
; i
++)
2201 memcpy(buffer
+ i
* pdb
->block_size
,
2202 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2207 static void* pdb_read_jg_file(const struct PDB_JG_HEADER
* pdb
,
2208 const struct PDB_JG_TOC
* toc
, DWORD file_nr
)
2210 const WORD
* block_list
;
2213 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2215 block_list
= (const WORD
*) &toc
->file
[toc
->num_files
];
2216 for (i
= 0; i
< file_nr
; i
++)
2217 block_list
+= (toc
->file
[i
].size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2219 return pdb_jg_read(pdb
, block_list
, toc
->file
[file_nr
].size
);
2222 static void* pdb_read_ds_file(const struct PDB_DS_HEADER
* pdb
,
2223 const struct PDB_DS_TOC
* toc
, DWORD file_nr
)
2225 const DWORD
* block_list
;
2228 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2229 if (toc
->file_size
[file_nr
] == 0 || toc
->file_size
[file_nr
] == 0xFFFFFFFF) return NULL
;
2231 block_list
= &toc
->file_size
[toc
->num_files
];
2232 for (i
= 0; i
< file_nr
; i
++)
2233 block_list
+= (toc
->file_size
[i
] + pdb
->block_size
- 1) / pdb
->block_size
;
2235 return pdb_ds_read(pdb
, block_list
, toc
->file_size
[file_nr
]);
2238 static void* pdb_read_file(const struct pdb_file_info
* pdb_file
,
2241 switch (pdb_file
->kind
)
2244 return pdb_read_jg_file((const struct PDB_JG_HEADER
*)pdb_file
->image
,
2245 pdb_file
->u
.jg
.toc
, file_nr
);
2247 return pdb_read_ds_file((const struct PDB_DS_HEADER
*)pdb_file
->image
,
2248 pdb_file
->u
.ds
.toc
, file_nr
);
2253 static unsigned pdb_get_file_size(const struct pdb_file_info
* pdb_file
, DWORD file_nr
)
2255 switch (pdb_file
->kind
)
2257 case PDB_JG
: return pdb_file
->u
.jg
.toc
->file
[file_nr
].size
;
2258 case PDB_DS
: return pdb_file
->u
.ds
.toc
->file_size
[file_nr
];
2263 static void pdb_free(void* buffer
)
2265 HeapFree(GetProcessHeap(), 0, buffer
);
2268 static void pdb_free_file(struct pdb_file_info
* pdb_file
)
2270 switch (pdb_file
->kind
)
2273 pdb_free(pdb_file
->u
.jg
.toc
);
2274 pdb_file
->u
.jg
.toc
= NULL
;
2277 pdb_free(pdb_file
->u
.ds
.toc
);
2278 pdb_file
->u
.ds
.toc
= NULL
;
2281 HeapFree(GetProcessHeap(), 0, pdb_file
->stream_dict
);
2284 static void pdb_load_stream_name_table(struct pdb_file_info
* pdb_file
, const char* str
, unsigned cb
)
2292 pdw
= (DWORD
*)(str
+ cb
);
2296 pdb_file
->stream_dict
= HeapAlloc(GetProcessHeap(), 0, (numok
+ 1) * sizeof(struct pdb_stream_name
) + cb
);
2297 if (!pdb_file
->stream_dict
) return;
2298 cpstr
= (char*)(pdb_file
->stream_dict
+ numok
+ 1);
2299 memcpy(cpstr
, str
, cb
);
2301 /* bitfield: first dword is len (in dword), then data */
2303 pdw
+= *ok_bits
++ + 1;
2306 FIXME("unexpected value\n");
2310 for (i
= j
= 0; i
< count
; i
++)
2312 if (ok_bits
[i
/ 32] & (1 << (i
% 32)))
2314 if (j
>= numok
) break;
2315 pdb_file
->stream_dict
[j
].name
= &cpstr
[*pdw
++];
2316 pdb_file
->stream_dict
[j
].index
= *pdw
++;
2321 pdb_file
->stream_dict
[numok
].name
= NULL
;
2322 pdb_file
->fpoext_stream
= -1;
2325 static unsigned pdb_get_stream_by_name(const struct pdb_file_info
* pdb_file
, const char* name
)
2327 struct pdb_stream_name
* psn
;
2329 for (psn
= pdb_file
->stream_dict
; psn
&& psn
->name
; psn
++)
2331 if (!strcmp(psn
->name
, name
)) return psn
->index
;
2336 static void* pdb_read_strings(const struct pdb_file_info
* pdb_file
)
2341 idx
= pdb_get_stream_by_name(pdb_file
, "/names");
2344 ret
= pdb_read_file( pdb_file
, idx
);
2345 if (ret
&& *(const DWORD
*)ret
== 0xeffeeffe) return ret
;
2348 WARN("string table not found\n");
2352 static void pdb_module_remove(struct process
* pcsn
, struct module_format
* modfmt
)
2356 for (i
= 0; i
< modfmt
->u
.pdb_info
->used_subfiles
; i
++)
2358 pdb_free_file(&modfmt
->u
.pdb_info
->pdb_files
[i
]);
2359 if (modfmt
->u
.pdb_info
->pdb_files
[i
].image
)
2360 UnmapViewOfFile(modfmt
->u
.pdb_info
->pdb_files
[i
].image
);
2361 if (modfmt
->u
.pdb_info
->pdb_files
[i
].hMap
)
2362 CloseHandle(modfmt
->u
.pdb_info
->pdb_files
[i
].hMap
);
2364 HeapFree(GetProcessHeap(), 0, modfmt
);
2367 static void pdb_convert_types_header(PDB_TYPES
* types
, const BYTE
* image
)
2369 memset(types
, 0, sizeof(PDB_TYPES
));
2372 if (*(const DWORD
*)image
< 19960000) /* FIXME: correct version? */
2374 /* Old version of the types record header */
2375 const PDB_TYPES_OLD
* old
= (const PDB_TYPES_OLD
*)image
;
2376 types
->version
= old
->version
;
2377 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
2378 types
->type_size
= old
->type_size
;
2379 types
->first_index
= old
->first_index
;
2380 types
->last_index
= old
->last_index
;
2381 types
->file
= old
->file
;
2385 /* New version of the types record header */
2386 *types
= *(const PDB_TYPES
*)image
;
2390 static void pdb_convert_symbols_header(PDB_SYMBOLS
* symbols
,
2391 int* header_size
, const BYTE
* image
)
2393 memset(symbols
, 0, sizeof(PDB_SYMBOLS
));
2396 if (*(const DWORD
*)image
!= 0xffffffff)
2398 /* Old version of the symbols record header */
2399 const PDB_SYMBOLS_OLD
* old
= (const PDB_SYMBOLS_OLD
*)image
;
2400 symbols
->version
= 0;
2401 symbols
->module_size
= old
->module_size
;
2402 symbols
->offset_size
= old
->offset_size
;
2403 symbols
->hash_size
= old
->hash_size
;
2404 symbols
->srcmodule_size
= old
->srcmodule_size
;
2405 symbols
->pdbimport_size
= 0;
2406 symbols
->hash1_file
= old
->hash1_file
;
2407 symbols
->hash2_file
= old
->hash2_file
;
2408 symbols
->gsym_file
= old
->gsym_file
;
2410 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
2414 /* New version of the symbols record header */
2415 *symbols
= *(const PDB_SYMBOLS
*)image
;
2416 *header_size
= sizeof(PDB_SYMBOLS
);
2420 static void pdb_convert_symbol_file(const PDB_SYMBOLS
* symbols
,
2421 PDB_SYMBOL_FILE_EX
* sfile
,
2422 unsigned* size
, const void* image
)
2425 if (symbols
->version
< 19970000)
2427 const PDB_SYMBOL_FILE
*sym_file
= image
;
2428 memset(sfile
, 0, sizeof(*sfile
));
2429 sfile
->file
= sym_file
->file
;
2430 sfile
->range
.index
= sym_file
->range
.index
;
2431 sfile
->symbol_size
= sym_file
->symbol_size
;
2432 sfile
->lineno_size
= sym_file
->lineno_size
;
2433 *size
= sizeof(PDB_SYMBOL_FILE
) - 1;
2437 memcpy(sfile
, image
, sizeof(PDB_SYMBOL_FILE_EX
));
2438 *size
= sizeof(PDB_SYMBOL_FILE_EX
) - 1;
2442 static HANDLE
map_pdb_file(const struct process
* pcs
,
2443 const struct pdb_lookup
* lookup
,
2444 struct module
* module
)
2446 HANDLE hFile
, hMap
= NULL
;
2447 char dbg_file_path
[MAX_PATH
];
2450 switch (lookup
->kind
)
2453 ret
= path_find_symbol_file(pcs
, lookup
->filename
, NULL
, lookup
->timestamp
,
2454 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2457 ret
= path_find_symbol_file(pcs
, lookup
->filename
, &lookup
->guid
, 0,
2458 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2463 WARN("\tCouldn't find %s\n", lookup
->filename
);
2466 if ((hFile
= CreateFileA(dbg_file_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2467 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) != INVALID_HANDLE_VALUE
)
2469 hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
2475 static void pdb_process_types(const struct msc_debug_info
* msc_dbg
,
2476 const struct pdb_file_info
* pdb_file
)
2478 BYTE
* types_image
= NULL
;
2480 types_image
= pdb_read_file(pdb_file
, 2);
2484 struct codeview_type_parse ctp
;
2489 pdb_convert_types_header(&types
, types_image
);
2491 /* Check for unknown versions */
2492 switch (types
.version
)
2494 case 19950410: /* VC 4.0 */
2496 case 19961031: /* VC 5.0 / 6.0 */
2497 case 19990903: /* VC 7.0 */
2498 case 20040203: /* VC 8.0 */
2501 ERR("-Unknown type info version %d\n", types
.version
);
2504 ctp
.module
= msc_dbg
->module
;
2505 /* reconstruct the types offset...
2506 * FIXME: maybe it's present in the newest PDB_TYPES structures
2508 total
= types
.last_index
- types
.first_index
+ 1;
2509 offset
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD
) * total
);
2510 ctp
.table
= ptr
= types_image
+ types
.type_offset
;
2512 while (ptr
< ctp
.table
+ types
.type_size
&& ctp
.num
< total
)
2514 offset
[ctp
.num
++] = ptr
- ctp
.table
;
2515 ptr
+= ((const union codeview_type
*)ptr
)->generic
.len
+ 2;
2517 ctp
.offset
= offset
;
2519 /* Read type table */
2520 codeview_parse_type_table(&ctp
);
2521 HeapFree(GetProcessHeap(), 0, offset
);
2522 pdb_free(types_image
);
2526 static const char PDB_JG_IDENT
[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
2527 static const char PDB_DS_IDENT
[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
2529 /******************************************************************
2532 * Tries to load a pdb file
2533 * 'matched' is filled with the number of correct matches for this file:
2534 * - age counts for one
2535 * - timestamp or guid depending on kind counts for one
2536 * a wrong kind of file returns FALSE (FIXME ?)
2538 static BOOL
pdb_init(const struct pdb_lookup
* pdb_lookup
, struct pdb_file_info
* pdb_file
,
2539 const char* image
, unsigned* matched
)
2543 /* check the file header, and if ok, load the TOC */
2544 TRACE("PDB(%s): %.40s\n", pdb_lookup
->filename
, debugstr_an(image
, 40));
2547 if (!memcmp(image
, PDB_JG_IDENT
, sizeof(PDB_JG_IDENT
)))
2549 const struct PDB_JG_HEADER
* pdb
= (const struct PDB_JG_HEADER
*)image
;
2550 struct PDB_JG_ROOT
* root
;
2552 pdb_file
->u
.jg
.toc
= pdb_jg_read(pdb
, pdb
->toc_block
, pdb
->toc
.size
);
2553 root
= pdb_read_jg_file(pdb
, pdb_file
->u
.jg
.toc
, 1);
2556 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2559 switch (root
->Version
)
2561 case 19950623: /* VC 4.0 */
2563 case 19960307: /* VC 5.0 */
2564 case 19970604: /* VC 6.0 */
2567 ERR("-Unknown root block version %d\n", root
->Version
);
2569 if (pdb_lookup
->kind
!= PDB_JG
)
2571 WARN("Found %s, but wrong PDB kind\n", pdb_lookup
->filename
);
2575 pdb_file
->kind
= PDB_JG
;
2576 pdb_file
->u
.jg
.timestamp
= root
->TimeDateStamp
;
2577 pdb_file
->age
= root
->Age
;
2578 if (root
->TimeDateStamp
== pdb_lookup
->timestamp
) (*matched
)++;
2579 else WARN("Found %s, but wrong signature: %08x %08x\n",
2580 pdb_lookup
->filename
, root
->TimeDateStamp
, pdb_lookup
->timestamp
);
2581 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2582 else WARN("Found %s, but wrong age: %08x %08x\n",
2583 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2584 TRACE("found JG for %s: age=%x timestamp=%x\n",
2585 pdb_lookup
->filename
, root
->Age
, root
->TimeDateStamp
);
2586 pdb_load_stream_name_table(pdb_file
, &root
->names
[0], root
->cbNames
);
2590 else if (!memcmp(image
, PDB_DS_IDENT
, sizeof(PDB_DS_IDENT
)))
2592 const struct PDB_DS_HEADER
* pdb
= (const struct PDB_DS_HEADER
*)image
;
2593 struct PDB_DS_ROOT
* root
;
2595 pdb_file
->u
.ds
.toc
=
2597 (const DWORD
*)((const char*)pdb
+ pdb
->toc_page
* pdb
->block_size
),
2599 root
= pdb_read_ds_file(pdb
, pdb_file
->u
.ds
.toc
, 1);
2602 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2605 switch (root
->Version
)
2610 ERR("-Unknown root block version %d\n", root
->Version
);
2612 pdb_file
->kind
= PDB_DS
;
2613 pdb_file
->u
.ds
.guid
= root
->guid
;
2614 pdb_file
->age
= root
->Age
;
2615 if (!memcmp(&root
->guid
, &pdb_lookup
->guid
, sizeof(GUID
))) (*matched
)++;
2616 else WARN("Found %s, but wrong GUID: %s %s\n",
2617 pdb_lookup
->filename
, debugstr_guid(&root
->guid
),
2618 debugstr_guid(&pdb_lookup
->guid
));
2619 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2620 else WARN("Found %s, but wrong age: %08x %08x\n",
2621 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2622 TRACE("found DS for %s: age=%x guid=%s\n",
2623 pdb_lookup
->filename
, root
->Age
, debugstr_guid(&root
->guid
));
2624 pdb_load_stream_name_table(pdb_file
, &root
->names
[0], root
->cbNames
);
2629 if (0) /* some tool to dump the internal files from a PDB file */
2633 switch (pdb_file
->kind
)
2635 case PDB_JG
: num_files
= pdb_file
->u
.jg
.toc
->num_files
; break;
2636 case PDB_DS
: num_files
= pdb_file
->u
.ds
.toc
->num_files
; break;
2639 for (i
= 1; i
< num_files
; i
++)
2641 unsigned char* x
= pdb_read_file(pdb_file
, i
);
2642 FIXME("********************** [%u]: size=%08x\n",
2643 i
, pdb_get_file_size(pdb_file
, i
));
2644 dump(x
, pdb_get_file_size(pdb_file
, i
));
2651 static BOOL
pdb_process_internal(const struct process
* pcs
,
2652 const struct msc_debug_info
* msc_dbg
,
2653 const struct pdb_lookup
* pdb_lookup
,
2654 struct pdb_module_info
* pdb_module_info
,
2655 unsigned module_index
);
2657 static void pdb_process_symbol_imports(const struct process
* pcs
,
2658 const struct msc_debug_info
* msc_dbg
,
2659 const PDB_SYMBOLS
* symbols
,
2660 const void* symbols_image
,
2662 const struct pdb_lookup
* pdb_lookup
,
2663 struct pdb_module_info
* pdb_module_info
,
2664 unsigned module_index
)
2666 if (module_index
== -1 && symbols
&& symbols
->pdbimport_size
)
2668 const PDB_SYMBOL_IMPORT
*imp
;
2673 struct pdb_file_info sf0
= pdb_module_info
->pdb_files
[0];
2675 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2676 symbols
->module_size
+ symbols
->offset_size
+
2677 symbols
->hash_size
+ symbols
->srcmodule_size
);
2679 last
= (const char*)imp
+ symbols
->pdbimport_size
;
2680 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
2682 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
2683 if (i
>= CV_MAX_MODULES
) FIXME("Out of bounds!!!\n");
2684 if (!strcasecmp(pdb_lookup
->filename
, imp
->filename
))
2686 if (module_index
!= -1) FIXME("Twice the entry\n");
2687 else module_index
= i
;
2688 pdb_module_info
->pdb_files
[i
] = sf0
;
2692 struct pdb_lookup imp_pdb_lookup
;
2694 /* FIXME: this is an import of a JG PDB file
2695 * how's a DS PDB handled ?
2697 imp_pdb_lookup
.filename
= imp
->filename
;
2698 imp_pdb_lookup
.kind
= PDB_JG
;
2699 imp_pdb_lookup
.timestamp
= imp
->TimeDateStamp
;
2700 imp_pdb_lookup
.age
= imp
->Age
;
2701 TRACE("got for %s: age=%u ts=%x\n",
2702 imp
->filename
, imp
->Age
, imp
->TimeDateStamp
);
2703 pdb_process_internal(pcs
, msc_dbg
, &imp_pdb_lookup
, pdb_module_info
, i
);
2706 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)first
+ ((ptr
- (const char*)first
+ strlen(ptr
) + 1 + 3) & ~3));
2708 pdb_module_info
->used_subfiles
= i
;
2710 if (module_index
== -1)
2713 pdb_module_info
->used_subfiles
= 1;
2715 cv_current_module
= &cv_zmodules
[module_index
];
2716 if (cv_current_module
->allowed
) FIXME("Already allowed??\n");
2717 cv_current_module
->allowed
= TRUE
;
2720 static BOOL
pdb_process_internal(const struct process
* pcs
,
2721 const struct msc_debug_info
* msc_dbg
,
2722 const struct pdb_lookup
* pdb_lookup
,
2723 struct pdb_module_info
* pdb_module_info
,
2724 unsigned module_index
)
2728 BYTE
* symbols_image
= NULL
;
2729 char* files_image
= NULL
;
2730 DWORD files_size
= 0;
2732 struct pdb_file_info
* pdb_file
;
2734 TRACE("Processing PDB file %s\n", pdb_lookup
->filename
);
2736 pdb_file
= &pdb_module_info
->pdb_files
[module_index
== -1 ? 0 : module_index
];
2737 /* Open and map() .PDB file */
2738 if ((hMap
= map_pdb_file(pcs
, pdb_lookup
, msc_dbg
->module
)) == NULL
||
2739 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2741 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2745 if (!pdb_init(pdb_lookup
, pdb_file
, image
, &matched
) || matched
!= 2)
2748 UnmapViewOfFile(image
);
2752 pdb_file
->hMap
= hMap
;
2753 pdb_file
->image
= image
;
2754 symbols_image
= pdb_read_file(pdb_file
, 3);
2757 PDB_SYMBOLS symbols
;
2761 int header_size
= 0;
2762 PDB_STREAM_INDEXES
* psi
;
2764 pdb_convert_symbols_header(&symbols
, &header_size
, symbols_image
);
2765 switch (symbols
.version
)
2767 case 0: /* VC 4.0 */
2768 case 19960307: /* VC 5.0 */
2769 case 19970606: /* VC 6.0 */
2773 ERR("-Unknown symbol info version %d %08x\n",
2774 symbols
.version
, symbols
.version
);
2777 switch (symbols
.stream_index_size
)
2780 case sizeof(PDB_STREAM_INDEXES_OLD
):
2781 /* no fpo ext stream in this case */
2783 case sizeof(PDB_STREAM_INDEXES
):
2784 psi
= (PDB_STREAM_INDEXES
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2785 symbols
.module_size
+ symbols
.offset_size
+
2786 symbols
.hash_size
+ symbols
.srcmodule_size
+
2787 symbols
.pdbimport_size
+ symbols
.unknown2_size
);
2788 pdb_file
->fpoext_stream
= psi
->FPO_EXT
;
2791 FIXME("Unknown PDB_STREAM_INDEXES size (%d)\n", symbols
.stream_index_size
);
2794 files_image
= pdb_read_strings(pdb_file
);
2795 if (files_image
) files_size
= *(const DWORD
*)(files_image
+ 8);
2797 pdb_process_symbol_imports(pcs
, msc_dbg
, &symbols
, symbols_image
, image
,
2798 pdb_lookup
, pdb_module_info
, module_index
);
2799 pdb_process_types(msc_dbg
, pdb_file
);
2801 /* Read global symbol table */
2802 globalimage
= pdb_read_file(pdb_file
, symbols
.gsym_file
);
2805 codeview_snarf(msc_dbg
, globalimage
, 0,
2806 pdb_get_file_size(pdb_file
, symbols
.gsym_file
), FALSE
);
2809 /* Read per-module symbols' tables */
2810 file
= symbols_image
+ header_size
;
2811 while (file
- symbols_image
< header_size
+ symbols
.module_size
)
2813 PDB_SYMBOL_FILE_EX sfile
;
2814 const char* file_name
;
2817 HeapValidate(GetProcessHeap(), 0, NULL
);
2818 pdb_convert_symbol_file(&symbols
, &sfile
, &size
, file
);
2820 modimage
= pdb_read_file(pdb_file
, sfile
.file
);
2823 if (sfile
.symbol_size
)
2824 codeview_snarf(msc_dbg
, modimage
, sizeof(DWORD
),
2825 sfile
.symbol_size
, TRUE
);
2827 if (sfile
.lineno_size
)
2828 codeview_snarf_linetab(msc_dbg
,
2829 modimage
+ sfile
.symbol_size
,
2831 pdb_file
->kind
== PDB_JG
);
2833 codeview_snarf_linetab2(msc_dbg
, modimage
+ sfile
.symbol_size
+ sfile
.lineno_size
,
2834 pdb_get_file_size(pdb_file
, sfile
.file
) - sfile
.symbol_size
- sfile
.lineno_size
,
2835 files_image
+ 12, files_size
);
2839 file_name
= (const char*)file
+ size
;
2840 file_name
+= strlen(file_name
) + 1;
2841 file
= (BYTE
*)((DWORD_PTR
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3);
2843 /* finish the remaining public and global information */
2846 codeview_snarf_public(msc_dbg
, globalimage
, 0,
2847 pdb_get_file_size(pdb_file
, symbols
.gsym_file
));
2848 pdb_free(globalimage
);
2852 pdb_process_symbol_imports(pcs
, msc_dbg
, NULL
, NULL
, image
,
2853 pdb_lookup
, pdb_module_info
, module_index
);
2855 pdb_free(symbols_image
);
2856 pdb_free(files_image
);
2861 static BOOL
pdb_process_file(const struct process
* pcs
,
2862 const struct msc_debug_info
* msc_dbg
,
2863 struct pdb_lookup
* pdb_lookup
)
2866 struct module_format
* modfmt
;
2867 struct pdb_module_info
* pdb_module_info
;
2869 modfmt
= HeapAlloc(GetProcessHeap(), 0,
2870 sizeof(struct module_format
) + sizeof(struct pdb_module_info
));
2871 if (!modfmt
) return FALSE
;
2873 pdb_module_info
= (void*)(modfmt
+ 1);
2874 msc_dbg
->module
->format_info
[DFI_PDB
] = modfmt
;
2875 modfmt
->module
= msc_dbg
->module
;
2876 modfmt
->remove
= pdb_module_remove
;
2877 modfmt
->loc_compute
= NULL
;
2878 modfmt
->u
.pdb_info
= pdb_module_info
;
2880 memset(cv_zmodules
, 0, sizeof(cv_zmodules
));
2881 codeview_init_basic_types(msc_dbg
->module
);
2882 ret
= pdb_process_internal(pcs
, msc_dbg
, pdb_lookup
,
2883 msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
, -1);
2884 codeview_clear_type_table();
2887 struct pdb_module_info
* pdb_info
= msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
;
2888 msc_dbg
->module
->module
.SymType
= SymCv
;
2889 if (pdb_info
->pdb_files
[0].kind
== PDB_JG
)
2890 msc_dbg
->module
->module
.PdbSig
= pdb_info
->pdb_files
[0].u
.jg
.timestamp
;
2892 msc_dbg
->module
->module
.PdbSig70
= pdb_info
->pdb_files
[0].u
.ds
.guid
;
2893 msc_dbg
->module
->module
.PdbAge
= pdb_info
->pdb_files
[0].age
;
2894 MultiByteToWideChar(CP_ACP
, 0, pdb_lookup
->filename
, -1,
2895 msc_dbg
->module
->module
.LoadedPdbName
,
2896 sizeof(msc_dbg
->module
->module
.LoadedPdbName
) / sizeof(WCHAR
));
2897 /* FIXME: we could have a finer grain here */
2898 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
2899 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
2900 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
2901 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
2902 msc_dbg
->module
->module
.Publics
= TRUE
;
2906 msc_dbg
->module
->format_info
[DFI_PDB
] = NULL
;
2907 HeapFree(GetProcessHeap(), 0, modfmt
);
2912 BOOL
pdb_fetch_file_info(const struct pdb_lookup
* pdb_lookup
, unsigned* matched
)
2914 HANDLE hFile
, hMap
= NULL
;
2917 struct pdb_file_info pdb_file
;
2919 if ((hFile
= CreateFileA(pdb_lookup
->filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2920 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) == INVALID_HANDLE_VALUE
||
2921 ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
2922 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2924 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2929 ret
= pdb_init(pdb_lookup
, &pdb_file
, image
, matched
);
2930 pdb_free_file(&pdb_file
);
2933 if (image
) UnmapViewOfFile(image
);
2934 if (hMap
) CloseHandle(hMap
);
2935 if (hFile
!= INVALID_HANDLE_VALUE
) CloseHandle(hFile
);
2940 /*========================================================================
2941 * FPO unwinding code
2944 /* Stack unwinding is based on postfixed operations.
2945 * Let's define our Postfix EValuator
2947 #define PEV_MAX_LEN 32
2950 struct cpu_stack_walk
* csw
;
2952 struct vector stack
;
2954 struct hash_table values
;
2961 struct hash_table_elt elt
;
2964 #define PEV_ERROR(pev, msg) snprintf((pev)->error, sizeof((pev)->error), "%s", (msg))
2965 #define PEV_ERROR1(pev, msg, pmt) snprintf((pev)->error, sizeof((pev)->error), (msg), (pmt))
2968 static void pev_dump_stack(struct pevaluator
* pev
)
2971 FIXME("stack #%d\n", pev
->stk_index
);
2972 for (i
= 0; i
< pev
->stk_index
; i
++)
2974 FIXME("\t%d) %s\n", i
, *(char**)vector_at(&pev
->stack
, i
));
2979 /* get the value out of an operand (variable or literal) */
2980 static BOOL
pev_get_val(struct pevaluator
* pev
, const char* str
, DWORD_PTR
* val
)
2983 struct hash_table_iter hti
;
2990 hash_table_iter_init(&pev
->values
, &hti
, str
);
2991 while ((ptr
= hash_table_iter_up(&hti
)))
2993 if (!strcmp(CONTAINING_RECORD(ptr
, struct zvalue
, elt
)->elt
.name
, str
))
2995 *val
= CONTAINING_RECORD(ptr
, struct zvalue
, elt
)->value
;
2999 return PEV_ERROR1(pev
, "get_zvalue: no value found (%s)", str
);
3001 *val
= strtol(str
, &n
, 10);
3002 if (n
== str
|| *n
!= '\0')
3003 return PEV_ERROR1(pev
, "get_val: not a literal (%s)", str
);
3008 /* push an operand onto the stack */
3009 static BOOL
pev_push(struct pevaluator
* pev
, const char* elt
)
3012 if (pev
->stk_index
< vector_length(&pev
->stack
))
3013 at
= vector_at(&pev
->stack
, pev
->stk_index
);
3015 at
= vector_add(&pev
->stack
, &pev
->pool
);
3016 if (!at
) return PEV_ERROR(pev
, "push: out of memory");
3017 *at
= pool_strdup(&pev
->pool
, elt
);
3022 /* pop an operand from the stack */
3023 static BOOL
pev_pop(struct pevaluator
* pev
, char* elt
)
3025 char** at
= vector_at(&pev
->stack
, --pev
->stk_index
);
3026 if (!at
) return PEV_ERROR(pev
, "pop: stack empty");
3031 /* pop an operand from the stack, and gets its value */
3032 static BOOL
pev_pop_val(struct pevaluator
* pev
, DWORD_PTR
* val
)
3034 char p
[PEV_MAX_LEN
];
3036 return pev_pop(pev
, p
) && pev_get_val(pev
, p
, val
);
3039 /* set var 'name' a new value (creates the var if it doesn't exist) */
3040 static BOOL
pev_set_value(struct pevaluator
* pev
, const char* name
, DWORD_PTR val
)
3042 struct hash_table_iter hti
;
3045 hash_table_iter_init(&pev
->values
, &hti
, name
);
3046 while ((ptr
= hash_table_iter_up(&hti
)))
3048 if (!strcmp(CONTAINING_RECORD(ptr
, struct zvalue
, elt
)->elt
.name
, name
))
3050 CONTAINING_RECORD(ptr
, struct zvalue
, elt
)->value
= val
;
3056 struct zvalue
* zv
= pool_alloc(&pev
->pool
, sizeof(*zv
));
3057 if (!zv
) return PEV_ERROR(pev
, "set_value: out of memory");
3060 zv
->elt
.name
= pool_strdup(&pev
->pool
, name
);
3061 hash_table_add(&pev
->values
, &zv
->elt
);
3066 /* execute a binary operand from the two top most values on the stack.
3067 * puts result on top of the stack */
3068 static BOOL
pev_binop(struct pevaluator
* pev
, char op
)
3070 char res
[PEV_MAX_LEN
];
3071 DWORD_PTR v1
, v2
, c
;
3073 if (!pev_pop_val(pev
, &v1
) || !pev_pop_val(pev
, &v2
)) return FALSE
;
3076 case '+': c
= v1
+ v2
; break;
3077 case '-': c
= v1
- v2
; break;
3078 case '*': c
= v1
* v2
; break;
3079 case '/': c
= v1
/ v2
; break;
3080 case '%': c
= v1
% v2
; break;
3081 default: return PEV_ERROR1(pev
, "binop: unknown op (%c)", op
);
3083 snprintf(res
, sizeof(res
), "%ld", c
);
3088 /* pops top most operand, dereference it, on pushes the result on top of the stack */
3089 static BOOL
pev_deref(struct pevaluator
* pev
)
3091 char res
[PEV_MAX_LEN
];
3094 if (!pev_pop_val(pev
, &v1
)) return FALSE
;
3095 if (!sw_read_mem(pev
->csw
, v1
, &v2
, sizeof(v2
)))
3096 return PEV_ERROR1(pev
, "deref: cannot read mem at %lx\n", v1
);
3097 snprintf(res
, sizeof(res
), "%ld", v2
);
3102 /* assign value to variable (from two top most operands) */
3103 static BOOL
pev_assign(struct pevaluator
* pev
)
3105 char p2
[PEV_MAX_LEN
];
3108 if (!pev_pop_val(pev
, &v1
) || !pev_pop(pev
, p2
)) return FALSE
;
3109 if (p2
[0] != '$') return PEV_ERROR1(pev
, "assign: %s isn't a variable", p2
);
3110 pev_set_value(pev
, p2
, v1
);
3115 /* initializes the postfix evaluator */
3116 static void pev_init(struct pevaluator
* pev
, struct cpu_stack_walk
* csw
,
3117 PDB_FPO_DATA
* fpoext
, struct pdb_cmd_pair
* cpair
)
3120 pool_init(&pev
->pool
, 512);
3121 vector_init(&pev
->stack
, sizeof(char*), 8);
3123 hash_table_init(&pev
->pool
, &pev
->values
, 8);
3124 pev
->error
[0] = '\0';
3125 for (; cpair
->name
; cpair
++)
3126 pev_set_value(pev
, cpair
->name
, *cpair
->pvalue
);
3127 pev_set_value(pev
, ".raSearchStart", fpoext
->start
);
3128 pev_set_value(pev
, ".cbLocals", fpoext
->locals_size
);
3129 pev_set_value(pev
, ".cbParams", fpoext
->params_size
);
3130 pev_set_value(pev
, ".cbSavedRegs", fpoext
->savedregs_size
);
3133 static BOOL
pev_free(struct pevaluator
* pev
, struct pdb_cmd_pair
* cpair
)
3137 if (cpair
) for (; cpair
->name
; cpair
++)
3139 if (pev_get_val(pev
, cpair
->name
, &val
))
3140 *cpair
->pvalue
= val
;
3142 pool_destroy(&pev
->pool
);
3146 static BOOL
pdb_parse_cmd_string(struct cpu_stack_walk
* csw
, PDB_FPO_DATA
* fpoext
,
3147 const char* cmd
, struct pdb_cmd_pair
* cpair
)
3149 char token
[PEV_MAX_LEN
];
3153 struct pevaluator pev
;
3155 pev_init(&pev
, csw
, fpoext
, cpair
);
3156 for (ptr
= cmd
; !over
; ptr
++)
3158 if (*ptr
== ' ' || (over
= *ptr
== '\0'))
3162 if (!strcmp(token
, "+") || !strcmp(token
, "-") || !strcmp(token
, "*") ||
3163 !strcmp(token
, "/") || !strcmp(token
, "%"))
3165 if (!pev_binop(&pev
, token
[0])) goto done
;
3167 else if (!strcmp(token
, "^"))
3169 if (!pev_deref(&pev
)) goto done
;
3171 else if (!strcmp(token
, "="))
3173 if (!pev_assign(&pev
)) goto done
;
3177 if (!pev_push(&pev
, token
)) goto done
;
3183 if (ptok
- token
>= PEV_MAX_LEN
- 1)
3185 PEV_ERROR1(&pev
, "parse: token too long (%s)", ptr
- (ptok
- token
));
3191 pev_free(&pev
, cpair
);
3194 FIXME("Couldn't evaluate %s => %s\n", wine_dbgstr_a(cmd
), pev
.error
);
3195 pev_free(&pev
, NULL
);
3199 BOOL
pdb_virtual_unwind(struct cpu_stack_walk
* csw
, DWORD_PTR ip
,
3200 CONTEXT
* context
, struct pdb_cmd_pair
* cpair
)
3202 struct module_pair pair
;
3203 struct pdb_module_info
* pdb_info
;
3204 PDB_FPO_DATA
* fpoext
;
3205 unsigned i
, size
, strsize
;
3209 if (!(pair
.pcs
= process_find_by_handle(csw
->hProcess
)) ||
3210 !(pair
.requested
= module_find_by_addr(pair
.pcs
, ip
, DMT_UNKNOWN
)) ||
3211 !module_get_debug(&pair
))
3213 if (!pair
.effective
->format_info
[DFI_PDB
]) return FALSE
;
3214 pdb_info
= pair
.effective
->format_info
[DFI_PDB
]->u
.pdb_info
;
3215 TRACE("searching %lx => %lx\n", ip
, ip
- (DWORD_PTR
)pair
.effective
->module
.BaseOfImage
);
3216 ip
-= (DWORD_PTR
)pair
.effective
->module
.BaseOfImage
;
3218 strbase
= pdb_read_strings(&pdb_info
->pdb_files
[0]);
3219 if (!strbase
) return FALSE
;
3220 strsize
= *(const DWORD
*)(strbase
+ 8);
3221 fpoext
= pdb_read_file(&pdb_info
->pdb_files
[0], pdb_info
->pdb_files
[0].fpoext_stream
);
3222 size
= pdb_get_file_size(&pdb_info
->pdb_files
[0], pdb_info
->pdb_files
[0].fpoext_stream
);
3223 if (fpoext
&& (size
% sizeof(*fpoext
)) == 0)
3225 size
/= sizeof(*fpoext
);
3226 for (i
= 0; i
< size
; i
++)
3228 if (fpoext
[i
].start
<= ip
&& ip
< fpoext
[i
].start
+ fpoext
[i
].func_size
)
3230 TRACE("\t%08x %08x %8x %8x %4x %4x %4x %08x %s\n",
3231 fpoext
[i
].start
, fpoext
[i
].func_size
, fpoext
[i
].locals_size
,
3232 fpoext
[i
].params_size
, fpoext
[i
].maxstack_size
, fpoext
[i
].prolog_size
,
3233 fpoext
[i
].savedregs_size
, fpoext
[i
].flags
,
3234 fpoext
[i
].str_offset
< strsize
?
3235 wine_dbgstr_a(strbase
+ 12 + fpoext
[i
].str_offset
) : "<out of bounds>");
3236 if (fpoext
[i
].str_offset
< strsize
)
3237 ret
= pdb_parse_cmd_string(csw
, &fpoext
[i
], strbase
+ 12 + fpoext
[i
].str_offset
, cpair
);
3251 /*========================================================================
3252 * Process CodeView debug information.
3255 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
3256 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
3257 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
3258 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
3259 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
3261 static BOOL
codeview_process_info(const struct process
* pcs
,
3262 const struct msc_debug_info
* msc_dbg
)
3264 const DWORD
* signature
= (const DWORD
*)msc_dbg
->root
;
3266 struct pdb_lookup pdb_lookup
;
3268 TRACE("Processing signature %.4s\n", (const char*)signature
);
3272 case CODEVIEW_NB09_SIG
:
3273 case CODEVIEW_NB11_SIG
:
3275 const OMFSignature
* cv
= (const OMFSignature
*)msc_dbg
->root
;
3276 const OMFDirHeader
* hdr
= (const OMFDirHeader
*)(msc_dbg
->root
+ cv
->filepos
);
3277 const OMFDirEntry
* ent
;
3278 const OMFDirEntry
* prev
;
3279 const OMFDirEntry
* next
;
3282 codeview_init_basic_types(msc_dbg
->module
);
3284 for (i
= 0; i
< hdr
->cDir
; i
++)
3286 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
+ i
* hdr
->cbDirEntry
);
3287 if (ent
->SubSection
== sstGlobalTypes
)
3289 const OMFGlobalTypes
* types
;
3290 struct codeview_type_parse ctp
;
3292 types
= (const OMFGlobalTypes
*)(msc_dbg
->root
+ ent
->lfo
);
3293 ctp
.module
= msc_dbg
->module
;
3294 ctp
.offset
= (const DWORD
*)(types
+ 1);
3295 ctp
.num
= types
->cTypes
;
3296 ctp
.table
= (const BYTE
*)(ctp
.offset
+ types
->cTypes
);
3298 cv_current_module
= &cv_zmodules
[0];
3299 if (cv_current_module
->allowed
) FIXME("Already allowed??\n");
3300 cv_current_module
->allowed
= TRUE
;
3302 codeview_parse_type_table(&ctp
);
3307 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
);
3308 for (i
= 0; i
< hdr
->cDir
; i
++, ent
= next
)
3310 next
= (i
== hdr
->cDir
-1) ? NULL
:
3311 (const OMFDirEntry
*)((const BYTE
*)ent
+ hdr
->cbDirEntry
);
3312 prev
= (i
== 0) ? NULL
:
3313 (const OMFDirEntry
*)((const BYTE
*)ent
- hdr
->cbDirEntry
);
3315 if (ent
->SubSection
== sstAlignSym
)
3317 codeview_snarf(msc_dbg
, msc_dbg
->root
+ ent
->lfo
, sizeof(DWORD
),
3321 * Check the next and previous entry. If either is a
3322 * sstSrcModule, it contains the line number info for
3325 * FIXME: This is not a general solution!
3327 if (next
&& next
->iMod
== ent
->iMod
&& next
->SubSection
== sstSrcModule
)
3328 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ next
->lfo
,
3331 if (prev
&& prev
->iMod
== ent
->iMod
&& prev
->SubSection
== sstSrcModule
)
3332 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ prev
->lfo
,
3338 msc_dbg
->module
->module
.SymType
= SymCv
;
3339 /* FIXME: we could have a finer grain here */
3340 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
3341 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
3342 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
3343 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
3344 msc_dbg
->module
->module
.Publics
= TRUE
;
3345 codeview_clear_type_table();
3350 case CODEVIEW_NB10_SIG
:
3352 const CODEVIEW_PDB_DATA
* pdb
= (const CODEVIEW_PDB_DATA
*)msc_dbg
->root
;
3353 pdb_lookup
.filename
= pdb
->name
;
3354 pdb_lookup
.kind
= PDB_JG
;
3355 pdb_lookup
.timestamp
= pdb
->timestamp
;
3356 pdb_lookup
.age
= pdb
->age
;
3357 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
3360 case CODEVIEW_RSDS_SIG
:
3362 const OMFSignatureRSDS
* rsds
= (const OMFSignatureRSDS
*)msc_dbg
->root
;
3364 TRACE("Got RSDS type of PDB file: guid=%s age=%08x name=%s\n",
3365 wine_dbgstr_guid(&rsds
->guid
), rsds
->age
, rsds
->name
);
3366 pdb_lookup
.filename
= rsds
->name
;
3367 pdb_lookup
.kind
= PDB_DS
;
3368 pdb_lookup
.guid
= rsds
->guid
;
3369 pdb_lookup
.age
= rsds
->age
;
3370 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
3374 ERR("Unknown CODEVIEW signature %08x in module %s\n",
3375 *signature
, debugstr_w(msc_dbg
->module
->module
.ModuleName
));
3380 msc_dbg
->module
->module
.CVSig
= *signature
;
3381 memcpy(msc_dbg
->module
->module
.CVData
, msc_dbg
->root
,
3382 sizeof(msc_dbg
->module
->module
.CVData
));
3387 /*========================================================================
3388 * Process debug directory.
3390 BOOL
pe_load_debug_directory(const struct process
* pcs
, struct module
* module
,
3391 const BYTE
* mapping
,
3392 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
3393 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
)
3397 struct msc_debug_info msc_dbg
;
3399 msc_dbg
.module
= module
;
3400 msc_dbg
.nsect
= nsect
;
3401 msc_dbg
.sectp
= sectp
;
3403 msc_dbg
.omapp
= NULL
;
3409 /* First, watch out for OMAP data */
3410 for (i
= 0; i
< nDbg
; i
++)
3412 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
)
3414 msc_dbg
.nomap
= dbg
[i
].SizeOfData
/ sizeof(OMAP_DATA
);
3415 msc_dbg
.omapp
= (const OMAP_DATA
*)(mapping
+ dbg
[i
].PointerToRawData
);
3420 /* Now, try to parse CodeView debug info */
3421 for (i
= 0; i
< nDbg
; i
++)
3423 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_CODEVIEW
)
3425 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
3426 if ((ret
= codeview_process_info(pcs
, &msc_dbg
))) goto done
;
3430 /* If not found, try to parse COFF debug info */
3431 for (i
= 0; i
< nDbg
; i
++)
3433 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_COFF
)
3435 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
3436 if ((ret
= coff_process_info(&msc_dbg
))) goto done
;
3440 /* FIXME: this should be supported... this is the debug information for
3441 * functions compiled without a frame pointer (FPO = frame pointer omission)
3442 * the associated data helps finding out the relevant information
3444 for (i
= 0; i
< nDbg
; i
++)
3445 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_FPO
)
3446 FIXME("This guy has FPO information\n");
3450 #define FRAME_TRAP 1
3453 typedef struct _FPO_DATA
3455 DWORD ulOffStart
; /* offset 1st byte of function code */
3456 DWORD cbProcSize
; /* # bytes in function */
3457 DWORD cdwLocals
; /* # bytes in locals/4 */
3458 WORD cdwParams
; /* # bytes in params/4 */
3460 WORD cbProlog
: 8; /* # bytes in prolog */
3461 WORD cbRegs
: 3; /* # regs saved */
3462 WORD fHasSEH
: 1; /* TRUE if SEH in func */
3463 WORD fUseBP
: 1; /* TRUE if EBP has been allocated */
3464 WORD reserved
: 1; /* reserved for future use */
3465 WORD cbFrame
: 2; /* frame type */
3472 ERR("Got a page fault while loading symbols\n");