ReactOS  0.4.14-dev-293-g2b39b42
dwarfdump.c File Reference
#include "dwarf.h"
#include "pe.h"
Include dependency graph for dwarfdump.c:

Go to the source code of this file.

Functions

void printrules (Dwarf *d, ulong pc)
 
void usage (void)
 
void main (int argc, char **argv)
 

Function Documentation

◆ main()

void main ( int argc  ,
char **  argv 
)

Definition at line 21 of file dwarfdump.c.

22 {
23  int c;
24  Pe *pe;
25  Dwarf *d;
26  DwarfSym s;
27  char *cdir, *dir, *file;
28  ulong line, mtime, length;
29 
30  if(argc != 2)
31  usage();
32 
33 #if 0
34  fmtinstall('R', exprfmt);
35  fmtinstall('H', encodefmt);
36 #endif
37 
38  if((pe = peopen(argv[1])) == nil)
39  sysfatal("elfopen %s: %r", argv[1]);
40  if((d=dwarfopen(pe)) == nil)
41  sysfatal("dwarfopen: %r");
42 
43  if(dwarfenum(d, &s) < 0)
44  sysfatal("dwarfenumall: %r");
45 
46  while(dwarfnextsym(d, &s) == 1){
47  switch(s.attrs.tag){
48  case TagCompileUnit:
49  print("compileunit %s\n", s.attrs.name);
50  break;
51  case TagSubprogram:
52  c = 't';
53  goto sym;
54  case TagVariable:
55  c = 'd';
56  goto sym;
57  case TagConstant:
58  c = 'c';
59  goto sym;
60  case TagFormalParameter:
61  if(!s.attrs.name)
62  break;
63  c = 'p';
64  sym:
65  if(s.attrs.isexternal)
66  c += 'A' - 'a';
67  print("%c %s", c, s.attrs.name);
68  if(s.attrs.have.lowpc)
69  print(" 0x%lux-0x%lux", s.attrs.lowpc, s.attrs.highpc);
70  switch(s.attrs.have.location){
71  case TBlock:
72  print(" @ %.*H", s.attrs.location.b.len, s.attrs.location.b.data);
73  break;
74  case TConstant:
75  print(" @ 0x%lux", s.attrs.location.c);
76  break;
77  }
78  if(s.attrs.have.ranges)
79  print(" ranges@0x%lux", s.attrs.ranges);
80  print("\n");
81  if(s.attrs.have.lowpc){
82  if(dwarfpctoline(d, s.attrs.lowpc, &cdir, &dir, &file, &line, &mtime, &length) < 0)
83  print("\tcould not find source: %r\n");
84  else if(dir == nil)
85  print("\t%s/%s:%lud mtime=%lud length=%lud\n",
86  cdir, file, line, mtime, length);
87  else
88  print("\t%s/%s/%s:%lud mtime=%lud length=%lud\n",
89  cdir, dir, file, line, mtime, length);
90 
91  if(0) printrules(d, s.attrs.lowpc);
92  if(0) printrules(d, (s.attrs.lowpc+s.attrs.highpc)/2);
93  }
94  break;
95  }
96  }
97  exits(0);
98 }
int dwarfnextsym(Dwarf *, DwarfSym *)
Definition: dwarfinfo.c:251
static int argc
Definition: ServiceArgs.c:12
Dwarf * dwarfopen(struct _Pe *elf)
Definition: dwarfopen.c:16
Definition: pe.h:14
#define argv
Definition: mplay32.c:18
int dwarfpctoline(Dwarf *, ulong, char **, char **, char **, char **, ulong *, ulong *, ulong *)
Definition: dwarfpc.c:49
void usage(void)
Definition: dwarfdump.c:14
Definition: parser.c:48
unsigned int dir
Definition: maze.c:112
Definition: dwarf.h:131
int dwarfenum(Dwarf *, DwarfSym *)
Definition: dwarfinfo.c:242
#define d
Definition: ke_i.h:81
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
const char file[]
Definition: icontest.c:11
const GLubyte * c
Definition: glext.h:8905
char line[200]
Definition: main.c:97
GLdouble s
Definition: gl.h:2039
unsigned long ulong
Definition: linux.h:275
static void print(LPPRINTDLGW pd, LPWSTR wszFileName)
Definition: print.c:440
Pe * peopen(const char *name)
Definition: dwarf.h:436
#define nil
Definition: compat.h:23
#define c
Definition: ke_i.h:80
void printrules(Dwarf *d, ulong pc)
Definition: dwarfdump.c:101
Definition: fci.c:126

◆ printrules()

void printrules ( Dwarf d,
ulong  pc 
)

Definition at line 101 of file dwarfdump.c.

102 {
103  int i;
104  DwarfExpr r[10];
105  DwarfExpr cfa, ra;
106 
107  if(dwarfunwind(d, pc, &cfa, &ra, r, nelem(r)) < 0)
108  print("\tcannot unwind from pc 0x%lux: %r\n", pc);
109 
110  print("\tpc=0x%lux cfa=%R ra=%R", pc, &cfa, &ra);
111  for(i=0; i<nelem(r); i++)
112  if(r[i].type != RuleSame)
113  print(" r%d=%R", i, &r[i]);
114  print("\n");
115 }
int dwarfunwind(Dwarf *, ulong, DwarfExpr *, DwarfExpr *, DwarfExpr *, int)
Definition: dwarfcfa.c:48
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define nelem(x)
Definition: shaptest.c:19
GLsizei GLenum const GLvoid GLsizei GLenum 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 const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define d
Definition: ke_i.h:81
static void print(LPPRINTDLGW pd, LPWSTR wszFileName)
Definition: print.c:440

Referenced by main().

◆ usage()

void usage ( void  )

Definition at line 14 of file dwarfdump.c.

15 {
16  fprint(2, "usage: dwarfdump file\n");
17  exits("usage");
18 }

Referenced by main().