ReactOS 0.4.16-dev-122-g325d74c
dwarfdump.c
Go to the documentation of this file.
1#if 0
2#include <u.h>
3#include <libc.h>
4#include <bio.h>
5#include "elf.h"
6#endif
7#include "dwarf.h"
8#include "pe.h"
9
10void printrules(Dwarf *d, ulong pc);
11//int exprfmt(Fmt*);
12
13void
14usage(void)
15{
16 fprint(2, "usage: dwarfdump file\n");
17 exits("usage");
18}
19
20void
21main(int argc, char **argv)
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;
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}
99
100void
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}
116
117#if 0
118int
119exprfmt(Fmt *fmt)
120{
121 DwarfExpr *e;
122
123 if((e = va_arg(fmt->args, DwarfExpr*)) == nil)
124 return fmtstrcpy(fmt, "<nil>");
125
126 switch(e->type){
127 case RuleUndef:
128 return fmtstrcpy(fmt, "undef");
129 case RuleSame:
130 return fmtstrcpy(fmt, "same");
131 case RuleCfaOffset:
132 return fmtprint(fmt, "%ld(cfa)", e->offset);
133 case RuleRegister:
134 return fmtprint(fmt, "r%ld", e->reg);
135 case RuleRegOff:
136 return fmtprint(fmt, "%ld(r%ld)", e->offset, e->reg);
137 case RuleLocation:
138 return fmtprint(fmt, "l.%.*H", e->loc.len, e->loc.data);
139 default:
140 return fmtprint(fmt, "?%d", e->type);
141 }
142}
143#endif
static int argc
Definition: ServiceArgs.c:12
#define va_arg(ap, T)
Definition: acmsvcex.h:89
unsigned int dir
Definition: maze.c:112
static void print(LPPRINTDLGW pd, LPWSTR wszFileName)
Definition: print.c:438
int main()
Definition: test.c:6
unsigned long ulong
Definition: linux.h:275
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLdouble s
Definition: gl.h:2039
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
const GLubyte * c
Definition: glext.h:8905
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
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
#define e
Definition: ke_i.h:82
#define c
Definition: ke_i.h:80
#define argv
Definition: mplay32.c:18
void printrules(Dwarf *d, ulong pc)
Definition: dwarfdump.c:101
void usage(void)
Definition: dwarfdump.c:14
Pe * peopen(const char *name)
#define nil
Definition: compat.h:23
int dwarfpctoline(Dwarf *, ulong, char **, char **, char **, char **, ulong *, ulong *, ulong *)
Definition: dwarfpc.c:48
Dwarf * dwarfopen(struct _Pe *elf)
Definition: dwarfopen.c:16
@ RuleLocation
Definition: dwarf.h:363
@ RuleRegOff
Definition: dwarf.h:362
@ RuleRegister
Definition: dwarf.h:361
@ RuleSame
Definition: dwarf.h:359
@ RuleCfaOffset
Definition: dwarf.h:360
@ RuleUndef
Definition: dwarf.h:358
int dwarfnextsym(Dwarf *, DwarfSym *)
Definition: dwarfinfo.c:250
int dwarfenum(Dwarf *, DwarfSym *)
Definition: dwarfinfo.c:241
@ TagCompileUnit
Definition: dwarf.h:24
@ TagVariable
Definition: dwarf.h:58
@ TagFormalParameter
Definition: dwarf.h:17
@ TagConstant
Definition: dwarf.h:45
@ TConstant
Definition: dwarf.h:132
@ TagSubprogram
Definition: dwarf.h:52
@ TBlock
Definition: dwarf.h:131
int dwarfunwind(Dwarf *, ulong, DwarfExpr *, DwarfExpr *, DwarfExpr *, int)
Definition: dwarfcfa.c:47
#define nelem(x)
Definition: shaptest.c:19
Definition: dwarf.h:437
Definition: pe.h:14
Definition: fci.c:127
Definition: dsound.c:943
Definition: parser.c:49