ReactOS  0.4.11-dev-465-g0e6bc23
dwarf.h File Reference
#include "compat.h"
Include dependency graph for dwarf.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DwarfBlock
 
struct  DwarfBuf
 
union  DwarfVal
 
struct  DwarfAttrs
 
struct  DwarfExpr
 
struct  DwarfSym
 
struct  DwarfAttr
 
struct  DwarfAbbrev
 
struct  Dwarf
 

Macros

#define SYMBOL_SIZE   18
 
#define MAXIMUM_DWARF_NAME_SIZE   64
 
#define MAXIMUM_COFF_SYMBOL_LENGTH   256
 

Typedefs

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
 
typedef struct DwarfAbbrev DwarfAbbrev
 
typedef struct DwarfAttr DwarfAttr
 

Enumerations

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, IdCaseSensitive = 0x00, IdCaseUpper = 0x01, IdCaseLower = 0x02,
  IdCaseInsensitive = 0x03, CallingNormal = 0x01, CallingProgram = 0x02, CallingNocall = 0x03,
  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, OpDeref = 0x06,
  OpConst1u = 0x08, OpConst1s = 0x09, OpConst2u = 0x0A, OpConst2s = 0x0B,
  OpConst4u = 0x0C, OpConst4s = 0x0D, OpConst8u = 0x0E, OpConst8s = 0x0F,
  OpConstu = 0x10, OpConsts = 0x11, OpDup = 0x12, OpDrop = 0x13,
  OpOver = 0x14, OpPick = 0x15, 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,
  OpShl = 0x24, OpShr = 0x25, OpShra = 0x26, OpXor = 0x27,
  OpSkip = 0x2F, OpBra = 0x28, OpEq = 0x29, OpGe = 0x2A,
  OpGt = 0x2B, OpLe = 0x2C, OpLt = 0x2D, OpNe = 0x2E,
  OpLit0 = 0x30, OpReg0 = 0x50, OpBreg0 = 0x70, OpRegx = 0x90,
  OpFbreg = 0x91, OpBregx = 0x92, OpPiece = 0x93, OpDerefSize = 0x94,
  OpXderefSize = 0x95, OpNop = 0x96, OpPushObjAddr = 0x97, OpCall2 = 0x98,
  OpCall4 = 0x99, OpCallRef = 0x9A
}
 
enum  {
  RuleUndef, RuleSame, RuleCfaOffset, RuleRegister,
  RuleRegOff, RuleLocation
}
 

Functions

Dwarfdwarfopen (struct _Pe *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 **, 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)
 
uchardwarfgetnref (DwarfBuf *, ulong)
 
chardwarfgetstring (DwarfBuf *)
 
DwarfAbbrevdwarfgetabbrev (Dwarf *, ulong, ulong)
 
int dwarfgetinfounit (Dwarf *, ulong, DwarfBlock *)
 

Variables

int dwarf386nregs
 
chardwarf386regs []
 
chardwarf386fp
 

Macro Definition Documentation

#define MAXIMUM_COFF_SYMBOL_LENGTH   256

Definition at line 471 of file dwarf.h.

#define MAXIMUM_DWARF_NAME_SIZE   64

Definition at line 470 of file dwarf.h.

Referenced by RosSymCreateFromFile(), and RosSymCreateFromMem().

#define SYMBOL_SIZE   18

Definition at line 469 of file dwarf.h.

Referenced by RosSymCreateFromMem().

Typedef Documentation

typedef struct Dwarf Dwarf

Definition at line 3 of file dwarf.h.

Definition at line 416 of file dwarf.h.

Definition at line 417 of file dwarf.h.

Definition at line 4 of file dwarf.h.

Definition at line 5 of file dwarf.h.

Definition at line 6 of file dwarf.h.

Definition at line 7 of file dwarf.h.

Definition at line 8 of file dwarf.h.

typedef union DwarfVal DwarfVal

Definition at line 9 of file dwarf.h.

Enumeration Type Documentation

anonymous enum
Enumerator
TagArrayType 
TagClassType 
TagEntryPoint 
TagEnumerationType 
TagFormalParameter 
TagImportedDeclaration 
TagLabel 
TagLexDwarfBlock 
TagMember 
TagPointerType 
TagReferenceType 
TagCompileUnit 
TagStringType 
TagStructType 
TagSubroutineType 
TagTypedef 
TagUnionType 
TagUnspecifiedParameters 
TagVariant 
TagCommonDwarfBlock 
TagCommonInclusion 
TagInheritance 
TagInlinedSubroutine 
TagModule 
TagPtrToMemberType 
TagSetType 
TagSubrangeType 
TagWithStmt 
TagAccessDeclaration 
TagBaseType 
TagCatchDwarfBlock 
TagConstType 
TagConstant 
TagEnumerator 
TagFileType 
TagFriend 
TagNamelist 
TagNamelistItem 
TagPackedType 
TagSubprogram 
TagTemplateTypeParameter 
TagTemplateValueParameter 
TagThrownType 
TagTryDwarfBlock 
TagVariantPart 
TagVariable 
TagVolatileType 
TagDwarfProcedure 
TagRestrictType 
TagInterfaceType 
TagNamespace 
TagImportedModule 
TagUnspecifiedType 
TagPartialUnit 
TagImportedUnit 
TagMutableType 
TypeAddress 
TypeBoolean 
TypeComplexFloat 
TypeFloat 
TypeSigned 
TypeSignedChar 
TypeUnsigned 
TypeUnsignedChar 
TypeImaginaryFloat 
AccessPublic 
AccessProtected 
AccessPrivate 
VisLocal 
VisExported 
VisQualified 
VirtNone 
VirtVirtual 
VirtPureVirtual 
LangC89 
LangC 
LangAda83 
LangCplusplus 
LangCobol74 
LangCobol85 
LangFortran77 
LangFortran90 
LangPascal83 
LangModula2 
LangJava 
LangC99 
LangAda95 
LangFortran95 
LangPLI 
IdCaseSensitive 
IdCaseUpper 
IdCaseLower 
IdCaseInsensitive 
CallingNormal 
CallingProgram 
CallingNocall 
InNone 
InInlined 
InDeclaredNotInlined 
InDeclaredInlined 
OrderRowMajor 
OrderColumnMajor 
DiscLabel 
DiscRange 
TReference 
TBlock 
TConstant 
TString 
TFlag 
TAddress 
OpAddr 
OpDeref 
OpConst1u 
OpConst1s 
OpConst2u 
OpConst2s 
OpConst4u 
OpConst4s 
OpConst8u 
OpConst8s 
OpConstu 
OpConsts 
OpDup 
OpDrop 
OpOver 
OpPick 
OpSwap 
OpRot 
OpXderef 
OpAbs 
OpAnd 
OpDiv 
OpMinus 
OpMod 
OpMul 
OpNeg 
OpNot 
OpOr 
OpPlus 
OpPlusUconst 
OpShl 
OpShr 
OpShra 
OpXor 
OpSkip 
OpBra 
OpEq 
OpGe 
OpGt 
OpLe 
OpLt 
OpNe 
OpLit0 
OpReg0 
OpBreg0 
OpRegx 
OpFbreg 
OpBregx 
OpPiece 
OpDerefSize 
OpXderefSize 
OpNop 
OpPushObjAddr 
OpCall2 
OpCall4 
OpCallRef 

Definition at line 11 of file dwarf.h.

