dxgi: Remove DECLSPEC_HIDDEN usage.
[wine.git] / tools / winedump / debug.c
blobe62e4436e4d7c066b74260e046baf9460907af2e
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
6 * Copyright 2000 John R. Sheets
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.
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.
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
23 #include "config.h"
25 #include <stdlib.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <time.h>
30 #include "../tools.h"
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winedump.h"
36 * .DBG File Layout:
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[]
51 * Descriptions:
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
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
77 * IMAGE_SECTION_HEADER - number of entries determined by:
78 * (IMAGE_SEPARATE_DEBUG_HEADER.NumberOfSections)
80 * IMAGE_DEBUG_DIRECTORY - number of entries determined by:
81 * (IMAGE_SEPARATE_DEBUG_HEADER.DebugDirectorySize / sizeof (IMAGE_DEBUG_DIRECTORY))
83 * OMFDirEntry - number of entries determined by:
84 * (OMFDirHeader.cDir)
87 extern const IMAGE_NT_HEADERS* PE_nt_headers;
88 static const void* cv_base /* = 0 */;
90 static BOOL dump_cv_sst_module(const OMFDirEntry* omfde)
92 const OMFModule* module;
93 const OMFSegDesc* segDesc;
94 int i;
96 module = PRD(Offset(cv_base) + omfde->lfo, sizeof(OMFModule));
97 if (!module) {printf("Can't get the OMF-Module, aborting\n"); return FALSE;}
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);
107 segDesc = PRD(Offset(module + 1), sizeof(OMFSegDesc) * module->cSeg);
108 if (!segDesc) {printf("Can't get the OMF-SegDesc, aborting\n"); return FALSE;}
110 for (i = 0; i < module->cSeg; i++)
112 printf (" segment #%2d: offset = [0x%8x], size = [0x%8x]\n",
113 segDesc->Seg, segDesc->Off, segDesc->cbSeg);
114 segDesc++;
116 return TRUE;
119 static BOOL dump_cv_sst_global_pub(const OMFDirEntry* omfde)
121 long fileoffset;
122 const OMFSymHash* header;
123 const BYTE* symbols;
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));
129 printf ("\n ----- Begin Symbol Table -----\n");
131 header = PRD(fileoffset, sizeof(OMFSymHash));
132 if (!header) {printf("Can't get OMF-SymHash, aborting\n");return FALSE;}
134 symbols = PRD(fileoffset + sizeof(OMFSymHash), header->cbSymbol);
135 if (!symbols) {printf("Can't OMF-SymHash details, aborting\n"); return FALSE;}
137 codeview_dump_symbols(symbols, 0, header->cbSymbol);
139 return TRUE;
142 static BOOL dump_cv_sst_global_sym(const OMFDirEntry* omfde)
144 /*** NOT YET IMPLEMENTED ***/
145 return TRUE;
148 static BOOL dump_cv_sst_static_sym(const OMFDirEntry* omfde)
150 /*** NOT YET IMPLEMENTED ***/
151 return TRUE;
154 static BOOL dump_cv_sst_libraries(const OMFDirEntry* omfde)
156 /*** NOT YET IMPLEMENTED ***/
157 return TRUE;
160 static BOOL dump_cv_sst_global_types(const OMFDirEntry* omfde)
162 long fileoffset;
163 const OMFGlobalTypes*types;
164 const BYTE* data;
165 unsigned sz;
167 fileoffset = Offset(cv_base) + omfde->lfo;
168 printf (" GlobalTypes section starts at file offset 0x%lx\n", fileoffset);
170 printf ("\n ----- Begin Global Types Table -----\n");
172 types = PRD(fileoffset, sizeof(OMFGlobalTypes));
173 if (!types) {printf("Can't get OMF-GlobalTypes, aborting\n");return FALSE;}
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;}
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
184 codeview_dump_types_from_offsets(data, (const DWORD*)(types + 1), types->cTypes);
186 return TRUE;
189 static BOOL dump_cv_sst_seg_map(const OMFDirEntry* omfde)
191 const OMFSegMap* segMap;
192 const OMFSegMapDesc* segMapDesc;
193 int i;
195 segMap = PRD(Offset(cv_base) + omfde->lfo, sizeof(OMFSegMap));
196 if (!segMap) {printf("Can't get SegMap, aborting\n");return FALSE;}
198 printf(" cSeg: %u\n", segMap->cSeg);
199 printf(" cSegLog: %u\n", segMap->cSegLog);
201 segMapDesc = PRD(Offset(segMap + 1), segMap->cSeg * sizeof(OMFSegDesc));
202 if (!segMapDesc) {printf("Can't get SegDescr array, aborting\n");return FALSE;}
204 for (i = 0; i < segMap->cSeg; i++)
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);
217 return TRUE;
220 static BOOL dump_cv_sst_file_index(const OMFDirEntry* omfde)
222 /*** NOT YET IMPLEMENTED ***/
223 return TRUE;
226 static BOOL dump_cv_sst_src_module(const OMFDirEntry* omfde)
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;
237 rawdata = PRD(Offset(cv_base) + omfde->lfo, omfde->cb);
238 if (!rawdata) {printf("Can't get srcModule subsection details, aborting\n");return FALSE;}
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++)
246 printf (" File #%2d begins at an offset of 0x%x in this section\n",
247 i + 1, sourceModule->baseSrcFile[i]);
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++)
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]);
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;
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)
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));
280 ofs += 2 * sizeof(unsigned short) + 3 * sourceFile->cSeg * sizeof(unsigned int);
282 printf(" File table: %.*s\n",
283 *(const BYTE*)((const char*)sourceModule + ofs), (const char*)sourceModule + ofs + 1);
285 for (i = 0; i < sourceFile->cSeg; i++)
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]);
290 /* add file name length */
291 ofs += *(const BYTE*)((const char*)sourceModule + ofs) + 1;
292 ofs = (ofs + 3) & ~3;
294 for (i = 0; i < sourceModule->cSeg; i++)
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]);
300 printf (" Line table #%2d: Found %d line numbers for segment index %d\n",
301 i, sourceLine->cLnOff, sourceLine->Seg);
303 for (j = 0; j < sourceLine->cLnOff; j++)
305 printf (" Pair #%2d: offset = [0x%8x], linenumber = %d\n",
306 j + 1, seg_info_dw[j], seg_info_w[j]);
308 ofs += 2 * sizeof(unsigned short) +
309 sourceLine->cLnOff * (sizeof(unsigned int) + sizeof(unsigned short));
310 ofs = (ofs + 3) & ~3;
313 return TRUE;
316 static BOOL dump_cv_sst_align_sym(const OMFDirEntry* omfde)
318 const char* rawdata = PRD(Offset(cv_base) + omfde->lfo, omfde->cb);
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);
324 return TRUE;
327 static void dump_codeview_all_modules(const OMFDirHeader *omfdh)
329 unsigned i;
330 const OMFDirEntry* dirEntry;
331 const char* str;
333 if (!omfdh || !omfdh->cDir) return;
335 dirEntry = PRD(Offset(omfdh + 1), omfdh->cDir * sizeof(OMFDirEntry));
336 if (!dirEntry) {printf("Can't read DirEntry array, aborting\n"); return;}
338 for (i = 0; i < omfdh->cDir; i++)
340 switch (dirEntry[i].SubSection)
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;
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);
360 switch (dirEntry[i].SubSection)
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;
374 printf("\n");
377 return;
380 static void dump_codeview_headers(unsigned long base, unsigned long len)
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;
391 cv_base = PRD(base, len);
392 if (!cv_base) {printf("Can't get full debug content, aborting\n");return;}
394 signature = cv_base;
396 printf(" CodeView Data\n");
397 printf(" Signature: %.4s\n", signature);
399 if (memcmp(signature, "NB10", 4) == 0)
401 const CODEVIEW_PDB_DATA* pdb_data;
402 pdb_data = cv_base;
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;
411 if (memcmp(signature, "RSDS", 4) == 0)
413 const OMFSignatureRSDS* rsds_data;
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;
422 if (memcmp(signature, "NB09", 4) != 0 && memcmp(signature, "NB11", 4) != 0)
424 printf("Unsupported signature (%.4s), aborting\n", signature);
425 return;
428 sig = cv_base;
430 printf(" Filepos: 0x%08X\n", sig->filepos);
432 dirHeader = PRD(Offset(cv_base) + sig->filepos, sizeof(OMFDirHeader));
433 if (!dirHeader) {printf("Can't get debug header, aborting\n"); return;}
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);
441 if (!dirHeader->cDir) return;
443 dirEntry = PRD(Offset(dirHeader + 1), sizeof(OMFDirEntry) * dirHeader->cDir);
444 if (!dirEntry) {printf("Can't get DirEntry array, aborting\n");return;}
446 for (i = 0; i < dirHeader->cDir; i++)
448 switch (dirEntry[i].SubSection)
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;
463 /* This one has to be > 0
465 printf ("\nFound: %d sstModule subsections\n", modulecount);
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);
477 dump_codeview_all_modules(dirHeader);
480 static const char *get_coff_name( const IMAGE_SYMBOL *coff_sym, const char *coff_strtab )
482 static char namebuff[9];
483 const char* nampnt;
485 if( coff_sym->N.Name.Short )
487 memcpy(namebuff, coff_sym->N.ShortName, 8);
488 namebuff[8] = '\0';
489 nampnt = namebuff;
491 else
493 nampnt = coff_strtab + coff_sym->N.Name.Long;
496 if( nampnt[0] == '_' )
497 nampnt++;
498 return nampnt;
501 static const char* storage_class(BYTE sc)
503 static char tmp[7];
504 switch (sc)
506 case IMAGE_SYM_CLASS_STATIC: return "static";
507 case IMAGE_SYM_CLASS_EXTERNAL: return "extrnl";
508 case IMAGE_SYM_CLASS_LABEL: return "label ";
510 sprintf(tmp, "#%d", sc);
511 return tmp;
514 void dump_coff_symbol_table(const IMAGE_SYMBOL *coff_symbols, unsigned num_sym,
515 const IMAGE_SECTION_HEADER *sectHead)
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;
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++)
527 coff_sym = coff_symbols + i;
528 naux = coff_sym->NumberOfAuxSymbols;
530 switch (coff_sym->StorageClass)
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)
540 UINT base = sectHead[coff_sym->SectionNumber - 1].VirtualAddress;
541 nampnt = get_coff_name( coff_sym, coff_strtab );
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);
548 break;
549 default:
550 printf("%05d | %s\n", i, storage_class(coff_sym->StorageClass));
553 * For now, skip past the aux entries.
555 i += naux;
559 void dump_coff(unsigned long coffbase, unsigned long len, const IMAGE_SECTION_HEADER* sectHead)
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);
565 dump_coff_symbol_table(coff_symbols, coff->NumberOfSymbols, sectHead);
568 void dump_codeview(unsigned long base, unsigned long len)
570 dump_codeview_headers(base, len);
573 void dump_frame_pointer_omission(unsigned long base, unsigned long len)
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");
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);
586 while (fpo < last && fpo->ulOffStart)
588 switch (fpo->cbFrame)
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;
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++;
604 struct stab_nlist
606 union
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;
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 */
653 void dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr)
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];
664 nstab = szstabs / sizeof(struct stab_nlist);
665 strs_end = stabstr + szstr;
668 * Allocate a buffer into which we can build stab strings for cases
669 * where the stab is continued over multiple lines.
671 stabbufflen = 65536;
672 stabbuff = xmalloc(stabbufflen);
674 stabbuff[0] = '\0';
676 printf("#Sym n_type n_othr n_desc n_value n_strx String\n");
678 for (i = 0; i < nstab; i++, stab_ptr++)
680 ptr = stabstr + stab_ptr->n_un.n_strx;
681 if ((ptr > strs_end) || (ptr + strlen(ptr) > strs_end))
683 ptr = "[[*** bad string ***]]";
685 else if (ptr[strlen(ptr) - 1] == '\\')
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.
692 unsigned len = strlen(ptr);
693 if (strlen(stabbuff) + len > stabbufflen)
695 stabbufflen += 65536;
696 stabbuff = xrealloc(stabbuff, stabbufflen);
698 strcat(stabbuff, ptr);
699 continue;
701 else if (stabbuff[0] != '\0')
703 strcat(stabbuff, ptr);
704 ptr = stabbuff;
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);
714 free(stabbuff);