ReactOS  r76032
dwarfinfo.c File Reference
#include <ntifs.h>
#include <ndk/ntndk.h>
#include <reactos/rossym.h>
#include "rossympriv.h"
#include <ntimage.h>
#include <debug.h>
#include "dwarf.h"
#include <windef.h>
Include dependency graph for dwarfinfo.c:

Go to the source code of this file.

Classes

struct  Parse
 

Macros

#define NTOSAPI
 
#define NDEBUG
 
#define OFFSET(x)   offsetof(DwarfAttrs, x), offsetof(DwarfAttrs, have.x)
 

Typedefs

typedef struct Parse Parse
 

Enumerations

enum  {
  DwarfAttrSibling = 0x01, DwarfAttrLocation = 0x02, DwarfAttrName = 0x03, DwarfAttrOrdering = 0x09,
  DwarfAttrByteSize = 0x0B, DwarfAttrBitOffset = 0x0C, DwarfAttrBitSize = 0x0D, DwarfAttrStmtList = 0x10,
  DwarfAttrLowpc = 0x11, DwarfAttrHighpc = 0x12, DwarfAttrLanguage = 0x13, DwarfAttrDiscr = 0x15,
  DwarfAttrDiscrValue = 0x16, DwarfAttrVisibility = 0x17, DwarfAttrImport = 0x18, DwarfAttrStringLength = 0x19,
  DwarfAttrCommonRef = 0x1A, DwarfAttrCompDir = 0x1B, DwarfAttrConstValue = 0x1C, DwarfAttrContainingType = 0x1D,
  DwarfAttrDefaultValue = 0x1E, DwarfAttrInline = 0x20, DwarfAttrIsOptional = 0x21, DwarfAttrLowerBound = 0x22,
  DwarfAttrProducer = 0x25, DwarfAttrPrototyped = 0x27, DwarfAttrReturnAddr = 0x2A, DwarfAttrStartScope = 0x2C,
  DwarfAttrStrideSize = 0x2E, DwarfAttrUpperBound = 0x2F, DwarfAttrAbstractOrigin = 0x31, DwarfAttrAccessibility = 0x32,
  DwarfAttrAddrClass = 0x33, DwarfAttrArtificial = 0x34, DwarfAttrBaseTypes = 0x35, DwarfAttrCalling = 0x36,
  DwarfAttrCount = 0x37, DwarfAttrDataMemberLoc = 0x38, DwarfAttrDeclColumn = 0x39, DwarfAttrDeclFile = 0x3A,
  DwarfAttrDeclLine = 0x3B, DwarfAttrDeclaration = 0x3C, DwarfAttrDiscrList = 0x3D, DwarfAttrEncoding = 0x3E,
  DwarfAttrExternal = 0x3F, DwarfAttrFrameBase = 0x40, DwarfAttrFriend = 0x41, DwarfAttrIdentifierCase = 0x42,
  DwarfAttrMacroInfo = 0x43, DwarfAttrNamelistItem = 0x44, DwarfAttrPriority = 0x45, DwarfAttrSegment = 0x46,
  DwarfAttrSpecification = 0x47, DwarfAttrStaticLink = 0x48, DwarfAttrType = 0x49, DwarfAttrUseLocation = 0x4A,
  DwarfAttrVarParam = 0x4B, DwarfAttrVirtuality = 0x4C, DwarfAttrVtableElemLoc = 0x4D, DwarfAttrAllocated = 0x4E,
  DwarfAttrAssociated = 0x4F, DwarfAttrDataLocation = 0x50, DwarfAttrStride = 0x51, DwarfAttrEntrypc = 0x52,
  DwarfAttrUseUTF8 = 0x53, DwarfAttrExtension = 0x54, DwarfAttrRanges = 0x55, DwarfAttrTrampoline = 0x56,
  DwarfAttrCallColumn = 0x57, DwarfAttrCallFile = 0x58, DwarfAttrCallLine = 0x59, DwarfAttrDescription = 0x5A,
  DwarfAttrMax, FormAddr = 0x01, FormDwarfBlock2 = 0x03, FormDwarfBlock4 = 0x04,
  FormData2 = 0x05, FormData4 = 0x06, FormData8 = 0x07, FormString = 0x08,
  FormDwarfBlock = 0x09, FormDwarfBlock1 = 0x0A, FormData1 = 0x0B, FormFlag = 0x0C,
  FormSdata = 0x0D, FormStrp = 0x0E, FormUdata = 0x0F, FormRefAddr = 0x10,
  FormRef1 = 0x11, FormRef2 = 0x12, FormRef4 = 0x13, FormRef8 = 0x14,
  FormRefUdata = 0x15, FormIndirect = 0x16
}
 