12 {
13  TagArrayType = 0x01,
14  TagClassType = 0x02,
15  TagEntryPoint = 0x03,
16  TagEnumerationType = 0x04,
17  TagFormalParameter = 0x05,
19  TagLabel = 0x0A,
20  TagLexDwarfBlock = 0x0B,
21  TagMember = 0x0D,
22  TagPointerType = 0x0F,
23  TagReferenceType = 0x10,
24  TagCompileUnit = 0x11,
25  TagStringType = 0x12,
26  TagStructType = 0x13,
27  TagSubroutineType = 0x15,
28  TagTypedef = 0x16,
29  TagUnionType = 0x17,
31  TagVariant = 0x19,
32  TagCommonDwarfBlock = 0x1A,
33  TagCommonInclusion = 0x1B,
34  TagInheritance = 0x1C,
35  TagInlinedSubroutine = 0x1D,
36  TagModule = 0x1E,
37  TagPtrToMemberType = 0x1F,
38  TagSetType = 0x20,
39  TagSubrangeType = 0x21,
40  TagWithStmt = 0x22,
41  TagAccessDeclaration = 0x23,
42  TagBaseType = 0x24,
43  TagCatchDwarfBlock = 0x25,
44  TagConstType = 0x26,
45  TagConstant = 0x27,
46  TagEnumerator = 0x28,
47  TagFileType = 0x29,
48  TagFriend = 0x2A,
49  TagNamelist = 0x2B,
50  TagNamelistItem = 0x2C,
51  TagPackedType = 0x2D,
52  TagSubprogram = 0x2E,
55  TagThrownType = 0x31,
56  TagTryDwarfBlock = 0x32,
57  TagVariantPart = 0x33,
58  TagVariable = 0x34,
59  TagVolatileType = 0x35,
60  TagDwarfProcedure = 0x36,
61  TagRestrictType = 0x37,
62  TagInterfaceType = 0x38,
63  TagNamespace = 0x39,
64  TagImportedModule = 0x3A,
65  TagUnspecifiedType = 0x3B,
66  TagPartialUnit = 0x3C,
67  TagImportedUnit = 0x3D,
68  TagMutableType = 0x3E,
69 
70  TypeAddress = 0x01,
71  TypeBoolean = 0x02,
72  TypeComplexFloat = 0x03,
73  TypeFloat = 0x04,
74  TypeSigned = 0x05,
75  TypeSignedChar = 0x06,
76  TypeUnsigned = 0x07,
77  TypeUnsignedChar = 0x08,
78  TypeImaginaryFloat = 0x09,
79 
80  AccessPublic = 0x01,
81  AccessProtected = 0x02,
82  AccessPrivate = 0x03,
83 
84  VisLocal = 0x01,
85  VisExported = 0x02,
86  VisQualified = 0x03,
87 
88  VirtNone = 0x00,
89  VirtVirtual = 0x01,
90  VirtPureVirtual = 0x02,
91 
92  LangC89 = 0x0001,
93  LangC = 0x0002,
94  LangAda83 = 0x0003,
95  LangCplusplus = 0x0004,
96  LangCobol74 = 0x0005,
97  LangCobol85 = 0x0006,
98  LangFortran77 = 0x0007,
99  LangFortran90 = 0x0008,
100  LangPascal83 = 0x0009,
101  LangModula2 = 0x000A,
102  LangJava = 0x000B,
103  LangC99 = 0x000C,
104  LangAda95 = 0x000D,
105  LangFortran95 = 0x000E,
106  LangPLI = 0x000F,
107  /* 0x8000-0xFFFF reserved */
108 
109  IdCaseSensitive = 0x00,
110  IdCaseUpper = 0x01,
111  IdCaseLower = 0x02,
112  IdCaseInsensitive = 0x03,
113 
114  CallingNormal = 0x01,
115  CallingProgram = 0x02,
116  CallingNocall = 0x03,
117  /* 0x40-0xFF reserved */
118 
119  InNone = 0x00,
120  InInlined = 0x01,
121  InDeclaredNotInlined = 0x02,
122  InDeclaredInlined = 0x03,
123 
124  OrderRowMajor = 0x00,
125  OrderColumnMajor = 0x01,
126 
127  DiscLabel = 0x00,
128  DiscRange = 0x01,
129 
130  TReference = 1<<0,
131  TBlock = 1<<1,
132  TConstant = 1<<2,
133  TString = 1<<3,
134  TFlag = 1<<4,
135  TAddress = 1<<5,
136 
137  OpAddr = 0x03, /* 1 op, const addr */
138  OpDeref = 0x06,
139  OpConst1u = 0x08, /* 1 op, 1 byte const */
140  OpConst1s = 0x09, /* " signed */
141  OpConst2u = 0x0A, /* 1 op, 2 byte const */
142  OpConst2s = 0x0B, /* " signed */
143  OpConst4u = 0x0C, /* 1 op, 4 byte const */
144  OpConst4s = 0x0D, /* " signed */
145  OpConst8u = 0x0E, /* 1 op, 8 byte const */
146  OpConst8s = 0x0F, /* " signed */
147  OpConstu = 0x10, /* 1 op, LEB128 const */
148  OpConsts = 0x11, /* " signed */
149  OpDup = 0x12,
150  OpDrop = 0x13,
151  OpOver = 0x14,
152  OpPick = 0x15, /* 1 op, 1 byte stack index */
153  OpSwap = 0x16,
154  OpRot = 0x17,
155  OpXderef = 0x18,
156  OpAbs = 0x19,
157  OpAnd = 0x1A,
158  OpDiv = 0x1B,
159  OpMinus = 0x1C,
160  OpMod = 0x1D,
161  OpMul = 0x1E,
162  OpNeg = 0x1F,
163  OpNot = 0x20,
164  OpOr = 0x21,
165  OpPlus = 0x22,
166  OpPlusUconst = 0x23, /* 1 op, ULEB128 addend */
167  OpShl = 0x24,
168  OpShr = 0x25,
169  OpShra = 0x26,
170  OpXor = 0x27,
171  OpSkip = 0x2F, /* 1 op, signed 2-byte constant */
172  OpBra = 0x28, /* 1 op, signed 2-byte constant */
173  OpEq = 0x29,
174  OpGe = 0x2A,
175  OpGt = 0x2B,
176  OpLe = 0x2C,
177  OpLt = 0x2D,
178  OpNe = 0x2E,
179  OpLit0 = 0x30,
180  /* OpLitN = OpLit0 + N for N = 0..31 */
181  OpReg0 = 0x50,
182  /* OpRegN = OpReg0 + N for N = 0..31 */
183  OpBreg0 = 0x70, /* 1 op, signed LEB128 constant */
184  /* OpBregN = OpBreg0 + N for N = 0..31 */
185  OpRegx = 0x90, /* 1 op, ULEB128 register */
186  OpFbreg = 0x91, /* 1 op, SLEB128 offset */
187  OpBregx = 0x92, /* 2 op, ULEB128 reg, SLEB128 off */
188  OpPiece = 0x93, /* 1 op, ULEB128 size of piece */
189  OpDerefSize = 0x94, /* 1-byte size of data retrieved */
190  OpXderefSize = 0x95, /* 1-byte size of data retrieved */
191  OpNop = 0x96,
192  /* next four new in Dwarf v3 */
193  OpPushObjAddr = 0x97,
194  OpCall2 = 0x98, /* 2-byte offset of DIE */
195  OpCall4 = 0x99, /* 4-byte offset of DIE */
196  OpCallRef = 0x9A /* 4- or 8- byte offset of DIE */
197  /* 0xE0-0xFF reserved for user-specific */
198 };
Definition: dwarf.h:159
Definition: dwarf.h:183
Definition: dwarf.h:191
Definition: dwarf.h:177
Definition: dwarf.h:162
Definition: dwarf.h:185
Definition: dwarf.h:186
Definition: dwarf.h:165
Definition: dwarf.h:119
Definition: dwarf.h:150
Definition: dwarf.h:168
Definition: dwarf.h:170
Definition: dwarf.h:88
Definition: dwarf.h:137
Definition: dwarf.h:174
Definition: dwarf.h:167
Definition: dwarf.h:173
Definition: dwarf.h:84
Definition: dwarf.h:133
Definition: dwarf.h:164
Definition: dwarf.h:175
Definition: dwarf.h:92
Definition: dwarf.h:158
Definition: dwarf.h:187
Definition: dwarf.h:160
Definition: dwarf.h:171
Definition: dwarf.h:169
Definition: dwarf.h:131
Definition: dwarf.h:178
Definition: dwarf.h:161
Definition: dwarf.h:157
Definition: dwarf.h:152
Definition: dwarf.h:181
Definition: dwarf.h:154
Definition: dwarf.h:163
Definition: dwarf.h:172
Definition: dwarf.h:195
Definition: dwarf.h:134
Definition: dwarf.h:156
Definition: dwarf.h:151
Definition: dwarf.h:149
Definition: dwarf.h:103
Definition: dwarf.h:194
Definition: dwarf.h:176
Definition: dwarf.h:93
Definition: dwarf.h:188
Definition: dwarf.h:179
Definition: dwarf.h:153
Definition: dwarf.h:106
Definition: dwarf.h:19
Definition: dwarf.h:138
anonymous enum
Enumerator
RuleUndef 
RuleSame 
RuleCfaOffset 
RuleRegister 
RuleRegOff 
RuleLocation 

