URI:
       tdwarf.h - plan9port - [fork] Plan 9 from user space
  HTML git clone git://src.adamsgaard.dk/plan9port
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
       tdwarf.h (9434B)
       ---
            1 typedef struct Dwarf Dwarf;
            2 typedef struct DwarfAttrs DwarfAttrs;
            3 typedef struct DwarfBlock DwarfBlock;
            4 typedef struct DwarfBuf DwarfBuf;
            5 typedef struct DwarfExpr DwarfExpr;
            6 typedef struct DwarfSym DwarfSym;
            7 typedef union DwarfVal DwarfVal;
            8 
            9 enum
           10 {
           11         TagArrayType = 0x01,
           12         TagClassType = 0x02,
           13         TagEntryPoint = 0x03,
           14         TagEnumerationType = 0x04,
           15         TagFormalParameter = 0x05,
           16         TagImportedDeclaration = 0x08,
           17         TagLabel = 0x0A,
           18         TagLexDwarfBlock = 0x0B,
           19         TagMember = 0x0D,
           20         TagPointerType = 0x0F,
           21         TagReferenceType = 0x10,
           22         TagCompileUnit = 0x11,
           23         TagStringType = 0x12,
           24         TagStructType = 0x13,
           25         TagSubroutineType = 0x15,
           26         TagTypedef = 0x16,
           27         TagUnionType = 0x17,
           28         TagUnspecifiedParameters = 0x18,
           29         TagVariant = 0x19,
           30         TagCommonDwarfBlock = 0x1A,
           31         TagCommonInclusion = 0x1B,
           32         TagInheritance = 0x1C,
           33         TagInlinedSubroutine = 0x1D,
           34         TagModule = 0x1E,
           35         TagPtrToMemberType = 0x1F,
           36         TagSetType = 0x20,
           37         TagSubrangeType = 0x21,
           38         TagWithStmt = 0x22,
           39         TagAccessDeclaration = 0x23,
           40         TagBaseType = 0x24,
           41         TagCatchDwarfBlock = 0x25,
           42         TagConstType = 0x26,
           43         TagConstant = 0x27,
           44         TagEnumerator = 0x28,
           45         TagFileType = 0x29,
           46         TagFriend = 0x2A,
           47         TagNamelist = 0x2B,
           48         TagNamelistItem = 0x2C,
           49         TagPackedType = 0x2D,
           50         TagSubprogram = 0x2E,
           51         TagTemplateTypeParameter = 0x2F,
           52         TagTemplateValueParameter = 0x30,
           53         TagThrownType = 0x31,
           54         TagTryDwarfBlock = 0x32,
           55         TagVariantPart = 0x33,
           56         TagVariable = 0x34,
           57         TagVolatileType = 0x35,
           58         TagDwarfProcedure = 0x36,
           59         TagRestrictType = 0x37,
           60         TagInterfaceType = 0x38,
           61         TagNamespace = 0x39,
           62         TagImportedModule = 0x3A,
           63         TagUnspecifiedType = 0x3B,
           64         TagPartialUnit = 0x3C,
           65         TagImportedUnit = 0x3D,
           66         TagMutableType = 0x3E,
           67 
           68         TypeAddress = 0x01,
           69         TypeBoolean = 0x02,
           70         TypeComplexFloat = 0x03,
           71         TypeFloat = 0x04,
           72         TypeSigned = 0x05,
           73         TypeSignedChar = 0x06,
           74         TypeUnsigned = 0x07,
           75         TypeUnsignedChar = 0x08,
           76         TypeImaginaryFloat = 0x09,
           77 
           78         AccessPublic = 0x01,
           79         AccessProtected = 0x02,
           80         AccessPrivate = 0x03,
           81 
           82         VisLocal = 0x01,
           83         VisExported = 0x02,
           84         VisQualified = 0x03,
           85 
           86         VirtNone = 0x00,
           87         VirtVirtual = 0x01,
           88         VirtPureVirtual = 0x02,
           89 
           90         LangC89 = 0x0001,
           91         LangC = 0x0002,
           92         LangAda83 = 0x0003,
           93         LangCplusplus = 0x0004,
           94         LangCobol74 = 0x0005,
           95         LangCobol85 = 0x0006,
           96         LangFortran77 = 0x0007,
           97         LangFortran90 = 0x0008,
           98         LangPascal83 = 0x0009,
           99         LangModula2 = 0x000A,
          100         LangJava = 0x000B,
          101         LangC99 = 0x000C,
          102         LangAda95 = 0x000D,
          103         LangFortran95 = 0x000E,
          104         LangPLI = 0x000F,
          105         /* 0x8000-0xFFFF reserved */
          106 
          107         IdCaseSensitive = 0x00,
          108         IdCaseUpper = 0x01,
          109         IdCaseLower = 0x02,
          110         IdCaseInsensitive = 0x03,
          111 
          112         CallingNormal = 0x01,
          113         CallingProgram = 0x02,
          114         CallingNocall = 0x03,
          115         /* 0x40-0xFF reserved */
          116 
          117         InNone = 0x00,
          118         InInlined = 0x01,
          119         InDeclaredNotInlined = 0x02,
          120         InDeclaredInlined = 0x03,
          121 
          122         OrderRowMajor = 0x00,
          123         OrderColumnMajor = 0x01,
          124 
          125         DiscLabel = 0x00,
          126         DiscRange = 0x01,
          127 
          128         TReference = 1<<0,
          129         TBlock = 1<<1,
          130         TConstant = 1<<2,
          131         TString = 1<<3,
          132         TFlag = 1<<4,
          133         TAddress = 1<<5,
          134 
          135         OpAddr = 0x03,        /* 1 op, const addr */
          136         OpDeref = 0x06,
          137         OpConst1u = 0x08,        /* 1 op, 1 byte const */
          138         OpConst1s = 0x09,        /*        " signed */
          139         OpConst2u = 0x0A,        /* 1 op, 2 byte const  */
          140         OpConst2s = 0x0B,        /*        " signed */
          141         OpConst4u = 0x0C,        /* 1 op, 4 byte const */
          142         OpConst4s = 0x0D,        /*        " signed */
          143         OpConst8u = 0x0E,        /* 1 op, 8 byte const */
          144         OpConst8s = 0x0F,        /*        " signed */
          145         OpConstu = 0x10,        /* 1 op, LEB128 const */
          146         OpConsts = 0x11,        /*        " signed */
          147         OpDup = 0x12,
          148         OpDrop = 0x13,
          149         OpOver = 0x14,
          150         OpPick = 0x15,                /* 1 op, 1 byte stack index */
          151         OpSwap = 0x16,
          152         OpRot = 0x17,
          153         OpXderef = 0x18,
          154         OpAbs = 0x19,
          155         OpAnd = 0x1A,
          156         OpDiv = 0x1B,
          157         OpMinus = 0x1C,
          158         OpMod = 0x1D,
          159         OpMul = 0x1E,
          160         OpNeg = 0x1F,
          161         OpNot = 0x20,
          162         OpOr = 0x21,
          163         OpPlus = 0x22,
          164         OpPlusUconst = 0x23,        /* 1 op, ULEB128 addend */
          165         OpShl = 0x24,
          166         OpShr = 0x25,
          167         OpShra = 0x26,
          168         OpXor = 0x27,
          169         OpSkip = 0x2F,                /* 1 op, signed 2-byte constant */
          170         OpBra = 0x28,                /* 1 op, signed 2-byte constant */
          171         OpEq = 0x29,
          172         OpGe = 0x2A,
          173         OpGt = 0x2B,
          174         OpLe = 0x2C,
          175         OpLt = 0x2D,
          176         OpNe = 0x2E,
          177         OpLit0 = 0x30,
          178                 /* OpLitN = OpLit0 + N for N = 0..31 */
          179         OpReg0 = 0x50,
          180                 /* OpRegN = OpReg0 + N for N = 0..31 */
          181         OpBreg0 = 0x70,        /* 1 op, signed LEB128 constant */
          182                 /* OpBregN = OpBreg0 + N for N = 0..31 */
          183         OpRegx = 0x90,        /* 1 op, ULEB128 register */
          184         OpFbreg = 0x91,        /* 1 op, SLEB128 offset */
          185         OpBregx = 0x92,        /* 2 op, ULEB128 reg, SLEB128 off */
          186         OpPiece = 0x93,        /* 1 op, ULEB128 size of piece */
          187         OpDerefSize = 0x94,        /* 1-byte size of data retrieved */
          188         OpXderefSize = 0x95,        /* 1-byte size of data retrieved */
          189         OpNop = 0x96,
          190         /* next four new in Dwarf v3 */
          191         OpPushObjAddr = 0x97,
          192         OpCall2 = 0x98,        /* 2-byte offset of DIE */
          193         OpCall4 = 0x99,        /* 4-byte offset of DIE */
          194         OpCallRef = 0x9A        /* 4- or 8- byte offset of DIE */
          195         /* 0xE0-0xFF reserved for user-specific */
          196 };
          197 
          198 struct DwarfBlock
          199 {
          200         uchar *data;
          201         ulong len;
          202 };
          203 
          204 /* not for consumer use */
          205 struct DwarfBuf
          206 {
          207         Dwarf *d;
          208         uchar *p;
          209         uchar *ep;
          210         uint addrsize;
          211 };
          212 
          213 union DwarfVal
          214 {
          215         char *s;
          216         ulong c;
          217         ulong r;
          218         DwarfBlock b;
          219 };
          220 
          221 struct DwarfAttrs
          222 {
          223         ulong        tag;
          224         uchar        haskids;
          225 
          226         /* whether we have it, along with type */
          227         struct {
          228                 uchar        abstractorigin;
          229                 uchar        accessibility;
          230                 uchar        addrclass;
          231                 uchar        basetypes;
          232                 uchar        bitoffset;
          233                 uchar        bitsize;
          234                 uchar        bytesize;
          235                 uchar        calling;
          236                 uchar        commonref;
          237                 uchar        compdir;
          238                 uchar        constvalue;
          239                 uchar        containingtype;
          240                 uchar        count;
          241                 uchar        datamemberloc;
          242                 uchar        declcolumn;
          243                 uchar        declfile;
          244                 uchar        declline;
          245                 uchar        defaultvalue;
          246                 uchar        discr;
          247                 uchar        discrlist;
          248                 uchar        discrvalue;
          249                 uchar        encoding;
          250                 uchar        framebase;
          251                 uchar        friend;
          252                 uchar        highpc;
          253                 uchar        identifiercase;
          254                 uchar        import;
          255                 uchar        inlined;
          256                 uchar        isartificial;
          257                 uchar        isdeclaration;
          258                 uchar        isexternal;
          259                 uchar        isoptional;
          260                 uchar        isprototyped;
          261                 uchar        isvarparam;
          262                 uchar        language;
          263                 uchar        location;
          264                 uchar        lowerbound;
          265                 uchar        lowpc;
          266                 uchar        macroinfo;
          267                 uchar        name;
          268                 uchar        namelistitem;
          269                 uchar        ordering;
          270                 uchar        priority;
          271                 uchar        producer;
          272                 uchar        ranges;
          273                 uchar        returnaddr;
          274                 uchar        segment;
          275                 uchar        sibling;
          276                 uchar        specification;
          277                 uchar        startscope;
          278                 uchar        staticlink;
          279                 uchar        stmtlist;
          280                 uchar        stridesize;
          281                 uchar        stringlength;
          282                 uchar        type;
          283                 uchar        upperbound;
          284                 uchar        uselocation;
          285                 uchar        virtuality;
          286                 uchar        visibility;
          287                 uchar        vtableelemloc;
          288         } have;
          289 
          290         ulong        abstractorigin;
          291         ulong        accessibility;
          292         ulong        addrclass;
          293         ulong        basetypes;
          294         ulong        bitoffset;
          295         ulong        bitsize;
          296         ulong        bytesize;
          297         ulong        calling;
          298         ulong        commonref;
          299         char*        compdir;
          300         DwarfVal        constvalue;
          301         ulong        containingtype;
          302         ulong        count;
          303         DwarfVal        datamemberloc;
          304         ulong        declcolumn;
          305         ulong        declfile;
          306         ulong        declline;
          307         ulong        defaultvalue;
          308         ulong        discr;
          309         DwarfBlock        discrlist;
          310         ulong        discrvalue;
          311         ulong        encoding;
          312         DwarfVal        framebase;
          313         ulong        friend;
          314         ulong        highpc;
          315         ulong        identifiercase;
          316         ulong        import;
          317         ulong        inlined;
          318         uchar        isartificial;
          319         uchar        isdeclaration;
          320         uchar        isexternal;
          321         uchar        isoptional;
          322         uchar        isprototyped;
          323         uchar        isvarparam;
          324         ulong        language;
          325         DwarfVal        location;
          326         ulong        lowerbound;
          327         ulong        lowpc;
          328         ulong        macroinfo;
          329         char*        name;
          330         DwarfBlock        namelistitem;
          331         ulong        ordering;
          332         ulong        priority;
          333         char*        producer;
          334         ulong        ranges;
          335         DwarfVal        returnaddr;
          336         DwarfVal        segment;
          337         ulong        sibling;
          338         ulong        specification;
          339         ulong        startscope;
          340         DwarfVal        staticlink;
          341         ulong        stmtlist;
          342         ulong        stridesize;
          343         DwarfVal        stringlength;
          344         ulong        type;
          345         ulong        upperbound;
          346         DwarfVal        uselocation;
          347         ulong        virtuality;
          348         ulong        visibility;
          349         DwarfVal        vtableelemloc;
          350 };
          351 
          352 enum
          353 {
          354         RuleUndef,
          355         RuleSame,
          356         RuleCfaOffset,
          357         RuleRegister,
          358         RuleRegOff,
          359         RuleLocation
          360 };
          361 struct DwarfExpr
          362 {
          363         int type;
          364         long offset;
          365         ulong reg;
          366         DwarfBlock loc;
          367 };
          368 
          369 struct DwarfSym
          370 {
          371         DwarfAttrs attrs;
          372 
          373 /* not for consumer use... */
          374         DwarfBuf b;
          375         ulong unit;
          376         uint uoff;
          377         ulong aoff;
          378         int depth;
          379         int allunits;
          380         ulong nextunit;
          381 };
          382 
          383 
          384 Dwarf *dwarfopen(Elf *elf);
          385 void dwarfclose(Dwarf*);
          386 int dwarfaddrtounit(Dwarf*, ulong, ulong*);
          387 int dwarflookupfn(Dwarf*, ulong, ulong, DwarfSym*);
          388 int dwarflookupname(Dwarf*, char*, DwarfSym*);
          389 int dwarflookupnameinunit(Dwarf*, ulong, char*, DwarfSym*);
          390 int dwarflookupsubname(Dwarf*, DwarfSym*, char*, DwarfSym*);
          391 int dwarflookuptag(Dwarf*, ulong, ulong, DwarfSym*);
          392 int dwarfenumunit(Dwarf*, ulong, DwarfSym*);
          393 int dwarfseeksym(Dwarf*, ulong, ulong, DwarfSym*);
          394 int dwarfenum(Dwarf*, DwarfSym*);
          395 int dwarfnextsym(Dwarf*, DwarfSym*);
          396 int dwarfnextsymat(Dwarf*, DwarfSym*, int);
          397 int dwarfpctoline(Dwarf*, ulong, char**, char**, char**, ulong*, ulong*, ulong*);
          398 int dwarfunwind(Dwarf*, ulong, DwarfExpr*, DwarfExpr*, DwarfExpr*, int);
          399 ulong dwarfget1(DwarfBuf*);
          400 ulong dwarfget2(DwarfBuf*);
          401 ulong dwarfget4(DwarfBuf*);
          402 uvlong dwarfget8(DwarfBuf*);
          403 ulong dwarfget128(DwarfBuf*);
          404 long dwarfget128s(DwarfBuf*);
          405 ulong dwarfgetaddr(DwarfBuf*);
          406 int dwarfgetn(DwarfBuf*, uchar*, int);
          407 uchar *dwarfgetnref(DwarfBuf*, ulong);
          408 char *dwarfgetstring(DwarfBuf*);
          409 
          410 
          411 typedef struct DwarfAbbrev DwarfAbbrev;
          412 typedef struct DwarfAttr DwarfAttr;
          413 
          414 struct DwarfAttr
          415 {
          416         ulong name;
          417         ulong form;
          418 };
          419 
          420 struct DwarfAbbrev
          421 {
          422         ulong num;
          423         ulong tag;
          424         uchar haskids;
          425         DwarfAttr *attr;
          426         int nattr;
          427 };
          428 
          429 struct Dwarf
          430 {
          431         Elf *elf;
          432         int fd;
          433         char **reg;
          434         int nreg;
          435         int addrsize;
          436         DwarfBlock abbrev;
          437         DwarfBlock aranges;
          438         DwarfBlock frame;
          439         DwarfBlock info;
          440         DwarfBlock line;
          441         DwarfBlock pubnames;
          442         DwarfBlock pubtypes;
          443         DwarfBlock ranges;
          444         DwarfBlock str;
          445 
          446         /* little cache */
          447         struct {
          448                 DwarfAbbrev *a;
          449                 int na;
          450                 ulong off;
          451         } acache;
          452 };
          453 
          454 DwarfAbbrev *dwarfgetabbrev(Dwarf*, ulong, ulong);
          455 
          456 int dwarfgetinfounit(Dwarf*, ulong, DwarfBlock*);
          457 
          458 extern int dwarf386nregs;
          459 extern char *dwarf386regs[];
          460 extern char *dwarf386fp;