Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/tools/winedump/debug.c
4389 views
1
/*
2
* Made after:
3
* CVDump - Parses through a Visual Studio .DBG file in CodeView 4 format
4
* and dumps the info to STDOUT in a human-readable format
5
*
6
* Copyright 2000 John R. Sheets
7
*
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2.1 of the License, or (at your option) any later version.
12
*
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
17
*
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21
*/
22
23
#include "config.h"
24
25
#include <stdlib.h>
26
#include <stdarg.h>
27
#include <stdio.h>
28
#include <time.h>
29
30
#include "../tools.h"
31
#include "windef.h"
32
#include "winbase.h"
33
#include "winedump.h"
34
35
/*
36
* .DBG File Layout:
37
*
38
* IMAGE_SEPARATE_DEBUG_HEADER
39
* IMAGE_SECTION_HEADER[]
40
* IMAGE_DEBUG_DIRECTORY[]
41
* OMFSignature
42
* debug data (typical example)
43
* - IMAGE_DEBUG_TYPE_MISC
44
* - IMAGE_DEBUG_TYPE_FPO
45
* - IMAGE_DEBUG_TYPE_CODEVIEW
46
* OMFDirHeader
47
* OMFDirEntry[]
48
*/
49
50
/*
51
* Descriptions:
52
*
53
* (hdr) IMAGE_SEPARATE_DEBUG_HEADER - .DBG-specific file header; holds info that
54
* applies to the file as a whole, including # of COFF sections, file offsets, etc.
55
* (hdr) IMAGE_SECTION_HEADER - list of COFF sections copied verbatim from .EXE;
56
* although this directory contains file offsets, these offsets are meaningless
57
* in the context of the .DBG file, because only the section headers are copied
58
* to the .DBG file... not the binary data it points to.
59
* (hdr) IMAGE_DEBUG_DIRECTORY - list of different formats of debug info contained in file
60
* (see IMAGE_DEBUG_TYPE_* descriptions below); tells where each section starts
61
* (hdr) OMFSignature (CV) - Contains "NBxx" signature, plus file offset telling how far
62
* into the IMAGE_DEBUG_TYPE_CODEVIEW section the OMFDirHeader and OMFDirEntry's sit
63
* (data) IMAGE_DEBUG_TYPE_MISC - usually holds name of original .EXE file
64
* (data) IMAGE_DEBUG_TYPE_FPO - Frame Pointer Optimization data; used for dealing with
65
* optimized stack frames (optional)
66
* (data) IMAGE_DEBUG_TYPE_CODEVIEW - *** THE GOOD STUFF ***
67
* This block of data contains all the symbol tables, line number info, etc.,
68
* that the Visual C++ debugger needs.
69
* (hdr) OMFDirHeader (CV) -
70
* (hdr) OMFDirEntry (CV) - list of subsections within CodeView debug data section
71
*/
72
73
/*
74
* The .DBG file typically has three arrays of directory entries, which tell
75
* the OS or debugger where in the file to look for the actual data
76
*
77
* IMAGE_SECTION_HEADER - number of entries determined by:
78
* (IMAGE_SEPARATE_DEBUG_HEADER.NumberOfSections)
79
*
80
* IMAGE_DEBUG_DIRECTORY - number of entries determined by:
81
* (IMAGE_SEPARATE_DEBUG_HEADER.DebugDirectorySize / sizeof (IMAGE_DEBUG_DIRECTORY))
82
*
83
* OMFDirEntry - number of entries determined by:
84
* (OMFDirHeader.cDir)
85
*/
86
87
extern const IMAGE_NT_HEADERS* PE_nt_headers;
88
static const void* cv_base /* = 0 */;
89
90
static BOOL dump_cv_sst_module(const OMFDirEntry* omfde)
91
{
92
const OMFModule* module;
93
const OMFSegDesc* segDesc;
94
int i;
95
96
module = PRD(Offset(cv_base) + omfde->lfo, sizeof(OMFModule));
97
if (!module) {printf("Can't get the OMF-Module, aborting\n"); return FALSE;}
98
99
printf(" olvNumber: %u\n", module->ovlNumber);
100
printf(" iLib: %u\n", module->iLib);
101
printf(" cSeg: %u\n", module->cSeg);
102
printf(" Style: %c%c\n", module->Style[0], module->Style[1]);
103
printf(" Name: %.*s\n",
104
*(const BYTE*)((const char*)(module + 1) + sizeof(OMFSegDesc) * module->cSeg),
105
(const char*)(module + 1) + sizeof(OMFSegDesc) * module->cSeg + 1);
106
107
segDesc = PRD(Offset(module + 1), sizeof(OMFSegDesc) * module->cSeg);
108
if (!segDesc) {printf("Can't get the OMF-SegDesc, aborting\n"); return FALSE;}
109
110
for (i = 0; i < module->cSeg; i++)
111
{
112
printf (" segment #%2d: offset = [0x%8x], size = [0x%8x]\n",
113
segDesc->Seg, segDesc->Off, segDesc->cbSeg);
114
segDesc++;
115
}
116
return TRUE;
117
}
118
119
static BOOL dump_cv_sst_global_pub(const OMFDirEntry* omfde)
120
{
121
long fileoffset;
122
const OMFSymHash* header;
123
const BYTE* symbols;
124
125
fileoffset = Offset(cv_base) + omfde->lfo;
126
printf (" GlobalPub section starts at file offset 0x%lx\n", fileoffset);
127
printf (" Symbol table starts at 0x%lx\n", fileoffset + sizeof (OMFSymHash));
128
129
printf ("\n ----- Begin Symbol Table -----\n");
130
131
header = PRD(fileoffset, sizeof(OMFSymHash));
132
if (!header) {printf("Can't get OMF-SymHash, aborting\n");return FALSE;}
133
134
symbols = PRD(fileoffset + sizeof(OMFSymHash), header->cbSymbol);
135
if (!symbols) {printf("Can't OMF-SymHash details, aborting\n"); return FALSE;}
136
137
codeview_dump_symbols(symbols, 0, header->cbSymbol);
138
139
return TRUE;
140
}
141
142
static BOOL dump_cv_sst_global_sym(const OMFDirEntry* omfde)
143
{
144
/*** NOT YET IMPLEMENTED ***/
145
return TRUE;
146
}
147
148
static BOOL dump_cv_sst_static_sym(const OMFDirEntry* omfde)
149
{
150
/*** NOT YET IMPLEMENTED ***/
151
return TRUE;
152
}
153
154
static BOOL dump_cv_sst_libraries(const OMFDirEntry* omfde)
155
{
156
/*** NOT YET IMPLEMENTED ***/
157
return TRUE;
158
}
159
160
static BOOL dump_cv_sst_global_types(const OMFDirEntry* omfde)
161
{
162
long fileoffset;
163
const OMFGlobalTypes*types;
164
const BYTE* data;
165
unsigned sz;
166
167
fileoffset = Offset(cv_base) + omfde->lfo;
168
printf (" GlobalTypes section starts at file offset 0x%lx\n", fileoffset);
169
170
printf ("\n ----- Begin Global Types Table -----\n");
171
172
types = PRD(fileoffset, sizeof(OMFGlobalTypes));
173
if (!types) {printf("Can't get OMF-GlobalTypes, aborting\n");return FALSE;}
174
175
sz = omfde->cb - sizeof(OMFGlobalTypes) - sizeof(DWORD) * types->cTypes;
176
data = PRD(fileoffset + sizeof(OMFGlobalTypes) + sizeof(DWORD) * types->cTypes, sz);
177
if (!data) {printf("Can't OMF-SymHash details, aborting\n"); return FALSE;}
178
179
/* doc says:
180
* - for NB07 & NB08 (that we don't support yet), offsets are from types
181
* - for NB09, offsets are from data
182
* For now, we only support the latter
183
*/
184
codeview_dump_types_from_offsets(data, (const DWORD*)(types + 1), types->cTypes);
185
186
return TRUE;
187
}
188
189
static BOOL dump_cv_sst_seg_map(const OMFDirEntry* omfde)
190
{
191
const OMFSegMap* segMap;
192
const OMFSegMapDesc* segMapDesc;
193
int i;
194
195
segMap = PRD(Offset(cv_base) + omfde->lfo, sizeof(OMFSegMap));
196
if (!segMap) {printf("Can't get SegMap, aborting\n");return FALSE;}
197
198
printf(" cSeg: %u\n", segMap->cSeg);
199
printf(" cSegLog: %u\n", segMap->cSegLog);
200
201
segMapDesc = PRD(Offset(segMap + 1), segMap->cSeg * sizeof(OMFSegDesc));
202
if (!segMapDesc) {printf("Can't get SegDescr array, aborting\n");return FALSE;}
203
204
for (i = 0; i < segMap->cSeg; i++)
205
{
206
printf(" SegDescr #%2d\n", i + 1);
207
printf(" flags: %04X\n", segMapDesc[i].flags);
208
printf(" ovl: %u\n", segMapDesc[i].ovl);
209
printf(" group: %u\n", segMapDesc[i].group);
210
printf(" frame: %u\n", segMapDesc[i].frame);
211
printf(" iSegName: %u\n", segMapDesc[i].iSegName);
212
printf(" iClassName: %u\n", segMapDesc[i].iClassName);
213
printf(" offset: %u\n", segMapDesc[i].offset);
214
printf(" cbSeg: %u\n", segMapDesc[i].cbSeg);
215
}
216
217
return TRUE;
218
}
219
220
static BOOL dump_cv_sst_file_index(const OMFDirEntry* omfde)
221
{
222
/*** NOT YET IMPLEMENTED ***/
223
return TRUE;
224
}
225
226
static BOOL dump_cv_sst_src_module(const OMFDirEntry* omfde)
227
{
228
int i, j;
229
const BYTE* rawdata;
230
const unsigned int *seg_info_dw;
231
const unsigned short* seg_info_w;
232
unsigned ofs;
233
const OMFSourceModule* sourceModule;
234
const OMFSourceFile* sourceFile;
235
const OMFSourceLine* sourceLine;
236
237
rawdata = PRD(Offset(cv_base) + omfde->lfo, omfde->cb);
238
if (!rawdata) {printf("Can't get srcModule subsection details, aborting\n");return FALSE;}
239
240
/* FIXME: check ptr validity */
241
sourceModule = (const void*)rawdata;
242
printf (" Module table: Found %d file(s) and %d segment(s)\n",
243
sourceModule->cFile, sourceModule->cSeg);
244
for (i = 0; i < sourceModule->cFile; i++)
245
{
246
printf (" File #%2d begins at an offset of 0x%x in this section\n",
247
i + 1, sourceModule->baseSrcFile[i]);
248
}
249
250
/* FIXME: check ptr validity */
251
seg_info_dw = (const void*)((const char*)(sourceModule + 1) +
252
sizeof(unsigned int) * (sourceModule->cFile - 1));
253
seg_info_w = (const unsigned short*)(&seg_info_dw[sourceModule->cSeg * 2]);
254
for (i = 0; i < sourceModule->cSeg; i++)
255
{
256
printf (" Segment #%2d start = 0x%x, end = 0x%x, seg index = %u\n",
257
i + 1, seg_info_dw[i * 2], seg_info_dw[(i * 2) + 1],
258
seg_info_w[i]);
259
}
260
ofs = sizeof(OMFSourceModule) + sizeof(unsigned int) * (sourceModule->cFile - 1) +
261
sourceModule->cSeg * (2 * sizeof(unsigned int) + sizeof(unsigned short));
262
ofs = (ofs + 3) & ~3;
263
264
/* the OMFSourceFile is quite unpleasant to use:
265
* we have first:
266
* unsigned short number of segments
267
* unsigned short reserved
268
* unsigned int baseSrcLn[# segments]
269
* unsigned int offset[2 * #segments]
270
* odd indices are start offsets
271
* even indices are end offsets
272
* unsigned char string length for file name
273
* char file name (length is previous field)
274
*/
275
/* FIXME: check ptr validity */
276
sourceFile = (const void*)(rawdata + ofs);
277
seg_info_dw = (const void*)((const char*)sourceFile + 2 * sizeof(unsigned short) +
278
sourceFile->cSeg * sizeof(unsigned int));
279
280
ofs += 2 * sizeof(unsigned short) + 3 * sourceFile->cSeg * sizeof(unsigned int);
281
282
printf(" File table: %.*s\n",
283
*(const BYTE*)((const char*)sourceModule + ofs), (const char*)sourceModule + ofs + 1);
284
285
for (i = 0; i < sourceFile->cSeg; i++)
286
{
287
printf (" Segment #%2d start = 0x%x, end = 0x%x, offset = 0x%x\n",
288
i + 1, seg_info_dw[i * 2], seg_info_dw[(i * 2) + 1], sourceFile->baseSrcLn[i]);
289
}
290
/* add file name length */
291
ofs += *(const BYTE*)((const char*)sourceModule + ofs) + 1;
292
ofs = (ofs + 3) & ~3;
293
294
for (i = 0; i < sourceModule->cSeg; i++)
295
{
296
sourceLine = (const void*)(rawdata + ofs);
297
seg_info_dw = (const void*)((const char*)sourceLine + 2 * sizeof(unsigned short));
298
seg_info_w = (const void*)(&seg_info_dw[sourceLine->cLnOff]);
299
300
printf (" Line table #%2d: Found %d line numbers for segment index %d\n",
301
i, sourceLine->cLnOff, sourceLine->Seg);
302
303
for (j = 0; j < sourceLine->cLnOff; j++)
304
{
305
printf (" Pair #%2d: offset = [0x%8x], linenumber = %d\n",
306
j + 1, seg_info_dw[j], seg_info_w[j]);
307
}
308
ofs += 2 * sizeof(unsigned short) +
309
sourceLine->cLnOff * (sizeof(unsigned int) + sizeof(unsigned short));
310
ofs = (ofs + 3) & ~3;
311
}
312
313
return TRUE;
314
}
315
316
static BOOL dump_cv_sst_align_sym(const OMFDirEntry* omfde)
317
{
318
const char* rawdata = PRD(Offset(cv_base) + omfde->lfo, omfde->cb);
319
320
if (!rawdata) {printf("Can't get srcAlignSym subsection details, aborting\n");return FALSE;}
321
if (omfde->cb < sizeof(DWORD)) return TRUE;
322
codeview_dump_symbols(rawdata, sizeof(DWORD), omfde->cb);
323
324
return TRUE;
325
}
326
327
static void dump_codeview_all_modules(const OMFDirHeader *omfdh)
328
{
329
unsigned i;
330
const OMFDirEntry* dirEntry;
331
const char* str;
332
333
if (!omfdh || !omfdh->cDir) return;
334
335
dirEntry = PRD(Offset(omfdh + 1), omfdh->cDir * sizeof(OMFDirEntry));
336
if (!dirEntry) {printf("Can't read DirEntry array, aborting\n"); return;}
337
338
for (i = 0; i < omfdh->cDir; i++)
339
{
340
switch (dirEntry[i].SubSection)
341
{
342
case sstModule: str = "sstModule"; break;
343
case sstAlignSym: str = "sstAlignSym"; break;
344
case sstSrcModule: str = "sstSrcModule"; break;
345
case sstLibraries: str = "sstLibraries"; break;
346
case sstGlobalSym: str = "sstGlobalSym"; break;
347
case sstGlobalPub: str = "sstGlobalPub"; break;
348
case sstGlobalTypes: str = "sstGlobalTypes"; break;
349
case sstSegMap: str = "sstSegMap"; break;
350
case sstFileIndex: str = "sstFileIndex"; break;
351
case sstStaticSym: str = "sstStaticSym"; break;
352
default: str = "<undefined>"; break;
353
}
354
printf("Module #%2d (%p)\n", i + 1, &dirEntry[i]);
355
printf(" SubSection: %04X (%s)\n", dirEntry[i].SubSection, str);
356
printf(" iMod: %d\n", dirEntry[i].iMod);
357
printf(" lfo: %d\n", dirEntry[i].lfo);
358
printf(" cb: %u\n", dirEntry[i].cb);
359
360
switch (dirEntry[i].SubSection)
361
{
362
case sstModule: dump_cv_sst_module(&dirEntry[i]); break;
363
case sstAlignSym: dump_cv_sst_align_sym(&dirEntry[i]); break;
364
case sstSrcModule: dump_cv_sst_src_module(&dirEntry[i]); break;
365
case sstLibraries: dump_cv_sst_libraries(&dirEntry[i]); break;
366
case sstGlobalSym: dump_cv_sst_global_sym(&dirEntry[i]); break;
367
case sstGlobalPub: dump_cv_sst_global_pub(&dirEntry[i]); break;
368
case sstGlobalTypes: dump_cv_sst_global_types(&dirEntry[i]); break;
369
case sstSegMap: dump_cv_sst_seg_map(&dirEntry[i]); break;
370
case sstFileIndex: dump_cv_sst_file_index(&dirEntry[i]); break;
371
case sstStaticSym: dump_cv_sst_static_sym(&dirEntry[i]); break;
372
default: printf("unsupported type %x\n", dirEntry[i].SubSection); break;
373
}
374
printf("\n");
375
}
376
377
return;
378
}
379
380
static void dump_codeview_headers(unsigned long base, unsigned long len)
381
{
382
const OMFDirHeader* dirHeader;
383
const char* signature;
384
const OMFDirEntry* dirEntry;
385
const OMFSignature* sig;
386
unsigned i;
387
int modulecount = 0, alignsymcount = 0, srcmodulecount = 0, librariescount = 0;
388
int globalsymcount = 0, globalpubcount = 0, globaltypescount = 0;
389
int segmapcount = 0, fileindexcount = 0, staticsymcount = 0;
390
391
cv_base = PRD(base, len);
392
if (!cv_base) {printf("Can't get full debug content, aborting\n");return;}
393
394
signature = cv_base;
395
396
printf(" CodeView Data\n");
397
printf(" Signature: %.4s\n", signature);
398
399
if (memcmp(signature, "NB10", 4) == 0)
400
{
401
const CODEVIEW_PDB_DATA* pdb_data;
402
pdb_data = cv_base;
403
404
printf(" Filepos: 0x%08X\n", pdb_data->filepos);
405
printf(" TimeStamp: %08X (%s)\n",
406
pdb_data->timestamp, get_time_str(pdb_data->timestamp));
407
printf(" Age: %08X\n", pdb_data->age);
408
printf(" Filename: %s\n", pdb_data->name);
409
return;
410
}
411
if (memcmp(signature, "RSDS", 4) == 0)
412
{
413
const OMFSignatureRSDS* rsds_data;
414
415
rsds_data = cv_base;
416
printf(" Guid: %s\n", get_guid_str(&rsds_data->guid));
417
printf(" Age: %08X\n", rsds_data->age);
418
printf(" Filename: %s\n", rsds_data->name);
419
return;
420
}
421
422
if (memcmp(signature, "NB09", 4) != 0 && memcmp(signature, "NB11", 4) != 0)
423
{
424
printf("Unsupported signature (%.4s), aborting\n", signature);
425
return;
426
}
427
428
sig = cv_base;
429
430
printf(" Filepos: 0x%08X\n", sig->filepos);
431
432
dirHeader = PRD(Offset(cv_base) + sig->filepos, sizeof(OMFDirHeader));
433
if (!dirHeader) {printf("Can't get debug header, aborting\n"); return;}
434
435
printf(" Size of header: 0x%4X\n", dirHeader->cbDirHeader);
436
printf(" Size per entry: 0x%4X\n", dirHeader->cbDirEntry);
437
printf(" # of entries: 0x%8X (%d)\n", dirHeader->cDir, dirHeader->cDir);
438
printf(" Offset to NextDir: 0x%8X\n", dirHeader->lfoNextDir);
439
printf(" Flags: 0x%8X\n", dirHeader->flags);
440
441
if (!dirHeader->cDir) return;
442
443
dirEntry = PRD(Offset(dirHeader + 1), sizeof(OMFDirEntry) * dirHeader->cDir);
444
if (!dirEntry) {printf("Can't get DirEntry array, aborting\n");return;}
445
446
for (i = 0; i < dirHeader->cDir; i++)
447
{
448
switch (dirEntry[i].SubSection)
449
{
450
case sstModule: modulecount++; break;
451
case sstAlignSym: alignsymcount++; break;
452
case sstSrcModule: srcmodulecount++; break;
453
case sstLibraries: librariescount++; break;
454
case sstGlobalSym: globalsymcount++; break;
455
case sstGlobalPub: globalpubcount++; break;
456
case sstGlobalTypes: globaltypescount++; break;
457
case sstSegMap: segmapcount++; break;
458
case sstFileIndex: fileindexcount++; break;
459
case sstStaticSym: staticsymcount++; break;
460
}
461
}
462
463
/* This one has to be > 0
464
*/
465
printf ("\nFound: %d sstModule subsections\n", modulecount);
466
467
if (alignsymcount > 0) printf (" %d sstAlignSym subsections\n", alignsymcount);
468
if (srcmodulecount > 0) printf (" %d sstSrcModule subsections\n", srcmodulecount);
469
if (librariescount > 0) printf (" %d sstLibraries subsections\n", librariescount);
470
if (globalsymcount > 0) printf (" %d sstGlobalSym subsections\n", globalsymcount);
471
if (globalpubcount > 0) printf (" %d sstGlobalPub subsections\n", globalpubcount);
472
if (globaltypescount > 0) printf (" %d sstGlobalTypes subsections\n", globaltypescount);
473
if (segmapcount > 0) printf (" %d sstSegMap subsections\n", segmapcount);
474
if (fileindexcount > 0) printf (" %d sstFileIndex subsections\n", fileindexcount);
475
if (staticsymcount > 0) printf (" %d sstStaticSym subsections\n", staticsymcount);
476
477
dump_codeview_all_modules(dirHeader);
478
}
479
480
static const char *get_coff_name( const IMAGE_SYMBOL *coff_sym, const char *coff_strtab )
481
{
482
static char namebuff[9];
483
const char* nampnt;
484
485
if( coff_sym->N.Name.Short )
486
{
487
memcpy(namebuff, coff_sym->N.ShortName, 8);
488
namebuff[8] = '\0';
489
nampnt = namebuff;
490
}
491
else
492
{
493
nampnt = coff_strtab + coff_sym->N.Name.Long;
494
}
495
496
if( nampnt[0] == '_' )
497
nampnt++;
498
return nampnt;
499
}
500
501
static const char* storage_class(BYTE sc)
502
{
503
static char tmp[7];
504
switch (sc)
505
{
506
case IMAGE_SYM_CLASS_STATIC: return "static";
507
case IMAGE_SYM_CLASS_EXTERNAL: return "extrnl";
508
case IMAGE_SYM_CLASS_LABEL: return "label ";
509
}
510
sprintf(tmp, "#%d", sc);
511
return tmp;
512
}
513
514
void dump_coff_symbol_table(const IMAGE_SYMBOL *coff_symbols, unsigned num_sym,
515
const IMAGE_SECTION_HEADER *sectHead)
516
{
517
const IMAGE_SYMBOL *coff_sym;
518
const char *coff_strtab = (const char *) (coff_symbols + num_sym);
519
unsigned int i;
520
const char *nampnt;
521
int naux;
522
523
printf("\nDebug table: COFF format.\n");
524
printf(" ID | seg:offs [ abs ] | Kind | symbol/function name\n");
525
for (i=0; i < num_sym; i++)
526
{
527
coff_sym = coff_symbols + i;
528
naux = coff_sym->NumberOfAuxSymbols;
529
530
switch (coff_sym->StorageClass)
531
{
532
case IMAGE_SYM_CLASS_FILE:
533
printf("file %s\n", (const char *) (coff_sym + 1));
534
break;
535
case IMAGE_SYM_CLASS_STATIC:
536
case IMAGE_SYM_CLASS_EXTERNAL:
537
case IMAGE_SYM_CLASS_LABEL:
538
if (coff_sym->SectionNumber > 0)
539
{
540
UINT base = sectHead[coff_sym->SectionNumber - 1].VirtualAddress;
541
nampnt = get_coff_name( coff_sym, coff_strtab );
542
543
printf("%05d | %02d:%08x [%08x] | %s | %s\n",
544
i, coff_sym->SectionNumber - 1, (UINT)coff_sym->Value,
545
base + (UINT)coff_sym->Value,
546
storage_class(coff_sym->StorageClass), nampnt);
547
}
548
break;
549
default:
550
printf("%05d | %s\n", i, storage_class(coff_sym->StorageClass));
551
}
552
/*
553
* For now, skip past the aux entries.
554
*/
555
i += naux;
556
}
557
}
558
559
void dump_coff(unsigned long coffbase, unsigned long len, const IMAGE_SECTION_HEADER* sectHead)
560
{
561
const IMAGE_COFF_SYMBOLS_HEADER *coff = PRD(coffbase, len);
562
const IMAGE_SYMBOL *coff_symbols =
563
(const IMAGE_SYMBOL *) ((const char *)coff + coff->LvaToFirstSymbol);
564
565
dump_coff_symbol_table(coff_symbols, coff->NumberOfSymbols, sectHead);
566
}
567
568
void dump_codeview(unsigned long base, unsigned long len)
569
{
570
dump_codeview_headers(base, len);
571
}
572
573
void dump_frame_pointer_omission(unsigned long base, unsigned long len)
574
{
575
const FPO_DATA* fpo;
576
const FPO_DATA* last;
577
const char* x;
578
/* FPO is used to describe nonstandard stack frames */
579
printf("Range #loc #pmt Prlg #reg Info\n"
580
"-----------------+----+----+----+----+------------\n");
581
582
fpo = PRD(base, len);
583
if (!fpo) {printf("Couldn't get FPO blob\n"); return;}
584
last = (const FPO_DATA*)((const char*)fpo + len);
585
586
while (fpo < last && fpo->ulOffStart)
587
{
588
switch (fpo->cbFrame)
589
{
590
case FRAME_FPO: x = "FRAME_FPO"; break;
591
case FRAME_NONFPO: x = "FRAME_NONFPO"; break;
592
case FRAME_TRAP: x = "FRAME_TRAP"; break;
593
case FRAME_TSS: x = "case FRAME_TSS"; break;
594
default: x = NULL; break;
595
}
596
printf("%08x-%08x %4u %4u %4u %4u %s%s%s\n",
597
(UINT)fpo->ulOffStart, (UINT)(fpo->ulOffStart + fpo->cbProcSize),
598
(UINT)fpo->cdwLocals, fpo->cdwParams, fpo->cbProlog, fpo->cbRegs,
599
x, fpo->fHasSEH ? " SEH" : "", fpo->fUseBP ? " UseBP" : "");
600
fpo++;
601
}
602
}
603
604
struct stab_nlist
605
{
606
union
607
{
608
char* n_name;
609
struct stab_nlist* n_next;
610
int n_strx;
611
} n_un;
612
unsigned char n_type;
613
char n_other;
614
short n_desc;
615
unsigned int n_value;
616
};
617
618
static const char * const stabs_defs[] = {
619
NULL,NULL,NULL,NULL, /* 00 */
620
NULL,NULL,NULL,NULL, /* 08 */
621
NULL,NULL,NULL,NULL, /* 10 */
622
NULL,NULL,NULL,NULL, /* 18 */
623
"GSYM","FNAME","FUN","STSYM", /* 20 */
624
"LCSYM","MAIN","ROSYM","PC", /* 28 */
625
NULL,"NSYMS","NOMAP",NULL, /* 30 */
626
"OBJ",NULL,"OPT",NULL, /* 38 */
627
"RSYM","M2C","SLINE","DSLINE", /* 40 */
628
"BSLINE","DEFD","FLINE",NULL, /* 48 */
629
"EHDECL",NULL,"CATCH",NULL, /* 50 */
630
NULL,NULL,NULL,NULL, /* 58 */
631
"SSYM","ENDM","SO",NULL, /* 60 */
632
NULL,NULL,NULL,NULL, /* 68 */
633
NULL,NULL,NULL,NULL, /* 70 */
634
NULL,NULL,NULL,NULL, /* 78 */
635
"LSYM","BINCL","SOL",NULL, /* 80 */
636
NULL,NULL,NULL,NULL, /* 88 */
637
NULL,NULL,NULL,NULL, /* 90 */
638
NULL,NULL,NULL,NULL, /* 98 */
639
"PSYM","EINCL","ENTRY",NULL, /* a0 */
640
NULL,NULL,NULL,NULL, /* a8 */
641
NULL,NULL,NULL,NULL, /* b0 */
642
NULL,NULL,NULL,NULL, /* b8 */
643
"LBRAC","EXCL","SCOPE",NULL, /* c0 */
644
NULL,NULL,NULL,NULL, /* c8 */
645
NULL,NULL,NULL,NULL, /* d0 */
646
NULL,NULL,NULL,NULL, /* d8 */
647
"RBRAC","BCOMM","ECOMM",NULL, /* e0 */
648
"ECOML","WITH",NULL,NULL, /* e8 */
649
"NBTEXT","NBDATA","NBBSS","NBSTS", /* f0 */
650
"NBLCS",NULL,NULL,NULL /* f8 */
651
};
652
653
void dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr)
654
{
655
int i;
656
int nstab;
657
const char* ptr;
658
char* stabbuff;
659
unsigned int stabbufflen;
660
const struct stab_nlist* stab_ptr = pv_stabs;
661
const char* strs_end;
662
char n_buffer[16];
663
664
nstab = szstabs / sizeof(struct stab_nlist);
665
strs_end = stabstr + szstr;
666
667
/*
668
* Allocate a buffer into which we can build stab strings for cases
669
* where the stab is continued over multiple lines.
670
*/
671
stabbufflen = 65536;
672
stabbuff = xmalloc(stabbufflen);
673
674
stabbuff[0] = '\0';
675
676
printf("#Sym n_type n_othr n_desc n_value n_strx String\n");
677
678
for (i = 0; i < nstab; i++, stab_ptr++)
679
{
680
ptr = stabstr + stab_ptr->n_un.n_strx;
681
if ((ptr > strs_end) || (ptr + strlen(ptr) > strs_end))
682
{
683
ptr = "[[*** bad string ***]]";
684
}
685
else if (ptr[strlen(ptr) - 1] == '\\')
686
{
687
/*
688
* Indicates continuation. Append this to the buffer, and go onto the
689
* next record. Repeat the process until we find a stab without the
690
* '/' character, as this indicates we have the whole thing.
691
*/
692
unsigned len = strlen(ptr);
693
if (strlen(stabbuff) + len > stabbufflen)
694
{
695
stabbufflen += 65536;
696
stabbuff = xrealloc(stabbuff, stabbufflen);
697
}
698
strcat(stabbuff, ptr);
699
continue;
700
}
701
else if (stabbuff[0] != '\0')
702
{
703
strcat(stabbuff, ptr);
704
ptr = stabbuff;
705
}
706
if ((stab_ptr->n_type & 1) || !stabs_defs[stab_ptr->n_type / 2])
707
sprintf(n_buffer, "<0x%02x>", stab_ptr->n_type);
708
else
709
sprintf(n_buffer, "%-6s", stabs_defs[stab_ptr->n_type / 2]);
710
printf("%4d %s %-8x % 6d %-8x %-6x %s\n",
711
i, n_buffer, stab_ptr->n_other, stab_ptr->n_desc, stab_ptr->n_value,
712
stab_ptr->n_un.n_strx, ptr);
713
}
714
free(stabbuff);
715
}
716
717