Definition at line 356 of file dwarf.h.

357 {
358  RuleUndef,
359  RuleSame,
361  RuleRegister,
362  RuleRegOff,
364 };

Function Documentation

int dwarfaddrtounit ( Dwarf ,
ulong  ,
ulong  
)

Definition at line 17 of file dwarfaranges.c.

Referenced by dwarfpctoline(), and RosSymAggregate().

18 {
19  DwarfBuf b;
20  int segsize, i;
21  ulong len, id, off, base, size;
22  uchar *start, *end;
23 
24  memset(&b, 0, sizeof b);
25  b.d = d;
26  b.p = d->aranges.data;
27  b.ep = b.p + d->aranges.len;
28 
29  while(b.p < b.ep){
30  start = b.p;
31  len = dwarfget4(&b);
32  if (!len) { b.ep = b.p - 4; return -1; }
33  if((id = dwarfget2(&b)) != 2){
34  if(b.p == nil){
35  underflow:
36  werrstr("buffer underflow reading address ranges header");
37  }else
38  werrstr("bad dwarf version 0x%x in address ranges header", id);
39  return -1;
40  }
41  off = dwarfget4(&b);
42  b.addrsize = dwarfget1(&b);
43  if(d->addrsize == 0)
44  d->addrsize = b.addrsize;
45  segsize = dwarfget1(&b);
46  USED(segsize); /* what am i supposed to do with this? */
47  if(b.p == nil)
48  goto underflow;
49  if((i = (b.p-start) % (2*b.addrsize)) != 0)
50  b.p += 2*b.addrsize - i;
51  end = start+4+len;
52  while(b.p!=nil && b.p<end){
53  base = dwarfgetaddr(&b);
54  size = dwarfgetaddr(&b);
55  if (!size) continue;
56  if(b.p == nil)
57  goto underflow;
58  if(base <= addr && addr < base+size){
59  *unit = off;
60  return 0;
61  }
62  }
63  if(b.p == nil)
64  goto underflow;
65  b.p = end;
66  }
67  werrstr("address 0x%lux is not listed in dwarf debugging symbols", addr);
68  return -1;
69 }
uint addrsize
Definition: dwarf.h:212
#define werrstr(str,...)
Definition: compat.h:34
unsigned char uchar
Definition: Unfrag.h:59
Dwarf * d
Definition: dwarf.h:209
ulong dwarfget4(DwarfBuf *)
Definition: dwarfget.c:96
GLuint GLuint end
Definition: gl.h:1545
const XML_Char int const XML_Char int const XML_Char * base
Definition: expat.h:331
GLenum GLclampf GLint i
Definition: glfuncs.h:14
ulong dwarfget1(DwarfBuf *)
Definition: dwarfget.c:18
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
#define b
Definition: ke_i.h:79
GLsizeiptr size
Definition: glext.h:5919
#define d
Definition: ke_i.h:81
uchar * p
Definition: dwarf.h:210
ulong dwarfget2(DwarfBuf *)
Definition: dwarfget.c:82
GLenum const GLvoid * addr
Definition: glext.h:9621
GLenum GLsizei len
Definition: glext.h:6722
unsigned long ulong
Definition: linux.h:275
GLuint start
Definition: gl.h:1545
#define nil
Definition: compat.h:23
uchar * ep
Definition: dwarf.h:211
#define USED
Definition: compiler.h:158
GLenum GLuint id
Definition: glext.h:5579
#define memset(x, y, z)
Definition: compat.h:39
ulong dwarfgetaddr(DwarfBuf *)
Definition: dwarfget.c:124
off
Definition: i386-dis.c:3909
void dwarfclose ( Dwarf )

Definition at line 57 of file dwarfopen.c.

Referenced by RosSymDelete().

58 {
59  free(d->abbrev.data);
60  free(d->aranges.data);
61  free(d->frame.data);
62  free(d->line.data);
63  free(d->pubnames.data);
64  free(d->ranges.data);
65  free(d->str.data);
66  free(d->info.data);
67  pefree(d->pe);
68  free(d);
69 }
#define free
Definition: debug_ros.c:5
#define d
Definition: ke_i.h:81
void pefree(Pe *pe)
Definition: pe.c:109
int dwarfenum ( Dwarf ,
DwarfSym  
)

Definition at line 242 of file dwarfinfo.c.

Referenced by main().

243 {
244  if(dwarfenumunit(d, 0, s) < 0)
245  return -1;
246  s->allunits = 1;
247  return 0;
248 }
int dwarfenumunit(Dwarf *d, ulong unit, DwarfSym *s)
Definition: dwarfinfo.c:202
#define d
Definition: ke_i.h:81
GLdouble s
Definition: gl.h:2039
int dwarfenumunit ( Dwarf ,
ulong  ,
DwarfSym  
)

Definition at line 202 of file dwarfinfo.c.

Referenced by _dwarfnametounit(), and dwarfpctoline().

203 {
204  int i;
205  ulong aoff, len;
206 
207  if(unit >= d->info.len){
208  werrstr("dwarf unit address 0x%x >= 0x%x out of range", unit, d->info.len);
209  return -1;
210  }
211  memset(s, 0, sizeof *s);
212  memset(&s->b, 0, sizeof s->b);
213 
214  s->b.d = d;
215  s->b.p = d->info.data + unit;
216  s->b.ep = d->info.data + d->info.len;
217  len = dwarfget4(&s->b);
218  s->nextunit = unit + 4 + len;
219 
220  if(s->b.ep - s->b.p < len){
221  badheader:
222  werrstr("bad dwarf unit header at unit 0x%lux", unit);
223  return -1;
224  }
225  s->b.ep = s->b.p+len;
226  if((i=dwarfget2(&s->b)) != 2)
227  goto badheader;
228  aoff = dwarfget4(&s->b);
229  s->b.addrsize = dwarfget1(&s->b);
230  if(d->addrsize == 0)
231  d->addrsize = s->b.addrsize;
232  if(s->b.p == nil)
233  goto badheader;
234 
235  s->aoff = aoff;
236  s->unit = unit;
237  s->depth = 0;
238  return 0;
239 }
#define werrstr(str,...)
Definition: compat.h:34
ulong dwarfget4(DwarfBuf *)
Definition: dwarfget.c:96
GLenum GLclampf GLint i
Definition: glfuncs.h:14
ulong dwarfget1(DwarfBuf *)
Definition: dwarfget.c:18
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
#define d
Definition: ke_i.h:81
ulong dwarfget2(DwarfBuf *)
Definition: dwarfget.c:82
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
unsigned long ulong
Definition: linux.h:275
#define nil
Definition: compat.h:23
#define memset(x, y, z)
Definition: compat.h:39
ulong dwarfget1 ( DwarfBuf )

Definition at line 18 of file dwarfget.c.

Referenced by constblock(), dexec(), dwarfaddrtounit(), dwarfenumunit(), dwarfgetarg(), dwarfpctoline(), findfde(), getblock(), getuchar(), getulong(), and parseabbrevs().