Functions

static int parseattrs (DwarfBuf *, ulong, DwarfAbbrev *, DwarfAttrs *)
 
static int getulong (DwarfBuf *, int, ulong, ulong *, int *)
 
static int getuchar (DwarfBuf *, int, uchar *)
 
static int getstring (DwarfBuf *, int, char **)
 
static int getblock (DwarfBuf *, int, DwarfBlock *)
 
static int skipform (DwarfBuf *, int)
 
static int constblock (Dwarf *, DwarfBlock *, ulong *)
 
int dwarflookupnameinunit (Dwarf *d, ulong unit, char *name, DwarfSym *s)
 
int dwarflookupsubname (Dwarf *d, DwarfSym *parent, char *name, DwarfSym *s)
 
int dwarflookuptag (Dwarf *d, ulong unit, ulong tag, DwarfSym *s)
 
int dwarfseeksym (Dwarf *d, ulong unit, ulong off, DwarfSym *s)
 
int dwarflookupfn (Dwarf *d, ulong unit, ulong pc, DwarfSym *s)
 
int dwarfenumunit (Dwarf *d, ulong unit, DwarfSym *s)
 
int dwarfenum (Dwarf *d, DwarfSym *s)
 
int dwarfnextsym (Dwarf *d, DwarfSym *s)
 
int dwarfnextsymat (Dwarf *d, DwarfSym *s, int depth)
 

Variables

static Parse plist []
 
static Parse ptab [DwarfAttrMax]
 

Macro Definition Documentation

#define NDEBUG

Definition at line 12 of file dwarfinfo.c.

#define NTOSAPI

Definition at line 5 of file dwarfinfo.c.

Definition at line 338 of file dwarfinfo.c.

Typedef Documentation

typedef struct Parse Parse

Definition at line 330 of file dwarfinfo.c.

Enumeration Type Documentation

anonymous enum
Enumerator
DwarfAttrSibling 
DwarfAttrLocation 
DwarfAttrName 
DwarfAttrOrdering 
DwarfAttrByteSize 
DwarfAttrBitOffset 
DwarfAttrBitSize 
DwarfAttrStmtList 
DwarfAttrLowpc 
DwarfAttrHighpc 
DwarfAttrLanguage 
DwarfAttrDiscr 
DwarfAttrDiscrValue 
DwarfAttrVisibility 
DwarfAttrImport 
DwarfAttrStringLength 
DwarfAttrCommonRef 
DwarfAttrCompDir 
DwarfAttrConstValue 
DwarfAttrContainingType 
DwarfAttrDefaultValue 
DwarfAttrInline 
DwarfAttrIsOptional 
DwarfAttrLowerBound 
DwarfAttrProducer 
DwarfAttrPrototyped 
DwarfAttrReturnAddr 
DwarfAttrStartScope 
DwarfAttrStrideSize 
DwarfAttrUpperBound 
DwarfAttrAbstractOrigin 
DwarfAttrAccessibility 
DwarfAttrAddrClass 
DwarfAttrArtificial 
DwarfAttrBaseTypes 
DwarfAttrCalling 
DwarfAttrCount 
DwarfAttrDataMemberLoc 
DwarfAttrDeclColumn 
DwarfAttrDeclFile 
DwarfAttrDeclLine 
DwarfAttrDeclaration 
DwarfAttrDiscrList 
DwarfAttrEncoding 
DwarfAttrExternal 
DwarfAttrFrameBase 
DwarfAttrFriend 
DwarfAttrIdentifierCase 
DwarfAttrMacroInfo 
DwarfAttrNamelistItem 
DwarfAttrPriority 
DwarfAttrSegment 
DwarfAttrSpecification 
DwarfAttrStaticLink 
DwarfAttrType 
DwarfAttrUseLocation 
DwarfAttrVarParam 
DwarfAttrVirtuality 
DwarfAttrVtableElemLoc 
DwarfAttrAllocated 
DwarfAttrAssociated 
DwarfAttrDataLocation 
DwarfAttrStride 
DwarfAttrEntrypc 
DwarfAttrUseUTF8 
DwarfAttrExtension 
DwarfAttrRanges 
DwarfAttrTrampoline 
DwarfAttrCallColumn 
DwarfAttrCallFile 
DwarfAttrCallLine 
DwarfAttrDescription 
DwarfAttrMax 
FormAddr 
FormDwarfBlock2 
FormDwarfBlock4 
FormData2 
FormData4 
FormData8 
FormString 
FormDwarfBlock 
FormDwarfBlock1 
FormData1 
FormFlag 
FormSdata 
FormStrp 
FormUdata 
FormRefAddr 
FormRef1 
FormRef2 
FormRef4 
FormRef8 
FormRefUdata 
FormIndirect 

