00001 #include "compat.h"
00002
00003 typedef struct Dwarf Dwarf;
00004 typedef struct DwarfAttrs DwarfAttrs;
00005 typedef struct DwarfBlock DwarfBlock;
00006 typedef struct DwarfBuf DwarfBuf;
00007 typedef struct DwarfExpr DwarfExpr;
00008 typedef struct DwarfSym DwarfSym;
00009 typedef union DwarfVal DwarfVal;
00010
00011 enum
00012 {
00013 TagArrayType = 0x01,
00014 TagClassType = 0x02,
00015 TagEntryPoint = 0x03,
00016 TagEnumerationType = 0x04,
00017 TagFormalParameter = 0x05,
00018 TagImportedDeclaration = 0x08,
00019 TagLabel = 0x0A,
00020 TagLexDwarfBlock = 0x0B,
00021 TagMember = 0x0D,
00022 TagPointerType = 0x0F,
00023 TagReferenceType = 0x10,
00024 TagCompileUnit = 0x11,
00025 TagStringType = 0x12,
00026 TagStructType = 0x13,
00027 TagSubroutineType = 0x15,
00028 TagTypedef = 0x16,
00029 TagUnionType = 0x17,
00030 TagUnspecifiedParameters = 0x18,
00031 TagVariant = 0x19,
00032 TagCommonDwarfBlock = 0x1A,
00033 TagCommonInclusion = 0x1B,
00034 TagInheritance = 0x1C,
00035 TagInlinedSubroutine = 0x1D,
00036 TagModule = 0x1E,
00037 TagPtrToMemberType = 0x1F,
00038 TagSetType = 0x20,
00039 TagSubrangeType = 0x21,
00040 TagWithStmt = 0x22,
00041 TagAccessDeclaration = 0x23,
00042 TagBaseType = 0x24,
00043 TagCatchDwarfBlock = 0x25,
00044 TagConstType = 0x26,
00045 TagConstant = 0x27,
00046 TagEnumerator = 0x28,
00047 TagFileType = 0x29,
00048 TagFriend = 0x2A,
00049 TagNamelist = 0x2B,
00050 TagNamelistItem = 0x2C,
00051 TagPackedType = 0x2D,
00052 TagSubprogram = 0x2E,
00053 TagTemplateTypeParameter = 0x2F,
00054 TagTemplateValueParameter = 0x30,
00055 TagThrownType = 0x31,
00056 TagTryDwarfBlock = 0x32,
00057 TagVariantPart = 0x33,
00058 TagVariable = 0x34,
00059 TagVolatileType = 0x35,
00060 TagDwarfProcedure = 0x36,
00061 TagRestrictType = 0x37,
00062 TagInterfaceType = 0x38,
00063 TagNamespace = 0x39,
00064 TagImportedModule = 0x3A,
00065 TagUnspecifiedType = 0x3B,
00066 TagPartialUnit = 0x3C,
00067 TagImportedUnit = 0x3D,
00068 TagMutableType = 0x3E,
00069
00070 TypeAddress = 0x01,
00071 TypeBoolean = 0x02,
00072 TypeComplexFloat = 0x03,
00073 TypeFloat = 0x04,
00074 TypeSigned = 0x05,
00075 TypeSignedChar = 0x06,
00076 TypeUnsigned = 0x07,
00077 TypeUnsignedChar = 0x08,
00078 TypeImaginaryFloat = 0x09,
00079
00080 AccessPublic = 0x01,
00081 AccessProtected = 0x02,
00082 AccessPrivate = 0x03,
00083
00084 VisLocal = 0x01,
00085 VisExported = 0x02,
00086 VisQualified = 0x03,
00087
00088 VirtNone = 0x00,
00089 VirtVirtual = 0x01,
00090 VirtPureVirtual = 0x02,
00091
00092 LangC89 = 0x0001,
00093 LangC = 0x0002,
00094 LangAda83 = 0x0003,
00095 LangCplusplus = 0x0004,
00096 LangCobol74 = 0x0005,
00097 LangCobol85 = 0x0006,
00098 LangFortran77 = 0x0007,
00099 LangFortran90 = 0x0008,
00100 LangPascal83 = 0x0009,
00101 LangModula2 = 0x000A,
00102 LangJava = 0x000B,
00103 LangC99 = 0x000C,
00104 LangAda95 = 0x000D,
00105 LangFortran95 = 0x000E,
00106 LangPLI = 0x000F,
00107
00108
00109 IdCaseSensitive = 0x00,
00110 IdCaseUpper = 0x01,
00111 IdCaseLower = 0x02,
00112 IdCaseInsensitive = 0x03,
00113
00114 CallingNormal = 0x01,
00115 CallingProgram = 0x02,
00116 CallingNocall = 0x03,
00117
00118
00119 InNone = 0x00,
00120 InInlined = 0x01,
00121 InDeclaredNotInlined = 0x02,
00122 InDeclaredInlined = 0x03,
00123
00124 OrderRowMajor = 0x00,
00125 OrderColumnMajor = 0x01,
00126
00127 DiscLabel = 0x00,
00128 DiscRange = 0x01,
00129
00130 TReference = 1<<0,
00131 TBlock = 1<<1,
00132 TConstant = 1<<2,
00133 TString = 1<<3,
00134 TFlag = 1<<4,
00135 TAddress = 1<<5,
00136
00137 OpAddr = 0x03,
00138 OpDeref = 0x06,
00139 OpConst1u = 0x08,
00140 OpConst1s = 0x09,
00141 OpConst2u = 0x0A,
00142 OpConst2s = 0x0B,
00143 OpConst4u = 0x0C,
00144 OpConst4s = 0x0D,
00145 OpConst8u = 0x0E,
00146 OpConst8s = 0x0F,
00147 OpConstu = 0x10,
00148 OpConsts = 0x11,
00149 OpDup = 0x12,
00150 OpDrop = 0x13,
00151 OpOver = 0x14,
00152 OpPick = 0x15,
00153 OpSwap = 0x16,
00154 OpRot = 0x17,
00155 OpXderef = 0x18,
00156 OpAbs = 0x19,
00157 OpAnd = 0x1A,
00158 OpDiv = 0x1B,
00159 OpMinus = 0x1C,
00160 OpMod = 0x1D,
00161 OpMul = 0x1E,
00162 OpNeg = 0x1F,
00163 OpNot = 0x20,
00164 OpOr = 0x21,
00165 OpPlus = 0x22,
00166 OpPlusUconst = 0x23,
00167 OpShl = 0x24,
00168 OpShr = 0x25,
00169 OpShra = 0x26,
00170 OpXor = 0x27,
00171 OpSkip = 0x2F,
00172 OpBra = 0x28,
00173 OpEq = 0x29,
00174 OpGe = 0x2A,
00175 OpGt = 0x2B,
00176 OpLe = 0x2C,
00177 OpLt = 0x2D,
00178 OpNe = 0x2E,
00179 OpLit0 = 0x30,
00180
00181 OpReg0 = 0x50,
00182
00183 OpBreg0 = 0x70,
00184
00185 OpRegx = 0x90,
00186 OpFbreg = 0x91,
00187 OpBregx = 0x92,
00188 OpPiece = 0x93,
00189 OpDerefSize = 0x94,
00190 OpXderefSize = 0x95,
00191 OpNop = 0x96,
00192
00193 OpPushObjAddr = 0x97,
00194 OpCall2 = 0x98,
00195 OpCall4 = 0x99,
00196 OpCallRef = 0x9A
00197
00198 };
00199
00200 struct DwarfBlock
00201 {
00202 uchar *data;
00203 ulong len;
00204 };
00205
00206
00207 struct DwarfBuf
00208 {
00209 Dwarf *d;
00210 uchar *p;
00211 uchar *ep;
00212 uint addrsize;
00213 };
00214
00215 union DwarfVal
00216 {
00217 char *s;
00218 ulong c;
00219 ulong r;
00220 DwarfBlock b;
00221 };
00222
00223 struct DwarfAttrs
00224 {
00225 ulong tag;
00226 uchar haskids;
00227
00228
00229 struct {
00230 uchar abstractorigin;
00231 uchar accessibility;
00232 uchar addrclass;
00233 uchar basetypes;
00234 uchar bitoffset;
00235 uchar bitsize;
00236 uchar bytesize;
00237 uchar calling;
00238 uchar commonref;
00239 uchar compdir;
00240 uchar constvalue;
00241 uchar containingtype;
00242 uchar count;
00243 uchar datamemberloc;
00244 uchar declcolumn;
00245 uchar declfile;
00246 uchar declline;
00247 uchar defaultvalue;
00248 uchar discr;
00249 uchar discrlist;
00250 uchar discrvalue;
00251 uchar encoding;
00252 uchar framebase;
00253 uchar friend;
00254 uchar highpc;
00255 uchar entrypc;
00256 uchar identifiercase;
00257 uchar import;
00258 uchar inlined;
00259 uchar isartificial;
00260 uchar isdeclaration;
00261 uchar isexternal;
00262 uchar isoptional;
00263 uchar isprototyped;
00264 uchar isvarparam;
00265 uchar language;
00266 uchar location;
00267 uchar lowerbound;
00268 uchar lowpc;
00269 uchar macroinfo;
00270 uchar name;
00271 uchar namelistitem;
00272 uchar ordering;
00273 uchar priority;
00274 uchar producer;
00275 uchar ranges;
00276 uchar returnaddr;
00277 uchar segment;
00278 uchar sibling;
00279 uchar specification;
00280 uchar startscope;
00281 uchar staticlink;
00282 uchar stmtlist;
00283 uchar stridesize;
00284 uchar stringlength;
00285 uchar type;
00286 uchar upperbound;
00287 uchar uselocation;
00288 uchar virtuality;
00289 uchar visibility;
00290 uchar vtableelemloc;
00291 } have;
00292
00293 ulong abstractorigin;
00294 ulong accessibility;
00295 ulong addrclass;
00296 ulong basetypes;
00297 ulong bitoffset;
00298 ulong bitsize;
00299 ulong bytesize;
00300 ulong calling;
00301 ulong commonref;
00302 char* compdir;
00303 DwarfVal constvalue;
00304 ulong containingtype;
00305 ulong count;
00306 DwarfVal datamemberloc;
00307 ulong declcolumn;
00308 ulong declfile;
00309 ulong declline;
00310 ulong defaultvalue;
00311 ulong discr;
00312 DwarfBlock discrlist;
00313 ulong discrvalue;
00314 ulong encoding;
00315 DwarfVal framebase;
00316 ulong friend;
00317 ulong highpc;
00318 ulong entrypc;
00319 ulong identifiercase;
00320 ulong import;
00321 ulong inlined;
00322 uchar isartificial;
00323 uchar isdeclaration;
00324 uchar isexternal;
00325 uchar isoptional;
00326 uchar isprototyped;
00327 uchar isvarparam;
00328 ulong language;
00329 DwarfVal location;
00330 ulong lowerbound;
00331 ulong lowpc;
00332 ulong macroinfo;
00333 char* name;
00334 DwarfBlock namelistitem;
00335 ulong ordering;
00336 ulong priority;
00337 char* producer;
00338 ulong ranges;
00339 DwarfVal returnaddr;
00340 DwarfVal segment;
00341 ulong sibling;
00342 ulong specification;
00343 ulong startscope;
00344 DwarfVal staticlink;
00345 ulong stmtlist;
00346 ulong stridesize;
00347 DwarfVal stringlength;
00348 ulong type;
00349 ulong upperbound;
00350 DwarfVal uselocation;
00351 ulong virtuality;
00352 ulong visibility;
00353 DwarfVal vtableelemloc;
00354 };
00355
00356 enum
00357 {
00358 RuleUndef,
00359 RuleSame,
00360 RuleCfaOffset,
00361 RuleRegister,
00362 RuleRegOff,
00363 RuleLocation
00364 };
00365 struct DwarfExpr
00366 {
00367 int type;
00368 long offset;
00369 ulong reg;
00370 DwarfBlock loc;
00371 };
00372
00373 struct DwarfSym
00374 {
00375 DwarfAttrs attrs;
00376
00377
00378 DwarfBuf b;
00379 ulong unit;
00380 uint uoff;
00381 ulong aoff;
00382 int depth;
00383 int allunits;
00384 ulong nextunit;
00385 };
00386
00387
00388 struct _Pe;
00389 Dwarf *dwarfopen(struct _Pe *elf);
00390 void dwarfclose(Dwarf*);
00391 int dwarfaddrtounit(Dwarf*, ulong, ulong*);
00392 int dwarflookupfn(Dwarf*, ulong, ulong, DwarfSym*);
00393 int dwarflookupname(Dwarf*, char*, DwarfSym*);
00394 int dwarflookupnameinunit(Dwarf*, ulong, char*, DwarfSym*);
00395 int dwarflookupsubname(Dwarf*, DwarfSym*, char*, DwarfSym*);
00396 int dwarflookuptag(Dwarf*, ulong, ulong, DwarfSym*);
00397 int dwarfenumunit(Dwarf*, ulong, DwarfSym*);
00398 int dwarfseeksym(Dwarf*, ulong, ulong, DwarfSym*);
00399 int dwarfenum(Dwarf*, DwarfSym*);
00400 int dwarfnextsym(Dwarf*, DwarfSym*);
00401 int dwarfnextsymat(Dwarf*, DwarfSym*, int);
00402 int dwarfpctoline(Dwarf*, ulong, char**, char**, char**, char **, ulong*, ulong*, ulong*);
00403 int dwarfunwind(Dwarf*, ulong, DwarfExpr*, DwarfExpr*, DwarfExpr*, int);
00404 ulong dwarfget1(DwarfBuf*);
00405 ulong dwarfget2(DwarfBuf*);
00406 ulong dwarfget4(DwarfBuf*);
00407 uvlong dwarfget8(DwarfBuf*);
00408 ulong dwarfget128(DwarfBuf*);
00409 long dwarfget128s(DwarfBuf*);
00410 ulong dwarfgetaddr(DwarfBuf*);
00411 int dwarfgetn(DwarfBuf*, uchar*, int);
00412 uchar *dwarfgetnref(DwarfBuf*, ulong);
00413 char *dwarfgetstring(DwarfBuf*);
00414
00415
00416 typedef struct DwarfAbbrev DwarfAbbrev;
00417 typedef struct DwarfAttr DwarfAttr;
00418
00419 struct DwarfAttr
00420 {
00421 ulong name;
00422 ulong form;
00423 };
00424
00425 struct DwarfAbbrev
00426 {
00427 ulong num;
00428 ulong tag;
00429 uchar haskids;
00430 DwarfAttr *attr;
00431 int nattr;
00432 };
00433
00434 struct _Pe;
00435
00436 struct Dwarf
00437 {
00438 struct _Pe *pe;
00439
00440 char **reg;
00441 int nreg;
00442 int addrsize;
00443 DwarfBlock abbrev;
00444 DwarfBlock aranges;
00445 DwarfBlock frame;
00446 DwarfBlock info;
00447 DwarfBlock line;
00448 DwarfBlock pubnames;
00449 DwarfBlock pubtypes;
00450 DwarfBlock ranges;
00451 DwarfBlock str;
00452
00453
00454 struct {
00455 DwarfAbbrev *a;
00456 int na;
00457 ulong off;
00458 } acache;
00459 };
00460
00461 DwarfAbbrev *dwarfgetabbrev(Dwarf*, ulong, ulong);
00462
00463 int dwarfgetinfounit(Dwarf*, ulong, DwarfBlock*);
00464
00465 extern int dwarf386nregs;
00466 extern char *dwarf386regs[];
00467 extern char *dwarf386fp;
00468
00469 #define SYMBOL_SIZE 18
00470 #define MAXIMUM_DWARF_NAME_SIZE 64
00471 #define MAXIMUM_COFF_SYMBOL_LENGTH 256