19 {
20  if(b->p==nil || b->p+1 > b->ep){
21  b->p = nil;
22  return 0;
23  }
24  return *b->p++;
25 }
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define nil
Definition: compat.h:23
ulong dwarfget128 ( DwarfBuf )

Definition at line 153 of file dwarfget.c.

Referenced by constblock(), dexec(), dwarfgetarg(), dwarfnextsym(), dwarfpctoline(), findfde(), getblock(), getulong(), parseabbrevs(), and parseattrs().

154 {
155  static int nbad;
156  ulong c, d;
157 
158  if(b->p == nil)
159  return 0;
160  c = *b->p++;
161  if(!(c&0x80))
162 {n1++;
163  return c;
164 }
165  c &= ~0x80;
166  d = *b->p++;
167  c |= (d&0x7F)<<7;
168  if(!(d&0x80))
169 {n2++;
170  return c;
171 }
172  d = *b->p++;
173  c |= (d&0x7F)<<14;
174  if(!(d&0x80))
175 {n3++;
176  return c;
177 }
178  d = *b->p++;
179  c |= (d&0x7F)<<21;
180  if(!(d&0x80))
181 {n4++;
182  return c;
183 }
184  d = *b->p++;
185  c |= (d&0x7F)<<28;
186  if(!(d&0x80))
187 {n5++;
188  return c;
189 }
190  while(b->p<b->ep && *b->p&0x80)
191  b->p++;
192  if(++nbad == 1)
193  werrstr("dwarf: overflow during parsing of uleb128 integer\n");
194  return c;
195 }
#define werrstr(str,...)
Definition: compat.h:34
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define d
Definition: ke_i.h:81
int n3
Definition: dwarfget.c:148
int n1
Definition: dwarfget.c:148
unsigned long ulong
Definition: linux.h:275
int n2
Definition: dwarfget.c:148
int n4
Definition: dwarfget.c:148
#define nil
Definition: compat.h:23
int n5
Definition: dwarfget.c:148
#define c
Definition: ke_i.h:80
long dwarfget128s ( DwarfBuf )

Definition at line 198 of file dwarfget.c.

Referenced by constblock(), dexec(), dwarfgetarg(), dwarfpctoline(), findfde(), and getulong().

199 {
200  int nb, c;
201  ulong v;
202  static int nbad;
203 
204  v = 0;
205  nb = 0;
206  if(b->p==nil)
207  return 0;
208  while(b->p<b->ep){
209  c = *b->p++;
210  v |= (c & 0x7F)<<nb;
211  nb += 7;
212  if(!(c&0x80))
213  break;
214  }
215  if(v&(1<<(nb-1)))
216  v |= ~(((ulong)1<<nb)-1);
217  if(nb > 8*sizeof(ulong)){
218  if(0)
219  if(++nbad == 1)
220  werrstr("dwarf: overflow during parsing of sleb128 integer: got %d bits", nb);
221  }
222  return v;
223 }
#define werrstr(str,...)
Definition: compat.h:34
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
unsigned long ulong
Definition: linux.h:275
const GLdouble * v
Definition: gl.h:2040
#define nil
Definition: compat.h:23
#define c
Definition: ke_i.h:80
ulong dwarfget2 ( DwarfBuf )

Definition at line 82 of file dwarfget.c.

Referenced by _dwarfnametounit(), constblock(), dexec(), dwarfaddrtounit(), dwarfargvalue(), dwarfenumunit(), dwarfgetarg(), dwarfpctoline(), getblock(), and getulong().

83 {
84  ulong v;
85 
86  if(b->p==nil || b->p+2 > b->ep){
87  b->p = nil;
88  return 0;
89  }
90  v = b->d->pe->e2(b->p);
91  b->p += 2;
92  return v;
93 }
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
unsigned long ulong
Definition: linux.h:275
const GLdouble * v
Definition: gl.h:2040
#define nil
Definition: compat.h:23
ulong dwarfget4 ( DwarfBuf )

Definition at line 96 of file dwarfget.c.

Referenced by _dwarfnametounit(), constblock(), dexec(), dwarfaddrtounit(), dwarfargvalue(), dwarfenumunit(), dwarfgetarg(), dwarfpctoline(), findfde(), getblock(), getstring(), and getulong().

97 {
98  ulong v;
99 
100  if(b->p==nil || b->p+4 > b->ep){
101  b->p = nil;
102  return 0;
103  }
104  v = b->d->pe->e4(b->p);
105  b->p += 4;
106  return v;
107 }
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
unsigned long ulong
Definition: linux.h:275
const GLdouble * v
Definition: gl.h:2040
#define nil
Definition: compat.h:23
uvlong dwarfget8 ( DwarfBuf )

Definition at line 110 of file dwarfget.c.

Referenced by constblock(), and getulong().

111 {
112  uvlong v;
113 
114  if(b->p==nil || b->p+8 > b->ep){
115  b->p = nil;
116  return 0;
117  }
118  v = b->d->pe->e8(b->p);
119  b->p += 8;
120  return v;
121 }
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
const GLdouble * v
Definition: gl.h:2040
#define nil
Definition: compat.h:23
unsigned long long uvlong
Definition: compat.h:9
DwarfAbbrev * dwarfgetabbrev ( Dwarf d,
ulong  off,
ulong  num 
)

Definition at line 129 of file dwarfabbrev.c.

Referenced by dwarfnextsym().

130 {
131  DwarfAbbrev *a;
132  int na;
133 
134  if((na = loadabbrevs(d, off, &a)) < 0){
135  werrstr("loadabbrevs: %r");
136  return nil;
137  }
138  return findabbrev(a, na, num);
139 }
#define werrstr(str,...)
Definition: compat.h:34
#define a
Definition: ke_i.h:78
GLuint GLuint num
Definition: glext.h:9618
static int loadabbrevs(Dwarf *d, ulong off, DwarfAbbrev **aa)
Definition: dwarfabbrev.c:26
#define nil
Definition: compat.h:23
static DwarfAbbrev * findabbrev(DwarfAbbrev *a, int na, ulong num)
Definition: dwarfabbrev.c:117
off
Definition: i386-dis.c:3909
ulong dwarfgetaddr ( DwarfBuf )

Definition at line 124 of file dwarfget.c.

Referenced by constblock(), dexec(), dwarfaddrtounit(), dwarfpctoline(), findfde(), and getulong().

125 {
126  static int nbad;
127 
128  if(b->addrsize == 0)
129  b->addrsize = b->d->addrsize;
130 
131  switch(b->addrsize){
132  case 1:
133  return dwarfget1(b);
134  case 2:
135  return dwarfget2(b);
136  case 4:
137  return dwarfget4(b);
138  case 8:
139  return dwarfget8(b);
140  default:
141  if(++nbad == 1)
142  werrstr("dwarf: unexpected address size %lud in dwarfgetaddr\n", b->addrsize);
143  b->p = nil;
144  return 0;
145  }
146 }
#define werrstr(str,...)
Definition: compat.h:34
ulong dwarfget2(DwarfBuf *b)
Definition: dwarfget.c:82
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
uvlong dwarfget8(DwarfBuf *b)
Definition: dwarfget.c:110
ulong dwarfget4(DwarfBuf *b)
Definition: dwarfget.c:96
ulong dwarfget1(DwarfBuf *b)
Definition: dwarfget.c:18
#define nil
Definition: compat.h:23
int dwarfgetinfounit ( Dwarf ,
ulong  ,
DwarfBlock  
)
int dwarfgetn ( DwarfBuf ,
uchar ,
int   
)

Definition at line 28 of file dwarfget.c.

29 {
30  if(b->p==nil || b->p+n > b->ep){
31  b->p = nil;
32  memset(a, 0, n);
33  return -1;
34  }
35  memmove(a, b->p, n);
36  b->p += n;
37  return 0;
38 }
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
GLuint n
Definition: s_context.h:57
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define nil
Definition: compat.h:23
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define memset(x, y, z)
Definition: compat.h:39
uchar* dwarfgetnref ( DwarfBuf ,
ulong   
)

