-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathPDB.h
443 lines (377 loc) · 7.42 KB
/
PDB.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <dia2.h>
#include <set>
#include <unordered_set>
#include <unordered_map>
typedef struct _SYMBOL SYMBOL, *PSYMBOL;
//
// Representation of the enum field.
//
// enum XYZ
// {
// // Name Value
// // -----------------
// XYZ_1 = 2,
// XYZ_2 = 4,
// };
//
// Note that 'Value' is represented as the VARIANT type.
//
typedef struct _SYMBOL_ENUM_FIELD
{
//
// Name of the enumeration field.
//
CHAR* Name;
//
// Assigned value of the enumeration field.
//
VARIANT Value;
//
// Parent enumeration.
//
SYMBOL* Parent;
} SYMBOL_ENUM_FIELD, *PSYMBOL_ENUM_FIELD;
//
// Representation of the struct/class/union field.
//
// struct XYZ
// {
// // Type Name Bits Offset BitPosition
// // -------------------------------------------------
// int XYZ_1; // 0 0
// short XYZ_2 : 3; // 4 0
// short XYZ_3 : 13; // 4 3
// };
//
typedef struct _SYMBOL_UDT_FIELD
{
//
// Name of the UDT field.
//
CHAR* Name;
//
// Type of the field.
//
SYMBOL* Type;
//
// Offset from the start of the structure/class/union.
//
DWORD Offset;
//
// Amount of bits this field takes.
// If this value is 0, this field takes
// all of the space of the field type (Type->Size bytes).
//
DWORD Bits;
//
// Which bit this fields starts at (relative to the Offset).
//
DWORD BitPosition;
//
// Parent UDT symbol.
//
SYMBOL* Parent;
} SYMBOL_UDT_FIELD, *PSYMBOL_UDT_FIELD;
//
// Representation of the enumeration.
//
// Example for FieldCount = 3
//
// enum XYZ
// {
// XYZ_1,
// XYZ_2,
// XYZ_3,
// };
//
typedef struct _SYMBOL_ENUM
{
//
// Count of fields in the enumeration.
//
DWORD FieldCount;
//
// Pointer to the continuous array of structures of the enumeration fields.
//
SYMBOL_ENUM_FIELD* Fields;
} SYMBOL_ENUM, *PSYMBOL_ENUM;
//
// Representation of the typedef statement.
//
typedef struct _SYMBOL_TYPEDEF
{
//
// Underlying type of the type definition.
//
SYMBOL* Type;
} SYMBOL_TYPEDEF, *PSYMBOL_TYPEDEF;
//
// Representation of the pointer statement.
//
typedef struct _SYMBOL_POINTER
{
//
// Underlying type of the pointer definition.
//
SYMBOL* Type;
//
// Specifies if the pointer represents the reference.
//
BOOL IsReference;
} SYMBOL_POINTER, *PSYMBOL_POINTER;
//
// Representation of the array.
//
typedef struct _SYMBOL_ARRAY
{
//
// Type of the array element.
//
SYMBOL* ElementType;
//
// Array size in elements.
//
DWORD ElementCount;
} SYMBOL_ARRAY, *PSYMBOL_ARRAY;
//
// Representation of the function.
//
typedef struct _SYMBOL_FUNCTION
{
//
// Return type of the function.
//
SYMBOL* ReturnType;
//
// Calling convention of the function.
//
CV_call_e CallingConvention;
//
// Number of arguments.
//
DWORD ArgumentCount;
//
// Pointer to the continuous array of pointers to the symbol structure for arguments.
// These symbols are of type SYMBOL_FUNCTIONARG and has tag SymTagFunctionArgType.
//
SYMBOL** Arguments;
} SYMBOL_FUNCTION, *PSYMBOL_FUNCTION;
//
// Representation of the function argument type.
//
typedef struct _SYMBOL_FUNCTIONARG
{
//
// Underlying type of the argument.
//
SYMBOL* Type;
} SYMBOL_FUNCTIONARG, *PSYMBOL_FUNCTIONARG;
//
// Representation of the UDT (struct/class/union).
//
typedef struct _SYMBOL_UDT
{
//
// Kind of the UDT.
// It may be either UdtStruct, UdtClass or UdtUnion.
//
UdtKind Kind;
//
// Number of fields (members) in the UDT.
//
DWORD FieldCount;
//
// Pointer to the continuous array of structures of the UDT.
//
SYMBOL_UDT_FIELD* Fields;
} SYMBOL_UDT, *PSYMBOL_UDT;
//
// Representation of the debug symbol.
//
struct _SYMBOL
{
//
// Type of the symbol.
//
enum SymTagEnum Tag;
//
// Data kind.
// Only sef it Tag == SymTagData.
//
enum DataKind DataKind;
//
// Base type.
// Only set if Tag == SymTagBaseType.
//
BasicType BaseType;
//
// Internal ID of the type.
//
DWORD TypeId;
//
// Total size of the type which this symbol represents.
//
DWORD Size;
//
// Specifies constness.
//
BOOL IsConst;
//
// Specifies volatileness.
//
BOOL IsVolatile;
//
// Name of the type.
//
CHAR* Name;
union
{
SYMBOL_ENUM Enum;
SYMBOL_TYPEDEF Typedef;
SYMBOL_POINTER Pointer;
SYMBOL_ARRAY Array;
SYMBOL_FUNCTION Function;
SYMBOL_FUNCTIONARG FunctionArg;
SYMBOL_UDT Udt;
} u;
};
class SymbolModule;
using SymbolMap = std::unordered_map<DWORD, SYMBOL*>;
using SymbolNameMap = std::unordered_map<std::string, SYMBOL*>;
using SymbolSet = std::unordered_set<SYMBOL*>;
using FunctionSet = std::set<std::string>;
class PDB
{
public:
//
// Default constructor.
//
PDB();
//
// Instantiates PDB class with particular PDB file.
//
PDB(
IN const CHAR* Path
);
//
// Destructor.
//
~PDB();
//
// Opens particular PDB file and parses it.
//
// Returns non-zero value on success.
//
BOOL
Open(
IN const CHAR* Path
);
//
// Returns TRUE if a PDB file is opened.
//
BOOL
IsOpened() const;
//
// Returns path of the currently opened PDB file.
//
const CHAR*
GetPath() const;
//
// Closes all resources which holds the opened PDB file.
//
VOID
Close();
//
// Get machine type for which was the PDB compiled for.
//
DWORD
GetMachineType() const;
//
// Get language type of the global symbol.
//
CV_CFL_LANG
GetLanguage() const;
//
// Returns a SYMBOL structure of particular name.
//
// Returns non-NULL value on success.
//
const SYMBOL*
GetSymbolByName(
IN const CHAR* SymbolName
);
//
// Returns a SYMBOL structure of particular Type ID.
//
// Returns non-NULL value on success.
//
const SYMBOL*
GetSymbolByTypeId(
IN DWORD TypeId
);
//
// Returns collection of all symbols.
//
const SymbolMap&
GetSymbolMap() const;
//
// Returns collection of all named symbols.
//
const SymbolNameMap&
GetSymbolNameMap() const;
//
// Returns collection of all named functions.
//
const FunctionSet&
GetFunctionSet() const;
//
// Returns C-like name of the type of provided symbol.
// The symbol must be BaseType.
//
// Returns non-NULL value on success.
//
static
const CHAR*
GetBasicTypeString(
IN BasicType BaseType,
IN DWORD Size,
IN BOOL UseStdInt = FALSE
);
//
// Returns C-like name of the type of provided symbol.
// The symbol must be BaseType.
//
// Returns non-NULL value on success.
//
static
const CHAR*
GetBasicTypeString(
IN const SYMBOL* Symbol,
IN BOOL UseStdInt = FALSE
);
//
// Returns string representing the kind
// of provided user defined type.
//
// Returns non-NULL value on success.
//
static
const CHAR*
GetUdtKindString(
IN UdtKind Kind
);
//
// Returns TRUE if the provided symbol's name
// starts with "<anonymous-", "<unnamed-" or "__unnamed".
//
static
BOOL
IsUnnamedSymbol(
const SYMBOL* Symbol
);
private:
SymbolModule* m_Impl;
};