sane.ds: Downgrade more inappropriate FIXMEs to WARNs.
[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     char*           filesimage;
164     DWORD           filessize = 0;
165
166     symbols = reader->read_file(reader, 3);
167
168     if (!symbols) return;
169
170     switch (symbols->version)
171     {
172     case 0:            /* VC 4.0 */
173     case 19960307:     /* VC 5.0 */
174     case 19970606:     /* VC 6.0 */
175     case 19990903:     /* VC 7.0 */
176         break;
177     default:
178         printf("-Unknown symbol info version %d\n", symbols->version);
179     }
180     printf("Symbols:\n"
181            "\tsignature:      %08x\n"
182            "\tversion:        %u\n"
183            "\tunknown:        %08x\n"
184            "\thash1_file:     %08x\n"
185            "\thash2_file:     %08x\n"
186            "\tgsym_file:      %04x\n"
187            "\tunknown1:       %04x\n"
188            "\tmodule_size:    %08x\n"
189            "\toffset_size:    %08x\n"
190            "\thash_size:      %08x\n"
191            "\tsrc_module_size %08x\n"
192            "\tpdbimport_size  %08x\n",
193            symbols->signature,
194            symbols->version,
195            symbols->unknown,
196            symbols->hash1_file,
197            symbols->hash2_file,
198            symbols->gsym_file,
199            symbols->unknown1,
200            symbols->module_size,
201            symbols->offset_size,
202            symbols->hash_size,
203            symbols->srcmodule_size,
204            symbols->pdbimport_size);
205
206     if (symbols->offset_size)
207     {
208         const BYTE*                 src;
209
210         printf("\t----------offsets------------\n");
211         src = (const BYTE*)((const char*)symbols + sizeof(PDB_SYMBOLS) + symbols->module_size);
212         dump_data(src, symbols->offset_size, "    ");
213     }
214
215     filesimage = reader->read_file(reader, 12);   /* FIXME: really fixed ??? */
216     if (filesimage)
217     {
218         if (*(const DWORD*)filesimage == 0xeffeeffe)
219         {
220             filessize = *(const DWORD*)(filesimage + 8);
221         }
222         else
223         {
224             printf("wrong header %x expecting 0xeffeeffe\n", *(const DWORD*)filesimage);
225             free(filesimage);
226             filesimage = NULL;
227         }
228     }
229
230     if (symbols->srcmodule_size)
231     {
232         const PDB_SYMBOL_SOURCE*src;
233         int                     i, j, cfile;
234         const WORD*             indx;
235         const DWORD*            offset;
236         const char*             start_cstr;
237         const char*             cstr;
238
239         printf("\t----------src module------------\n");
240         src = (const PDB_SYMBOL_SOURCE*)((const char*)symbols + sizeof(PDB_SYMBOLS) + 
241                                          symbols->module_size + symbols->offset_size + symbols->hash_size);
242         printf("\tSource Modules\n"
243                "\t\tnModules:         %u\n"
244                "\t\tnSrcFiles:        %u\n",
245                src->nModules, src->nSrcFiles);
246
247         /* usage of table seems to be as follows:
248          * two arrays of WORD (src->nModules as size)
249          *  - first array contains index into files for "module" compilation
250          *    (module = compilation unit ??)
251          *  - second array contains the number of source files in module
252          *    an array of DWORD (src->nSrcFiles as size)
253          *  - contains offset (in following string table) of the source file name
254          *    a string table
255          *  - each string is a pascal string (ie. with its length as first BYTE) or
256          *    0-terminated string (depending on version)
257          */
258         indx = &src->table[src->nModules];
259         offset = (const DWORD*)&src->table[2 * src->nModules];
260         cstr = (const char*)&src->table[2 * (src->nModules + src->nSrcFiles)];
261         start_cstr = cstr;
262
263         for (i = cfile = 0; i < src->nModules; i++)
264         {
265             printf("\t\tModule[%2d]:\n", i);
266             for (j = 0; j < indx[i]; j++, cfile++)
267             {
268                 /* FIXME: in some cases, it's a p_string but WHEN ? */
269                 if (src->table[cfile] < src->nSrcFiles &&
270                     cstr + offset[src->table[cfile]] >= (const char*)start_cstr /* wrap around */ &&
271                     cstr + offset[src->table[cfile]] < (const char*)src + symbols->srcmodule_size)
272                     printf("\t\t\tSource file: %s\n", cstr + offset[src->table[cfile]]);
273                 else
274                     printf("\t\t\tSource file: <<out of bounds>>\n");
275             }
276         }
277     }
278     if (symbols->pdbimport_size)
279     {
280         const PDB_SYMBOL_IMPORT*  imp;
281         const char* first;
282         const char* last;
283         const char* ptr;
284
285         printf("\t------------import--------------\n");
286         imp = (const PDB_SYMBOL_IMPORT*)((const char*)symbols + sizeof(PDB_SYMBOLS) + 
287                                          symbols->module_size + symbols->offset_size + 
288                                          symbols->hash_size + symbols->srcmodule_size);
289         first = (const char*)imp;
290         last = (const char*)imp + symbols->pdbimport_size;
291         while (imp < (const PDB_SYMBOL_IMPORT*)last)
292         {
293             ptr = (const char*)imp + sizeof(*imp) + strlen(imp->filename);
294             printf("\tImport: %lx\n"
295                    "\t\tUnknown1:      %08x\n"
296                    "\t\tUnknown2:      %08x\n"
297                    "\t\tTimeDateStamp: %08x\n"
298                    "\t\tAge:           %08u\n"
299                    "\t\tfile1:         %s\n"
300                    "\t\tfile2:         %s\n",
301                    (ULONG_PTR)((const char*)imp - (const char*)first),
302                    imp->unknown1,
303                    imp->unknown2,
304                    imp->TimeDateStamp,
305                    imp->Age,
306                    imp->filename,
307                    ptr);
308             imp = (const PDB_SYMBOL_IMPORT*)(first + ((ptr - first + strlen(ptr) + 1 + 3) & ~3));
309         }
310     }
311
312     /* Read global symbol table */
313     modimage = reader->read_file(reader, symbols->gsym_file);
314     if (modimage)
315     {
316         printf("\t------------globals-------------\n"); 
317         codeview_dump_symbols(modimage, pdb_get_file_size(reader, symbols->gsym_file));
318         free(modimage);
319     }
320
321     /* Read per-module symbol / linenumber tables */
322     file = (const char*)symbols + sizeof(PDB_SYMBOLS);
323     while (file - (const char*)symbols < sizeof(PDB_SYMBOLS) + symbols->module_size)
324     {
325         int file_nr, symbol_size, lineno_size;
326         const char* file_name;
327             
328         if (symbols->version < 19970000)
329         {
330             const PDB_SYMBOL_FILE*      sym_file = (const PDB_SYMBOL_FILE*) file;
331             file_nr     = sym_file->file;
332             file_name   = sym_file->filename;
333             symbol_size = sym_file->symbol_size;
334             lineno_size = sym_file->lineno_size;
335             printf("\t--------symbol file----------- %s\n", file_name);
336             printf("\tgot symbol_file\n"
337                    "\t\tunknown1:   %08x\n"
338                    "\t\trange\n"
339                    "\t\t\tsegment:         %04x\n"
340                    "\t\t\tpad1:            %04x\n"
341                    "\t\t\toffset:          %08x\n"
342                    "\t\t\tsize:            %08x\n"
343                    "\t\t\tcharacteristics: %08x\n"
344                    "\t\t\tindex:           %04x\n"
345                    "\t\t\tpad2:            %04x\n"
346                    "\t\tflag:       %04x\n"
347                    "\t\tfile:       %04x\n"
348                    "\t\tsymb size:  %08x\n"
349                    "\t\tline size:  %08x\n"
350                    "\t\tunknown2:   %08x\n"
351                    "\t\tnSrcFiles:  %08x\n"
352                    "\t\tattribute:  %08x\n",
353                    sym_file->unknown1,
354                    sym_file->range.segment,
355                    sym_file->range.pad1,
356                    sym_file->range.offset,
357                    sym_file->range.size,
358                    sym_file->range.characteristics,
359                    sym_file->range.index,
360                    sym_file->range.pad2,
361                    sym_file->flag,
362                    sym_file->file,
363                    sym_file->symbol_size,
364                    sym_file->lineno_size,
365                    sym_file->unknown2,
366                    sym_file->nSrcFiles,
367                    sym_file->attribute);
368         }
369         else
370         {
371             const PDB_SYMBOL_FILE_EX*   sym_file = (const PDB_SYMBOL_FILE_EX*) file;
372             file_nr     = sym_file->file;
373             file_name   = sym_file->filename;
374             symbol_size = sym_file->symbol_size;
375             lineno_size = sym_file->lineno_size;
376             printf("\t--------symbol file----------- %s\n", file_name);
377             printf("\t\tunknown1:   %08x\n"
378                    "\t\trange\n"
379                    "\t\t\tsegment:         %04x\n"
380                    "\t\t\tpad1:            %04x\n"
381                    "\t\t\toffset:          %08x\n"
382                    "\t\t\tsize:            %08x\n"
383                    "\t\t\tcharacteristics: %08x\n"
384                    "\t\t\tindex:           %04x\n"
385                    "\t\t\tpad2:            %04x\n"
386                    "\t\t\ttimestamp:       %08x\n"
387                    "\t\t\tunknown:         %08x\n"
388                    "\t\tflag:       %04x\n"
389                    "\t\tfile:       %04x\n"
390                    "\t\tsymb size:  %08x\n"
391                    "\t\tline size:  %08x\n"
392                    "\t\tunknown2:   %08x\n"
393                    "\t\tnSrcFiles:  %08x\n"
394                    "\t\tattribute:  %08x\n"
395                    "\t\treserved/0: %08x\n"
396                    "\t\treserved/1: %08x\n",
397                    sym_file->unknown1,
398                    sym_file->range.segment,
399                    sym_file->range.pad1,
400                    sym_file->range.offset,
401                    sym_file->range.size,
402                    sym_file->range.characteristics,
403                    sym_file->range.index,
404                    sym_file->range.pad2,
405                    sym_file->range.timestamp,
406                    sym_file->range.unknown,
407                    sym_file->flag,
408                    sym_file->file,
409                    sym_file->symbol_size,
410                    sym_file->lineno_size,
411                    sym_file->unknown2,
412                    sym_file->nSrcFiles,
413                    sym_file->attribute,
414                    sym_file->reserved[0],
415                    sym_file->reserved[1]);
416         }
417         modimage = reader->read_file(reader, file_nr);
418         if (modimage)
419         {
420             int total_size = pdb_get_file_size(reader, file_nr);
421
422             if (symbol_size)
423                 codeview_dump_symbols((const char*)modimage + sizeof(DWORD), symbol_size);
424
425             /* line number info */
426             if (lineno_size)
427                 codeview_dump_linetab((const char*)modimage + symbol_size, lineno_size, TRUE, "        ");
428             /* anyway, lineno_size doesn't see to really be the size of the line number information, and
429              * it's not clear yet when to call for linetab2...
430              */
431             codeview_dump_linetab2((const char*)modimage + symbol_size + lineno_size,
432                                    total_size - (symbol_size + lineno_size),
433                                    filesimage + 12, filessize, "        ");
434             /* what's that part ??? */
435             if (0)
436                 dump_data(modimage + symbol_size + lineno_size, total_size - (symbol_size + lineno_size), "    ");
437             free(modimage);
438         }
439
440         file_name += strlen(file_name) + 1;
441         file = (char*)((DWORD_PTR)(file_name + strlen(file_name) + 1 + 3) & ~3);
442     }
443     free(symbols);
444     free(filesimage);
445 }
446
447 static void pdb_dump_types(struct pdb_reader* reader)
448 {
449     PDB_TYPES*  types = NULL;
450
451     types = reader->read_file(reader, 2);
452
453     switch (types->version)
454     {
455     case 19950410:      /* VC 4.0 */
456     case 19951122:
457     case 19961031:      /* VC 5.0 / 6.0 */
458     case 19990903:      /* VC 7.0 */
459         break;
460     default:
461         printf("-Unknown type info version %d\n", types->version);
462     }
463
464     /* Read type table */
465     printf("Types:\n"
466            "\tversion:        %u\n"
467            "\ttype_offset:    %08x\n"
468            "\tfirst_index:    %x\n"
469            "\tlast_index:     %x\n"
470            "\ttype_size:      %x\n"
471            "\tfile:           %x\n"
472            "\tpad:            %x\n"
473            "\thash_size:      %x\n"
474            "\thash_base:      %x\n"
475            "\thash_offset:    %x\n"
476            "\thash_len:       %x\n"
477            "\tsearch_offset:  %x\n"
478            "\tsearch_len:     %x\n"
479            "\tunknown_offset: %x\n"
480            "\tunknown_len:    %x\n",
481            types->version,
482            types->type_offset,
483            types->first_index,
484            types->last_index,
485            types->type_size,
486            types->file,
487            types->pad,
488            types->hash_size,
489            types->hash_base,
490            types->hash_offset,
491            types->hash_len,
492            types->search_offset,
493            types->search_len,
494            types->unknown_offset,
495            types->unknown_len);
496     codeview_dump_types_from_block((const char*)types + types->type_offset, types->type_size);
497     free(types);
498 }
499
500 static const char       pdb2[] = "Microsoft C/C++ program database 2.00";
501
502 static void pdb_jg_dump(void)
503 {
504     struct pdb_reader   reader;
505     struct PDB_JG_ROOT* root = NULL;
506
507     /*
508      * Read in TOC and well-known files
509      */
510     pdb_jg_init(&reader);
511     printf("Header (JG):\n"
512            "\tident:      %.*s\n"
513            "\tsignature:  %08x\n"
514            "\tblock_size: %08x\n"
515            "\tfree_list:  %04x\n"
516            "\ttotal_alloc:%04x\n",
517            (int)sizeof(pdb2) - 1, reader.u.jg.header->ident,
518            reader.u.jg.header->signature,
519            reader.u.jg.header->block_size,
520            reader.u.jg.header->free_list,
521            reader.u.jg.header->total_alloc);
522
523     root = reader.read_file(&reader, 1);
524     
525     if (root)
526     {
527         printf("Root:\n"
528                "\tVersion:       %u\n"
529                "\tTimeDateStamp: %08x\n"
530                "\tAge:           %08x\n"
531                "\tnames:         %.*s\n",
532                root->Version,
533                root->TimeDateStamp,
534                root->Age,
535                (unsigned)root->cbNames,
536                root->names);
537
538         /* Check for unknown versions */
539         switch (root->Version)
540         {
541         case 19950623:      /* VC 4.0 */
542         case 19950814:
543         case 19960307:      /* VC 5.0 */
544         case 19970604:      /* VC 6.0 */
545             break;
546         default:
547             printf("-Unknown root block version %d\n", root->Version);
548         }
549         free(root);
550     }
551     else printf("-Unable to get root\n");
552
553     pdb_dump_types(&reader);
554 #if 0
555     /* segments info, index is unknown */
556     {
557         const void*     segs = pdb_read_file(pdb, toc, 8); /* FIXME which index ??? */
558         const void*     ptr = segs;
559
560         if (segs) while (ptr < segs + toc->file[8].size)
561         {
562             printf("Segment %s\n", (const char*)ptr);
563             ptr += (strlen(ptr) + 1 + 3) & ~3;
564             printf("\tdword[0]: %08lx\n", *(DWORD*)ptr); ptr += 4;
565             printf("\tdword[1]: %08lx\n", *(DWORD*)ptr); ptr += 4;
566             printf("\tdword[2]: %08lx\n", *(DWORD*)ptr); ptr += 4;
567             printf("\tdword[3]: %08lx\n", *(DWORD*)ptr); ptr += 4;
568             printf("\tdword[4]: %08lx\n", *(DWORD*)ptr); ptr += 4;
569             printf("\tdword[5]: %08lx\n", *(DWORD*)ptr); ptr += 4;
570             printf("\tdword[6]: %08lx\n", *(DWORD*)ptr); ptr += 4;
571             printf("\tdword[7]: %08lx\n", *(DWORD*)ptr); ptr += 4;
572         }
573         free(segs);
574     }
575 #endif
576
577     pdb_dump_symbols(&reader);
578     pdb_exit(&reader);
579 }
580
581 static void* pdb_ds_read(const struct PDB_DS_HEADER* header, const DWORD* block_list, int size)
582 {
583     int                 i, nBlocks;
584     BYTE*               buffer;
585
586     if (!size) return NULL;
587
588     nBlocks = (size + header->block_size - 1) / header->block_size;
589     buffer = malloc(nBlocks * header->block_size);
590
591     for (i = 0; i < nBlocks; i++)
592         memcpy(buffer + i * header->block_size,
593                (const char*)header + block_list[i] * header->block_size, header->block_size);
594
595     return buffer;
596 }
597
598 static void* pdb_ds_read_file(struct pdb_reader* reader, DWORD file_number)
599 {
600     const DWORD*        block_list;
601     DWORD               i;
602
603     if (!reader->u.ds.toc || file_number >= reader->u.ds.toc->num_files) return NULL;
604
605     reader->file_used[file_number / 32] |= 1 << (file_number % 32);
606     if (reader->u.ds.toc->file_size[file_number] == 0 ||
607         reader->u.ds.toc->file_size[file_number] == 0xFFFFFFFF)
608         return NULL;
609     block_list = reader->u.ds.toc->file_size + reader->u.ds.toc->num_files;
610     for (i = 0; i < file_number; i++)
611         block_list += (reader->u.ds.toc->file_size[i] + reader->u.ds.header->block_size - 1) /
612             reader->u.ds.header->block_size;
613
614     return pdb_ds_read(reader->u.ds.header, block_list, reader->u.ds.toc->file_size[file_number]);
615 }
616
617 static BOOL pdb_ds_init(struct pdb_reader* reader)
618 {
619     reader->u.ds.header = PRD(0, sizeof(*reader->u.ds.header));
620     if (!reader->u.ds.header) return FALSE;
621     reader->read_file = pdb_ds_read_file;
622     reader->u.ds.toc = pdb_ds_read(reader->u.ds.header, 
623                                    (const DWORD*)((const char*)reader->u.ds.header + reader->u.ds.header->toc_page * reader->u.ds.header->block_size),
624                                    reader->u.ds.header->toc_size);
625     memset(reader->file_used, 0, sizeof(reader->file_used));
626     return TRUE;
627 }
628
629 static const char       pdb7[] = "Microsoft C/C++ MSF 7.00";
630
631 static void pdb_ds_dump(void)
632 {
633     struct pdb_reader   reader;
634     struct PDB_DS_ROOT* root;
635
636     pdb_ds_init(&reader);
637     printf("Header (DS)\n"
638            "\tsignature:        %.*s\n"
639            "\tblock_size:       %08x\n"
640            "\tunknown1:         %08x\n"
641            "\tnum_pages:        %08x\n"
642            "\ttoc_size:         %08x\n"
643            "\tunknown2:         %08x\n"
644            "\ttoc_page:         %08x\n",
645            (int)sizeof(pdb7) - 1, reader.u.ds.header->signature,
646            reader.u.ds.header->block_size,
647            reader.u.ds.header->unknown1,
648            reader.u.ds.header->num_pages,
649            reader.u.ds.header->toc_size,
650            reader.u.ds.header->unknown2,
651            reader.u.ds.header->toc_page);
652
653     /* files:
654      * 0: JG says old toc pages, I'd say free pages (tbc, low prio)
655      * 1: root structure
656      * 2: types
657      * 3: modules
658      */
659     root = reader.read_file(&reader, 1);
660     if (root)
661     {
662         const char*     ptr;
663
664         printf("Root:\n"
665                "\tVersion:              %u\n"
666                "\tTimeDateStamp:        %08x\n"
667                "\tAge:                  %08x\n"
668                "\tguid                  %s\n"
669                "\tcbNames:              %08x\n",
670                root->Version,
671                root->TimeDateStamp,
672                root->Age,
673                get_guid_str(&root->guid),
674                root->cbNames);
675         for (ptr = &root->names[0]; ptr < &root->names[0] + root->cbNames; ptr += strlen(ptr) + 1)
676             printf("\tString:               %s\n", ptr);
677         /* follows an unknown list of DWORDs */
678         free(root);
679     }
680     else printf("-Unable to get root\n");
681
682     pdb_dump_types(&reader);
683     pdb_dump_symbols(&reader);
684
685     pdb_exit(&reader);
686 }
687
688 enum FileSig get_kind_pdb(void)
689 {
690     const char* head;
691
692     head = PRD(0, sizeof(pdb2) - 1);
693     if (head && !memcmp(head, pdb2, sizeof(pdb2) - 1))
694         return SIG_PDB;
695     head = PRD(0, sizeof(pdb7) - 1);
696     if (head && !memcmp(head, pdb7, sizeof(pdb7) - 1))
697         return SIG_PDB;
698     return SIG_UNKNOWN;
699 }
700
701 void pdb_dump(void)
702 {
703     const char* head;
704
705 /*    init_types(); */
706     head = PRD(0, sizeof(pdb2) - 1);
707     if (head && !memcmp(head, pdb2, sizeof(pdb2) - 1))
708     {
709         pdb_jg_dump();
710         return;
711     }
712     head = PRD(0, sizeof(pdb7) - 1);
713     if (head && !memcmp(head, pdb7, sizeof(pdb7) - 1))
714     {
715         pdb_ds_dump();
716         return;
717     }
718     printf("Unrecognized header %s\n", head);
719 }