Definition at line 18 of file dwarfinfo.c.

19 {
20  DwarfAttrSibling = 0x01,
21  DwarfAttrLocation = 0x02,
22  DwarfAttrName = 0x03,
23  DwarfAttrOrdering = 0x09,
24  DwarfAttrByteSize = 0x0B,
25  DwarfAttrBitOffset = 0x0C,
26  DwarfAttrBitSize = 0x0D,
27  DwarfAttrStmtList = 0x10,
28  DwarfAttrLowpc = 0x11,
29  DwarfAttrHighpc = 0x12,
30  DwarfAttrLanguage = 0x13,
31  DwarfAttrDiscr = 0x15,
32  DwarfAttrDiscrValue = 0x16,
33  DwarfAttrVisibility = 0x17,
34  DwarfAttrImport = 0x18,
35  DwarfAttrStringLength = 0x19,
36  DwarfAttrCommonRef = 0x1A,
37  DwarfAttrCompDir = 0x1B,
38  DwarfAttrConstValue = 0x1C,
40  DwarfAttrDefaultValue = 0x1E,
41  DwarfAttrInline = 0x20,
42  DwarfAttrIsOptional = 0x21,
43  DwarfAttrLowerBound = 0x22,
44  DwarfAttrProducer = 0x25,
45  DwarfAttrPrototyped = 0x27,
46  DwarfAttrReturnAddr = 0x2A,
47  DwarfAttrStartScope = 0x2C,
48  DwarfAttrStrideSize = 0x2E,
49  DwarfAttrUpperBound = 0x2F,
52  DwarfAttrAddrClass = 0x33,
53  DwarfAttrArtificial = 0x34,
54  DwarfAttrBaseTypes = 0x35,
55  DwarfAttrCalling = 0x36,
56  DwarfAttrCount = 0x37,
58  DwarfAttrDeclColumn = 0x39,
59  DwarfAttrDeclFile = 0x3A,
60  DwarfAttrDeclLine = 0x3B,
61  DwarfAttrDeclaration = 0x3C,
62  DwarfAttrDiscrList = 0x3D,
63  DwarfAttrEncoding = 0x3E,
64  DwarfAttrExternal = 0x3F,
65  DwarfAttrFrameBase = 0x40,
66  DwarfAttrFriend = 0x41,
68  DwarfAttrMacroInfo = 0x43,
69  DwarfAttrNamelistItem = 0x44,
70  DwarfAttrPriority = 0x45,
71  DwarfAttrSegment = 0x46,
73  DwarfAttrStaticLink = 0x48,
74  DwarfAttrType = 0x49,
75  DwarfAttrUseLocation = 0x4A,
76  DwarfAttrVarParam = 0x4B,
77  DwarfAttrVirtuality = 0x4C,
79  DwarfAttrAllocated = 0x4E,
80  DwarfAttrAssociated = 0x4F,
81  DwarfAttrDataLocation = 0x50,
82  DwarfAttrStride = 0x51,
83  DwarfAttrEntrypc = 0x52,
84  DwarfAttrUseUTF8 = 0x53,
85  DwarfAttrExtension = 0x54,
86  DwarfAttrRanges = 0x55,
87  DwarfAttrTrampoline = 0x56,
88  DwarfAttrCallColumn = 0x57,
89  DwarfAttrCallFile = 0x58,
90  DwarfAttrCallLine = 0x59,
91  DwarfAttrDescription = 0x5A,
93 
94  FormAddr = 0x01,
95  FormDwarfBlock2 = 0x03,
96  FormDwarfBlock4 = 0x04,
97  FormData2 = 0x05,
98  FormData4 = 0x06,
99  FormData8 = 0x07,
100  FormString = 0x08,
101  FormDwarfBlock = 0x09,
102  FormDwarfBlock1 = 0x0A,
103  FormData1 = 0x0B,
104  FormFlag = 0x0C,
105  FormSdata = 0x0D,
106  FormStrp = 0x0E,
107  FormUdata = 0x0F,
108  FormRefAddr = 0x10,
109  FormRef1 = 0x11,
110  FormRef2 = 0x12,
111  FormRef4 = 0x13,
112  FormRef8 = 0x14,
113  FormRefUdata = 0x15,
114  FormIndirect = 0x16
115 };

