urlmon: Added application/java mime filter.
[wine/wine64.git] / tools / winedump / debug.c
blob4ce09c85aaaf93777157abd9767a3979651043b5
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"
24 #include "wine/port.h"
26 #include <stdlib.h>
27 #include <stdarg.h>
28 #include <stdio.h>
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
32 #include <time.h>
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
35 #endif
36 #ifdef HAVE_SYS_STAT_H
37 # include <sys/stat.h>
38 #endif
39 #ifdef HAVE_SYS_MMAN_H
40 #include <sys/mman.h>
41 #endif
42 #include <fcntl.h>
44 #include "windef.h"
45 #include "winbase.h"
46 #include "winedump.h"
47 #include "cvinclude.h"
50 * .DBG File Layout:
52 * IMAGE_SEPARATE_DEBUG_HEADER
53 * IMAGE_SECTION_HEADER[]
54 * IMAGE_DEBUG_DIRECTORY[]
55 * OMFSignature
56 * debug data (typical example)
57 * - IMAGE_DEBUG_TYPE_MISC
58 * - IMAGE_DEBUG_TYPE_FPO
59 * - IMAGE_DEBUG_TYPE_CODEVIEW
60 * OMFDirHeader
61 * OMFDirEntry[]
65 * Descriptions:
67 * (hdr) IMAGE_SEPARATE_DEBUG_HEADER - .DBG-specific file header; holds info that
68 * applies to the file as a whole, including # of COFF sections, file offsets, etc.
69 * (hdr) IMAGE_SECTION_HEADER - list of COFF sections copied verbatim from .EXE;
70 * although this directory contains file offsets, these offsets are meaningless
71 * in the context of the .DBG file, because only the section headers are copied
72 * to the .DBG file...not the binary data it points to.
73 * (hdr) IMAGE_DEBUG_DIRECTORY - list of different formats of debug info contained in file
74 * (see IMAGE_DEBUG_TYPE_* descriptions below); tells where each section starts
75 * (hdr) OMFSignature (CV) - Contains "NBxx" signature, plus file offset telling how far
76 * into the IMAGE_DEBUG_TYPE_CODEVIEW section the OMFDirHeader and OMFDirEntry's sit
77 * (data) IMAGE_DEBUG_TYPE_MISC - usually holds name of original .EXE file
78 * (data) IMAGE_DEBUG_TYPE_FPO - Frame Pointer Optimization data; used for dealing with
79 * optimized stack frames (optional)
80 * (data) IMAGE_DEBUG_TYPE_CODEVIEW - *** THE GOOD STUFF ***
81 * This block of data contains all the symbol tables, line number info, etc.,
82 * that the Visual C++ debugger needs.
83 * (hdr) OMFDirHeader (CV) -
84 * (hdr) OMFDirEntry (CV) - list of subsections within CodeView debug data section
88 * The .DBG file typically has three arrays of directory entries, which tell
89 * the OS or debugger where in the file to look for the actual data
91 * IMAGE_SECTION_HEADER - number of entries determined by:
92 * (IMAGE_SEPARATE_DEBUG_HEADER.NumberOfSections)
94 * IMAGE_DEBUG_DIRECTORY - number of entries determined by:
95 * (IMAGE_SEPARATE_DEBUG_HEADER.DebugDirectorySize / sizeof (IMAGE_DEBUG_DIRECTORY))
97 * OMFDirEntry - number of entries determined by:
98 * (OMFDirHeader.cDir)
101 extern const IMAGE_NT_HEADERS* PE_nt_headers;
102 static const void* cv_base /* = 0 */;
104 static int dump_cv_sst_module(const OMFDirEntry* omfde)
106 const OMFModule* module;
107 const OMFSegDesc* segDesc;
108 int i;
110 module = PRD(Offset(cv_base) + omfde->lfo, sizeof(OMFModule));
111 if (!module) {printf("Can't get the OMF-Module, aborting\n"); return FALSE;}
113 printf(" olvNumber: %u\n", module->ovlNumber);
114 printf(" iLib: %u\n", module->iLib);
115 printf(" cSeg: %u\n", module->cSeg);
116 printf(" Style: %c%c\n", module->Style[0], module->Style[1]);
117 printf(" Name: %.*s\n",
118 *(const BYTE*)((const char*)(module + 1) + sizeof(OMFSegDesc) * module->cSeg),
119 (const char*)(module + 1) + sizeof(OMFSegDesc) * module->cSeg + 1);
121 segDesc = PRD(Offset(module + 1), sizeof(OMFSegDesc) * module->cSeg);
122 if (!segDesc) {printf("Can't get the OMF-SegDesc, aborting\n"); return FALSE;}
124 for (i = 0; i < module->cSeg; i++)
126 printf (" segment #%2d: offset = [0x%8lx], size = [0x%8lx]\n",
127 segDesc->Seg, segDesc->Off, segDesc->cbSeg);
128 segDesc++;
130 return TRUE;
133 static int dump_cv_sst_global_pub(const OMFDirEntry* omfde)
135 long fileoffset;
136 const OMFSymHash* header;
137 const BYTE* symbols;
138 const BYTE* curpos;
139 const PUBSYM32* sym;
140 unsigned symlen;
141 int recordlen;
142 char nametmp[256];
144 fileoffset = Offset(cv_base) + omfde->lfo;
145 printf (" GlobalPub section starts at file offset 0x%lx\n", fileoffset);
146 printf (" Symbol table starts at 0x%lx\n", fileoffset + sizeof (OMFSymHash));
148 printf ("\n ----- Begin Symbol Table -----\n");
149 printf (" (type) (symbol name) (offset) (len) (seg) (ind)\n");
151 header = PRD(fileoffset, sizeof(OMFSymHash));
152 if (!header) {printf("Can't get OMF-SymHash, aborting\n");return FALSE;}
154 symbols = PRD(fileoffset + sizeof(OMFSymHash), header->cbSymbol);
155 if (!symbols) {printf("Can't OMF-SymHash details, aborting\n"); return FALSE;}
157 /* We don't know how many symbols are in this block of memory...only what
158 * the total size of the block is. Because the symbol's name is tacked
159 * on to the end of the PUBSYM32 struct, each symbol may take up a different
160 * # of bytes. This makes it harder to parse through the symbol table,
161 * since we won't know the exact location of the following symbol until we've
162 * already parsed the current one.
164 for (curpos = symbols; curpos < symbols + header->cbSymbol; curpos += recordlen)
166 /* Point to the next PUBSYM32 in the table.
168 sym = (const PUBSYM32*)curpos;
170 if (sym->reclen < sizeof(PUBSYM32)) break;
172 symlen = sym->reclen - sizeof(PUBSYM32) + 1;
173 if (symlen > sizeof(nametmp)) {printf("\nsqueeze%d\n", symlen);symlen = sizeof(nametmp) - 1;}
175 memcpy(nametmp, curpos + sizeof (PUBSYM32) + 1, symlen);
176 nametmp[symlen] = '\0';
178 printf (" 0x%04x %-30.30s [0x%8lx] [0x%4x] %d %ld\n",
179 sym->rectyp, nametmp, sym->off, sym->reclen, sym->seg, sym->typind);
181 /* The entire record is null-padded to the nearest 4-byte
182 * boundary, so we must do a little extra math to keep things straight.
184 recordlen = (sym->reclen + 3) & ~3;
187 return TRUE;
190 static int dump_cv_sst_global_sym(const OMFDirEntry* omfde)
192 /*** NOT YET IMPLEMENTED ***/
193 return TRUE;
196 static int dump_cv_sst_static_sym(const OMFDirEntry* omfde)
198 /*** NOT YET IMPLEMENTED ***/
199 return TRUE;
202 static int dump_cv_sst_libraries(const OMFDirEntry* omfde)
204 /*** NOT YET IMPLEMENTED ***/
205 return TRUE;
208 static int dump_cv_sst_global_types(const OMFDirEntry* omfde)
210 /*** NOT YET IMPLEMENTED ***/
211 return TRUE;
214 static int dump_cv_sst_seg_map(const OMFDirEntry* omfde)
216 const OMFSegMap* segMap;
217 const OMFSegMapDesc* segMapDesc;
218 int i;
220 segMap = PRD(Offset(cv_base) + omfde->lfo, sizeof(OMFSegMap));
221 if (!segMap) {printf("Can't get SegMap, aborting\n");return FALSE;}
223 printf(" cSeg: %u\n", segMap->cSeg);
224 printf(" cSegLog: %u\n", segMap->cSegLog);
226 segMapDesc = PRD(Offset(segMap + 1), segMap->cSeg * sizeof(OMFSegDesc));
227 if (!segMapDesc) {printf("Can't get SegDescr array, aborting\n");return FALSE;}
229 for (i = 0; i < segMap->cSeg; i++)
231 printf(" SegDescr #%2d\n", i + 1);
232 printf(" flags: %04X\n", segMapDesc[i].flags);
233 printf(" ovl: %u\n", segMapDesc[i].ovl);
234 printf(" group: %u\n", segMapDesc[i].group);
235 printf(" frame: %u\n", segMapDesc[i].frame);
236 printf(" iSegName: %u\n", segMapDesc[i].iSegName);
237 printf(" iClassName: %u\n", segMapDesc[i].iClassName);
238 printf(" offset: %lu\n", segMapDesc[i].offset);
239 printf(" cbSeg: %lu\n", segMapDesc[i].cbSeg);
242 return TRUE;
245 static int dump_cv_sst_file_index(const OMFDirEntry* omfde)
247 /*** NOT YET IMPLEMENTED ***/
248 return TRUE;
251 static int dump_cv_sst_src_module(const OMFDirEntry* omfde)
253 int i, j;
254 const BYTE* rawdata;
255 const unsigned long* seg_info_dw;
256 const unsigned short* seg_info_w;
257 unsigned ofs;
258 const OMFSourceModule* sourceModule;
259 const OMFSourceFile* sourceFile;
260 const OMFSourceLine* sourceLine;
262 rawdata = PRD(Offset(cv_base) + omfde->lfo, omfde->cb);
263 if (!rawdata) {printf("Can't get srcModule subsection details, aborting\n");return FALSE;}
265 /* FIXME: check ptr validity */
266 sourceModule = (const void*)rawdata;
267 printf (" Module table: Found %d file(s) and %d segment(s)\n",
268 sourceModule->cFile, sourceModule->cSeg);
269 for (i = 0; i < sourceModule->cFile; i++)
271 printf (" File #%2d begins at an offset of 0x%lx in this section\n",
272 i + 1, sourceModule->baseSrcFile[i]);
275 /* FIXME: check ptr validity */
276 seg_info_dw = (const void*)((const char*)(sourceModule + 1) +
277 sizeof(unsigned long) * (sourceModule->cFile - 1));
278 seg_info_w = (const unsigned short*)(&seg_info_dw[sourceModule->cSeg * 2]);
279 for (i = 0; i < sourceModule->cSeg; i++)
281 printf (" Segment #%2d start = 0x%lx, end = 0x%lx, seg index = %u\n",
282 i + 1, seg_info_dw[i * 2], seg_info_dw[(i * 2) + 1],
283 seg_info_w[i]);
285 ofs = sizeof(OMFSourceModule) + sizeof(unsigned long) * (sourceModule->cFile - 1) +
286 sourceModule->cSeg * (2 * sizeof(unsigned long) + sizeof(unsigned short));
287 ofs = (ofs + 3) & ~3;
289 /* the OMFSourceFile is quite unpleasant to use:
290 * we have first:
291 * unsigned short number of segments
292 * unsigned short reservered
293 * unsigned long baseSrcLn[# segments]
294 * unsigned long offset[2 * #segments]
295 * odd indices are start offsets
296 * even indices are end offsets
297 * unsigned char string length for file name
298 * char file name (length is previous field)
300 /* FIXME: check ptr validity */
301 sourceFile = (const void*)(rawdata + ofs);
302 seg_info_dw = (const void*)((const char*)sourceFile + 2 * sizeof(unsigned short) +
303 sourceFile->cSeg * sizeof(unsigned long));
305 ofs += 2 * sizeof(unsigned short) + 3 * sourceFile->cSeg * sizeof(unsigned long);
307 printf(" File table: %.*s\n",
308 *(const BYTE*)((const char*)sourceModule + ofs), (const char*)sourceModule + ofs + 1);
310 for (i = 0; i < sourceFile->cSeg; i++)
312 printf (" Segment #%2d start = 0x%lx, end = 0x%lx, offset = 0x%lx\n",
313 i + 1, seg_info_dw[i * 2], seg_info_dw[(i * 2) + 1], sourceFile->baseSrcLn[i]);
315 /* add file name length */
316 ofs += *(const BYTE*)((const char*)sourceModule + ofs) + 1;
317 ofs = (ofs + 3) & ~3;
319 for (i = 0; i < sourceModule->cSeg; i++)
321 sourceLine = (const void*)(rawdata + ofs);
322 seg_info_dw = (const void*)((const char*)sourceLine + 2 * sizeof(unsigned short));
323 seg_info_w = (const void*)(&seg_info_dw[sourceLine->cLnOff]);
325 printf (" Line table #%2d: Found %d line numbers for segment index %d\n",
326 i, sourceLine->cLnOff, sourceLine->Seg);
328 for (j = 0; j < sourceLine->cLnOff; j++)
330 printf (" Pair #%2d: offset = [0x%8lx], linenumber = %d\n",
331 j + 1, seg_info_dw[j], seg_info_w[j]);
333 ofs += 2 * sizeof(unsigned short) +
334 sourceLine->cLnOff * (sizeof(unsigned long) + sizeof(unsigned short));
335 ofs = (ofs + 3) & ~3;
338 return TRUE;
341 static int dump_cv_sst_align_sym(const OMFDirEntry* omfde)
343 /*** NOT YET IMPLEMENTED ***/
345 return TRUE;
348 static void dump_codeview_all_modules(const OMFDirHeader *omfdh)
350 unsigned i;
351 const OMFDirEntry* dirEntry;
352 const char* str;
354 if (!omfdh || !omfdh->cDir) return;
356 dirEntry = PRD(Offset(omfdh + 1), omfdh->cDir * sizeof(OMFDirEntry));
357 if (!dirEntry) {printf("Can't read DirEntry array, aborting\n"); return;}
359 for (i = 0; i < omfdh->cDir; i++)
361 switch (dirEntry[i].SubSection)
363 case sstModule: str = "sstModule"; break;
364 case sstAlignSym: str = "sstAlignSym"; break;
365 case sstSrcModule: str = "sstSrcModule"; break;
366 case sstLibraries: str = "sstLibraries"; break;
367 case sstGlobalSym: str = "sstGlobalSym"; break;
368 case sstGlobalPub: str = "sstGlobalPub"; break;
369 case sstGlobalTypes: str = "sstGlobalTypes"; break;
370 case sstSegMap: str = "sstSegMap"; break;
371 case sstFileIndex: str = "sstFileIndex"; break;
372 case sstStaticSym: str = "sstStaticSym"; break;
373 default: str = "<undefined>"; break;
375 printf("Module #%2d (%p)\n", i + 1, &dirEntry[i]);
376 printf(" SubSection: %04X (%s)\n", dirEntry[i].SubSection, str);
377 printf(" iMod: %d\n", dirEntry[i].iMod);
378 printf(" lfo: %ld\n", dirEntry[i].lfo);
379 printf(" cb: %lu\n", dirEntry[i].cb);
381 switch (dirEntry[i].SubSection)
383 case sstModule: dump_cv_sst_module(&dirEntry[i]); break;
384 case sstAlignSym: dump_cv_sst_align_sym(&dirEntry[i]); break;
385 case sstSrcModule: dump_cv_sst_src_module(&dirEntry[i]); break;
386 case sstLibraries: dump_cv_sst_libraries(&dirEntry[i]); break;
387 case sstGlobalSym: dump_cv_sst_global_sym(&dirEntry[i]); break;
388 case sstGlobalPub: dump_cv_sst_global_pub(&dirEntry[i]); break;
389 case sstGlobalTypes: dump_cv_sst_global_types(&dirEntry[i]); break;
390 case sstSegMap: dump_cv_sst_seg_map(&dirEntry[i]); break;
391 case sstFileIndex: dump_cv_sst_file_index(&dirEntry[i]); break;
392 case sstStaticSym: dump_cv_sst_static_sym(&dirEntry[i]); break;
393 default: printf("unsupported type %x\n", dirEntry[i].SubSection); break;
395 printf("\n");
398 return;
401 static void dump_codeview_headers(unsigned long base, unsigned long len)
403 const OMFDirHeader* dirHeader;
404 const OMFSignature* signature;
405 const OMFDirEntry* dirEntry;
406 unsigned i;
407 int modulecount = 0, alignsymcount = 0, srcmodulecount = 0, librariescount = 0;
408 int globalsymcount = 0, globalpubcount = 0, globaltypescount = 0;
409 int segmapcount = 0, fileindexcount = 0, staticsymcount = 0;
411 cv_base = PRD(base, len);
412 if (!cv_base) {printf("Can't get full debug content, aborting\n");return;}
414 signature = cv_base;
416 printf(" CodeView Data\n");
418 printf(" Signature: %.4s\n", signature->Signature);
419 printf(" Filepos: 0x%08lX\n", signature->filepos);
421 if (memcmp(signature->Signature, "NB10", 4) == 0)
423 const struct {DWORD TimeStamp; DWORD Dunno; char Name[1];} *pdb_data;
424 pdb_data = (const void *)(signature + 1);
426 printf(" TimeStamp: %08X (%s)\n",
427 pdb_data->TimeStamp, get_time_str(pdb_data->TimeStamp));
428 printf(" Dunno: %08X\n", pdb_data->Dunno);
429 printf(" Filename: %s\n", pdb_data->Name);
430 return;
433 if (memcmp(signature->Signature, "NB09", 4) != 0 && memcmp(signature->Signature, "NB11", 4) != 0)
435 printf("Unsupported signature, aborting\n");
436 return;
439 dirHeader = PRD(Offset(cv_base) + signature->filepos, sizeof(OMFDirHeader));
440 if (!dirHeader) {printf("Can't get debug header, aborting\n"); return;}
442 printf(" Size of header: 0x%4X\n", dirHeader->cbDirHeader);
443 printf(" Size per entry: 0x%4X\n", dirHeader->cbDirEntry);
444 printf(" # of entries: 0x%8lX (%ld)\n", dirHeader->cDir, dirHeader->cDir);
445 printf(" Offset to NextDir: 0x%8lX\n", dirHeader->lfoNextDir);
446 printf(" Flags: 0x%8lX\n", dirHeader->flags);
448 if (!dirHeader->cDir) return;
450 dirEntry = PRD(Offset(dirHeader + 1), sizeof(OMFDirEntry) * dirHeader->cDir);
451 if (!dirEntry) {printf("Can't get DirEntry array, aborting\n");return;}
453 for (i = 0; i < dirHeader->cDir; i++)
455 switch (dirEntry[i].SubSection)
457 case sstModule: modulecount++; break;
458 case sstAlignSym: alignsymcount++; break;
459 case sstSrcModule: srcmodulecount++; break;
460 case sstLibraries: librariescount++; break;
461 case sstGlobalSym: globalsymcount++; break;
462 case sstGlobalPub: globalpubcount++; break;
463 case sstGlobalTypes: globaltypescount++; break;
464 case sstSegMap: segmapcount++; break;
465 case sstFileIndex: fileindexcount++; break;
466 case sstStaticSym: staticsymcount++; break;
470 /* This one has to be > 0
472 printf ("\nFound: %d sstModule subsections\n", modulecount);
474 if (alignsymcount > 0) printf (" %d sstAlignSym subsections\n", alignsymcount);
475 if (srcmodulecount > 0) printf (" %d sstSrcModule subsections\n", srcmodulecount);
476 if (librariescount > 0) printf (" %d sstLibraries subsections\n", librariescount);
477 if (globalsymcount > 0) printf (" %d sstGlobalSym subsections\n", globalsymcount);
478 if (globalpubcount > 0) printf (" %d sstGlobalPub subsections\n", globalpubcount);
479 if (globaltypescount > 0) printf (" %d sstGlobalTypes subsections\n", globaltypescount);
480 if (segmapcount > 0) printf (" %d sstSegMap subsections\n", segmapcount);
481 if (fileindexcount > 0) printf (" %d sstFileIndex subsections\n", fileindexcount);
482 if (staticsymcount > 0) printf (" %d sstStaticSym subsections\n", staticsymcount);
484 dump_codeview_all_modules(dirHeader);
487 static const char *get_coff_name( const IMAGE_SYMBOL *coff_sym, const char *coff_strtab )
489 static char namebuff[9];
490 const char* nampnt;
492 if( coff_sym->N.Name.Short )
494 memcpy(namebuff, coff_sym->N.ShortName, 8);
495 namebuff[8] = '\0';
496 nampnt = &namebuff[0];
498 else
500 nampnt = coff_strtab + coff_sym->N.Name.Long;
503 if( nampnt[0] == '_' )
504 nampnt++;
505 return nampnt;
508 void dump_coff(unsigned long coffbase, unsigned long len, const void* pmt)
510 const IMAGE_COFF_SYMBOLS_HEADER *coff = (const IMAGE_COFF_SYMBOLS_HEADER *)PRD(coffbase, len);
511 const IMAGE_SYMBOL *coff_sym;
512 const IMAGE_SYMBOL *coff_symbols =
513 (const IMAGE_SYMBOL *) ((const char *)coff + coff->LvaToFirstSymbol);
514 const char *coff_strtab = (const char *) (coff_symbols + coff->NumberOfSymbols);
515 const IMAGE_SECTION_HEADER *sectHead = pmt;
516 unsigned int i;
517 const char *nampnt;
518 int naux;
520 printf("\nDebug table: COFF format. modbase %p, coffbase %p\n", PRD(0, 0), coff);
521 printf(" ID | seg:offs [ abs ] | symbol/function name\n");
522 for(i=0; i < coff->NumberOfSymbols; i++ )
524 coff_sym = coff_symbols + i;
525 naux = coff_sym->NumberOfAuxSymbols;
527 if( coff_sym->StorageClass == IMAGE_SYM_CLASS_FILE )
529 printf("file %s\n", (const char *) (coff_sym + 1));
530 i += naux;
531 continue;
534 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_STATIC)
535 && (naux == 0)
536 && (coff_sym->SectionNumber == 1) )
538 DWORD base = sectHead[coff_sym->SectionNumber - 1].VirtualAddress;
540 * This is a normal static function when naux == 0.
541 * Just register it. The current file is the correct
542 * one in this instance.
544 nampnt = get_coff_name( coff_sym, coff_strtab );
546 printf("%05d | %02d:%08x [%08x] | %s\n", i, coff_sym->SectionNumber - 1, coff_sym->Value - base, coff_sym->Value, nampnt);
547 i += naux;
548 continue;
551 if( (coff_sym->StorageClass == IMAGE_SYM_CLASS_EXTERNAL)
552 && ISFCN(coff_sym->Type)
553 && (coff_sym->SectionNumber > 0) )
555 DWORD base = sectHead[coff_sym->SectionNumber - 1].VirtualAddress;
557 nampnt = get_coff_name( coff_sym, coff_strtab );
559 /* FIXME: add code to find out the file this symbol belongs to,
560 * see winedbg */
561 printf("%05d | %02d:%08x [%08x] | %s\n", i, coff_sym->SectionNumber - 1, coff_sym->Value - base, coff_sym->Value, nampnt);
562 i += naux;
563 continue;
567 * For now, skip past the aux entries.
569 i += naux;
574 void dump_codeview(unsigned long base, unsigned long len)
576 dump_codeview_headers(base, len);
579 void dump_frame_pointer_omission(unsigned long base, unsigned long len)
581 /* FPO is used to describe nonstandard stack frames */
582 printf("FIXME: FPO (frame pointer omission) debug symbol dumping not implemented yet.\n");
585 struct stab_nlist
587 union
589 char* n_name;
590 struct stab_nlist* n_next;
591 long n_strx;
592 } n_un;
593 unsigned char n_type;
594 char n_other;
595 short n_desc;
596 unsigned long n_value;
599 static const char * const stabs_defs[] = {
600 NULL,NULL,NULL,NULL, /* 00 */
601 NULL,NULL,NULL,NULL, /* 08 */
602 NULL,NULL,NULL,NULL, /* 10 */
603 NULL,NULL,NULL,NULL, /* 18 */
604 "GSYM","FNAME","FUN","STSYM", /* 20 */
605 "LCSYM","MAIN","ROSYM","PC", /* 28 */
606 NULL,"NSYMS","NOMAP",NULL, /* 30 */
607 "OBJ",NULL,"OPT",NULL, /* 38 */
608 "RSYM","M2C","SLINE","DSLINE", /* 40 */
609 "BSLINE","DEFD","FLINE",NULL, /* 48 */
610 "EHDECL",NULL,"CATCH",NULL, /* 50 */
611 NULL,NULL,NULL,NULL, /* 58 */
612 "SSYM","ENDM","SO",NULL, /* 60 */
613 NULL,NULL,NULL,NULL, /* 68 */
614 NULL,NULL,NULL,NULL, /* 70 */
615 NULL,NULL,NULL,NULL, /* 78 */
616 "LSYM","BINCL","SOL",NULL, /* 80 */
617 NULL,NULL,NULL,NULL, /* 88 */
618 NULL,NULL,NULL,NULL, /* 90 */
619 NULL,NULL,NULL,NULL, /* 98 */
620 "PSYM","EINCL","ENTRY",NULL, /* a0 */
621 NULL,NULL,NULL,NULL, /* a8 */
622 NULL,NULL,NULL,NULL, /* b0 */
623 NULL,NULL,NULL,NULL, /* b8 */
624 "LBRAC","EXCL","SCOPE",NULL, /* c0 */
625 NULL,NULL,NULL,NULL, /* c8 */
626 NULL,NULL,NULL,NULL, /* d0 */
627 NULL,NULL,NULL,NULL, /* d8 */
628 "RBRAC","BCOMM","ECOMM",NULL, /* e0 */
629 "ECOML","WITH",NULL,NULL, /* e8 */
630 "NBTEXT","NBDATA","NBBSS","NBSTS", /* f0 */
631 "NBLCS",NULL,NULL,NULL /* f8 */
634 void dump_stabs(const void* pv_stabs, unsigned szstabs, const char* stabstr, unsigned szstr)
636 int i;
637 int nstab;
638 const char* ptr;
639 char* stabbuff;
640 unsigned int stabbufflen;
641 const struct stab_nlist* stab_ptr = pv_stabs;
642 const char* strs_end;
643 char n_buffer[16];
645 nstab = szstabs / sizeof(struct stab_nlist);
646 strs_end = stabstr + szstr;
649 * Allocate a buffer into which we can build stab strings for cases
650 * where the stab is continued over multiple lines.
652 stabbufflen = 65536;
653 stabbuff = malloc(stabbufflen);
655 stabbuff[0] = '\0';
657 printf("#Sym n_type n_othr n_desc n_value n_strx String\n");
659 for (i = 0; i < nstab; i++, stab_ptr++)
661 ptr = stabstr + stab_ptr->n_un.n_strx;
662 if ((ptr > strs_end) || (ptr + strlen(ptr) > strs_end))
664 ptr = "[[*** bad string ***]]";
666 else if (ptr[strlen(ptr) - 1] == '\\')
669 * Indicates continuation. Append this to the buffer, and go onto the
670 * next record. Repeat the process until we find a stab without the
671 * '/' character, as this indicates we have the whole thing.
673 unsigned len = strlen(ptr);
674 if (strlen(stabbuff) + len > stabbufflen)
676 stabbufflen += 65536;
677 stabbuff = realloc(stabbuff, stabbufflen);
679 strncat(stabbuff, ptr, len - 1);
680 continue;
682 else if (stabbuff[0] != '\0')
684 strcat(stabbuff, ptr);
685 ptr = stabbuff;
687 if ((stab_ptr->n_type & 1) || !stabs_defs[stab_ptr->n_type / 2])
688 sprintf(n_buffer, "<0x%02x>", stab_ptr->n_type);
689 else
690 sprintf(n_buffer, "%-6s", stabs_defs[stab_ptr->n_type / 2]);
691 printf("%4d %s %-8x % 6d %-8lx %-6lx %s\n",
692 i, n_buffer, stab_ptr->n_other, stab_ptr->n_desc, stab_ptr->n_value,
693 stab_ptr->n_un.n_strx, ptr);
695 free(stabbuff);