2 * File msc.c - read VC++ debug information from COFF and eventually
5 * Copyright (C) 1996, Eric Youngdale.
6 * Copyright (C) 1999-2000, Ulrich Weigand.
7 * Copyright (C) 2004-2009, Eric Pouech.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 * Note - this handles reading debug information for 32 bit applications
26 * that run under Windows-NT for example. I doubt that this would work well
27 * for 16 bit applications, but I don't think it really matters since the
28 * file format is different, and we should never get in here in such cases.
31 * Get 16 bit CV stuff working.
32 * Add symbol size to internal symbol table.
35 #define NONAMELESSUNION
38 #include "wine/port.h"
49 #define PATH_MAX MAX_PATH
56 #include "wine/exception.h"
57 #include "wine/debug.h"
58 #include "dbghelp_private.h"
59 #include "wine/mscvpdb.h"
61 WINE_DEFAULT_DEBUG_CHANNEL(dbghelp_msc
);
63 #define MAX_PATHNAME_LEN 1024
65 struct pdb_stream_name
77 struct pdb_stream_name
* stream_dict
;
78 unsigned fpoext_stream
;
84 struct PDB_JG_TOC
* toc
;
89 struct PDB_DS_TOC
* toc
;
94 /* FIXME: don't make it static */
95 #define CV_MAX_MODULES 32
96 struct pdb_module_info
98 unsigned used_subfiles
;
99 struct pdb_file_info pdb_files
[CV_MAX_MODULES
];
102 /*========================================================================
103 * Debug file access helper routines
106 static void dump(const void* ptr
, unsigned len
)
110 const char* hexof
= "0123456789abcdef";
113 for (i
= 0; i
< len
; i
+= 16)
115 sprintf(msg
, "%08x: ", i
);
116 memset(msg
+ 10, ' ', 3 * 16 + 1 + 16);
117 for (j
= 0; j
< min(16, len
- i
); j
++)
119 msg
[10 + 3 * j
+ 0] = hexof
[x
[i
+ j
] >> 4];
120 msg
[10 + 3 * j
+ 1] = hexof
[x
[i
+ j
] & 15];
121 msg
[10 + 3 * j
+ 2] = ' ';
122 msg
[10 + 3 * 16 + 1 + j
] = (x
[i
+ j
] >= 0x20 && x
[i
+ j
] < 0x7f) ?
125 msg
[10 + 3 * 16] = ' ';
126 msg
[10 + 3 * 16 + 1 + 16] = '\0';
131 /*========================================================================
132 * Process CodeView type information.
135 #define MAX_BUILTIN_TYPES 0x06FF
136 #define FIRST_DEFINABLE_TYPE 0x1000
138 static struct symt
* cv_basic_types
[MAX_BUILTIN_TYPES
];
140 struct cv_defined_module
143 unsigned int num_defined_types
;
144 struct symt
** defined_types
;
146 /* FIXME: don't make it static */
147 #define CV_MAX_MODULES 32
148 static struct cv_defined_module cv_zmodules
[CV_MAX_MODULES
];
149 static struct cv_defined_module
*cv_current_module
;
151 static void codeview_init_basic_types(struct module
* module
)
154 * These are the common builtin types that are used by VC++.
156 cv_basic_types
[T_NOTYPE
] = NULL
;
157 cv_basic_types
[T_ABS
] = NULL
;
158 cv_basic_types
[T_VOID
] = &symt_new_basic(module
, btVoid
, "void", 0)->symt
;
159 cv_basic_types
[T_CHAR
] = &symt_new_basic(module
, btChar
, "char", 1)->symt
;
160 cv_basic_types
[T_SHORT
] = &symt_new_basic(module
, btInt
, "short int", 2)->symt
;
161 cv_basic_types
[T_LONG
] = &symt_new_basic(module
, btInt
, "long int", 4)->symt
;
162 cv_basic_types
[T_QUAD
] = &symt_new_basic(module
, btInt
, "long long int", 8)->symt
;
163 cv_basic_types
[T_UCHAR
] = &symt_new_basic(module
, btUInt
, "unsigned char", 1)->symt
;
164 cv_basic_types
[T_USHORT
] = &symt_new_basic(module
, btUInt
, "unsigned short", 2)->symt
;
165 cv_basic_types
[T_ULONG
] = &symt_new_basic(module
, btUInt
, "unsigned long", 4)->symt
;
166 cv_basic_types
[T_UQUAD
] = &symt_new_basic(module
, btUInt
, "unsigned long long", 8)->symt
;
167 cv_basic_types
[T_BOOL08
] = &symt_new_basic(module
, btBool
, "BOOL08", 1)->symt
;
168 cv_basic_types
[T_BOOL16
] = &symt_new_basic(module
, btBool
, "BOOL16", 2)->symt
;
169 cv_basic_types
[T_BOOL32
] = &symt_new_basic(module
, btBool
, "BOOL32", 4)->symt
;
170 cv_basic_types
[T_BOOL64
] = &symt_new_basic(module
, btBool
, "BOOL64", 8)->symt
;
171 cv_basic_types
[T_REAL32
] = &symt_new_basic(module
, btFloat
, "float", 4)->symt
;
172 cv_basic_types
[T_REAL64
] = &symt_new_basic(module
, btFloat
, "double", 8)->symt
;
173 cv_basic_types
[T_REAL80
] = &symt_new_basic(module
, btFloat
, "long double", 10)->symt
;
174 cv_basic_types
[T_RCHAR
] = &symt_new_basic(module
, btInt
, "signed char", 1)->symt
;
175 cv_basic_types
[T_WCHAR
] = &symt_new_basic(module
, btWChar
, "wchar_t", 2)->symt
;
176 cv_basic_types
[T_INT2
] = &symt_new_basic(module
, btInt
, "INT2", 2)->symt
;
177 cv_basic_types
[T_UINT2
] = &symt_new_basic(module
, btUInt
, "UINT2", 2)->symt
;
178 cv_basic_types
[T_INT4
] = &symt_new_basic(module
, btInt
, "INT4", 4)->symt
;
179 cv_basic_types
[T_UINT4
] = &symt_new_basic(module
, btUInt
, "UINT4", 4)->symt
;
180 cv_basic_types
[T_INT8
] = &symt_new_basic(module
, btInt
, "INT8", 8)->symt
;
181 cv_basic_types
[T_UINT8
] = &symt_new_basic(module
, btUInt
, "UINT8", 8)->symt
;
182 cv_basic_types
[T_HRESULT
]= &symt_new_basic(module
, btUInt
, "HRESULT", 4)->symt
;
184 cv_basic_types
[T_32PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], 4)->symt
;
185 cv_basic_types
[T_32PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], 4)->symt
;
186 cv_basic_types
[T_32PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], 4)->symt
;
187 cv_basic_types
[T_32PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], 4)->symt
;
188 cv_basic_types
[T_32PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], 4)->symt
;
189 cv_basic_types
[T_32PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], 4)->symt
;
190 cv_basic_types
[T_32PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], 4)->symt
;
191 cv_basic_types
[T_32PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], 4)->symt
;
192 cv_basic_types
[T_32PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], 4)->symt
;
193 cv_basic_types
[T_32PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], 4)->symt
;
194 cv_basic_types
[T_32PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], 4)->symt
;
195 cv_basic_types
[T_32PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], 4)->symt
;
196 cv_basic_types
[T_32PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], 4)->symt
;
197 cv_basic_types
[T_32PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], 4)->symt
;
198 cv_basic_types
[T_32PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], 4)->symt
;
199 cv_basic_types
[T_32PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], 4)->symt
;
200 cv_basic_types
[T_32PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], 4)->symt
;
201 cv_basic_types
[T_32PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], 4)->symt
;
202 cv_basic_types
[T_32PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], 4)->symt
;
203 cv_basic_types
[T_32PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], 4)->symt
;
204 cv_basic_types
[T_32PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], 4)->symt
;
205 cv_basic_types
[T_32PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], 4)->symt
;
206 cv_basic_types
[T_32PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], 4)->symt
;
207 cv_basic_types
[T_32PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], 4)->symt
;
208 cv_basic_types
[T_32PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
], 4)->symt
;
210 cv_basic_types
[T_64PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
], 8)->symt
;
211 cv_basic_types
[T_64PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
], 8)->symt
;
212 cv_basic_types
[T_64PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
], 8)->symt
;
213 cv_basic_types
[T_64PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
], 8)->symt
;
214 cv_basic_types
[T_64PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
], 8)->symt
;
215 cv_basic_types
[T_64PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
], 8)->symt
;
216 cv_basic_types
[T_64PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
], 8)->symt
;
217 cv_basic_types
[T_64PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
], 8)->symt
;
218 cv_basic_types
[T_64PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
], 8)->symt
;
219 cv_basic_types
[T_64PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
], 8)->symt
;
220 cv_basic_types
[T_64PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
], 8)->symt
;
221 cv_basic_types
[T_64PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
], 8)->symt
;
222 cv_basic_types
[T_64PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
], 8)->symt
;
223 cv_basic_types
[T_64PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
], 8)->symt
;
224 cv_basic_types
[T_64PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
], 8)->symt
;
225 cv_basic_types
[T_64PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
], 8)->symt
;
226 cv_basic_types
[T_64PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
], 8)->symt
;
227 cv_basic_types
[T_64PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
], 8)->symt
;
228 cv_basic_types
[T_64PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
], 8)->symt
;
229 cv_basic_types
[T_64PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
], 8)->symt
;
230 cv_basic_types
[T_64PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
], 8)->symt
;
231 cv_basic_types
[T_64PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
], 8)->symt
;
232 cv_basic_types
[T_64PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
], 8)->symt
;
233 cv_basic_types
[T_64PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
], 8)->symt
;
234 cv_basic_types
[T_64PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
], 8)->symt
;
237 static int leaf_as_variant(VARIANT
* v
, const unsigned short int* leaf
)
239 unsigned short int type
= *leaf
++;
242 if (type
< LF_NUMERIC
)
244 v
->n1
.n2
.vt
= VT_UINT
;
245 v
->n1
.n2
.n3
.uintVal
= type
;
254 v
->n1
.n2
.n3
.cVal
= *(const char*)leaf
;
260 v
->n1
.n2
.n3
.iVal
= *(const short*)leaf
;
265 v
->n1
.n2
.vt
= VT_UI2
;
266 v
->n1
.n2
.n3
.uiVal
= *leaf
;
272 v
->n1
.n2
.n3
.lVal
= *(const int*)leaf
;
277 v
->n1
.n2
.vt
= VT_UI4
;
278 v
->n1
.n2
.n3
.uiVal
= *(const unsigned int*)leaf
;
284 v
->n1
.n2
.n3
.llVal
= *(const long long int*)leaf
;
289 v
->n1
.n2
.vt
= VT_UI8
;
290 v
->n1
.n2
.n3
.ullVal
= *(const long long unsigned int*)leaf
;
296 v
->n1
.n2
.n3
.fltVal
= *(const float*)leaf
;
300 FIXME("Unsupported numeric leaf type %04x\n", type
);
302 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
308 v
->n1
.n2
.n3
.fltVal
= *(const double*)leaf
;
312 FIXME("Unsupported numeric leaf type %04x\n", type
);
314 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
318 FIXME("Unsupported numeric leaf type %04x\n", type
);
320 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
324 FIXME("Unsupported numeric leaf type %04x\n", type
);
326 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
330 FIXME("Unsupported numeric leaf type %04x\n", type
);
332 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
336 FIXME("Unsupported numeric leaf type %04x\n", type
);
338 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
342 FIXME("Unsupported numeric leaf type %04x\n", type
);
344 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
348 FIXME("Unsupported numeric leaf type %04x\n", type
);
350 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
354 FIXME("Unknown numeric leaf type %04x\n", type
);
355 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
363 static int numeric_leaf(int* value
, const unsigned short int* leaf
)
365 unsigned short int type
= *leaf
++;
368 if (type
< LF_NUMERIC
)
378 *value
= *(const char*)leaf
;
383 *value
= *(const short*)leaf
;
393 *value
= *(const int*)leaf
;
398 *value
= *(const unsigned int*)leaf
;
403 FIXME("Unsupported numeric leaf type %04x\n", type
);
405 *value
= 0; /* FIXME */
409 FIXME("Unsupported numeric leaf type %04x\n", type
);
411 *value
= 0; /* FIXME */
415 FIXME("Unsupported numeric leaf type %04x\n", type
);
417 *value
= 0; /* FIXME */
421 FIXME("Unsupported numeric leaf type %04x\n", type
);
423 *value
= 0; /* FIXME */
427 FIXME("Unsupported numeric leaf type %04x\n", type
);
429 *value
= 0; /* FIXME */
433 FIXME("Unsupported numeric leaf type %04x\n", type
);
435 *value
= 0; /* FIXME */
439 FIXME("Unsupported numeric leaf type %04x\n", type
);
441 *value
= 0; /* FIXME */
445 FIXME("Unsupported numeric leaf type %04x\n", type
);
447 *value
= 0; /* FIXME */
451 FIXME("Unsupported numeric leaf type %04x\n", type
);
453 *value
= 0; /* FIXME */
457 FIXME("Unsupported numeric leaf type %04x\n", type
);
459 *value
= 0; /* FIXME */
463 FIXME("Unsupported numeric leaf type %04x\n", type
);
465 *value
= 0; /* FIXME */
469 FIXME("Unknown numeric leaf type %04x\n", type
);
478 /* convert a pascal string (as stored in debug information) into
479 * a C string (null terminated).
481 static const char* terminate_string(const struct p_string
* p_name
)
483 static char symname
[256];
485 memcpy(symname
, p_name
->name
, p_name
->namelen
);
486 symname
[p_name
->namelen
] = '\0';
488 return (!*symname
|| strcmp(symname
, "__unnamed") == 0) ? NULL
: symname
;
491 static struct symt
* codeview_get_type(unsigned int typeno
, BOOL quiet
)
493 struct symt
* symt
= NULL
;
496 * Convert Codeview type numbers into something we can grok internally.
497 * Numbers < FIRST_DEFINABLE_TYPE are all fixed builtin types.
498 * Numbers from FIRST_DEFINABLE_TYPE and up are all user defined (structs, etc).
500 if (typeno
< FIRST_DEFINABLE_TYPE
)
502 if (typeno
< MAX_BUILTIN_TYPES
)
503 symt
= cv_basic_types
[typeno
];
507 unsigned mod_index
= typeno
>> 24;
508 unsigned mod_typeno
= typeno
& 0x00FFFFFF;
509 struct cv_defined_module
* mod
;
511 mod
= (mod_index
== 0) ? cv_current_module
: &cv_zmodules
[mod_index
];
513 if (mod_index
>= CV_MAX_MODULES
|| !mod
->allowed
)
514 FIXME("Module of index %d isn't loaded yet (%x)\n", mod_index
, typeno
);
517 if (mod_typeno
- FIRST_DEFINABLE_TYPE
< mod
->num_defined_types
)
518 symt
= mod
->defined_types
[mod_typeno
- FIRST_DEFINABLE_TYPE
];
521 if (!quiet
&& !symt
&& typeno
) FIXME("Returning NULL symt for type-id %x\n", typeno
);
525 struct codeview_type_parse
527 struct module
* module
;
533 static inline const void* codeview_jump_to_type(const struct codeview_type_parse
* ctp
, DWORD idx
)
535 if (idx
< FIRST_DEFINABLE_TYPE
) return NULL
;
536 idx
-= FIRST_DEFINABLE_TYPE
;
537 return (idx
>= ctp
->num
) ? NULL
: (ctp
->table
+ ctp
->offset
[idx
]);
540 static int codeview_add_type(unsigned int typeno
, struct symt
* dt
)
542 if (typeno
< FIRST_DEFINABLE_TYPE
)
543 FIXME("What the heck\n");
544 if (!cv_current_module
)
546 FIXME("Adding %x to non allowed module\n", typeno
);
549 if ((typeno
>> 24) != 0)
550 FIXME("No module index while inserting type-id assumption is wrong %x\n",
552 if (typeno
- FIRST_DEFINABLE_TYPE
>= cv_current_module
->num_defined_types
)
554 if (cv_current_module
->defined_types
)
556 cv_current_module
->num_defined_types
= max( cv_current_module
->num_defined_types
* 2,
557 typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
558 cv_current_module
->defined_types
= HeapReAlloc(GetProcessHeap(),
559 HEAP_ZERO_MEMORY
, cv_current_module
->defined_types
,
560 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
564 cv_current_module
->num_defined_types
= max( 256, typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
565 cv_current_module
->defined_types
= HeapAlloc(GetProcessHeap(),
567 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
569 if (cv_current_module
->defined_types
== NULL
) return FALSE
;
571 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
])
573 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] != dt
)
574 FIXME("Overwriting at %x\n", typeno
);
576 cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] = dt
;
580 static void codeview_clear_type_table(void)
584 for (i
= 0; i
< CV_MAX_MODULES
; i
++)
586 if (cv_zmodules
[i
].allowed
)
587 HeapFree(GetProcessHeap(), 0, cv_zmodules
[i
].defined_types
);
588 cv_zmodules
[i
].allowed
= FALSE
;
589 cv_zmodules
[i
].defined_types
= NULL
;
590 cv_zmodules
[i
].num_defined_types
= 0;
592 cv_current_module
= NULL
;
595 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
597 const union codeview_type
* type
, BOOL details
);
599 static void* codeview_cast_symt(struct symt
* symt
, enum SymTagEnum tag
)
601 if (symt
->tag
!= tag
)
603 FIXME("Bad tag. Expected %d, but got %d\n", tag
, symt
->tag
);
609 static struct symt
* codeview_fetch_type(struct codeview_type_parse
* ctp
,
610 unsigned typeno
, BOOL details
)
613 const union codeview_type
* p
;
615 if (!typeno
) return NULL
;
616 if ((symt
= codeview_get_type(typeno
, TRUE
))) return symt
;
618 /* forward declaration */
619 if (!(p
= codeview_jump_to_type(ctp
, typeno
)))
621 FIXME("Cannot locate type %x\n", typeno
);
624 symt
= codeview_parse_one_type(ctp
, typeno
, p
, details
);
625 if (!symt
) FIXME("Couldn't load forward type %x\n", typeno
);
629 static struct symt
* codeview_add_type_pointer(struct codeview_type_parse
* ctp
,
630 struct symt
* existing
,
631 unsigned int pointee_type
)
633 struct symt
* pointee
;
637 existing
= codeview_cast_symt(existing
, SymTagPointerType
);
640 pointee
= codeview_fetch_type(ctp
, pointee_type
, FALSE
);
641 return &symt_new_pointer(ctp
->module
, pointee
, sizeof(void *))->symt
;
644 static struct symt
* codeview_add_type_array(struct codeview_type_parse
* ctp
,
646 unsigned int elemtype
,
647 unsigned int indextype
,
648 unsigned int arr_len
)
650 struct symt
* elem
= codeview_fetch_type(ctp
, elemtype
, FALSE
);
651 struct symt
* index
= codeview_fetch_type(ctp
, indextype
, FALSE
);
653 return &symt_new_array(ctp
->module
, 0, -arr_len
, elem
, index
)->symt
;
656 static int codeview_add_type_enum_field_list(struct module
* module
,
657 struct symt_enum
* symt
,
658 const union codeview_reftype
* ref_type
)
660 const unsigned char* ptr
= ref_type
->fieldlist
.list
;
661 const unsigned char* last
= (const BYTE
*)ref_type
+ ref_type
->generic
.len
+ 2;
662 const union codeview_fieldtype
* type
;
666 if (*ptr
>= 0xf0) /* LF_PAD... */
672 type
= (const union codeview_fieldtype
*)ptr
;
674 switch (type
->generic
.id
)
676 case LF_ENUMERATE_V1
:
678 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v1
.value
);
679 const struct p_string
* p_name
= (const struct p_string
*)((const unsigned char*)&type
->enumerate_v1
.value
+ vlen
);
681 symt_add_enum_element(module
, symt
, terminate_string(p_name
), value
);
682 ptr
+= 2 + 2 + vlen
+ (1 + p_name
->namelen
);
685 case LF_ENUMERATE_V3
:
687 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v3
.value
);
688 const char* name
= (const char*)&type
->enumerate_v3
.value
+ vlen
;
690 symt_add_enum_element(module
, symt
, name
, value
);
691 ptr
+= 2 + 2 + vlen
+ (1 + strlen(name
));
696 FIXME("Unsupported type %04x in ENUM field list\n", type
->generic
.id
);
703 static void codeview_add_udt_element(struct codeview_type_parse
* ctp
,
704 struct symt_udt
* symt
, const char* name
,
705 int value
, unsigned type
)
707 struct symt
* subtype
;
708 const union codeview_reftype
*cv_type
;
710 if ((cv_type
= codeview_jump_to_type(ctp
, type
)))
712 switch (cv_type
->generic
.id
)
715 symt_add_udt_element(ctp
->module
, symt
, name
,
716 codeview_fetch_type(ctp
, cv_type
->bitfield_v1
.type
, FALSE
),
717 (value
<< 3) + cv_type
->bitfield_v1
.bitoff
,
718 cv_type
->bitfield_v1
.nbits
);
721 symt_add_udt_element(ctp
->module
, symt
, name
,
722 codeview_fetch_type(ctp
, cv_type
->bitfield_v2
.type
, FALSE
),
723 (value
<< 3) + cv_type
->bitfield_v2
.bitoff
,
724 cv_type
->bitfield_v2
.nbits
);
728 subtype
= codeview_fetch_type(ctp
, type
, FALSE
);
732 DWORD64 elem_size
= 0;
733 symt_get_info(ctp
->module
, subtype
, TI_GET_LENGTH
, &elem_size
);
734 symt_add_udt_element(ctp
->module
, symt
, name
, subtype
,
735 value
<< 3, (DWORD
)elem_size
<< 3);
739 static int codeview_add_type_struct_field_list(struct codeview_type_parse
* ctp
,
740 struct symt_udt
* symt
,
741 unsigned fieldlistno
)
743 const unsigned char* ptr
;
744 const unsigned char* last
;
746 const struct p_string
* p_name
;
748 const union codeview_reftype
*type_ref
;
749 const union codeview_fieldtype
* type
;
751 if (!fieldlistno
) return TRUE
;
752 type_ref
= codeview_jump_to_type(ctp
, fieldlistno
);
753 ptr
= type_ref
->fieldlist
.list
;
754 last
= (const BYTE
*)type_ref
+ type_ref
->generic
.len
+ 2;
758 if (*ptr
>= 0xf0) /* LF_PAD... */
764 type
= (const union codeview_fieldtype
*)ptr
;
766 switch (type
->generic
.id
)
769 leaf_len
= numeric_leaf(&value
, &type
->bclass_v1
.offset
);
771 /* FIXME: ignored for now */
773 ptr
+= 2 + 2 + 2 + leaf_len
;
777 leaf_len
= numeric_leaf(&value
, &type
->bclass_v2
.offset
);
779 /* FIXME: ignored for now */
781 ptr
+= 2 + 2 + 4 + leaf_len
;
787 const unsigned short int* p_vboff
;
789 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v1
.vbpoff
);
790 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v1
.vbpoff
+ leaf_len
);
791 vplen
= numeric_leaf(&vpoff
, p_vboff
);
793 /* FIXME: ignored for now */
795 ptr
+= 2 + 2 + 2 + 2 + leaf_len
+ vplen
;
802 const unsigned short int* p_vboff
;
804 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v2
.vbpoff
);
805 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v2
.vbpoff
+ leaf_len
);
806 vplen
= numeric_leaf(&vpoff
, p_vboff
);
808 /* FIXME: ignored for now */
810 ptr
+= 2 + 2 + 4 + 4 + leaf_len
+ vplen
;
815 leaf_len
= numeric_leaf(&value
, &type
->member_v1
.offset
);
816 p_name
= (const struct p_string
*)((const char*)&type
->member_v1
.offset
+ leaf_len
);
818 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
819 type
->member_v1
.type
);
821 ptr
+= 2 + 2 + 2 + leaf_len
+ (1 + p_name
->namelen
);
825 leaf_len
= numeric_leaf(&value
, &type
->member_v2
.offset
);
826 p_name
= (const struct p_string
*)((const unsigned char*)&type
->member_v2
.offset
+ leaf_len
);
828 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
829 type
->member_v2
.type
);
831 ptr
+= 2 + 2 + 4 + leaf_len
+ (1 + p_name
->namelen
);
835 leaf_len
= numeric_leaf(&value
, &type
->member_v3
.offset
);
836 c_name
= (const char*)&type
->member_v3
.offset
+ leaf_len
;
838 codeview_add_udt_element(ctp
, symt
, c_name
, value
, type
->member_v3
.type
);
840 ptr
+= 2 + 2 + 4 + leaf_len
+ (strlen(c_name
) + 1);
844 /* FIXME: ignored for now */
845 ptr
+= 2 + 2 + 2 + (1 + type
->stmember_v1
.p_name
.namelen
);
849 /* FIXME: ignored for now */
850 ptr
+= 2 + 4 + 2 + (1 + type
->stmember_v2
.p_name
.namelen
);
854 /* FIXME: ignored for now */
855 ptr
+= 2 + 4 + 2 + (strlen(type
->stmember_v3
.name
) + 1);
859 /* FIXME: ignored for now */
860 ptr
+= 2 + 2 + 2 + (1 + type
->method_v1
.p_name
.namelen
);
864 /* FIXME: ignored for now */
865 ptr
+= 2 + 2 + 4 + (1 + type
->method_v2
.p_name
.namelen
);
869 /* FIXME: ignored for now */
870 ptr
+= 2 + 2 + 4 + (strlen(type
->method_v3
.name
) + 1);
874 /* FIXME: ignored for now */
875 ptr
+= 2 + 2 + (1 + type
->nesttype_v1
.p_name
.namelen
);
879 /* FIXME: ignored for now */
880 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype_v2
.p_name
.namelen
);
884 /* FIXME: ignored for now */
885 ptr
+= 2 + 2 + 4 + (strlen(type
->nesttype_v3
.name
) + 1);
889 /* FIXME: ignored for now */
894 /* FIXME: ignored for now */
898 case LF_ONEMETHOD_V1
:
899 /* FIXME: ignored for now */
900 switch ((type
->onemethod_v1
.attribute
>> 2) & 7)
902 case 4: case 6: /* (pure) introducing virtual method */
903 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt_v1
.p_name
.namelen
);
907 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod_v1
.p_name
.namelen
);
912 case LF_ONEMETHOD_V2
:
913 /* FIXME: ignored for now */
914 switch ((type
->onemethod_v2
.attribute
>> 2) & 7)
916 case 4: case 6: /* (pure) introducing virtual method */
917 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod_virt_v2
.p_name
.namelen
);
921 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod_v2
.p_name
.namelen
);
926 case LF_ONEMETHOD_V3
:
927 /* FIXME: ignored for now */
928 switch ((type
->onemethod_v3
.attribute
>> 2) & 7)
930 case 4: case 6: /* (pure) introducing virtual method */
931 ptr
+= 2 + 2 + 4 + 4 + (strlen(type
->onemethod_virt_v3
.name
) + 1);
935 ptr
+= 2 + 2 + 4 + (strlen(type
->onemethod_v3
.name
) + 1);
941 FIXME("Unsupported type %04x in STRUCT field list\n", type
->generic
.id
);
949 static struct symt
* codeview_add_type_enum(struct codeview_type_parse
* ctp
,
950 struct symt
* existing
,
952 unsigned fieldlistno
,
955 struct symt_enum
* symt
;
959 if (!(symt
= codeview_cast_symt(existing
, SymTagEnum
))) return NULL
;
960 /* should also check that all fields are the same */
964 symt
= symt_new_enum(ctp
->module
, name
,
965 codeview_fetch_type(ctp
, basetype
, FALSE
));
968 const union codeview_reftype
* fieldlist
;
969 fieldlist
= codeview_jump_to_type(ctp
, fieldlistno
);
970 codeview_add_type_enum_field_list(ctp
->module
, symt
, fieldlist
);
976 static struct symt
* codeview_add_type_struct(struct codeview_type_parse
* ctp
,
977 struct symt
* existing
,
978 const char* name
, int structlen
,
979 enum UdtKind kind
, unsigned property
)
981 struct symt_udt
* symt
;
983 /* if we don't have an existing type, try to find one with same name
984 * FIXME: what to do when several types in different CUs have same name ?
989 struct symt_ht
* type
;
990 struct hash_table_iter hti
;
992 hash_table_iter_init(&ctp
->module
->ht_types
, &hti
, name
);
993 while ((ptr
= hash_table_iter_up(&hti
)))
995 type
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
997 if (type
->symt
.tag
== SymTagUDT
&&
998 type
->hash_elt
.name
&& !strcmp(type
->hash_elt
.name
, name
))
1000 existing
= &type
->symt
;
1007 if (!(symt
= codeview_cast_symt(existing
, SymTagUDT
))) return NULL
;
1008 /* should also check that all fields are the same */
1009 if (!(property
& 0x80)) /* 0x80 = forward declaration */
1011 if (!symt
->size
) /* likely prior forward declaration, set UDT size */
1012 symt_set_udt_size(ctp
->module
, symt
, structlen
);
1013 else /* different UDT with same name, create a new type */
1017 if (!existing
) symt
= symt_new_udt(ctp
->module
, name
, structlen
, kind
);
1022 static struct symt
* codeview_new_func_signature(struct codeview_type_parse
* ctp
,
1023 struct symt
* existing
,
1024 enum CV_call_e call_conv
)
1026 struct symt_function_signature
* sym
;
1030 sym
= codeview_cast_symt(existing
, SymTagFunctionType
);
1031 if (!sym
) return NULL
;
1035 sym
= symt_new_function_signature(ctp
->module
, NULL
, call_conv
);
1040 static void codeview_add_func_signature_args(struct codeview_type_parse
* ctp
,
1041 struct symt_function_signature
* sym
,
1045 const union codeview_reftype
* reftype
;
1047 sym
->rettype
= codeview_fetch_type(ctp
, ret_type
, FALSE
);
1048 if (args_list
&& (reftype
= codeview_jump_to_type(ctp
, args_list
)))
1051 switch (reftype
->generic
.id
)
1054 for (i
= 0; i
< reftype
->arglist_v1
.num
; i
++)
1055 symt_add_function_signature_parameter(ctp
->module
, sym
,
1056 codeview_fetch_type(ctp
, reftype
->arglist_v1
.args
[i
], FALSE
));
1059 for (i
= 0; i
< reftype
->arglist_v2
.num
; i
++)
1060 symt_add_function_signature_parameter(ctp
->module
, sym
,
1061 codeview_fetch_type(ctp
, reftype
->arglist_v2
.args
[i
], FALSE
));
1064 FIXME("Unexpected leaf %x for signature's pmt\n", reftype
->generic
.id
);
1069 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
1071 const union codeview_type
* type
, BOOL details
)
1074 int value
, leaf_len
;
1075 const struct p_string
* p_name
;
1077 struct symt
* existing
;
1079 existing
= codeview_get_type(curr_type
, TRUE
);
1081 switch (type
->generic
.id
)
1083 case LF_MODIFIER_V1
:
1084 /* FIXME: we don't handle modifiers,
1085 * but read previous type on the curr_type
1087 WARN("Modifier on %x: %s%s%s%s\n",
1088 type
->modifier_v1
.type
,
1089 type
->modifier_v1
.attribute
& 0x01 ? "const " : "",
1090 type
->modifier_v1
.attribute
& 0x02 ? "volatile " : "",
1091 type
->modifier_v1
.attribute
& 0x04 ? "unaligned " : "",
1092 type
->modifier_v1
.attribute
& ~0x07 ? "unknown " : "");
1093 symt
= codeview_fetch_type(ctp
, type
->modifier_v1
.type
, details
);
1095 case LF_MODIFIER_V2
:
1096 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
1097 WARN("Modifier on %x: %s%s%s%s\n",
1098 type
->modifier_v2
.type
,
1099 type
->modifier_v2
.attribute
& 0x01 ? "const " : "",
1100 type
->modifier_v2
.attribute
& 0x02 ? "volatile " : "",
1101 type
->modifier_v2
.attribute
& 0x04 ? "unaligned " : "",
1102 type
->modifier_v2
.attribute
& ~0x07 ? "unknown " : "");
1103 symt
= codeview_fetch_type(ctp
, type
->modifier_v2
.type
, details
);
1107 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v1
.datatype
);
1110 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v2
.datatype
);
1114 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1117 leaf_len
= numeric_leaf(&value
, &type
->array_v1
.arrlen
);
1118 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v1
.arrlen
+ leaf_len
);
1119 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1120 type
->array_v1
.elemtype
,
1121 type
->array_v1
.idxtype
, value
);
1125 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1128 leaf_len
= numeric_leaf(&value
, &type
->array_v2
.arrlen
);
1129 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v2
.arrlen
+ leaf_len
);
1131 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1132 type
->array_v2
.elemtype
,
1133 type
->array_v2
.idxtype
, value
);
1137 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1140 leaf_len
= numeric_leaf(&value
, &type
->array_v3
.arrlen
);
1141 c_name
= (const char*)&type
->array_v3
.arrlen
+ leaf_len
;
1143 symt
= codeview_add_type_array(ctp
, c_name
,
1144 type
->array_v3
.elemtype
,
1145 type
->array_v3
.idxtype
, value
);
1149 case LF_STRUCTURE_V1
:
1151 leaf_len
= numeric_leaf(&value
, &type
->struct_v1
.structlen
);
1152 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v1
.structlen
+ leaf_len
);
1153 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1154 type
->generic
.id
== LF_CLASS_V1
? UdtClass
: UdtStruct
,
1155 type
->struct_v1
.property
);
1158 codeview_add_type(curr_type
, symt
);
1159 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1160 type
->struct_v1
.fieldlist
);
1164 case LF_STRUCTURE_V2
:
1166 leaf_len
= numeric_leaf(&value
, &type
->struct_v2
.structlen
);
1167 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v2
.structlen
+ leaf_len
);
1168 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1169 type
->generic
.id
== LF_CLASS_V2
? UdtClass
: UdtStruct
,
1170 type
->struct_v2
.property
);
1173 codeview_add_type(curr_type
, symt
);
1174 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1175 type
->struct_v2
.fieldlist
);
1179 case LF_STRUCTURE_V3
:
1181 leaf_len
= numeric_leaf(&value
, &type
->struct_v3
.structlen
);
1182 c_name
= (const char*)&type
->struct_v3
.structlen
+ leaf_len
;
1183 symt
= codeview_add_type_struct(ctp
, existing
, c_name
, value
,
1184 type
->generic
.id
== LF_CLASS_V3
? UdtClass
: UdtStruct
,
1185 type
->struct_v3
.property
);
1188 codeview_add_type(curr_type
, symt
);
1189 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1190 type
->struct_v3
.fieldlist
);
1195 leaf_len
= numeric_leaf(&value
, &type
->union_v1
.un_len
);
1196 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v1
.un_len
+ leaf_len
);
1197 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1198 value
, UdtUnion
, type
->union_v1
.property
);
1201 codeview_add_type(curr_type
, symt
);
1202 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1203 type
->union_v1
.fieldlist
);
1208 leaf_len
= numeric_leaf(&value
, &type
->union_v2
.un_len
);
1209 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v2
.un_len
+ leaf_len
);
1210 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1211 value
, UdtUnion
, type
->union_v2
.property
);
1214 codeview_add_type(curr_type
, symt
);
1215 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1216 type
->union_v2
.fieldlist
);
1221 leaf_len
= numeric_leaf(&value
, &type
->union_v3
.un_len
);
1222 c_name
= (const char*)&type
->union_v3
.un_len
+ leaf_len
;
1223 symt
= codeview_add_type_struct(ctp
, existing
, c_name
,
1224 value
, UdtUnion
, type
->union_v3
.property
);
1227 codeview_add_type(curr_type
, symt
);
1228 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1229 type
->union_v3
.fieldlist
);
1234 symt
= codeview_add_type_enum(ctp
, existing
,
1235 terminate_string(&type
->enumeration_v1
.p_name
),
1236 type
->enumeration_v1
.fieldlist
,
1237 type
->enumeration_v1
.type
);
1241 symt
= codeview_add_type_enum(ctp
, existing
,
1242 terminate_string(&type
->enumeration_v2
.p_name
),
1243 type
->enumeration_v2
.fieldlist
,
1244 type
->enumeration_v2
.type
);
1248 symt
= codeview_add_type_enum(ctp
, existing
, type
->enumeration_v3
.name
,
1249 type
->enumeration_v3
.fieldlist
,
1250 type
->enumeration_v3
.type
);
1253 case LF_PROCEDURE_V1
:
1254 symt
= codeview_new_func_signature(ctp
, existing
, type
->procedure_v1
.call
);
1257 codeview_add_type(curr_type
, symt
);
1258 codeview_add_func_signature_args(ctp
,
1259 (struct symt_function_signature
*)symt
,
1260 type
->procedure_v1
.rvtype
,
1261 type
->procedure_v1
.arglist
);
1264 case LF_PROCEDURE_V2
:
1265 symt
= codeview_new_func_signature(ctp
, existing
,type
->procedure_v2
.call
);
1268 codeview_add_type(curr_type
, symt
);
1269 codeview_add_func_signature_args(ctp
,
1270 (struct symt_function_signature
*)symt
,
1271 type
->procedure_v2
.rvtype
,
1272 type
->procedure_v2
.arglist
);
1276 case LF_MFUNCTION_V1
:
1277 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1278 * nor class information, this would just do for now
1280 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v1
.call
);
1283 codeview_add_type(curr_type
, symt
);
1284 codeview_add_func_signature_args(ctp
,
1285 (struct symt_function_signature
*)symt
,
1286 type
->mfunction_v1
.rvtype
,
1287 type
->mfunction_v1
.arglist
);
1290 case LF_MFUNCTION_V2
:
1291 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1292 * nor class information, this would just do for now
1294 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v2
.call
);
1297 codeview_add_type(curr_type
, symt
);
1298 codeview_add_func_signature_args(ctp
,
1299 (struct symt_function_signature
*)symt
,
1300 type
->mfunction_v2
.rvtype
,
1301 type
->mfunction_v2
.arglist
);
1306 /* this is an ugly hack... FIXME when we have C++ support */
1307 if (!(symt
= existing
))
1310 snprintf(buf
, sizeof(buf
), "__internal_vt_shape_%x\n", curr_type
);
1311 symt
= &symt_new_udt(ctp
->module
, buf
, 0, UdtStruct
)->symt
;
1315 FIXME("Unsupported type-id leaf %x\n", type
->generic
.id
);
1316 dump(type
, 2 + type
->generic
.len
);
1319 return codeview_add_type(curr_type
, symt
) ? symt
: NULL
;
1322 static int codeview_parse_type_table(struct codeview_type_parse
* ctp
)
1324 unsigned int curr_type
= FIRST_DEFINABLE_TYPE
;
1325 const union codeview_type
* type
;
1327 for (curr_type
= FIRST_DEFINABLE_TYPE
; curr_type
< FIRST_DEFINABLE_TYPE
+ ctp
->num
; curr_type
++)
1329 type
= codeview_jump_to_type(ctp
, curr_type
);
1331 /* type records we're interested in are the ones referenced by symbols
1332 * The known ranges are (X mark the ones we want):
1333 * X 0000-0016 for V1 types
1334 * 0200-020c for V1 types referenced by other types
1335 * 0400-040f for V1 types (complex lists & sets)
1336 * X 1000-100f for V2 types
1337 * 1200-120c for V2 types referenced by other types
1338 * 1400-140f for V1 types (complex lists & sets)
1339 * X 1500-150d for V3 types
1340 * 8000-8010 for numeric leafes
1342 if (!(type
->generic
.id
& 0x8600) || (type
->generic
.id
& 0x0100))
1343 codeview_parse_one_type(ctp
, curr_type
, type
, TRUE
);
1349 /*========================================================================
1350 * Process CodeView line number information.
1352 static unsigned long codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1353 unsigned seg
, unsigned offset
);
1355 static void codeview_snarf_linetab(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
,
1356 int size
, BOOL pascal_str
)
1358 const BYTE
* ptr
= linetab
;
1361 const unsigned int* filetab
;
1362 const unsigned int* lt_ptr
;
1363 const unsigned short* linenos
;
1364 const struct startend
* start
;
1366 unsigned long addr
, func_addr0
;
1367 struct symt_function
* func
;
1368 const struct codeview_linetab_block
* ltb
;
1370 nfile
= *(const short*)linetab
;
1371 filetab
= (const unsigned int*)(linetab
+ 2 * sizeof(short));
1373 for (i
= 0; i
< nfile
; i
++)
1375 ptr
= linetab
+ filetab
[i
];
1376 nseg
= *(const short*)ptr
;
1377 lt_ptr
= (const unsigned int*)(ptr
+ 2 * sizeof(short));
1378 start
= (const struct startend
*)(lt_ptr
+ nseg
);
1381 * Now snarf the filename for all of the segments for this file.
1384 source
= source_new(msc_dbg
->module
, NULL
, terminate_string((const struct p_string
*)(start
+ nseg
)));
1386 source
= source_new(msc_dbg
->module
, NULL
, (const char*)(start
+ nseg
));
1388 for (j
= 0; j
< nseg
; j
++)
1390 ltb
= (const struct codeview_linetab_block
*)(linetab
+ *lt_ptr
++);
1391 linenos
= (const unsigned short*)<b
->offsets
[ltb
->num_lines
];
1392 func_addr0
= codeview_get_address(msc_dbg
, ltb
->seg
, start
[j
].start
);
1393 if (!func_addr0
) continue;
1394 for (func
= NULL
, k
= 0; k
< ltb
->num_lines
; k
++)
1396 /* now locate function (if any) */
1397 addr
= func_addr0
+ ltb
->offsets
[k
] - start
[j
].start
;
1398 /* unfortunetaly, we can have several functions in the same block, if there's no
1399 * gap between them... find the new function if needed
1401 if (!func
|| addr
>= func
->address
+ func
->size
)
1403 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1404 /* FIXME: at least labels support line numbers */
1405 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1407 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1408 ltb
->seg
, ltb
->offsets
[k
], addr
, func
? func
->symt
.tag
: -1);
1413 symt_add_func_line(msc_dbg
->module
, func
, source
,
1414 linenos
[k
], addr
- func
->address
);
1420 static void codeview_snarf_linetab2(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
, DWORD size
,
1421 const char* strimage
, DWORD strsize
)
1425 const struct codeview_linetab2
* lt2
;
1426 const struct codeview_linetab2
* lt2_files
= NULL
;
1427 const struct codeview_lt2blk_lines
* lines_blk
;
1428 const struct codeview_linetab2_file
*fd
;
1430 struct symt_function
* func
;
1432 /* locate LT2_FILES_BLOCK (if any) */
1433 lt2
= (const struct codeview_linetab2
*)linetab
;
1434 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1436 if (lt2
->header
== LT2_FILES_BLOCK
)
1441 lt2
= codeview_linetab2_next_block(lt2
);
1445 TRACE("No LT2_FILES_BLOCK found\n");
1449 lt2
= (const struct codeview_linetab2
*)linetab
;
1450 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1452 /* FIXME: should also check that whole lines_blk fits in linetab + size */
1453 switch (lt2
->header
)
1455 case LT2_LINES_BLOCK
:
1456 lines_blk
= (const struct codeview_lt2blk_lines
*)lt2
;
1457 /* FIXME: should check that file_offset is within the LT2_FILES_BLOCK we've seen */
1458 addr
= codeview_get_address(msc_dbg
, lines_blk
->seg
, lines_blk
->start
);
1459 TRACE("block from %04x:%08x #%x (%x lines)\n",
1460 lines_blk
->seg
, lines_blk
->start
, lines_blk
->size
, lines_blk
->nlines
);
1461 fd
= (const struct codeview_linetab2_file
*)((const char*)lt2_files
+ 8 + lines_blk
->file_offset
);
1462 /* FIXME: should check that string is within strimage + strsize */
1463 source
= source_new(msc_dbg
->module
, NULL
, strimage
+ fd
->offset
);
1464 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1465 /* FIXME: at least labels support line numbers */
1466 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1468 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1469 lines_blk
->seg
, lines_blk
->start
, addr
, func
? func
->symt
.tag
: -1);
1472 for (i
= 0; i
< lines_blk
->nlines
; i
++)
1474 symt_add_func_line(msc_dbg
->module
, func
, source
,
1475 lines_blk
->l
[i
].lineno
^ 0x80000000,
1476 lines_blk
->l
[i
].offset
);
1479 case LT2_FILES_BLOCK
: /* skip */
1482 TRACE("Block end %x\n", lt2
->header
);
1483 lt2
= (const struct codeview_linetab2
*)((const char*)linetab
+ size
);
1486 lt2
= codeview_linetab2_next_block(lt2
);
1490 /*========================================================================
1491 * Process CodeView symbol information.
1494 static unsigned int codeview_map_offset(const struct msc_debug_info
* msc_dbg
,
1495 unsigned int offset
)
1497 int nomap
= msc_dbg
->nomap
;
1498 const OMAP_DATA
* omapp
= msc_dbg
->omapp
;
1501 if (!nomap
|| !omapp
) return offset
;
1503 /* FIXME: use binary search */
1504 for (i
= 0; i
< nomap
- 1; i
++)
1505 if (omapp
[i
].from
<= offset
&& omapp
[i
+1].from
> offset
)
1506 return !omapp
[i
].to
? 0 : omapp
[i
].to
+ (offset
- omapp
[i
].from
);
1511 static unsigned long codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1512 unsigned seg
, unsigned offset
)
1514 int nsect
= msc_dbg
->nsect
;
1515 const IMAGE_SECTION_HEADER
* sectp
= msc_dbg
->sectp
;
1517 if (!seg
|| seg
> nsect
) return 0;
1518 return msc_dbg
->module
->module
.BaseOfImage
+
1519 codeview_map_offset(msc_dbg
, sectp
[seg
-1].VirtualAddress
+ offset
);
1522 static inline void codeview_add_variable(const struct msc_debug_info
* msc_dbg
,
1523 struct symt_compiland
* compiland
,
1525 unsigned segment
, unsigned offset
,
1526 unsigned symtype
, BOOL is_local
, BOOL force
)
1530 unsigned long address
= codeview_get_address(msc_dbg
, segment
, offset
);
1531 struct location loc
;
1533 loc
.kind
= loc_absolute
;
1535 loc
.offset
= address
;
1536 if (force
|| !symt_find_nearest(msc_dbg
->module
, address
))
1538 symt_new_global_variable(msc_dbg
->module
, compiland
,
1539 name
, is_local
, loc
, 0,
1540 codeview_get_type(symtype
, FALSE
));
1545 static int codeview_snarf(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1546 int offset
, int size
, BOOL do_globals
)
1548 struct symt_function
* curr_func
= NULL
;
1550 struct symt_block
* block
= NULL
;
1553 struct symt_compiland
* compiland
= NULL
;
1554 struct location loc
;
1557 * Loop over the different types of records and whenever we
1558 * find something we are interested in, record it and move on.
1560 for (i
= offset
; i
< size
; i
+= length
)
1562 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1563 length
= sym
->generic
.len
+ 2;
1564 if (i
+ length
> size
) break;
1565 if (!sym
->generic
.id
|| length
< 4) break;
1566 if (length
& 3) FIXME("unpadded len %u\n", length
);
1568 switch (sym
->generic
.id
)
1571 * Global and local data symbols. We don't associate these
1572 * with any given source file.
1577 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
1578 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
1579 sym
->generic
.id
== S_LDATA_V1
, TRUE
);
1584 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
1585 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
1586 sym
->generic
.id
== S_LDATA_V2
, TRUE
);
1591 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
1592 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
1593 sym
->generic
.id
== S_LDATA_V3
, TRUE
);
1596 /* Public symbols */
1600 case S_PUB_FUNC1_V3
:
1601 case S_PUB_FUNC2_V3
:
1602 /* will be handled later on in codeview_snarf_public */
1606 * Sort of like a global function, but it just points
1607 * to a thunk, which is a stupid name for what amounts to
1608 * a PLT slot in the normal jargon that everyone else uses.
1611 symt_new_thunk(msc_dbg
->module
, compiland
,
1612 terminate_string(&sym
->thunk_v1
.p_name
), sym
->thunk_v1
.thtype
,
1613 codeview_get_address(msc_dbg
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
),
1614 sym
->thunk_v1
.thunk_len
);
1617 symt_new_thunk(msc_dbg
->module
, compiland
,
1618 sym
->thunk_v3
.name
, sym
->thunk_v3
.thtype
,
1619 codeview_get_address(msc_dbg
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
),
1620 sym
->thunk_v3
.thunk_len
);
1624 * Global and static functions.
1628 if (curr_func
) FIXME("nested function\n");
1629 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1630 terminate_string(&sym
->proc_v1
.p_name
),
1631 codeview_get_address(msc_dbg
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
),
1632 sym
->proc_v1
.proc_len
,
1633 codeview_get_type(sym
->proc_v1
.proctype
, FALSE
));
1634 loc
.kind
= loc_absolute
;
1635 loc
.offset
= sym
->proc_v1
.debug_start
;
1636 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1637 loc
.offset
= sym
->proc_v1
.debug_end
;
1638 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1642 if (curr_func
) FIXME("nested function\n");
1643 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1644 terminate_string(&sym
->proc_v2
.p_name
),
1645 codeview_get_address(msc_dbg
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
),
1646 sym
->proc_v2
.proc_len
,
1647 codeview_get_type(sym
->proc_v2
.proctype
, FALSE
));
1648 loc
.kind
= loc_absolute
;
1649 loc
.offset
= sym
->proc_v2
.debug_start
;
1650 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1651 loc
.offset
= sym
->proc_v2
.debug_end
;
1652 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1656 if (curr_func
) FIXME("nested function\n");
1657 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1659 codeview_get_address(msc_dbg
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
),
1660 sym
->proc_v3
.proc_len
,
1661 codeview_get_type(sym
->proc_v3
.proctype
, FALSE
));
1662 loc
.kind
= loc_absolute
;
1663 loc
.offset
= sym
->proc_v3
.debug_start
;
1664 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1665 loc
.offset
= sym
->proc_v3
.debug_end
;
1666 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1669 * Function parameters and stack variables.
1672 loc
.kind
= loc_regrel
;
1673 loc
.reg
= 0; /* FIXME */
1674 loc
.offset
= sym
->stack_v1
.offset
;
1675 symt_add_func_local(msc_dbg
->module
, curr_func
,
1676 sym
->stack_v1
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1678 codeview_get_type(sym
->stack_v1
.symtype
, FALSE
),
1679 terminate_string(&sym
->stack_v1
.p_name
));
1682 loc
.kind
= loc_regrel
;
1683 loc
.reg
= 0; /* FIXME */
1684 loc
.offset
= sym
->stack_v2
.offset
;
1685 symt_add_func_local(msc_dbg
->module
, curr_func
,
1686 sym
->stack_v2
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1688 codeview_get_type(sym
->stack_v2
.symtype
, FALSE
),
1689 terminate_string(&sym
->stack_v2
.p_name
));
1692 loc
.kind
= loc_regrel
;
1693 loc
.reg
= 0; /* FIXME */
1694 loc
.offset
= sym
->stack_v3
.offset
;
1695 symt_add_func_local(msc_dbg
->module
, curr_func
,
1696 sym
->stack_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1698 codeview_get_type(sym
->stack_v3
.symtype
, FALSE
),
1699 sym
->stack_v3
.name
);
1702 loc
.kind
= loc_regrel
;
1703 loc
.reg
= sym
->regrel_v3
.reg
;
1704 loc
.offset
= sym
->regrel_v3
.offset
;
1705 symt_add_func_local(msc_dbg
->module
, curr_func
,
1706 /* FIXME this is wrong !!! */
1707 sym
->regrel_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1709 codeview_get_type(sym
->regrel_v3
.symtype
, FALSE
),
1710 sym
->regrel_v3
.name
);
1714 loc
.kind
= loc_register
;
1715 loc
.reg
= sym
->register_v1
.reg
;
1717 symt_add_func_local(msc_dbg
->module
, curr_func
,
1719 block
, codeview_get_type(sym
->register_v1
.type
, FALSE
),
1720 terminate_string(&sym
->register_v1
.p_name
));
1723 loc
.kind
= loc_register
;
1724 loc
.reg
= sym
->register_v2
.reg
;
1726 symt_add_func_local(msc_dbg
->module
, curr_func
,
1728 block
, codeview_get_type(sym
->register_v2
.type
, FALSE
),
1729 terminate_string(&sym
->register_v2
.p_name
));
1732 loc
.kind
= loc_register
;
1733 loc
.reg
= sym
->register_v3
.reg
;
1735 symt_add_func_local(msc_dbg
->module
, curr_func
,
1737 block
, codeview_get_type(sym
->register_v3
.type
, FALSE
),
1738 sym
->register_v3
.name
);
1742 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1743 codeview_get_address(msc_dbg
, sym
->block_v1
.segment
, sym
->block_v1
.offset
),
1744 sym
->block_v1
.length
);
1747 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1748 codeview_get_address(msc_dbg
, sym
->block_v3
.segment
, sym
->block_v3
.offset
),
1749 sym
->block_v3
.length
);
1755 block
= symt_close_func_block(msc_dbg
->module
, curr_func
, block
, 0);
1759 symt_normalize_function(msc_dbg
->module
, curr_func
);
1764 case S_COMPILAND_V1
:
1765 TRACE("S-Compiland-V1 %x %s\n",
1766 sym
->compiland_v1
.unknown
, terminate_string(&sym
->compiland_v1
.p_name
));
1769 case S_COMPILAND_V2
:
1770 TRACE("S-Compiland-V2 %s\n", terminate_string(&sym
->compiland_v2
.p_name
));
1771 if (TRACE_ON(dbghelp_msc
))
1773 const char* ptr1
= sym
->compiland_v2
.p_name
.name
+ sym
->compiland_v2
.p_name
.namelen
;
1777 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1778 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1779 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1783 case S_COMPILAND_V3
:
1784 TRACE("S-Compiland-V3 %s\n", sym
->compiland_v3
.name
);
1785 if (TRACE_ON(dbghelp_msc
))
1787 const char* ptr1
= sym
->compiland_v3
.name
+ strlen(sym
->compiland_v3
.name
);
1791 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1792 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1793 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1799 TRACE("S-ObjName %s\n", terminate_string(&sym
->objname_v1
.p_name
));
1800 compiland
= symt_new_compiland(msc_dbg
->module
, 0 /* FIXME */,
1801 source_new(msc_dbg
->module
, NULL
,
1802 terminate_string(&sym
->objname_v1
.p_name
)));
1808 loc
.kind
= loc_absolute
;
1809 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
) - curr_func
->address
;
1810 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
, &loc
,
1811 terminate_string(&sym
->label_v1
.p_name
));
1813 else symt_new_label(msc_dbg
->module
, compiland
,
1814 terminate_string(&sym
->label_v1
.p_name
),
1815 codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
));
1820 loc
.kind
= loc_absolute
;
1821 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
) - curr_func
->address
;
1822 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1823 &loc
, sym
->label_v3
.name
);
1825 else symt_new_label(msc_dbg
->module
, compiland
, sym
->label_v3
.name
,
1826 codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
));
1832 const struct p_string
* name
;
1836 vlen
= leaf_as_variant(&v
, &sym
->constant_v1
.cvalue
);
1837 name
= (const struct p_string
*)((const char*)&sym
->constant_v1
.cvalue
+ vlen
);
1838 se
= codeview_get_type(sym
->constant_v1
.type
, FALSE
);
1840 TRACE("S-Constant-V1 %u %s %x\n",
1841 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v1
.type
);
1842 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1849 const struct p_string
* name
;
1853 vlen
= leaf_as_variant(&v
, &sym
->constant_v2
.cvalue
);
1854 name
= (const struct p_string
*)((const char*)&sym
->constant_v2
.cvalue
+ vlen
);
1855 se
= codeview_get_type(sym
->constant_v2
.type
, FALSE
);
1857 TRACE("S-Constant-V2 %u %s %x\n",
1858 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v2
.type
);
1859 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1870 vlen
= leaf_as_variant(&v
, &sym
->constant_v3
.cvalue
);
1871 name
= (const char*)&sym
->constant_v3
.cvalue
+ vlen
;
1872 se
= codeview_get_type(sym
->constant_v3
.type
, FALSE
);
1874 TRACE("S-Constant-V3 %u %s %x\n",
1875 v
.n1
.n2
.n3
.intVal
, name
, sym
->constant_v3
.type
);
1876 /* FIXME: we should add this as a constant value */
1877 symt_new_constant(msc_dbg
->module
, compiland
, name
, se
, &v
);
1882 if (sym
->udt_v1
.type
)
1884 if ((symt
= codeview_get_type(sym
->udt_v1
.type
, FALSE
)))
1885 symt_new_typedef(msc_dbg
->module
, symt
,
1886 terminate_string(&sym
->udt_v1
.p_name
));
1888 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1889 terminate_string(&sym
->udt_v1
.p_name
), sym
->udt_v1
.type
);
1893 if (sym
->udt_v2
.type
)
1895 if ((symt
= codeview_get_type(sym
->udt_v2
.type
, FALSE
)))
1896 symt_new_typedef(msc_dbg
->module
, symt
,
1897 terminate_string(&sym
->udt_v2
.p_name
));
1899 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1900 terminate_string(&sym
->udt_v2
.p_name
), sym
->udt_v2
.type
);
1904 if (sym
->udt_v3
.type
)
1906 if ((symt
= codeview_get_type(sym
->udt_v3
.type
, FALSE
)))
1907 symt_new_typedef(msc_dbg
->module
, symt
, sym
->udt_v3
.name
);
1909 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1910 sym
->udt_v3
.name
, sym
->udt_v3
.type
);
1915 * These are special, in that they are always followed by an
1916 * additional length-prefixed string which is *not* included
1917 * into the symbol length count. We need to skip it.
1922 name
= (const char*)sym
+ length
;
1923 length
+= (*name
+ 1 + 3) & ~3;
1926 case S_MSTOOL_V3
: /* just to silence a few warnings */
1927 case S_MSTOOLINFO_V3
:
1928 case S_MSTOOLENV_V3
:
1932 TRACE("Start search: seg=0x%x at offset 0x%08x\n",
1933 sym
->ssearch_v1
.segment
, sym
->ssearch_v1
.offset
);
1937 TRACE("S-Align V1\n");
1940 /* the symbols we can safely ignore for now */
1942 case S_FRAMEINFO_V2
:
1943 case S_SECUCOOKIE_V3
:
1945 case S_SUBSECTINFO_V3
:
1946 case S_ENTRYPOINT_V3
:
1948 TRACE("Unsupported symbol id %x\n", sym
->generic
.id
);
1952 FIXME("Unsupported symbol id %x\n", sym
->generic
.id
);
1953 dump(sym
, 2 + sym
->generic
.len
);
1958 if (curr_func
) symt_normalize_function(msc_dbg
->module
, curr_func
);
1963 static int codeview_snarf_public(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1964 int offset
, int size
)
1968 struct symt_compiland
* compiland
= NULL
;
1971 * Loop over the different types of records and whenever we
1972 * find something we are interested in, record it and move on.
1974 for (i
= offset
; i
< size
; i
+= length
)
1976 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1977 length
= sym
->generic
.len
+ 2;
1978 if (i
+ length
> size
) break;
1979 if (!sym
->generic
.id
|| length
< 4) break;
1980 if (length
& 3) FIXME("unpadded len %u\n", length
);
1982 switch (sym
->generic
.id
)
1984 case S_PUB_V1
: /* FIXME is this really a 'data_v1' structure ?? */
1985 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1987 symt_new_public(msc_dbg
->module
, compiland
,
1988 terminate_string(&sym
->data_v1
.p_name
),
1989 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
), 1);
1992 case S_PUB_V2
: /* FIXME is this really a 'data_v2' structure ?? */
1993 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1995 symt_new_public(msc_dbg
->module
, compiland
,
1996 terminate_string(&sym
->data_v2
.p_name
),
1997 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
), 1);
2002 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2004 symt_new_public(msc_dbg
->module
, compiland
,
2006 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
), 1);
2009 case S_PUB_FUNC1_V3
:
2010 case S_PUB_FUNC2_V3
: /* using a data_v3 isn't what we'd expect */
2012 /* FIXME: this is plain wrong (from a simple test) */
2013 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2015 symt_new_public(msc_dbg
->module
, compiland
,
2017 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
), 1);
2022 * Global and local data symbols. We don't associate these
2023 * with any given source file.
2027 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
2028 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
2029 sym
->generic
.id
== S_LDATA_V1
, FALSE
);
2033 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
2034 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
2035 sym
->generic
.id
== S_LDATA_V2
, FALSE
);
2039 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
2040 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
2041 sym
->generic
.id
== S_LDATA_V3
, FALSE
);
2044 * These are special, in that they are always followed by an
2045 * additional length-prefixed string which is *not* included
2046 * into the symbol length count. We need to skip it.
2051 length
+= (((const char*)sym
)[length
] + 1 + 3) & ~3;
2054 msc_dbg
->module
->sortlist_valid
= TRUE
;
2056 msc_dbg
->module
->sortlist_valid
= FALSE
;
2060 /*========================================================================
2064 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
,
2070 if (!size
) return NULL
;
2072 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2073 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2075 for (i
= 0; i
< num_blocks
; i
++)
2076 memcpy(buffer
+ i
* pdb
->block_size
,
2077 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2082 static void* pdb_ds_read(const struct PDB_DS_HEADER
* pdb
, const DWORD
* block_list
,
2088 if (!size
) return NULL
;
2090 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2091 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2093 for (i
= 0; i
< num_blocks
; i
++)
2094 memcpy(buffer
+ i
* pdb
->block_size
,
2095 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2100 static void* pdb_read_jg_file(const struct PDB_JG_HEADER
* pdb
,
2101 const struct PDB_JG_TOC
* toc
, DWORD file_nr
)
2103 const WORD
* block_list
;
2106 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2108 block_list
= (const WORD
*) &toc
->file
[toc
->num_files
];
2109 for (i
= 0; i
< file_nr
; i
++)
2110 block_list
+= (toc
->file
[i
].size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2112 return pdb_jg_read(pdb
, block_list
, toc
->file
[file_nr
].size
);
2115 static void* pdb_read_ds_file(const struct PDB_DS_HEADER
* pdb
,
2116 const struct PDB_DS_TOC
* toc
, DWORD file_nr
)
2118 const DWORD
* block_list
;
2121 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2122 if (toc
->file_size
[file_nr
] == 0 || toc
->file_size
[file_nr
] == 0xFFFFFFFF) return NULL
;
2124 block_list
= &toc
->file_size
[toc
->num_files
];
2125 for (i
= 0; i
< file_nr
; i
++)
2126 block_list
+= (toc
->file_size
[i
] + pdb
->block_size
- 1) / pdb
->block_size
;
2128 return pdb_ds_read(pdb
, block_list
, toc
->file_size
[file_nr
]);
2131 static void* pdb_read_file(const struct pdb_file_info
* pdb_file
,
2134 switch (pdb_file
->kind
)
2137 return pdb_read_jg_file((const struct PDB_JG_HEADER
*)pdb_file
->image
,
2138 pdb_file
->u
.jg
.toc
, file_nr
);
2140 return pdb_read_ds_file((const struct PDB_DS_HEADER
*)pdb_file
->image
,
2141 pdb_file
->u
.ds
.toc
, file_nr
);
2146 static unsigned pdb_get_file_size(const struct pdb_file_info
* pdb_file
, DWORD file_nr
)
2148 switch (pdb_file
->kind
)
2150 case PDB_JG
: return pdb_file
->u
.jg
.toc
->file
[file_nr
].size
;
2151 case PDB_DS
: return pdb_file
->u
.ds
.toc
->file_size
[file_nr
];
2156 static void pdb_free(void* buffer
)
2158 HeapFree(GetProcessHeap(), 0, buffer
);
2161 static void pdb_free_file(struct pdb_file_info
* pdb_file
)
2163 switch (pdb_file
->kind
)
2166 pdb_free(pdb_file
->u
.jg
.toc
);
2167 pdb_file
->u
.jg
.toc
= NULL
;
2170 pdb_free(pdb_file
->u
.ds
.toc
);
2171 pdb_file
->u
.ds
.toc
= NULL
;
2174 HeapFree(GetProcessHeap(), 0, pdb_file
->stream_dict
);
2177 static BOOL
pdb_load_stream_name_table(struct pdb_file_info
* pdb_file
, const char* str
, unsigned cb
)
2185 pdw
= (DWORD
*)(str
+ cb
);
2189 pdb_file
->stream_dict
= HeapAlloc(GetProcessHeap(), 0, (numok
+ 1) * sizeof(struct pdb_stream_name
) + cb
);
2190 if (!pdb_file
->stream_dict
) return FALSE
;
2191 cpstr
= (char*)(pdb_file
->stream_dict
+ numok
+ 1);
2192 memcpy(cpstr
, str
, cb
);
2194 /* bitfield: first dword is len (in dword), then data */
2196 pdw
+= *ok_bits
++ + 1;
2199 FIXME("unexpected value\n");
2203 for (i
= j
= 0; i
< count
; i
++)
2205 if (ok_bits
[i
/ 32] & (1 << (i
% 32)))
2207 if (j
>= numok
) break;
2208 pdb_file
->stream_dict
[j
].name
= &cpstr
[*pdw
++];
2209 pdb_file
->stream_dict
[j
].index
= *pdw
++;
2214 pdb_file
->stream_dict
[numok
].name
= NULL
;
2215 pdb_file
->fpoext_stream
= -1;
2216 return j
== numok
&& i
== count
;
2219 static unsigned pdb_get_stream_by_name(const struct pdb_file_info
* pdb_file
, const char* name
)
2221 struct pdb_stream_name
* psn
;
2223 for (psn
= pdb_file
->stream_dict
; psn
&& psn
->name
; psn
++)
2225 if (!strcmp(psn
->name
, name
)) return psn
->index
;
2230 static void* pdb_read_strings(const struct pdb_file_info
* pdb_file
)
2235 idx
= pdb_get_stream_by_name(pdb_file
, "/names");
2238 ret
= pdb_read_file( pdb_file
, idx
);
2239 if (ret
&& *(const DWORD
*)ret
== 0xeffeeffe) return ret
;
2242 WARN("string table not found\n");
2246 static void pdb_module_remove(struct process
* pcsn
, struct module_format
* modfmt
)
2250 for (i
= 0; i
< modfmt
->u
.pdb_info
->used_subfiles
; i
++)
2252 pdb_free_file(&modfmt
->u
.pdb_info
->pdb_files
[i
]);
2253 if (modfmt
->u
.pdb_info
->pdb_files
[i
].image
)
2254 UnmapViewOfFile(modfmt
->u
.pdb_info
->pdb_files
[i
].image
);
2255 if (modfmt
->u
.pdb_info
->pdb_files
[i
].hMap
)
2256 CloseHandle(modfmt
->u
.pdb_info
->pdb_files
[i
].hMap
);
2258 HeapFree(GetProcessHeap(), 0, modfmt
);
2261 static void pdb_convert_types_header(PDB_TYPES
* types
, const BYTE
* image
)
2263 memset(types
, 0, sizeof(PDB_TYPES
));
2266 if (*(const DWORD
*)image
< 19960000) /* FIXME: correct version? */
2268 /* Old version of the types record header */
2269 const PDB_TYPES_OLD
* old
= (const PDB_TYPES_OLD
*)image
;
2270 types
->version
= old
->version
;
2271 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
2272 types
->type_size
= old
->type_size
;
2273 types
->first_index
= old
->first_index
;
2274 types
->last_index
= old
->last_index
;
2275 types
->file
= old
->file
;
2279 /* New version of the types record header */
2280 *types
= *(const PDB_TYPES
*)image
;
2284 static void pdb_convert_symbols_header(PDB_SYMBOLS
* symbols
,
2285 int* header_size
, const BYTE
* image
)
2287 memset(symbols
, 0, sizeof(PDB_SYMBOLS
));
2290 if (*(const DWORD
*)image
!= 0xffffffff)
2292 /* Old version of the symbols record header */
2293 const PDB_SYMBOLS_OLD
* old
= (const PDB_SYMBOLS_OLD
*)image
;
2294 symbols
->version
= 0;
2295 symbols
->module_size
= old
->module_size
;
2296 symbols
->offset_size
= old
->offset_size
;
2297 symbols
->hash_size
= old
->hash_size
;
2298 symbols
->srcmodule_size
= old
->srcmodule_size
;
2299 symbols
->pdbimport_size
= 0;
2300 symbols
->hash1_file
= old
->hash1_file
;
2301 symbols
->hash2_file
= old
->hash2_file
;
2302 symbols
->gsym_file
= old
->gsym_file
;
2304 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
2308 /* New version of the symbols record header */
2309 *symbols
= *(const PDB_SYMBOLS
*)image
;
2310 *header_size
= sizeof(PDB_SYMBOLS
);
2314 static void pdb_convert_symbol_file(const PDB_SYMBOLS
* symbols
,
2315 PDB_SYMBOL_FILE_EX
* sfile
,
2316 unsigned* size
, const void* image
)
2319 if (symbols
->version
< 19970000)
2321 const PDB_SYMBOL_FILE
*sym_file
= image
;
2322 memset(sfile
, 0, sizeof(*sfile
));
2323 sfile
->file
= sym_file
->file
;
2324 sfile
->range
.index
= sym_file
->range
.index
;
2325 sfile
->symbol_size
= sym_file
->symbol_size
;
2326 sfile
->lineno_size
= sym_file
->lineno_size
;
2327 *size
= sizeof(PDB_SYMBOL_FILE
) - 1;
2331 memcpy(sfile
, image
, sizeof(PDB_SYMBOL_FILE_EX
));
2332 *size
= sizeof(PDB_SYMBOL_FILE_EX
) - 1;
2336 static HANDLE
map_pdb_file(const struct process
* pcs
,
2337 const struct pdb_lookup
* lookup
,
2338 struct module
* module
)
2340 HANDLE hFile
, hMap
= NULL
;
2341 char dbg_file_path
[MAX_PATH
];
2344 switch (lookup
->kind
)
2347 ret
= path_find_symbol_file(pcs
, lookup
->filename
, NULL
, lookup
->timestamp
,
2348 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2351 ret
= path_find_symbol_file(pcs
, lookup
->filename
, &lookup
->guid
, 0,
2352 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2357 WARN("\tCouldn't find %s\n", lookup
->filename
);
2360 if ((hFile
= CreateFileA(dbg_file_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2361 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) != INVALID_HANDLE_VALUE
)
2363 hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
2369 static void pdb_process_types(const struct msc_debug_info
* msc_dbg
,
2370 const struct pdb_file_info
* pdb_file
)
2372 BYTE
* types_image
= NULL
;
2374 types_image
= pdb_read_file(pdb_file
, 2);
2378 struct codeview_type_parse ctp
;
2383 pdb_convert_types_header(&types
, types_image
);
2385 /* Check for unknown versions */
2386 switch (types
.version
)
2388 case 19950410: /* VC 4.0 */
2390 case 19961031: /* VC 5.0 / 6.0 */
2391 case 19990903: /* VC 7.0 */
2392 case 20040203: /* VC 8.0 */
2395 ERR("-Unknown type info version %d\n", types
.version
);
2398 ctp
.module
= msc_dbg
->module
;
2399 /* reconstruct the types offset...
2400 * FIXME: maybe it's present in the newest PDB_TYPES structures
2402 total
= types
.last_index
- types
.first_index
+ 1;
2403 offset
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD
) * total
);
2404 ctp
.table
= ptr
= types_image
+ types
.type_offset
;
2406 while (ptr
< ctp
.table
+ types
.type_size
&& ctp
.num
< total
)
2408 offset
[ctp
.num
++] = ptr
- ctp
.table
;
2409 ptr
+= ((const union codeview_type
*)ptr
)->generic
.len
+ 2;
2411 ctp
.offset
= offset
;
2413 /* Read type table */
2414 codeview_parse_type_table(&ctp
);
2415 HeapFree(GetProcessHeap(), 0, offset
);
2416 pdb_free(types_image
);
2420 static const char PDB_JG_IDENT
[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
2421 static const char PDB_DS_IDENT
[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
2423 /******************************************************************
2426 * Tries to load a pdb file
2427 * 'matched' is filled with the number of correct matches for this file:
2428 * - age counts for one
2429 * - timestamp or guid depending on kind counts for one
2430 * a wrong kind of file returns FALSE (FIXME ?)
2432 static BOOL
pdb_init(const struct pdb_lookup
* pdb_lookup
, struct pdb_file_info
* pdb_file
,
2433 const char* image
, unsigned* matched
)
2437 /* check the file header, and if ok, load the TOC */
2438 TRACE("PDB(%s): %.40s\n", pdb_lookup
->filename
, debugstr_an(image
, 40));
2441 if (!memcmp(image
, PDB_JG_IDENT
, sizeof(PDB_JG_IDENT
)))
2443 const struct PDB_JG_HEADER
* pdb
= (const struct PDB_JG_HEADER
*)image
;
2444 struct PDB_JG_ROOT
* root
;
2446 pdb_file
->u
.jg
.toc
= pdb_jg_read(pdb
, pdb
->toc_block
, pdb
->toc
.size
);
2447 root
= pdb_read_jg_file(pdb
, pdb_file
->u
.jg
.toc
, 1);
2450 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2453 switch (root
->Version
)
2455 case 19950623: /* VC 4.0 */
2457 case 19960307: /* VC 5.0 */
2458 case 19970604: /* VC 6.0 */
2461 ERR("-Unknown root block version %d\n", root
->Version
);
2463 if (pdb_lookup
->kind
!= PDB_JG
)
2465 WARN("Found %s, but wrong PDB kind\n", pdb_lookup
->filename
);
2468 pdb_file
->kind
= PDB_JG
;
2469 pdb_file
->u
.jg
.timestamp
= root
->TimeDateStamp
;
2470 pdb_file
->age
= root
->Age
;
2471 if (root
->TimeDateStamp
== pdb_lookup
->timestamp
) (*matched
)++;
2472 else WARN("Found %s, but wrong signature: %08x %08x\n",
2473 pdb_lookup
->filename
, root
->TimeDateStamp
, pdb_lookup
->timestamp
);
2474 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2475 else WARN("Found %s, but wrong age: %08x %08x\n",
2476 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2477 TRACE("found JG for %s: age=%x timestamp=%x\n",
2478 pdb_lookup
->filename
, root
->Age
, root
->TimeDateStamp
);
2479 pdb_load_stream_name_table(pdb_file
, &root
->names
[0], root
->cbNames
);
2483 else if (!memcmp(image
, PDB_DS_IDENT
, sizeof(PDB_DS_IDENT
)))
2485 const struct PDB_DS_HEADER
* pdb
= (const struct PDB_DS_HEADER
*)image
;
2486 struct PDB_DS_ROOT
* root
;
2488 pdb_file
->u
.ds
.toc
=
2490 (const DWORD
*)((const char*)pdb
+ pdb
->toc_page
* pdb
->block_size
),
2492 root
= pdb_read_ds_file(pdb
, pdb_file
->u
.ds
.toc
, 1);
2495 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2498 switch (root
->Version
)
2503 ERR("-Unknown root block version %d\n", root
->Version
);
2505 pdb_file
->kind
= PDB_DS
;
2506 pdb_file
->u
.ds
.guid
= root
->guid
;
2507 pdb_file
->age
= root
->Age
;
2508 if (!memcmp(&root
->guid
, &pdb_lookup
->guid
, sizeof(GUID
))) (*matched
)++;
2509 else WARN("Found %s, but wrong GUID: %s %s\n",
2510 pdb_lookup
->filename
, debugstr_guid(&root
->guid
),
2511 debugstr_guid(&pdb_lookup
->guid
));
2512 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2513 else WARN("Found %s, but wrong age: %08x %08x\n",
2514 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2515 TRACE("found DS for %s: age=%x guid=%s\n",
2516 pdb_lookup
->filename
, root
->Age
, debugstr_guid(&root
->guid
));
2517 pdb_load_stream_name_table(pdb_file
, &root
->names
[0], root
->cbNames
);
2522 if (0) /* some tool to dump the internal files from a PDB file */
2526 switch (pdb_file
->kind
)
2528 case PDB_JG
: num_files
= pdb_file
->u
.jg
.toc
->num_files
; break;
2529 case PDB_DS
: num_files
= pdb_file
->u
.ds
.toc
->num_files
; break;
2532 for (i
= 1; i
< num_files
; i
++)
2534 unsigned char* x
= pdb_read_file(pdb_file
, i
);
2535 FIXME("********************** [%u]: size=%08x\n",
2536 i
, pdb_get_file_size(pdb_file
, i
));
2537 dump(x
, pdb_get_file_size(pdb_file
, i
));
2544 static BOOL
pdb_process_internal(const struct process
* pcs
,
2545 const struct msc_debug_info
* msc_dbg
,
2546 const struct pdb_lookup
* pdb_lookup
,
2547 struct pdb_module_info
* pdb_module_info
,
2548 unsigned module_index
);
2550 static void pdb_process_symbol_imports(const struct process
* pcs
,
2551 const struct msc_debug_info
* msc_dbg
,
2552 const PDB_SYMBOLS
* symbols
,
2553 const void* symbols_image
,
2555 const struct pdb_lookup
* pdb_lookup
,
2556 struct pdb_module_info
* pdb_module_info
,
2557 unsigned module_index
)
2559 if (module_index
== -1 && symbols
&& symbols
->pdbimport_size
)
2561 const PDB_SYMBOL_IMPORT
*imp
;
2566 struct pdb_file_info sf0
= pdb_module_info
->pdb_files
[0];
2568 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2569 symbols
->module_size
+ symbols
->offset_size
+
2570 symbols
->hash_size
+ symbols
->srcmodule_size
);
2572 last
= (const char*)imp
+ symbols
->pdbimport_size
;
2573 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
2575 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
2576 if (i
>= CV_MAX_MODULES
) FIXME("Out of bounds !!!\n");
2577 if (!strcasecmp(pdb_lookup
->filename
, imp
->filename
))
2579 if (module_index
!= -1) FIXME("Twice the entry\n");
2580 else module_index
= i
;
2581 pdb_module_info
->pdb_files
[i
] = sf0
;
2585 struct pdb_lookup imp_pdb_lookup
;
2587 /* FIXME: this is an import of a JG PDB file
2588 * how's a DS PDB handled ?
2590 imp_pdb_lookup
.filename
= imp
->filename
;
2591 imp_pdb_lookup
.kind
= PDB_JG
;
2592 imp_pdb_lookup
.timestamp
= imp
->TimeDateStamp
;
2593 imp_pdb_lookup
.age
= imp
->Age
;
2594 TRACE("got for %s: age=%u ts=%x\n",
2595 imp
->filename
, imp
->Age
, imp
->TimeDateStamp
);
2596 pdb_process_internal(pcs
, msc_dbg
, &imp_pdb_lookup
, pdb_module_info
, i
);
2599 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)first
+ ((ptr
- (const char*)first
+ strlen(ptr
) + 1 + 3) & ~3));
2601 pdb_module_info
->used_subfiles
= i
;
2603 if (module_index
== -1)
2606 pdb_module_info
->used_subfiles
= 1;
2608 cv_current_module
= &cv_zmodules
[module_index
];
2609 if (cv_current_module
->allowed
) FIXME("Already allowed ??\n");
2610 cv_current_module
->allowed
= TRUE
;
2613 static BOOL
pdb_process_internal(const struct process
* pcs
,
2614 const struct msc_debug_info
* msc_dbg
,
2615 const struct pdb_lookup
* pdb_lookup
,
2616 struct pdb_module_info
* pdb_module_info
,
2617 unsigned module_index
)
2621 BYTE
* symbols_image
= NULL
;
2622 char* files_image
= NULL
;
2623 DWORD files_size
= 0;
2625 struct pdb_file_info
* pdb_file
;
2627 TRACE("Processing PDB file %s\n", pdb_lookup
->filename
);
2629 pdb_file
= &pdb_module_info
->pdb_files
[module_index
== -1 ? 0 : module_index
];
2630 /* Open and map() .PDB file */
2631 if ((hMap
= map_pdb_file(pcs
, pdb_lookup
, msc_dbg
->module
)) == NULL
||
2632 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2634 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2638 if (!pdb_init(pdb_lookup
, pdb_file
, image
, &matched
) || matched
!= 2)
2641 UnmapViewOfFile(image
);
2645 pdb_file
->hMap
= hMap
;
2646 pdb_file
->image
= image
;
2647 symbols_image
= pdb_read_file(pdb_file
, 3);
2650 PDB_SYMBOLS symbols
;
2654 int header_size
= 0;
2655 PDB_STREAM_INDEXES
* psi
;
2657 pdb_convert_symbols_header(&symbols
, &header_size
, symbols_image
);
2658 switch (symbols
.version
)
2660 case 0: /* VC 4.0 */
2661 case 19960307: /* VC 5.0 */
2662 case 19970606: /* VC 6.0 */
2666 ERR("-Unknown symbol info version %d %08x\n",
2667 symbols
.version
, symbols
.version
);
2670 switch (symbols
.stream_index_size
)
2673 case sizeof(PDB_STREAM_INDEXES_OLD
):
2674 /* no fpo ext stream in this case */
2676 case sizeof(PDB_STREAM_INDEXES
):
2677 psi
= (PDB_STREAM_INDEXES
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2678 symbols
.module_size
+ symbols
.offset_size
+
2679 symbols
.hash_size
+ symbols
.srcmodule_size
+
2680 symbols
.pdbimport_size
+ symbols
.unknown2_size
);
2681 pdb_file
->fpoext_stream
= psi
->FPO_EXT
;
2684 FIXME("Unknown PDB_STREAM_INDEXES size (%d)\n", symbols
.stream_index_size
);
2687 files_image
= pdb_read_strings(pdb_file
);
2688 if (files_image
) files_size
= *(const DWORD
*)(files_image
+ 8);
2690 pdb_process_symbol_imports(pcs
, msc_dbg
, &symbols
, symbols_image
, image
,
2691 pdb_lookup
, pdb_module_info
, module_index
);
2692 pdb_process_types(msc_dbg
, pdb_file
);
2694 /* Read global symbol table */
2695 globalimage
= pdb_read_file(pdb_file
, symbols
.gsym_file
);
2698 codeview_snarf(msc_dbg
, globalimage
, 0,
2699 pdb_get_file_size(pdb_file
, symbols
.gsym_file
), FALSE
);
2702 /* Read per-module symbols' tables */
2703 file
= symbols_image
+ header_size
;
2704 while (file
- symbols_image
< header_size
+ symbols
.module_size
)
2706 PDB_SYMBOL_FILE_EX sfile
;
2707 const char* file_name
;
2710 HeapValidate(GetProcessHeap(), 0, NULL
);
2711 pdb_convert_symbol_file(&symbols
, &sfile
, &size
, file
);
2713 modimage
= pdb_read_file(pdb_file
, sfile
.file
);
2716 if (sfile
.symbol_size
)
2717 codeview_snarf(msc_dbg
, modimage
, sizeof(DWORD
),
2718 sfile
.symbol_size
, TRUE
);
2720 if (sfile
.lineno_size
)
2721 codeview_snarf_linetab(msc_dbg
,
2722 modimage
+ sfile
.symbol_size
,
2724 pdb_file
->kind
== PDB_JG
);
2726 codeview_snarf_linetab2(msc_dbg
, modimage
+ sfile
.symbol_size
+ sfile
.lineno_size
,
2727 pdb_get_file_size(pdb_file
, sfile
.file
) - sfile
.symbol_size
- sfile
.lineno_size
,
2728 files_image
+ 12, files_size
);
2732 file_name
= (const char*)file
+ size
;
2733 file_name
+= strlen(file_name
) + 1;
2734 file
= (BYTE
*)((DWORD_PTR
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3);
2736 /* finish the remaining public and global information */
2739 codeview_snarf_public(msc_dbg
, globalimage
, 0,
2740 pdb_get_file_size(pdb_file
, symbols
.gsym_file
));
2741 pdb_free(globalimage
);
2745 pdb_process_symbol_imports(pcs
, msc_dbg
, NULL
, NULL
, image
,
2746 pdb_lookup
, pdb_module_info
, module_index
);
2748 pdb_free(symbols_image
);
2749 pdb_free(files_image
);
2754 static BOOL
pdb_process_file(const struct process
* pcs
,
2755 const struct msc_debug_info
* msc_dbg
,
2756 struct pdb_lookup
* pdb_lookup
)
2759 struct module_format
* modfmt
;
2760 struct pdb_module_info
* pdb_module_info
;
2762 modfmt
= HeapAlloc(GetProcessHeap(), 0,
2763 sizeof(struct module_format
) + sizeof(struct pdb_module_info
));
2764 if (!modfmt
) return FALSE
;
2766 pdb_module_info
= (void*)(modfmt
+ 1);
2767 msc_dbg
->module
->format_info
[DFI_PDB
] = modfmt
;
2768 modfmt
->module
= msc_dbg
->module
;
2769 modfmt
->remove
= pdb_module_remove
;
2770 modfmt
->loc_compute
= NULL
;
2771 modfmt
->u
.pdb_info
= pdb_module_info
;
2773 memset(cv_zmodules
, 0, sizeof(cv_zmodules
));
2774 codeview_init_basic_types(msc_dbg
->module
);
2775 ret
= pdb_process_internal(pcs
, msc_dbg
, pdb_lookup
,
2776 msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
, -1);
2777 codeview_clear_type_table();
2780 struct pdb_module_info
* pdb_info
= msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
;
2781 msc_dbg
->module
->module
.SymType
= SymCv
;
2782 if (pdb_info
->pdb_files
[0].kind
== PDB_JG
)
2783 msc_dbg
->module
->module
.PdbSig
= pdb_info
->pdb_files
[0].u
.jg
.timestamp
;
2785 msc_dbg
->module
->module
.PdbSig70
= pdb_info
->pdb_files
[0].u
.ds
.guid
;
2786 msc_dbg
->module
->module
.PdbAge
= pdb_info
->pdb_files
[0].age
;
2787 MultiByteToWideChar(CP_ACP
, 0, pdb_lookup
->filename
, -1,
2788 msc_dbg
->module
->module
.LoadedPdbName
,
2789 sizeof(msc_dbg
->module
->module
.LoadedPdbName
) / sizeof(WCHAR
));
2790 /* FIXME: we could have a finer grain here */
2791 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
2792 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
2793 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
2794 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
2795 msc_dbg
->module
->module
.Publics
= TRUE
;
2799 msc_dbg
->module
->format_info
[DFI_PDB
] = NULL
;
2800 HeapFree(GetProcessHeap(), 0, modfmt
);
2805 BOOL
pdb_fetch_file_info(const struct pdb_lookup
* pdb_lookup
, unsigned* matched
)
2807 HANDLE hFile
, hMap
= NULL
;
2810 struct pdb_file_info pdb_file
;
2812 if ((hFile
= CreateFileA(pdb_lookup
->filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2813 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) == INVALID_HANDLE_VALUE
||
2814 ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
2815 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2817 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2822 ret
= pdb_init(pdb_lookup
, &pdb_file
, image
, matched
);
2823 pdb_free_file(&pdb_file
);
2826 if (image
) UnmapViewOfFile(image
);
2827 if (hMap
) CloseHandle(hMap
);
2828 if (hFile
!= INVALID_HANDLE_VALUE
) CloseHandle(hFile
);
2833 /*========================================================================
2834 * FPO unwinding code
2837 /* Stack unwinding is based on postfixed operations.
2838 * Let's define our Postfix EValuator
2840 #define PEV_MAX_LEN 32
2843 struct cpu_stack_walk
* csw
;
2845 struct vector stack
;
2847 struct hash_table values
;
2854 struct hash_table_elt elt
;
2857 #define PEV_ERROR(pev, msg) snprintf((pev)->error, sizeof((pev)->error), "%s", (msg)),FALSE
2858 #define PEV_ERROR1(pev, msg, pmt) snprintf((pev)->error, sizeof((pev)->error), (msg), (pmt)),FALSE
2861 static void pev_dump_stack(struct pevaluator
* pev
)
2864 FIXME("stack #%d\n", pev
->stk_index
);
2865 for (i
= 0; i
< pev
->stk_index
; i
++)
2867 FIXME("\t%d) %s\n", i
, *(char**)vector_at(&pev
->stack
, i
));
2872 /* get the value out of an operand (variable or literal) */
2873 static BOOL
pev_get_val(struct pevaluator
* pev
, const char* str
, DWORD_PTR
* val
)
2876 struct hash_table_iter hti
;
2883 hash_table_iter_init(&pev
->values
, &hti
, str
);
2884 if (!(ptr
= hash_table_iter_up(&hti
)))
2885 return PEV_ERROR1(pev
, "get_zvalue: no value found (%s)", str
);
2886 *val
= GET_ENTRY(ptr
, struct zvalue
, elt
)->value
;
2889 *val
= strtol(str
, &n
, 10);
2890 if (n
== str
|| *n
!= '\0')
2891 return PEV_ERROR1(pev
, "get_val: not a literal (%s)", str
);
2896 /* push an operand onto the stack */
2897 static BOOL
pev_push(struct pevaluator
* pev
, const char* elt
)
2900 if (pev
->stk_index
< vector_length(&pev
->stack
))
2901 at
= vector_at(&pev
->stack
, pev
->stk_index
);
2903 at
= vector_add(&pev
->stack
, &pev
->pool
);
2904 if (!at
) return PEV_ERROR(pev
, "push: out of memory");
2905 *at
= pool_strdup(&pev
->pool
, elt
);
2910 /* pop an operand from the stack */
2911 static BOOL
pev_pop(struct pevaluator
* pev
, char* elt
)
2913 char** at
= vector_at(&pev
->stack
, --pev
->stk_index
);
2914 if (!at
) return PEV_ERROR(pev
, "pop: stack empty");
2919 /* pop an operand from the stack, and gets its value */
2920 static BOOL
pev_pop_val(struct pevaluator
* pev
, DWORD_PTR
* val
)
2922 char p
[PEV_MAX_LEN
];
2924 return pev_pop(pev
, p
) && pev_get_val(pev
, p
, val
);
2927 /* set var 'name' a new value (creates the var if it doesn't exist) */
2928 static BOOL
pev_set_value(struct pevaluator
* pev
, const char* name
, DWORD_PTR val
)
2930 struct hash_table_iter hti
;
2933 hash_table_iter_init(&pev
->values
, &hti
, name
);
2934 if (!(ptr
= hash_table_iter_up(&hti
)))
2936 struct zvalue
* zv
= pool_alloc(&pev
->pool
, sizeof(*zv
));
2937 if (!zv
) return PEV_ERROR(pev
, "set_value: out of memory");
2940 zv
->elt
.name
= pool_strdup(&pev
->pool
, name
);
2941 hash_table_add(&pev
->values
, &zv
->elt
);
2943 else GET_ENTRY(ptr
, struct zvalue
, elt
)->value
= val
;
2947 /* execute a binary operand from the two top most values on the stack.
2948 * puts result on top of the stack */
2949 static BOOL
pev_binop(struct pevaluator
* pev
, char op
)
2951 char res
[PEV_MAX_LEN
];
2952 DWORD_PTR v1
, v2
, c
;
2954 if (!pev_pop_val(pev
, &v1
) || !pev_pop_val(pev
, &v2
)) return FALSE
;
2957 case '+': c
= v1
+ v2
; break;
2958 case '-': c
= v1
- v2
; break;
2959 case '*': c
= v1
* v2
; break;
2960 case '/': c
= v1
/ v2
; break;
2961 case '%': c
= v1
% v2
; break;
2962 default: return PEV_ERROR1(pev
, "binop: unknown op (%c)", op
);
2964 snprintf(res
, sizeof(res
), "%ld", c
);
2969 /* pops top most operand, dereference it, on pushes the result on top of the stack */
2970 static BOOL
pev_deref(struct pevaluator
* pev
)
2972 char res
[PEV_MAX_LEN
];
2975 if (!pev_pop_val(pev
, &v1
)) return FALSE
;
2976 if (!sw_read_mem(pev
->csw
, v1
, &v2
, sizeof(v2
)))
2977 return PEV_ERROR1(pev
, "deref: cannot read mem at %lx\n", v1
);
2978 snprintf(res
, sizeof(res
), "%ld", v2
);
2983 /* assign value to variable (from two top most operands) */
2984 static BOOL
pev_assign(struct pevaluator
* pev
)
2986 char p2
[PEV_MAX_LEN
];
2989 if (!pev_pop_val(pev
, &v1
) || !pev_pop(pev
, p2
)) return FALSE
;
2990 if (p2
[0] != '$') return PEV_ERROR1(pev
, "assign: %s isn't a variable", p2
);
2991 pev_set_value(pev
, p2
, v1
);
2996 /* initializes the postfix evaluator */
2997 static void pev_init(struct pevaluator
* pev
, struct cpu_stack_walk
* csw
,
2998 PDB_FPO_DATA
* fpoext
, struct pdb_cmd_pair
* cpair
)
3001 pool_init(&pev
->pool
, 512);
3002 vector_init(&pev
->stack
, sizeof(char*), 8);
3004 hash_table_init(&pev
->pool
, &pev
->values
, 8);
3005 pev
->error
[0] = '\0';
3006 for (; cpair
->name
; cpair
++)
3007 pev_set_value(pev
, cpair
->name
, *cpair
->pvalue
);
3008 pev_set_value(pev
, ".raSearchStart", fpoext
->start
);
3009 pev_set_value(pev
, ".cbLocals", fpoext
->locals_size
);
3010 pev_set_value(pev
, ".cbParams", fpoext
->params_size
);
3011 pev_set_value(pev
, ".cbSavedRegs", fpoext
->savedregs_size
);
3014 static BOOL
pev_free(struct pevaluator
* pev
, struct pdb_cmd_pair
* cpair
)
3018 if (cpair
) for (; cpair
->name
; cpair
++)
3020 if (pev_get_val(pev
, cpair
->name
, &val
))
3021 *cpair
->pvalue
= val
;
3023 pool_destroy(&pev
->pool
);
3027 static BOOL
pdb_parse_cmd_string(struct cpu_stack_walk
* csw
, PDB_FPO_DATA
* fpoext
,
3028 const char* cmd
, struct pdb_cmd_pair
* cpair
)
3030 char token
[PEV_MAX_LEN
];
3034 struct pevaluator pev
;
3036 pev_init(&pev
, csw
, fpoext
, cpair
);
3037 for (ptr
= cmd
; !over
; ptr
++)
3039 if (*ptr
== ' ' || (over
= *ptr
== '\0'))
3043 if (!strcmp(token
, "+") || !strcmp(token
, "-") || !strcmp(token
, "*") ||
3044 !strcmp(token
, "/") || !strcmp(token
, "%"))
3046 if (!pev_binop(&pev
, token
[0])) goto done
;
3048 else if (!strcmp(token
, "^"))
3050 if (!pev_deref(&pev
)) goto done
;
3052 else if (!strcmp(token
, "="))
3054 if (!pev_assign(&pev
)) goto done
;
3058 if (!pev_push(&pev
, token
)) goto done
;
3064 if (ptok
- token
>= PEV_MAX_LEN
- 1)
3066 PEV_ERROR1(&pev
, "parse: token too long (%s)", ptr
- (ptok
- token
));
3072 pev_free(&pev
, cpair
);
3075 FIXME("Couldn't evaluate %s => %s\n", wine_dbgstr_a(cmd
), pev
.error
);
3076 pev_free(&pev
, NULL
);
3080 BOOL
pdb_virtual_unwind(struct cpu_stack_walk
* csw
, DWORD_PTR ip
,
3081 CONTEXT
* context
, struct pdb_cmd_pair
* cpair
)
3083 struct module_pair pair
;
3084 struct pdb_module_info
* pdb_info
;
3085 PDB_FPO_DATA
* fpoext
;
3086 unsigned i
, size
, strsize
;
3090 if (!(pair
.pcs
= process_find_by_handle(csw
->hProcess
)) ||
3091 !(pair
.requested
= module_find_by_addr(pair
.pcs
, ip
, DMT_UNKNOWN
)) ||
3092 !module_get_debug(&pair
))
3094 if (!pair
.effective
->format_info
[DFI_PDB
]) return FALSE
;
3095 pdb_info
= pair
.effective
->format_info
[DFI_PDB
]->u
.pdb_info
;
3096 TRACE("searching %lx => %lx\n", ip
, ip
- (DWORD_PTR
)pair
.effective
->module
.BaseOfImage
);
3097 ip
-= (DWORD_PTR
)pair
.effective
->module
.BaseOfImage
;
3099 strbase
= pdb_read_strings(&pdb_info
->pdb_files
[0]);
3100 if (!strbase
) return FALSE
;
3101 strsize
= *(const DWORD
*)(strbase
+ 8);
3102 fpoext
= pdb_read_file(&pdb_info
->pdb_files
[0], pdb_info
->pdb_files
[0].fpoext_stream
);
3103 size
= pdb_get_file_size(&pdb_info
->pdb_files
[0], pdb_info
->pdb_files
[0].fpoext_stream
);
3104 if (fpoext
&& (size
% sizeof(*fpoext
)) == 0)
3106 size
/= sizeof(*fpoext
);
3107 for (i
= 0; i
< size
; i
++)
3109 if (fpoext
[i
].start
<= ip
&& ip
< fpoext
[i
].start
+ fpoext
[i
].func_size
)
3111 TRACE("\t%08x %08x %8x %8x %4x %4x %4x %08x %s\n",
3112 fpoext
[i
].start
, fpoext
[i
].func_size
, fpoext
[i
].locals_size
,
3113 fpoext
[i
].params_size
, fpoext
[i
].maxstack_size
, fpoext
[i
].prolog_size
,
3114 fpoext
[i
].savedregs_size
, fpoext
[i
].flags
,
3115 fpoext
[i
].str_offset
< strsize
?
3116 wine_dbgstr_a(strbase
+ 12 + fpoext
[i
].str_offset
) : "<out of bounds>");
3117 if (fpoext
[i
].str_offset
< strsize
)
3118 ret
= pdb_parse_cmd_string(csw
, fpoext
, strbase
+ 12 + fpoext
[i
].str_offset
, cpair
);
3132 /*========================================================================
3133 * Process CodeView debug information.
3136 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
3137 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
3138 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
3139 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
3140 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
3142 static BOOL
codeview_process_info(const struct process
* pcs
,
3143 const struct msc_debug_info
* msc_dbg
)
3145 const DWORD
* signature
= (const DWORD
*)msc_dbg
->root
;
3147 struct pdb_lookup pdb_lookup
;
3149 TRACE("Processing signature %.4s\n", (const char*)signature
);
3153 case CODEVIEW_NB09_SIG
:
3154 case CODEVIEW_NB11_SIG
:
3156 const OMFSignature
* cv
= (const OMFSignature
*)msc_dbg
->root
;
3157 const OMFDirHeader
* hdr
= (const OMFDirHeader
*)(msc_dbg
->root
+ cv
->filepos
);
3158 const OMFDirEntry
* ent
;
3159 const OMFDirEntry
* prev
;
3160 const OMFDirEntry
* next
;
3163 codeview_init_basic_types(msc_dbg
->module
);
3165 for (i
= 0; i
< hdr
->cDir
; i
++)
3167 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
+ i
* hdr
->cbDirEntry
);
3168 if (ent
->SubSection
== sstGlobalTypes
)
3170 const OMFGlobalTypes
* types
;
3171 struct codeview_type_parse ctp
;
3173 types
= (const OMFGlobalTypes
*)(msc_dbg
->root
+ ent
->lfo
);
3174 ctp
.module
= msc_dbg
->module
;
3175 ctp
.offset
= (const DWORD
*)(types
+ 1);
3176 ctp
.num
= types
->cTypes
;
3177 ctp
.table
= (const BYTE
*)(ctp
.offset
+ types
->cTypes
);
3179 cv_current_module
= &cv_zmodules
[0];
3180 if (cv_current_module
->allowed
) FIXME("Already allowed ??\n");
3181 cv_current_module
->allowed
= TRUE
;
3183 codeview_parse_type_table(&ctp
);
3188 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
);
3189 for (i
= 0; i
< hdr
->cDir
; i
++, ent
= next
)
3191 next
= (i
== hdr
->cDir
-1) ? NULL
:
3192 (const OMFDirEntry
*)((const BYTE
*)ent
+ hdr
->cbDirEntry
);
3193 prev
= (i
== 0) ? NULL
:
3194 (const OMFDirEntry
*)((const BYTE
*)ent
- hdr
->cbDirEntry
);
3196 if (ent
->SubSection
== sstAlignSym
)
3198 codeview_snarf(msc_dbg
, msc_dbg
->root
+ ent
->lfo
, sizeof(DWORD
),
3202 * Check the next and previous entry. If either is a
3203 * sstSrcModule, it contains the line number info for
3206 * FIXME: This is not a general solution!
3208 if (next
&& next
->iMod
== ent
->iMod
&& next
->SubSection
== sstSrcModule
)
3209 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ next
->lfo
,
3212 if (prev
&& prev
->iMod
== ent
->iMod
&& prev
->SubSection
== sstSrcModule
)
3213 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ prev
->lfo
,
3219 msc_dbg
->module
->module
.SymType
= SymCv
;
3220 /* FIXME: we could have a finer grain here */
3221 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
3222 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
3223 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
3224 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
3225 msc_dbg
->module
->module
.Publics
= TRUE
;
3226 codeview_clear_type_table();
3231 case CODEVIEW_NB10_SIG
:
3233 const CODEVIEW_PDB_DATA
* pdb
= (const CODEVIEW_PDB_DATA
*)msc_dbg
->root
;
3234 pdb_lookup
.filename
= pdb
->name
;
3235 pdb_lookup
.kind
= PDB_JG
;
3236 pdb_lookup
.timestamp
= pdb
->timestamp
;
3237 pdb_lookup
.age
= pdb
->age
;
3238 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
3241 case CODEVIEW_RSDS_SIG
:
3243 const OMFSignatureRSDS
* rsds
= (const OMFSignatureRSDS
*)msc_dbg
->root
;
3245 TRACE("Got RSDS type of PDB file: guid=%s age=%08x name=%s\n",
3246 wine_dbgstr_guid(&rsds
->guid
), rsds
->age
, rsds
->name
);
3247 pdb_lookup
.filename
= rsds
->name
;
3248 pdb_lookup
.kind
= PDB_DS
;
3249 pdb_lookup
.guid
= rsds
->guid
;
3250 pdb_lookup
.age
= rsds
->age
;
3251 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
3255 ERR("Unknown CODEVIEW signature %08x in module %s\n",
3256 *signature
, debugstr_w(msc_dbg
->module
->module
.ModuleName
));
3261 msc_dbg
->module
->module
.CVSig
= *signature
;
3262 memcpy(msc_dbg
->module
->module
.CVData
, msc_dbg
->root
,
3263 sizeof(msc_dbg
->module
->module
.CVData
));
3268 /*========================================================================
3269 * Process debug directory.
3271 BOOL
pe_load_debug_directory(const struct process
* pcs
, struct module
* module
,
3272 const BYTE
* mapping
,
3273 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
3274 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
)
3278 struct msc_debug_info msc_dbg
;
3280 msc_dbg
.module
= module
;
3281 msc_dbg
.nsect
= nsect
;
3282 msc_dbg
.sectp
= sectp
;
3284 msc_dbg
.omapp
= NULL
;
3290 /* First, watch out for OMAP data */
3291 for (i
= 0; i
< nDbg
; i
++)
3293 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
)
3295 msc_dbg
.nomap
= dbg
[i
].SizeOfData
/ sizeof(OMAP_DATA
);
3296 msc_dbg
.omapp
= (const OMAP_DATA
*)(mapping
+ dbg
[i
].PointerToRawData
);
3301 /* Now, try to parse CodeView debug info */
3302 for (i
= 0; i
< nDbg
; i
++)
3304 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_CODEVIEW
)
3306 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
3307 if ((ret
= codeview_process_info(pcs
, &msc_dbg
))) goto done
;
3311 /* If not found, try to parse COFF debug info */
3312 for (i
= 0; i
< nDbg
; i
++)
3314 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_COFF
)
3316 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
3317 if ((ret
= coff_process_info(&msc_dbg
))) goto done
;
3321 /* FIXME: this should be supported... this is the debug information for
3322 * functions compiled without a frame pointer (FPO = frame pointer omission)
3323 * the associated data helps finding out the relevant information
3325 for (i
= 0; i
< nDbg
; i
++)
3326 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_FPO
)
3327 FIXME("This guy has FPO information\n");
3331 #define FRAME_TRAP 1
3334 typedef struct _FPO_DATA
3336 DWORD ulOffStart
; /* offset 1st byte of function code */
3337 DWORD cbProcSize
; /* # bytes in function */
3338 DWORD cdwLocals
; /* # bytes in locals/4 */
3339 WORD cdwParams
; /* # bytes in params/4 */
3341 WORD cbProlog
: 8; /* # bytes in prolog */
3342 WORD cbRegs
: 3; /* # regs saved */
3343 WORD fHasSEH
: 1; /* TRUE if SEH in func */
3344 WORD fUseBP
: 1; /* TRUE if EBP has been allocated */
3345 WORD reserved
: 1; /* reserved for future use */
3346 WORD cbFrame
: 2; /* frame type */
3353 ERR("Got a page fault while loading symbols\n");