xref: /openbmc/qemu/contrib/elf2dmp/pdb.h (revision 31cf4b97)
1 /*
2  * Copyright (c) 2018 Virtuozzo International GmbH
3  *
4  * This work is licensed under the terms of the GNU GPL, version 2 or later.
5  *
6  */
7 
8 #ifndef PDB_H
9 #define PDB_H
10 
11 
12 typedef struct GUID {
13     unsigned int Data1;
14     unsigned short Data2;
15     unsigned short Data3;
16     unsigned char Data4[8];
17 } GUID;
18 
19 struct PDB_FILE {
20     uint32_t size;
21     uint32_t unknown;
22 };
23 
24 typedef struct PDB_DS_HEADER {
25     char signature[32];
26     uint32_t block_size;
27     uint32_t unknown1;
28     uint32_t num_pages;
29     uint32_t toc_size;
30     uint32_t unknown2;
31     uint32_t toc_page;
32 } PDB_DS_HEADER;
33 
34 typedef struct PDB_DS_TOC {
35     uint32_t num_files;
36     uint32_t file_size[1];
37 } PDB_DS_TOC;
38 
39 typedef struct PDB_DS_ROOT {
40     uint32_t Version;
41     uint32_t TimeDateStamp;
42     uint32_t Age;
43     GUID guid;
44     uint32_t cbNames;
45     char names[1];
46 } PDB_DS_ROOT;
47 
48 typedef struct PDB_TYPES_OLD {
49     uint32_t version;
50     uint16_t first_index;
51     uint16_t last_index;
52     uint32_t type_size;
53     uint16_t file;
54     uint16_t pad;
55 } PDB_TYPES_OLD;
56 
57 typedef struct PDB_TYPES {
58     uint32_t version;
59     uint32_t type_offset;
60     uint32_t first_index;
61     uint32_t last_index;
62     uint32_t type_size;
63     uint16_t file;
64     uint16_t pad;
65     uint32_t hash_size;
66     uint32_t hash_base;
67     uint32_t hash_offset;
68     uint32_t hash_len;
69     uint32_t search_offset;
70     uint32_t search_len;
71     uint32_t unknown_offset;
72     uint32_t unknown_len;
73 } PDB_TYPES;
74 
75 typedef struct PDB_SYMBOL_RANGE {
76     uint16_t segment;
77     uint16_t pad1;
78     uint32_t offset;
79     uint32_t size;
80     uint32_t characteristics;
81     uint16_t index;
82     uint16_t pad2;
83 } PDB_SYMBOL_RANGE;
84 
85 typedef struct PDB_SYMBOL_RANGE_EX {
86     uint16_t segment;
87     uint16_t pad1;
88     uint32_t offset;
89     uint32_t size;
90     uint32_t characteristics;
91     uint16_t index;
92     uint16_t pad2;
93     uint32_t timestamp;
94     uint32_t unknown;
95 } PDB_SYMBOL_RANGE_EX;
96 
97 typedef struct PDB_SYMBOL_FILE {
98     uint32_t unknown1;
99     PDB_SYMBOL_RANGE range;
100     uint16_t flag;
101     uint16_t file;
102     uint32_t symbol_size;
103     uint32_t lineno_size;
104     uint32_t unknown2;
105     uint32_t nSrcFiles;
106     uint32_t attribute;
107     char filename[1];
108 } PDB_SYMBOL_FILE;
109 
110 typedef struct PDB_SYMBOL_FILE_EX {
111     uint32_t unknown1;
112     PDB_SYMBOL_RANGE_EX range;
113     uint16_t flag;
114     uint16_t file;
115     uint32_t symbol_size;
116     uint32_t lineno_size;
117     uint32_t unknown2;
118     uint32_t nSrcFiles;
119     uint32_t attribute;
120     uint32_t reserved[2];
121     char filename[1];
122 } PDB_SYMBOL_FILE_EX;
123 
124 typedef struct PDB_SYMBOL_SOURCE {
125     uint16_t nModules;
126     uint16_t nSrcFiles;
127     uint16_t table[1];
128 } PDB_SYMBOL_SOURCE;
129 
130 typedef struct PDB_SYMBOL_IMPORT {
131     uint32_t unknown1;
132     uint32_t unknown2;
133     uint32_t TimeDateStamp;
134     uint32_t Age;
135     char filename[1];
136 } PDB_SYMBOL_IMPORT;
137 
138 typedef struct PDB_SYMBOLS_OLD {
139     uint16_t hash1_file;
140     uint16_t hash2_file;
141     uint16_t gsym_file;
142     uint16_t pad;
143     uint32_t module_size;
144     uint32_t offset_size;
145     uint32_t hash_size;
146     uint32_t srcmodule_size;
147 } PDB_SYMBOLS_OLD;
148 
149 typedef struct PDB_SYMBOLS {
150     uint32_t signature;
151     uint32_t version;
152     uint32_t unknown;
153     uint32_t hash1_file;
154     uint32_t hash2_file;
155     uint16_t gsym_file;
156     uint16_t unknown1;
157     uint32_t module_size;
158     uint32_t offset_size;
159     uint32_t hash_size;
160     uint32_t srcmodule_size;
161     uint32_t pdbimport_size;
162     uint32_t resvd0;
163     uint32_t stream_index_size;
164     uint32_t unknown2_size;
165     uint16_t resvd3;
166     uint16_t machine;
167     uint32_t resvd4;
168 } PDB_SYMBOLS;
169 
170 typedef struct {
171     uint16_t FPO;
172     uint16_t unk0;
173     uint16_t unk1;
174     uint16_t unk2;
175     uint16_t unk3;
176     uint16_t segments;
177 } PDB_STREAM_INDEXES_OLD;
178 
179 typedef struct {
180     uint16_t FPO;
181     uint16_t unk0;
182     uint16_t unk1;
183     uint16_t unk2;
184     uint16_t unk3;
185     uint16_t segments;
186     uint16_t unk4;
187     uint16_t unk5;
188     uint16_t unk6;
189     uint16_t FPO_EXT;
190     uint16_t unk7;
191 } PDB_STREAM_INDEXES;
192 
193 union codeview_symbol {
194     struct {
195         int16_t len;
196         int16_t id;
197     } generic;
198 
199     struct {
200         int16_t len;
201         int16_t id;
202         uint32_t symtype;
203         uint32_t offset;
204         uint16_t segment;
205         char name[1];
206     } public_v3;
207 };
208 
209 #define S_PUB_V3        0x110E
210 
211 typedef struct pdb_seg {
212     uint32_t dword[8];
213 } __attribute__ ((packed)) pdb_seg;
214 
215 #define IMAGE_FILE_MACHINE_I386 0x014c
216 #define IMAGE_FILE_MACHINE_AMD64 0x8664
217 
218 struct pdb_reader {
219     int fd;
220     size_t file_size;
221     struct {
222         PDB_DS_HEADER *header;
223         PDB_DS_TOC *toc;
224         PDB_DS_ROOT *root;
225     } ds;
226     uint32_t file_used[1024];
227     PDB_SYMBOLS *symbols;
228     PDB_STREAM_INDEXES sidx;
229     uint8_t *modimage;
230     char *segs;
231     size_t segs_size;
232 };
233 
234 int pdb_init_from_file(const char *name, struct pdb_reader *reader);
235 void pdb_exit(struct pdb_reader *reader);
236 uint64_t pdb_resolve(uint64_t img_base, struct pdb_reader *r, const char *name);
237 uint64_t pdb_find_public_v3_symbol(struct pdb_reader *reader, const char *name);
238 
239 #endif /* PDB_H */
240