1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
typedef struct Dwarf Dwarf;
typedef struct DwarfAttrs DwarfAttrs;
typedef struct DwarfBlock DwarfBlock;
typedef struct DwarfBuf DwarfBuf;
typedef struct DwarfExpr DwarfExpr;
typedef struct DwarfSym DwarfSym;
typedef union DwarfVal DwarfVal;
enum
{
TagArrayType = 0x01,
TagClassType = 0x02,
TagEntryPoint = 0x03,
TagEnumerationType = 0x04,
TagFormalParameter = 0x05,
TagImportedDeclaration = 0x08,
TagLabel = 0x0A,
TagLexDwarfBlock = 0x0B,
TagMember = 0x0D,
TagPointerType = 0x0F,
TagReferenceType = 0x10,
TagCompileUnit = 0x11,
TagStringType = 0x12,
TagStructType = 0x13,
TagSubroutineType = 0x15,
TagTypedef = 0x16,
TagUnionType = 0x17,
TagUnspecifiedParameters = 0x18,
TagVariant = 0x19,
TagCommonDwarfBlock = 0x1A,
TagCommonInclusion = 0x1B,
TagInheritance = 0x1C,
TagInlinedSubroutine = 0x1D,
TagModule = 0x1E,
TagPtrToMemberType = 0x1F,
TagSetType = 0x20,
TagSubrangeType = 0x21,
TagWithStmt = 0x22,
TagAccessDeclaration = 0x23,
TagBaseType = 0x24,
TagCatchDwarfBlock = 0x25,
TagConstType = 0x26,
TagConstant = 0x27,
TagEnumerator = 0x28,
TagFileType = 0x29,
TagFriend = 0x2A,
TagNamelist = 0x2B,
TagNamelistItem = 0x2C,
TagPackedType = 0x2D,
TagSubprogram = 0x2E,
TagTemplateTypeParameter = 0x2F,
TagTemplateValueParameter = 0x30,
TagThrownType = 0x31,
TagTryDwarfBlock = 0x32,
TagVariantPart = 0x33,
TagVariable = 0x34,
TagVolatileType = 0x35,
TagDwarfProcedure = 0x36,
TagRestrictType = 0x37,
TagInterfaceType = 0x38,
TagNamespace = 0x39,
TagImportedModule = 0x3A,
TagUnspecifiedType = 0x3B,
TagPartialUnit = 0x3C,
TagImportedUnit = 0x3D,
TagMutableType = 0x3E,
TypeAddress = 0x01,
TypeBoolean = 0x02,
TypeComplexFloat = 0x03,
TypeFloat = 0x04,
TypeSigned = 0x05,
TypeSignedChar = 0x06,
TypeUnsigned = 0x07,
TypeUnsignedChar = 0x08,
TypeImaginaryFloat = 0x09,
AccessPublic = 0x01,
AccessProtected = 0x02,
AccessPrivate = 0x03,
VisLocal = 0x01,
VisExported = 0x02,
VisQualified = 0x03,
VirtNone = 0x00,
VirtVirtual = 0x01,
VirtPureVirtual = 0x02,
LangC89 = 0x0001,
LangC = 0x0002,
LangAda83 = 0x0003,
LangCplusplus = 0x0004,
LangCobol74 = 0x0005,
LangCobol85 = 0x0006,
LangFortran77 = 0x0007,
LangFortran90 = 0x0008,
LangPascal83 = 0x0009,
LangModula2 = 0x000A,
LangJava = 0x000B,
LangC99 = 0x000C,
LangAda95 = 0x000D,
LangFortran95 = 0x000E,
LangPLI = 0x000F,
/* 0x8000-0xFFFF reserved */
IdCaseSensitive = 0x00,
IdCaseUpper = 0x01,
IdCaseLower = 0x02,
IdCaseInsensitive = 0x03,
CallingNormal = 0x01,
CallingProgram = 0x02,
CallingNocall = 0x03,
/* 0x40-0xFF reserved */
InNone = 0x00,
InInlined = 0x01,
InDeclaredNotInlined = 0x02,
InDeclaredInlined = 0x03,
OrderRowMajor = 0x00,
OrderColumnMajor = 0x01,
DiscLabel = 0x00,
DiscRange = 0x01,
TReference = 1<<0,
TBlock = 1<<1,
TConstant = 1<<2,
TString = 1<<3,
TFlag = 1<<4,
TAddress = 1<<5,
OpAddr = 0x03, /* 1 op, const addr */
OpDeref = 0x06,
OpConst1u = 0x08, /* 1 op, 1 byte const */
OpConst1s = 0x09, /* " signed */
OpConst2u = 0x0A, /* 1 op, 2 byte const */
OpConst2s = 0x0B, /* " signed */
OpConst4u = 0x0C, /* 1 op, 4 byte const */
OpConst4s = 0x0D, /* " signed */
OpConst8u = 0x0E, /* 1 op, 8 byte const */
OpConst8s = 0x0F, /* " signed */
OpConstu = 0x10, /* 1 op, LEB128 const */
OpConsts = 0x11, /* " signed */
OpDup = 0x12,
OpDrop = 0x13,
OpOver = 0x14,
OpPick = 0x15, /* 1 op, 1 byte stack index */
OpSwap = 0x16,
OpRot = 0x17,
OpXderef = 0x18,
OpAbs = 0x19,
OpAnd = 0x1A,
OpDiv = 0x1B,
OpMinus = 0x1C,
OpMod = 0x1D,
OpMul = 0x1E,
OpNeg = 0x1F,
OpNot = 0x20,
OpOr = 0x21,
OpPlus = 0x22,
OpPlusUconst = 0x23, /* 1 op, ULEB128 addend */
OpShl = 0x24,
OpShr = 0x25,
OpShra = 0x26,
OpXor = 0x27,
OpSkip = 0x2F, /* 1 op, signed 2-byte constant */
OpBra = 0x28, /* 1 op, signed 2-byte constant */
OpEq = 0x29,
OpGe = 0x2A,
OpGt = 0x2B,
OpLe = 0x2C,
OpLt = 0x2D,
OpNe = 0x2E,
OpLit0 = 0x30,
/* OpLitN = OpLit0 + N for N = 0..31 */
OpReg0 = 0x50,
/* OpRegN = OpReg0 + N for N = 0..31 */
OpBreg0 = 0x70, /* 1 op, signed LEB128 constant */
/* OpBregN = OpBreg0 + N for N = 0..31 */
OpRegx = 0x90, /* 1 op, ULEB128 register */
OpFbreg = 0x91, /* 1 op, SLEB128 offset */
OpBregx = 0x92, /* 2 op, ULEB128 reg, SLEB128 off */
OpPiece = 0x93, /* 1 op, ULEB128 size of piece */
OpDerefSize = 0x94, /* 1-byte size of data retrieved */
OpXderefSize = 0x95, /* 1-byte size of data retrieved */
OpNop = 0x96,
/* next four new in Dwarf v3 */
OpPushObjAddr = 0x97,
OpCall2 = 0x98, /* 2-byte offset of DIE */
OpCall4 = 0x99, /* 4-byte offset of DIE */
OpCallRef = 0x9A /* 4- or 8- byte offset of DIE */
/* 0xE0-0xFF reserved for user-specific */
};
struct DwarfBlock
{
uchar *data;
ulong len;
};
/* not for consumer use */
struct DwarfBuf
{
Dwarf *d;
uchar *p;
uchar *ep;
uint addrsize;
};
union DwarfVal
{
char *s;
ulong c;
ulong r;
DwarfBlock b;
};
struct DwarfAttrs
{
ulong tag;
uchar haskids;
/* whether we have it, along with type */
struct {
uchar abstractorigin;
uchar accessibility;
uchar addrclass;
uchar basetypes;
uchar bitoffset;
uchar bitsize;
uchar bytesize;
uchar calling;
uchar commonref;
uchar compdir;
uchar constvalue;
uchar containingtype;
uchar count;
uchar datamemberloc;
uchar declcolumn;
uchar declfile;
uchar declline;
uchar defaultvalue;
uchar discr;
uchar discrlist;
uchar discrvalue;
uchar encoding;
uchar framebase;
uchar friend;
uchar highpc;
uchar identifiercase;
uchar import;
uchar inlined;
uchar isartificial;
uchar isdeclaration;
uchar isexternal;
uchar isoptional;
uchar isprototyped;
uchar isvarparam;
uchar language;
uchar location;
uchar lowerbound;
uchar lowpc;
uchar macroinfo;
uchar name;
uchar namelistitem;
uchar ordering;
uchar priority;
uchar producer;
uchar ranges;
uchar returnaddr;
uchar segment;
uchar sibling;
uchar specification;
uchar startscope;
uchar staticlink;
uchar stmtlist;
uchar stridesize;
uchar stringlength;
uchar type;
uchar upperbound;
uchar uselocation;
uchar virtuality;
uchar visibility;
uchar vtableelemloc;
} have;
ulong abstractorigin;
ulong accessibility;
ulong addrclass;
ulong basetypes;
ulong bitoffset;
ulong bitsize;
ulong bytesize;
ulong calling;
ulong commonref;
char* compdir;
DwarfVal constvalue;
ulong containingtype;
ulong count;
DwarfVal datamemberloc;
ulong declcolumn;
ulong declfile;
ulong declline;
ulong defaultvalue;
ulong discr;
DwarfBlock discrlist;
ulong discrvalue;
ulong encoding;
DwarfVal framebase;
ulong friend;
ulong highpc;
ulong identifiercase;
ulong import;
ulong inlined;
uchar isartificial;
uchar isdeclaration;
uchar isexternal;
uchar isoptional;
uchar isprototyped;
uchar isvarparam;
ulong language;
DwarfVal location;
ulong lowerbound;
ulong lowpc;
ulong macroinfo;
char* name;
DwarfBlock namelistitem;
ulong ordering;
ulong priority;
char* producer;
ulong ranges;
DwarfVal returnaddr;
DwarfVal segment;
ulong sibling;
ulong specification;
ulong startscope;
DwarfVal staticlink;
ulong stmtlist;
ulong stridesize;
DwarfVal stringlength;
ulong type;
ulong upperbound;
DwarfVal uselocation;
ulong virtuality;
ulong visibility;
DwarfVal vtableelemloc;
};
enum
{
RuleUndef,
RuleSame,
RuleCfaOffset,
RuleRegister,
RuleRegOff,
RuleLocation
};
struct DwarfExpr
{
int type;
long offset;
ulong reg;
DwarfBlock loc;
};
struct DwarfSym
{
DwarfAttrs attrs;
/* not for consumer use... */
DwarfBuf b;
ulong unit;
uint uoff;
ulong aoff;
int depth;
int allunits;
ulong nextunit;
};
Dwarf *dwarfopen(Elf *elf);
void dwarfclose(Dwarf*);
int dwarfaddrtounit(Dwarf*, ulong, ulong*);
int dwarflookupfn(Dwarf*, ulong, ulong, DwarfSym*);
int dwarflookupname(Dwarf*, char*, DwarfSym*);
int dwarflookupnameinunit(Dwarf*, ulong, char*, DwarfSym*);
int dwarflookupsubname(Dwarf*, DwarfSym*, char*, DwarfSym*);
int dwarflookuptag(Dwarf*, ulong, ulong, DwarfSym*);
int dwarfenumunit(Dwarf*, ulong, DwarfSym*);
int dwarfseeksym(Dwarf*, ulong, ulong, DwarfSym*);
int dwarfenum(Dwarf*, DwarfSym*);
int dwarfnextsym(Dwarf*, DwarfSym*);
int dwarfnextsymat(Dwarf*, DwarfSym*, int);
int dwarfpctoline(Dwarf*, ulong, char**, char**, char**, ulong*, ulong*, ulong*);
int dwarfunwind(Dwarf*, ulong, DwarfExpr*, DwarfExpr*, DwarfExpr*, int);
ulong dwarfget1(DwarfBuf*);
ulong dwarfget2(DwarfBuf*);
ulong dwarfget4(DwarfBuf*);
uvlong dwarfget8(DwarfBuf*);
ulong dwarfget128(DwarfBuf*);
long dwarfget128s(DwarfBuf*);
ulong dwarfgetaddr(DwarfBuf*);
int dwarfgetn(DwarfBuf*, uchar*, int);
uchar *dwarfgetnref(DwarfBuf*, ulong);
char *dwarfgetstring(DwarfBuf*);
typedef struct DwarfAbbrev DwarfAbbrev;
typedef struct DwarfAttr DwarfAttr;
struct DwarfAttr
{
ulong name;
ulong form;
};
struct DwarfAbbrev
{
ulong num;
ulong tag;
uchar haskids;
DwarfAttr *attr;
int nattr;
};
struct Dwarf
{
Elf *elf;
int fd;
char **reg;
int nreg;
int addrsize;
DwarfBlock abbrev;
DwarfBlock aranges;
DwarfBlock frame;
DwarfBlock info;
DwarfBlock line;
DwarfBlock pubnames;
DwarfBlock pubtypes;
DwarfBlock ranges;
DwarfBlock str;
/* little cache */
struct {
DwarfAbbrev *a;
int na;
ulong off;
} acache;
};
DwarfAbbrev *dwarfgetabbrev(Dwarf*, ulong, ulong);
int dwarfgetinfounit(Dwarf*, ulong, DwarfBlock*);
extern int dwarf386nregs;
extern char *dwarf386regs[];
extern char *dwarf386fp;
|