Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendwarfabbrev.c
Go to the documentation of this file.
00001 /* 00002 * Dwarf abbreviation parsing code. 00003 * 00004 * The convention here is that calling dwarfgetabbrevs relinquishes 00005 * access to any abbrevs returned previously. Will have to add 00006 * explicit reference counting if this turns out not to be acceptable. 00007 */ 00008 00009 #include <precomp.h> 00010 00011 #define NDEBUG 00012 #include <debug.h> 00013 00014 static int parseabbrevs(Dwarf*, ulong, DwarfAbbrev*, DwarfAttr*, int*, int*); 00015 DwarfAbbrev *dwarfgetabbrev(Dwarf*, ulong, ulong); 00016 00017 static int 00018 loadabbrevs(Dwarf *d, ulong off, DwarfAbbrev **aa) 00019 { 00020 int nattr, nabbrev; 00021 DwarfAbbrev *abbrev; 00022 DwarfAttr *attr; 00023 00024 if(d->acache.off == off && d->acache.na){ 00025 *aa = d->acache.a; 00026 return d->acache.na; 00027 } 00028 00029 /* two passes - once to count, then allocate, then a second to copy */ 00030 if(parseabbrevs(d, off, nil, nil, &nabbrev, &nattr) < 0) { 00031 return -1; 00032 } 00033 00034 abbrev = malloc(nabbrev*sizeof(DwarfAbbrev) + nattr*sizeof(DwarfAttr)); 00035 attr = (DwarfAttr*)(abbrev+nabbrev); 00036 00037 if(parseabbrevs(d, off, abbrev, attr, nil, nil) < 0){ 00038 free(abbrev); 00039 return -1; 00040 } 00041 00042 free(d->acache.a); 00043 d->acache.a = abbrev; 00044 d->acache.na = nabbrev; 00045 d->acache.off = off; 00046 00047 *aa = abbrev; 00048 return nabbrev; 00049 } 00050 00051 static int 00052 parseabbrevs(Dwarf *d, ulong off, DwarfAbbrev *abbrev, DwarfAttr *attr, int *pnabbrev, int *pnattr) 00053 { 00054 int i, nabbrev, nattr, haskids; 00055 ulong num, tag, name, form; 00056 DwarfBuf b; 00057 00058 if(off >= d->abbrev.len){ 00059 werrstr("bad abbrev section offset 0x%lux >= 0x%lux", off, d->abbrev.len); 00060 return -1; 00061 } 00062 00063 memset(&b, 0, sizeof b); 00064 b.p = d->abbrev.data + off; 00065 b.ep = d->abbrev.data + d->abbrev.len; 00066 00067 nabbrev = 0; 00068 nattr = 0; 00069 for(;;){ 00070 if(b.p == nil){ 00071 werrstr("malformed abbrev data"); 00072 return -1; 00073 } 00074 num = dwarfget128(&b); 00075 if(num == 0) 00076 break; 00077 tag = dwarfget128(&b); 00078 werrstr("abbrev: num %d tag %x @ %x", num, tag, b.p - d->abbrev.data); 00079 haskids = dwarfget1(&b); 00080 for(i=0;; i++){ 00081 name = dwarfget128(&b); 00082 form = dwarfget128(&b); 00083 assert(form < 0x3000); 00084 if(name == 0 && form == 0) 00085 break; 00086 if(attr){ 00087 attr[i].name = name; 00088 attr[i].form = form; 00089 } 00090 } 00091 if(abbrev){ 00092 abbrev->num = num; 00093 abbrev->tag = tag; 00094 abbrev->haskids = haskids; 00095 abbrev->attr = attr; 00096 abbrev->nattr = i; 00097 abbrev++; 00098 attr += i; 00099 } 00100 nabbrev++; 00101 nattr += i; 00102 } 00103 if(pnabbrev) 00104 *pnabbrev = nabbrev; 00105 if(pnattr) 00106 *pnattr = nattr; 00107 return 0; 00108 } 00109 00110 static DwarfAbbrev* 00111 findabbrev(DwarfAbbrev *a, int na, ulong num) 00112 { 00113 int i; 00114 00115 for(i=0; i<na; i++) { 00116 if(a[i].num == num) { 00117 return &a[i]; 00118 } 00119 } 00120 werrstr("abbrev not found (%x)", na); 00121 return nil; 00122 } 00123 00124 DwarfAbbrev* 00125 dwarfgetabbrev(Dwarf *d, ulong off, ulong num) 00126 { 00127 DwarfAbbrev *a; 00128 int na; 00129 werrstr("want num %d\n", num); 00130 if((na = loadabbrevs(d, off, &a)) < 0){ 00131 werrstr("loadabbrevs: %r"); 00132 return nil; 00133 } 00134 return findabbrev(a, na, num); 00135 } 00136 Generated on Sun May 27 2012 04:36:16 for ReactOS by
1.7.6.1
|