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 #define NTOSAPI 00010 #include <ntddk.h> 00011 #include <reactos/rossym.h> 00012 #include "rossympriv.h" 00013 #include <ntimage.h> 00014 00015 #define NDEBUG 00016 #include <debug.h> 00017 00018 #include "rossym.h" 00019 #include "rossympriv.h" 00020 #include "dwarf.h" 00021 00022 static int parseabbrevs(Dwarf*, ulong, DwarfAbbrev*, DwarfAttr*, int*, int*); 00023 DwarfAbbrev *dwarfgetabbrev(Dwarf*, ulong, ulong); 00024 00025 static int 00026 loadabbrevs(Dwarf *d, ulong off, DwarfAbbrev **aa) 00027 { 00028 int nattr, nabbrev; 00029 DwarfAbbrev *abbrev; 00030 DwarfAttr *attr; 00031 00032 if(d->acache.off == off && d->acache.na){ 00033 *aa = d->acache.a; 00034 return d->acache.na; 00035 } 00036 00037 /* two passes - once to count, then allocate, then a second to copy */ 00038 if(parseabbrevs(d, off, nil, nil, &nabbrev, &nattr) < 0) { 00039 return -1; 00040 } 00041 00042 abbrev = malloc(nabbrev*sizeof(DwarfAbbrev) + nattr*sizeof(DwarfAttr)); 00043 attr = (DwarfAttr*)(abbrev+nabbrev); 00044 00045 if(parseabbrevs(d, off, abbrev, attr, nil, nil) < 0){ 00046 free(abbrev); 00047 return -1; 00048 } 00049 00050 free(d->acache.a); 00051 d->acache.a = abbrev; 00052 d->acache.na = nabbrev; 00053 d->acache.off = off; 00054 00055 *aa = abbrev; 00056 return nabbrev; 00057 } 00058 00059 static int 00060 parseabbrevs(Dwarf *d, ulong off, DwarfAbbrev *abbrev, DwarfAttr *attr, int *pnabbrev, int *pnattr) 00061 { 00062 int i, nabbrev, nattr, haskids; 00063 ulong num, tag, name, form; 00064 DwarfBuf b; 00065 00066 if(off >= d->abbrev.len){ 00067 werrstr("bad abbrev section offset 0x%lux >= 0x%lux\n", off, d->abbrev.len); 00068 return -1; 00069 } 00070 00071 memset(&b, 0, sizeof b); 00072 b.p = d->abbrev.data + off; 00073 b.ep = d->abbrev.data + d->abbrev.len; 00074 00075 nabbrev = 0; 00076 nattr = 0; 00077 for(;;){ 00078 if(b.p == nil){ 00079 werrstr("malformed abbrev data"); 00080 return -1; 00081 } 00082 num = dwarfget128(&b); 00083 if(num == 0) 00084 break; 00085 tag = dwarfget128(&b); 00086 haskids = dwarfget1(&b); 00087 for(i=0;; i++){ 00088 name = dwarfget128(&b); 00089 form = dwarfget128(&b); 00090 if(name == 0 && form == 0) 00091 break; 00092 if(attr){ 00093 attr[i].name = name; 00094 attr[i].form = form; 00095 } 00096 } 00097 if(abbrev){ 00098 abbrev->num = num; 00099 abbrev->tag = tag; 00100 abbrev->haskids = haskids; 00101 abbrev->attr = attr; 00102 abbrev->nattr = i; 00103 abbrev++; 00104 attr += i; 00105 } 00106 nabbrev++; 00107 nattr += i; 00108 } 00109 if(pnabbrev) 00110 *pnabbrev = nabbrev; 00111 if(pnattr) 00112 *pnattr = nattr; 00113 return 0; 00114 } 00115 00116 static DwarfAbbrev* 00117 findabbrev(DwarfAbbrev *a, int na, ulong num) 00118 { 00119 int i; 00120 00121 for(i=0; i<na; i++) 00122 if(a[i].num == num) 00123 return &a[i]; 00124 werrstr("abbrev not found"); 00125 return nil; 00126 } 00127 00128 DwarfAbbrev* 00129 dwarfgetabbrev(Dwarf *d, ulong off, ulong num) 00130 { 00131 DwarfAbbrev *a; 00132 int na; 00133 00134 if((na = loadabbrevs(d, off, &a)) < 0){ 00135 werrstr("loadabbrevs: %r"); 00136 return nil; 00137 } 00138 return findabbrev(a, na, num); 00139 } 00140 00141 Generated on Sat May 26 2012 04:35:17 for ReactOS by
1.7.6.1
|