Function Documentation

static int constblock ( Dwarf d,
DwarfBlock bl,
ulong pval 
)
static

Definition at line 596 of file dwarfinfo.c.

Referenced by parseattrs().

597 {
598  DwarfBuf b;
599 
600  memset(&b, 0, sizeof b);
601  b.p = bl->data;
602  b.ep = bl->data+bl->len;
603  b.d = d;
604 
605  switch(dwarfget1(&b)){
606  case OpAddr:
607  *pval = dwarfgetaddr(&b);
608  return TConstant;
609  case OpConst1u:
610  *pval = dwarfget1(&b);
611  return TConstant;
612  case OpConst1s:
613  *pval = (schar)dwarfget1(&b);
614  return TConstant;
615  case OpConst2u:
616  *pval = dwarfget2(&b);
617  return TConstant;
618  case OpConst2s:
619  *pval = (s16int)dwarfget2(&b);
620  return TConstant;
621  case OpConst4u:
622  *pval = dwarfget4(&b);
623  return TConstant;
624  case OpConst4s:
625  *pval = (s32int)dwarfget4(&b);
626  return TConstant;
627  case OpConst8u:
628  *pval = (u64int)dwarfget8(&b);
629  return TConstant;
630  case OpConst8s:
631  *pval = (s64int)dwarfget8(&b);
632  return TConstant;
633  case OpConstu:
634  *pval = dwarfget128(&b);
635  return TConstant;
636  case OpConsts:
637  *pval = dwarfget128s(&b);
638  return TConstant;
639  case OpPlusUconst:
640  *pval = dwarfget128(&b);
641  return TConstant;
642  default:
643  return TBlock;
644  }
645 }
Definition: dwarf.h:137
Definition: dwarf.h:131
Dwarf * d
Definition: dwarf.h:209
ulong dwarfget4(DwarfBuf *)
Definition: dwarfget.c:96
uchar * data
Definition: dwarf.h:202
signed char schar
Definition: compat.h:5
int s32int
Definition: compat.h:14
long long s64int
Definition: compat.h:16
ulong dwarfget1(DwarfBuf *)
Definition: dwarfget.c:18
short s16int
Definition: compat.h:12
#define b
Definition: ke_i.h:79
#define d
Definition: ke_i.h:81
ulong len
Definition: dwarf.h:203
uchar * p
Definition: dwarf.h:210
long dwarfget128s(DwarfBuf *)
Definition: dwarfget.c:198
ulong dwarfget2(DwarfBuf *)
Definition: dwarfget.c:82
ulong dwarfget128(DwarfBuf *)
Definition: dwarfget.c:153
uchar * ep
Definition: dwarf.h:211
uvlong dwarfget8(DwarfBuf *)
Definition: dwarfget.c:110
#define memset(x, y, z)
Definition: compat.h:39
ulong dwarfgetaddr(DwarfBuf *)
Definition: dwarfget.c:124
unsigned long long u64int
Definition: compat.h:15
int dwarfenum ( Dwarf d,
DwarfSym s 
)

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
int allunits
Definition: dwarf.h:383
int dwarfenumunit ( Dwarf d,
ulong  unit,
DwarfSym s 
)

Definition at line 202 of file dwarfinfo.c.