Definition at line 41 of file dwarfget.c.

Referenced by dexec(), dwarfpctoline(), and getblock().

42 {
43  uchar *p;
44 
45  if(b->p==nil || b->p+n > b->ep){
46  b->p = nil;
47  return nil;
48  }
49  p = b->p;
50  b->p += n;
51  return p;
52 }
unsigned char uchar
Definition: Unfrag.h:59
GLuint n
Definition: s_context.h:57
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define nil
Definition: compat.h:23
GLfloat GLfloat p
Definition: glext.h:8902
char* dwarfgetstring ( DwarfBuf )

Definition at line 55 of file dwarfget.c.

Referenced by _dwarfnametounit(), dwarfpctoline(), findfde(), and getstring().

56 {
57  char *s;
58 
59  if(b->p == nil)
60  return nil;
61  s = (char*)b->p;
62  while(b->p < b->ep && *b->p)
63  b->p++;
64  if(b->p >= b->ep){
65  b->p = nil;
66  return nil;
67  }
68  b->p++;
69  return s;
70 }
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLdouble s
Definition: gl.h:2039
#define nil
Definition: compat.h:23
int dwarflookupfn ( Dwarf ,
ulong  ,
ulong  ,
DwarfSym  
)

Definition at line 182 of file dwarfinfo.c.

Referenced by dwarfpctoline().

183 {
184  if(dwarfenumunit(d, unit, s) < 0)
185  return -1;
186 
187  if(dwarfnextsymat(d, s, 0) != 1)
188  return -1;
189  /* s is now the CompileUnit */
190 
191  while(dwarfnextsymat(d, s, 1) == 1){
192  if(s->attrs.tag != TagSubprogram)
193  continue;
194  if(s->attrs.lowpc <= pc && pc < s->attrs.highpc)
195  return 0;
196  }
197  werrstr("fn containing pc 0x%lux not found", pc);
198  return -1;
199 }
#define werrstr(str,...)
Definition: compat.h:34
int dwarfenumunit(Dwarf *d, ulong unit, DwarfSym *s)
Definition: dwarfinfo.c:202
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
#define d
Definition: ke_i.h:81
int dwarfnextsymat(Dwarf *d, DwarfSym *s, int depth)
Definition: dwarfinfo.c:293
GLdouble s
Definition: gl.h:2039
int dwarflookupname ( Dwarf ,
char ,
DwarfSym  
)

Definition at line 67 of file dwarfpubnames.c.

68 {
69  return _dwarfnametounit(d, name, &d->pubnames, sym);
70 }
#define d
Definition: ke_i.h:81
Definition: name.c:36
static int _dwarfnametounit(Dwarf *d, char *name, DwarfBlock *bl, DwarfSym *s)
Definition: dwarfpubnames.c:12
int dwarflookupnameinunit ( Dwarf ,
ulong  ,
char ,
DwarfSym  
)

Definition at line 126 of file dwarfinfo.c.

Referenced by RosSymAggregate().

127 {
128  if(dwarfenumunit(d, unit, s) < 0)
129  return -1;
130 
131  dwarfnextsymat(d, s, 0); /* s is now the CompileUnit */
132  while(dwarfnextsymat(d, s, 1) == 1)
133  if(s->attrs.name && strcmp(s->attrs.name, name) == 0)
134  return 0;
135  werrstr("symbol '%s' not found", name);
136  return -1;
137 }
#define werrstr(str,...)
Definition: compat.h:34
int dwarfenumunit(Dwarf *d, ulong unit, DwarfSym *s)
Definition: dwarfinfo.c:202
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
#define d
Definition: ke_i.h:81
int dwarfnextsymat(Dwarf *d, DwarfSym *s, int depth)
Definition: dwarfinfo.c:293
GLdouble s
Definition: gl.h:2039
Definition: name.c:36
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int dwarflookupsubname ( Dwarf ,
DwarfSym ,
char ,
DwarfSym  
)

Definition at line 141 of file dwarfinfo.c.

142 {
143  *s = *parent;
144  while(dwarfnextsymat(d, s, parent->depth+1))
145  if(s->attrs.name && strcmp(s->attrs.name, name) == 0)
146  return 0;
147  werrstr("symbol '%s' not found", name);
148  return -1;
149 }
#define werrstr(str,...)
Definition: compat.h:34
#define d
Definition: ke_i.h:81
r parent
Definition: btrfs.c:2644
int dwarfnextsymat(Dwarf *d, DwarfSym *s, int depth)
Definition: dwarfinfo.c:293
GLdouble s
Definition: gl.h:2039
Definition: name.c:36
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int dwarflookuptag ( Dwarf ,
ulong  ,
ulong  ,
DwarfSym  
)

Definition at line 152 of file dwarfinfo.c.

Referenced by dwarfpctoline().

153 {
154  if(dwarfenumunit(d, unit, s) < 0) {
155  return -1;
156  }
157 
158  dwarfnextsymat(d, s, 0); /* s is now the CompileUnit */
159  if(s->attrs.tag == tag) {
160  return 0;
161  }
162  while(dwarfnextsymat(d, s, 1) == 1)
163  if(s->attrs.tag == tag) {
164  return 0;
165  }
166  werrstr("symbol with tag 0x%lux not found", tag);
167  return -1;
168 }
#define werrstr(str,...)
Definition: compat.h:34
int dwarfenumunit(Dwarf *d, ulong unit, DwarfSym *s)
Definition: dwarfinfo.c:202
Definition: ecma_167.h:138
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
#define d
Definition: ke_i.h:81
int dwarfnextsymat(Dwarf *d, DwarfSym *s, int depth)
Definition: dwarfinfo.c:293
GLdouble s
Definition: gl.h:2039
int dwarfnextsym ( Dwarf ,
DwarfSym  
)

Definition at line 251 of file dwarfinfo.c.

Referenced by _dwarfnametounit(), dwarfpctoline(), and main().

252 {
253  ulong num;
254  DwarfAbbrev *a;
255 
256  if(s->attrs.haskids)
257  s->depth++;
258 top:
259  if(s->b.p >= s->b.ep){
260  if(s->allunits && s->nextunit < d->info.len){
261  if(dwarfenumunit(d, s->nextunit, s) < 0) {
262  return -1;
263  }
264  s->allunits = 1;
265  goto top;
266  }
267  return 0;
268  }
269 
270  s->uoff = s->b.p - (d->info.data+s->unit);
271  num = dwarfget128(&s->b);
272  if(num == 0){
273  if(s->depth == 0) {
274  return 0;
275  }
276  if(s->depth > 0)
277  s->depth--;
278  goto top;
279  }
280 
281  a = dwarfgetabbrev(d, s->aoff, num);
282  if(a == nil){
283  werrstr("getabbrev %ud %ud for %ud,%ud: %r\n", s->aoff, num, s->unit, s->uoff);
284  return -1;
285  }
286  if(parseattrs(&s->b, s->unit, a, &s->attrs) < 0) {
287  return -1;
288  }
289  return 1;
290 }
#define werrstr(str,...)
Definition: compat.h:34
int dwarfenumunit(Dwarf *d, ulong unit, DwarfSym *s)
Definition: dwarfinfo.c:202
#define a
Definition: ke_i.h:78
#define d
Definition: ke_i.h:81
GLuint GLuint num
Definition: glext.h:9618
GLdouble s
Definition: gl.h:2039
unsigned long ulong
Definition: linux.h:275
ulong dwarfget128(DwarfBuf *)
Definition: dwarfget.c:153
DwarfAbbrev * dwarfgetabbrev(Dwarf *, ulong, ulong)
Definition: dwarfabbrev.c:129
#define nil
Definition: compat.h:23
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
static int parseattrs(DwarfBuf *, ulong, DwarfAbbrev *, DwarfAttrs *)
Definition: dwarfinfo.c:408
int dwarfnextsymat ( Dwarf ,
DwarfSym ,
int   
)

