aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/acidtypes/dwarf.c
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2004-04-21 02:02:47 +0000
committerrsc <devnull@localhost>2004-04-21 02:02:47 +0000
commit87a478a361877db7c4f904da527cb72d4eff6de2 (patch)
treee1a3512007cdb1ba91615ca63b75b4bd2376946e /src/cmd/acidtypes/dwarf.c
parente37302c4b99f147f1fd85ca27a2dbd2aa7a4eb41 (diff)
downloadplan9port-87a478a361877db7c4f904da527cb72d4eff6de2.tar.gz
plan9port-87a478a361877db7c4f904da527cb72d4eff6de2.tar.bz2
plan9port-87a478a361877db7c4f904da527cb72d4eff6de2.zip
Clean up the dwarf code a little and make
acidtypes handle gcc 3.3.3 binaries.
Diffstat (limited to 'src/cmd/acidtypes/dwarf.c')
-rw-r--r--src/cmd/acidtypes/dwarf.c261
1 files changed, 124 insertions, 137 deletions
diff --git a/src/cmd/acidtypes/dwarf.c b/src/cmd/acidtypes/dwarf.c
index f8c38685..3c53e849 100644
--- a/src/cmd/acidtypes/dwarf.c
+++ b/src/cmd/acidtypes/dwarf.c
@@ -6,6 +6,8 @@
#include <dwarf.h>
#include "dat.h"
+static void ds2acid(Dwarf*, DwarfSym*, Biobuf*, char*);
+
static ulong
valof(uint ty, DwarfVal *v)
{
@@ -32,162 +34,147 @@ xnewtype(uint ty, DwarfSym *s)
int
dwarf2acid(Dwarf *d, Biobuf *b)
{
- char *fn;
DwarfSym s;
- Type *t;
/* pass over dwarf section pulling out type info */
if(dwarfenum(d, &s) < 0)
return -1;
- while(dwarfnextsym(d, &s, s.depth!=1) == 1){
- top:
- switch(s.attrs.tag){
- case TagSubprogram:
- case TagLexDwarfBlock:
- dwarfnextsym(d, &s, 1);
- goto top;
-
- case TagTypedef:
- t = xnewtype(Typedef, &s);
- t->name = s.attrs.name;
- t->sub = typebynum(s.attrs.type, 0);
- break;
- case TagBaseType:
- t = xnewtype(Base, &s);
- t->xsizeof = s.attrs.bytesize;
- switch(s.attrs.encoding){
- default:
- case TypeAddress:
- t->printfmt = 'x';
- break;
- case TypeBoolean:
- case TypeUnsigned:
- case TypeSigned:
- case TypeSignedChar:
- case TypeUnsignedChar:
- t->printfmt = 'd';
- break;
- case TypeFloat:
- t->printfmt = 'f';
- break;
- case TypeComplexFloat:
- t->printfmt = 'F';
- break;
- case TypeImaginaryFloat:
- t->printfmt = 'i';
- break;
- }
- break;
- case TagPointerType:
- t = xnewtype(Pointer, &s);
- t->sub = typebynum(s.attrs.type, 0);
- break;
- case TagStructType:
- case TagUnionType:
- t = xnewtype(Aggr, &s);
- t->sue = s.attrs.tag==TagStructType ? 's' : 'u';
- t->xsizeof = s.attrs.bytesize;
- t->suename = s.attrs.name;
- t->isunion = s.attrs.tag==TagUnionType;
- dwarfnextsym(d, &s, 1);
- if(s.depth != 2)
- goto top;
- do{
- if(!s.attrs.have.name || !s.attrs.have.type || s.attrs.tag != TagMember)
- continue;
- if(t->n%32 == 0){
- t->tname = erealloc(t->tname, (t->n+32)*sizeof(t->tname[0]));
- t->val = erealloc(t->val, (t->n+32)*sizeof(t->val[0]));
- t->t = erealloc(t->t, (t->n+32)*sizeof(t->t[0]));
- }
- t->tname[t->n] = s.attrs.name;
- if(t->isunion)
- t->val[t->n] = 0;
- else
- t->val[t->n] = valof(s.attrs.have.datamemberloc, &s.attrs.datamemberloc);
- t->t[t->n] = typebynum(s.attrs.type, 0);
- t->n++;
- }while(dwarfnextsym(d, &s, 1) == 1 && s.depth==2);
- goto top;
+ while(dwarfnextsymat(d, &s, 0) == 1)
+ ds2acid(d, &s, b, nil);
+
+ printtypes(b);
+ dumpsyms(b);
+ freetypes();
+ return 0;
+}
+
+static void
+ds2acid(Dwarf *d, DwarfSym *s, Biobuf *b, char *fn)
+{
+ int depth;
+ Type *t;
+
+ depth = s->depth;
+
+ switch(s->attrs.tag){
+ case TagSubroutineType:
+ t = xnewtype(Function, s);
+ goto Recurse;
+
+ case TagSubprogram:
+ fn = s->attrs.name;
+ goto Recurse;
+
+ case TagCompileUnit:
+ case TagLexDwarfBlock:
+ Recurse:
+ /* recurse into substructure */
+ while(dwarfnextsymat(d, s, depth+1) == 1)
+ ds2acid(d, s, b, fn);
+ break;
+
+ case TagTypedef:
+ t = xnewtype(Typedef, s);
+ t->name = s->attrs.name;
+ t->sub = typebynum(s->attrs.type, 0);
+ break;
+
+ case TagBaseType:
+ t = xnewtype(Base, s);
+ t->xsizeof = s->attrs.bytesize;
+ switch(s->attrs.encoding){
+ default:
+ case TypeAddress:
+ t->printfmt = 'x';
break;
- case TagSubroutineType:
- t = xnewtype(Function, &s);
+ case TypeBoolean:
+ case TypeUnsigned:
+ case TypeSigned:
+ case TypeSignedChar:
+ case TypeUnsignedChar:
+ t->printfmt = 'd';
break;
- case TagConstType:
- case TagVolatileType:
- t = xnewtype(Defer, &s);
- t->sub = typebynum(s.attrs.type, 0);
+ case TypeFloat:
+ t->printfmt = 'f';
break;
- case TagArrayType:
- t = xnewtype(Array, &s);
- t->sub = typebynum(s.attrs.type, 0);
+ case TypeComplexFloat:
+ t->printfmt = 'F';
break;
- case TagEnumerationType:
- t = xnewtype(Enum, &s);
- t->sue = 'e';
- t->suename = s.attrs.name;
- t->xsizeof = s.attrs.bytesize;
- dwarfnextsym(d, &s, 1);
- if(s.depth != 2)
- goto top;
- do{
- if(!s.attrs.have.name || !s.attrs.have.constvalue || s.attrs.tag != TagEnumerator)
- continue;
- if(t->n%32 == 0){
- t->tname = erealloc(t->tname, (t->n+32)*sizeof(t->tname[0]));
- t->val = erealloc(t->val, (t->n+32)*sizeof(t->val[0]));
- }
- t->tname[t->n] = s.attrs.name;
- t->val[t->n] = valof(s.attrs.have.constvalue, &s.attrs.constvalue);
- t->n++;
- }while(dwarfnextsym(d, &s, 1) == 1 && s.depth==2);
- goto top;
+ case TypeImaginaryFloat:
+ t->printfmt = 'i';
break;
}
- }
+ break;
- printtypes(b);
+ case TagPointerType:
+ t = xnewtype(Pointer, s);
+ t->sub = typebynum(s->attrs.type, 0);
+ break;
- /* pass over dwarf section pulling out type definitions */
- if(dwarfenum(d, &s) < 0)
- goto out;
-
- fn = nil;
- while(dwarfnextsym(d, &s, 1) == 1){
- if(s.depth == 1)
- fn = nil;
- switch(s.attrs.tag){
- case TagSubprogram:
- fn = s.attrs.name;
- break;
- case TagFormalParameter:
- if(s.depth != 2)
- break;
- /* fall through */
- case TagVariable:
- if(s.attrs.name == nil || s.attrs.type == 0)
+ case TagConstType:
+ case TagVolatileType:
+ t = xnewtype(Defer, s);
+ t->sub = typebynum(s->attrs.type, 0);
+ break;
+
+ case TagArrayType:
+ t = xnewtype(Array, s);
+ t->sub = typebynum(s->attrs.type, 0);
+ break;
+
+ case TagStructType:
+ case TagUnionType:
+ t = xnewtype(Aggr, s);
+ t->sue = s->attrs.tag==TagStructType ? 's' : 'u';
+ t->xsizeof = s->attrs.bytesize;
+ t->suename = s->attrs.name;
+ t->isunion = s->attrs.tag==TagUnionType;
+ while(dwarfnextsymat(d, s, depth+1) == 1){
+ if(s->attrs.tag != TagMember){
+ ds2acid(d, s, b, fn);
continue;
- t = typebynum(s.attrs.type, 0);
- if(t->ty == Pointer){
- t = t->sub;
- if(t && t->equiv)
- t = t->equiv;
}
- if(t == nil)
- break;
- if(t->ty != Aggr)
- break;
- Bprint(b, "complex %s %s%s%s;\n", nameof(t, 1),
- fn ? fixname(fn) : "", fn ? ":" : "", fixname(s.attrs.name));
- break;
+ if(!s->attrs.have.name || !s->attrs.have.type)
+ continue;
+ if(t->n%32 == 0){
+ t->tname = erealloc(t->tname, (t->n+32)*sizeof(t->tname[0]));
+ t->val = erealloc(t->val, (t->n+32)*sizeof(t->val[0]));
+ t->t = erealloc(t->t, (t->n+32)*sizeof(t->t[0]));
+ }
+ t->tname[t->n] = s->attrs.name;
+ if(t->isunion)
+ t->val[t->n] = 0;
+ else
+ t->val[t->n] = valof(s->attrs.have.datamemberloc, &s->attrs.datamemberloc);
+ t->t[t->n] = typebynum(s->attrs.type, 0);
+ t->n++;
}
- }
+ break;
-out:
- freetypes();
- return 0;
+ case TagEnumerationType:
+ t = xnewtype(Enum, s);
+ t->sue = 'e';
+ t->suename = s->attrs.name;
+ t->xsizeof = s->attrs.bytesize;
+ while(dwarfnextsymat(d, s, depth+1) == 1){
+ if(s->attrs.tag != TagEnumerator){
+ ds2acid(d, s, b, fn);
+ continue;
+ }
+ if(!s->attrs.have.name || !s->attrs.have.constvalue)
+ continue;
+ if(t->n%32 == 0){
+ t->tname = erealloc(t->tname, (t->n+32)*sizeof(t->tname[0]));
+ t->val = erealloc(t->val, (t->n+32)*sizeof(t->val[0]));
+ }
+ t->tname[t->n] = s->attrs.name;
+ t->val[t->n] = valof(s->attrs.have.constvalue, &s->attrs.constvalue);
+ t->n++;
+ }
+ break;
+ }
}