Referenced by dwarfargvalue(), dwarfenum(), dwarflookupfn(), dwarflookupnameinunit(), dwarflookuptag(), dwarfnextsym(), and dwarfseeksym().

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 }
uint addrsize
Definition: dwarf.h:212
#define werrstr(str,...)
Definition: compat.h:34
DwarfBlock info
Definition: dwarf.h:446
Dwarf * d
Definition: dwarf.h:209
ulong dwarfget4(DwarfBuf *)
Definition: dwarfget.c:96
uchar * data
Definition: dwarf.h:202
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
ulong unit
Definition: dwarf.h:379
#define d
Definition: ke_i.h:81
int addrsize
Definition: dwarf.h:442
ulong len
Definition: dwarf.h:203
uchar * p
Definition: dwarf.h:210
ulong dwarfget2(DwarfBuf *)
Definition: dwarfget.c:82
ulong nextunit
Definition: dwarf.h:384
GLenum GLsizei len
Definition: glext.h:6722
unsigned long ulong
Definition: linux.h:275
DwarfBuf b
Definition: dwarf.h:378
#define nil
Definition: compat.h:23
uchar * ep
Definition: dwarf.h:211
int depth
Definition: dwarf.h:382
ulong aoff
Definition: dwarf.h:381
#define memset(x, y, z)
Definition: compat.h:39
int dwarflookupfn ( Dwarf d,
ulong  unit,
ulong  pc,
DwarfSym s 
)

Definition at line 182 of file dwarfinfo.c.

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 }
uchar lowpc
Definition: dwarf.h:268
#define werrstr(str,...)
Definition: compat.h:34
int dwarfenumunit(Dwarf *d, ulong unit, DwarfSym *s)
Definition: dwarfinfo.c:202
ulong tag
Definition: dwarf.h:225
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
int dwarfnextsymat(Dwarf *d, DwarfSym *s, int depth)
Definition: dwarfinfo.c:293
DwarfAttrs attrs
Definition: dwarf.h:375
int dwarflookupnameinunit ( Dwarf d,
ulong  unit,
char name,
DwarfSym s 
)

Definition at line 126 of file dwarfinfo.c.

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
int dwarfnextsymat(Dwarf *d, DwarfSym *s, int depth)
Definition: dwarfinfo.c:293
Definition: name.c:23
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
uchar name
Definition: dwarf.h:270
DwarfAttrs attrs
Definition: dwarf.h:375
int dwarflookupsubname ( Dwarf d,
DwarfSym parent,
char name,
DwarfSym s 
)

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
r parent
Definition: btrfs.c:2598
int dwarfnextsymat(Dwarf *d, DwarfSym *s, int depth)
Definition: dwarfinfo.c:293
Definition: name.c:23
int depth
Definition: dwarf.h:382
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
uchar name
Definition: dwarf.h:270
DwarfAttrs attrs
Definition: dwarf.h:375
int dwarflookuptag ( Dwarf d,
ulong  unit,
ulong  tag,
DwarfSym s 
)

Definition at line 152 of file dwarfinfo.c.

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
ulong tag
Definition: dwarf.h:225
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
int dwarfnextsymat(Dwarf *d, DwarfSym *s, int depth)
Definition: dwarfinfo.c:293
DwarfAttrs attrs
Definition: dwarf.h:375
int dwarfnextsym ( Dwarf d,
DwarfSym s 
)

Definition at line 251 of file dwarfinfo.c.

Referenced by dwarfenumunit(), dwarflookupchildtag(), dwarflookuptag(), dwarfnextsym(), and dwarfnextsymat().

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
DwarfBlock info
Definition: dwarf.h:446
uchar * data
Definition: dwarf.h:202
uint uoff
Definition: dwarf.h:380
#define a
Definition: ke_i.h:78
int allunits
Definition: dwarf.h:383
ulong unit
Definition: dwarf.h:379
uchar haskids
Definition: dwarf.h:226
ulong len
Definition: dwarf.h:203
GLuint GLuint num
Definition: glext.h:9618
uchar * p
Definition: dwarf.h:210
ulong nextunit
Definition: dwarf.h:384
unsigned long ulong
Definition: linux.h:275
DwarfBuf b
Definition: dwarf.h:378
ulong dwarfget128(DwarfBuf *)
Definition: dwarfget.c:153
DwarfAbbrev * dwarfgetabbrev(Dwarf *, ulong, ulong)
Definition: dwarfabbrev.c:129
#define nil
Definition: compat.h:23
uchar * ep
Definition: dwarf.h:211
int depth
Definition: dwarf.h:382
ulong aoff
Definition: dwarf.h:381
GLdouble GLdouble GLdouble GLdouble top
Definition: glext.h:10859
static int parseattrs(DwarfBuf *, ulong, DwarfAbbrev *, DwarfAttrs *)
Definition: dwarfinfo.c:408
DwarfAttrs attrs
Definition: dwarf.h:375
int dwarfnextsymat ( Dwarf d,
DwarfSym s,
int  depth 
)

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 }
DwarfBlock info
Definition: dwarf.h:446
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
struct DwarfAttrs::@3764 have
uchar * data
Definition: dwarf.h:202
GLdouble GLdouble t
Definition: gl.h:2047
int dwarfnextsym(Dwarf *d, DwarfSym *s)
Definition: dwarfinfo.c:251
Definition: compobj.c:613
uchar haskids
Definition: dwarf.h:226
uchar * p
Definition: dwarf.h:210
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
GLdouble s
Definition: gl.h:2039
DwarfBuf b
Definition: dwarf.h:378
int depth
Definition: dwarf.h:382
UINT32 uint
Definition: types.h:83
uchar sibling
Definition: dwarf.h:278
DwarfAttrs attrs
Definition: dwarf.h:375
int dwarfseeksym ( Dwarf d,
ulong  unit,
ulong  off,
DwarfSym s 
)