Definition at line 293 of file dwarfinfo.c.

Referenced by dwarfgetparams(), dwarflookupchildtag(), dwarflookupfn(), dwarflookupnameinunit(), dwarflookupsubname(), dwarflookuptag(), dwarfnextsym(), dwarfpctoline(), dwarfseeksym(), and RosSymAggregate().

294 {
295  int r;
296  DwarfSym t;
297  uint sib;
298 
299  if(s->depth == depth && s->attrs.have.sibling){
300  sib = s->attrs.sibling;
301  if(sib < d->info.len && d->info.data+sib >= s->b.p)
302  s->b.p = d->info.data+sib;
303  s->attrs.haskids = 0;
304  }
305 
306  /*
307  * The funny game with t and s make sure that
308  * if we get to the end of a run of a particular
309  * depth, we leave s so that a call to nextsymat with depth-1
310  * will actually produce the desired guy. We could change
311  * the interface to dwarfnextsym instead, but I'm scared
312  * to touch it.
313  */
314  t = *s;
315  for(;;){
316  if((r = dwarfnextsym(d, &t)) != 1) {
317  return r;
318  }
319  if(t.depth < depth){
320  /* went too far - nothing to see */
321  return 0;
322  }
323  *s = t;
324  if(t.depth == depth) {
325  return 1;
326  }
327  }
328 }
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLdouble GLdouble t
Definition: gl.h:2047
int dwarfnextsym(Dwarf *d, DwarfSym *s)
Definition: dwarfinfo.c:251
#define d
Definition: ke_i.h:81
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLdouble s
Definition: gl.h:2039
int depth
Definition: dwarf.h:382
UINT32 uint
Definition: types.h:83
Dwarf* dwarfopen ( struct _Pe elf)

Definition at line 16 of file dwarfopen.c.

Referenced by main(), RosSymCreateFromFile(), and RosSymCreateFromMem().

17 {
18  Dwarf *d;
19 
20  if(pe == nil){
21  werrstr("nil pe passed to dwarfopen");
22  return nil;
23  }
24 
25  d = mallocz(sizeof(Dwarf), 1);
26  if(d == nil)
27  return nil;
28 
29  d->pe = pe;
30  if(pe->loadsection(pe, ".debug_abbrev", &d->abbrev) < 0
31  || pe->loadsection(pe, ".debug_aranges", &d->aranges) < 0
32  || pe->loadsection(pe, ".debug_line", &d->line) < 0
33  || pe->loadsection(pe, ".debug_pubnames", &d->pubnames) < 0
34  || pe->loadsection(pe, ".debug_info", &d->info) < 0)
35  goto err;
36  pe->loadsection(pe, ".debug_frame", &d->frame);
37  pe->loadsection(pe, ".debug_ranges", &d->ranges);
38  pe->loadsection(pe, ".debug_str", &d->str);
39 
40  return d;
41 
42 err:
43  DPRINT("Failed to open dwarf\n");
44  free(d->abbrev.data);
45  free(d->aranges.data);
46  free(d->frame.data);
47  free(d->line.data);
48  free(d->pubnames.data);
49  free(d->ranges.data);
50  free(d->str.data);
51  free(d->info.data);
52  free(d);
53  return nil;
54 }
#define werrstr(str,...)
Definition: compat.h:34
DwarfBlock info
Definition: dwarf.h:446
DwarfBlock frame
Definition: dwarf.h:445
#define free
Definition: debug_ros.c:5
#define mallocz(x, y)
Definition: compat.h:36
uchar * data
Definition: dwarf.h:202
DwarfBlock pubnames
Definition: dwarf.h:448
DwarfBlock line
Definition: dwarf.h:447
int int int * err
Definition: fci.h:172
DwarfBlock abbrev
Definition: dwarf.h:443
void DPRINT(...)
Definition: polytest.cpp:61
#define d
Definition: ke_i.h:81
DwarfBlock ranges
Definition: dwarf.h:450
Definition: dwarf.h:436
struct _Pe * pe
Definition: dwarf.h:438
#define nil
Definition: compat.h:23
DwarfBlock str
Definition: dwarf.h:451
DwarfBlock aranges
Definition: dwarf.h:444
int dwarfpctoline ( Dwarf ,
ulong  ,
char **  ,
char **  ,
char **  ,
char **  ,
ulong ,
ulong ,
ulong  
)

Definition at line 49 of file dwarfpc.c.

Referenced by main(), and RosSymGetAddressInformation().

