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