Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendwarfdump.c
Go to the documentation of this file.
00001 #if 0 00002 #include <u.h> 00003 #include <libc.h> 00004 #include <bio.h> 00005 #include "elf.h" 00006 #endif 00007 #include "dwarf.h" 00008 #include "pe.h" 00009 00010 void printrules(Dwarf *d, ulong pc); 00011 //int exprfmt(Fmt*); 00012 00013 void 00014 usage(void) 00015 { 00016 fprint(2, "usage: dwarfdump file\n"); 00017 exits("usage"); 00018 } 00019 00020 void 00021 main(int argc, char **argv) 00022 { 00023 int c; 00024 Pe *pe; 00025 Dwarf *d; 00026 DwarfSym s; 00027 char *cdir, *dir, *file; 00028 ulong line, mtime, length; 00029 00030 if(argc != 2) 00031 usage(); 00032 00033 #if 0 00034 fmtinstall('R', exprfmt); 00035 fmtinstall('H', encodefmt); 00036 #endif 00037 00038 if((pe = peopen(argv[1])) == nil) 00039 sysfatal("elfopen %s: %r", argv[1]); 00040 if((d=dwarfopen(pe)) == nil) 00041 sysfatal("dwarfopen: %r"); 00042 00043 if(dwarfenum(d, &s) < 0) 00044 sysfatal("dwarfenumall: %r"); 00045 00046 while(dwarfnextsym(d, &s) == 1){ 00047 switch(s.attrs.tag){ 00048 case TagCompileUnit: 00049 print("compileunit %s\n", s.attrs.name); 00050 break; 00051 case TagSubprogram: 00052 c = 't'; 00053 goto sym; 00054 case TagVariable: 00055 c = 'd'; 00056 goto sym; 00057 case TagConstant: 00058 c = 'c'; 00059 goto sym; 00060 case TagFormalParameter: 00061 if(!s.attrs.name) 00062 break; 00063 c = 'p'; 00064 sym: 00065 if(s.attrs.isexternal) 00066 c += 'A' - 'a'; 00067 print("%c %s", c, s.attrs.name); 00068 if(s.attrs.have.lowpc) 00069 print(" 0x%lux-0x%lux", s.attrs.lowpc, s.attrs.highpc); 00070 switch(s.attrs.have.location){ 00071 case TBlock: 00072 print(" @ %.*H", s.attrs.location.b.len, s.attrs.location.b.data); 00073 break; 00074 case TConstant: 00075 print(" @ 0x%lux", s.attrs.location.c); 00076 break; 00077 } 00078 if(s.attrs.have.ranges) 00079 print(" ranges@0x%lux", s.attrs.ranges); 00080 print("\n"); 00081 if(s.attrs.have.lowpc){ 00082 if(dwarfpctoline(d, s.attrs.lowpc, &cdir, &dir, &file, &line, &mtime, &length) < 0) 00083 print("\tcould not find source: %r\n"); 00084 else if(dir == nil) 00085 print("\t%s/%s:%lud mtime=%lud length=%lud\n", 00086 cdir, file, line, mtime, length); 00087 else 00088 print("\t%s/%s/%s:%lud mtime=%lud length=%lud\n", 00089 cdir, dir, file, line, mtime, length); 00090 00091 if(0) printrules(d, s.attrs.lowpc); 00092 if(0) printrules(d, (s.attrs.lowpc+s.attrs.highpc)/2); 00093 } 00094 break; 00095 } 00096 } 00097 exits(0); 00098 } 00099 00100 void 00101 printrules(Dwarf *d, ulong pc) 00102 { 00103 int i; 00104 DwarfExpr r[10]; 00105 DwarfExpr cfa, ra; 00106 00107 if(dwarfunwind(d, pc, &cfa, &ra, r, nelem(r)) < 0) 00108 print("\tcannot unwind from pc 0x%lux: %r\n", pc); 00109 00110 print("\tpc=0x%lux cfa=%R ra=%R", pc, &cfa, &ra); 00111 for(i=0; i<nelem(r); i++) 00112 if(r[i].type != RuleSame) 00113 print(" r%d=%R", i, &r[i]); 00114 print("\n"); 00115 } 00116 00117 #if 0 00118 int 00119 exprfmt(Fmt *fmt) 00120 { 00121 DwarfExpr *e; 00122 00123 if((e = va_arg(fmt->args, DwarfExpr*)) == nil) 00124 return fmtstrcpy(fmt, "<nil>"); 00125 00126 switch(e->type){ 00127 case RuleUndef: 00128 return fmtstrcpy(fmt, "undef"); 00129 case RuleSame: 00130 return fmtstrcpy(fmt, "same"); 00131 case RuleCfaOffset: 00132 return fmtprint(fmt, "%ld(cfa)", e->offset); 00133 case RuleRegister: 00134 return fmtprint(fmt, "r%ld", e->reg); 00135 case RuleRegOff: 00136 return fmtprint(fmt, "%ld(r%ld)", e->offset, e->reg); 00137 case RuleLocation: 00138 return fmtprint(fmt, "l.%.*H", e->loc.len, e->loc.data); 00139 default: 00140 return fmtprint(fmt, "?%d", e->type); 00141 } 00142 } 00143 #endif Generated on Sun May 27 2012 04:36:17 for ReactOS by
1.7.6.1
|