50 {
51  uchar *prog, *opcount, *end, *dirs;
52  ulong off, unit, len, vers, x, start, lastline;
53  int i, first, firstline, op, a, l, quantum, isstmt, linebase, linerange, opcodebase, nf;
54  char *files, *s;
55  DwarfBuf b;
56  DwarfSym sym;
57  State emit, cur, reset;
58  uchar **f, **newf;
59 
60  f = nil;
61 
62  if(dwarfaddrtounit(d, pc, &unit) < 0
63  || dwarflookuptag(d, unit, TagCompileUnit, &sym) < 0)
64  return -1;
65 
66  if(!sym.attrs.have.stmtlist){
67  werrstr("no line mapping information for 0x%x", pc);
68  return -1;
69  }
70  off = sym.attrs.stmtlist;
71  if(off >= d->line.len){
72  werrstr("bad stmtlist\n");
73  goto bad;
74  }
75 
76  if(trace) werrstr("unit 0x%x stmtlist 0x%x", unit, sym.attrs.stmtlist);
77 
78  memset(&b, 0, sizeof b);
79  b.d = d;
80  b.p = d->line.data + off;
81  b.ep = b.p + d->line.len;
82  b.addrsize = sym.b.addrsize; /* should i get this from somewhere else? */
83 
84  len = dwarfget4(&b);
85  if(b.p==nil || b.p+len > b.ep || b.p+len < b.p){
86  werrstr("bad len\n");
87  goto bad;
88  }
89 
90  b.ep = b.p+len;
91  vers = dwarfget2(&b);
92  if(vers != 2){
93  werrstr("bad dwarf version 0x%x", vers);
94  return -1;
95  }
96 
97  len = dwarfget4(&b);
98  if(b.p==nil || b.p+len > b.ep || b.p+len < b.p){
99  werrstr("another bad len\n");
100  goto bad;
101  }
102  prog = b.p+len;
103 
104  quantum = dwarfget1(&b);
105  isstmt = dwarfget1(&b);
106  linebase = (schar)dwarfget1(&b);
107  linerange = (schar)dwarfget1(&b);
108  opcodebase = dwarfget1(&b);
109 
110  opcount = b.p-1;
111  dwarfgetnref(&b, opcodebase-1);
112  if(b.p == nil){
113  werrstr("bad opcode chart\n");
114  goto bad;
115  }
116 
117  /* just skip the files and dirs for now; we'll come back */
118  dirs = b.p;
119  while (b.p && *b.p)
120  dwarfgetstring(&b);
121  dwarfget1(&b);
122 
123  files = (char*)b.p;
124  while(b.p!=nil && *b.p!=0){
125  dwarfgetstring(&b);
126  dwarfget128(&b);
127  dwarfget128(&b);
128  dwarfget128(&b);
129  }
130  dwarfget1(&b);
131 
132  /* move on to the program */
133  if(b.p == nil || b.p > prog){
134  werrstr("bad header\n");
135  goto bad;
136  }
137  b.p = prog;
138 
139  reset.addr = 0;
140  reset.file = 1;
141  reset.line = 1;
142  reset.column = 0;
143  reset.flags = isstmt ? Isstmt : 0;
144  reset.isa = 0;
145 
146  cur = reset;
147  emit = reset;
148  nf = 0;
149  start = 0;
150  if(trace) werrstr("program @ %lu ... %.*H opbase = %d\n", b.p - d->line.data, b.ep-b.p, b.p, opcodebase);
151  first = 1;
152  while(b.p != nil){
153  firstline = 0;
154  op = dwarfget1(&b);
155  if(trace) werrstr("\tline %lu, addr 0x%x, op %d %.10H", cur.line, cur.addr, op, b.p);
156  if(op >= opcodebase){
157  a = (op - opcodebase) / linerange;
158  l = (op - opcodebase) % linerange + linebase;
159  cur.line += l;
160  cur.addr += a * quantum;
161  if(trace) werrstr(" +%d,%d\n", a, l);
162  emit:
163  if(first){
164  if(cur.addr > pc){
165  werrstr("found wrong line mapping 0x%x for pc 0x%x", cur.addr, pc);
166  /* This is an overzealous check. gcc can produce discontiguous ranges
167  and reorder statements, so it's possible for a future line to start
168  ahead of pc and still find a matching one. */
169  /*goto out;*/
170  firstline = 1;
171  }
172  first = 0;
173  start = cur.addr;
174  }
175  if(cur.addr > pc && !firstline)
176  break;
177  if(b.p == nil){
178  werrstr("buffer underflow in line mapping");
179  goto out;
180  }
181  emit = cur;
182  if(emit.flags & EndSequence){
183  werrstr("found wrong line mapping 0x%x-0x%x for pc 0x%x", start, cur.addr, pc);
184  goto out;
185  }
187  }else{
188  switch(op){
189  case 0: /* extended op code */
190  if(trace) werrstr(" ext");
191  len = dwarfget128(&b);
192  end = b.p+len;
193  if(b.p == nil || end > b.ep || end < b.p || len < 1)
194  goto bad;
195  switch(dwarfget1(&b)){
196  case 1: /* end sequence */
197  if(trace) werrstr(" end\n");
198  cur.flags |= EndSequence;
199  goto emit;
200  case 2: /* set address */
201  cur.addr = dwarfgetaddr(&b);
202  if(trace) werrstr(" set pc 0x%x\n", cur.addr);
203  break;
204  case 3: /* define file */
205  newf = malloc(nf+1*sizeof(f[0]));
206  if (newf)
207  RtlMoveMemory(newf, f, nf*sizeof(f[0]));
208  if(newf == nil)
209  goto out;
210  f[nf++] = b.p;
211  s = dwarfgetstring(&b);
212  dwarfget128(&b);
213  dwarfget128(&b);
214  dwarfget128(&b);
215  if(trace) werrstr(" def file %s\n", s);
216  break;
217  }
218  if(b.p == nil || b.p > end)
219  goto bad;
220  b.p = end;
221  break;
222  case 1: /* emit */
223  if(trace) werrstr(" emit\n");
224  goto emit;
225  case 2: /* advance pc */
226  a = dwarfget128(&b);
227  if(trace) werrstr(" advance pc + %lu\n", a*quantum);
228  cur.addr += a * quantum;
229  break;
230  case 3: /* advance line */
231  l = dwarfget128s(&b);
232  if(trace) werrstr(" advance line + %ld\n", l);
233  cur.line += l;
234  break;
235  case 4: /* set file */
236  if(trace) werrstr(" set file\n");
237  cur.file = dwarfget128s(&b);
238  break;
239  case 5: /* set column */
240  if(trace) werrstr(" set column\n");
241  cur.column = dwarfget128(&b);
242  break;
243  case 6: /* negate stmt */
244  if(trace) werrstr(" negate stmt\n");
245  cur.flags ^= Isstmt;
246  break;
247  case 7: /* set basic block */
248  if(trace) werrstr(" set basic block\n");
249  cur.flags |= BasicDwarfBlock;
250  break;
251  case 8: /* const add pc */
252  a = (255 - opcodebase) / linerange * quantum;
253  if(trace) werrstr(" const add pc + %d\n", a);
254  cur.addr += a;
255  break;
256  case 9: /* fixed advance pc */
257  a = dwarfget2(&b);
258  if(trace) werrstr(" fixed advance pc + %d\n", a);
259  cur.addr += a;
260  break;
261  case 10: /* set prologue end */
262  if(trace) werrstr(" set prologue end\n");
263  cur.flags |= PrologueEnd;
264  break;
265  case 11: /* set epilogue begin */
266  if(trace) werrstr(" set epilogue begin\n");
267  cur.flags |= EpilogueBegin;
268  break;
269  case 12: /* set isa */
270  if(trace) werrstr(" set isa\n");
271  cur.isa = dwarfget128(&b);
272  break;
273  default: /* something new - skip it */
274  if(trace) werrstr(" unknown %d\n", opcount[op]);
275  for(i=0; i<opcount[op]; i++)
276  dwarfget128(&b);
277  break;
278  }
279  }
280  }
281  if(b.p == nil)
282  goto bad;
283 
284  /* finally! the data we seek is in "emit" */
285 
286  if(emit.file == 0){
287  werrstr("invalid file index in mapping data");
288  goto out;
289  }
290  if(line)
291  *line = emit.line;
292 
293  /* skip over first emit.file-2 guys */
294  b.p = (uchar*)files;
295  for(i=emit.file-1; i > 0 && b.p!=nil && *b.p!=0; i--){
296  dwarfgetstring(&b);
297  dwarfget128(&b);
298  dwarfget128(&b);
299  dwarfget128(&b);
300  }
301  if(b.p == nil){
302  werrstr("problem parsing file data second time (cannot happen)");
303  goto bad;
304  }
305  if(*b.p == 0){
306  if(i >= nf){
307  werrstr("bad file index in mapping data");
308  goto bad;
309  }
310  b.p = f[i];
311  }
312  s = dwarfgetstring(&b);
313  if(file)
314  *file = s;
315  i = dwarfget128(&b); /* directory */
316  x = dwarfget128(&b);
317  if(mtime)
318  *mtime = x;
319  x = dwarfget128(&b);
320  if(length)
321  *length = x;
322 
323  /* fetch dir name */
324  if(cdir)
325  *cdir = sym.attrs.compdir;
326 
327  if(dir){
328  *dir = nil;
329  b.p = dirs;
330  for (x = 1; b.p && *b.p; x++)
331  if (x == i) {
332  *dir = dwarfgetstring(&b);
333  break;
334  }
335  }
336 
337  *function = nil;
338  lastline = 0;
339 #if 0
340  if (dwarfenumunit(d, unit, &proc) >= 0) {
341  dwarfnextsymat(d, &proc, 0);
342  while (dwarfnextsymat(d, &proc, 1) == 1) {
343  if (proc.attrs.tag == TagSubprogram &&
344  proc.attrs.have.name &&
345  proc.attrs.declfile == emit.file &&
346  proc.attrs.declline <= *line &&
347  proc.attrs.declline > lastline) {
348  lastline = proc.attrs.declline;
349  free(*function);
350  *function = malloc(strlen(proc.attrs.name)+1);
351  strcpy(*function, proc.attrs.name);
352  }
353  }
354  }
355 #elif 1
356  ulong lastaddr = 0;
357  *function = NULL;
358  for (i = 0; i < d->pe->nsymbols; i++) {
359  if (d->pe->symtab[i].address > lastaddr &&
360  d->pe->symtab[i].address <= pc - d->pe->imagebase &&
361  d->pe->symtab[i].address < d->pe->imagesize) {
362  lastaddr = d->pe->symtab[i].address;
363  *function = d->pe->symtab[i].name;
364  }
365  }
366 #else
367  // *sigh* we get unrelocated low_pc and high_pc because the dwarf symbols
368  // are not 'loaded' in the PE sense.
369  if (dwarflookupfn(d, unit, pc, &proc) >= 0) {
370  *function = malloc(strlen(proc.attrs.name)+1);
371  strcpy(*function, proc.attrs.name);
372  }
373 #endif
374 
375  /* free at last, free at last */
376  free(f);
377  return 0;
378 
379 bad:
380  werrstr("corrupted line mapping for 0x%x", pc);
381 out:
382  free(f);
383  return -1;
384 }
uint addrsize
Definition: dwarf.h:212
int dwarfaddrtounit(Dwarf *, ulong, ulong *)
Definition: dwarfaranges.c:17
#define werrstr(str,...)
Definition: compat.h:34
char * name
Definition: wpp.c:36
unsigned char uchar
Definition: Unfrag.h:59
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
char * dwarfgetstring(DwarfBuf *)
Definition: dwarfget.c:55
char * prog
Definition: isohybrid.c:47
Dwarf * d
Definition: dwarf.h:209
#define free
Definition: debug_ros.c:5
const GLint * first
Definition: glext.h:5794
ulong dwarfget4(DwarfBuf *)
Definition: dwarfget.c:96
int dwarfnextsymat(Dwarf *, DwarfSym *, int)
Definition: dwarfinfo.c:293
signed char schar
Definition: compat.h:5
GLuint GLuint end
Definition: gl.h:1545
static HANDLE proc()
Definition: pdb.c:31
ulong addr
Definition: dwarfpc.c:40
#define trace
Definition: dwarfpc.c:26
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
GLenum GLclampf GLint i
Definition: glfuncs.h:14
UINT op
Definition: effect.c:223
ulong dwarfget1(DwarfBuf *)
Definition: dwarfget.c:18
#define a
Definition: ke_i.h:78
PIN_DIRECTION dir
Definition: strmbase.h:230
uchar compdir
Definition: dwarf.h:239
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
smooth NULL
Definition: ftsmooth.c:416
Definition: parser.c:48
int dwarfenumunit(Dwarf *, ulong, DwarfSym *)
Definition: dwarfinfo.c:202
#define b
Definition: ke_i.h:79
r l[0]
Definition: byte_order.h:167
Definition: dwarfpc.c:30
#define d
Definition: ke_i.h:81
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
static FILE * out
Definition: regtests2xml.c:44
ulong flags
Definition: dwarfpc.c:44
ulong column
Definition: dwarfpc.c:43
uchar * p
Definition: dwarf.h:210
long dwarfget128s(DwarfBuf *)
Definition: dwarfget.c:198
ulong dwarfget2(DwarfBuf *)
Definition: dwarfget.c:82
uchar stmtlist
Definition: dwarf.h:282
ulong file
Definition: dwarfpc.c:41
ulong line
Definition: dwarfpc.c:42
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
unsigned long ulong
Definition: linux.h:275
DwarfBuf b
Definition: dwarf.h:378
GLboolean reset
Definition: glext.h:5666
ulong dwarfget128(DwarfBuf *)
Definition: dwarfget.c:153
GLuint start
Definition: gl.h:1545
#define f
Definition: ke_i.h:83
#define nil
Definition: compat.h:23
uchar * ep
Definition: dwarf.h:211
ulong isa
Definition: dwarfpc.c:45
uchar * dwarfgetnref(DwarfBuf *, ulong)
Definition: dwarfget.c:41
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define malloc
Definition: debug_ros.c:4
int dwarflookupfn(Dwarf *, ulong, ulong, DwarfSym *)
Definition: dwarfinfo.c:182
int dwarflookuptag(Dwarf *, ulong, ulong, DwarfSym *)
Definition: dwarfinfo.c:152
struct DwarfAttrs::@3957 have
#define memset(x, y, z)
Definition: compat.h:39
ulong dwarfgetaddr(DwarfBuf *)
Definition: dwarfget.c:124
DwarfAttrs attrs
Definition: dwarf.h:375
INT x
Definition: msvc.h:62
off
Definition: i386-dis.c:3909
Definition: fci.c:126
int dwarfseeksym ( Dwarf ,
ulong  ,
ulong  ,
DwarfSym  
)

