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
47 #include "wine/exception.h"
48 #include "wine/debug.h"
49 #include "dbghelp_private.h"
50 #include "wine/mscvpdb.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp_msc
);
54 struct pdb_stream_name
66 struct pdb_stream_name
* stream_dict
;
67 unsigned fpoext_stream
;
73 struct PDB_JG_TOC
* toc
;
78 struct PDB_DS_TOC
* toc
;
83 /* FIXME: don't make it static */
84 #define CV_MAX_MODULES 32
85 struct pdb_module_info
87 unsigned used_subfiles
;
88 struct pdb_file_info pdb_files
[CV_MAX_MODULES
];
91 /*========================================================================
92 * Debug file access helper routines
95 static void dump(const void* ptr
, unsigned len
)
99 const char* hexof
= "0123456789abcdef";
102 for (i
= 0; i
< len
; i
+= 16)
104 sprintf(msg
, "%08x: ", i
);
105 memset(msg
+ 10, ' ', 3 * 16 + 1 + 16);
106 for (j
= 0; j
< min(16, len
- i
); j
++)
108 msg
[10 + 3 * j
+ 0] = hexof
[x
[i
+ j
] >> 4];
109 msg
[10 + 3 * j
+ 1] = hexof
[x
[i
+ j
] & 15];
110 msg
[10 + 3 * j
+ 2] = ' ';
111 msg
[10 + 3 * 16 + 1 + j
] = (x
[i
+ j
] >= 0x20 && x
[i
+ j
] < 0x7f) ?
114 msg
[10 + 3 * 16] = ' ';
115 msg
[10 + 3 * 16 + 1 + 16] = '\0';
120 /*========================================================================
121 * Process CodeView type information.
124 #define MAX_BUILTIN_TYPES 0x06FF
125 #define FIRST_DEFINABLE_TYPE 0x1000
127 static struct symt
* cv_basic_types
[MAX_BUILTIN_TYPES
];
129 struct cv_defined_module
132 unsigned int num_defined_types
;
133 struct symt
** defined_types
;
135 /* FIXME: don't make it static */
136 #define CV_MAX_MODULES 32
137 static struct cv_defined_module cv_zmodules
[CV_MAX_MODULES
];
138 static struct cv_defined_module
*cv_current_module
;
140 static void codeview_init_basic_types(struct module
* module
)
143 * These are the common builtin types that are used by VC++.
145 cv_basic_types
[T_NOTYPE
] = NULL
;
146 cv_basic_types
[T_ABS
] = NULL
;
147 cv_basic_types
[T_VOID
] = &symt_new_basic(module
, btVoid
, "void", 0)->symt
;
148 cv_basic_types
[T_CHAR
] = &symt_new_basic(module
, btChar
, "char", 1)->symt
;
149 cv_basic_types
[T_SHORT
] = &symt_new_basic(module
, btInt
, "short int", 2)->symt
;
150 cv_basic_types
[T_LONG
] = &symt_new_basic(module
, btInt
, "long int", 4)->symt
;
151 cv_basic_types
[T_QUAD
] = &symt_new_basic(module
, btInt
, "long long int", 8)->symt
;
152 cv_basic_types
[T_UCHAR
] = &symt_new_basic(module
, btUInt
, "unsigned char", 1)->symt
;
153 cv_basic_types
[T_USHORT
] = &symt_new_basic(module
, btUInt
, "unsigned short", 2)->symt
;
154 cv_basic_types
[T_ULONG
] = &symt_new_basic(module
, btUInt
, "unsigned long", 4)->symt
;
155 cv_basic_types
[T_UQUAD
] = &symt_new_basic(module
, btUInt
, "unsigned long long", 8)->symt
;
156 cv_basic_types
[T_BOOL08
] = &symt_new_basic(module
, btBool
, "BOOL08", 1)->symt
;
157 cv_basic_types
[T_BOOL16
] = &symt_new_basic(module
, btBool
, "BOOL16", 2)->symt
;
158 cv_basic_types
[T_BOOL32
] = &symt_new_basic(module
, btBool
, "BOOL32", 4)->symt
;
159 cv_basic_types
[T_BOOL64
] = &symt_new_basic(module
, btBool
, "BOOL64", 8)->symt
;
160 cv_basic_types
[T_REAL32
] = &symt_new_basic(module
, btFloat
, "float", 4)->symt
;
161 cv_basic_types
[T_REAL64
] = &symt_new_basic(module
, btFloat
, "double", 8)->symt
;
162 cv_basic_types
[T_REAL80
] = &symt_new_basic(module
, btFloat
, "long double", 10)->symt
;
163 cv_basic_types
[T_RCHAR
] = &symt_new_basic(module
, btInt
, "signed char", 1)->symt
;
164 cv_basic_types
[T_WCHAR
] = &symt_new_basic(module
, btWChar
, "wchar_t", 2)->symt
;
165 cv_basic_types
[T_CHAR16
] = &symt_new_basic(module
, btChar16
,"char16_t", 2)->symt
;
166 cv_basic_types
[T_CHAR32
] = &symt_new_basic(module
, btChar32
,"char32_t", 4)->symt
;
167 cv_basic_types
[T_INT2
] = &symt_new_basic(module
, btInt
, "INT2", 2)->symt
;
168 cv_basic_types
[T_UINT2
] = &symt_new_basic(module
, btUInt
, "UINT2", 2)->symt
;
169 cv_basic_types
[T_INT4
] = &symt_new_basic(module
, btInt
, "INT4", 4)->symt
;
170 cv_basic_types
[T_UINT4
] = &symt_new_basic(module
, btUInt
, "UINT4", 4)->symt
;
171 cv_basic_types
[T_INT8
] = &symt_new_basic(module
, btInt
, "INT8", 8)->symt
;
172 cv_basic_types
[T_UINT8
] = &symt_new_basic(module
, btUInt
, "UINT8", 8)->symt
;
173 cv_basic_types
[T_HRESULT
]= &symt_new_basic(module
, btUInt
, "HRESULT", 4)->symt
;
175 cv_basic_types
[T_32PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], 4)->symt
;
176 cv_basic_types
[T_32PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], 4)->symt
;
177 cv_basic_types
[T_32PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], 4)->symt
;
178 cv_basic_types
[T_32PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], 4)->symt
;
179 cv_basic_types
[T_32PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], 4)->symt
;
180 cv_basic_types
[T_32PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], 4)->symt
;
181 cv_basic_types
[T_32PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], 4)->symt
;
182 cv_basic_types
[T_32PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], 4)->symt
;
183 cv_basic_types
[T_32PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], 4)->symt
;
184 cv_basic_types
[T_32PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], 4)->symt
;
185 cv_basic_types
[T_32PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], 4)->symt
;
186 cv_basic_types
[T_32PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], 4)->symt
;
187 cv_basic_types
[T_32PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], 4)->symt
;
188 cv_basic_types
[T_32PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], 4)->symt
;
189 cv_basic_types
[T_32PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], 4)->symt
;
190 cv_basic_types
[T_32PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], 4)->symt
;
191 cv_basic_types
[T_32PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], 4)->symt
;
192 cv_basic_types
[T_32PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], 4)->symt
;
193 cv_basic_types
[T_32PCHAR16
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR16
], 4)->symt
;
194 cv_basic_types
[T_32PCHAR32
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR32
], 4)->symt
;
195 cv_basic_types
[T_32PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], 4)->symt
;
196 cv_basic_types
[T_32PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], 4)->symt
;
197 cv_basic_types
[T_32PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], 4)->symt
;
198 cv_basic_types
[T_32PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], 4)->symt
;
199 cv_basic_types
[T_32PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], 4)->symt
;
200 cv_basic_types
[T_32PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], 4)->symt
;
201 cv_basic_types
[T_32PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
], 4)->symt
;
203 cv_basic_types
[T_64PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], 8)->symt
;
204 cv_basic_types
[T_64PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], 8)->symt
;
205 cv_basic_types
[T_64PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], 8)->symt
;
206 cv_basic_types
[T_64PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], 8)->symt
;
207 cv_basic_types
[T_64PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], 8)->symt
;
208 cv_basic_types
[T_64PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], 8)->symt
;
209 cv_basic_types
[T_64PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], 8)->symt
;
210 cv_basic_types
[T_64PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], 8)->symt
;
211 cv_basic_types
[T_64PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], 8)->symt
;
212 cv_basic_types
[T_64PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], 8)->symt
;
213 cv_basic_types
[T_64PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], 8)->symt
;
214 cv_basic_types
[T_64PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], 8)->symt
;
215 cv_basic_types
[T_64PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], 8)->symt
;
216 cv_basic_types
[T_64PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], 8)->symt
;
217 cv_basic_types
[T_64PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], 8)->symt
;
218 cv_basic_types
[T_64PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], 8)->symt
;
219 cv_basic_types
[T_64PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], 8)->symt
;
220 cv_basic_types
[T_64PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], 8)->symt
;
221 cv_basic_types
[T_64PCHAR16
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR16
], 8)->symt
;
222 cv_basic_types
[T_64PCHAR32
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR32
], 8)->symt
;
223 cv_basic_types
[T_64PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], 8)->symt
;
224 cv_basic_types
[T_64PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], 8)->symt
;
225 cv_basic_types
[T_64PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], 8)->symt
;
226 cv_basic_types
[T_64PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], 8)->symt
;
227 cv_basic_types
[T_64PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], 8)->symt
;
228 cv_basic_types
[T_64PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], 8)->symt
;
229 cv_basic_types
[T_64PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
], 8)->symt
;
231 cv_basic_types
[T_PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], sizeof(void*))->symt
;
232 cv_basic_types
[T_PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], sizeof(void*))->symt
;
233 cv_basic_types
[T_PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], sizeof(void*))->symt
;
234 cv_basic_types
[T_PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], sizeof(void*))->symt
;
235 cv_basic_types
[T_PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], sizeof(void*))->symt
;
236 cv_basic_types
[T_PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], sizeof(void*))->symt
;
237 cv_basic_types
[T_PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], sizeof(void*))->symt
;
238 cv_basic_types
[T_PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], sizeof(void*))->symt
;
239 cv_basic_types
[T_PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], sizeof(void*))->symt
;
240 cv_basic_types
[T_PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], sizeof(void*))->symt
;
241 cv_basic_types
[T_PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], sizeof(void*))->symt
;
242 cv_basic_types
[T_PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], sizeof(void*))->symt
;
243 cv_basic_types
[T_PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], sizeof(void*))->symt
;
244 cv_basic_types
[T_PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], sizeof(void*))->symt
;
245 cv_basic_types
[T_PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], sizeof(void*))->symt
;
246 cv_basic_types
[T_PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], sizeof(void*))->symt
;
247 cv_basic_types
[T_PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], sizeof(void*))->symt
;
248 cv_basic_types
[T_PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], sizeof(void*))->symt
;
249 cv_basic_types
[T_PCHAR16
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR16
], sizeof(void*))->symt
;
250 cv_basic_types
[T_PCHAR32
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR32
], sizeof(void*))->symt
;
251 cv_basic_types
[T_PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], sizeof(void*))->symt
;
252 cv_basic_types
[T_PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], sizeof(void*))->symt
;
253 cv_basic_types
[T_PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], sizeof(void*))->symt
;
254 cv_basic_types
[T_PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], sizeof(void*))->symt
;
255 cv_basic_types
[T_PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], sizeof(void*))->symt
;
256 cv_basic_types
[T_PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], sizeof(void*))->symt
;
259 static int leaf_as_variant(VARIANT
* v
, const unsigned short int* leaf
)
261 unsigned short int type
= *leaf
++;
264 if (type
< LF_NUMERIC
)
266 v
->n1
.n2
.vt
= VT_UINT
;
267 v
->n1
.n2
.n3
.uintVal
= type
;
276 v
->n1
.n2
.n3
.cVal
= *(const char*)leaf
;
282 v
->n1
.n2
.n3
.iVal
= *(const short*)leaf
;
287 v
->n1
.n2
.vt
= VT_UI2
;
288 v
->n1
.n2
.n3
.uiVal
= *leaf
;
294 v
->n1
.n2
.n3
.lVal
= *(const int*)leaf
;
299 v
->n1
.n2
.vt
= VT_UI4
;
300 v
->n1
.n2
.n3
.uiVal
= *(const unsigned int*)leaf
;
306 v
->n1
.n2
.n3
.llVal
= *(const long long int*)leaf
;
311 v
->n1
.n2
.vt
= VT_UI8
;
312 v
->n1
.n2
.n3
.ullVal
= *(const long long unsigned int*)leaf
;
318 v
->n1
.n2
.n3
.fltVal
= *(const float*)leaf
;
322 FIXME("Unsupported numeric leaf type %04x\n", type
);
324 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
330 v
->n1
.n2
.n3
.fltVal
= *(const double*)leaf
;
334 FIXME("Unsupported numeric leaf type %04x\n", type
);
336 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
340 FIXME("Unsupported numeric leaf type %04x\n", type
);
342 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
346 FIXME("Unsupported numeric leaf type %04x\n", type
);
348 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
352 FIXME("Unsupported numeric leaf type %04x\n", type
);
354 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
358 FIXME("Unsupported numeric leaf type %04x\n", type
);
360 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
364 FIXME("Unsupported numeric leaf type %04x\n", type
);
366 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
370 FIXME("Unsupported numeric leaf type %04x\n", type
);
372 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
376 FIXME("Unknown numeric leaf type %04x\n", type
);
377 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
385 static int numeric_leaf(int* value
, const unsigned short int* leaf
)
387 unsigned short int type
= *leaf
++;
390 if (type
< LF_NUMERIC
)
400 *value
= *(const char*)leaf
;
405 *value
= *(const short*)leaf
;
415 *value
= *(const int*)leaf
;
420 *value
= *(const unsigned int*)leaf
;
425 FIXME("Unsupported numeric leaf type %04x\n", type
);
427 *value
= 0; /* FIXME */
431 FIXME("Unsupported numeric leaf type %04x\n", type
);
433 *value
= 0; /* FIXME */
437 FIXME("Unsupported numeric leaf type %04x\n", type
);
439 *value
= 0; /* FIXME */
443 FIXME("Unsupported numeric leaf type %04x\n", type
);
445 *value
= 0; /* FIXME */
449 FIXME("Unsupported numeric leaf type %04x\n", type
);
451 *value
= 0; /* FIXME */
455 FIXME("Unsupported numeric leaf type %04x\n", type
);
457 *value
= 0; /* FIXME */
461 FIXME("Unsupported numeric leaf type %04x\n", type
);
463 *value
= 0; /* FIXME */
467 FIXME("Unsupported numeric leaf type %04x\n", type
);
469 *value
= 0; /* FIXME */
473 FIXME("Unsupported numeric leaf type %04x\n", type
);
475 *value
= 0; /* FIXME */
479 FIXME("Unsupported numeric leaf type %04x\n", type
);
481 *value
= 0; /* FIXME */
485 FIXME("Unsupported numeric leaf type %04x\n", type
);
487 *value
= 0; /* FIXME */
491 FIXME("Unknown numeric leaf type %04x\n", type
);
500 /* convert a pascal string (as stored in debug information) into
501 * a C string (null terminated).
503 static const char* terminate_string(const struct p_string
* p_name
)
505 static char symname
[256];
507 memcpy(symname
, p_name
->name
, p_name
->namelen
);
508 symname
[p_name
->namelen
] = '\0';
510 return (!*symname
|| strcmp(symname
, "__unnamed") == 0) ? NULL
: symname
;
513 static struct symt
* codeview_get_type(unsigned int typeno
, BOOL quiet
)
515 struct symt
* symt
= NULL
;
518 * Convert Codeview type numbers into something we can grok internally.
519 * Numbers < FIRST_DEFINABLE_TYPE are all fixed builtin types.
520 * Numbers from FIRST_DEFINABLE_TYPE and up are all user defined (structs, etc).
522 if (typeno
< FIRST_DEFINABLE_TYPE
)
524 if (typeno
< MAX_BUILTIN_TYPES
)
525 symt
= cv_basic_types
[typeno
];
529 unsigned mod_index
= typeno
>> 24;
530 unsigned mod_typeno
= typeno
& 0x00FFFFFF;
531 struct cv_defined_module
* mod
;
533 mod
= (mod_index
== 0) ? cv_current_module
: &cv_zmodules
[mod_index
];
535 if (mod_index
>= CV_MAX_MODULES
|| !mod
->allowed
)
536 FIXME("Module of index %d isn't loaded yet (%x)\n", mod_index
, typeno
);
539 if (mod_typeno
- FIRST_DEFINABLE_TYPE
< mod
->num_defined_types
)
540 symt
= mod
->defined_types
[mod_typeno
- FIRST_DEFINABLE_TYPE
];
543 if (!quiet
&& !symt
&& typeno
) FIXME("Returning NULL symt for type-id %x\n", typeno
);
547 struct codeview_type_parse
549 struct module
* module
;
555 static inline const void* codeview_jump_to_type(const struct codeview_type_parse
* ctp
, DWORD idx
)
557 if (idx
< FIRST_DEFINABLE_TYPE
) return NULL
;
558 idx
-= FIRST_DEFINABLE_TYPE
;
559 return (idx
>= ctp
->num
) ? NULL
: (ctp
->table
+ ctp
->offset
[idx
]);
562 static int codeview_add_type(unsigned int typeno
, struct symt
* dt
)
564 if (typeno
< FIRST_DEFINABLE_TYPE
)
565 FIXME("What the heck\n");
566 if (!cv_current_module
)
568 FIXME("Adding %x to non allowed module\n", typeno
);
571 if ((typeno
>> 24) != 0)
572 FIXME("No module index while inserting type-id assumption is wrong %x\n",
574 if (typeno
- FIRST_DEFINABLE_TYPE
>= cv_current_module
->num_defined_types
)
576 if (cv_current_module
->defined_types
)
578 cv_current_module
->num_defined_types
= max( cv_current_module
->num_defined_types
* 2,
579 typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
580 cv_current_module
->defined_types
= HeapReAlloc(GetProcessHeap(),
581 HEAP_ZERO_MEMORY
, cv_current_module
->defined_types
,
582 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
586 cv_current_module
->num_defined_types
= max( 256, typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
587 cv_current_module
->defined_types
= HeapAlloc(GetProcessHeap(),
589 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
591 if (cv_current_module
->defined_types
== NULL
) return FALSE
;
593 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
])
595 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] != dt
)
596 FIXME("Overwriting at %x\n", typeno
);
598 cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] = dt
;
602 static void codeview_clear_type_table(void)
606 for (i
= 0; i
< CV_MAX_MODULES
; i
++)
608 if (cv_zmodules
[i
].allowed
)
609 HeapFree(GetProcessHeap(), 0, cv_zmodules
[i
].defined_types
);
610 cv_zmodules
[i
].allowed
= FALSE
;
611 cv_zmodules
[i
].defined_types
= NULL
;
612 cv_zmodules
[i
].num_defined_types
= 0;
614 cv_current_module
= NULL
;
617 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
619 const union codeview_type
* type
, BOOL details
);
621 static void* codeview_cast_symt(struct symt
* symt
, enum SymTagEnum tag
)
623 if (symt
->tag
!= tag
)
625 FIXME("Bad tag. Expected %d, but got %d\n", tag
, symt
->tag
);
631 static struct symt
* codeview_fetch_type(struct codeview_type_parse
* ctp
,
632 unsigned typeno
, BOOL details
)
635 const union codeview_type
* p
;
637 if (!typeno
) return NULL
;
638 if ((symt
= codeview_get_type(typeno
, TRUE
))) return symt
;
640 /* forward declaration */
641 if (!(p
= codeview_jump_to_type(ctp
, typeno
)))
643 FIXME("Cannot locate type %x\n", typeno
);
646 symt
= codeview_parse_one_type(ctp
, typeno
, p
, details
);
647 if (!symt
) FIXME("Couldn't load forward type %x\n", typeno
);
651 static struct symt
* codeview_add_type_pointer(struct codeview_type_parse
* ctp
,
652 struct symt
* existing
,
653 unsigned int pointee_type
)
655 struct symt
* pointee
;
659 existing
= codeview_cast_symt(existing
, SymTagPointerType
);
662 pointee
= codeview_fetch_type(ctp
, pointee_type
, FALSE
);
663 return &symt_new_pointer(ctp
->module
, pointee
, sizeof(void *))->symt
;
666 static struct symt
* codeview_add_type_array(struct codeview_type_parse
* ctp
,
668 unsigned int elemtype
,
669 unsigned int indextype
,
670 unsigned int arr_len
)
672 struct symt
* elem
= codeview_fetch_type(ctp
, elemtype
, FALSE
);
673 struct symt
* index
= codeview_fetch_type(ctp
, indextype
, FALSE
);
675 return &symt_new_array(ctp
->module
, 0, -arr_len
, elem
, index
)->symt
;
678 static BOOL
codeview_add_type_enum_field_list(struct module
* module
,
679 struct symt_enum
* symt
,
680 const union codeview_reftype
* ref_type
)
682 const unsigned char* ptr
= ref_type
->fieldlist
.list
;
683 const unsigned char* last
= (const BYTE
*)ref_type
+ ref_type
->generic
.len
+ 2;
684 const union codeview_fieldtype
* type
;
688 if (*ptr
>= 0xf0) /* LF_PAD... */
694 type
= (const union codeview_fieldtype
*)ptr
;
696 switch (type
->generic
.id
)
698 case LF_ENUMERATE_V1
:
700 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v1
.value
);
701 const struct p_string
* p_name
= (const struct p_string
*)((const unsigned char*)&type
->enumerate_v1
.value
+ vlen
);
703 symt_add_enum_element(module
, symt
, terminate_string(p_name
), value
);
704 ptr
+= 2 + 2 + vlen
+ (1 + p_name
->namelen
);
707 case LF_ENUMERATE_V3
:
709 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v3
.value
);
710 const char* name
= (const char*)&type
->enumerate_v3
.value
+ vlen
;
712 symt_add_enum_element(module
, symt
, name
, value
);
713 ptr
+= 2 + 2 + vlen
+ (1 + strlen(name
));
718 FIXME("Unsupported type %04x in ENUM field list\n", type
->generic
.id
);
725 static void codeview_add_udt_element(struct codeview_type_parse
* ctp
,
726 struct symt_udt
* symt
, const char* name
,
727 int value
, unsigned type
)
729 struct symt
* subtype
;
730 const union codeview_reftype
*cv_type
;
732 if ((cv_type
= codeview_jump_to_type(ctp
, type
)))
734 switch (cv_type
->generic
.id
)
737 symt_add_udt_element(ctp
->module
, symt
, name
,
738 codeview_fetch_type(ctp
, cv_type
->bitfield_v1
.type
, FALSE
),
739 (value
<< 3) + cv_type
->bitfield_v1
.bitoff
,
740 cv_type
->bitfield_v1
.nbits
);
743 symt_add_udt_element(ctp
->module
, symt
, name
,
744 codeview_fetch_type(ctp
, cv_type
->bitfield_v2
.type
, FALSE
),
745 (value
<< 3) + cv_type
->bitfield_v2
.bitoff
,
746 cv_type
->bitfield_v2
.nbits
);
750 subtype
= codeview_fetch_type(ctp
, type
, FALSE
);
754 DWORD64 elem_size
= 0;
755 symt_get_info(ctp
->module
, subtype
, TI_GET_LENGTH
, &elem_size
);
756 symt_add_udt_element(ctp
->module
, symt
, name
, subtype
,
757 value
<< 3, (DWORD
)elem_size
<< 3);
761 static int codeview_add_type_struct_field_list(struct codeview_type_parse
* ctp
,
762 struct symt_udt
* symt
,
763 unsigned fieldlistno
)
765 const unsigned char* ptr
;
766 const unsigned char* last
;
768 const struct p_string
* p_name
;
770 const union codeview_reftype
*type_ref
;
771 const union codeview_fieldtype
* type
;
773 if (!fieldlistno
) return TRUE
;
774 type_ref
= codeview_jump_to_type(ctp
, fieldlistno
);
775 ptr
= type_ref
->fieldlist
.list
;
776 last
= (const BYTE
*)type_ref
+ type_ref
->generic
.len
+ 2;
780 if (*ptr
>= 0xf0) /* LF_PAD... */
786 type
= (const union codeview_fieldtype
*)ptr
;
788 switch (type
->generic
.id
)
791 leaf_len
= numeric_leaf(&value
, &type
->bclass_v1
.offset
);
793 /* FIXME: ignored for now */
795 ptr
+= 2 + 2 + 2 + leaf_len
;
799 leaf_len
= numeric_leaf(&value
, &type
->bclass_v2
.offset
);
801 /* FIXME: ignored for now */
803 ptr
+= 2 + 2 + 4 + leaf_len
;
809 const unsigned short int* p_vboff
;
811 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v1
.vbpoff
);
812 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v1
.vbpoff
+ leaf_len
);
813 vplen
= numeric_leaf(&vpoff
, p_vboff
);
815 /* FIXME: ignored for now */
817 ptr
+= 2 + 2 + 2 + 2 + leaf_len
+ vplen
;
824 const unsigned short int* p_vboff
;
826 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v2
.vbpoff
);
827 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v2
.vbpoff
+ leaf_len
);
828 vplen
= numeric_leaf(&vpoff
, p_vboff
);
830 /* FIXME: ignored for now */
832 ptr
+= 2 + 2 + 4 + 4 + leaf_len
+ vplen
;
837 leaf_len
= numeric_leaf(&value
, &type
->member_v1
.offset
);
838 p_name
= (const struct p_string
*)((const char*)&type
->member_v1
.offset
+ leaf_len
);
840 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
841 type
->member_v1
.type
);
843 ptr
+= 2 + 2 + 2 + leaf_len
+ (1 + p_name
->namelen
);
847 leaf_len
= numeric_leaf(&value
, &type
->member_v2
.offset
);
848 p_name
= (const struct p_string
*)((const unsigned char*)&type
->member_v2
.offset
+ leaf_len
);
850 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
851 type
->member_v2
.type
);
853 ptr
+= 2 + 2 + 4 + leaf_len
+ (1 + p_name
->namelen
);
857 leaf_len
= numeric_leaf(&value
, &type
->member_v3
.offset
);
858 c_name
= (const char*)&type
->member_v3
.offset
+ leaf_len
;
860 codeview_add_udt_element(ctp
, symt
, c_name
, value
, type
->member_v3
.type
);
862 ptr
+= 2 + 2 + 4 + leaf_len
+ (strlen(c_name
) + 1);
866 /* FIXME: ignored for now */
867 ptr
+= 2 + 2 + 2 + (1 + type
->stmember_v1
.p_name
.namelen
);
871 /* FIXME: ignored for now */
872 ptr
+= 2 + 4 + 2 + (1 + type
->stmember_v2
.p_name
.namelen
);
876 /* FIXME: ignored for now */
877 ptr
+= 2 + 4 + 2 + (strlen(type
->stmember_v3
.name
) + 1);
881 /* FIXME: ignored for now */
882 ptr
+= 2 + 2 + 2 + (1 + type
->method_v1
.p_name
.namelen
);
886 /* FIXME: ignored for now */
887 ptr
+= 2 + 2 + 4 + (1 + type
->method_v2
.p_name
.namelen
);
891 /* FIXME: ignored for now */
892 ptr
+= 2 + 2 + 4 + (strlen(type
->method_v3
.name
) + 1);
896 /* FIXME: ignored for now */
897 ptr
+= 2 + 2 + (1 + type
->nesttype_v1
.p_name
.namelen
);
901 /* FIXME: ignored for now */
902 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype_v2
.p_name
.namelen
);
906 /* FIXME: ignored for now */
907 ptr
+= 2 + 2 + 4 + (strlen(type
->nesttype_v3
.name
) + 1);
911 /* FIXME: ignored for now */
916 /* FIXME: ignored for now */
920 case LF_ONEMETHOD_V1
:
921 /* FIXME: ignored for now */
922 switch ((type
->onemethod_v1
.attribute
>> 2) & 7)
924 case 4: case 6: /* (pure) introducing virtual method */
925 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt_v1
.p_name
.namelen
);
929 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod_v1
.p_name
.namelen
);
934 case LF_ONEMETHOD_V2
:
935 /* FIXME: ignored for now */
936 switch ((type
->onemethod_v2
.attribute
>> 2) & 7)
938 case 4: case 6: /* (pure) introducing virtual method */
939 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod_virt_v2
.p_name
.namelen
);
943 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod_v2
.p_name
.namelen
);
948 case LF_ONEMETHOD_V3
:
949 /* FIXME: ignored for now */
950 switch ((type
->onemethod_v3
.attribute
>> 2) & 7)
952 case 4: case 6: /* (pure) introducing virtual method */
953 ptr
+= 2 + 2 + 4 + 4 + (strlen(type
->onemethod_virt_v3
.name
) + 1);
957 ptr
+= 2 + 2 + 4 + (strlen(type
->onemethod_v3
.name
) + 1);
963 if (!codeview_add_type_struct_field_list(ctp
, symt
, type
->index_v1
.ref
))
969 if (!codeview_add_type_struct_field_list(ctp
, symt
, type
->index_v2
.ref
))
975 FIXME("Unsupported type %04x in STRUCT field list\n", type
->generic
.id
);
983 static struct symt
* codeview_add_type_enum(struct codeview_type_parse
* ctp
,
984 struct symt
* existing
,
986 unsigned fieldlistno
,
989 struct symt_enum
* symt
;
993 if (!(symt
= codeview_cast_symt(existing
, SymTagEnum
))) return NULL
;
994 /* should also check that all fields are the same */
998 symt
= symt_new_enum(ctp
->module
, name
,
999 codeview_fetch_type(ctp
, basetype
, FALSE
));
1002 const union codeview_reftype
* fieldlist
;
1003 fieldlist
= codeview_jump_to_type(ctp
, fieldlistno
);
1004 codeview_add_type_enum_field_list(ctp
->module
, symt
, fieldlist
);
1010 static struct symt
* codeview_add_type_struct(struct codeview_type_parse
* ctp
,
1011 struct symt
* existing
,
1012 const char* name
, int structlen
,
1013 enum UdtKind kind
, unsigned property
)
1015 struct symt_udt
* symt
;
1017 /* if we don't have an existing type, try to find one with same name
1018 * FIXME: what to do when several types in different CUs have same name ?
1023 struct symt_ht
* type
;
1024 struct hash_table_iter hti
;
1026 hash_table_iter_init(&ctp
->module
->ht_types
, &hti
, name
);
1027 while ((ptr
= hash_table_iter_up(&hti
)))
1029 type
= CONTAINING_RECORD(ptr
, struct symt_ht
, hash_elt
);
1031 if (type
->symt
.tag
== SymTagUDT
&&
1032 type
->hash_elt
.name
&& !strcmp(type
->hash_elt
.name
, name
))
1034 existing
= &type
->symt
;
1041 if (!(symt
= codeview_cast_symt(existing
, SymTagUDT
))) return NULL
;
1042 /* should also check that all fields are the same */
1043 if (!(property
& 0x80)) /* 0x80 = forward declaration */
1045 if (!symt
->size
) /* likely prior forward declaration, set UDT size */
1046 symt_set_udt_size(ctp
->module
, symt
, structlen
);
1047 else /* different UDT with same name, create a new type */
1051 if (!existing
) symt
= symt_new_udt(ctp
->module
, name
, structlen
, kind
);
1056 static struct symt
* codeview_new_func_signature(struct codeview_type_parse
* ctp
,
1057 struct symt
* existing
,
1058 enum CV_call_e call_conv
)
1060 struct symt_function_signature
* sym
;
1064 sym
= codeview_cast_symt(existing
, SymTagFunctionType
);
1065 if (!sym
) return NULL
;
1069 sym
= symt_new_function_signature(ctp
->module
, NULL
, call_conv
);
1074 static void codeview_add_func_signature_args(struct codeview_type_parse
* ctp
,
1075 struct symt_function_signature
* sym
,
1079 const union codeview_reftype
* reftype
;
1081 sym
->rettype
= codeview_fetch_type(ctp
, ret_type
, FALSE
);
1082 if (args_list
&& (reftype
= codeview_jump_to_type(ctp
, args_list
)))
1085 switch (reftype
->generic
.id
)
1088 for (i
= 0; i
< reftype
->arglist_v1
.num
; i
++)
1089 symt_add_function_signature_parameter(ctp
->module
, sym
,
1090 codeview_fetch_type(ctp
, reftype
->arglist_v1
.args
[i
], FALSE
));
1093 for (i
= 0; i
< reftype
->arglist_v2
.num
; i
++)
1094 symt_add_function_signature_parameter(ctp
->module
, sym
,
1095 codeview_fetch_type(ctp
, reftype
->arglist_v2
.args
[i
], FALSE
));
1098 FIXME("Unexpected leaf %x for signature's pmt\n", reftype
->generic
.id
);
1103 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
1105 const union codeview_type
* type
, BOOL details
)
1108 int value
, leaf_len
;
1109 const struct p_string
* p_name
;
1111 struct symt
* existing
;
1113 existing
= codeview_get_type(curr_type
, TRUE
);
1115 switch (type
->generic
.id
)
1117 case LF_MODIFIER_V1
:
1118 /* FIXME: we don't handle modifiers,
1119 * but read previous type on the curr_type
1121 WARN("Modifier on %x: %s%s%s%s\n",
1122 type
->modifier_v1
.type
,
1123 type
->modifier_v1
.attribute
& 0x01 ? "const " : "",
1124 type
->modifier_v1
.attribute
& 0x02 ? "volatile " : "",
1125 type
->modifier_v1
.attribute
& 0x04 ? "unaligned " : "",
1126 type
->modifier_v1
.attribute
& ~0x07 ? "unknown " : "");
1127 symt
= codeview_fetch_type(ctp
, type
->modifier_v1
.type
, details
);
1129 case LF_MODIFIER_V2
:
1130 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
1131 WARN("Modifier on %x: %s%s%s%s\n",
1132 type
->modifier_v2
.type
,
1133 type
->modifier_v2
.attribute
& 0x01 ? "const " : "",
1134 type
->modifier_v2
.attribute
& 0x02 ? "volatile " : "",
1135 type
->modifier_v2
.attribute
& 0x04 ? "unaligned " : "",
1136 type
->modifier_v2
.attribute
& ~0x07 ? "unknown " : "");
1137 symt
= codeview_fetch_type(ctp
, type
->modifier_v2
.type
, details
);
1141 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v1
.datatype
);
1144 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v2
.datatype
);
1148 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1151 leaf_len
= numeric_leaf(&value
, &type
->array_v1
.arrlen
);
1152 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v1
.arrlen
+ leaf_len
);
1153 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1154 type
->array_v1
.elemtype
,
1155 type
->array_v1
.idxtype
, value
);
1159 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1162 leaf_len
= numeric_leaf(&value
, &type
->array_v2
.arrlen
);
1163 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v2
.arrlen
+ leaf_len
);
1165 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1166 type
->array_v2
.elemtype
,
1167 type
->array_v2
.idxtype
, value
);
1171 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1174 leaf_len
= numeric_leaf(&value
, &type
->array_v3
.arrlen
);
1175 c_name
= (const char*)&type
->array_v3
.arrlen
+ leaf_len
;
1177 symt
= codeview_add_type_array(ctp
, c_name
,
1178 type
->array_v3
.elemtype
,
1179 type
->array_v3
.idxtype
, value
);
1183 case LF_STRUCTURE_V1
:
1185 leaf_len
= numeric_leaf(&value
, &type
->struct_v1
.structlen
);
1186 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v1
.structlen
+ leaf_len
);
1187 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1188 type
->generic
.id
== LF_CLASS_V1
? UdtClass
: UdtStruct
,
1189 type
->struct_v1
.property
);
1192 codeview_add_type(curr_type
, symt
);
1193 if (!(type
->struct_v1
.property
& 0x80)) /* 0x80 = forward declaration */
1194 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1195 type
->struct_v1
.fieldlist
);
1199 case LF_STRUCTURE_V2
:
1201 leaf_len
= numeric_leaf(&value
, &type
->struct_v2
.structlen
);
1202 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v2
.structlen
+ leaf_len
);
1203 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1204 type
->generic
.id
== LF_CLASS_V2
? UdtClass
: UdtStruct
,
1205 type
->struct_v2
.property
);
1208 codeview_add_type(curr_type
, symt
);
1209 if (!(type
->struct_v2
.property
& 0x80)) /* 0x80 = forward declaration */
1210 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1211 type
->struct_v2
.fieldlist
);
1215 case LF_STRUCTURE_V3
:
1217 leaf_len
= numeric_leaf(&value
, &type
->struct_v3
.structlen
);
1218 c_name
= (const char*)&type
->struct_v3
.structlen
+ leaf_len
;
1219 symt
= codeview_add_type_struct(ctp
, existing
, c_name
, value
,
1220 type
->generic
.id
== LF_CLASS_V3
? UdtClass
: UdtStruct
,
1221 type
->struct_v3
.property
);
1224 codeview_add_type(curr_type
, symt
);
1225 if (!(type
->struct_v3
.property
& 0x80)) /* 0x80 = forward declaration */
1226 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1227 type
->struct_v3
.fieldlist
);
1232 leaf_len
= numeric_leaf(&value
, &type
->union_v1
.un_len
);
1233 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v1
.un_len
+ leaf_len
);
1234 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1235 value
, UdtUnion
, type
->union_v1
.property
);
1238 codeview_add_type(curr_type
, symt
);
1239 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1240 type
->union_v1
.fieldlist
);
1245 leaf_len
= numeric_leaf(&value
, &type
->union_v2
.un_len
);
1246 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v2
.un_len
+ leaf_len
);
1247 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1248 value
, UdtUnion
, type
->union_v2
.property
);
1251 codeview_add_type(curr_type
, symt
);
1252 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1253 type
->union_v2
.fieldlist
);
1258 leaf_len
= numeric_leaf(&value
, &type
->union_v3
.un_len
);
1259 c_name
= (const char*)&type
->union_v3
.un_len
+ leaf_len
;
1260 symt
= codeview_add_type_struct(ctp
, existing
, c_name
,
1261 value
, UdtUnion
, type
->union_v3
.property
);
1264 codeview_add_type(curr_type
, symt
);
1265 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1266 type
->union_v3
.fieldlist
);
1271 symt
= codeview_add_type_enum(ctp
, existing
,
1272 terminate_string(&type
->enumeration_v1
.p_name
),
1273 type
->enumeration_v1
.fieldlist
,
1274 type
->enumeration_v1
.type
);
1278 symt
= codeview_add_type_enum(ctp
, existing
,
1279 terminate_string(&type
->enumeration_v2
.p_name
),
1280 type
->enumeration_v2
.fieldlist
,
1281 type
->enumeration_v2
.type
);
1285 symt
= codeview_add_type_enum(ctp
, existing
, type
->enumeration_v3
.name
,
1286 type
->enumeration_v3
.fieldlist
,
1287 type
->enumeration_v3
.type
);
1290 case LF_PROCEDURE_V1
:
1291 symt
= codeview_new_func_signature(ctp
, existing
, type
->procedure_v1
.call
);
1294 codeview_add_type(curr_type
, symt
);
1295 codeview_add_func_signature_args(ctp
,
1296 (struct symt_function_signature
*)symt
,
1297 type
->procedure_v1
.rvtype
,
1298 type
->procedure_v1
.arglist
);
1301 case LF_PROCEDURE_V2
:
1302 symt
= codeview_new_func_signature(ctp
, existing
,type
->procedure_v2
.call
);
1305 codeview_add_type(curr_type
, symt
);
1306 codeview_add_func_signature_args(ctp
,
1307 (struct symt_function_signature
*)symt
,
1308 type
->procedure_v2
.rvtype
,
1309 type
->procedure_v2
.arglist
);
1313 case LF_MFUNCTION_V1
:
1314 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1315 * nor class information, this would just do for now
1317 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v1
.call
);
1320 codeview_add_type(curr_type
, symt
);
1321 codeview_add_func_signature_args(ctp
,
1322 (struct symt_function_signature
*)symt
,
1323 type
->mfunction_v1
.rvtype
,
1324 type
->mfunction_v1
.arglist
);
1327 case LF_MFUNCTION_V2
:
1328 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1329 * nor class information, this would just do for now
1331 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v2
.call
);
1334 codeview_add_type(curr_type
, symt
);
1335 codeview_add_func_signature_args(ctp
,
1336 (struct symt_function_signature
*)symt
,
1337 type
->mfunction_v2
.rvtype
,
1338 type
->mfunction_v2
.arglist
);
1343 /* this is an ugly hack... FIXME when we have C++ support */
1344 if (!(symt
= existing
))
1347 snprintf(buf
, sizeof(buf
), "__internal_vt_shape_%x\n", curr_type
);
1348 symt
= &symt_new_udt(ctp
->module
, buf
, 0, UdtStruct
)->symt
;
1352 FIXME("Unsupported type-id leaf %x\n", type
->generic
.id
);
1353 dump(type
, 2 + type
->generic
.len
);
1356 return codeview_add_type(curr_type
, symt
) ? symt
: NULL
;
1359 static BOOL
codeview_parse_type_table(struct codeview_type_parse
* ctp
)
1361 unsigned int curr_type
= FIRST_DEFINABLE_TYPE
;
1362 const union codeview_type
* type
;
1364 for (curr_type
= FIRST_DEFINABLE_TYPE
; curr_type
< FIRST_DEFINABLE_TYPE
+ ctp
->num
; curr_type
++)
1366 type
= codeview_jump_to_type(ctp
, curr_type
);
1368 /* type records we're interested in are the ones referenced by symbols
1369 * The known ranges are (X mark the ones we want):
1370 * X 0000-0016 for V1 types
1371 * 0200-020c for V1 types referenced by other types
1372 * 0400-040f for V1 types (complex lists & sets)
1373 * X 1000-100f for V2 types
1374 * 1200-120c for V2 types referenced by other types
1375 * 1400-140f for V1 types (complex lists & sets)
1376 * X 1500-150d for V3 types
1377 * 8000-8010 for numeric leafes
1379 if (!(type
->generic
.id
& 0x8600) || (type
->generic
.id
& 0x0100))
1380 codeview_parse_one_type(ctp
, curr_type
, type
, TRUE
);
1386 /*========================================================================
1387 * Process CodeView line number information.
1389 static ULONG_PTR
codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1390 unsigned seg
, unsigned offset
);
1392 static void codeview_snarf_linetab(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
,
1393 int size
, BOOL pascal_str
)
1395 const BYTE
* ptr
= linetab
;
1399 const unsigned int* filetab
;
1400 const unsigned int* lt_ptr
;
1401 const unsigned short* linenos
;
1402 const struct startend
* start
;
1404 ULONG_PTR addr
, func_addr0
;
1405 struct symt_function
* func
;
1406 const struct codeview_linetab_block
* ltb
;
1408 nfile
= *(const short*)linetab
;
1409 filetab
= (const unsigned int*)(linetab
+ 2 * sizeof(short));
1411 for (i
= 0; i
< nfile
; i
++)
1413 ptr
= linetab
+ filetab
[i
];
1414 nseg
= *(const short*)ptr
;
1415 lt_ptr
= (const unsigned int*)(ptr
+ 2 * sizeof(short));
1416 start
= (const struct startend
*)(lt_ptr
+ nseg
);
1419 * Now snarf the filename for all of the segments for this file.
1422 source
= source_new(msc_dbg
->module
, NULL
, terminate_string((const struct p_string
*)(start
+ nseg
)));
1424 source
= source_new(msc_dbg
->module
, NULL
, (const char*)(start
+ nseg
));
1426 for (j
= 0; j
< nseg
; j
++)
1428 ltb
= (const struct codeview_linetab_block
*)(linetab
+ *lt_ptr
++);
1429 linenos
= (const unsigned short*)<b
->offsets
[ltb
->num_lines
];
1430 func_addr0
= codeview_get_address(msc_dbg
, ltb
->seg
, start
[j
].start
);
1431 if (!func_addr0
) continue;
1432 for (func
= NULL
, k
= 0; k
< ltb
->num_lines
; k
++)
1434 /* now locate function (if any) */
1435 addr
= func_addr0
+ ltb
->offsets
[k
] - start
[j
].start
;
1436 /* unfortunately, we can have several functions in the same block, if there's no
1437 * gap between them... find the new function if needed
1439 if (!func
|| addr
>= func
->address
+ func
->size
)
1441 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1442 /* FIXME: at least labels support line numbers */
1443 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1445 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1446 ltb
->seg
, ltb
->offsets
[k
], addr
, func
? func
->symt
.tag
: -1);
1451 symt_add_func_line(msc_dbg
->module
, func
, source
,
1452 linenos
[k
], addr
- func
->address
);
1458 static void codeview_snarf_linetab2(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
, DWORD size
,
1459 const char* strimage
, DWORD strsize
)
1463 const struct codeview_linetab2
* lt2
;
1464 const struct codeview_linetab2
* lt2_files
= NULL
;
1465 const struct codeview_lt2blk_lines
* lines_blk
;
1466 const struct codeview_linetab2_file
*fd
;
1468 struct symt_function
* func
;
1470 /* locate LT2_FILES_BLOCK (if any) */
1471 lt2
= (const struct codeview_linetab2
*)linetab
;
1472 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1474 if (lt2
->header
== LT2_FILES_BLOCK
)
1479 lt2
= codeview_linetab2_next_block(lt2
);
1483 TRACE("No LT2_FILES_BLOCK found\n");
1487 lt2
= (const struct codeview_linetab2
*)linetab
;
1488 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1490 /* FIXME: should also check that whole lines_blk fits in linetab + size */
1491 switch (lt2
->header
)
1493 case LT2_LINES_BLOCK
:
1494 /* Skip blocks that are too small - Intel C Compiler generates these. */
1495 if (lt2
->size_of_block
< sizeof (struct codeview_lt2blk_lines
)) break;
1496 lines_blk
= (const struct codeview_lt2blk_lines
*)lt2
;
1497 /* FIXME: should check that file_offset is within the LT2_FILES_BLOCK we've seen */
1498 addr
= codeview_get_address(msc_dbg
, lines_blk
->seg
, lines_blk
->start
);
1499 TRACE("block from %04x:%08x #%x (%x lines)\n",
1500 lines_blk
->seg
, lines_blk
->start
, lines_blk
->size
, lines_blk
->nlines
);
1501 fd
= (const struct codeview_linetab2_file
*)((const char*)lt2_files
+ 8 + lines_blk
->file_offset
);
1502 /* FIXME: should check that string is within strimage + strsize */
1503 source
= source_new(msc_dbg
->module
, NULL
, strimage
+ fd
->offset
);
1504 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1505 /* FIXME: at least labels support line numbers */
1506 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1508 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1509 lines_blk
->seg
, lines_blk
->start
, addr
, func
? func
->symt
.tag
: -1);
1512 for (i
= 0; i
< lines_blk
->nlines
; i
++)
1514 symt_add_func_line(msc_dbg
->module
, func
, source
,
1515 lines_blk
->l
[i
].lineno
^ 0x80000000,
1516 lines_blk
->l
[i
].offset
);
1519 case LT2_FILES_BLOCK
: /* skip */
1522 TRACE("Block end %x\n", lt2
->header
);
1523 lt2
= (const struct codeview_linetab2
*)((const char*)linetab
+ size
);
1526 lt2
= codeview_linetab2_next_block(lt2
);
1530 /*========================================================================
1531 * Process CodeView symbol information.
1534 static unsigned int codeview_map_offset(const struct msc_debug_info
* msc_dbg
,
1535 unsigned int offset
)
1537 int nomap
= msc_dbg
->nomap
;
1538 const OMAP_DATA
* omapp
= msc_dbg
->omapp
;
1541 if (!nomap
|| !omapp
) return offset
;
1543 /* FIXME: use binary search */
1544 for (i
= 0; i
< nomap
- 1; i
++)
1545 if (omapp
[i
].from
<= offset
&& omapp
[i
+1].from
> offset
)
1546 return !omapp
[i
].to
? 0 : omapp
[i
].to
+ (offset
- omapp
[i
].from
);
1551 static ULONG_PTR
codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1552 unsigned seg
, unsigned offset
)
1554 int nsect
= msc_dbg
->nsect
;
1555 const IMAGE_SECTION_HEADER
* sectp
= msc_dbg
->sectp
;
1557 if (!seg
|| seg
> nsect
) return 0;
1558 return msc_dbg
->module
->module
.BaseOfImage
+
1559 codeview_map_offset(msc_dbg
, sectp
[seg
-1].VirtualAddress
+ offset
);
1562 static inline void codeview_add_variable(const struct msc_debug_info
* msc_dbg
,
1563 struct symt_compiland
* compiland
,
1565 unsigned segment
, unsigned offset
,
1566 unsigned symtype
, BOOL is_local
, BOOL in_tls
, BOOL force
)
1570 struct location loc
;
1572 loc
.kind
= in_tls
? loc_tlsrel
: loc_absolute
;
1574 loc
.offset
= in_tls
? offset
: codeview_get_address(msc_dbg
, segment
, offset
);
1575 if (force
|| in_tls
|| !symt_find_nearest(msc_dbg
->module
, loc
.offset
))
1577 symt_new_global_variable(msc_dbg
->module
, compiland
,
1578 name
, is_local
, loc
, 0,
1579 codeview_get_type(symtype
, FALSE
));
1584 static BOOL
codeview_snarf(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1585 int offset
, int size
, BOOL do_globals
)
1587 struct symt_function
* curr_func
= NULL
;
1589 struct symt_block
* block
= NULL
;
1591 struct symt_compiland
* compiland
= NULL
;
1592 struct location loc
;
1595 * Loop over the different types of records and whenever we
1596 * find something we are interested in, record it and move on.
1598 for (i
= offset
; i
< size
; i
+= length
)
1600 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1601 length
= sym
->generic
.len
+ 2;
1602 if (i
+ length
> size
) break;
1603 if (!sym
->generic
.id
|| length
< 4) break;
1604 if (length
& 3) FIXME("unpadded len %u\n", length
);
1606 switch (sym
->generic
.id
)
1609 * Global and local data symbols. We don't associate these
1610 * with any given source file.
1615 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
1616 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
1617 sym
->generic
.id
== S_LDATA_V1
, FALSE
, TRUE
);
1622 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
1623 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
1624 sym
->generic
.id
== S_LDATA_V2
, FALSE
, TRUE
);
1629 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
1630 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
1631 sym
->generic
.id
== S_LDATA_V3
, FALSE
, TRUE
);
1634 /* variables with thread storage */
1638 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v1
.p_name
),
1639 sym
->thread_v1
.segment
, sym
->thread_v1
.offset
, sym
->thread_v1
.symtype
,
1640 sym
->generic
.id
== S_LTHREAD_V1
, TRUE
, TRUE
);
1645 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v2
.p_name
),
1646 sym
->thread_v2
.segment
, sym
->thread_v2
.offset
, sym
->thread_v2
.symtype
,
1647 sym
->generic
.id
== S_LTHREAD_V2
, TRUE
, TRUE
);
1652 codeview_add_variable(msc_dbg
, compiland
, sym
->thread_v3
.name
,
1653 sym
->thread_v3
.segment
, sym
->thread_v3
.offset
, sym
->thread_v3
.symtype
,
1654 sym
->generic
.id
== S_LTHREAD_V3
, TRUE
, TRUE
);
1657 /* Public symbols */
1661 case S_PUB_FUNC1_V3
:
1662 case S_PUB_FUNC2_V3
:
1663 /* will be handled later on in codeview_snarf_public */
1667 * Sort of like a global function, but it just points
1668 * to a thunk, which is a stupid name for what amounts to
1669 * a PLT slot in the normal jargon that everyone else uses.
1672 symt_new_thunk(msc_dbg
->module
, compiland
,
1673 terminate_string(&sym
->thunk_v1
.p_name
), sym
->thunk_v1
.thtype
,
1674 codeview_get_address(msc_dbg
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
),
1675 sym
->thunk_v1
.thunk_len
);
1678 symt_new_thunk(msc_dbg
->module
, compiland
,
1679 sym
->thunk_v3
.name
, sym
->thunk_v3
.thtype
,
1680 codeview_get_address(msc_dbg
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
),
1681 sym
->thunk_v3
.thunk_len
);
1685 * Global and static functions.
1689 if (curr_func
) FIXME("nested function\n");
1690 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1691 terminate_string(&sym
->proc_v1
.p_name
),
1692 codeview_get_address(msc_dbg
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
),
1693 sym
->proc_v1
.proc_len
,
1694 codeview_get_type(sym
->proc_v1
.proctype
, FALSE
));
1695 loc
.kind
= loc_absolute
;
1696 loc
.offset
= sym
->proc_v1
.debug_start
;
1697 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1698 loc
.offset
= sym
->proc_v1
.debug_end
;
1699 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1703 if (curr_func
) FIXME("nested function\n");
1704 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1705 terminate_string(&sym
->proc_v2
.p_name
),
1706 codeview_get_address(msc_dbg
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
),
1707 sym
->proc_v2
.proc_len
,
1708 codeview_get_type(sym
->proc_v2
.proctype
, FALSE
));
1709 loc
.kind
= loc_absolute
;
1710 loc
.offset
= sym
->proc_v2
.debug_start
;
1711 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1712 loc
.offset
= sym
->proc_v2
.debug_end
;
1713 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1717 if (curr_func
) FIXME("nested function\n");
1718 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1720 codeview_get_address(msc_dbg
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
),
1721 sym
->proc_v3
.proc_len
,
1722 codeview_get_type(sym
->proc_v3
.proctype
, FALSE
));
1723 loc
.kind
= loc_absolute
;
1724 loc
.offset
= sym
->proc_v3
.debug_start
;
1725 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1726 loc
.offset
= sym
->proc_v3
.debug_end
;
1727 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1730 * Function parameters and stack variables.
1733 loc
.kind
= loc_regrel
;
1734 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1735 loc
.reg
= CV_REG_EBP
;
1736 loc
.offset
= sym
->stack_v1
.offset
;
1737 symt_add_func_local(msc_dbg
->module
, curr_func
,
1738 sym
->stack_v1
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1740 codeview_get_type(sym
->stack_v1
.symtype
, FALSE
),
1741 terminate_string(&sym
->stack_v1
.p_name
));
1744 loc
.kind
= loc_regrel
;
1745 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1746 loc
.reg
= CV_REG_EBP
;
1747 loc
.offset
= sym
->stack_v2
.offset
;
1748 symt_add_func_local(msc_dbg
->module
, curr_func
,
1749 sym
->stack_v2
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1751 codeview_get_type(sym
->stack_v2
.symtype
, FALSE
),
1752 terminate_string(&sym
->stack_v2
.p_name
));
1755 loc
.kind
= loc_regrel
;
1756 /* Yes, it's i386 dependent, but that's the symbol purpose. S_REGREL is used on other CPUs */
1757 loc
.reg
= CV_REG_EBP
;
1758 loc
.offset
= sym
->stack_v3
.offset
;
1759 symt_add_func_local(msc_dbg
->module
, curr_func
,
1760 sym
->stack_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1762 codeview_get_type(sym
->stack_v3
.symtype
, FALSE
),
1763 sym
->stack_v3
.name
);
1766 loc
.kind
= loc_regrel
;
1767 loc
.reg
= sym
->regrel_v3
.reg
;
1768 loc
.offset
= sym
->regrel_v3
.offset
;
1769 symt_add_func_local(msc_dbg
->module
, curr_func
,
1770 /* FIXME this is wrong !!! */
1771 sym
->regrel_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1773 codeview_get_type(sym
->regrel_v3
.symtype
, FALSE
),
1774 sym
->regrel_v3
.name
);
1778 loc
.kind
= loc_register
;
1779 loc
.reg
= sym
->register_v1
.reg
;
1781 symt_add_func_local(msc_dbg
->module
, curr_func
,
1783 block
, codeview_get_type(sym
->register_v1
.type
, FALSE
),
1784 terminate_string(&sym
->register_v1
.p_name
));
1787 loc
.kind
= loc_register
;
1788 loc
.reg
= sym
->register_v2
.reg
;
1790 symt_add_func_local(msc_dbg
->module
, curr_func
,
1792 block
, codeview_get_type(sym
->register_v2
.type
, FALSE
),
1793 terminate_string(&sym
->register_v2
.p_name
));
1796 loc
.kind
= loc_register
;
1797 loc
.reg
= sym
->register_v3
.reg
;
1799 symt_add_func_local(msc_dbg
->module
, curr_func
,
1801 block
, codeview_get_type(sym
->register_v3
.type
, FALSE
),
1802 sym
->register_v3
.name
);
1806 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1807 codeview_get_address(msc_dbg
, sym
->block_v1
.segment
, sym
->block_v1
.offset
),
1808 sym
->block_v1
.length
);
1811 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1812 codeview_get_address(msc_dbg
, sym
->block_v3
.segment
, sym
->block_v3
.offset
),
1813 sym
->block_v3
.length
);
1819 block
= symt_close_func_block(msc_dbg
->module
, curr_func
, block
, 0);
1823 symt_normalize_function(msc_dbg
->module
, curr_func
);
1828 case S_COMPILAND_V1
:
1829 TRACE("S-Compiland-V1 %x %s\n",
1830 sym
->compiland_v1
.unknown
, terminate_string(&sym
->compiland_v1
.p_name
));
1833 case S_COMPILAND_V2
:
1834 TRACE("S-Compiland-V2 %s\n", terminate_string(&sym
->compiland_v2
.p_name
));
1835 if (TRACE_ON(dbghelp_msc
))
1837 const char* ptr1
= sym
->compiland_v2
.p_name
.name
+ sym
->compiland_v2
.p_name
.namelen
;
1841 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1842 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1843 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1847 case S_COMPILAND_V3
:
1848 TRACE("S-Compiland-V3 %s\n", sym
->compiland_v3
.name
);
1849 if (TRACE_ON(dbghelp_msc
))
1851 const char* ptr1
= sym
->compiland_v3
.name
+ strlen(sym
->compiland_v3
.name
);
1855 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1856 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1857 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1863 TRACE("S-ObjName %s\n", terminate_string(&sym
->objname_v1
.p_name
));
1864 compiland
= symt_new_compiland(msc_dbg
->module
, 0 /* FIXME */,
1865 source_new(msc_dbg
->module
, NULL
,
1866 terminate_string(&sym
->objname_v1
.p_name
)));
1872 loc
.kind
= loc_absolute
;
1873 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
) - curr_func
->address
;
1874 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
, &loc
,
1875 terminate_string(&sym
->label_v1
.p_name
));
1877 else symt_new_label(msc_dbg
->module
, compiland
,
1878 terminate_string(&sym
->label_v1
.p_name
),
1879 codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
));
1884 loc
.kind
= loc_absolute
;
1885 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
) - curr_func
->address
;
1886 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1887 &loc
, sym
->label_v3
.name
);
1889 else symt_new_label(msc_dbg
->module
, compiland
, sym
->label_v3
.name
,
1890 codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
));
1896 const struct p_string
* name
;
1900 vlen
= leaf_as_variant(&v
, &sym
->constant_v1
.cvalue
);
1901 name
= (const struct p_string
*)((const char*)&sym
->constant_v1
.cvalue
+ vlen
);
1902 se
= codeview_get_type(sym
->constant_v1
.type
, FALSE
);
1904 TRACE("S-Constant-V1 %u %s %x\n",
1905 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v1
.type
);
1906 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1913 const struct p_string
* name
;
1917 vlen
= leaf_as_variant(&v
, &sym
->constant_v2
.cvalue
);
1918 name
= (const struct p_string
*)((const char*)&sym
->constant_v2
.cvalue
+ vlen
);
1919 se
= codeview_get_type(sym
->constant_v2
.type
, FALSE
);
1921 TRACE("S-Constant-V2 %u %s %x\n",
1922 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v2
.type
);
1923 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1934 vlen
= leaf_as_variant(&v
, &sym
->constant_v3
.cvalue
);
1935 name
= (const char*)&sym
->constant_v3
.cvalue
+ vlen
;
1936 se
= codeview_get_type(sym
->constant_v3
.type
, FALSE
);
1938 TRACE("S-Constant-V3 %u %s %x\n",
1939 v
.n1
.n2
.n3
.intVal
, name
, sym
->constant_v3
.type
);
1940 /* FIXME: we should add this as a constant value */
1941 symt_new_constant(msc_dbg
->module
, compiland
, name
, se
, &v
);
1946 if (sym
->udt_v1
.type
)
1948 if ((symt
= codeview_get_type(sym
->udt_v1
.type
, FALSE
)))
1949 symt_new_typedef(msc_dbg
->module
, symt
,
1950 terminate_string(&sym
->udt_v1
.p_name
));
1952 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1953 terminate_string(&sym
->udt_v1
.p_name
), sym
->udt_v1
.type
);
1957 if (sym
->udt_v2
.type
)
1959 if ((symt
= codeview_get_type(sym
->udt_v2
.type
, FALSE
)))
1960 symt_new_typedef(msc_dbg
->module
, symt
,
1961 terminate_string(&sym
->udt_v2
.p_name
));
1963 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1964 terminate_string(&sym
->udt_v2
.p_name
), sym
->udt_v2
.type
);
1968 if (sym
->udt_v3
.type
)
1970 if ((symt
= codeview_get_type(sym
->udt_v3
.type
, FALSE
)))
1971 symt_new_typedef(msc_dbg
->module
, symt
, sym
->udt_v3
.name
);
1973 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1974 sym
->udt_v3
.name
, sym
->udt_v3
.type
);
1979 * These are special, in that they are always followed by an
1980 * additional length-prefixed string which is *not* included
1981 * into the symbol length count. We need to skip it.
1989 name
= (const char*)sym
+ length
;
1990 length
+= (*name
+ 1 + 3) & ~3;
1994 case S_MSTOOL_V3
: /* just to silence a few warnings */
1995 case S_MSTOOLINFO_V3
:
1996 case S_MSTOOLENV_V3
:
2000 TRACE("Start search: seg=0x%x at offset 0x%08x\n",
2001 sym
->ssearch_v1
.segment
, sym
->ssearch_v1
.offset
);
2005 TRACE("S-Align V1\n");
2007 case S_HEAPALLOCSITE
:
2008 TRACE("heap site: offset=0x%08x at sect_idx 0x%04x, inst_len 0x%08x, index 0x%08x\n",
2009 sym
->heap_alloc_site
.offset
, sym
->heap_alloc_site
.sect_idx
,
2010 sym
->heap_alloc_site
.inst_len
, sym
->heap_alloc_site
.index
);
2013 /* the symbols we can safely ignore for now */
2015 case S_FRAMEINFO_V2
:
2016 case S_SECUCOOKIE_V3
:
2018 case S_SUBSECTINFO_V3
:
2019 case S_ENTRYPOINT_V3
:
2020 case S_LOCAL_VS2013
:
2021 case S_CALLSITEINFO
:
2022 case S_DEFRANGE_REGISTER
:
2023 case S_DEFRANGE_FRAMEPOINTER_REL
:
2024 case S_DEFRANGE_SUBFIELD_REGISTER
:
2025 case S_FPOFF_VS2013
:
2026 case S_DEFRANGE_REGISTER_REL
:
2029 case S_INLINESITE_END
:
2032 TRACE("Unsupported symbol id %x\n", sym
->generic
.id
);
2036 FIXME("Unsupported symbol id %x\n", sym
->generic
.id
);
2037 dump(sym
, 2 + sym
->generic
.len
);
2042 if (curr_func
) symt_normalize_function(msc_dbg
->module
, curr_func
);
2047 static BOOL
codeview_snarf_public(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
2048 int offset
, int size
)
2052 struct symt_compiland
* compiland
= NULL
;
2055 * Loop over the different types of records and whenever we
2056 * find something we are interested in, record it and move on.
2058 for (i
= offset
; i
< size
; i
+= length
)
2060 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
2061 length
= sym
->generic
.len
+ 2;
2062 if (i
+ length
> size
) break;
2063 if (!sym
->generic
.id
|| length
< 4) break;
2064 if (length
& 3) FIXME("unpadded len %u\n", length
);
2066 switch (sym
->generic
.id
)
2069 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2071 symt_new_public(msc_dbg
->module
, compiland
,
2072 terminate_string(&sym
->public_v1
.p_name
),
2073 sym
->public_v1
.symtype
== SYMTYPE_FUNCTION
,
2074 codeview_get_address(msc_dbg
, sym
->public_v1
.segment
, sym
->public_v1
.offset
), 1);
2078 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2080 symt_new_public(msc_dbg
->module
, compiland
,
2081 terminate_string(&sym
->public_v2
.p_name
),
2082 sym
->public_v2
.symtype
== SYMTYPE_FUNCTION
,
2083 codeview_get_address(msc_dbg
, sym
->public_v2
.segment
, sym
->public_v2
.offset
), 1);
2088 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2090 symt_new_public(msc_dbg
->module
, compiland
,
2091 sym
->public_v3
.name
,
2092 sym
->public_v3
.symtype
== SYMTYPE_FUNCTION
,
2093 codeview_get_address(msc_dbg
, sym
->public_v3
.segment
, sym
->public_v3
.offset
), 1);
2096 case S_PUB_FUNC1_V3
:
2097 case S_PUB_FUNC2_V3
: /* using a data_v3 isn't what we'd expect */
2099 /* FIXME: this is plain wrong (from a simple test) */
2100 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2102 symt_new_public(msc_dbg
->module
, compiland
,
2104 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
), 1);
2109 * Global and local data symbols. We don't associate these
2110 * with any given source file.
2114 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
2115 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
2116 sym
->generic
.id
== S_LDATA_V1
, FALSE
, FALSE
);
2120 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
2121 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
2122 sym
->generic
.id
== S_LDATA_V2
, FALSE
, FALSE
);
2126 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
2127 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
2128 sym
->generic
.id
== S_LDATA_V3
, FALSE
, FALSE
);
2131 /* variables with thread storage */
2134 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v1
.p_name
),
2135 sym
->thread_v1
.segment
, sym
->thread_v1
.offset
, sym
->thread_v1
.symtype
,
2136 sym
->generic
.id
== S_LTHREAD_V1
, TRUE
, FALSE
);
2140 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->thread_v2
.p_name
),
2141 sym
->thread_v2
.segment
, sym
->thread_v2
.offset
, sym
->thread_v2
.symtype
,
2142 sym
->generic
.id
== S_LTHREAD_V2
, TRUE
, FALSE
);
2146 codeview_add_variable(msc_dbg
, compiland
, sym
->thread_v3
.name
,
2147 sym
->thread_v3
.segment
, sym
->thread_v3
.offset
, sym
->thread_v3
.symtype
,
2148 sym
->generic
.id
== S_LTHREAD_V3
, TRUE
, FALSE
);
2152 * These are special, in that they are always followed by an
2153 * additional length-prefixed string which is *not* included
2154 * into the symbol length count. We need to skip it.
2159 length
+= (((const char*)sym
)[length
] + 1 + 3) & ~3;
2162 msc_dbg
->module
->sortlist_valid
= TRUE
;
2164 msc_dbg
->module
->sortlist_valid
= FALSE
;
2168 /*========================================================================
2172 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
,
2178 if (!size
) return NULL
;
2180 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2181 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2183 for (i
= 0; i
< num_blocks
; i
++)
2184 memcpy(buffer
+ i
* pdb
->block_size
,
2185 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2190 static void* pdb_ds_read(const struct PDB_DS_HEADER
* pdb
, const DWORD
* block_list
,
2196 if (!size
) return NULL
;
2198 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2199 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2201 for (i
= 0; i
< num_blocks
; i
++)
2202 memcpy(buffer
+ i
* pdb
->block_size
,
2203 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2208 static void* pdb_read_jg_file(const struct PDB_JG_HEADER
* pdb
,
2209 const struct PDB_JG_TOC
* toc
, DWORD file_nr
)
2211 const WORD
* block_list
;
2214 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2216 block_list
= (const WORD
*) &toc
->file
[toc
->num_files
];
2217 for (i
= 0; i
< file_nr
; i
++)
2218 block_list
+= (toc
->file
[i
].size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2220 return pdb_jg_read(pdb
, block_list
, toc
->file
[file_nr
].size
);
2223 static void* pdb_read_ds_file(const struct PDB_DS_HEADER
* pdb
,
2224 const struct PDB_DS_TOC
* toc
, DWORD file_nr
)
2226 const DWORD
* block_list
;
2229 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2230 if (toc
->file_size
[file_nr
] == 0 || toc
->file_size
[file_nr
] == 0xFFFFFFFF) return NULL
;
2232 block_list
= &toc
->file_size
[toc
->num_files
];
2233 for (i
= 0; i
< file_nr
; i
++)
2234 block_list
+= (toc
->file_size
[i
] + pdb
->block_size
- 1) / pdb
->block_size
;
2236 return pdb_ds_read(pdb
, block_list
, toc
->file_size
[file_nr
]);
2239 static void* pdb_read_file(const struct pdb_file_info
* pdb_file
,
2242 switch (pdb_file
->kind
)
2245 return pdb_read_jg_file((const struct PDB_JG_HEADER
*)pdb_file
->image
,
2246 pdb_file
->u
.jg
.toc
, file_nr
);
2248 return pdb_read_ds_file((const struct PDB_DS_HEADER
*)pdb_file
->image
,
2249 pdb_file
->u
.ds
.toc
, file_nr
);
2254 static unsigned pdb_get_file_size(const struct pdb_file_info
* pdb_file
, DWORD file_nr
)
2256 switch (pdb_file
->kind
)
2258 case PDB_JG
: return pdb_file
->u
.jg
.toc
->file
[file_nr
].size
;
2259 case PDB_DS
: return pdb_file
->u
.ds
.toc
->file_size
[file_nr
];
2264 static void pdb_free(void* buffer
)
2266 HeapFree(GetProcessHeap(), 0, buffer
);
2269 static void pdb_free_file(struct pdb_file_info
* pdb_file
)
2271 switch (pdb_file
->kind
)
2274 pdb_free(pdb_file
->u
.jg
.toc
);
2275 pdb_file
->u
.jg
.toc
= NULL
;
2278 pdb_free(pdb_file
->u
.ds
.toc
);
2279 pdb_file
->u
.ds
.toc
= NULL
;
2282 HeapFree(GetProcessHeap(), 0, pdb_file
->stream_dict
);
2285 static void pdb_load_stream_name_table(struct pdb_file_info
* pdb_file
, const char* str
, unsigned cb
)
2293 pdw
= (DWORD
*)(str
+ cb
);
2297 pdb_file
->stream_dict
= HeapAlloc(GetProcessHeap(), 0, (numok
+ 1) * sizeof(struct pdb_stream_name
) + cb
);
2298 if (!pdb_file
->stream_dict
) return;
2299 cpstr
= (char*)(pdb_file
->stream_dict
+ numok
+ 1);
2300 memcpy(cpstr
, str
, cb
);
2302 /* bitfield: first dword is len (in dword), then data */
2304 pdw
+= *ok_bits
++ + 1;
2307 FIXME("unexpected value\n");
2311 for (i
= j
= 0; i
< count
; i
++)
2313 if (ok_bits
[i
/ 32] & (1 << (i
% 32)))
2315 if (j
>= numok
) break;
2316 pdb_file
->stream_dict
[j
].name
= &cpstr
[*pdw
++];
2317 pdb_file
->stream_dict
[j
].index
= *pdw
++;
2322 pdb_file
->stream_dict
[numok
].name
= NULL
;
2323 pdb_file
->fpoext_stream
= -1;
2326 static unsigned pdb_get_stream_by_name(const struct pdb_file_info
* pdb_file
, const char* name
)
2328 struct pdb_stream_name
* psn
;
2330 for (psn
= pdb_file
->stream_dict
; psn
&& psn
->name
; psn
++)
2332 if (!strcmp(psn
->name
, name
)) return psn
->index
;
2337 static void* pdb_read_strings(const struct pdb_file_info
* pdb_file
)
2342 idx
= pdb_get_stream_by_name(pdb_file
, "/names");
2345 ret
= pdb_read_file( pdb_file
, idx
);
2346 if (ret
&& *(const DWORD
*)ret
== 0xeffeeffe) return ret
;
2349 WARN("string table not found\n");
2353 static void pdb_module_remove(struct process
* pcsn
, struct module_format
* modfmt
)
2357 for (i
= 0; i
< modfmt
->u
.pdb_info
->used_subfiles
; i
++)
2359 pdb_free_file(&modfmt
->u
.pdb_info
->pdb_files
[i
]);
2360 if (modfmt
->u
.pdb_info
->pdb_files
[i
].image
)
2361 UnmapViewOfFile(modfmt
->u
.pdb_info
->pdb_files
[i
].image
);
2362 if (modfmt
->u
.pdb_info
->pdb_files
[i
].hMap
)
2363 CloseHandle(modfmt
->u
.pdb_info
->pdb_files
[i
].hMap
);
2365 HeapFree(GetProcessHeap(), 0, modfmt
);
2368 static void pdb_convert_types_header(PDB_TYPES
* types
, const BYTE
* image
)
2370 memset(types
, 0, sizeof(PDB_TYPES
));
2373 if (*(const DWORD
*)image
< 19960000) /* FIXME: correct version? */
2375 /* Old version of the types record header */
2376 const PDB_TYPES_OLD
* old
= (const PDB_TYPES_OLD
*)image
;
2377 types
->version
= old
->version
;
2378 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
2379 types
->type_size
= old
->type_size
;
2380 types
->first_index
= old
->first_index
;
2381 types
->last_index
= old
->last_index
;
2382 types
->file
= old
->file
;
2386 /* New version of the types record header */
2387 *types
= *(const PDB_TYPES
*)image
;
2391 static void pdb_convert_symbols_header(PDB_SYMBOLS
* symbols
,
2392 int* header_size
, const BYTE
* image
)
2394 memset(symbols
, 0, sizeof(PDB_SYMBOLS
));
2397 if (*(const DWORD
*)image
!= 0xffffffff)
2399 /* Old version of the symbols record header */
2400 const PDB_SYMBOLS_OLD
* old
= (const PDB_SYMBOLS_OLD
*)image
;
2401 symbols
->version
= 0;
2402 symbols
->module_size
= old
->module_size
;
2403 symbols
->offset_size
= old
->offset_size
;
2404 symbols
->hash_size
= old
->hash_size
;
2405 symbols
->srcmodule_size
= old
->srcmodule_size
;
2406 symbols
->pdbimport_size
= 0;
2407 symbols
->hash1_file
= old
->hash1_file
;
2408 symbols
->hash2_file
= old
->hash2_file
;
2409 symbols
->gsym_file
= old
->gsym_file
;
2411 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
2415 /* New version of the symbols record header */
2416 *symbols
= *(const PDB_SYMBOLS
*)image
;
2417 *header_size
= sizeof(PDB_SYMBOLS
);
2421 static void pdb_convert_symbol_file(const PDB_SYMBOLS
* symbols
,
2422 PDB_SYMBOL_FILE_EX
* sfile
,
2423 unsigned* size
, const void* image
)
2426 if (symbols
->version
< 19970000)
2428 const PDB_SYMBOL_FILE
*sym_file
= image
;
2429 memset(sfile
, 0, sizeof(*sfile
));
2430 sfile
->file
= sym_file
->file
;
2431 sfile
->range
.index
= sym_file
->range
.index
;
2432 sfile
->symbol_size
= sym_file
->symbol_size
;
2433 sfile
->lineno_size
= sym_file
->lineno_size
;
2434 *size
= sizeof(PDB_SYMBOL_FILE
) - 1;
2438 memcpy(sfile
, image
, sizeof(PDB_SYMBOL_FILE_EX
));
2439 *size
= sizeof(PDB_SYMBOL_FILE_EX
) - 1;
2443 static HANDLE
map_pdb_file(const struct process
* pcs
,
2444 const struct pdb_lookup
* lookup
,
2445 struct module
* module
)
2447 HANDLE hFile
, hMap
= NULL
;
2448 WCHAR dbg_file_path
[MAX_PATH
];
2451 switch (lookup
->kind
)
2454 ret
= path_find_symbol_file(pcs
, module
, lookup
->filename
, DMT_PDB
, NULL
, lookup
->timestamp
,
2455 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2458 ret
= path_find_symbol_file(pcs
, module
, lookup
->filename
, DMT_PDB
, &lookup
->guid
, 0,
2459 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2464 WARN("\tCouldn't find %s\n", lookup
->filename
);
2467 if ((hFile
= CreateFileW(dbg_file_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2468 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) != INVALID_HANDLE_VALUE
)
2470 hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
2476 static void pdb_process_types(const struct msc_debug_info
* msc_dbg
,
2477 const struct pdb_file_info
* pdb_file
)
2479 BYTE
* types_image
= NULL
;
2481 types_image
= pdb_read_file(pdb_file
, 2);
2485 struct codeview_type_parse ctp
;
2490 pdb_convert_types_header(&types
, types_image
);
2492 /* Check for unknown versions */
2493 switch (types
.version
)
2495 case 19950410: /* VC 4.0 */
2497 case 19961031: /* VC 5.0 / 6.0 */
2498 case 19990903: /* VC 7.0 */
2499 case 20040203: /* VC 8.0 */
2502 ERR("-Unknown type info version %d\n", types
.version
);
2505 ctp
.module
= msc_dbg
->module
;
2506 /* reconstruct the types offset...
2507 * FIXME: maybe it's present in the newest PDB_TYPES structures
2509 total
= types
.last_index
- types
.first_index
+ 1;
2510 offset
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD
) * total
);
2511 ctp
.table
= ptr
= types_image
+ types
.type_offset
;
2513 while (ptr
< ctp
.table
+ types
.type_size
&& ctp
.num
< total
)
2515 offset
[ctp
.num
++] = ptr
- ctp
.table
;
2516 ptr
+= ((const union codeview_type
*)ptr
)->generic
.len
+ 2;
2518 ctp
.offset
= offset
;
2520 /* Read type table */
2521 codeview_parse_type_table(&ctp
);
2522 HeapFree(GetProcessHeap(), 0, offset
);
2523 pdb_free(types_image
);
2527 static const char PDB_JG_IDENT
[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
2528 static const char PDB_DS_IDENT
[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
2530 /******************************************************************
2533 * Tries to load a pdb file
2534 * 'matched' is filled with the number of correct matches for this file:
2535 * - age counts for one
2536 * - timestamp or guid depending on kind counts for one
2537 * a wrong kind of file returns FALSE (FIXME ?)
2539 static BOOL
pdb_init(const struct pdb_lookup
* pdb_lookup
, struct pdb_file_info
* pdb_file
,
2540 const char* image
, unsigned* matched
)
2544 /* check the file header, and if ok, load the TOC */
2545 TRACE("PDB(%s): %.40s\n", pdb_lookup
->filename
, debugstr_an(image
, 40));
2548 if (!memcmp(image
, PDB_JG_IDENT
, sizeof(PDB_JG_IDENT
)))
2550 const struct PDB_JG_HEADER
* pdb
= (const struct PDB_JG_HEADER
*)image
;
2551 struct PDB_JG_ROOT
* root
;
2553 pdb_file
->u
.jg
.toc
= pdb_jg_read(pdb
, pdb
->toc_block
, pdb
->toc
.size
);
2554 root
= pdb_read_jg_file(pdb
, pdb_file
->u
.jg
.toc
, 1);
2557 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2560 switch (root
->Version
)
2562 case 19950623: /* VC 4.0 */
2564 case 19960307: /* VC 5.0 */
2565 case 19970604: /* VC 6.0 */
2568 ERR("-Unknown root block version %d\n", root
->Version
);
2570 if (pdb_lookup
->kind
!= PDB_JG
)
2572 WARN("Found %s, but wrong PDB kind\n", pdb_lookup
->filename
);
2576 pdb_file
->kind
= PDB_JG
;
2577 pdb_file
->u
.jg
.timestamp
= root
->TimeDateStamp
;
2578 pdb_file
->age
= root
->Age
;
2579 if (root
->TimeDateStamp
== pdb_lookup
->timestamp
) (*matched
)++;
2580 else WARN("Found %s, but wrong signature: %08x %08x\n",
2581 pdb_lookup
->filename
, root
->TimeDateStamp
, pdb_lookup
->timestamp
);
2582 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2583 else WARN("Found %s, but wrong age: %08x %08x\n",
2584 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2585 TRACE("found JG for %s: age=%x timestamp=%x\n",
2586 pdb_lookup
->filename
, root
->Age
, root
->TimeDateStamp
);
2587 pdb_load_stream_name_table(pdb_file
, &root
->names
[0], root
->cbNames
);
2591 else if (!memcmp(image
, PDB_DS_IDENT
, sizeof(PDB_DS_IDENT
)))
2593 const struct PDB_DS_HEADER
* pdb
= (const struct PDB_DS_HEADER
*)image
;
2594 struct PDB_DS_ROOT
* root
;
2596 pdb_file
->u
.ds
.toc
=
2598 (const DWORD
*)((const char*)pdb
+ pdb
->toc_page
* pdb
->block_size
),
2600 root
= pdb_read_ds_file(pdb
, pdb_file
->u
.ds
.toc
, 1);
2603 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2606 switch (root
->Version
)
2611 ERR("-Unknown root block version %d\n", root
->Version
);
2613 pdb_file
->kind
= PDB_DS
;
2614 pdb_file
->u
.ds
.guid
= root
->guid
;
2615 pdb_file
->age
= root
->Age
;
2616 if (!memcmp(&root
->guid
, &pdb_lookup
->guid
, sizeof(GUID
))) (*matched
)++;
2617 else WARN("Found %s, but wrong GUID: %s %s\n",
2618 pdb_lookup
->filename
, debugstr_guid(&root
->guid
),
2619 debugstr_guid(&pdb_lookup
->guid
));
2620 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2621 else WARN("Found %s, but wrong age: %08x %08x\n",
2622 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2623 TRACE("found DS for %s: age=%x guid=%s\n",
2624 pdb_lookup
->filename
, root
->Age
, debugstr_guid(&root
->guid
));
2625 pdb_load_stream_name_table(pdb_file
, &root
->names
[0], root
->cbNames
);
2630 if (0) /* some tool to dump the internal files from a PDB file */
2634 switch (pdb_file
->kind
)
2636 case PDB_JG
: num_files
= pdb_file
->u
.jg
.toc
->num_files
; break;
2637 case PDB_DS
: num_files
= pdb_file
->u
.ds
.toc
->num_files
; break;
2640 for (i
= 1; i
< num_files
; i
++)
2642 unsigned char* x
= pdb_read_file(pdb_file
, i
);
2643 FIXME("********************** [%u]: size=%08x\n",
2644 i
, pdb_get_file_size(pdb_file
, i
));
2645 dump(x
, pdb_get_file_size(pdb_file
, i
));
2652 static BOOL
pdb_process_internal(const struct process
* pcs
,
2653 const struct msc_debug_info
* msc_dbg
,
2654 const struct pdb_lookup
* pdb_lookup
,
2655 struct pdb_module_info
* pdb_module_info
,
2656 unsigned module_index
);
2658 static void pdb_process_symbol_imports(const struct process
* pcs
,
2659 const struct msc_debug_info
* msc_dbg
,
2660 const PDB_SYMBOLS
* symbols
,
2661 const void* symbols_image
,
2663 const struct pdb_lookup
* pdb_lookup
,
2664 struct pdb_module_info
* pdb_module_info
,
2665 unsigned module_index
)
2667 if (module_index
== -1 && symbols
&& symbols
->pdbimport_size
)
2669 const PDB_SYMBOL_IMPORT
*imp
;
2674 struct pdb_file_info sf0
= pdb_module_info
->pdb_files
[0];
2676 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2677 symbols
->module_size
+ symbols
->offset_size
+
2678 symbols
->hash_size
+ symbols
->srcmodule_size
);
2680 last
= (const char*)imp
+ symbols
->pdbimport_size
;
2681 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
2683 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
2684 if (i
>= CV_MAX_MODULES
) FIXME("Out of bounds!!!\n");
2685 if (!stricmp(pdb_lookup
->filename
, imp
->filename
))
2687 if (module_index
!= -1) FIXME("Twice the entry\n");
2688 else module_index
= i
;
2689 pdb_module_info
->pdb_files
[i
] = sf0
;
2693 struct pdb_lookup imp_pdb_lookup
;
2695 /* FIXME: this is an import of a JG PDB file
2696 * how's a DS PDB handled ?
2698 imp_pdb_lookup
.filename
= imp
->filename
;
2699 imp_pdb_lookup
.kind
= PDB_JG
;
2700 imp_pdb_lookup
.timestamp
= imp
->TimeDateStamp
;
2701 imp_pdb_lookup
.age
= imp
->Age
;
2702 TRACE("got for %s: age=%u ts=%x\n",
2703 imp
->filename
, imp
->Age
, imp
->TimeDateStamp
);
2704 pdb_process_internal(pcs
, msc_dbg
, &imp_pdb_lookup
, pdb_module_info
, i
);
2707 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)first
+ ((ptr
- (const char*)first
+ strlen(ptr
) + 1 + 3) & ~3));
2709 pdb_module_info
->used_subfiles
= i
;
2711 if (module_index
== -1)
2714 pdb_module_info
->used_subfiles
= 1;
2716 cv_current_module
= &cv_zmodules
[module_index
];
2717 if (cv_current_module
->allowed
) FIXME("Already allowed??\n");
2718 cv_current_module
->allowed
= TRUE
;
2721 static BOOL
pdb_process_internal(const struct process
* pcs
,
2722 const struct msc_debug_info
* msc_dbg
,
2723 const struct pdb_lookup
* pdb_lookup
,
2724 struct pdb_module_info
* pdb_module_info
,
2725 unsigned module_index
)
2729 BYTE
* symbols_image
= NULL
;
2730 char* files_image
= NULL
;
2731 DWORD files_size
= 0;
2733 struct pdb_file_info
* pdb_file
;
2735 TRACE("Processing PDB file %s\n", pdb_lookup
->filename
);
2737 pdb_file
= &pdb_module_info
->pdb_files
[module_index
== -1 ? 0 : module_index
];
2738 /* Open and map() .PDB file */
2739 if ((hMap
= map_pdb_file(pcs
, pdb_lookup
, msc_dbg
->module
)) == NULL
||
2740 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2742 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2746 if (!pdb_init(pdb_lookup
, pdb_file
, image
, &matched
) || matched
!= 2)
2749 UnmapViewOfFile(image
);
2753 pdb_file
->hMap
= hMap
;
2754 pdb_file
->image
= image
;
2755 symbols_image
= pdb_read_file(pdb_file
, 3);
2758 PDB_SYMBOLS symbols
;
2762 int header_size
= 0;
2763 PDB_STREAM_INDEXES
* psi
;
2765 pdb_convert_symbols_header(&symbols
, &header_size
, symbols_image
);
2766 switch (symbols
.version
)
2768 case 0: /* VC 4.0 */
2769 case 19960307: /* VC 5.0 */
2770 case 19970606: /* VC 6.0 */
2774 ERR("-Unknown symbol info version %d %08x\n",
2775 symbols
.version
, symbols
.version
);
2778 switch (symbols
.stream_index_size
)
2781 case sizeof(PDB_STREAM_INDEXES_OLD
):
2782 /* no fpo ext stream in this case */
2784 case sizeof(PDB_STREAM_INDEXES
):
2785 psi
= (PDB_STREAM_INDEXES
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2786 symbols
.module_size
+ symbols
.offset_size
+
2787 symbols
.hash_size
+ symbols
.srcmodule_size
+
2788 symbols
.pdbimport_size
+ symbols
.unknown2_size
);
2789 pdb_file
->fpoext_stream
= psi
->FPO_EXT
;
2792 FIXME("Unknown PDB_STREAM_INDEXES size (%d)\n", symbols
.stream_index_size
);
2795 files_image
= pdb_read_strings(pdb_file
);
2796 if (files_image
) files_size
= *(const DWORD
*)(files_image
+ 8);
2798 pdb_process_symbol_imports(pcs
, msc_dbg
, &symbols
, symbols_image
, image
,
2799 pdb_lookup
, pdb_module_info
, module_index
);
2800 pdb_process_types(msc_dbg
, pdb_file
);
2802 /* Read global symbol table */
2803 globalimage
= pdb_read_file(pdb_file
, symbols
.gsym_file
);
2806 codeview_snarf(msc_dbg
, globalimage
, 0,
2807 pdb_get_file_size(pdb_file
, symbols
.gsym_file
), FALSE
);
2810 /* Read per-module symbols' tables */
2811 file
= symbols_image
+ header_size
;
2812 while (file
- symbols_image
< header_size
+ symbols
.module_size
)
2814 PDB_SYMBOL_FILE_EX sfile
;
2815 const char* file_name
;
2818 HeapValidate(GetProcessHeap(), 0, NULL
);
2819 pdb_convert_symbol_file(&symbols
, &sfile
, &size
, file
);
2821 modimage
= pdb_read_file(pdb_file
, sfile
.file
);
2824 if (sfile
.symbol_size
)
2825 codeview_snarf(msc_dbg
, modimage
, sizeof(DWORD
),
2826 sfile
.symbol_size
, TRUE
);
2828 if (sfile
.lineno_size
)
2829 codeview_snarf_linetab(msc_dbg
,
2830 modimage
+ sfile
.symbol_size
,
2832 pdb_file
->kind
== PDB_JG
);
2834 codeview_snarf_linetab2(msc_dbg
, modimage
+ sfile
.symbol_size
+ sfile
.lineno_size
,
2835 pdb_get_file_size(pdb_file
, sfile
.file
) - sfile
.symbol_size
- sfile
.lineno_size
,
2836 files_image
+ 12, files_size
);
2840 file_name
= (const char*)file
+ size
;
2841 file_name
+= strlen(file_name
) + 1;
2842 file
= (BYTE
*)((DWORD_PTR
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3);
2844 /* finish the remaining public and global information */
2847 codeview_snarf_public(msc_dbg
, globalimage
, 0,
2848 pdb_get_file_size(pdb_file
, symbols
.gsym_file
));
2849 pdb_free(globalimage
);
2853 pdb_process_symbol_imports(pcs
, msc_dbg
, NULL
, NULL
, image
,
2854 pdb_lookup
, pdb_module_info
, module_index
);
2856 pdb_free(symbols_image
);
2857 pdb_free(files_image
);
2862 static BOOL
pdb_process_file(const struct process
* pcs
,
2863 const struct msc_debug_info
* msc_dbg
,
2864 struct pdb_lookup
* pdb_lookup
)
2867 struct module_format
* modfmt
;
2868 struct pdb_module_info
* pdb_module_info
;
2870 modfmt
= HeapAlloc(GetProcessHeap(), 0,
2871 sizeof(struct module_format
) + sizeof(struct pdb_module_info
));
2872 if (!modfmt
) return FALSE
;
2874 pdb_module_info
= (void*)(modfmt
+ 1);
2875 msc_dbg
->module
->format_info
[DFI_PDB
] = modfmt
;
2876 modfmt
->module
= msc_dbg
->module
;
2877 modfmt
->remove
= pdb_module_remove
;
2878 modfmt
->loc_compute
= NULL
;
2879 modfmt
->u
.pdb_info
= pdb_module_info
;
2881 memset(cv_zmodules
, 0, sizeof(cv_zmodules
));
2882 codeview_init_basic_types(msc_dbg
->module
);
2883 ret
= pdb_process_internal(pcs
, msc_dbg
, pdb_lookup
,
2884 msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
, -1);
2885 codeview_clear_type_table();
2888 struct pdb_module_info
* pdb_info
= msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
;
2889 msc_dbg
->module
->module
.SymType
= SymPdb
;
2890 if (pdb_info
->pdb_files
[0].kind
== PDB_JG
)
2891 msc_dbg
->module
->module
.PdbSig
= pdb_info
->pdb_files
[0].u
.jg
.timestamp
;
2893 msc_dbg
->module
->module
.PdbSig70
= pdb_info
->pdb_files
[0].u
.ds
.guid
;
2894 msc_dbg
->module
->module
.PdbAge
= pdb_info
->pdb_files
[0].age
;
2895 MultiByteToWideChar(CP_ACP
, 0, pdb_lookup
->filename
, -1,
2896 msc_dbg
->module
->module
.LoadedPdbName
,
2897 ARRAY_SIZE(msc_dbg
->module
->module
.LoadedPdbName
));
2898 /* FIXME: we could have a finer grain here */
2899 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
2900 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
2901 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
2902 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
2903 msc_dbg
->module
->module
.Publics
= TRUE
;
2907 msc_dbg
->module
->format_info
[DFI_PDB
] = NULL
;
2908 HeapFree(GetProcessHeap(), 0, modfmt
);
2913 BOOL
pdb_fetch_file_info(const struct pdb_lookup
* pdb_lookup
, unsigned* matched
)
2915 HANDLE hFile
, hMap
= NULL
;
2918 struct pdb_file_info pdb_file
;
2920 if ((hFile
= CreateFileA(pdb_lookup
->filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2921 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) == INVALID_HANDLE_VALUE
||
2922 ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
2923 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2925 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2930 ret
= pdb_init(pdb_lookup
, &pdb_file
, image
, matched
);
2931 pdb_free_file(&pdb_file
);
2934 if (image
) UnmapViewOfFile(image
);
2935 if (hMap
) CloseHandle(hMap
);
2936 if (hFile
!= INVALID_HANDLE_VALUE
) CloseHandle(hFile
);
2941 /*========================================================================
2942 * FPO unwinding code
2945 /* Stack unwinding is based on postfixed operations.
2946 * Let's define our Postfix EValuator
2948 #define PEV_MAX_LEN 32
2951 struct cpu_stack_walk
* csw
;
2953 struct vector stack
;
2955 struct hash_table values
;
2962 struct hash_table_elt elt
;
2965 #define PEV_ERROR(pev, msg) snprintf((pev)->error, sizeof((pev)->error), "%s", (msg))
2966 #define PEV_ERROR1(pev, msg, pmt) snprintf((pev)->error, sizeof((pev)->error), (msg), (pmt))
2969 static void pev_dump_stack(struct pevaluator
* pev
)
2972 FIXME("stack #%d\n", pev
->stk_index
);
2973 for (i
= 0; i
< pev
->stk_index
; i
++)
2975 FIXME("\t%d) %s\n", i
, *(char**)vector_at(&pev
->stack
, i
));
2980 /* get the value out of an operand (variable or literal) */
2981 static BOOL
pev_get_val(struct pevaluator
* pev
, const char* str
, DWORD_PTR
* val
)
2984 struct hash_table_iter hti
;
2991 hash_table_iter_init(&pev
->values
, &hti
, str
);
2992 while ((ptr
= hash_table_iter_up(&hti
)))
2994 if (!strcmp(CONTAINING_RECORD(ptr
, struct zvalue
, elt
)->elt
.name
, str
))
2996 *val
= CONTAINING_RECORD(ptr
, struct zvalue
, elt
)->value
;
3000 return PEV_ERROR1(pev
, "get_zvalue: no value found (%s)", str
);
3002 *val
= strtol(str
, &n
, 10);
3003 if (n
== str
|| *n
!= '\0')
3004 return PEV_ERROR1(pev
, "get_val: not a literal (%s)", str
);
3009 /* push an operand onto the stack */
3010 static BOOL
pev_push(struct pevaluator
* pev
, const char* elt
)
3013 if (pev
->stk_index
< vector_length(&pev
->stack
))
3014 at
= vector_at(&pev
->stack
, pev
->stk_index
);
3016 at
= vector_add(&pev
->stack
, &pev
->pool
);
3017 if (!at
) return PEV_ERROR(pev
, "push: out of memory");
3018 *at
= pool_strdup(&pev
->pool
, elt
);
3023 /* pop an operand from the stack */
3024 static BOOL
pev_pop(struct pevaluator
* pev
, char* elt
)
3026 char** at
= vector_at(&pev
->stack
, --pev
->stk_index
);
3027 if (!at
) return PEV_ERROR(pev
, "pop: stack empty");
3032 /* pop an operand from the stack, and gets its value */
3033 static BOOL
pev_pop_val(struct pevaluator
* pev
, DWORD_PTR
* val
)
3035 char p
[PEV_MAX_LEN
];
3037 return pev_pop(pev
, p
) && pev_get_val(pev
, p
, val
);
3040 /* set var 'name' a new value (creates the var if it doesn't exist) */
3041 static BOOL
pev_set_value(struct pevaluator
* pev
, const char* name
, DWORD_PTR val
)
3043 struct hash_table_iter hti
;
3046 hash_table_iter_init(&pev
->values
, &hti
, name
);
3047 while ((ptr
= hash_table_iter_up(&hti
)))
3049 if (!strcmp(CONTAINING_RECORD(ptr
, struct zvalue
, elt
)->elt
.name
, name
))
3051 CONTAINING_RECORD(ptr
, struct zvalue
, elt
)->value
= val
;
3057 struct zvalue
* zv
= pool_alloc(&pev
->pool
, sizeof(*zv
));
3058 if (!zv
) return PEV_ERROR(pev
, "set_value: out of memory");
3061 zv
->elt
.name
= pool_strdup(&pev
->pool
, name
);
3062 hash_table_add(&pev
->values
, &zv
->elt
);
3067 /* execute a binary operand from the two top most values on the stack.
3068 * puts result on top of the stack */
3069 static BOOL
pev_binop(struct pevaluator
* pev
, char op
)
3071 char res
[PEV_MAX_LEN
];
3072 DWORD_PTR v1
, v2
, c
;
3074 if (!pev_pop_val(pev
, &v1
) || !pev_pop_val(pev
, &v2
)) return FALSE
;
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 case '%': c
= v1
% v2
; break;
3082 default: return PEV_ERROR1(pev
, "binop: unknown op (%c)", op
);
3084 snprintf(res
, sizeof(res
), "%ld", c
);
3089 /* pops top most operand, dereference it, on pushes the result on top of the stack */
3090 static BOOL
pev_deref(struct pevaluator
* pev
)
3092 char res
[PEV_MAX_LEN
];
3093 DWORD_PTR v1
, v2
= 0;
3095 if (!pev_pop_val(pev
, &v1
)) return FALSE
;
3096 if (!sw_read_mem(pev
->csw
, v1
, &v2
, pev
->csw
->cpu
->word_size
))
3097 return PEV_ERROR1(pev
, "deref: cannot read mem at %lx\n", v1
);
3098 snprintf(res
, sizeof(res
), "%ld", v2
);
3103 /* assign value to variable (from two top most operands) */
3104 static BOOL
pev_assign(struct pevaluator
* pev
)
3106 char p2
[PEV_MAX_LEN
];
3109 if (!pev_pop_val(pev
, &v1
) || !pev_pop(pev
, p2
)) return FALSE
;
3110 if (p2
[0] != '$') return PEV_ERROR1(pev
, "assign: %s isn't a variable", p2
);
3111 pev_set_value(pev
, p2
, v1
);
3116 /* initializes the postfix evaluator */
3117 static void pev_init(struct pevaluator
* pev
, struct cpu_stack_walk
* csw
,
3118 PDB_FPO_DATA
* fpoext
, struct pdb_cmd_pair
* cpair
)
3121 pool_init(&pev
->pool
, 512);
3122 vector_init(&pev
->stack
, sizeof(char*), 8);
3124 hash_table_init(&pev
->pool
, &pev
->values
, 8);
3125 pev
->error
[0] = '\0';
3126 for (; cpair
->name
; cpair
++)
3127 pev_set_value(pev
, cpair
->name
, *cpair
->pvalue
);
3128 pev_set_value(pev
, ".raSearchStart", fpoext
->start
);
3129 pev_set_value(pev
, ".cbLocals", fpoext
->locals_size
);
3130 pev_set_value(pev
, ".cbParams", fpoext
->params_size
);
3131 pev_set_value(pev
, ".cbSavedRegs", fpoext
->savedregs_size
);
3134 static BOOL
pev_free(struct pevaluator
* pev
, struct pdb_cmd_pair
* cpair
)
3138 if (cpair
) for (; cpair
->name
; cpair
++)
3140 if (pev_get_val(pev
, cpair
->name
, &val
))
3141 *cpair
->pvalue
= val
;
3143 pool_destroy(&pev
->pool
);
3147 static BOOL
pdb_parse_cmd_string(struct cpu_stack_walk
* csw
, PDB_FPO_DATA
* fpoext
,
3148 const char* cmd
, struct pdb_cmd_pair
* cpair
)
3150 char token
[PEV_MAX_LEN
];
3154 struct pevaluator pev
;
3156 pev_init(&pev
, csw
, fpoext
, cpair
);
3157 for (ptr
= cmd
; !over
; ptr
++)
3159 if (*ptr
== ' ' || (over
= *ptr
== '\0'))
3163 if (!strcmp(token
, "+") || !strcmp(token
, "-") || !strcmp(token
, "*") ||
3164 !strcmp(token
, "/") || !strcmp(token
, "%"))
3166 if (!pev_binop(&pev
, token
[0])) goto done
;
3168 else if (!strcmp(token
, "^"))
3170 if (!pev_deref(&pev
)) goto done
;
3172 else if (!strcmp(token
, "="))
3174 if (!pev_assign(&pev
)) goto done
;
3178 if (!pev_push(&pev
, token
)) goto done
;
3184 if (ptok
- token
>= PEV_MAX_LEN
- 1)
3186 PEV_ERROR1(&pev
, "parse: token too long (%s)", ptr
- (ptok
- token
));
3192 pev_free(&pev
, cpair
);
3195 FIXME("Couldn't evaluate %s => %s\n", wine_dbgstr_a(cmd
), pev
.error
);
3196 pev_free(&pev
, NULL
);
3200 BOOL
pdb_virtual_unwind(struct cpu_stack_walk
*csw
, DWORD_PTR ip
,
3201 union ctx
*context
, struct pdb_cmd_pair
*cpair
)
3203 struct module_pair pair
;
3204 struct pdb_module_info
* pdb_info
;
3205 PDB_FPO_DATA
* fpoext
;
3206 unsigned i
, size
, strsize
;
3210 if (!(pair
.pcs
= process_find_by_handle(csw
->hProcess
)) ||
3211 !(pair
.requested
= module_find_by_addr(pair
.pcs
, ip
, DMT_UNKNOWN
)) ||
3212 !module_get_debug(&pair
))
3214 if (!pair
.effective
->format_info
[DFI_PDB
]) return FALSE
;
3215 pdb_info
= pair
.effective
->format_info
[DFI_PDB
]->u
.pdb_info
;
3216 TRACE("searching %lx => %lx\n", ip
, ip
- (DWORD_PTR
)pair
.effective
->module
.BaseOfImage
);
3217 ip
-= (DWORD_PTR
)pair
.effective
->module
.BaseOfImage
;
3219 strbase
= pdb_read_strings(&pdb_info
->pdb_files
[0]);
3220 if (!strbase
) return FALSE
;
3221 strsize
= *(const DWORD
*)(strbase
+ 8);
3222 fpoext
= pdb_read_file(&pdb_info
->pdb_files
[0], pdb_info
->pdb_files
[0].fpoext_stream
);
3223 size
= pdb_get_file_size(&pdb_info
->pdb_files
[0], pdb_info
->pdb_files
[0].fpoext_stream
);
3224 if (fpoext
&& (size
% sizeof(*fpoext
)) == 0)
3226 size
/= sizeof(*fpoext
);
3227 for (i
= 0; i
< size
; i
++)
3229 if (fpoext
[i
].start
<= ip
&& ip
< fpoext
[i
].start
+ fpoext
[i
].func_size
)
3231 TRACE("\t%08x %08x %8x %8x %4x %4x %4x %08x %s\n",
3232 fpoext
[i
].start
, fpoext
[i
].func_size
, fpoext
[i
].locals_size
,
3233 fpoext
[i
].params_size
, fpoext
[i
].maxstack_size
, fpoext
[i
].prolog_size
,
3234 fpoext
[i
].savedregs_size
, fpoext
[i
].flags
,
3235 fpoext
[i
].str_offset
< strsize
?
3236 wine_dbgstr_a(strbase
+ 12 + fpoext
[i
].str_offset
) : "<out of bounds>");
3237 if (fpoext
[i
].str_offset
< strsize
)
3238 ret
= pdb_parse_cmd_string(csw
, &fpoext
[i
], strbase
+ 12 + fpoext
[i
].str_offset
, cpair
);
3252 /*========================================================================
3253 * Process CodeView debug information.
3256 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
3257 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
3258 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
3259 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
3260 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
3262 static BOOL
codeview_process_info(const struct process
* pcs
,
3263 const struct msc_debug_info
* msc_dbg
)
3265 const DWORD
* signature
= (const DWORD
*)msc_dbg
->root
;
3267 struct pdb_lookup pdb_lookup
;
3269 TRACE("Processing signature %.4s\n", (const char*)signature
);
3273 case CODEVIEW_NB09_SIG
:
3274 case CODEVIEW_NB11_SIG
:
3276 const OMFSignature
* cv
= (const OMFSignature
*)msc_dbg
->root
;
3277 const OMFDirHeader
* hdr
= (const OMFDirHeader
*)(msc_dbg
->root
+ cv
->filepos
);
3278 const OMFDirEntry
* ent
;
3279 const OMFDirEntry
* prev
;
3280 const OMFDirEntry
* next
;
3283 codeview_init_basic_types(msc_dbg
->module
);
3285 for (i
= 0; i
< hdr
->cDir
; i
++)
3287 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
+ i
* hdr
->cbDirEntry
);
3288 if (ent
->SubSection
== sstGlobalTypes
)
3290 const OMFGlobalTypes
* types
;
3291 struct codeview_type_parse ctp
;
3293 types
= (const OMFGlobalTypes
*)(msc_dbg
->root
+ ent
->lfo
);
3294 ctp
.module
= msc_dbg
->module
;
3295 ctp
.offset
= (const DWORD
*)(types
+ 1);
3296 ctp
.num
= types
->cTypes
;
3297 ctp
.table
= (const BYTE
*)(ctp
.offset
+ types
->cTypes
);
3299 cv_current_module
= &cv_zmodules
[0];
3300 if (cv_current_module
->allowed
) FIXME("Already allowed??\n");
3301 cv_current_module
->allowed
= TRUE
;
3303 codeview_parse_type_table(&ctp
);
3308 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
);
3309 for (i
= 0; i
< hdr
->cDir
; i
++, ent
= next
)
3311 next
= (i
== hdr
->cDir
-1) ? NULL
:
3312 (const OMFDirEntry
*)((const BYTE
*)ent
+ hdr
->cbDirEntry
);
3313 prev
= (i
== 0) ? NULL
:
3314 (const OMFDirEntry
*)((const BYTE
*)ent
- hdr
->cbDirEntry
);
3316 if (ent
->SubSection
== sstAlignSym
)
3318 codeview_snarf(msc_dbg
, msc_dbg
->root
+ ent
->lfo
, sizeof(DWORD
),
3322 * Check the next and previous entry. If either is a
3323 * sstSrcModule, it contains the line number info for
3326 * FIXME: This is not a general solution!
3328 if (next
&& next
->iMod
== ent
->iMod
&& next
->SubSection
== sstSrcModule
)
3329 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ next
->lfo
,
3332 if (prev
&& prev
->iMod
== ent
->iMod
&& prev
->SubSection
== sstSrcModule
)
3333 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ prev
->lfo
,
3339 msc_dbg
->module
->module
.SymType
= SymCv
;
3340 /* FIXME: we could have a finer grain here */
3341 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
3342 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
3343 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
3344 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
3345 msc_dbg
->module
->module
.Publics
= TRUE
;
3346 codeview_clear_type_table();
3351 case CODEVIEW_NB10_SIG
:
3353 const CODEVIEW_PDB_DATA
* pdb
= (const CODEVIEW_PDB_DATA
*)msc_dbg
->root
;
3354 pdb_lookup
.filename
= pdb
->name
;
3355 pdb_lookup
.kind
= PDB_JG
;
3356 pdb_lookup
.timestamp
= pdb
->timestamp
;
3357 pdb_lookup
.age
= pdb
->age
;
3358 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
3361 case CODEVIEW_RSDS_SIG
:
3363 const OMFSignatureRSDS
* rsds
= (const OMFSignatureRSDS
*)msc_dbg
->root
;
3365 TRACE("Got RSDS type of PDB file: guid=%s age=%08x name=%s\n",
3366 wine_dbgstr_guid(&rsds
->guid
), rsds
->age
, rsds
->name
);
3367 pdb_lookup
.filename
= rsds
->name
;
3368 pdb_lookup
.kind
= PDB_DS
;
3369 pdb_lookup
.guid
= rsds
->guid
;
3370 pdb_lookup
.age
= rsds
->age
;
3371 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
3375 ERR("Unknown CODEVIEW signature %08x in module %s\n",
3376 *signature
, debugstr_w(msc_dbg
->module
->module
.ModuleName
));
3381 msc_dbg
->module
->module
.CVSig
= *signature
;
3382 memcpy(msc_dbg
->module
->module
.CVData
, msc_dbg
->root
,
3383 sizeof(msc_dbg
->module
->module
.CVData
));
3388 /*========================================================================
3389 * Process debug directory.
3391 BOOL
pe_load_debug_directory(const struct process
* pcs
, struct module
* module
,
3392 const BYTE
* mapping
,
3393 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
3394 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
)
3398 struct msc_debug_info msc_dbg
;
3400 msc_dbg
.module
= module
;
3401 msc_dbg
.nsect
= nsect
;
3402 msc_dbg
.sectp
= sectp
;
3404 msc_dbg
.omapp
= NULL
;
3410 /* First, watch out for OMAP data */
3411 for (i
= 0; i
< nDbg
; i
++)
3413 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
)
3415 msc_dbg
.nomap
= dbg
[i
].SizeOfData
/ sizeof(OMAP_DATA
);
3416 msc_dbg
.omapp
= (const OMAP_DATA
*)(mapping
+ dbg
[i
].PointerToRawData
);
3421 /* Now, try to parse CodeView debug info */
3422 for (i
= 0; i
< nDbg
; i
++)
3424 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_CODEVIEW
)
3426 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
3427 if ((ret
= codeview_process_info(pcs
, &msc_dbg
))) goto done
;
3431 /* If not found, try to parse COFF debug info */
3432 for (i
= 0; i
< nDbg
; i
++)
3434 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_COFF
)
3436 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
3437 if ((ret
= coff_process_info(&msc_dbg
))) goto done
;
3441 /* FIXME: this should be supported... this is the debug information for
3442 * functions compiled without a frame pointer (FPO = frame pointer omission)
3443 * the associated data helps finding out the relevant information
3445 for (i
= 0; i
< nDbg
; i
++)
3446 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_FPO
)
3447 FIXME("This guy has FPO information\n");
3451 #define FRAME_TRAP 1
3454 typedef struct _FPO_DATA
3456 DWORD ulOffStart
; /* offset 1st byte of function code */
3457 DWORD cbProcSize
; /* # bytes in function */
3458 DWORD cdwLocals
; /* # bytes in locals/4 */
3459 WORD cdwParams
; /* # bytes in params/4 */
3461 WORD cbProlog
: 8; /* # bytes in prolog */
3462 WORD cbRegs
: 3; /* # regs saved */
3463 WORD fHasSEH
: 1; /* TRUE if SEH in func */
3464 WORD fUseBP
: 1; /* TRUE if EBP has been allocated */
3465 WORD reserved
: 1; /* reserved for future use */
3466 WORD cbFrame
: 2; /* frame type */
3473 ERR("Got a page fault while loading symbols\n");