Definition at line 171 of file dwarfinfo.c.

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
DwarfBlock info
Definition: dwarf.h:446
uchar * data
Definition: dwarf.h:202
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
int dwarfnextsymat(Dwarf *d, DwarfSym *s, int depth)
Definition: dwarfinfo.c:293
uchar * p
Definition: dwarf.h:210
DwarfBuf b
Definition: dwarf.h:378
off
Definition: i386-dis.c:3909
static int getblock ( DwarfBuf b,
int  form,
DwarfBlock bl 
)
static

Definition at line 568 of file dwarfinfo.c.

Referenced by parseattrs(), and skipform().

569 {
570  ulong n;
571 
572  switch(form){
573  default:
574  return -1;
575  case FormDwarfBlock:
576  n = dwarfget128(b);
577  goto copyn;
578  case FormDwarfBlock1:
579  n = dwarfget1(b);
580  goto copyn;
581  case FormDwarfBlock2:
582  n = dwarfget2(b);
583  goto copyn;
584  case FormDwarfBlock4:
585  n = dwarfget4(b);
586  copyn:
587  bl->data = dwarfgetnref(b, n);
588  bl->len = n;
589  if(bl->data == nil)
590  return -1;
591  return 0;
592  }
593 }
int form
Definition: main.c:89
ulong dwarfget4(DwarfBuf *)
Definition: dwarfget.c:96
uchar * data
Definition: dwarf.h:202
GLuint n
Definition: s_context.h:57
ulong dwarfget1(DwarfBuf *)
Definition: dwarfget.c:18
ulong len
Definition: dwarf.h:203
ulong dwarfget2(DwarfBuf *)
Definition: dwarfget.c:82
unsigned long ulong
Definition: linux.h:275
ulong dwarfget128(DwarfBuf *)
Definition: dwarfget.c:153
#define nil
Definition: compat.h:23
uchar * dwarfgetnref(DwarfBuf *, ulong)
Definition: dwarfget.c:41
static int getstring ( DwarfBuf b,
int  form,
char **  s 
)
static

Definition at line 540 of file dwarfinfo.c.

Referenced by parseattrs(), and skipform().

541 {
542  static int nbad;
543  ulong u;
544 
545  switch(form){
546  default:
547  return -1;
548 
549  case FormString:
550  *s = dwarfgetstring(b);
551  return 0;
552 
553  case FormStrp:
554  u = dwarfget4(b);
555  if(u >= b->d->str.len){
556  if(++nbad == 1)
557  werrstr("dwarf: bad string pointer 0x%lux in attribute", u);
558  /* don't return error - maybe can proceed */
559  *s = nil;
560  }else
561  *s = (char*)b->d->str.data + u;
562  return 0;
563 
564  }
565 }
#define werrstr(str,...)
Definition: compat.h:34
char * dwarfgetstring(DwarfBuf *)
Definition: dwarfget.c:55
Dwarf * d
Definition: dwarf.h:209
int form
Definition: main.c:89
ulong dwarfget4(DwarfBuf *)
Definition: dwarfget.c:96
uchar * data
Definition: dwarf.h:202
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble * u
Definition: glfuncs.h:88
ulong len
Definition: dwarf.h:203
GLdouble s
Definition: gl.h:2039
unsigned long ulong
Definition: linux.h:275
#define nil
Definition: compat.h:23
DwarfBlock str
Definition: dwarf.h:451
static int getuchar ( DwarfBuf b,
int  form,
uchar u 
)
static

