winedump: Print more meaningful information about module list.
[wine] / tools / winedump / pdb.c
1 /*
2  *      PDB dumping utility
3  *
4  *      Copyright 2006 Eric Pouech
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #ifdef HAVE_UNISTD_H
28 # include <unistd.h>
29 #endif
30 #include <time.h>
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
33 #endif
34 #ifdef HAVE_SYS_STAT_H
35 # include <sys/stat.h>
36 #endif
37 #ifdef HAVE_SYS_MMAN_H
38 #include <sys/mman.h>
39 #endif
40 #include <fcntl.h>
41
42 #define NONAMELESSUNION
43 #define NONAMELESSSTRUCT
44 #include "windef.h"
45 #include "winbase.h"
46 #include "winedump.h"
47 #include "wine/mscvpdb.h"
48
49 struct pdb_reader
50 {
51     union
52     {
53         struct
54         {
55             const struct PDB_JG_HEADER* header;
56             const struct PDB_JG_TOC*    toc;
57         } jg;
58         struct
59         {
60             const struct PDB_DS_HEADER* header;
61             const struct PDB_DS_TOC*    toc;
62         } ds;
63     } u;
64     void*       (*read_file)(struct pdb_reader*, DWORD);
65     DWORD       file_used[1024];
66 };
67
68 static void* pdb_jg_read(const struct PDB_JG_HEADER* pdb, const WORD* block_list, int size)
69 {
70     int                 i, nBlocks;
71     BYTE*               buffer;
72
73     if (!size) return NULL;
74
75     nBlocks = (size + pdb->block_size - 1) / pdb->block_size;
76     buffer = malloc(nBlocks * pdb->block_size);
77
78     for (i = 0; i < nBlocks; i++)
79         memcpy(buffer + i * pdb->block_size,
80                (const char*)pdb + block_list[i] * pdb->block_size, pdb->block_size);
81
82     return buffer;
83 }
84
85 static void* pdb_jg_read_file(struct pdb_reader* reader, DWORD file_nr)
86 {
87     const WORD*         block_list;
88     DWORD               i;
89
90     if (!reader->u.jg.toc || file_nr >= reader->u.jg.toc->num_files) return NULL;
91
92     reader->file_used[file_nr / 32] |= 1 << (file_nr % 32);
93     if (reader->u.jg.toc->file[file_nr].size == 0 ||
94         reader->u.jg.toc->file[file_nr].size == 0xFFFFFFFF)
95         return NULL;
96     block_list = (const WORD*) &reader->u.jg.toc->file[reader->u.jg.toc->num_files];
97     for (i = 0; i < file_nr; i++)
98         block_list += (reader->u.jg.toc->file[i].size +
99                        reader->u.jg.header->block_size - 1) / reader->u.jg.header->block_size;
100
101     return pdb_jg_read(reader->u.jg.header, block_list,
102                        reader->u.jg.toc->file[file_nr].size);
103 }
104
105 static void pdb_jg_init(struct pdb_reader* reader)
106 {
107     reader->u.jg.header = PRD(0, sizeof(struct PDB_JG_HEADER));
108     reader->read_file = pdb_jg_read_file;
109     reader->u.jg.toc = pdb_jg_read(reader->u.jg.header, 
110                                    reader->u.jg.header->toc_block,
111                                    reader->u.jg.header->toc.size);
112     memset(reader->file_used, 0, sizeof(reader->file_used));
113 }
114
115 static DWORD    pdb_get_num_files(const struct pdb_reader* reader)
116 {
117     if (reader->read_file == pdb_jg_read_file)
118         return reader->u.jg.toc->num_files;
119     else
120         return reader->u.ds.toc->num_files;
121 }
122
123 static DWORD    pdb_get_file_size(const struct pdb_reader* reader, unsigned idx)
124 {
125     if (reader->read_file == pdb_jg_read_file)
126         return reader->u.jg.toc->file[idx].size;
127     else
128         return reader->u.ds.toc->file_size[idx];
129 }
130
131 static void pdb_exit(struct pdb_reader* reader)
132 {
133 #if 1
134     unsigned            i;
135     unsigned char*      file;
136     DWORD               size;
137
138     for (i = 0; i < pdb_get_num_files(reader); i++)
139     {
140         if (reader->file_used[i / 32] & (1 << (i % 32))) continue;
141
142         file = reader->read_file(reader, i);
143         if (!file) continue;
144
145         size = pdb_get_file_size(reader, i);
146
147         printf("File --unused-- #%d (%x)\n", i, size);
148         dump_data(file, size, "    ");
149         free(file);
150     }
151 #endif
152     if (reader->read_file == pdb_jg_read_file)
153         free((char*)reader->u.jg.toc);
154     else
155         free((char*)reader->u.ds.toc);
156 }
157
158 static void pdb_dump_symbols(struct pdb_reader* reader)
159 {
160     PDB_SYMBOLS*    symbols;
161     unsigned char*  modimage;
162     const char*     file;
163
164     symbols = reader->read_file(reader, 3);
165
166     if (!symbols) return;
167
168     switch (symbols->version)
169     {
170     case 0:            /* VC 4.0 */
171     case 19960307:     /* VC 5.0 */
172     case 19970606:     /* VC 6.0 */
173         break;
174     default:
175         printf("-Unknown symbol info version %d\n", symbols->version);
176     }
177     printf("Symbols:\n"
178            "\tsignature:      %08x\n"
179            "\tversion:        %u\n"
180            "\tunknown:        %08x\n"
181            "\thash1_file:     %08x\n"
182            "\thash2_file:     %08x\n"
183            "\tgsym_file:      %08x\n"
184            "\tmodule_size:    %08x\n"
185            "\toffset_size:    %08x\n"
186            "\thash_size:      %08x\n"
187            "\tsrc_module_size %08x\n"
188            "\tpdbimport_size  %08x\n",
189            symbols->signature,
190            symbols->version,
191            symbols->unknown,
192            symbols->hash1_file,
193            symbols->hash2_file,
194            symbols->gsym_file,
195            symbols->module_size,
196            symbols->offset_size,
197            symbols->hash_size,
198            symbols->srcmodule_size,
199            symbols->pdbimport_size);
200
201     if (symbols->offset_size)
202     {
203         const BYTE*                 src;
204
205         printf("\t----------offsets------------\n");
206         src = (const BYTE*)((const char*)symbols + sizeof(PDB_SYMBOLS) + symbols->module_size);
207         dump_data(src, symbols->offset_size, "    ");
208     }
209
210     if (symbols->srcmodule_size)
211     {
212         const PDB_SYMBOL_SOURCE*src;
213         int                     i, j, cfile;
214         const WORD*             indx;
215         const DWORD*            offset;
216         const char*             start_cstr;
217         const char*             cstr;
218
219         printf("\t----------src module------------\n");
220         src = (const PDB_SYMBOL_SOURCE*)((const char*)symbols + sizeof(PDB_SYMBOLS) + 
221                                          symbols->module_size + symbols->offset_size + symbols->hash_size);
222         printf("\tSource Modules\n"
223                "\t\tnModules:         %u\n"
224                "\t\tnSrcFiles:        %u\n",
225                src->nModules, src->nSrcFiles);
226
227         /* usage of table seems to be as follows:
228          * two arrays of WORD (src->nModules as size)
229          *  - first array contains index into files for "module" compilation
230          *    (module = compilation unit ??)
231          *  - second array contains the number of source files in module
232          *    an array of DWORD (src->nSrcFiles as size)
233          *  - contains offset (in following string table) of the source file name
234          *    a string table
235          *  - each string is a pascal string (ie. with its length as first BYTE) or
236          *    0-terminated string (depending on version)
237          */
238         indx = &src->table[src->nModules];
239         offset = (const DWORD*)&src->table[2 * src->nModules];
240         cstr = (const char*)&src->table[2 * (src->nModules + src->nSrcFiles)];
241         start_cstr = cstr;
242
243         for (i = cfile = 0; i < src->nModules; i++)
244         {
245             printf("\t\tModule[%2d]:\n", i);
246             for (j = 0; j < indx[i]; j++, cfile++)
247             {
248                 /* FIXME: in some cases, it's a p_string but WHEN ? */
249                 if (src->table[cfile] < src->nSrcFiles &&
250                     cstr + offset[src->table[cfile]] >= (const char*)start_cstr /* wrap around */ &&
251                     cstr + offset[src->table[cfile]] < (const char*)src + symbols->srcmodule_size)
252                     printf("\t\t\tSource file: %s\n", cstr + offset[src->table[cfile]]);
253                 else
254                     printf("\t\t\tSource file: <<out of bounds>>\n");
255             }
256         }
257     }
258     if (symbols->pdbimport_size)
259     {
260         const PDB_SYMBOL_IMPORT*  imp;
261         const char* first;
262         const char* last;
263         const char* ptr;
264
265         printf("\t------------import--------------\n");
266         imp = (const PDB_SYMBOL_IMPORT*)((const char*)symbols + sizeof(PDB_SYMBOLS) + 
267                                          symbols->module_size + symbols->offset_size + 
268                                          symbols->hash_size + symbols->srcmodule_size);
269         first = (const char*)imp;
270         last = (const char*)imp + symbols->pdbimport_size;
271         while (imp < (const PDB_SYMBOL_IMPORT*)last)
272         {
273             ptr = (const char*)imp + sizeof(*imp) + strlen(imp->filename);
274             printf("\tImport: %lx\n"
275                    "\t\tUnknown1:      %08x\n"
276                    "\t\tUnknown2:      %08x\n"
277                    "\t\tTimeDateStamp: %08x\n"
278                    "\t\tAge:           %08u\n"
279                    "\t\tfile1:         %s\n"
280                    "\t\tfile2:         %s\n",
281                    (ULONG_PTR)((const char*)imp - (const char*)first),
282                    imp->unknown1,
283                    imp->unknown2,
284                    imp->TimeDateStamp,
285                    imp->Age,
286                    imp->filename,
287                    ptr);
288             imp = (const PDB_SYMBOL_IMPORT*)(first + ((ptr - first + strlen(ptr) + 1 + 3) & ~3));
289         }
290     }
291
292     /* Read global symbol table */
293     modimage = reader->read_file(reader, symbols->gsym_file);
294     if (modimage)
295     {
296         printf("\t------------globals-------------\n"); 
297         codeview_dump_symbols(modimage, pdb_get_file_size(reader, symbols->gsym_file));
298         free(modimage);
299     }
300
301     /* Read per-module symbol / linenumber tables */
302     file = (const char*)symbols + sizeof(PDB_SYMBOLS);
303     while (file - (const char*)symbols < sizeof(PDB_SYMBOLS) + symbols->module_size)
304     {
305         int file_nr, symbol_size, lineno_size;
306         const char* file_name;
307             
308         if (symbols->version < 19970000)
309         {
310             const PDB_SYMBOL_FILE*      sym_file = (const PDB_SYMBOL_FILE*) file;
311             file_nr     = sym_file->file;
312             file_name   = sym_file->filename;
313             symbol_size = sym_file->symbol_size;
314             lineno_size = sym_file->lineno_size;
315             printf("\t--------symbol file----------- %s\n", file_name);
316             printf("\tgot symbol_file\n"
317                    "\t\tunknown1:   %08x \n"
318                    "\t\trange\n"
319                    "\t\t\tsegment:         %04x\n"
320                    "\t\t\tpad1:            %04x\n"
321                    "\t\t\toffset:          %08x\n"
322                    "\t\t\tsize:            %08x\n"
323                    "\t\t\tcharacteristics: %08x\n"
324                    "\t\t\tindex:           %04x\n"
325                    "\t\t\tpad2:            %04x\n"
326                    "\t\tflag:       %04x\n"
327                    "\t\tfile:       %04x\n"
328                    "\t\tsymb size:  %08x\n"
329                    "\t\tline size:  %08x\n"
330                    "\t\tunknown2:   %08x\n"
331                    "\t\tnSrcFiles:  %08x\n"
332                    "\t\tattribute:  %08x\n",
333                    sym_file->unknown1,
334                    sym_file->range.segment,
335                    sym_file->range.pad1,
336                    sym_file->range.offset,
337                    sym_file->range.size,
338                    sym_file->range.characteristics,
339                    sym_file->range.index,
340                    sym_file->range.pad2,
341                    sym_file->flag,
342                    sym_file->file,
343                    sym_file->symbol_size,
344                    sym_file->lineno_size,
345                    sym_file->unknown2,
346                    sym_file->nSrcFiles,
347                    sym_file->attribute);
348         }
349         else
350         {
351             const PDB_SYMBOL_FILE_EX*   sym_file = (const PDB_SYMBOL_FILE_EX*) file;
352             file_nr     = sym_file->file;
353             file_name   = sym_file->filename;
354             symbol_size = sym_file->symbol_size;
355             lineno_size = sym_file->lineno_size;
356             printf("\t--------symbol file----------- %s\n", file_name);
357             printf("\t\tunknown1:   %08x \n"
358                    "\t\trange\n"
359                    "\t\t\tsegment:         %04x\n"
360                    "\t\t\tpad1:            %04x\n"
361                    "\t\t\toffset:          %08x\n"
362                    "\t\t\tsize:            %08x\n"
363                    "\t\t\tcharacteristics: %08x\n"
364                    "\t\t\tindex:           %04x\n"
365                    "\t\t\tpad2:            %04x\n"
366                    "\t\t\ttimestamp:       %08x\n"
367                    "\t\t\tunknown:         %08x\n"
368                    "\t\tflag:       %04x\n"
369                    "\t\tfile:       %04x\n"
370                    "\t\tsymb size:  %08x\n"
371                    "\t\tline size:  %08x\n"
372                    "\t\tunknown2:   %08x\n"
373                    "\t\tnSrcFiles:  %08x\n"
374                    "\t\tattribute:  %08x\n"
375                    "\t\treserved/0: %08x\n"
376                    "\t\treserved/1: %08x\n",
377                    sym_file->unknown1,
378                    sym_file->range.segment,
379                    sym_file->range.pad1,
380                    sym_file->range.offset,
381                    sym_file->range.size,
382                    sym_file->range.characteristics,
383                    sym_file->range.index,
384                    sym_file->range.pad2,
385                    sym_file->range.timestamp,
386                    sym_file->range.unknown,
387                    sym_file->flag,
388                    sym_file->file,
389                    sym_file->symbol_size,
390                    sym_file->lineno_size,
391                    sym_file->unknown2,
392                    sym_file->nSrcFiles,
393                    sym_file->attribute,
394                    sym_file->reserved[0],
395                    sym_file->reserved[1]);
396         }
397         modimage = reader->read_file(reader, file_nr);
398         if (modimage)
399         {
400             int total_size = pdb_get_file_size(reader, file_nr);
401
402             if (symbol_size)
403                 codeview_dump_symbols((const char*)modimage + sizeof(DWORD), symbol_size);
404
405             /* what's that part ??? */
406             if (0)
407                 dump_data(modimage + symbol_size + lineno_size, total_size - (symbol_size + lineno_size), "    ");
408             free(modimage);
409         }
410
411         file_name += strlen(file_name) + 1;
412         file = (char*)((DWORD_PTR)(file_name + strlen(file_name) + 1 + 3) & ~3);
413     }
414     free(symbols);
415 }
416
417 static void pdb_dump_types(struct pdb_reader* reader)
418 {
419     PDB_TYPES*  types = NULL;
420
421     types = reader->read_file(reader, 2);
422
423     switch (types->version)
424     {
425     case 19950410:      /* VC 4.0 */
426     case 19951122:
427     case 19961031:      /* VC 5.0 / 6.0 */
428     case 19990903:      /* VC 7.0 */
429         break;
430     default:
431         printf("-Unknown type info version %d\n", types->version);
432     }
433
434     /* Read type table */
435     printf("Types:\n"
436            "\tversion:        %u\n"
437            "\ttype_offset:    %08x\n"
438            "\tfirst_index:    %x\n"
439            "\tlast_index:     %x\n"
440            "\ttype_size:      %x\n"
441            "\tfile:           %x\n"
442            "\tpad:            %x\n"
443            "\thash_size:      %x\n"
444            "\thash_base:      %x\n"
445            "\thash_offset:    %x\n"
446            "\thash_len:       %x\n"
447            "\tsearch_offset:  %x\n"
448            "\tsearch_len:     %x\n"
449            "\tunknown_offset: %x\n"
450            "\tunknown_len:    %x\n",
451            types->version,
452            types->type_offset,
453            types->first_index,
454            types->last_index,
455            types->type_size,
456            types->file,
457            types->pad,
458            types->hash_size,
459            types->hash_base,
460            types->hash_offset,
461            types->hash_len,
462            types->search_offset,
463            types->search_len,
464            types->unknown_offset,
465            types->unknown_len);
466     codeview_dump_types_from_block((const char*)types + types->type_offset, types->type_size);
467     free(types);
468 }
469
470 static const char       pdb2[] = "Microsoft C/C++ program database 2.00";
471
472 static void pdb_jg_dump(void)
473 {
474     struct pdb_reader   reader;
475     struct PDB_JG_ROOT* root = NULL;
476
477     /*
478      * Read in TOC and well-known files
479      */
480     pdb_jg_init(&reader);
481     printf("Header (JG):\n"
482            "\tident:      %.*s\n"
483            "\tsignature:  %08x\n"
484            "\tblock_size: %08x\n"
485            "\tfree_list:  %04x\n"
486            "\ttotal_alloc:%04x\n",
487            (int)sizeof(pdb2) - 1, reader.u.jg.header->ident,
488            reader.u.jg.header->signature,
489            reader.u.jg.header->block_size,
490            reader.u.jg.header->free_list,
491            reader.u.jg.header->total_alloc);
492
493     root = reader.read_file(&reader, 1);
494     
495     if (root)
496     {
497         printf("Root:\n"
498                "\tVersion:       %u\n"
499                "\tTimeDateStamp: %08x\n"
500                "\tAge:           %08x\n"
501                "\tnames:         %.*s\n",
502                root->Version,
503                root->TimeDateStamp,
504                root->Age,
505                (unsigned)root->cbNames,
506                root->names);
507
508         /* Check for unknown versions */
509         switch (root->Version)
510         {
511         case 19950623:      /* VC 4.0 */
512         case 19950814:
513         case 19960307:      /* VC 5.0 */
514         case 19970604:      /* VC 6.0 */
515             break;
516         default:
517             printf("-Unknown root block version %d\n", root->Version);
518         }
519         free(root);
520     }
521     else printf("-Unable to get root\n");
522
523     pdb_dump_types(&reader);
524 #if 0
525     /* segments info, index is unknown */
526     {
527         const void*     segs = pdb_read_file(pdb, toc, 8); /* FIXME which index ??? */
528         const void*     ptr = segs;
529
530         if (segs) while (ptr < segs + toc->file[8].size)
531         {
532             printf("Segment %s\n", (const char*)ptr);
533             ptr += (strlen(ptr) + 1 + 3) & ~3;
534             printf("\tdword[0]: %08lx\n", *(DWORD*)ptr); ptr += 4;
535             printf("\tdword[1]: %08lx\n", *(DWORD*)ptr); ptr += 4;
536             printf("\tdword[2]: %08lx\n", *(DWORD*)ptr); ptr += 4;
537             printf("\tdword[3]: %08lx\n", *(DWORD*)ptr); ptr += 4;
538             printf("\tdword[4]: %08lx\n", *(DWORD*)ptr); ptr += 4;
539             printf("\tdword[5]: %08lx\n", *(DWORD*)ptr); ptr += 4;
540             printf("\tdword[6]: %08lx\n", *(DWORD*)ptr); ptr += 4;
541             printf("\tdword[7]: %08lx\n", *(DWORD*)ptr); ptr += 4;
542         }
543         free(segs);
544     }
545 #endif
546
547     pdb_dump_symbols(&reader);
548     pdb_exit(&reader);
549 }
550
551 static void* pdb_ds_read(const struct PDB_DS_HEADER* header, const DWORD* block_list, int size)
552 {
553     int                 i, nBlocks;
554     BYTE*               buffer;
555
556     if (!size) return NULL;
557
558     nBlocks = (size + header->block_size - 1) / header->block_size;
559     buffer = malloc(nBlocks * header->block_size);
560
561     for (i = 0; i < nBlocks; i++)
562         memcpy(buffer + i * header->block_size,
563                (const char*)header + block_list[i] * header->block_size, header->block_size);
564
565     return buffer;
566 }
567
568 static void* pdb_ds_read_file(struct pdb_reader* reader, DWORD file_number)
569 {
570     const DWORD*        block_list;
571     DWORD               i;
572
573     if (!reader->u.ds.toc || file_number >= reader->u.ds.toc->num_files) return NULL;
574
575     reader->file_used[file_number / 32] |= 1 << (file_number % 32);
576     if (reader->u.ds.toc->file_size[file_number] == 0 ||
577         reader->u.ds.toc->file_size[file_number] == 0xFFFFFFFF)
578         return NULL;
579     block_list = reader->u.ds.toc->file_size + reader->u.ds.toc->num_files;
580     for (i = 0; i < file_number; i++)
581         block_list += (reader->u.ds.toc->file_size[i] + reader->u.ds.header->block_size - 1) /
582             reader->u.ds.header->block_size;
583
584     return pdb_ds_read(reader->u.ds.header, block_list, reader->u.ds.toc->file_size[file_number]);
585 }
586
587 static BOOL pdb_ds_init(struct pdb_reader* reader)
588 {
589     reader->u.ds.header = PRD(0, sizeof(*reader->u.ds.header));
590     if (!reader->u.ds.header) return FALSE;
591     reader->read_file = pdb_ds_read_file;
592     reader->u.ds.toc = pdb_ds_read(reader->u.ds.header, 
593                                    (const DWORD*)((const char*)reader->u.ds.header + reader->u.ds.header->toc_page * reader->u.ds.header->block_size),
594                                    reader->u.ds.header->toc_size);
595     memset(reader->file_used, 0, sizeof(reader->file_used));
596     return TRUE;
597 }
598
599 static const char       pdb7[] = "Microsoft C/C++ MSF 7.00";
600
601 static void pdb_ds_dump(void)
602 {
603     struct pdb_reader   reader;
604     struct PDB_DS_ROOT* root;
605
606     pdb_ds_init(&reader);
607     printf("Header (DS)\n"
608            "\tsignature:        %.*s\n"
609            "\tblock_size:       %08x\n"
610            "\tunknown1:         %08x\n"
611            "\tnum_pages:        %08x\n"
612            "\ttoc_size:         %08x\n"
613            "\tunknown2:         %08x\n"
614            "\ttoc_page:         %08x\n",
615            (int)sizeof(pdb7) - 1, reader.u.ds.header->signature,
616            reader.u.ds.header->block_size,
617            reader.u.ds.header->unknown1,
618            reader.u.ds.header->num_pages,
619            reader.u.ds.header->toc_size,
620            reader.u.ds.header->unknown2,
621            reader.u.ds.header->toc_page);
622
623     /* files:
624      * 0: JG says old toc pages, I'd say free pages (tbc, low prio)
625      * 1: root structure
626      * 2: types
627      * 3: modules
628      */
629     root = reader.read_file(&reader, 1);
630     if (root)
631     {
632         const char*     ptr;
633
634         printf("Root:\n"
635                "\tVersion:              %u\n"
636                "\tTimeDateStamp:        %08x\n"
637                "\tAge:                  %08x\n"
638                "\tguid                  %s\n"
639                "\tcbNames:              %08x\n",
640                root->Version,
641                root->TimeDateStamp,
642                root->Age,
643                get_guid_str(&root->guid),
644                root->cbNames);
645         for (ptr = &root->names[0]; ptr < &root->names[0] + root->cbNames; ptr += strlen(ptr) + 1)
646             printf("\tString:               %s\n", ptr);
647         /* follows an unknown list of DWORDs */
648         free(root);
649     }
650     else printf("-Unable to get root\n");
651
652     pdb_dump_types(&reader);
653     pdb_dump_symbols(&reader);
654
655     pdb_exit(&reader);
656 }
657
658 enum FileSig get_kind_pdb(void)
659 {
660     const char* head;
661
662     head = PRD(0, sizeof(pdb2) - 1);
663     if (head && !memcmp(head, pdb2, sizeof(pdb2) - 1))
664         return SIG_PDB;
665     head = PRD(0, sizeof(pdb7) - 1);
666     if (head && !memcmp(head, pdb7, sizeof(pdb7) - 1))
667         return SIG_PDB;
668     return SIG_UNKNOWN;
669 }
670
671 void pdb_dump(void)
672 {
673     const char* head;
674
675 /*    init_types(); */
676     head = PRD(0, sizeof(pdb2) - 1);
677     if (head && !memcmp(head, pdb2, sizeof(pdb2) - 1))
678     {
679         pdb_jg_dump();
680         return;
681     }
682     head = PRD(0, sizeof(pdb7) - 1);
683     if (head && !memcmp(head, pdb7, sizeof(pdb7) - 1))
684     {
685         pdb_ds_dump();
686         return;
687     }
688     printf("Unrecognized header %s\n", head);
689 }