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
74 struct PDB_JG_TOC
* toc
;
79 struct PDB_DS_TOC
* toc
;
84 /* FIXME: don't make it static */
85 #define CV_MAX_MODULES 32
86 struct pdb_module_info
88 unsigned used_subfiles
;
89 struct pdb_file_info pdb_files
[CV_MAX_MODULES
];
92 /*========================================================================
93 * Debug file access helper routines
96 static void dump(const void* ptr
, unsigned len
)
100 const char* hexof
= "0123456789abcdef";
103 for (i
= 0; i
< len
; i
+= 16)
105 sprintf(msg
, "%08x: ", i
);
106 memset(msg
+ 10, ' ', 3 * 16 + 1 + 16);
107 for (j
= 0; j
< min(16, len
- i
); j
++)
109 msg
[10 + 3 * j
+ 0] = hexof
[x
[i
+ j
] >> 4];
110 msg
[10 + 3 * j
+ 1] = hexof
[x
[i
+ j
] & 15];
111 msg
[10 + 3 * j
+ 2] = ' ';
112 msg
[10 + 3 * 16 + 1 + j
] = (x
[i
+ j
] >= 0x20 && x
[i
+ j
] < 0x7f) ?
115 msg
[10 + 3 * 16] = ' ';
116 msg
[10 + 3 * 16 + 1 + 16] = '\0';
121 /*========================================================================
122 * Process CodeView type information.
125 #define MAX_BUILTIN_TYPES 0x06FF
126 #define FIRST_DEFINABLE_TYPE 0x1000
128 static struct symt
* cv_basic_types
[MAX_BUILTIN_TYPES
];
130 struct cv_defined_module
133 unsigned int num_defined_types
;
134 struct symt
** defined_types
;
136 /* FIXME: don't make it static */
137 #define CV_MAX_MODULES 32
138 static struct cv_defined_module cv_zmodules
[CV_MAX_MODULES
];
139 static struct cv_defined_module
*cv_current_module
;
141 static void codeview_init_basic_types(struct module
* module
)
143 struct symt_udt
* udt
;
145 * These are the common builtin types that are used by VC++.
147 cv_basic_types
[T_NOTYPE
] = NULL
;
148 cv_basic_types
[T_ABS
] = NULL
;
149 cv_basic_types
[T_VOID
] = &symt_new_basic(module
, btVoid
, "void", 0)->symt
;
150 cv_basic_types
[T_CHAR
] = &symt_new_basic(module
, btChar
, "char", 1)->symt
;
151 cv_basic_types
[T_SHORT
] = &symt_new_basic(module
, btInt
, "short int", 2)->symt
;
152 cv_basic_types
[T_LONG
] = &symt_new_basic(module
, btInt
, "long int", 4)->symt
;
153 cv_basic_types
[T_QUAD
] = &symt_new_basic(module
, btInt
, "long long int", 8)->symt
;
154 cv_basic_types
[T_UCHAR
] = &symt_new_basic(module
, btUInt
, "unsigned char", 1)->symt
;
155 cv_basic_types
[T_USHORT
] = &symt_new_basic(module
, btUInt
, "unsigned short", 2)->symt
;
156 cv_basic_types
[T_ULONG
] = &symt_new_basic(module
, btUInt
, "unsigned long", 4)->symt
;
157 cv_basic_types
[T_UQUAD
] = &symt_new_basic(module
, btUInt
, "unsigned long long", 8)->symt
;
158 cv_basic_types
[T_BOOL08
] = &symt_new_basic(module
, btBool
, "BOOL08", 1)->symt
;
159 cv_basic_types
[T_BOOL16
] = &symt_new_basic(module
, btBool
, "BOOL16", 2)->symt
;
160 cv_basic_types
[T_BOOL32
] = &symt_new_basic(module
, btBool
, "BOOL32", 4)->symt
;
161 cv_basic_types
[T_BOOL64
] = &symt_new_basic(module
, btBool
, "BOOL64", 8)->symt
;
162 cv_basic_types
[T_REAL32
] = &symt_new_basic(module
, btFloat
, "float", 4)->symt
;
163 cv_basic_types
[T_REAL64
] = &symt_new_basic(module
, btFloat
, "double", 8)->symt
;
164 cv_basic_types
[T_REAL80
] = &symt_new_basic(module
, btFloat
, "long double", 10)->symt
;
165 cv_basic_types
[T_RCHAR
] = &symt_new_basic(module
, btInt
, "signed char", 1)->symt
;
166 cv_basic_types
[T_WCHAR
] = &symt_new_basic(module
, btWChar
, "wchar_t", 2)->symt
;
167 cv_basic_types
[T_INT2
] = &symt_new_basic(module
, btInt
, "INT2", 2)->symt
;
168 cv_basic_types
[T_UINT2
] = &symt_new_basic(module
, btUInt
, "UINT2", 2)->symt
;
169 cv_basic_types
[T_INT4
] = &symt_new_basic(module
, btInt
, "INT4", 4)->symt
;
170 cv_basic_types
[T_UINT4
] = &symt_new_basic(module
, btUInt
, "UINT4", 4)->symt
;
171 cv_basic_types
[T_INT8
] = &symt_new_basic(module
, btInt
, "INT8", 8)->symt
;
172 cv_basic_types
[T_UINT8
] = &symt_new_basic(module
, btUInt
, "UINT8", 8)->symt
;
173 cv_basic_types
[T_HRESULT
]= &symt_new_basic(module
, btUInt
, "HRESULT", 4)->symt
;
175 if (sizeof(void*) == 4)
177 cv_basic_types
[T_32PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
])->symt
;
178 cv_basic_types
[T_32PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
])->symt
;
179 cv_basic_types
[T_32PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
])->symt
;
180 cv_basic_types
[T_32PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
])->symt
;
181 cv_basic_types
[T_32PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
])->symt
;
182 cv_basic_types
[T_32PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
])->symt
;
183 cv_basic_types
[T_32PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
])->symt
;
184 cv_basic_types
[T_32PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
])->symt
;
185 cv_basic_types
[T_32PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
])->symt
;
186 cv_basic_types
[T_32PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
])->symt
;
187 cv_basic_types
[T_32PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
])->symt
;
188 cv_basic_types
[T_32PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
])->symt
;
189 cv_basic_types
[T_32PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
])->symt
;
190 cv_basic_types
[T_32PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
])->symt
;
191 cv_basic_types
[T_32PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
])->symt
;
192 cv_basic_types
[T_32PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
])->symt
;
193 cv_basic_types
[T_32PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
])->symt
;
194 cv_basic_types
[T_32PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
])->symt
;
195 cv_basic_types
[T_32PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
])->symt
;
196 cv_basic_types
[T_32PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
])->symt
;
197 cv_basic_types
[T_32PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
])->symt
;
198 cv_basic_types
[T_32PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
])->symt
;
199 cv_basic_types
[T_32PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
])->symt
;
200 cv_basic_types
[T_32PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
])->symt
;
201 cv_basic_types
[T_32PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
])->symt
;
203 /* The .pdb file can refer to 64 bit pointers values even on 32 bits applications. */
204 udt
= symt_new_udt(module
, "PVOID64", 8, UdtStruct
);
205 symt_add_udt_element(module
, udt
, "ptr64_low", cv_basic_types
[T_LONG
], 0, 32);
206 symt_add_udt_element(module
, udt
, "ptr64_high", cv_basic_types
[T_LONG
], 32, 32);
207 cv_basic_types
[T_64PVOID
]= &udt
->symt
;
211 cv_basic_types
[T_64PVOID
] = &symt_new_pointer(module
, cv_basic_types
[T_VOID
])->symt
;
212 cv_basic_types
[T_64PCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_CHAR
])->symt
;
213 cv_basic_types
[T_64PSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_SHORT
])->symt
;
214 cv_basic_types
[T_64PLONG
] = &symt_new_pointer(module
, cv_basic_types
[T_LONG
])->symt
;
215 cv_basic_types
[T_64PQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_QUAD
])->symt
;
216 cv_basic_types
[T_64PUCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_UCHAR
])->symt
;
217 cv_basic_types
[T_64PUSHORT
] = &symt_new_pointer(module
, cv_basic_types
[T_USHORT
])->symt
;
218 cv_basic_types
[T_64PULONG
] = &symt_new_pointer(module
, cv_basic_types
[T_ULONG
])->symt
;
219 cv_basic_types
[T_64PUQUAD
] = &symt_new_pointer(module
, cv_basic_types
[T_UQUAD
])->symt
;
220 cv_basic_types
[T_64PBOOL08
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL08
])->symt
;
221 cv_basic_types
[T_64PBOOL16
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL16
])->symt
;
222 cv_basic_types
[T_64PBOOL32
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL32
])->symt
;
223 cv_basic_types
[T_64PBOOL64
] = &symt_new_pointer(module
, cv_basic_types
[T_BOOL64
])->symt
;
224 cv_basic_types
[T_64PREAL32
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL32
])->symt
;
225 cv_basic_types
[T_64PREAL64
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL64
])->symt
;
226 cv_basic_types
[T_64PREAL80
] = &symt_new_pointer(module
, cv_basic_types
[T_REAL80
])->symt
;
227 cv_basic_types
[T_64PRCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_RCHAR
])->symt
;
228 cv_basic_types
[T_64PWCHAR
] = &symt_new_pointer(module
, cv_basic_types
[T_WCHAR
])->symt
;
229 cv_basic_types
[T_64PINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_INT2
])->symt
;
230 cv_basic_types
[T_64PUINT2
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT2
])->symt
;
231 cv_basic_types
[T_64PINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_INT4
])->symt
;
232 cv_basic_types
[T_64PUINT4
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT4
])->symt
;
233 cv_basic_types
[T_64PINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_INT8
])->symt
;
234 cv_basic_types
[T_64PUINT8
] = &symt_new_pointer(module
, cv_basic_types
[T_UINT8
])->symt
;
235 cv_basic_types
[T_64PHRESULT
]= &symt_new_pointer(module
, cv_basic_types
[T_HRESULT
])->symt
;
239 static int leaf_as_variant(VARIANT
* v
, const unsigned short int* leaf
)
241 unsigned short int type
= *leaf
++;
244 if (type
< LF_NUMERIC
)
246 v
->n1
.n2
.vt
= VT_UINT
;
247 v
->n1
.n2
.n3
.uintVal
= type
;
256 v
->n1
.n2
.n3
.cVal
= *(const char*)leaf
;
262 v
->n1
.n2
.n3
.iVal
= *(const short*)leaf
;
267 v
->n1
.n2
.vt
= VT_UI2
;
268 v
->n1
.n2
.n3
.uiVal
= *leaf
;
274 v
->n1
.n2
.n3
.lVal
= *(const int*)leaf
;
279 v
->n1
.n2
.vt
= VT_UI4
;
280 v
->n1
.n2
.n3
.uiVal
= *(const unsigned int*)leaf
;
286 v
->n1
.n2
.n3
.llVal
= *(const long long int*)leaf
;
291 v
->n1
.n2
.vt
= VT_UI8
;
292 v
->n1
.n2
.n3
.ullVal
= *(const long long unsigned int*)leaf
;
298 v
->n1
.n2
.n3
.fltVal
= *(const float*)leaf
;
302 FIXME("Unsupported numeric leaf type %04x\n", type
);
304 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
310 v
->n1
.n2
.n3
.fltVal
= *(const double*)leaf
;
314 FIXME("Unsupported numeric leaf type %04x\n", type
);
316 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
320 FIXME("Unsupported numeric leaf type %04x\n", type
);
322 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
326 FIXME("Unsupported numeric leaf type %04x\n", type
);
328 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
332 FIXME("Unsupported numeric leaf type %04x\n", type
);
334 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
338 FIXME("Unsupported numeric leaf type %04x\n", type
);
340 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
344 FIXME("Unsupported numeric leaf type %04x\n", type
);
346 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
350 FIXME("Unsupported numeric leaf type %04x\n", type
);
352 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
356 FIXME("Unknown numeric leaf type %04x\n", type
);
357 v
->n1
.n2
.vt
= VT_EMPTY
; /* FIXME */
365 static int numeric_leaf(int* value
, const unsigned short int* leaf
)
367 unsigned short int type
= *leaf
++;
370 if (type
< LF_NUMERIC
)
380 *value
= *(const char*)leaf
;
385 *value
= *(const short*)leaf
;
395 *value
= *(const int*)leaf
;
400 *value
= *(const unsigned int*)leaf
;
405 FIXME("Unsupported numeric leaf type %04x\n", type
);
407 *value
= 0; /* FIXME */
411 FIXME("Unsupported numeric leaf type %04x\n", type
);
413 *value
= 0; /* FIXME */
417 FIXME("Unsupported numeric leaf type %04x\n", type
);
419 *value
= 0; /* FIXME */
423 FIXME("Unsupported numeric leaf type %04x\n", type
);
425 *value
= 0; /* FIXME */
429 FIXME("Unsupported numeric leaf type %04x\n", type
);
431 *value
= 0; /* FIXME */
435 FIXME("Unsupported numeric leaf type %04x\n", type
);
437 *value
= 0; /* FIXME */
441 FIXME("Unsupported numeric leaf type %04x\n", type
);
443 *value
= 0; /* FIXME */
447 FIXME("Unsupported numeric leaf type %04x\n", type
);
449 *value
= 0; /* FIXME */
453 FIXME("Unsupported numeric leaf type %04x\n", type
);
455 *value
= 0; /* FIXME */
459 FIXME("Unsupported numeric leaf type %04x\n", type
);
461 *value
= 0; /* FIXME */
465 FIXME("Unsupported numeric leaf type %04x\n", type
);
467 *value
= 0; /* FIXME */
471 FIXME("Unknown numeric leaf type %04x\n", type
);
480 /* convert a pascal string (as stored in debug information) into
481 * a C string (null terminated).
483 static const char* terminate_string(const struct p_string
* p_name
)
485 static char symname
[256];
487 memcpy(symname
, p_name
->name
, p_name
->namelen
);
488 symname
[p_name
->namelen
] = '\0';
490 return (!*symname
|| strcmp(symname
, "__unnamed") == 0) ? NULL
: symname
;
493 static struct symt
* codeview_get_type(unsigned int typeno
, BOOL quiet
)
495 struct symt
* symt
= NULL
;
498 * Convert Codeview type numbers into something we can grok internally.
499 * Numbers < FIRST_DEFINABLE_TYPE are all fixed builtin types.
500 * Numbers from FIRST_DEFINABLE_TYPE and up are all user defined (structs, etc).
502 if (typeno
< FIRST_DEFINABLE_TYPE
)
504 if (typeno
< MAX_BUILTIN_TYPES
)
505 symt
= cv_basic_types
[typeno
];
509 unsigned mod_index
= typeno
>> 24;
510 unsigned mod_typeno
= typeno
& 0x00FFFFFF;
511 struct cv_defined_module
* mod
;
513 mod
= (mod_index
== 0) ? cv_current_module
: &cv_zmodules
[mod_index
];
515 if (mod_index
>= CV_MAX_MODULES
|| !mod
->allowed
)
516 FIXME("Module of index %d isn't loaded yet (%x)\n", mod_index
, typeno
);
519 if (mod_typeno
- FIRST_DEFINABLE_TYPE
< mod
->num_defined_types
)
520 symt
= mod
->defined_types
[mod_typeno
- FIRST_DEFINABLE_TYPE
];
523 if (!quiet
&& !symt
&& typeno
) FIXME("Returning NULL symt for type-id %x\n", typeno
);
527 struct codeview_type_parse
529 struct module
* module
;
535 static inline const void* codeview_jump_to_type(const struct codeview_type_parse
* ctp
, DWORD idx
)
537 if (idx
< FIRST_DEFINABLE_TYPE
) return NULL
;
538 idx
-= FIRST_DEFINABLE_TYPE
;
539 return (idx
>= ctp
->num
) ? NULL
: (ctp
->table
+ ctp
->offset
[idx
]);
542 static int codeview_add_type(unsigned int typeno
, struct symt
* dt
)
544 if (typeno
< FIRST_DEFINABLE_TYPE
)
545 FIXME("What the heck\n");
546 if (!cv_current_module
)
548 FIXME("Adding %x to non allowed module\n", typeno
);
551 if ((typeno
>> 24) != 0)
552 FIXME("No module index while inserting type-id assumption is wrong %x\n",
554 if (typeno
- FIRST_DEFINABLE_TYPE
>= cv_current_module
->num_defined_types
)
556 if (cv_current_module
->defined_types
)
558 cv_current_module
->num_defined_types
= max( cv_current_module
->num_defined_types
* 2,
559 typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
560 cv_current_module
->defined_types
= HeapReAlloc(GetProcessHeap(),
561 HEAP_ZERO_MEMORY
, cv_current_module
->defined_types
,
562 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
566 cv_current_module
->num_defined_types
= max( 256, typeno
- FIRST_DEFINABLE_TYPE
+ 1 );
567 cv_current_module
->defined_types
= HeapAlloc(GetProcessHeap(),
569 cv_current_module
->num_defined_types
* sizeof(struct symt
*));
571 if (cv_current_module
->defined_types
== NULL
) return FALSE
;
573 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
])
575 if (cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] != dt
)
576 FIXME("Overwriting at %x\n", typeno
);
578 cv_current_module
->defined_types
[typeno
- FIRST_DEFINABLE_TYPE
] = dt
;
582 static void codeview_clear_type_table(void)
586 for (i
= 0; i
< CV_MAX_MODULES
; i
++)
588 if (cv_zmodules
[i
].allowed
)
589 HeapFree(GetProcessHeap(), 0, cv_zmodules
[i
].defined_types
);
590 cv_zmodules
[i
].allowed
= FALSE
;
591 cv_zmodules
[i
].defined_types
= NULL
;
592 cv_zmodules
[i
].num_defined_types
= 0;
594 cv_current_module
= NULL
;
597 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
599 const union codeview_type
* type
, BOOL details
);
601 static void* codeview_cast_symt(struct symt
* symt
, enum SymTagEnum tag
)
603 if (symt
->tag
!= tag
)
605 FIXME("Bad tag. Expected %d, but got %d\n", tag
, symt
->tag
);
611 static struct symt
* codeview_fetch_type(struct codeview_type_parse
* ctp
,
612 unsigned typeno
, BOOL details
)
615 const union codeview_type
* p
;
617 if (!typeno
) return NULL
;
618 if ((symt
= codeview_get_type(typeno
, TRUE
))) return symt
;
620 /* forward declaration */
621 if (!(p
= codeview_jump_to_type(ctp
, typeno
)))
623 FIXME("Cannot locate type %x\n", typeno
);
626 symt
= codeview_parse_one_type(ctp
, typeno
, p
, details
);
627 if (!symt
) FIXME("Couldn't load forward type %x\n", typeno
);
631 static struct symt
* codeview_add_type_pointer(struct codeview_type_parse
* ctp
,
632 struct symt
* existing
,
633 unsigned int pointee_type
)
635 struct symt
* pointee
;
639 existing
= codeview_cast_symt(existing
, SymTagPointerType
);
642 pointee
= codeview_fetch_type(ctp
, pointee_type
, FALSE
);
643 return &symt_new_pointer(ctp
->module
, pointee
)->symt
;
646 static struct symt
* codeview_add_type_array(struct codeview_type_parse
* ctp
,
648 unsigned int elemtype
,
649 unsigned int indextype
,
650 unsigned int arr_len
)
652 struct symt
* elem
= codeview_fetch_type(ctp
, elemtype
, FALSE
);
653 struct symt
* index
= codeview_fetch_type(ctp
, indextype
, FALSE
);
655 return &symt_new_array(ctp
->module
, 0, -arr_len
, elem
, index
)->symt
;
658 static int codeview_add_type_enum_field_list(struct module
* module
,
659 struct symt_enum
* symt
,
660 const union codeview_reftype
* ref_type
)
662 const unsigned char* ptr
= ref_type
->fieldlist
.list
;
663 const unsigned char* last
= (const BYTE
*)ref_type
+ ref_type
->generic
.len
+ 2;
664 const union codeview_fieldtype
* type
;
668 if (*ptr
>= 0xf0) /* LF_PAD... */
674 type
= (const union codeview_fieldtype
*)ptr
;
676 switch (type
->generic
.id
)
678 case LF_ENUMERATE_V1
:
680 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v1
.value
);
681 const struct p_string
* p_name
= (const struct p_string
*)((const unsigned char*)&type
->enumerate_v1
.value
+ vlen
);
683 symt_add_enum_element(module
, symt
, terminate_string(p_name
), value
);
684 ptr
+= 2 + 2 + vlen
+ (1 + p_name
->namelen
);
687 case LF_ENUMERATE_V3
:
689 int value
, vlen
= numeric_leaf(&value
, &type
->enumerate_v3
.value
);
690 const char* name
= (const char*)&type
->enumerate_v3
.value
+ vlen
;
692 symt_add_enum_element(module
, symt
, name
, value
);
693 ptr
+= 2 + 2 + vlen
+ (1 + strlen(name
));
698 FIXME("Unsupported type %04x in ENUM field list\n", type
->generic
.id
);
705 static void codeview_add_udt_element(struct codeview_type_parse
* ctp
,
706 struct symt_udt
* symt
, const char* name
,
707 int value
, unsigned type
)
709 struct symt
* subtype
;
710 const union codeview_reftype
*cv_type
;
712 if ((cv_type
= codeview_jump_to_type(ctp
, type
)))
714 switch (cv_type
->generic
.id
)
717 symt_add_udt_element(ctp
->module
, symt
, name
,
718 codeview_fetch_type(ctp
, cv_type
->bitfield_v1
.type
, FALSE
),
719 (value
<< 3) + cv_type
->bitfield_v1
.bitoff
,
720 cv_type
->bitfield_v1
.nbits
);
723 symt_add_udt_element(ctp
->module
, symt
, name
,
724 codeview_fetch_type(ctp
, cv_type
->bitfield_v2
.type
, FALSE
),
725 (value
<< 3) + cv_type
->bitfield_v2
.bitoff
,
726 cv_type
->bitfield_v2
.nbits
);
730 subtype
= codeview_fetch_type(ctp
, type
, FALSE
);
734 DWORD64 elem_size
= 0;
735 symt_get_info(ctp
->module
, subtype
, TI_GET_LENGTH
, &elem_size
);
736 symt_add_udt_element(ctp
->module
, symt
, name
, subtype
,
737 value
<< 3, (DWORD
)elem_size
<< 3);
741 static int codeview_add_type_struct_field_list(struct codeview_type_parse
* ctp
,
742 struct symt_udt
* symt
,
743 unsigned fieldlistno
)
745 const unsigned char* ptr
;
746 const unsigned char* last
;
748 const struct p_string
* p_name
;
750 const union codeview_reftype
*type_ref
;
751 const union codeview_fieldtype
* type
;
753 if (!fieldlistno
) return TRUE
;
754 type_ref
= codeview_jump_to_type(ctp
, fieldlistno
);
755 ptr
= type_ref
->fieldlist
.list
;
756 last
= (const BYTE
*)type_ref
+ type_ref
->generic
.len
+ 2;
760 if (*ptr
>= 0xf0) /* LF_PAD... */
766 type
= (const union codeview_fieldtype
*)ptr
;
768 switch (type
->generic
.id
)
771 leaf_len
= numeric_leaf(&value
, &type
->bclass_v1
.offset
);
773 /* FIXME: ignored for now */
775 ptr
+= 2 + 2 + 2 + leaf_len
;
779 leaf_len
= numeric_leaf(&value
, &type
->bclass_v2
.offset
);
781 /* FIXME: ignored for now */
783 ptr
+= 2 + 2 + 4 + leaf_len
;
789 const unsigned short int* p_vboff
;
791 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v1
.vbpoff
);
792 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v1
.vbpoff
+ leaf_len
);
793 vplen
= numeric_leaf(&vpoff
, p_vboff
);
795 /* FIXME: ignored for now */
797 ptr
+= 2 + 2 + 2 + 2 + leaf_len
+ vplen
;
804 const unsigned short int* p_vboff
;
806 leaf_len
= numeric_leaf(&value
, &type
->vbclass_v2
.vbpoff
);
807 p_vboff
= (const unsigned short int*)((const char*)&type
->vbclass_v2
.vbpoff
+ leaf_len
);
808 vplen
= numeric_leaf(&vpoff
, p_vboff
);
810 /* FIXME: ignored for now */
812 ptr
+= 2 + 2 + 4 + 4 + leaf_len
+ vplen
;
817 leaf_len
= numeric_leaf(&value
, &type
->member_v1
.offset
);
818 p_name
= (const struct p_string
*)((const char*)&type
->member_v1
.offset
+ leaf_len
);
820 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
821 type
->member_v1
.type
);
823 ptr
+= 2 + 2 + 2 + leaf_len
+ (1 + p_name
->namelen
);
827 leaf_len
= numeric_leaf(&value
, &type
->member_v2
.offset
);
828 p_name
= (const struct p_string
*)((const unsigned char*)&type
->member_v2
.offset
+ leaf_len
);
830 codeview_add_udt_element(ctp
, symt
, terminate_string(p_name
), value
,
831 type
->member_v2
.type
);
833 ptr
+= 2 + 2 + 4 + leaf_len
+ (1 + p_name
->namelen
);
837 leaf_len
= numeric_leaf(&value
, &type
->member_v3
.offset
);
838 c_name
= (const char*)&type
->member_v3
.offset
+ leaf_len
;
840 codeview_add_udt_element(ctp
, symt
, c_name
, value
, type
->member_v3
.type
);
842 ptr
+= 2 + 2 + 4 + leaf_len
+ (strlen(c_name
) + 1);
846 /* FIXME: ignored for now */
847 ptr
+= 2 + 2 + 2 + (1 + type
->stmember_v1
.p_name
.namelen
);
851 /* FIXME: ignored for now */
852 ptr
+= 2 + 4 + 2 + (1 + type
->stmember_v2
.p_name
.namelen
);
856 /* FIXME: ignored for now */
857 ptr
+= 2 + 4 + 2 + (strlen(type
->stmember_v3
.name
) + 1);
861 /* FIXME: ignored for now */
862 ptr
+= 2 + 2 + 2 + (1 + type
->method_v1
.p_name
.namelen
);
866 /* FIXME: ignored for now */
867 ptr
+= 2 + 2 + 4 + (1 + type
->method_v2
.p_name
.namelen
);
871 /* FIXME: ignored for now */
872 ptr
+= 2 + 2 + 4 + (strlen(type
->method_v3
.name
) + 1);
876 /* FIXME: ignored for now */
877 ptr
+= 2 + 2 + (1 + type
->nesttype_v1
.p_name
.namelen
);
881 /* FIXME: ignored for now */
882 ptr
+= 2 + 2 + 4 + (1 + type
->nesttype_v2
.p_name
.namelen
);
886 /* FIXME: ignored for now */
887 ptr
+= 2 + 2 + 4 + (strlen(type
->nesttype_v3
.name
) + 1);
891 /* FIXME: ignored for now */
896 /* FIXME: ignored for now */
900 case LF_ONEMETHOD_V1
:
901 /* FIXME: ignored for now */
902 switch ((type
->onemethod_v1
.attribute
>> 2) & 7)
904 case 4: case 6: /* (pure) introducing virtual method */
905 ptr
+= 2 + 2 + 2 + 4 + (1 + type
->onemethod_virt_v1
.p_name
.namelen
);
909 ptr
+= 2 + 2 + 2 + (1 + type
->onemethod_v1
.p_name
.namelen
);
914 case LF_ONEMETHOD_V2
:
915 /* FIXME: ignored for now */
916 switch ((type
->onemethod_v2
.attribute
>> 2) & 7)
918 case 4: case 6: /* (pure) introducing virtual method */
919 ptr
+= 2 + 2 + 4 + 4 + (1 + type
->onemethod_virt_v2
.p_name
.namelen
);
923 ptr
+= 2 + 2 + 4 + (1 + type
->onemethod_v2
.p_name
.namelen
);
928 case LF_ONEMETHOD_V3
:
929 /* FIXME: ignored for now */
930 switch ((type
->onemethod_v3
.attribute
>> 2) & 7)
932 case 4: case 6: /* (pure) introducing virtual method */
933 ptr
+= 2 + 2 + 4 + 4 + (strlen(type
->onemethod_virt_v3
.name
) + 1);
937 ptr
+= 2 + 2 + 4 + (strlen(type
->onemethod_v3
.name
) + 1);
943 FIXME("Unsupported type %04x in STRUCT field list\n", type
->generic
.id
);
951 static struct symt
* codeview_add_type_enum(struct codeview_type_parse
* ctp
,
952 struct symt
* existing
,
954 unsigned fieldlistno
,
957 struct symt_enum
* symt
;
961 if (!(symt
= codeview_cast_symt(existing
, SymTagEnum
))) return NULL
;
962 /* should also check that all fields are the same */
966 symt
= symt_new_enum(ctp
->module
, name
,
967 codeview_fetch_type(ctp
, basetype
, FALSE
));
970 const union codeview_reftype
* fieldlist
;
971 fieldlist
= codeview_jump_to_type(ctp
, fieldlistno
);
972 codeview_add_type_enum_field_list(ctp
->module
, symt
, fieldlist
);
978 static struct symt
* codeview_add_type_struct(struct codeview_type_parse
* ctp
,
979 struct symt
* existing
,
980 const char* name
, int structlen
,
981 enum UdtKind kind
, unsigned property
)
983 struct symt_udt
* symt
;
985 /* if we don't have an existing type, try to find one with same name
986 * FIXME: what to do when several types in different CUs have same name ?
991 struct symt_ht
* type
;
992 struct hash_table_iter hti
;
994 hash_table_iter_init(&ctp
->module
->ht_types
, &hti
, name
);
995 while ((ptr
= hash_table_iter_up(&hti
)))
997 type
= GET_ENTRY(ptr
, struct symt_ht
, hash_elt
);
999 if (type
->symt
.tag
== SymTagUDT
&&
1000 type
->hash_elt
.name
&& !strcmp(type
->hash_elt
.name
, name
))
1002 existing
= &type
->symt
;
1009 if (!(symt
= codeview_cast_symt(existing
, SymTagUDT
))) return NULL
;
1010 /* should also check that all fields are the same */
1011 if (!(property
& 0x80)) /* 0x80 = forward declaration */
1013 if (!symt
->size
) /* likely prior forward declaration, set UDT size */
1014 symt_set_udt_size(ctp
->module
, symt
, structlen
);
1015 else /* different UDT with same name, create a new type */
1019 if (!existing
) symt
= symt_new_udt(ctp
->module
, name
, structlen
, kind
);
1024 static struct symt
* codeview_new_func_signature(struct codeview_type_parse
* ctp
,
1025 struct symt
* existing
,
1026 enum CV_call_e call_conv
)
1028 struct symt_function_signature
* sym
;
1032 sym
= codeview_cast_symt(existing
, SymTagFunctionType
);
1033 if (!sym
) return NULL
;
1037 sym
= symt_new_function_signature(ctp
->module
, NULL
, call_conv
);
1042 static void codeview_add_func_signature_args(struct codeview_type_parse
* ctp
,
1043 struct symt_function_signature
* sym
,
1047 const union codeview_reftype
* reftype
;
1049 sym
->rettype
= codeview_fetch_type(ctp
, ret_type
, FALSE
);
1050 if (args_list
&& (reftype
= codeview_jump_to_type(ctp
, args_list
)))
1053 switch (reftype
->generic
.id
)
1056 for (i
= 0; i
< reftype
->arglist_v1
.num
; i
++)
1057 symt_add_function_signature_parameter(ctp
->module
, sym
,
1058 codeview_fetch_type(ctp
, reftype
->arglist_v1
.args
[i
], FALSE
));
1061 for (i
= 0; i
< reftype
->arglist_v2
.num
; i
++)
1062 symt_add_function_signature_parameter(ctp
->module
, sym
,
1063 codeview_fetch_type(ctp
, reftype
->arglist_v2
.args
[i
], FALSE
));
1066 FIXME("Unexpected leaf %x for signature's pmt\n", reftype
->generic
.id
);
1071 static struct symt
* codeview_parse_one_type(struct codeview_type_parse
* ctp
,
1073 const union codeview_type
* type
, BOOL details
)
1076 int value
, leaf_len
;
1077 const struct p_string
* p_name
;
1079 struct symt
* existing
;
1081 existing
= codeview_get_type(curr_type
, TRUE
);
1083 switch (type
->generic
.id
)
1085 case LF_MODIFIER_V1
:
1086 /* FIXME: we don't handle modifiers,
1087 * but read previous type on the curr_type
1089 WARN("Modifier on %x: %s%s%s%s\n",
1090 type
->modifier_v1
.type
,
1091 type
->modifier_v1
.attribute
& 0x01 ? "const " : "",
1092 type
->modifier_v1
.attribute
& 0x02 ? "volatile " : "",
1093 type
->modifier_v1
.attribute
& 0x04 ? "unaligned " : "",
1094 type
->modifier_v1
.attribute
& ~0x07 ? "unknown " : "");
1095 symt
= codeview_fetch_type(ctp
, type
->modifier_v1
.type
, details
);
1097 case LF_MODIFIER_V2
:
1098 /* FIXME: we don't handle modifiers, but readd previous type on the curr_type */
1099 WARN("Modifier on %x: %s%s%s%s\n",
1100 type
->modifier_v2
.type
,
1101 type
->modifier_v2
.attribute
& 0x01 ? "const " : "",
1102 type
->modifier_v2
.attribute
& 0x02 ? "volatile " : "",
1103 type
->modifier_v2
.attribute
& 0x04 ? "unaligned " : "",
1104 type
->modifier_v2
.attribute
& ~0x07 ? "unknown " : "");
1105 symt
= codeview_fetch_type(ctp
, type
->modifier_v2
.type
, details
);
1109 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v1
.datatype
);
1112 symt
= codeview_add_type_pointer(ctp
, existing
, type
->pointer_v2
.datatype
);
1116 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1119 leaf_len
= numeric_leaf(&value
, &type
->array_v1
.arrlen
);
1120 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v1
.arrlen
+ leaf_len
);
1121 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1122 type
->array_v1
.elemtype
,
1123 type
->array_v1
.idxtype
, value
);
1127 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1130 leaf_len
= numeric_leaf(&value
, &type
->array_v2
.arrlen
);
1131 p_name
= (const struct p_string
*)((const unsigned char*)&type
->array_v2
.arrlen
+ leaf_len
);
1133 symt
= codeview_add_type_array(ctp
, terminate_string(p_name
),
1134 type
->array_v2
.elemtype
,
1135 type
->array_v2
.idxtype
, value
);
1139 if (existing
) symt
= codeview_cast_symt(existing
, SymTagArrayType
);
1142 leaf_len
= numeric_leaf(&value
, &type
->array_v3
.arrlen
);
1143 c_name
= (const char*)&type
->array_v3
.arrlen
+ leaf_len
;
1145 symt
= codeview_add_type_array(ctp
, c_name
,
1146 type
->array_v3
.elemtype
,
1147 type
->array_v3
.idxtype
, value
);
1151 case LF_STRUCTURE_V1
:
1153 leaf_len
= numeric_leaf(&value
, &type
->struct_v1
.structlen
);
1154 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v1
.structlen
+ leaf_len
);
1155 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1156 type
->generic
.id
== LF_CLASS_V1
? UdtClass
: UdtStruct
,
1157 type
->struct_v1
.property
);
1160 codeview_add_type(curr_type
, symt
);
1161 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1162 type
->struct_v1
.fieldlist
);
1166 case LF_STRUCTURE_V2
:
1168 leaf_len
= numeric_leaf(&value
, &type
->struct_v2
.structlen
);
1169 p_name
= (const struct p_string
*)((const unsigned char*)&type
->struct_v2
.structlen
+ leaf_len
);
1170 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
), value
,
1171 type
->generic
.id
== LF_CLASS_V2
? UdtClass
: UdtStruct
,
1172 type
->struct_v2
.property
);
1175 codeview_add_type(curr_type
, symt
);
1176 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1177 type
->struct_v2
.fieldlist
);
1181 case LF_STRUCTURE_V3
:
1183 leaf_len
= numeric_leaf(&value
, &type
->struct_v3
.structlen
);
1184 c_name
= (const char*)&type
->struct_v3
.structlen
+ leaf_len
;
1185 symt
= codeview_add_type_struct(ctp
, existing
, c_name
, value
,
1186 type
->generic
.id
== LF_CLASS_V3
? UdtClass
: UdtStruct
,
1187 type
->struct_v3
.property
);
1190 codeview_add_type(curr_type
, symt
);
1191 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1192 type
->struct_v3
.fieldlist
);
1197 leaf_len
= numeric_leaf(&value
, &type
->union_v1
.un_len
);
1198 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v1
.un_len
+ leaf_len
);
1199 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1200 value
, UdtUnion
, type
->union_v1
.property
);
1203 codeview_add_type(curr_type
, symt
);
1204 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1205 type
->union_v1
.fieldlist
);
1210 leaf_len
= numeric_leaf(&value
, &type
->union_v2
.un_len
);
1211 p_name
= (const struct p_string
*)((const unsigned char*)&type
->union_v2
.un_len
+ leaf_len
);
1212 symt
= codeview_add_type_struct(ctp
, existing
, terminate_string(p_name
),
1213 value
, UdtUnion
, type
->union_v2
.property
);
1216 codeview_add_type(curr_type
, symt
);
1217 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1218 type
->union_v2
.fieldlist
);
1223 leaf_len
= numeric_leaf(&value
, &type
->union_v3
.un_len
);
1224 c_name
= (const char*)&type
->union_v3
.un_len
+ leaf_len
;
1225 symt
= codeview_add_type_struct(ctp
, existing
, c_name
,
1226 value
, UdtUnion
, type
->union_v3
.property
);
1229 codeview_add_type(curr_type
, symt
);
1230 codeview_add_type_struct_field_list(ctp
, (struct symt_udt
*)symt
,
1231 type
->union_v3
.fieldlist
);
1236 symt
= codeview_add_type_enum(ctp
, existing
,
1237 terminate_string(&type
->enumeration_v1
.p_name
),
1238 type
->enumeration_v1
.fieldlist
,
1239 type
->enumeration_v1
.type
);
1243 symt
= codeview_add_type_enum(ctp
, existing
,
1244 terminate_string(&type
->enumeration_v2
.p_name
),
1245 type
->enumeration_v2
.fieldlist
,
1246 type
->enumeration_v2
.type
);
1250 symt
= codeview_add_type_enum(ctp
, existing
, type
->enumeration_v3
.name
,
1251 type
->enumeration_v3
.fieldlist
,
1252 type
->enumeration_v3
.type
);
1255 case LF_PROCEDURE_V1
:
1256 symt
= codeview_new_func_signature(ctp
, existing
, type
->procedure_v1
.call
);
1259 codeview_add_type(curr_type
, symt
);
1260 codeview_add_func_signature_args(ctp
,
1261 (struct symt_function_signature
*)symt
,
1262 type
->procedure_v1
.rvtype
,
1263 type
->procedure_v1
.arglist
);
1266 case LF_PROCEDURE_V2
:
1267 symt
= codeview_new_func_signature(ctp
, existing
,type
->procedure_v2
.call
);
1270 codeview_add_type(curr_type
, symt
);
1271 codeview_add_func_signature_args(ctp
,
1272 (struct symt_function_signature
*)symt
,
1273 type
->procedure_v2
.rvtype
,
1274 type
->procedure_v2
.arglist
);
1278 case LF_MFUNCTION_V1
:
1279 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1280 * nor class information, this would just do for now
1282 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v1
.call
);
1285 codeview_add_type(curr_type
, symt
);
1286 codeview_add_func_signature_args(ctp
,
1287 (struct symt_function_signature
*)symt
,
1288 type
->mfunction_v1
.rvtype
,
1289 type
->mfunction_v1
.arglist
);
1292 case LF_MFUNCTION_V2
:
1293 /* FIXME: for C++, this is plain wrong, but as we don't use arg types
1294 * nor class information, this would just do for now
1296 symt
= codeview_new_func_signature(ctp
, existing
, type
->mfunction_v2
.call
);
1299 codeview_add_type(curr_type
, symt
);
1300 codeview_add_func_signature_args(ctp
,
1301 (struct symt_function_signature
*)symt
,
1302 type
->mfunction_v2
.rvtype
,
1303 type
->mfunction_v2
.arglist
);
1308 /* this is an ugly hack... FIXME when we have C++ support */
1309 if (!(symt
= existing
))
1312 snprintf(buf
, sizeof(buf
), "__internal_vt_shape_%x\n", curr_type
);
1313 symt
= &symt_new_udt(ctp
->module
, buf
, 0, UdtStruct
)->symt
;
1317 FIXME("Unsupported type-id leaf %x\n", type
->generic
.id
);
1318 dump(type
, 2 + type
->generic
.len
);
1321 return codeview_add_type(curr_type
, symt
) ? symt
: NULL
;
1324 static int codeview_parse_type_table(struct codeview_type_parse
* ctp
)
1326 unsigned int curr_type
= FIRST_DEFINABLE_TYPE
;
1327 const union codeview_type
* type
;
1329 for (curr_type
= FIRST_DEFINABLE_TYPE
; curr_type
< FIRST_DEFINABLE_TYPE
+ ctp
->num
; curr_type
++)
1331 type
= codeview_jump_to_type(ctp
, curr_type
);
1333 /* type records we're interested in are the ones referenced by symbols
1334 * The known ranges are (X mark the ones we want):
1335 * X 0000-0016 for V1 types
1336 * 0200-020c for V1 types referenced by other types
1337 * 0400-040f for V1 types (complex lists & sets)
1338 * X 1000-100f for V2 types
1339 * 1200-120c for V2 types referenced by other types
1340 * 1400-140f for V1 types (complex lists & sets)
1341 * X 1500-150d for V3 types
1342 * 8000-8010 for numeric leafes
1344 if (!(type
->generic
.id
& 0x8600) || (type
->generic
.id
& 0x0100))
1345 codeview_parse_one_type(ctp
, curr_type
, type
, TRUE
);
1351 /*========================================================================
1352 * Process CodeView line number information.
1354 static unsigned long codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1355 unsigned seg
, unsigned offset
);
1357 static void codeview_snarf_linetab(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
,
1358 int size
, BOOL pascal_str
)
1360 const BYTE
* ptr
= linetab
;
1363 const unsigned int* filetab
;
1364 const unsigned int* lt_ptr
;
1365 const unsigned short* linenos
;
1366 const struct startend
* start
;
1368 unsigned long addr
, func_addr0
;
1369 struct symt_function
* func
;
1370 const struct codeview_linetab_block
* ltb
;
1372 nfile
= *(const short*)linetab
;
1373 filetab
= (const unsigned int*)(linetab
+ 2 * sizeof(short));
1375 for (i
= 0; i
< nfile
; i
++)
1377 ptr
= linetab
+ filetab
[i
];
1378 nseg
= *(const short*)ptr
;
1379 lt_ptr
= (const unsigned int*)(ptr
+ 2 * sizeof(short));
1380 start
= (const struct startend
*)(lt_ptr
+ nseg
);
1383 * Now snarf the filename for all of the segments for this file.
1386 source
= source_new(msc_dbg
->module
, NULL
, terminate_string((const struct p_string
*)(start
+ nseg
)));
1388 source
= source_new(msc_dbg
->module
, NULL
, (const char*)(start
+ nseg
));
1390 for (j
= 0; j
< nseg
; j
++)
1392 ltb
= (const struct codeview_linetab_block
*)(linetab
+ *lt_ptr
++);
1393 linenos
= (const unsigned short*)<b
->offsets
[ltb
->num_lines
];
1394 func_addr0
= codeview_get_address(msc_dbg
, ltb
->seg
, start
[j
].start
);
1395 if (!func_addr0
) continue;
1396 for (func
= NULL
, k
= 0; k
< ltb
->num_lines
; k
++)
1398 /* now locate function (if any) */
1399 addr
= func_addr0
+ ltb
->offsets
[k
] - start
[j
].start
;
1400 /* unfortunetaly, we can have several functions in the same block, if there's no
1401 * gap between them... find the new function if needed
1403 if (!func
|| addr
>= func
->address
+ func
->size
)
1405 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1406 /* FIXME: at least labels support line numbers */
1407 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1409 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1410 ltb
->seg
, ltb
->offsets
[k
], addr
, func
? func
->symt
.tag
: -1);
1415 symt_add_func_line(msc_dbg
->module
, func
, source
,
1416 linenos
[k
], addr
- func
->address
);
1422 static void codeview_snarf_linetab2(const struct msc_debug_info
* msc_dbg
, const BYTE
* linetab
, DWORD size
,
1423 const char* strimage
, DWORD strsize
)
1427 const struct codeview_linetab2
* lt2
;
1428 const struct codeview_linetab2
* lt2_files
= NULL
;
1429 const struct codeview_lt2blk_lines
* lines_blk
;
1430 const struct codeview_linetab2_file
*fd
;
1432 struct symt_function
* func
;
1434 /* locate LT2_FILES_BLOCK (if any) */
1435 lt2
= (const struct codeview_linetab2
*)linetab
;
1436 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1438 if (lt2
->header
== LT2_FILES_BLOCK
)
1443 lt2
= codeview_linetab2_next_block(lt2
);
1447 TRACE("No LT2_FILES_BLOCK found\n");
1451 lt2
= (const struct codeview_linetab2
*)linetab
;
1452 while ((const BYTE
*)(lt2
+ 1) < linetab
+ size
)
1454 /* FIXME: should also check that whole lines_blk fits in linetab + size */
1455 switch (lt2
->header
)
1457 case LT2_LINES_BLOCK
:
1458 lines_blk
= (const struct codeview_lt2blk_lines
*)lt2
;
1459 /* FIXME: should check that file_offset is within the LT2_FILES_BLOCK we've seen */
1460 addr
= codeview_get_address(msc_dbg
, lines_blk
->seg
, lines_blk
->start
);
1461 TRACE("block from %04x:%08x #%x (%x lines)\n",
1462 lines_blk
->seg
, lines_blk
->start
, lines_blk
->size
, lines_blk
->nlines
);
1463 fd
= (const struct codeview_linetab2_file
*)((const char*)lt2_files
+ 8 + lines_blk
->file_offset
);
1464 /* FIXME: should check that string is within strimage + strsize */
1465 source
= source_new(msc_dbg
->module
, NULL
, strimage
+ fd
->offset
);
1466 func
= (struct symt_function
*)symt_find_nearest(msc_dbg
->module
, addr
);
1467 /* FIXME: at least labels support line numbers */
1468 if (!func
|| func
->symt
.tag
!= SymTagFunction
)
1470 WARN("--not a func at %04x:%08x %lx tag=%d\n",
1471 lines_blk
->seg
, lines_blk
->start
, addr
, func
? func
->symt
.tag
: -1);
1474 for (i
= 0; i
< lines_blk
->nlines
; i
++)
1476 symt_add_func_line(msc_dbg
->module
, func
, source
,
1477 lines_blk
->l
[i
].lineno
^ 0x80000000,
1478 lines_blk
->l
[i
].offset
);
1481 case LT2_FILES_BLOCK
: /* skip */
1484 TRACE("Block end %x\n", lt2
->header
);
1485 lt2
= (const struct codeview_linetab2
*)((const char*)linetab
+ size
);
1488 lt2
= codeview_linetab2_next_block(lt2
);
1492 /*========================================================================
1493 * Process CodeView symbol information.
1496 static unsigned int codeview_map_offset(const struct msc_debug_info
* msc_dbg
,
1497 unsigned int offset
)
1499 int nomap
= msc_dbg
->nomap
;
1500 const OMAP_DATA
* omapp
= msc_dbg
->omapp
;
1503 if (!nomap
|| !omapp
) return offset
;
1505 /* FIXME: use binary search */
1506 for (i
= 0; i
< nomap
- 1; i
++)
1507 if (omapp
[i
].from
<= offset
&& omapp
[i
+1].from
> offset
)
1508 return !omapp
[i
].to
? 0 : omapp
[i
].to
+ (offset
- omapp
[i
].from
);
1513 static unsigned long codeview_get_address(const struct msc_debug_info
* msc_dbg
,
1514 unsigned seg
, unsigned offset
)
1516 int nsect
= msc_dbg
->nsect
;
1517 const IMAGE_SECTION_HEADER
* sectp
= msc_dbg
->sectp
;
1519 if (!seg
|| seg
> nsect
) return 0;
1520 return msc_dbg
->module
->module
.BaseOfImage
+
1521 codeview_map_offset(msc_dbg
, sectp
[seg
-1].VirtualAddress
+ offset
);
1524 static inline void codeview_add_variable(const struct msc_debug_info
* msc_dbg
,
1525 struct symt_compiland
* compiland
,
1527 unsigned segment
, unsigned offset
,
1528 unsigned symtype
, BOOL is_local
, BOOL force
)
1532 unsigned long address
= codeview_get_address(msc_dbg
, segment
, offset
);
1534 if (force
|| !symt_find_nearest(msc_dbg
->module
, address
))
1536 symt_new_global_variable(msc_dbg
->module
, compiland
,
1537 name
, is_local
, address
, 0,
1538 codeview_get_type(symtype
, FALSE
));
1543 static int codeview_snarf(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1544 int offset
, int size
, BOOL do_globals
)
1546 struct symt_function
* curr_func
= NULL
;
1548 struct symt_block
* block
= NULL
;
1551 struct symt_compiland
* compiland
= NULL
;
1552 struct location loc
;
1555 * Loop over the different types of records and whenever we
1556 * find something we are interested in, record it and move on.
1558 for (i
= offset
; i
< size
; i
+= length
)
1560 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1561 length
= sym
->generic
.len
+ 2;
1562 if (i
+ length
> size
) break;
1563 if (!sym
->generic
.id
|| length
< 4) break;
1564 if (length
& 3) FIXME("unpadded len %u\n", length
);
1566 switch (sym
->generic
.id
)
1569 * Global and local data symbols. We don't associate these
1570 * with any given source file.
1575 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
1576 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
1577 sym
->generic
.id
== S_LDATA_V1
, TRUE
);
1582 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
1583 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
1584 sym
->generic
.id
== S_LDATA_V2
, TRUE
);
1589 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
1590 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
1591 sym
->generic
.id
== S_LDATA_V3
, TRUE
);
1594 /* Public symbols */
1598 case S_PUB_FUNC1_V3
:
1599 case S_PUB_FUNC2_V3
:
1600 /* will be handled later on in codeview_snarf_public */
1604 * Sort of like a global function, but it just points
1605 * to a thunk, which is a stupid name for what amounts to
1606 * a PLT slot in the normal jargon that everyone else uses.
1609 symt_new_thunk(msc_dbg
->module
, compiland
,
1610 terminate_string(&sym
->thunk_v1
.p_name
), sym
->thunk_v1
.thtype
,
1611 codeview_get_address(msc_dbg
, sym
->thunk_v1
.segment
, sym
->thunk_v1
.offset
),
1612 sym
->thunk_v1
.thunk_len
);
1615 symt_new_thunk(msc_dbg
->module
, compiland
,
1616 sym
->thunk_v3
.name
, sym
->thunk_v3
.thtype
,
1617 codeview_get_address(msc_dbg
, sym
->thunk_v3
.segment
, sym
->thunk_v3
.offset
),
1618 sym
->thunk_v3
.thunk_len
);
1622 * Global and static functions.
1626 if (curr_func
) FIXME("nested function\n");
1627 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1628 terminate_string(&sym
->proc_v1
.p_name
),
1629 codeview_get_address(msc_dbg
, sym
->proc_v1
.segment
, sym
->proc_v1
.offset
),
1630 sym
->proc_v1
.proc_len
,
1631 codeview_get_type(sym
->proc_v1
.proctype
, FALSE
));
1632 loc
.kind
= loc_absolute
;
1633 loc
.offset
= sym
->proc_v1
.debug_start
;
1634 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1635 loc
.offset
= sym
->proc_v1
.debug_end
;
1636 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1640 if (curr_func
) FIXME("nested function\n");
1641 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1642 terminate_string(&sym
->proc_v2
.p_name
),
1643 codeview_get_address(msc_dbg
, sym
->proc_v2
.segment
, sym
->proc_v2
.offset
),
1644 sym
->proc_v2
.proc_len
,
1645 codeview_get_type(sym
->proc_v2
.proctype
, FALSE
));
1646 loc
.kind
= loc_absolute
;
1647 loc
.offset
= sym
->proc_v2
.debug_start
;
1648 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1649 loc
.offset
= sym
->proc_v2
.debug_end
;
1650 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1654 if (curr_func
) FIXME("nested function\n");
1655 curr_func
= symt_new_function(msc_dbg
->module
, compiland
,
1657 codeview_get_address(msc_dbg
, sym
->proc_v3
.segment
, sym
->proc_v3
.offset
),
1658 sym
->proc_v3
.proc_len
,
1659 codeview_get_type(sym
->proc_v3
.proctype
, FALSE
));
1660 loc
.kind
= loc_absolute
;
1661 loc
.offset
= sym
->proc_v3
.debug_start
;
1662 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugStart
, &loc
, NULL
);
1663 loc
.offset
= sym
->proc_v3
.debug_end
;
1664 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagFuncDebugEnd
, &loc
, NULL
);
1667 * Function parameters and stack variables.
1670 loc
.kind
= loc_regrel
;
1671 loc
.reg
= 0; /* FIXME */
1672 loc
.offset
= sym
->stack_v1
.offset
;
1673 symt_add_func_local(msc_dbg
->module
, curr_func
,
1674 sym
->stack_v1
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1676 codeview_get_type(sym
->stack_v1
.symtype
, FALSE
),
1677 terminate_string(&sym
->stack_v1
.p_name
));
1680 loc
.kind
= loc_regrel
;
1681 loc
.reg
= 0; /* FIXME */
1682 loc
.offset
= sym
->stack_v2
.offset
;
1683 symt_add_func_local(msc_dbg
->module
, curr_func
,
1684 sym
->stack_v2
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1686 codeview_get_type(sym
->stack_v2
.symtype
, FALSE
),
1687 terminate_string(&sym
->stack_v2
.p_name
));
1690 loc
.kind
= loc_regrel
;
1691 loc
.reg
= 0; /* FIXME */
1692 loc
.offset
= sym
->stack_v3
.offset
;
1693 symt_add_func_local(msc_dbg
->module
, curr_func
,
1694 sym
->stack_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1696 codeview_get_type(sym
->stack_v3
.symtype
, FALSE
),
1697 sym
->stack_v3
.name
);
1700 loc
.kind
= loc_regrel
;
1701 loc
.reg
= sym
->regrel_v3
.reg
;
1702 loc
.offset
= sym
->regrel_v3
.offset
;
1703 symt_add_func_local(msc_dbg
->module
, curr_func
,
1704 /* FIXME this is wrong !!! */
1705 sym
->regrel_v3
.offset
> 0 ? DataIsParam
: DataIsLocal
,
1707 codeview_get_type(sym
->regrel_v3
.symtype
, FALSE
),
1708 sym
->regrel_v3
.name
);
1712 loc
.kind
= loc_register
;
1713 loc
.reg
= sym
->register_v1
.reg
;
1715 symt_add_func_local(msc_dbg
->module
, curr_func
,
1717 block
, codeview_get_type(sym
->register_v1
.type
, FALSE
),
1718 terminate_string(&sym
->register_v1
.p_name
));
1721 loc
.kind
= loc_register
;
1722 loc
.reg
= sym
->register_v2
.reg
;
1724 symt_add_func_local(msc_dbg
->module
, curr_func
,
1726 block
, codeview_get_type(sym
->register_v2
.type
, FALSE
),
1727 terminate_string(&sym
->register_v2
.p_name
));
1730 loc
.kind
= loc_register
;
1731 loc
.reg
= sym
->register_v3
.reg
;
1733 symt_add_func_local(msc_dbg
->module
, curr_func
,
1735 block
, codeview_get_type(sym
->register_v3
.type
, FALSE
),
1736 sym
->register_v3
.name
);
1740 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1741 codeview_get_address(msc_dbg
, sym
->block_v1
.segment
, sym
->block_v1
.offset
),
1742 sym
->block_v1
.length
);
1745 block
= symt_open_func_block(msc_dbg
->module
, curr_func
, block
,
1746 codeview_get_address(msc_dbg
, sym
->block_v3
.segment
, sym
->block_v3
.offset
),
1747 sym
->block_v3
.length
);
1753 block
= symt_close_func_block(msc_dbg
->module
, curr_func
, block
, 0);
1757 symt_normalize_function(msc_dbg
->module
, curr_func
);
1762 case S_COMPILAND_V1
:
1763 TRACE("S-Compiland-V1 %x %s\n",
1764 sym
->compiland_v1
.unknown
, terminate_string(&sym
->compiland_v1
.p_name
));
1767 case S_COMPILAND_V2
:
1768 TRACE("S-Compiland-V2 %s\n", terminate_string(&sym
->compiland_v2
.p_name
));
1769 if (TRACE_ON(dbghelp_msc
))
1771 const char* ptr1
= sym
->compiland_v2
.p_name
.name
+ sym
->compiland_v2
.p_name
.namelen
;
1775 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1776 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1777 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1781 case S_COMPILAND_V3
:
1782 TRACE("S-Compiland-V3 %s\n", sym
->compiland_v3
.name
);
1783 if (TRACE_ON(dbghelp_msc
))
1785 const char* ptr1
= sym
->compiland_v3
.name
+ strlen(sym
->compiland_v3
.name
);
1789 ptr2
= ptr1
+ strlen(ptr1
) + 1;
1790 TRACE("\t%s => %s\n", ptr1
, debugstr_a(ptr2
));
1791 ptr1
= ptr2
+ strlen(ptr2
) + 1;
1797 TRACE("S-ObjName %s\n", terminate_string(&sym
->objname_v1
.p_name
));
1798 compiland
= symt_new_compiland(msc_dbg
->module
, 0 /* FIXME */,
1799 source_new(msc_dbg
->module
, NULL
,
1800 terminate_string(&sym
->objname_v1
.p_name
)));
1806 loc
.kind
= loc_absolute
;
1807 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
) - curr_func
->address
;
1808 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
, &loc
,
1809 terminate_string(&sym
->label_v1
.p_name
));
1811 else symt_new_label(msc_dbg
->module
, compiland
,
1812 terminate_string(&sym
->label_v1
.p_name
),
1813 codeview_get_address(msc_dbg
, sym
->label_v1
.segment
, sym
->label_v1
.offset
));
1818 loc
.kind
= loc_absolute
;
1819 loc
.offset
= codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
) - curr_func
->address
;
1820 symt_add_function_point(msc_dbg
->module
, curr_func
, SymTagLabel
,
1821 &loc
, sym
->label_v3
.name
);
1823 else symt_new_label(msc_dbg
->module
, compiland
, sym
->label_v3
.name
,
1824 codeview_get_address(msc_dbg
, sym
->label_v3
.segment
, sym
->label_v3
.offset
));
1830 const struct p_string
* name
;
1834 vlen
= leaf_as_variant(&v
, &sym
->constant_v1
.cvalue
);
1835 name
= (const struct p_string
*)((const char*)&sym
->constant_v1
.cvalue
+ vlen
);
1836 se
= codeview_get_type(sym
->constant_v1
.type
, FALSE
);
1838 TRACE("S-Constant-V1 %u %s %x\n",
1839 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v1
.type
);
1840 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1847 const struct p_string
* name
;
1851 vlen
= leaf_as_variant(&v
, &sym
->constant_v2
.cvalue
);
1852 name
= (const struct p_string
*)((const char*)&sym
->constant_v2
.cvalue
+ vlen
);
1853 se
= codeview_get_type(sym
->constant_v2
.type
, FALSE
);
1855 TRACE("S-Constant-V2 %u %s %x\n",
1856 v
.n1
.n2
.n3
.intVal
, terminate_string(name
), sym
->constant_v2
.type
);
1857 symt_new_constant(msc_dbg
->module
, compiland
, terminate_string(name
),
1868 vlen
= leaf_as_variant(&v
, &sym
->constant_v3
.cvalue
);
1869 name
= (const char*)&sym
->constant_v3
.cvalue
+ vlen
;
1870 se
= codeview_get_type(sym
->constant_v3
.type
, FALSE
);
1872 TRACE("S-Constant-V3 %u %s %x\n",
1873 v
.n1
.n2
.n3
.intVal
, name
, sym
->constant_v3
.type
);
1874 /* FIXME: we should add this as a constant value */
1875 symt_new_constant(msc_dbg
->module
, compiland
, name
, se
, &v
);
1880 if (sym
->udt_v1
.type
)
1882 if ((symt
= codeview_get_type(sym
->udt_v1
.type
, FALSE
)))
1883 symt_new_typedef(msc_dbg
->module
, symt
,
1884 terminate_string(&sym
->udt_v1
.p_name
));
1886 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1887 terminate_string(&sym
->udt_v1
.p_name
), sym
->udt_v1
.type
);
1891 if (sym
->udt_v2
.type
)
1893 if ((symt
= codeview_get_type(sym
->udt_v2
.type
, FALSE
)))
1894 symt_new_typedef(msc_dbg
->module
, symt
,
1895 terminate_string(&sym
->udt_v2
.p_name
));
1897 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1898 terminate_string(&sym
->udt_v2
.p_name
), sym
->udt_v2
.type
);
1902 if (sym
->udt_v3
.type
)
1904 if ((symt
= codeview_get_type(sym
->udt_v3
.type
, FALSE
)))
1905 symt_new_typedef(msc_dbg
->module
, symt
, sym
->udt_v3
.name
);
1907 FIXME("S-Udt %s: couldn't find type 0x%x\n",
1908 sym
->udt_v3
.name
, sym
->udt_v3
.type
);
1913 * These are special, in that they are always followed by an
1914 * additional length-prefixed string which is *not* included
1915 * into the symbol length count. We need to skip it.
1920 name
= (const char*)sym
+ length
;
1921 length
+= (*name
+ 1 + 3) & ~3;
1924 case S_MSTOOL_V3
: /* just to silence a few warnings */
1925 case S_MSTOOLINFO_V3
:
1926 case S_MSTOOLENV_V3
:
1930 TRACE("Start search: seg=0x%x at offset 0x%08x\n",
1931 sym
->ssearch_v1
.segment
, sym
->ssearch_v1
.offset
);
1935 TRACE("S-Align V1\n");
1938 /* the symbols we can safely ignore for now */
1941 case S_SECUCOOKIE_V3
:
1943 case S_SUBSECTINFO_V3
:
1944 case S_ENTRYPOINT_V3
:
1946 TRACE("Unsupported symbol id %x\n", sym
->generic
.id
);
1950 FIXME("Unsupported symbol id %x\n", sym
->generic
.id
);
1951 dump(sym
, 2 + sym
->generic
.len
);
1956 if (curr_func
) symt_normalize_function(msc_dbg
->module
, curr_func
);
1961 static int codeview_snarf_public(const struct msc_debug_info
* msc_dbg
, const BYTE
* root
,
1962 int offset
, int size
)
1966 struct symt_compiland
* compiland
= NULL
;
1969 * Loop over the different types of records and whenever we
1970 * find something we are interested in, record it and move on.
1972 for (i
= offset
; i
< size
; i
+= length
)
1974 const union codeview_symbol
* sym
= (const union codeview_symbol
*)(root
+ i
);
1975 length
= sym
->generic
.len
+ 2;
1976 if (i
+ length
> size
) break;
1977 if (!sym
->generic
.id
|| length
< 4) break;
1978 if (length
& 3) FIXME("unpadded len %u\n", length
);
1980 switch (sym
->generic
.id
)
1982 case S_PUB_V1
: /* FIXME is this really a 'data_v1' structure ?? */
1983 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1985 symt_new_public(msc_dbg
->module
, compiland
,
1986 terminate_string(&sym
->data_v1
.p_name
),
1987 codeview_get_address(msc_dbg
, sym
->data_v1
.segment
, sym
->data_v1
.offset
), 1);
1990 case S_PUB_V2
: /* FIXME is this really a 'data_v2' structure ?? */
1991 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
1993 symt_new_public(msc_dbg
->module
, compiland
,
1994 terminate_string(&sym
->data_v2
.p_name
),
1995 codeview_get_address(msc_dbg
, sym
->data_v2
.segment
, sym
->data_v2
.offset
), 1);
2000 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2002 symt_new_public(msc_dbg
->module
, compiland
,
2004 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
), 1);
2007 case S_PUB_FUNC1_V3
:
2008 case S_PUB_FUNC2_V3
: /* using a data_v3 isn't what we'd expect */
2010 /* FIXME: this is plain wrong (from a simple test) */
2011 if (!(dbghelp_options
& SYMOPT_NO_PUBLICS
))
2013 symt_new_public(msc_dbg
->module
, compiland
,
2015 codeview_get_address(msc_dbg
, sym
->data_v3
.segment
, sym
->data_v3
.offset
), 1);
2020 * Global and local data symbols. We don't associate these
2021 * with any given source file.
2025 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v1
.p_name
),
2026 sym
->data_v1
.segment
, sym
->data_v1
.offset
, sym
->data_v1
.symtype
,
2027 sym
->generic
.id
== S_LDATA_V1
, FALSE
);
2031 codeview_add_variable(msc_dbg
, compiland
, terminate_string(&sym
->data_v2
.p_name
),
2032 sym
->data_v2
.segment
, sym
->data_v2
.offset
, sym
->data_v2
.symtype
,
2033 sym
->generic
.id
== S_LDATA_V2
, FALSE
);
2037 codeview_add_variable(msc_dbg
, compiland
, sym
->data_v3
.name
,
2038 sym
->data_v3
.segment
, sym
->data_v3
.offset
, sym
->data_v3
.symtype
,
2039 sym
->generic
.id
== S_LDATA_V3
, FALSE
);
2042 * These are special, in that they are always followed by an
2043 * additional length-prefixed string which is *not* included
2044 * into the symbol length count. We need to skip it.
2049 length
+= (((const char*)sym
)[length
] + 1 + 3) & ~3;
2052 msc_dbg
->module
->sortlist_valid
= TRUE
;
2054 msc_dbg
->module
->sortlist_valid
= FALSE
;
2058 /*========================================================================
2062 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
,
2068 if (!size
) return NULL
;
2070 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2071 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2073 for (i
= 0; i
< num_blocks
; i
++)
2074 memcpy(buffer
+ i
* pdb
->block_size
,
2075 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2080 static void* pdb_ds_read(const struct PDB_DS_HEADER
* pdb
, const DWORD
* block_list
,
2086 if (!size
) return NULL
;
2088 num_blocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2089 buffer
= HeapAlloc(GetProcessHeap(), 0, num_blocks
* pdb
->block_size
);
2091 for (i
= 0; i
< num_blocks
; i
++)
2092 memcpy(buffer
+ i
* pdb
->block_size
,
2093 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
2098 static void* pdb_read_jg_file(const struct PDB_JG_HEADER
* pdb
,
2099 const struct PDB_JG_TOC
* toc
, DWORD file_nr
)
2101 const WORD
* block_list
;
2104 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2106 block_list
= (const WORD
*) &toc
->file
[toc
->num_files
];
2107 for (i
= 0; i
< file_nr
; i
++)
2108 block_list
+= (toc
->file
[i
].size
+ pdb
->block_size
- 1) / pdb
->block_size
;
2110 return pdb_jg_read(pdb
, block_list
, toc
->file
[file_nr
].size
);
2113 static void* pdb_read_ds_file(const struct PDB_DS_HEADER
* pdb
,
2114 const struct PDB_DS_TOC
* toc
, DWORD file_nr
)
2116 const DWORD
* block_list
;
2119 if (!toc
|| file_nr
>= toc
->num_files
) return NULL
;
2121 if (toc
->file_size
[file_nr
] == 0 || toc
->file_size
[file_nr
] == 0xFFFFFFFF)
2123 FIXME(">>> requesting NULL stream (%u)\n", file_nr
);
2126 block_list
= &toc
->file_size
[toc
->num_files
];
2127 for (i
= 0; i
< file_nr
; i
++)
2128 block_list
+= (toc
->file_size
[i
] + pdb
->block_size
- 1) / pdb
->block_size
;
2130 return pdb_ds_read(pdb
, block_list
, toc
->file_size
[file_nr
]);
2133 static void* pdb_read_file(const char* image
, const struct pdb_file_info
* pdb_file
,
2136 switch (pdb_file
->kind
)
2139 return pdb_read_jg_file((const struct PDB_JG_HEADER
*)image
,
2140 pdb_file
->u
.jg
.toc
, file_nr
);
2142 return pdb_read_ds_file((const struct PDB_DS_HEADER
*)image
,
2143 pdb_file
->u
.ds
.toc
, file_nr
);
2148 static unsigned pdb_get_file_size(const struct pdb_file_info
* pdb_file
, DWORD file_nr
)
2150 switch (pdb_file
->kind
)
2152 case PDB_JG
: return pdb_file
->u
.jg
.toc
->file
[file_nr
].size
;
2153 case PDB_DS
: return pdb_file
->u
.ds
.toc
->file_size
[file_nr
];
2158 static void pdb_free(void* buffer
)
2160 HeapFree(GetProcessHeap(), 0, buffer
);
2163 static void pdb_free_file(struct pdb_file_info
* pdb_file
)
2165 switch (pdb_file
->kind
)
2168 pdb_free(pdb_file
->u
.jg
.toc
);
2169 pdb_file
->u
.jg
.toc
= NULL
;
2172 pdb_free(pdb_file
->u
.ds
.toc
);
2173 pdb_file
->u
.ds
.toc
= NULL
;
2178 static void pdb_module_remove(struct process
* pcsn
, struct module_format
* modfmt
)
2182 for (i
= 0; i
< modfmt
->u
.pdb_info
->used_subfiles
; i
++)
2183 pdb_free_file(&modfmt
->u
.pdb_info
->pdb_files
[i
]);
2184 HeapFree(GetProcessHeap(), 0, modfmt
);
2187 static void pdb_convert_types_header(PDB_TYPES
* types
, const BYTE
* image
)
2189 memset(types
, 0, sizeof(PDB_TYPES
));
2192 if (*(const DWORD
*)image
< 19960000) /* FIXME: correct version? */
2194 /* Old version of the types record header */
2195 const PDB_TYPES_OLD
* old
= (const PDB_TYPES_OLD
*)image
;
2196 types
->version
= old
->version
;
2197 types
->type_offset
= sizeof(PDB_TYPES_OLD
);
2198 types
->type_size
= old
->type_size
;
2199 types
->first_index
= old
->first_index
;
2200 types
->last_index
= old
->last_index
;
2201 types
->file
= old
->file
;
2205 /* New version of the types record header */
2206 *types
= *(const PDB_TYPES
*)image
;
2210 static void pdb_convert_symbols_header(PDB_SYMBOLS
* symbols
,
2211 int* header_size
, const BYTE
* image
)
2213 memset(symbols
, 0, sizeof(PDB_SYMBOLS
));
2216 if (*(const DWORD
*)image
!= 0xffffffff)
2218 /* Old version of the symbols record header */
2219 const PDB_SYMBOLS_OLD
* old
= (const PDB_SYMBOLS_OLD
*)image
;
2220 symbols
->version
= 0;
2221 symbols
->module_size
= old
->module_size
;
2222 symbols
->offset_size
= old
->offset_size
;
2223 symbols
->hash_size
= old
->hash_size
;
2224 symbols
->srcmodule_size
= old
->srcmodule_size
;
2225 symbols
->pdbimport_size
= 0;
2226 symbols
->hash1_file
= old
->hash1_file
;
2227 symbols
->hash2_file
= old
->hash2_file
;
2228 symbols
->gsym_file
= old
->gsym_file
;
2230 *header_size
= sizeof(PDB_SYMBOLS_OLD
);
2234 /* New version of the symbols record header */
2235 *symbols
= *(const PDB_SYMBOLS
*)image
;
2236 *header_size
= sizeof(PDB_SYMBOLS
);
2240 static void pdb_convert_symbol_file(const PDB_SYMBOLS
* symbols
,
2241 PDB_SYMBOL_FILE_EX
* sfile
,
2242 unsigned* size
, const void* image
)
2245 if (symbols
->version
< 19970000)
2247 const PDB_SYMBOL_FILE
*sym_file
= image
;
2248 memset(sfile
, 0, sizeof(*sfile
));
2249 sfile
->file
= sym_file
->file
;
2250 sfile
->range
.index
= sym_file
->range
.index
;
2251 sfile
->symbol_size
= sym_file
->symbol_size
;
2252 sfile
->lineno_size
= sym_file
->lineno_size
;
2253 *size
= sizeof(PDB_SYMBOL_FILE
) - 1;
2257 memcpy(sfile
, image
, sizeof(PDB_SYMBOL_FILE_EX
));
2258 *size
= sizeof(PDB_SYMBOL_FILE_EX
) - 1;
2262 static HANDLE
open_pdb_file(const struct process
* pcs
,
2263 const struct pdb_lookup
* lookup
,
2264 struct module
* module
)
2267 char dbg_file_path
[MAX_PATH
];
2270 switch (lookup
->kind
)
2273 ret
= path_find_symbol_file(pcs
, lookup
->filename
, NULL
, lookup
->timestamp
,
2274 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2277 ret
= path_find_symbol_file(pcs
, lookup
->filename
, &lookup
->guid
, 0,
2278 lookup
->age
, dbg_file_path
, &module
->module
.PdbUnmatched
);
2283 WARN("\tCouldn't find %s\n", lookup
->filename
);
2286 h
= CreateFileA(dbg_file_path
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2287 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2288 TRACE("%s: %s returns %p\n", lookup
->filename
, dbg_file_path
, h
);
2289 return (h
== INVALID_HANDLE_VALUE
) ? NULL
: h
;
2292 static void pdb_process_types(const struct msc_debug_info
* msc_dbg
,
2294 const struct pdb_file_info
* pdb_file
)
2296 BYTE
* types_image
= NULL
;
2298 types_image
= pdb_read_file(image
, pdb_file
, 2);
2302 struct codeview_type_parse ctp
;
2307 pdb_convert_types_header(&types
, types_image
);
2309 /* Check for unknown versions */
2310 switch (types
.version
)
2312 case 19950410: /* VC 4.0 */
2314 case 19961031: /* VC 5.0 / 6.0 */
2315 case 19990903: /* VC 7.0 */
2316 case 20040203: /* VC 8.0 */
2319 ERR("-Unknown type info version %d\n", types
.version
);
2322 ctp
.module
= msc_dbg
->module
;
2323 /* reconstruct the types offset...
2324 * FIXME: maybe it's present in the newest PDB_TYPES structures
2326 total
= types
.last_index
- types
.first_index
+ 1;
2327 offset
= HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD
) * total
);
2328 ctp
.table
= ptr
= types_image
+ types
.type_offset
;
2330 while (ptr
< ctp
.table
+ types
.type_size
&& ctp
.num
< total
)
2332 offset
[ctp
.num
++] = ptr
- ctp
.table
;
2333 ptr
+= ((const union codeview_type
*)ptr
)->generic
.len
+ 2;
2335 ctp
.offset
= offset
;
2337 /* Read type table */
2338 codeview_parse_type_table(&ctp
);
2339 HeapFree(GetProcessHeap(), 0, offset
);
2340 pdb_free(types_image
);
2344 static const char PDB_JG_IDENT
[] = "Microsoft C/C++ program database 2.00\r\n\032JG\0";
2345 static const char PDB_DS_IDENT
[] = "Microsoft C/C++ MSF 7.00\r\n\032DS\0";
2347 /******************************************************************
2350 * Tries to load a pdb file
2351 * 'matched' is filled with the number of correct matches for this file:
2352 * - age counts for one
2353 * - timestamp or guid depending on kind counts for one
2354 * a wrong kind of file returns FALSE (FIXME ?)
2356 static BOOL
pdb_init(const struct pdb_lookup
* pdb_lookup
, struct pdb_file_info
* pdb_file
,
2357 const char* image
, unsigned* matched
)
2361 /* check the file header, and if ok, load the TOC */
2362 TRACE("PDB(%s): %.40s\n", pdb_lookup
->filename
, debugstr_an(image
, 40));
2365 if (!memcmp(image
, PDB_JG_IDENT
, sizeof(PDB_JG_IDENT
)))
2367 const struct PDB_JG_HEADER
* pdb
= (const struct PDB_JG_HEADER
*)image
;
2368 struct PDB_JG_ROOT
* root
;
2370 pdb_file
->u
.jg
.toc
= pdb_jg_read(pdb
, pdb
->toc_block
, pdb
->toc
.size
);
2371 root
= pdb_read_jg_file(pdb
, pdb_file
->u
.jg
.toc
, 1);
2374 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2377 switch (root
->Version
)
2379 case 19950623: /* VC 4.0 */
2381 case 19960307: /* VC 5.0 */
2382 case 19970604: /* VC 6.0 */
2385 ERR("-Unknown root block version %d\n", root
->Version
);
2387 if (pdb_lookup
->kind
!= PDB_JG
)
2389 WARN("Found %s, but wrong PDB kind\n", pdb_lookup
->filename
);
2392 pdb_file
->kind
= PDB_JG
;
2393 pdb_file
->u
.jg
.timestamp
= root
->TimeDateStamp
;
2394 pdb_file
->age
= root
->Age
;
2395 if (root
->TimeDateStamp
== pdb_lookup
->timestamp
) (*matched
)++;
2396 else WARN("Found %s, but wrong signature: %08x %08x\n",
2397 pdb_lookup
->filename
, root
->TimeDateStamp
, pdb_lookup
->timestamp
);
2398 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2399 else WARN("Found %s, but wrong age: %08x %08x\n",
2400 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2401 TRACE("found JG for %s: age=%x timestamp=%x\n",
2402 pdb_lookup
->filename
, root
->Age
, root
->TimeDateStamp
);
2405 else if (!memcmp(image
, PDB_DS_IDENT
, sizeof(PDB_DS_IDENT
)))
2407 const struct PDB_DS_HEADER
* pdb
= (const struct PDB_DS_HEADER
*)image
;
2408 struct PDB_DS_ROOT
* root
;
2410 pdb_file
->u
.ds
.toc
=
2412 (const DWORD
*)((const char*)pdb
+ pdb
->toc_page
* pdb
->block_size
),
2414 root
= pdb_read_ds_file(pdb
, pdb_file
->u
.ds
.toc
, 1);
2417 ERR("-Unable to get root from .PDB in %s\n", pdb_lookup
->filename
);
2420 switch (root
->Version
)
2425 ERR("-Unknown root block version %d\n", root
->Version
);
2427 pdb_file
->kind
= PDB_DS
;
2428 pdb_file
->u
.ds
.guid
= root
->guid
;
2429 pdb_file
->age
= root
->Age
;
2430 if (!memcmp(&root
->guid
, &pdb_lookup
->guid
, sizeof(GUID
))) (*matched
)++;
2431 else WARN("Found %s, but wrong GUID: %s %s\n",
2432 pdb_lookup
->filename
, debugstr_guid(&root
->guid
),
2433 debugstr_guid(&pdb_lookup
->guid
));
2434 if (root
->Age
== pdb_lookup
->age
) (*matched
)++;
2435 else WARN("Found %s, but wrong age: %08x %08x\n",
2436 pdb_lookup
->filename
, root
->Age
, pdb_lookup
->age
);
2437 TRACE("found DS for %s: age=%x guid=%s\n",
2438 pdb_lookup
->filename
, root
->Age
, debugstr_guid(&root
->guid
));
2442 if (0) /* some tool to dump the internal files from a PDB file */
2446 switch (pdb_file
->kind
)
2448 case PDB_JG
: num_files
= pdb_file
->u
.jg
.toc
->num_files
; break;
2449 case PDB_DS
: num_files
= pdb_file
->u
.ds
.toc
->num_files
; break;
2452 for (i
= 1; i
< num_files
; i
++)
2454 unsigned char* x
= pdb_read_file(image
, pdb_file
, i
);
2455 FIXME("********************** [%u]: size=%08x\n",
2456 i
, pdb_get_file_size(pdb_file
, i
));
2457 dump(x
, pdb_get_file_size(pdb_file
, i
));
2464 static BOOL
pdb_process_internal(const struct process
* pcs
,
2465 const struct msc_debug_info
* msc_dbg
,
2466 const struct pdb_lookup
* pdb_lookup
,
2467 struct pdb_module_info
* pdb_module_info
,
2468 unsigned module_index
);
2470 static void pdb_process_symbol_imports(const struct process
* pcs
,
2471 const struct msc_debug_info
* msc_dbg
,
2472 const PDB_SYMBOLS
* symbols
,
2473 const void* symbols_image
,
2475 const struct pdb_lookup
* pdb_lookup
,
2476 struct pdb_module_info
* pdb_module_info
,
2477 unsigned module_index
)
2479 if (module_index
== -1 && symbols
&& symbols
->pdbimport_size
)
2481 const PDB_SYMBOL_IMPORT
*imp
;
2486 struct pdb_file_info sf0
= pdb_module_info
->pdb_files
[0];
2488 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols_image
+ sizeof(PDB_SYMBOLS
) +
2489 symbols
->module_size
+ symbols
->offset_size
+
2490 symbols
->hash_size
+ symbols
->srcmodule_size
);
2492 last
= (const char*)imp
+ symbols
->pdbimport_size
;
2493 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
2495 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
2496 if (i
>= CV_MAX_MODULES
) FIXME("Out of bounds !!!\n");
2497 if (!strcasecmp(pdb_lookup
->filename
, imp
->filename
))
2499 if (module_index
!= -1) FIXME("Twice the entry\n");
2500 else module_index
= i
;
2501 pdb_module_info
->pdb_files
[i
] = sf0
;
2505 struct pdb_lookup imp_pdb_lookup
;
2507 /* FIXME: this is an import of a JG PDB file
2508 * how's a DS PDB handled ?
2510 imp_pdb_lookup
.filename
= imp
->filename
;
2511 imp_pdb_lookup
.kind
= PDB_JG
;
2512 imp_pdb_lookup
.timestamp
= imp
->TimeDateStamp
;
2513 imp_pdb_lookup
.age
= imp
->Age
;
2514 TRACE("got for %s: age=%u ts=%x\n",
2515 imp
->filename
, imp
->Age
, imp
->TimeDateStamp
);
2516 pdb_process_internal(pcs
, msc_dbg
, &imp_pdb_lookup
, pdb_module_info
, i
);
2519 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)first
+ ((ptr
- (const char*)first
+ strlen(ptr
) + 1 + 3) & ~3));
2521 pdb_module_info
->used_subfiles
= i
;
2523 if (module_index
== -1)
2526 pdb_module_info
->used_subfiles
= 1;
2528 cv_current_module
= &cv_zmodules
[module_index
];
2529 if (cv_current_module
->allowed
) FIXME("Already allowed ??\n");
2530 cv_current_module
->allowed
= TRUE
;
2533 static BOOL
pdb_process_internal(const struct process
* pcs
,
2534 const struct msc_debug_info
* msc_dbg
,
2535 const struct pdb_lookup
* pdb_lookup
,
2536 struct pdb_module_info
* pdb_module_info
,
2537 unsigned module_index
)
2540 HANDLE hFile
, hMap
= NULL
;
2542 BYTE
* symbols_image
= NULL
;
2543 char* files_image
= NULL
;
2544 DWORD files_size
= 0;
2546 struct pdb_file_info
* pdb_file
;
2548 TRACE("Processing PDB file %s\n", pdb_lookup
->filename
);
2550 pdb_file
= &pdb_module_info
->pdb_files
[module_index
== -1 ? 0 : module_index
];
2551 /* Open and map() .PDB file */
2552 if ((hFile
= open_pdb_file(pcs
, pdb_lookup
, msc_dbg
->module
)) == NULL
||
2553 ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
2554 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2556 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2559 if (!pdb_init(pdb_lookup
, pdb_file
, image
, &matched
) || matched
!= 2)
2564 symbols_image
= pdb_read_file(image
, pdb_file
, 3);
2567 PDB_SYMBOLS symbols
;
2571 int header_size
= 0;
2573 pdb_convert_symbols_header(&symbols
, &header_size
, symbols_image
);
2574 switch (symbols
.version
)
2576 case 0: /* VC 4.0 */
2577 case 19960307: /* VC 5.0 */
2578 case 19970606: /* VC 6.0 */
2582 ERR("-Unknown symbol info version %d %08x\n",
2583 symbols
.version
, symbols
.version
);
2586 files_image
= pdb_read_file(image
, pdb_file
, 12); /* FIXME: really fixed ??? */
2589 if (*(const DWORD
*)files_image
== 0xeffeeffe)
2591 files_size
= *(const DWORD
*)(files_image
+ 8);
2595 WARN("wrong header %x expecting 0xeffeeffe\n", *(const DWORD
*)files_image
);
2596 pdb_free(files_image
);
2601 pdb_process_symbol_imports(pcs
, msc_dbg
, &symbols
, symbols_image
, image
,
2602 pdb_lookup
, pdb_module_info
, module_index
);
2603 pdb_process_types(msc_dbg
, image
, pdb_file
);
2605 /* Read global symbol table */
2606 globalimage
= pdb_read_file(image
, pdb_file
, symbols
.gsym_file
);
2609 codeview_snarf(msc_dbg
, globalimage
, 0,
2610 pdb_get_file_size(pdb_file
, symbols
.gsym_file
), FALSE
);
2613 /* Read per-module symbols' tables */
2614 file
= symbols_image
+ header_size
;
2615 while (file
- symbols_image
< header_size
+ symbols
.module_size
)
2617 PDB_SYMBOL_FILE_EX sfile
;
2618 const char* file_name
;
2621 HeapValidate(GetProcessHeap(), 0, NULL
);
2622 pdb_convert_symbol_file(&symbols
, &sfile
, &size
, file
);
2624 modimage
= pdb_read_file(image
, pdb_file
, sfile
.file
);
2627 if (sfile
.symbol_size
)
2628 codeview_snarf(msc_dbg
, modimage
, sizeof(DWORD
),
2629 sfile
.symbol_size
, TRUE
);
2631 if (sfile
.lineno_size
)
2632 codeview_snarf_linetab(msc_dbg
,
2633 modimage
+ sfile
.symbol_size
,
2635 pdb_file
->kind
== PDB_JG
);
2637 codeview_snarf_linetab2(msc_dbg
, modimage
+ sfile
.symbol_size
+ sfile
.lineno_size
,
2638 pdb_get_file_size(pdb_file
, sfile
.file
) - sfile
.symbol_size
- sfile
.lineno_size
,
2639 files_image
+ 12, files_size
);
2643 file_name
= (const char*)file
+ size
;
2644 file_name
+= strlen(file_name
) + 1;
2645 file
= (BYTE
*)((DWORD_PTR
)(file_name
+ strlen(file_name
) + 1 + 3) & ~3);
2647 /* finish the remaining public and global information */
2650 codeview_snarf_public(msc_dbg
, globalimage
, 0,
2651 pdb_get_file_size(pdb_file
, symbols
.gsym_file
));
2652 pdb_free(globalimage
);
2656 pdb_process_symbol_imports(pcs
, msc_dbg
, NULL
, NULL
, image
,
2657 pdb_lookup
, pdb_module_info
, module_index
);
2662 pdb_free(symbols_image
);
2663 pdb_free(files_image
);
2664 pdb_free_file(pdb_file
);
2666 if (image
) UnmapViewOfFile(image
);
2667 if (hMap
) CloseHandle(hMap
);
2668 if (hFile
) CloseHandle(hFile
);
2673 static BOOL
pdb_process_file(const struct process
* pcs
,
2674 const struct msc_debug_info
* msc_dbg
,
2675 struct pdb_lookup
* pdb_lookup
)
2678 struct module_format
* modfmt
;
2679 struct pdb_module_info
* pdb_module_info
;
2681 modfmt
= HeapAlloc(GetProcessHeap(), 0,
2682 sizeof(struct module_format
) + sizeof(struct pdb_module_info
));
2683 if (!modfmt
) return FALSE
;
2685 pdb_module_info
= (void*)(modfmt
+ 1);
2686 msc_dbg
->module
->format_info
[DFI_PDB
] = modfmt
;
2687 modfmt
->module
= msc_dbg
->module
;
2688 modfmt
->remove
= pdb_module_remove
;
2689 modfmt
->loc_compute
= NULL
;
2690 modfmt
->u
.pdb_info
= pdb_module_info
;
2692 memset(cv_zmodules
, 0, sizeof(cv_zmodules
));
2693 codeview_init_basic_types(msc_dbg
->module
);
2694 ret
= pdb_process_internal(pcs
, msc_dbg
, pdb_lookup
,
2695 msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
, -1);
2696 codeview_clear_type_table();
2699 struct pdb_module_info
* pdb_info
= msc_dbg
->module
->format_info
[DFI_PDB
]->u
.pdb_info
;
2700 msc_dbg
->module
->module
.SymType
= SymCv
;
2701 if (pdb_info
->pdb_files
[0].kind
== PDB_JG
)
2702 msc_dbg
->module
->module
.PdbSig
= pdb_info
->pdb_files
[0].u
.jg
.timestamp
;
2704 msc_dbg
->module
->module
.PdbSig70
= pdb_info
->pdb_files
[0].u
.ds
.guid
;
2705 msc_dbg
->module
->module
.PdbAge
= pdb_info
->pdb_files
[0].age
;
2706 MultiByteToWideChar(CP_ACP
, 0, pdb_lookup
->filename
, -1,
2707 msc_dbg
->module
->module
.LoadedPdbName
,
2708 sizeof(msc_dbg
->module
->module
.LoadedPdbName
) / sizeof(WCHAR
));
2709 /* FIXME: we could have a finer grain here */
2710 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
2711 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
2712 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
2713 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
2714 msc_dbg
->module
->module
.Publics
= TRUE
;
2719 BOOL
pdb_fetch_file_info(const struct pdb_lookup
* pdb_lookup
, unsigned* matched
)
2721 HANDLE hFile
, hMap
= NULL
;
2724 struct pdb_file_info pdb_file
;
2726 if ((hFile
= CreateFileA(pdb_lookup
->filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
2727 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
)) == INVALID_HANDLE_VALUE
||
2728 ((hMap
= CreateFileMappingW(hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
)) == NULL
) ||
2729 ((image
= MapViewOfFile(hMap
, FILE_MAP_READ
, 0, 0, 0)) == NULL
))
2731 WARN("Unable to open .PDB file: %s\n", pdb_lookup
->filename
);
2736 ret
= pdb_init(pdb_lookup
, &pdb_file
, image
, matched
);
2737 pdb_free_file(&pdb_file
);
2740 if (image
) UnmapViewOfFile(image
);
2741 if (hMap
) CloseHandle(hMap
);
2742 if (hFile
!= INVALID_HANDLE_VALUE
) CloseHandle(hFile
);
2747 /*========================================================================
2748 * Process CodeView debug information.
2751 #define MAKESIG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24))
2752 #define CODEVIEW_NB09_SIG MAKESIG('N','B','0','9')
2753 #define CODEVIEW_NB10_SIG MAKESIG('N','B','1','0')
2754 #define CODEVIEW_NB11_SIG MAKESIG('N','B','1','1')
2755 #define CODEVIEW_RSDS_SIG MAKESIG('R','S','D','S')
2757 static BOOL
codeview_process_info(const struct process
* pcs
,
2758 const struct msc_debug_info
* msc_dbg
)
2760 const DWORD
* signature
= (const DWORD
*)msc_dbg
->root
;
2762 struct pdb_lookup pdb_lookup
;
2764 TRACE("Processing signature %.4s\n", (const char*)signature
);
2768 case CODEVIEW_NB09_SIG
:
2769 case CODEVIEW_NB11_SIG
:
2771 const OMFSignature
* cv
= (const OMFSignature
*)msc_dbg
->root
;
2772 const OMFDirHeader
* hdr
= (const OMFDirHeader
*)(msc_dbg
->root
+ cv
->filepos
);
2773 const OMFDirEntry
* ent
;
2774 const OMFDirEntry
* prev
;
2775 const OMFDirEntry
* next
;
2778 codeview_init_basic_types(msc_dbg
->module
);
2780 for (i
= 0; i
< hdr
->cDir
; i
++)
2782 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
+ i
* hdr
->cbDirEntry
);
2783 if (ent
->SubSection
== sstGlobalTypes
)
2785 const OMFGlobalTypes
* types
;
2786 struct codeview_type_parse ctp
;
2788 types
= (const OMFGlobalTypes
*)(msc_dbg
->root
+ ent
->lfo
);
2789 ctp
.module
= msc_dbg
->module
;
2790 ctp
.offset
= (const DWORD
*)(types
+ 1);
2791 ctp
.num
= types
->cTypes
;
2792 ctp
.table
= (const BYTE
*)(ctp
.offset
+ types
->cTypes
);
2794 cv_current_module
= &cv_zmodules
[0];
2795 if (cv_current_module
->allowed
) FIXME("Already allowed ??\n");
2796 cv_current_module
->allowed
= TRUE
;
2798 codeview_parse_type_table(&ctp
);
2803 ent
= (const OMFDirEntry
*)((const BYTE
*)hdr
+ hdr
->cbDirHeader
);
2804 for (i
= 0; i
< hdr
->cDir
; i
++, ent
= next
)
2806 next
= (i
== hdr
->cDir
-1) ? NULL
:
2807 (const OMFDirEntry
*)((const BYTE
*)ent
+ hdr
->cbDirEntry
);
2808 prev
= (i
== 0) ? NULL
:
2809 (const OMFDirEntry
*)((const BYTE
*)ent
- hdr
->cbDirEntry
);
2811 if (ent
->SubSection
== sstAlignSym
)
2813 codeview_snarf(msc_dbg
, msc_dbg
->root
+ ent
->lfo
, sizeof(DWORD
),
2817 * Check the next and previous entry. If either is a
2818 * sstSrcModule, it contains the line number info for
2821 * FIXME: This is not a general solution!
2823 if (next
&& next
->iMod
== ent
->iMod
&& next
->SubSection
== sstSrcModule
)
2824 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ next
->lfo
,
2827 if (prev
&& prev
->iMod
== ent
->iMod
&& prev
->SubSection
== sstSrcModule
)
2828 codeview_snarf_linetab(msc_dbg
, msc_dbg
->root
+ prev
->lfo
,
2834 msc_dbg
->module
->module
.SymType
= SymCv
;
2835 /* FIXME: we could have a finer grain here */
2836 msc_dbg
->module
->module
.LineNumbers
= TRUE
;
2837 msc_dbg
->module
->module
.GlobalSymbols
= TRUE
;
2838 msc_dbg
->module
->module
.TypeInfo
= TRUE
;
2839 msc_dbg
->module
->module
.SourceIndexed
= TRUE
;
2840 msc_dbg
->module
->module
.Publics
= TRUE
;
2841 codeview_clear_type_table();
2846 case CODEVIEW_NB10_SIG
:
2848 const CODEVIEW_PDB_DATA
* pdb
= (const CODEVIEW_PDB_DATA
*)msc_dbg
->root
;
2849 pdb_lookup
.filename
= pdb
->name
;
2850 pdb_lookup
.kind
= PDB_JG
;
2851 pdb_lookup
.timestamp
= pdb
->timestamp
;
2852 pdb_lookup
.age
= pdb
->age
;
2853 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
2856 case CODEVIEW_RSDS_SIG
:
2858 const OMFSignatureRSDS
* rsds
= (const OMFSignatureRSDS
*)msc_dbg
->root
;
2860 TRACE("Got RSDS type of PDB file: guid=%s age=%08x name=%s\n",
2861 wine_dbgstr_guid(&rsds
->guid
), rsds
->age
, rsds
->name
);
2862 pdb_lookup
.filename
= rsds
->name
;
2863 pdb_lookup
.kind
= PDB_DS
;
2864 pdb_lookup
.guid
= rsds
->guid
;
2865 pdb_lookup
.age
= rsds
->age
;
2866 ret
= pdb_process_file(pcs
, msc_dbg
, &pdb_lookup
);
2870 ERR("Unknown CODEVIEW signature %08x in module %s\n",
2871 *signature
, debugstr_w(msc_dbg
->module
->module
.ModuleName
));
2876 msc_dbg
->module
->module
.CVSig
= *signature
;
2877 memcpy(msc_dbg
->module
->module
.CVData
, msc_dbg
->root
,
2878 sizeof(msc_dbg
->module
->module
.CVData
));
2883 /*========================================================================
2884 * Process debug directory.
2886 BOOL
pe_load_debug_directory(const struct process
* pcs
, struct module
* module
,
2887 const BYTE
* mapping
,
2888 const IMAGE_SECTION_HEADER
* sectp
, DWORD nsect
,
2889 const IMAGE_DEBUG_DIRECTORY
* dbg
, int nDbg
)
2893 struct msc_debug_info msc_dbg
;
2895 msc_dbg
.module
= module
;
2896 msc_dbg
.nsect
= nsect
;
2897 msc_dbg
.sectp
= sectp
;
2899 msc_dbg
.omapp
= NULL
;
2905 /* First, watch out for OMAP data */
2906 for (i
= 0; i
< nDbg
; i
++)
2908 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_OMAP_FROM_SRC
)
2910 msc_dbg
.nomap
= dbg
[i
].SizeOfData
/ sizeof(OMAP_DATA
);
2911 msc_dbg
.omapp
= (const OMAP_DATA
*)(mapping
+ dbg
[i
].PointerToRawData
);
2916 /* Now, try to parse CodeView debug info */
2917 for (i
= 0; i
< nDbg
; i
++)
2919 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_CODEVIEW
)
2921 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
2922 if ((ret
= codeview_process_info(pcs
, &msc_dbg
))) goto done
;
2926 /* If not found, try to parse COFF debug info */
2927 for (i
= 0; i
< nDbg
; i
++)
2929 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_COFF
)
2931 msc_dbg
.root
= mapping
+ dbg
[i
].PointerToRawData
;
2932 if ((ret
= coff_process_info(&msc_dbg
))) goto done
;
2936 /* FIXME: this should be supported... this is the debug information for
2937 * functions compiled without a frame pointer (FPO = frame pointer omission)
2938 * the associated data helps finding out the relevant information
2940 for (i
= 0; i
< nDbg
; i
++)
2941 if (dbg
[i
].Type
== IMAGE_DEBUG_TYPE_FPO
)
2942 FIXME("This guy has FPO information\n");
2946 #define FRAME_TRAP 1
2949 typedef struct _FPO_DATA
2951 DWORD ulOffStart
; /* offset 1st byte of function code */
2952 DWORD cbProcSize
; /* # bytes in function */
2953 DWORD cdwLocals
; /* # bytes in locals/4 */
2954 WORD cdwParams
; /* # bytes in params/4 */
2956 WORD cbProlog
: 8; /* # bytes in prolog */
2957 WORD cbRegs
: 3; /* # regs saved */
2958 WORD fHasSEH
: 1; /* TRUE if SEH in func */
2959 WORD fUseBP
: 1; /* TRUE if EBP has been allocated */
2960 WORD reserved
: 1; /* reserved for future use */
2961 WORD cbFrame
: 2; /* frame type */
2968 ERR("Got a page fault while loading symbols\n");