Definition at line 527 of file dwarfinfo.c.

Referenced by parseattrs(), and skipform().

528 {
529  switch(form){
530  default:
531  return -1;
532 
533  case FormFlag:
534  *u = dwarfget1(b);
535  return 0;
536  }
537 }
int form
Definition: main.c:89
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble * u
Definition: glfuncs.h:88
ulong dwarfget1(DwarfBuf *)
Definition: dwarfget.c:18
static int getulong ( DwarfBuf b,
int  form,
ulong  unit,
ulong u,
int type 
)
static

Definition at line 459 of file dwarfinfo.c.

Referenced by parseattrs(), and skipform().

460 {
461  static int nbad;
462  uvlong uv;
463 
464  switch(form){
465  default:
466  return -1;
467 
468  /* addresses */
469  case FormAddr:
470  *type = TAddress;
471  *u = dwarfgetaddr(b);
472  return 0;
473 
474  /* references */
475  case FormRefAddr:
476  /* absolute ref in .debug_info */
477  *type = TReference;
478  *u = dwarfgetaddr(b);
479  return 0;
480  case FormRef1:
481  *u = dwarfget1(b);
482  goto relativeref;
483  case FormRef2:
484  *u = dwarfget2(b);
485  goto relativeref;
486  case FormRef4:
487  *u = dwarfget4(b);
488  goto relativeref;
489  case FormRef8:
490  *u = dwarfget8(b);
491  goto relativeref;
492  case FormRefUdata:
493  *u = dwarfget128(b);
494  relativeref:
495  *u += unit;
496  *type = TReference;
497  return 0;
498 
499  /* constants */
500  case FormData1:
501  *u = dwarfget1(b);
502  goto constant;
503  case FormData2:
504  *u = dwarfget2(b);
505  goto constant;
506  case FormData4:
507  *u = dwarfget4(b);
508  goto constant;
509  case FormData8:
510  uv = dwarfget8(b);
511  *u = uv;
512  if(uv != *u && ++nbad == 1)
513  werrstr("dwarf: truncating 64-bit attribute constants");
514  goto constant;
515  case FormSdata:
516  *u = dwarfget128s(b);
517  goto constant;
518  case FormUdata:
519  *u = dwarfget128(b);
520  constant:
521  *type = TConstant;
522  return 0;
523  }
524 }
#define werrstr(str,...)
Definition: compat.h:34
int form
Definition: main.c:89
ulong dwarfget4(DwarfBuf *)
Definition: dwarfget.c:96
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble * u
Definition: glfuncs.h:88
ulong dwarfget1(DwarfBuf *)
Definition: dwarfget.c:18
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
long dwarfget128s(DwarfBuf *)
Definition: dwarfget.c:198
ulong dwarfget2(DwarfBuf *)
Definition: dwarfget.c:82
ulong dwarfget128(DwarfBuf *)
Definition: dwarfget.c:153
unsigned long long uvlong
Definition: compat.h:9
uvlong dwarfget8(DwarfBuf *)
Definition: dwarfget.c:110
ulong dwarfgetaddr(DwarfBuf *)
Definition: dwarfget.c:124
static int parseattrs ( DwarfBuf b,
ulong  unit,
DwarfAbbrev a,
DwarfAttrs attrs 
)
static

Definition at line 408 of file dwarfinfo.c.

Referenced by dwarfnextsym().

