4 * Copyright 2006 Eric Pouech
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.
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.
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
39 const struct PDB_JG_HEADER
* header
;
40 const struct PDB_JG_TOC
* toc
;
41 const struct PDB_JG_ROOT
* root
;
45 const struct PDB_DS_HEADER
* header
;
46 const struct PDB_DS_TOC
* toc
;
47 const struct PDB_DS_ROOT
* root
;
50 void* (*read_stream
)(struct pdb_reader
*, DWORD
);
51 DWORD stream_used
[1024];
52 PDB_STRING_TABLE
* global_string_table
;
55 static inline BOOL
has_stream_been_read(struct pdb_reader
* reader
, unsigned stream_nr
)
57 return reader
->stream_used
[stream_nr
/ 32] & (1 << (stream_nr
% 32));
60 static inline void mark_stream_been_read(struct pdb_reader
* reader
, unsigned stream_nr
)
62 reader
->stream_used
[stream_nr
/ 32] |= 1 << (stream_nr
% 32);
65 static inline void clear_stream_been_read(struct pdb_reader
* reader
, unsigned stream_nr
)
67 reader
->stream_used
[stream_nr
/ 32] &= ~(1 << (stream_nr
% 32));
70 static void* pdb_jg_read(const struct PDB_JG_HEADER
* pdb
, const WORD
* block_list
, int size
)
75 if (!size
) return NULL
;
77 nBlocks
= (size
+ pdb
->block_size
- 1) / pdb
->block_size
;
78 buffer
= xmalloc(nBlocks
* pdb
->block_size
);
80 for (i
= 0; i
< nBlocks
; i
++)
81 memcpy(buffer
+ i
* pdb
->block_size
,
82 (const char*)pdb
+ block_list
[i
] * pdb
->block_size
, pdb
->block_size
);
87 static void* pdb_jg_read_stream(struct pdb_reader
* reader
, DWORD stream_nr
)
89 const WORD
* block_list
;
92 if (!reader
->u
.jg
.toc
|| stream_nr
>= reader
->u
.jg
.toc
->num_streams
) return NULL
;
94 mark_stream_been_read(reader
, stream_nr
);
95 if (reader
->u
.jg
.toc
->streams
[stream_nr
].size
== 0 ||
96 reader
->u
.jg
.toc
->streams
[stream_nr
].size
== 0xFFFFFFFF)
98 block_list
= (const WORD
*) &reader
->u
.jg
.toc
->streams
[reader
->u
.jg
.toc
->num_streams
];
99 for (i
= 0; i
< stream_nr
; i
++)
100 block_list
+= (reader
->u
.jg
.toc
->streams
[i
].size
+
101 reader
->u
.jg
.header
->block_size
- 1) / reader
->u
.jg
.header
->block_size
;
103 return pdb_jg_read(reader
->u
.jg
.header
, block_list
,
104 reader
->u
.jg
.toc
->streams
[stream_nr
].size
);
107 static BOOL
pdb_jg_init(struct pdb_reader
* reader
)
109 reader
->u
.jg
.header
= PRD(0, sizeof(struct PDB_JG_HEADER
));
110 if (!reader
->u
.jg
.header
) return FALSE
;
111 reader
->read_stream
= pdb_jg_read_stream
;
112 reader
->u
.jg
.toc
= pdb_jg_read(reader
->u
.jg
.header
,
113 reader
->u
.jg
.header
->toc_block
,
114 reader
->u
.jg
.header
->toc
.size
);
115 memset(reader
->stream_used
, 0, sizeof(reader
->stream_used
));
116 reader
->u
.jg
.root
= reader
->read_stream(reader
, 1);
117 if (!reader
->u
.jg
.root
) return FALSE
;
121 static DWORD
pdb_get_num_streams(const struct pdb_reader
* reader
)
123 if (reader
->read_stream
== pdb_jg_read_stream
)
124 return reader
->u
.jg
.toc
->num_streams
;
126 return reader
->u
.ds
.toc
->num_streams
;
129 static DWORD
pdb_get_stream_size(const struct pdb_reader
* reader
, unsigned idx
)
131 if (reader
->read_stream
== pdb_jg_read_stream
)
132 return reader
->u
.jg
.toc
->streams
[idx
].size
;
134 return reader
->u
.ds
.toc
->stream_size
[idx
];
137 static void pdb_exit(struct pdb_reader
* reader
)
140 unsigned char* stream
;
142 if (globals_dump_sect("ALL")) /* otherwise we won't have loaded all streams */
144 for (i
= 0; i
< pdb_get_num_streams(reader
); i
++)
146 if (has_stream_been_read(reader
, i
)) continue;
148 stream
= reader
->read_stream(reader
, i
);
149 if (!stream
) continue;
151 size
= pdb_get_stream_size(reader
, i
);
153 printf("Stream --unused-- #%d (%x)\n", i
, size
);
154 dump_data(stream
, size
, " ");
158 free(reader
->global_string_table
);
159 if (reader
->read_stream
== pdb_jg_read_stream
)
161 free((char*)reader
->u
.jg
.root
);
162 free((char*)reader
->u
.jg
.toc
);
166 free((char*)reader
->u
.ds
.root
);
167 free((char*)reader
->u
.ds
.toc
);
171 /* forward declarations */
172 static void pdb_dump_fpo(struct pdb_reader
* reader
, unsigned stream_idx
);
173 static void pdb_dump_fpo_ext(struct pdb_reader
* reader
, unsigned stream_idx
);
174 static void pdb_dump_sections(struct pdb_reader
* reader
, unsigned stream_idx
);
176 static unsigned get_stream_by_name(struct pdb_reader
* reader
, const char* name
)
181 DWORD string_idx
, stream_idx
;
185 if (reader
->read_stream
== pdb_jg_read_stream
)
187 str
= reader
->u
.jg
.root
->names
;
188 cbstr
= reader
->u
.jg
.root
->cbNames
;
192 str
= reader
->u
.ds
.root
->names
;
193 cbstr
= reader
->u
.ds
.root
->cbNames
;
196 pdw
= (DWORD
*)(str
+ cbstr
);
197 pdw
++; /* number of ok entries */
200 /* bitfield: first dword is len (in dword), then data */
202 pdw
+= *ok_bits
++ + 1;
205 printf("unexpected value\n");
209 for (i
= 0; i
< count
; i
++)
211 if (ok_bits
[i
/ 32] & (1 << (i
% 32)))
215 if (!strcmp(name
, &str
[string_idx
])) return stream_idx
;
221 static void dump_string_table(const PDB_STRING_TABLE
* strtable
, const char* name
, const char* pfx
)
226 unsigned num_buckets
;
231 printf("%sString table (%s) isn't present\n", pfx
, name
);
234 printf("%sString table (%s)\n"
237 "%s\tHash version: %u\n",
238 pfx
, name
, pfx
, strtable
->magic
, pfx
, strtable
->length
, pfx
, strtable
->hash_version
);
239 ptr
= (const char*)(strtable
+ 1);
240 end
= ptr
+ strtable
->length
;
243 printf("%s\t%zu] %s\n", pfx
, ptr
- (const char*)(strtable
+ 1), ptr
);
244 ptr
+= strlen(ptr
) + 1;
246 table
= (unsigned *)((char*)(strtable
+ 1) + strtable
->length
);
247 num_buckets
= *table
++;
249 if (globals_dump_sect("hash"))
252 "%s\t\tnum_strings: %x\n"
253 "%s\t\tnum_buckets: %x\n",
254 pfx
, pfx
, table
[num_buckets
], pfx
, num_buckets
);
256 for (i
= 0; i
< num_buckets
; i
++)
257 printf("%s\t\t%x] %x\n", pfx
, i
, table
[i
]);
261 static PDB_STRING_TABLE
* read_string_table(struct pdb_reader
* reader
)
264 PDB_STRING_TABLE
* ret
;
265 unsigned stream_size
;
267 stream_idx
= get_stream_by_name(reader
, "/names");
268 if (stream_idx
== -1) return NULL
;
269 ret
= reader
->read_stream(reader
, stream_idx
);
270 if (!ret
) return NULL
;
271 stream_size
= pdb_get_stream_size(reader
, stream_idx
);
272 if (globals_dump_sect("PDB")) dump_string_table(ret
, "Global", " ");
273 if (ret
->magic
== 0xeffeeffe && sizeof(*ret
) + ret
->length
< stream_size
) return ret
;
274 printf("Improper string table header (magic=%x)\n", ret
->magic
);
275 dump_data((const unsigned char*)ret
, stream_size
, " ");
280 const char* pdb_get_string_table_entry(const PDB_STRING_TABLE
* table
, unsigned ofs
)
282 if (!table
) return "<<no string table>>";
283 if (ofs
>= table
->length
) return "<<invalid string table offset>>";
284 /* strings start after header */
285 return (char*)(table
+ 1) + ofs
;
288 static void dump_dbi_hash_table(const BYTE
* root
, unsigned size
, const char* name
, const char* pfx
)
290 if (!globals_dump_sect("hash")) return;
291 if (size
>= sizeof(DBI_HASH_HEADER
))
293 const DBI_HASH_HEADER
* hdr
= (const DBI_HASH_HEADER
*)root
;
295 printf("%s%s symbols hash:\n", pfx
, name
);
296 printf("%s\tSignature: 0x%x\n", pfx
, hdr
->signature
);
297 printf("%s\tVersion: 0x%x (%u)\n", pfx
, hdr
->version
, hdr
->version
- 0xeffe0000);
298 printf("%s\tSize of hash records: %u\n", pfx
, hdr
->hash_records_size
);
299 printf("%s\tUnknown: %u\n", pfx
, hdr
->unknown
);
301 if (hdr
->signature
!= 0xFFFFFFFF ||
302 hdr
->version
!= 0xeffe0000 + 19990810 ||
303 (hdr
->hash_records_size
% sizeof(DBI_HASH_RECORD
)) != 0 ||
304 sizeof(DBI_HASH_HEADER
) + hdr
->hash_records_size
+ DBI_BITMAP_HASH_SIZE
> size
||
305 (size
- (sizeof(DBI_HASH_HEADER
) + hdr
->hash_records_size
+ DBI_BITMAP_HASH_SIZE
)) % sizeof(unsigned))
307 if (size
>= sizeof(DBI_HASH_HEADER
) && !hdr
->hash_records_size
)
308 printf("%s\t\tEmpty hash structure\n", pfx
);
310 printf("%s\t\tIncorrect hash structure\n", pfx
);
315 unsigned num_hash_records
= hdr
->hash_records_size
/ sizeof(DBI_HASH_RECORD
);
316 const DBI_HASH_RECORD
* hr
= (const DBI_HASH_RECORD
*)(hdr
+ 1);
317 unsigned* bitmap
= (unsigned*)((char*)(hdr
+ 1) + hdr
->hash_records_size
);
318 unsigned* buckets
= (unsigned*)((char*)(hdr
+ 1) + hdr
->hash_records_size
+ DBI_BITMAP_HASH_SIZE
);
319 unsigned index
, last_index
= (size
- (sizeof(DBI_HASH_HEADER
) + hdr
->hash_records_size
+ DBI_BITMAP_HASH_SIZE
)) / sizeof(unsigned);
321 /* Yes, offsets for accessiong hr[] are stored as multiple of 12; and not
322 * as multiple of sizeof(*hr) = 8 as one might expect.
323 * Perhaps, native implementation likes to keep the same offsets between
324 * in memory representation vs on file representations.
326 for (index
= 0, i
= 0; i
<= DBI_MAX_HASH
; i
++)
328 if (bitmap
[i
/ 32] & (1u << (i
% 32)))
331 printf("%s\t[%u]\n", pfx
, i
);
332 for (j
= buckets
[index
] / 12; j
< (index
+ 1 < last_index
? buckets
[index
+ 1] / 12 : num_hash_records
); j
++)
333 printf("%s\t\t[%u] offset=%08x unk=%x\n", pfx
, j
, hr
[j
].offset
- 1, hr
[j
].unknown
);
337 printf("%s\t[%u] <<empty>>\n", pfx
, i
);
339 /* shouldn't happen */
340 if (sizeof(DBI_HASH_HEADER
) + hdr
->hash_records_size
+ DBI_BITMAP_HASH_SIZE
+ index
* sizeof(unsigned) > size
)
342 printf("%s-- left over %u bytes\n", pfx
,
343 size
- (unsigned)(sizeof(DBI_HASH_HEADER
) + hdr
->hash_records_size
+ DBI_BITMAP_HASH_SIZE
+ index
* sizeof(unsigned)));
348 printf("%sNo header in symbols hash\n", pfx
);
351 static void dump_global_symbol(struct pdb_reader
* reader
, unsigned stream
)
356 global
= reader
->read_stream(reader
, stream
);
359 size
= pdb_get_stream_size(reader
, stream
);
361 dump_dbi_hash_table(global
, size
, "Global", "");
365 static void dump_public_symbol(struct pdb_reader
* reader
, unsigned stream
)
368 DBI_PUBLIC_HEADER
* hdr
;
372 if (!globals_dump_sect("public")) return;
373 hdr
= reader
->read_stream(reader
, stream
);
376 size
= pdb_get_stream_size(reader
, stream
);
378 printf("Public symbols table: (%u)\n", size
);
380 printf("\tHash size: %u\n", hdr
->hash_size
);
381 printf("\tAddress map size: %u\n", hdr
->address_map_size
);
382 printf("\tNumber of thunks: %u\n", hdr
->num_thunks
);
383 printf("\tSize of thunk map: %u\n", hdr
->thunk_size
);
384 printf("\tSection of thunk table: %u\n", hdr
->section_thunk_table
);
385 printf("\tOffset of thunk table: %u\n", hdr
->offset_thunk_table
);
386 printf("\tNumber of sections: %u\n", hdr
->num_sections
);
388 ptr
= (const BYTE
*)(hdr
+ 1);
389 dump_dbi_hash_table(ptr
, hdr
->hash_size
, "Public", "\t");
391 ptr
+= hdr
->hash_size
;
392 printf("\tAddress map:\n");
393 for (i
= 0; i
< hdr
->address_map_size
/ sizeof(unsigned); i
++)
394 printf("\t\t%u] %08x\n", i
, ((const unsigned*)ptr
)[i
]);
396 ptr
+= hdr
->address_map_size
;
397 printf("\tThunk map:\n");
398 for (i
= 0; i
< hdr
->num_thunks
; i
++)
399 printf("\t\t%u] %08x\n", i
, ((const unsigned*)ptr
)[i
]);
401 ptr
+= hdr
->num_thunks
* sizeof(unsigned);
402 printf("\tSection map:\n");
403 for (i
= 0; i
< hdr
->num_sections
; i
++)
404 printf("\t\t%u] %04x:%08x\n", i
, (unsigned short)((const unsigned*)ptr
)[2 * i
+ 1], ((const unsigned*)ptr
)[2 * i
+ 0]);
406 if (ptr
+ hdr
->num_sections
* 8 != ((const BYTE
*)hdr
) + size
)
407 printf("Incorrect stream\n");
411 static const void* pdb_dump_dbi_module(struct pdb_reader
* reader
, const PDB_SYMBOL_FILE_EX
* sym_file
,
412 const char* file_name
)
414 const char* lib_name
;
415 unsigned char* modimage
;
416 BOOL new_format
= !file_name
;
418 if (new_format
) file_name
= sym_file
->filename
;
419 printf("\t--------symbol file-----------\n");
420 printf("\tName: %s\n", file_name
);
421 lib_name
= file_name
+ strlen(file_name
) + 1;
422 if (strcmp(file_name
, lib_name
)) printf("\tLibrary: %s\n", lib_name
);
423 printf("\t\tunknown1: %08x\n"
425 "\t\t\tsegment: %04x\n"
427 "\t\t\toffset: %08x\n"
429 "\t\t\tcharacteristics: %08x",
431 sym_file
->range
.segment
,
432 sym_file
->range
.pad1
,
433 sym_file
->range
.offset
,
434 sym_file
->range
.size
,
435 sym_file
->range
.characteristics
);
436 dump_section_characteristics(sym_file
->range
.characteristics
, " ");
438 "\t\t\tindex: %04x\n"
439 "\t\t\tpad2: %04x\n",
440 sym_file
->range
.index
,
441 sym_file
->range
.pad2
);
443 printf("\t\t\ttimestamp: %08x\n"
444 "\t\t\tunknown: %08x\n",
445 sym_file
->range
.timestamp
,
446 sym_file
->range
.unknown
);
447 printf("\t\tflag: %04x\n"
449 "\t\tsymb size: %08x\n"
450 "\t\tline size: %08x\n"
451 "\t\tline2 size: %08x\n"
452 "\t\tnSrcFiles: %08x\n"
453 "\t\tattribute: %08x\n",
456 sym_file
->symbol_size
,
457 sym_file
->lineno_size
,
458 sym_file
->lineno2_size
,
460 sym_file
->attribute
);
462 printf("\t\treserved/0: %08x\n"
463 "\t\treserved/1: %08x\n",
464 sym_file
->reserved
[0],
465 sym_file
->reserved
[1]);
467 modimage
= reader
->read_stream(reader
, sym_file
->stream
);
470 int total_size
= pdb_get_stream_size(reader
, sym_file
->stream
);
472 if (sym_file
->symbol_size
)
473 codeview_dump_symbols((const char*)modimage
, sizeof(DWORD
), sym_file
->symbol_size
);
475 /* line number info */
476 if (sym_file
->lineno_size
)
477 codeview_dump_linetab((const char*)modimage
+ sym_file
->symbol_size
, TRUE
, " ");
478 else if (sym_file
->lineno2_size
) /* actually, only one of the 2 lineno should be present */
479 codeview_dump_linetab2((const char*)modimage
+ sym_file
->symbol_size
, sym_file
->lineno2_size
,
480 reader
->global_string_table
, " ");
481 /* what's that part ??? */
483 dump_data(modimage
+ sym_file
->symbol_size
+ sym_file
->lineno_size
+ sym_file
->lineno2_size
,
484 total_size
- (sym_file
->symbol_size
+ sym_file
->lineno_size
+ sym_file
->lineno2_size
), " ");
487 return (const void*)((DWORD_PTR
)(lib_name
+ strlen(lib_name
) + 1 + 3) & ~3);
490 static void pdb_dump_symbols(struct pdb_reader
* reader
)
492 PDB_SYMBOLS
* symbols
;
493 unsigned char* modimage
;
496 PDB_STREAM_INDEXES sidx
;
498 sidx
.FPO
= sidx
.unk0
= sidx
.unk1
= sidx
.unk2
= sidx
.unk3
= sidx
.sections_stream
=
499 sidx
.unk4
= sidx
.unk5
= sidx
.unk6
= sidx
.FPO_EXT
= sidx
.unk7
= -1;
501 symbols
= reader
->read_stream(reader
, 3);
502 if (!symbols
) return;
504 if (globals_dump_sect("DBI"))
506 switch (symbols
->version
)
509 case 19960307: /* VC 5.0 */
510 case 19970606: /* VC 6.0 */
511 case 19990903: /* VC 7.0 */
514 printf("-Unknown symbol info version %d\n", symbols
->version
);
516 if (symbols
->flags
& 0x8000) /* new */
517 sprintf(tcver
, "%u.%u", (symbols
->flags
>> 8) & 0x7f, symbols
->flags
& 0xff);
519 sprintf(tcver
, "old-%x", symbols
->flags
);
521 "\tsignature: %08x\n"
524 "\tglobal_hash_stream: %u\n"
526 "\tpublic_stream: %u\n"
528 "\tgsym_stream: %u\n"
530 "\tmodule_size: %08x\n"
531 "\tsectcontrib_size: %08x\n"
532 "\tsegmap_size: %08x\n"
533 "\tsrc_module_size: %08x\n"
534 "\tpdbimport_size: %08x\n"
536 "\tstream_idx_size: %08x\n"
537 "\tunknown2_size: %08x\n"
544 symbols
->global_hash_stream
,
545 tcver
, /* from symbols->flags */
546 symbols
->public_stream
,
548 symbols
->gsym_stream
,
550 symbols
->module_size
,
551 symbols
->sectcontrib_size
,
552 symbols
->segmap_size
,
553 symbols
->srcmodule_size
,
554 symbols
->pdbimport_size
,
556 symbols
->stream_index_size
,
557 symbols
->unknown2_size
,
559 get_machine_str( symbols
->machine
),
563 if (symbols
->sectcontrib_size
&& globals_dump_sect("image"))
565 const BYTE
* src
= (const BYTE
*)symbols
+ sizeof(PDB_SYMBOLS
) + symbols
->module_size
;
566 const BYTE
* last
= src
+ symbols
->sectcontrib_size
;
567 unsigned version
, size
;
569 printf("\t----------section contrib------------\n");
570 version
= *(unsigned*)src
;
571 printf("\tVersion: %#x (%d)\n", version
, version
- 0xeffe0000);
574 case 0xeffe0000 + 19970605: size
= sizeof(PDB_SYMBOL_RANGE_EX
); break;
575 case 0xeffe0000 + 20140516: size
= sizeof(PDB_SYMBOL_RANGE_EX
) + sizeof(unsigned); break;
576 default: printf("\t\tUnsupported version number\n"); size
= 0;
580 const PDB_SYMBOL_RANGE_EX
* range
;
582 if ((symbols
->sectcontrib_size
- sizeof(unsigned)) % size
)
583 printf("Incoherent size: %zu = %zu * %u + %zu\n",
584 symbols
->sectcontrib_size
- sizeof(unsigned),
585 (symbols
->sectcontrib_size
- sizeof(unsigned)) / size
,
587 (symbols
->sectcontrib_size
- sizeof(unsigned)) % size
);
588 if ((symbols
->sectcontrib_size
- sizeof(unsigned)) % size
)
589 if ((symbols
->sectcontrib_size
- sizeof(unsigned)) % size
)
590 src
+= sizeof(unsigned);
591 while (src
+ size
<= last
)
593 range
= (const PDB_SYMBOL_RANGE_EX
*)(src
+ sizeof(unsigned));
594 printf("\tRange #%tu\n",
595 ((const BYTE
*)range
- ((const BYTE
*)symbols
+ sizeof(PDB_SYMBOLS
) + symbols
->module_size
)) / size
);
596 printf("\t\tsegment: %04x\n"
600 "\t\tcharacteristics: %08x",
605 range
->characteristics
);
606 dump_section_characteristics(range
->characteristics
, " ");
610 "\t\ttimestamp: %08x\n"
611 "\t\tunknown: %08x\n",
616 if (version
== 0xeffe0000 + 20140516)
617 printf("\t\tcoff_section: %08x\n", *(unsigned*)(range
+ 1));
623 if (symbols
->srcmodule_size
&& globals_dump_sect("DBI"))
625 const PDB_SYMBOL_SOURCE
*src
;
629 const char* start_cstr
;
632 printf("\t----------src module------------\n");
633 src
= (const PDB_SYMBOL_SOURCE
*)((const char*)symbols
+ sizeof(PDB_SYMBOLS
) +
634 symbols
->module_size
+ symbols
->sectcontrib_size
+ symbols
->segmap_size
);
635 printf("\tSource Modules\n"
637 "\t\tnSrcFiles: %u\n",
638 src
->nModules
, src
->nSrcFiles
);
640 /* usage of table seems to be as follows:
641 * two arrays of WORD (src->nModules as size)
642 * - first array contains index into files for "module" compilation
643 * (module = compilation unit ??)
644 * - second array contains the number of source files in module
645 * an array of DWORD (src->nSrcFiles as size)
646 * - contains offset (in following string table) of the source file name
648 * - each string is a pascal string (ie. with its length as first BYTE) or
649 * 0-terminated string (depending on version)
651 indx
= &src
->table
[src
->nModules
];
652 offset
= (const DWORD
*)&src
->table
[2 * src
->nModules
];
653 cstr
= (const char*)&src
->table
[2 * (src
->nModules
+ src
->nSrcFiles
)];
656 for (i
= cfile
= 0; i
< src
->nModules
; i
++)
658 printf("\t\tModule[%2d]:\n", i
);
659 cfile
= src
->table
[i
];
660 for (j
= cfile
; j
< src
->nSrcFiles
&& j
< cfile
+ indx
[i
]; j
++)
662 /* FIXME: in some cases, it's a p_string but WHEN ? */
663 if (cstr
+ offset
[j
] >= start_cstr
/* wrap around */ &&
664 cstr
+ offset
[j
] < (const char*)src
+ symbols
->srcmodule_size
)
665 printf("\t\t\tSource file: %s\n", cstr
+ offset
[j
]);
667 printf("\t\t\tSource file: <<out of bounds>>\n");
671 if (symbols
->pdbimport_size
&& globals_dump_sect("PDB"))
673 const PDB_SYMBOL_IMPORT
* imp
;
678 printf("\t------------import--------------\n");
679 imp
= (const PDB_SYMBOL_IMPORT
*)((const char*)symbols
+ sizeof(PDB_SYMBOLS
) +
680 symbols
->module_size
+ symbols
->sectcontrib_size
+
681 symbols
->segmap_size
+ symbols
->srcmodule_size
);
682 first
= (const char*)imp
;
683 last
= (const char*)imp
+ symbols
->pdbimport_size
;
684 while (imp
< (const PDB_SYMBOL_IMPORT
*)last
)
686 ptr
= (const char*)imp
+ sizeof(*imp
) + strlen(imp
->filename
);
687 printf("\tImport: %lx\n"
688 "\t\tUnknown1: %08x\n"
689 "\t\tUnknown2: %08x\n"
690 "\t\tTimeDateStamp: %08x\n"
694 (ULONG_PTR
)((const char*)imp
- first
),
701 imp
= (const PDB_SYMBOL_IMPORT
*)(first
+ ((ptr
- first
+ strlen(ptr
) + 1 + 3) & ~3));
704 if (symbols
->segmap_size
&& globals_dump_sect("image"))
706 const struct OMFSegMap
* segmap
= (const struct OMFSegMap
*)((const BYTE
*)symbols
+ sizeof(PDB_SYMBOLS
) +
707 symbols
->module_size
+ symbols
->sectcontrib_size
);
708 const struct OMFSegMapDesc
* desc
= (const struct OMFSegMapDesc
*)(segmap
+ 1);
710 printf("\t--------------segment map----------------\n");
711 printf("\tNumber of segments: %x\n", segmap
->cSeg
);
712 printf("\tNumber of logical segments: %x\n", segmap
->cSegLog
);
713 /* FIXME check mapping old symbols */
714 for (; (const BYTE
*)(desc
+ 1) <= ((const BYTE
*)(segmap
+ 1) + symbols
->segmap_size
); desc
++)
716 printf("\t\tSegment descriptor #%tu\n", desc
- (const struct OMFSegMapDesc
*)(segmap
+ 1));
717 printf("\t\t\tFlags: %04x (%c%c%c%s%s%s%s)\n",
719 (desc
->flags
& 0x01) ? 'R' : '-',
720 (desc
->flags
& 0x02) ? 'W' : '-',
721 (desc
->flags
& 0x04) ? 'X' : '-',
722 (desc
->flags
& 0x08) ? " 32bit-linear" : "",
723 (desc
->flags
& 0x100) ? " selector" : "",
724 (desc
->flags
& 0x200) ? " absolute" : "",
725 (desc
->flags
& 0x400) ? " group" : "");
726 printf("\t\t\tOverlay: %04x\n", desc
->ovl
);
727 printf("\t\t\tGroup: %04x\n", desc
->group
);
728 printf("\t\t\tFrame: %04x\n", desc
->frame
);
729 printf("\t\t\tSegment name: %s\n", desc
->iSegName
== 0xffff ? "none" : pdb_get_string_table_entry(reader
->global_string_table
, desc
->iSegName
));
730 printf("\t\t\tClass name: %s\n", desc
->iClassName
== 0xffff ? "none" : pdb_get_string_table_entry(reader
->global_string_table
, desc
->iClassName
));
731 printf("\t\t\tOffset: %08x\n", desc
->offset
);
732 printf("\t\t\tSize: %04x\n", desc
->cbSeg
);
735 if (symbols
->unknown2_size
&& globals_dump_sect("PDB"))
737 const char* ptr
= (const char*)symbols
+ sizeof(PDB_SYMBOLS
) + symbols
->module_size
+
738 symbols
->sectcontrib_size
+ symbols
->segmap_size
+ symbols
->srcmodule_size
+
739 symbols
->pdbimport_size
;
740 printf("\t------------Unknown2--------------\n");
741 dump_string_table((const PDB_STRING_TABLE
*)ptr
, "Unknown from DBI", "\t");
743 if (symbols
->stream_index_size
&& globals_dump_sect("image"))
745 printf("\t------------stream indexes--------------\n");
746 switch (symbols
->stream_index_size
)
748 case sizeof(PDB_STREAM_INDEXES_OLD
):
749 /* PDB_STREAM_INDEXES is a superset of PDB_STREAM_INDEX_OLD
750 * FIXME: to be confirmed when all fields are fully understood
753 (const char*)symbols
+ sizeof(PDB_SYMBOLS
) + symbols
->module_size
+
754 symbols
->sectcontrib_size
+ symbols
->segmap_size
+ symbols
->srcmodule_size
+
755 symbols
->pdbimport_size
+ symbols
->unknown2_size
,
756 sizeof(PDB_STREAM_INDEXES_OLD
));
757 printf("\tFPO: %04x\n"
762 "\tSections stream: %04x\n",
763 sidx
.FPO
, sidx
.unk0
, sidx
.unk1
, sidx
.unk2
, sidx
.unk3
,
764 sidx
.sections_stream
);
766 case sizeof(PDB_STREAM_INDEXES
):
768 (const char*)symbols
+ sizeof(PDB_SYMBOLS
) + symbols
->module_size
+
769 symbols
->sectcontrib_size
+ symbols
->segmap_size
+ symbols
->srcmodule_size
+
770 symbols
->pdbimport_size
+ symbols
->unknown2_size
,
772 printf("\tFPO: %04x\n"
777 "\tSection stream: %04x\n"
783 sidx
.FPO
, sidx
.unk0
, sidx
.unk1
, sidx
.unk2
, sidx
.unk3
,
784 sidx
.sections_stream
, sidx
.unk4
, sidx
.unk5
, sidx
.unk6
, sidx
.FPO_EXT
,
788 printf("unexpected size for stream index %d\n", symbols
->stream_index_size
);
793 /* Read global symbol table */
794 modimage
= reader
->read_stream(reader
, symbols
->gsym_stream
);
795 if (modimage
&& globals_dump_sect("DBI"))
797 printf("\t------------globals-------------\n");
798 codeview_dump_symbols(modimage
, 0, pdb_get_stream_size(reader
, symbols
->gsym_stream
));
802 /* Read per-module symbol / linenumber tables */
803 if (symbols
->module_size
&& globals_dump_sect("DBI"))
805 SIZE_T module_header_size
= symbols
->version
< 19970000 ? sizeof(PDB_SYMBOL_FILE
) : sizeof(PDB_SYMBOL_FILE_EX
);
807 file
= (const char*)symbols
+ sizeof(PDB_SYMBOLS
);
808 while (file
+ module_header_size
<= (const char*)symbols
+ sizeof(PDB_SYMBOLS
) + symbols
->module_size
)
810 if (symbols
->version
< 19970000)
812 PDB_SYMBOL_FILE_EX copy
;
813 const PDB_SYMBOL_FILE
* sym_file
= (const PDB_SYMBOL_FILE
*)file
;
815 copy
.unknown1
= sym_file
->unknown1
;
816 copy
.range
.segment
= sym_file
->range
.segment
;
817 copy
.range
.pad1
= sym_file
->range
.pad1
;
818 copy
.range
.offset
= sym_file
->range
.offset
;
819 copy
.range
.size
= sym_file
->range
.size
;
820 copy
.range
.characteristics
= sym_file
->range
.characteristics
;
821 copy
.range
.index
= sym_file
->range
.index
;
822 copy
.range
.pad2
= sym_file
->range
.pad2
;
823 copy
.range
.timestamp
= 0;
824 copy
.range
.unknown
= 0;
825 copy
.flag
= sym_file
->flag
;
826 copy
.stream
= sym_file
->stream
;
827 copy
.symbol_size
= sym_file
->symbol_size
;
828 copy
.lineno_size
= sym_file
->lineno_size
;
829 copy
.lineno2_size
= sym_file
->lineno2_size
;
830 copy
.nSrcFiles
= sym_file
->nSrcFiles
;
831 copy
.attribute
= sym_file
->attribute
;
832 copy
.reserved
[0] = 0;
833 copy
.reserved
[1] = 0;
834 file
= pdb_dump_dbi_module(reader
, ©
, sym_file
->filename
);
837 file
= pdb_dump_dbi_module(reader
, (const PDB_SYMBOL_FILE_EX
*)file
, NULL
);
840 dump_global_symbol(reader
, symbols
->global_hash_stream
);
841 dump_public_symbol(reader
, symbols
->public_stream
);
843 if (globals_dump_sect("image"))
845 pdb_dump_fpo(reader
, sidx
.FPO
);
846 pdb_dump_fpo_ext(reader
, sidx
.FPO_EXT
);
847 pdb_dump_sections(reader
, sidx
.sections_stream
);
853 static BOOL
is_bit_set(const unsigned* dw
, unsigned len
, unsigned i
)
855 if (i
>= len
* sizeof(unsigned) * 8) return FALSE
;
856 return (dw
[i
>> 5] & (1u << (i
& 31u))) != 0;
859 static void pdb_dump_hash_value(const BYTE
* ptr
, unsigned len
)
864 for (i
= len
- 1; i
>= 0; i
--)
865 printf("%02x", ptr
[i
]);
875 static int collision_compar(const void *p1
, const void *p2
)
877 unsigned idx1
= *(unsigned*)p1
;
878 unsigned idx2
= *(unsigned*)p2
;
879 return memcmp(collision_arg
.hash
+ idx1
* collision_arg
.hash_size
,
880 collision_arg
.hash
+ idx2
* collision_arg
.hash_size
,
881 collision_arg
.hash_size
);
884 static void pdb_dump_types_hash(struct pdb_reader
* reader
, const PDB_TYPES
* types
, const char* strmname
)
887 unsigned i
, strmsize
;
888 const unsigned* table
;
891 if (!globals_dump_sect("hash")) return;
892 hash
= reader
->read_stream(reader
, types
->hash_stream
);
895 printf("Types (%s) hash:\n", strmname
);
896 strmsize
= pdb_get_stream_size(reader
, types
->hash_stream
);
897 if (types
->hash_offset
+ types
->hash_size
> strmsize
||
898 (types
->last_index
- types
->first_index
) * types
->hash_value_size
!= types
->hash_size
||
899 types
->search_offset
+ types
->search_size
> strmsize
||
900 types
->type_remap_offset
+ types
->type_remap_size
> strmsize
)
902 printf("\nIncoherent sizes... skipping\n");
905 printf("\n\tIndexes => hash value:\n");
906 for (i
= types
->first_index
; i
< types
->last_index
; i
++)
908 printf("\t\t%08x => ", i
);
909 pdb_dump_hash_value((const BYTE
*)hash
+ types
->hash_offset
+ (i
- types
->first_index
) * types
->hash_value_size
, types
->hash_value_size
);
912 /* print collisions in hash table (if any) */
913 collision
= malloc((types
->last_index
- types
->first_index
) * sizeof(unsigned));
916 unsigned head_printed
= 0;
918 collision_arg
.hash
= (const BYTE
*)hash
+ types
->hash_offset
;
919 collision_arg
.hash_size
= types
->hash_value_size
;
921 for (i
= 0; i
< types
->last_index
- types
->first_index
; i
++) collision
[i
] = i
;
922 qsort(collision
, types
->last_index
- types
->first_index
, sizeof(unsigned), collision_compar
);
923 for (i
= 0; i
< types
->last_index
- types
->first_index
; i
++)
926 for (j
= i
+ 1; j
< types
->last_index
- types
->first_index
; j
++)
927 if (memcmp((const BYTE
*)hash
+ types
->hash_offset
+ collision
[i
] * types
->hash_value_size
,
928 (const BYTE
*)hash
+ types
->hash_offset
+ collision
[j
] * types
->hash_value_size
,
929 types
->hash_value_size
))
936 printf("\n\t\tCollisions:\n");
939 printf("\t\t\tHash ");
940 pdb_dump_hash_value((const BYTE
*)hash
+ types
->hash_offset
+ collision
[i
] * types
->hash_value_size
, types
->hash_value_size
);
942 for (k
= i
; k
< j
; k
++)
943 printf(" %x", types
->first_index
+ collision
[k
]);
950 printf("\n\tIndexes => offsets:\n");
951 table
= (const unsigned*)((const BYTE
*)hash
+ types
->search_offset
);
952 for (i
= 0; i
< types
->search_size
/ (2 * sizeof(unsigned)); i
+= 2)
954 printf("\t\t%08x => %08x\n", table
[2 * i
+ 0], table
[2 * i
+ 1]);
957 if (types
->type_remap_size
)
959 unsigned num
, capa
, count_present
, count_deleted
;
960 const unsigned* present_bitset
;
961 const unsigned* deleted_bitset
;
963 printf("\n\tType remap:\n");
964 table
= (const unsigned*)((const BYTE
*)hash
+ types
->type_remap_offset
);
967 count_present
= *table
++;
968 present_bitset
= table
;
969 table
+= count_present
;
970 count_deleted
= *table
++;
971 deleted_bitset
= table
;
972 table
+= count_deleted
;
973 printf("\t\tNumber of present entries: %u\n", num
);
974 printf("\t\tCapacity: %u\n", capa
);
975 printf("\t\tBitset present:\n");
976 printf("\t\t\tCount: %u\n", count_present
);
977 printf("\t\t\tBitset: ");
978 pdb_dump_hash_value((const BYTE
*)present_bitset
, count_present
* sizeof(unsigned));
980 printf("\t\tBitset deleted:\n");
981 printf("\t\t\tCount: %u\n", count_deleted
);
982 printf("\t\t\tBitset: ");
983 pdb_dump_hash_value((const BYTE
*)deleted_bitset
, count_deleted
* sizeof(unsigned));
985 for (i
= 0; i
< capa
; ++i
)
987 printf("\t\t%2u) %c",
989 is_bit_set(present_bitset
, count_present
, i
) ? 'P' :
990 is_bit_set(deleted_bitset
, count_deleted
, i
) ? 'D' : '_');
991 if (is_bit_set(present_bitset
, count_present
, i
))
993 printf(" %s => ", pdb_get_string_table_entry(reader
->global_string_table
, *table
++));
994 pdb_dump_hash_value((const BYTE
*)table
, types
->hash_value_size
);
995 table
= (const unsigned*)((const BYTE
*)table
+ types
->hash_value_size
);
1004 /* there are two 'type' related streams, but with different indexes... */
1005 static void pdb_dump_types(struct pdb_reader
* reader
, unsigned strmidx
, const char* strmname
)
1007 PDB_TYPES
* types
= NULL
;
1008 BOOL used
= has_stream_been_read(reader
, strmidx
);
1010 if (!globals_dump_sect(strmidx
== 2 ? "TPI" : "IPI")) return;
1011 if (pdb_get_stream_size(reader
, strmidx
) < sizeof(*types
))
1014 printf("-Too small type header\n");
1017 types
= reader
->read_stream(reader
, strmidx
);
1020 switch (types
->version
)
1022 case 19950410: /* VC 4.0 */
1024 case 19961031: /* VC 5.0 / 6.0 */
1025 case 19990903: /* VC 7.0 */
1026 case 20040203: /* VC 8.0 */
1029 /* IPI stream is not always present in older PDB files */
1031 printf("-Unknown type info version %d\n", types
->version
);
1033 if (used
) clear_stream_been_read(reader
, strmidx
);
1037 /* Read type table */
1038 printf("Types (%s):\n"
1040 "\ttype_offset: %08x\n"
1041 "\tfirst_index: %x\n"
1042 "\tlast_index: %x\n"
1044 "\thash_stream: %x\n"
1046 "\thash_value_size: %x\n"
1047 "\thash_buckets %x\n"
1048 "\thash_offset: %x\n"
1050 "\tsearch_offset: %x\n"
1051 "\tsearch_size: %x\n"
1052 "\ttype_remap_offset: %x\n"
1053 "\ttype_remap_size: %x\n",
1062 types
->hash_value_size
,
1063 types
->hash_num_buckets
,
1066 types
->search_offset
,
1068 types
->type_remap_offset
,
1069 types
->type_remap_size
);
1070 codeview_dump_types_from_block((const char*)types
+ types
->type_offset
, types
->type_size
);
1071 pdb_dump_types_hash(reader
, types
, strmname
);
1075 static void pdb_dump_fpo(struct pdb_reader
* reader
, unsigned stream_idx
)
1079 const char* frame_type
[4] = {"Fpo", "Trap", "Tss", "NonFpo"};
1081 if (stream_idx
== (WORD
)-1) return;
1082 fpo
= reader
->read_stream(reader
, stream_idx
);
1083 size
= pdb_get_stream_size(reader
, stream_idx
);
1084 if (fpo
&& (size
% sizeof(*fpo
)) == 0)
1086 size
/= sizeof(*fpo
);
1087 printf("FPO data:\n\t Start Length #loc #pmt #prolog #reg frame SEH /BP\n");
1088 for (i
= 0; i
< size
; i
++)
1090 printf("\t%08x %08x %4d %4d %7d %4d %6s %c %c\n",
1091 (UINT
)fpo
[i
].ulOffStart
, (UINT
)fpo
[i
].cbProcSize
, (UINT
)fpo
[i
].cdwLocals
, fpo
[i
].cdwParams
,
1092 fpo
[i
].cbProlog
, fpo
[i
].cbRegs
, frame_type
[fpo
[i
].cbFrame
],
1093 fpo
[i
].fHasSEH
? 'Y' : 'N', fpo
[i
].fUseBP
? 'Y' : 'N');
1099 static void pdb_dump_fpo_ext(struct pdb_reader
* reader
, unsigned stream_idx
)
1101 PDB_FPO_DATA
* fpoext
;
1104 if (stream_idx
== (WORD
)-1) return;
1106 fpoext
= reader
->read_stream(reader
, stream_idx
);
1107 size
= pdb_get_stream_size(reader
, stream_idx
);
1108 if (fpoext
&& (size
% sizeof(*fpoext
)) == 0)
1110 size
/= sizeof(*fpoext
);
1111 printf("FPO data (extended):\n"
1112 "\t Start Length Locals Params MaxStack Prolog #SavedRegs Flags Command\n");
1113 for (i
= 0; i
< size
; i
++)
1115 printf("\t%08x %08x %8x %8x %8x %6x %8x %08x %s\n",
1116 fpoext
[i
].start
, fpoext
[i
].func_size
, fpoext
[i
].locals_size
, fpoext
[i
].params_size
,
1117 fpoext
[i
].maxstack_size
, fpoext
[i
].prolog_size
, fpoext
[i
].savedregs_size
, fpoext
[i
].flags
,
1118 pdb_get_string_table_entry(reader
->global_string_table
, fpoext
[i
].str_offset
));
1124 static void pdb_dump_sections(struct pdb_reader
* reader
, unsigned stream_idx
)
1128 const IMAGE_SECTION_HEADER
* sect_hdr
;
1130 if (stream_idx
== (WORD
)-1) return;
1131 segs
= reader
->read_stream(reader
, stream_idx
);
1135 printf("Sections:\n");
1136 size
= pdb_get_stream_size(reader
, stream_idx
);
1137 for (sect_hdr
= (const IMAGE_SECTION_HEADER
*)segs
; (const char*)sect_hdr
< segs
+ size
; sect_hdr
++)
1139 printf("\tSection: %-8.8s\n", sect_hdr
->Name
);
1140 printf("\t\tVirtual size: %08x\n", (unsigned)sect_hdr
->Misc
.VirtualSize
);
1141 printf("\t\tVirtualAddress: %08x\n", (unsigned)sect_hdr
->VirtualAddress
);
1142 printf("\t\tSizeOfRawData: %08x\n", (unsigned)sect_hdr
->SizeOfRawData
);
1143 printf("\t\tPointerToRawData: %08x\n", (unsigned)sect_hdr
->PointerToRawData
);
1144 printf("\t\tPointerToRelocations: %08x\n", (unsigned)sect_hdr
->PointerToRelocations
);
1145 printf("\t\tPointerToLinenumbers: %08x\n", (unsigned)sect_hdr
->PointerToLinenumbers
);
1146 printf("\t\tNumberOfRelocations: %u\n", (unsigned)sect_hdr
->NumberOfRelocations
);
1147 printf("\t\tNumberOfLinenumbers: %u\n", (unsigned)sect_hdr
->NumberOfLinenumbers
);
1148 printf("\t\tCharacteristics: %08x", (unsigned)sect_hdr
->Characteristics
);
1149 dump_section_characteristics(sect_hdr
->Characteristics
, " ");
1156 static const char pdb2
[] = "Microsoft C/C++ program database 2.00";
1158 static void pdb_jg_dump_header_root(struct pdb_reader
* reader
)
1160 UINT
*pdw
, *ok_bits
;
1161 UINT i
, numok
, count
;
1163 if (!globals_dump_sect("PDB")) return;
1165 printf("Header (JG):\n"
1167 "\tsignature: %08x\n"
1168 "\tblock_size: %08x\n"
1169 "\tfree_list_block: %04x\n"
1170 "\ttotal_alloc: %04x\n",
1171 (int)sizeof(pdb2
) - 1, reader
->u
.jg
.header
->ident
,
1172 reader
->u
.jg
.header
->signature
,
1173 reader
->u
.jg
.header
->block_size
,
1174 reader
->u
.jg
.header
->free_list_block
,
1175 reader
->u
.jg
.header
->total_alloc
);
1179 "\tTimeDateStamp: %08x\n"
1182 reader
->u
.jg
.root
->Version
,
1183 reader
->u
.jg
.root
->TimeDateStamp
,
1184 reader
->u
.jg
.root
->Age
,
1185 (unsigned)reader
->u
.jg
.root
->cbNames
);
1187 pdw
= (UINT
*)(reader
->u
.jg
.root
->names
+ reader
->u
.jg
.root
->cbNames
);
1190 printf("\tStreams directory:\n"
1196 /* bitfield: first dword is len (in dword), then data */
1198 pdw
+= *ok_bits
++ + 1;
1201 printf("unexpected value\n");
1205 for (i
= 0; i
< count
; i
++)
1207 if (ok_bits
[i
/ 32] & (1 << (i
% 32)))
1209 UINT string_idx
, stream_idx
;
1210 string_idx
= *pdw
++;
1211 stream_idx
= *pdw
++;
1212 printf("\t\t\t%2d) %-20s => %x\n", i
, &reader
->u
.jg
.root
->names
[string_idx
], stream_idx
);
1216 if (numok
) printf(">>> unmatched present field with found\n");
1218 /* Check for unknown versions */
1219 switch (reader
->u
.jg
.root
->Version
)
1221 case 19950623: /* VC 4.0 */
1223 case 19960307: /* VC 5.0 */
1224 case 19970604: /* VC 6.0 */
1227 printf("-Unknown root block version %d\n", reader
->u
.jg
.root
->Version
);
1231 static void* pdb_ds_read(const struct PDB_DS_HEADER
* header
, const UINT
*block_list
, int size
)
1236 if (!size
) return NULL
;
1238 nBlocks
= (size
+ header
->block_size
- 1) / header
->block_size
;
1239 buffer
= xmalloc(nBlocks
* header
->block_size
);
1241 for (i
= 0; i
< nBlocks
; i
++)
1242 memcpy(buffer
+ i
* header
->block_size
,
1243 (const char*)header
+ block_list
[i
] * header
->block_size
, header
->block_size
);
1248 static void* pdb_ds_read_stream(struct pdb_reader
* reader
, DWORD stream_number
)
1250 const UINT
*block_list
;
1253 if (!reader
->u
.ds
.toc
|| stream_number
>= reader
->u
.ds
.toc
->num_streams
) return NULL
;
1255 mark_stream_been_read(reader
, stream_number
);
1256 if (reader
->u
.ds
.toc
->stream_size
[stream_number
] == 0 ||
1257 reader
->u
.ds
.toc
->stream_size
[stream_number
] == 0xFFFFFFFF)
1259 block_list
= reader
->u
.ds
.toc
->stream_size
+ reader
->u
.ds
.toc
->num_streams
;
1260 for (i
= 0; i
< stream_number
; i
++)
1261 block_list
+= (reader
->u
.ds
.toc
->stream_size
[i
] + reader
->u
.ds
.header
->block_size
- 1) /
1262 reader
->u
.ds
.header
->block_size
;
1264 return pdb_ds_read(reader
->u
.ds
.header
, block_list
, reader
->u
.ds
.toc
->stream_size
[stream_number
]);
1267 static BOOL
pdb_ds_init(struct pdb_reader
* reader
)
1269 reader
->u
.ds
.header
= PRD(0, sizeof(*reader
->u
.ds
.header
));
1270 if (!reader
->u
.ds
.header
) return FALSE
;
1271 reader
->read_stream
= pdb_ds_read_stream
;
1272 reader
->u
.ds
.toc
= pdb_ds_read(reader
->u
.ds
.header
,
1273 (const UINT
*)((const char*)reader
->u
.ds
.header
+ reader
->u
.ds
.header
->toc_block
* reader
->u
.ds
.header
->block_size
),
1274 reader
->u
.ds
.header
->toc_size
);
1275 memset(reader
->stream_used
, 0, sizeof(reader
->stream_used
));
1276 reader
->u
.ds
.root
= reader
->read_stream(reader
, 1);
1277 if (!reader
->u
.ds
.root
) return FALSE
;
1281 static const char pdb7
[] = "Microsoft C/C++ MSF 7.00";
1283 static void pdb_ds_dump_header_root(struct pdb_reader
* reader
)
1285 unsigned int i
, j
, ofs
;
1286 const UINT
*block_list
;
1287 UINT
*pdw
, *ok_bits
;
1291 if (!globals_dump_sect("PDB")) return;
1292 strmsize
= pdb_get_stream_size(reader
, 1);
1293 printf("Header (DS)\n"
1294 "\tsignature: %.*s\n"
1295 "\tblock_size: %08x\n"
1296 "\tfree_list_block: %08x\n"
1297 "\tnum_blocks: %08x\n"
1298 "\ttoc_size: %08x\n"
1299 "\tunknown2: %08x\n"
1300 "\ttoc_block: %08x\n",
1301 (int)sizeof(pdb7
) - 1, reader
->u
.ds
.header
->signature
,
1302 reader
->u
.ds
.header
->block_size
,
1303 reader
->u
.ds
.header
->free_list_block
,
1304 reader
->u
.ds
.header
->num_blocks
,
1305 reader
->u
.ds
.header
->toc_size
,
1306 reader
->u
.ds
.header
->unknown2
,
1307 reader
->u
.ds
.header
->toc_block
);
1309 block_list
= reader
->u
.ds
.toc
->stream_size
+ reader
->u
.ds
.toc
->num_streams
;
1310 printf("\t\tnum_streams: %u\n", reader
->u
.ds
.toc
->num_streams
);
1311 for (ofs
= i
= 0; i
< reader
->u
.ds
.toc
->num_streams
; i
++)
1313 unsigned int nblk
= (reader
->u
.ds
.toc
->stream_size
[i
] + reader
->u
.ds
.header
->block_size
- 1) / reader
->u
.ds
.header
->block_size
;
1314 printf("\t\tstream[%#x]:\tsize: %u\n", i
, reader
->u
.ds
.toc
->stream_size
[i
]);
1317 for (j
= 0; j
< nblk
; j
++)
1319 if (j
% 16 == 0) printf("\t\t\t");
1320 printf("%4x ", block_list
[ofs
+ j
]);
1321 if (j
% 16 == 15 || (j
+ 1 == nblk
)) printf("\n");
1329 "\tTimeDateStamp: %08x\n"
1332 "\tcbNames: %08x\n",
1333 reader
->u
.ds
.root
->Version
,
1334 reader
->u
.ds
.root
->TimeDateStamp
,
1335 reader
->u
.ds
.root
->Age
,
1336 get_guid_str(&reader
->u
.ds
.root
->guid
),
1337 reader
->u
.ds
.root
->cbNames
);
1338 pdw
= (UINT
*)(reader
->u
.ds
.root
->names
+ reader
->u
.ds
.root
->cbNames
);
1341 printf("\tStreams directory:\n"
1347 /* bitfield: first dword is len (in dword), then data */
1349 pdw
+= *ok_bits
++ + 1;
1352 printf("unexpected value\n");
1356 for (i
= 0; i
< count
; i
++)
1358 if (ok_bits
[i
/ 32] & (1 << (i
% 32)))
1360 UINT string_idx
, stream_idx
;
1361 string_idx
= *pdw
++;
1362 stream_idx
= *pdw
++;
1363 printf("\t\t\t%2d) %-20s => %x\n", i
, &reader
->u
.ds
.root
->names
[string_idx
], stream_idx
);
1367 if (numok
) printf(">>> unmatched present field with found\n");
1370 printf("unexpected value\n");
1374 if (pdw
+ 1 <= (UINT
*)((char*)reader
->u
.ds
.root
+ strmsize
))
1376 /* extra information (version reference and features) */
1377 printf("\tVersion and features\n");
1378 while (pdw
+ 1 <= (UINT
*)((char*)reader
->u
.ds
.root
+ strmsize
))
1382 /* version reference */
1383 case 20091201: printf("\t\tVC110\n"); break;
1384 case 20140508: printf("\t\tVC140\n"); break;
1386 case 0x4D544F4E /* NOTM */: printf("\t\tNo type merge\n"); break;
1387 case 0x494E494D /* MINI */: printf("\t\tMinimal debug info\n"); break;
1388 default: printf("\t\tUnknown value %x\n", *pdw
);
1395 enum FileSig
get_kind_pdb(void)
1399 head
= PRD(0, sizeof(pdb2
) - 1);
1400 if (head
&& !memcmp(head
, pdb2
, sizeof(pdb2
) - 1))
1402 head
= PRD(0, sizeof(pdb7
) - 1);
1403 if (head
&& !memcmp(head
, pdb7
, sizeof(pdb7
) - 1))
1411 const char** saved_dumpsect
= globals
.dumpsect
;
1412 static const char* default_dumpsect
[] = {"DBI", "TPI", "IPI", NULL
};
1413 struct pdb_reader reader
;
1415 if (!globals
.dumpsect
) globals
.dumpsect
= default_dumpsect
;
1417 if ((head
= PRD(0, sizeof(pdb2
) - 1)) && !memcmp(head
, pdb2
, sizeof(pdb2
) - 1))
1419 if (!pdb_jg_init(&reader
))
1421 printf("Unable to get header information\n");
1425 pdb_jg_dump_header_root(&reader
);
1427 else if ((head
= PRD(0, sizeof(pdb7
) - 1)) && !memcmp(head
, pdb7
, sizeof(pdb7
) - 1))
1429 if (!pdb_ds_init(&reader
))
1431 printf("Unable to get header information\n");
1434 pdb_ds_dump_header_root(&reader
);
1436 mark_stream_been_read(&reader
, 0); /* mark stream #0 (old TOC) as read */
1438 reader
.global_string_table
= read_string_table(&reader
);
1440 pdb_dump_types(&reader
, 2, "TPI");
1441 pdb_dump_types(&reader
, 4, "IPI");
1442 pdb_dump_symbols(&reader
);
1446 globals
.dumpsect
= saved_dumpsect
;