Definition at line 171 of file dwarfinfo.c.

Referenced by RosSymAggregate().

172 {
173  if(dwarfenumunit(d, unit, s) < 0)
174  return -1;
175  s->b.p = d->info.data + unit + off;
176  if(dwarfnextsymat(d, s, 0) != 1)
177  return -1;
178  return 0;
179 }
int dwarfenumunit(Dwarf *d, ulong unit, DwarfSym *s)
Definition: dwarfinfo.c:202
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
#define d
Definition: ke_i.h:81
int dwarfnextsymat(Dwarf *d, DwarfSym *s, int depth)
Definition: dwarfinfo.c:293
GLdouble s
Definition: gl.h:2039
off
Definition: i386-dis.c:3909
int dwarfunwind ( Dwarf ,
ulong  ,
DwarfExpr ,
DwarfExpr ,
DwarfExpr ,
int   
)

Definition at line 48 of file dwarfcfa.c.

Referenced by dwarfregunwind(), and printrules().

49 {
50  int i, ret;
51  DwarfBuf fde, b;
52  DwarfExpr *initr;
53  State s;
54 
55  initr = mallocz(nr*sizeof(initr[0]), 1);
56  if(initr == 0)
57  return -1;
58 
59  memset(&s, 0, sizeof s);
60  s.loc = 0;
61  s.cfa = cfa;
62  s.ra = ra;
63  s.r = r;
64  s.nr = nr;
65 
66  if(findfde(d, pc, &s, &fde) < 0){
67  free(initr);
68  return -1;
69  }
70 
71  memset(r, 0, nr*sizeof(r[0]));
72  for(i=0; i<nr; i++)
73  r[i].type = RuleSame;
74  if(trace) werrstr("s.init %p-%p, fde %p-%p\n", s.init.p, s.init.ep, fde.p, fde.ep);
75  b = s.init;
76  if(dexec(&b, &s, 0) < 0)
77  goto err;
78 
79  s.initr = initr;
80  memmove(initr, r, nr*sizeof(initr[0]));
81 
82  if(trace) werrstr("s.loc 0x%lux pc 0x%lux\n", s.loc, pc);
83  while(s.loc < pc){
84  if(trace) werrstr("s.loc 0x%lux pc 0x%lux\n", s.loc, pc);
85  if(dexec(&fde, &s, 1) < 0)
86  goto err;
87  }
88  *ra = s.r[s.rareg];
89 
90  ret = 0;
91  goto out;
92 
93 err:
94  ret = -1;
95 out:
96  free(initr);
97  for(i=0; i<s.nstack; i++)
98  free(s.stack[i]);
99  free(s.stack);
100  return ret;
101 }
#define werrstr(str,...)
Definition: compat.h:34
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
ULONG nr
Definition: thread.c:7
int nr
Definition: dwarfcfa.c:39
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define free
Definition: debug_ros.c:5
#define mallocz(x, y)
Definition: compat.h:36
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
static int dexec(DwarfBuf *, State *, int)
Definition: dwarfcfa.c:190
GLenum GLclampf GLint i
Definition: glfuncs.h:14
int int int * err
Definition: fci.h:172
DwarfExpr ** stack
Definition: dwarfcfa.c:40
#define b
Definition: ke_i.h:79
int nstack
Definition: dwarfcfa.c:41
DwarfBuf init
Definition: dwarfcfa.c:34
#define d
Definition: ke_i.h:81
DwarfExpr * initr
Definition: dwarfcfa.c:38
static FILE * out
Definition: regtests2xml.c:44
uchar * p
Definition: dwarf.h:210
int ret
static int findfde(Dwarf *, ulong, State *, DwarfBuf *)
Definition: dwarfcfa.c:110
GLdouble s
Definition: gl.h:2039
#define err(...)
DwarfExpr * r
Definition: dwarfcfa.c:37
#define trace
Definition: dwarfcfa.c:22
DwarfExpr * ra
Definition: dwarfcfa.c:36
DwarfExpr * cfa
Definition: dwarfcfa.c:35
ulong loc
Definition: dwarfcfa.c:27
ulong rareg
Definition: dwarfcfa.c:33
uchar * ep
Definition: dwarf.h:211
#define memset(x, y, z)
Definition: compat.h:39

Variable Documentation

char* dwarf386fp
int dwarf386nregs

Definition at line 22 of file dwarf386.c.

char* dwarf386regs[]

Definition at line 10 of file dwarf386.c.