409 {
410  int i, f, n, got;
411  static int nbad;
412  void *v;
413 
414  /* initialize ptab first time through for quick access */
416  for(i=0; plist[i].name; i++)
417  ptab[plist[i].name] = plist[i];
418 
419  memset(attrs, 0, sizeof *attrs);
420  attrs->tag = a->tag;
421  attrs->haskids = a->haskids;
422 
423  for(i=0; i<a->nattr; i++){
424  n = a->attr[i].name;
425  f = a->attr[i].form;
426  if(n < 0 || n >= DwarfAttrMax || ptab[n].name==0){
427  if(++nbad == 1)
428  werrstr("dwarf parse attrs: unexpected attribute name 0x%x", n);
429  continue; //return -1;
430  }
431  v = (char*)attrs + ptab[n].off;
432  got = 0;
433  if(f == FormIndirect)
434  f = dwarfget128(b);
436  && getulong(b, f, unit, v, &got) >= 0)
437  ;
438  else if((ptab[n].type&TFlag) && getuchar(b, f, v) >= 0)
439  got = TFlag;
440  else if((ptab[n].type&TString) && getstring(b, f, v) >= 0)
441  got = TString;
442  else if((ptab[n].type&TBlock) && getblock(b, f, v) >= 0)
443  got = TBlock;
444  else{
445  if(skipform(b, f) < 0){
446  if(++nbad == 1)
447  werrstr("dwarf parse attrs: cannot skip form %d", f);
448  return -1;
449  }
450  }
451  if(got == TBlock && (ptab[n].type&TConstant))
452  got = constblock(b->d, v, v);
453  *((uchar*)attrs+ptab[n].haveoff) = got;
454  }
455  return 0;
456 }
#define werrstr(str,...)
Definition: compat.h:34
static int getstring(DwarfBuf *, int, char **)
Definition: dwarfinfo.c:540
static Parse plist[]
Definition: dwarfinfo.c:340
Definition: dwarf.h:131
ulong name
Definition: dwarf.h:421
unsigned char uchar
Definition: Unfrag.h:59
Dwarf * d
Definition: dwarf.h:209
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
static Parse ptab[DwarfAttrMax]
Definition: dwarfinfo.c:405
int nattr
Definition: dwarf.h:431
int name
Definition: dwarfinfo.c:332
GLuint n
Definition: s_context.h:57
static int skipform(DwarfBuf *, int)
Definition: dwarfinfo.c:649
GLenum GLclampf GLint i
Definition: glfuncs.h:14
ulong tag
Definition: dwarf.h:225
Definition: dwarf.h:134
png_const_structrp png_const_inforp int * unit
Definition: png.h:2192
ulong tag
Definition: dwarf.h:428
static int constblock(Dwarf *, DwarfBlock *, ulong *)
Definition: dwarfinfo.c:596
uchar haskids
Definition: dwarf.h:226
static int getblock(DwarfBuf *, int, DwarfBlock *)
Definition: dwarfinfo.c:568
static int getulong(DwarfBuf *, int, ulong, ulong *, int *)
Definition: dwarfinfo.c:459
Definition: dwarf.h:133
const GLdouble * v
Definition: gl.h:2040
ulong dwarfget128(DwarfBuf *)
Definition: dwarfget.c:153
static int getuchar(DwarfBuf *, int, uchar *)
Definition: dwarfinfo.c:527
#define f
Definition: ke_i.h:83
DwarfAttr * attr
Definition: dwarf.h:430
ulong form
Definition: dwarf.h:422
Definition: name.c:23
uchar haskids
Definition: dwarf.h:429
#define memset(x, y, z)
Definition: compat.h:39
off
Definition: i386-dis.c:3909
static int skipform ( DwarfBuf b,
int  form 
)
static

Definition at line 649 of file dwarfinfo.c.

Referenced by parseattrs().

650 {
651  int type;
652  DwarfVal val;
653 
654  if(getulong(b, form, 0, &val.c, &type) < 0
655  && getuchar(b, form, (uchar*)&val) < 0
656  && getstring(b, form, &val.s) < 0
657  && getblock(b, form, &val.b) < 0)
658  return -1;
659  return 0;
660 }
static int getstring(DwarfBuf *, int, char **)
Definition: dwarfinfo.c:540
unsigned char uchar
Definition: Unfrag.h:59
int form
Definition: main.c:89
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint GLfloat * val
Definition: glext.h:7180
static int getblock(DwarfBuf *, int, DwarfBlock *)
Definition: dwarfinfo.c:568
static int getulong(DwarfBuf *, int, ulong, ulong *, int *)
Definition: dwarfinfo.c:459
DwarfBlock b
Definition: dwarf.h:220
ulong c
Definition: dwarf.h:218
static int getuchar(DwarfBuf *, int, uchar *)
Definition: dwarfinfo.c:527
char * s
Definition: dwarf.h:217

Variable Documentation

Parse ptab[DwarfAttrMax]
static

Definition at line 405 of file dwarfinfo.c.