2 * Dwarf abbreviation parsing code.
4 * The convention here is that calling dwarfgetabbrevs relinquishes
5 * access to any abbrevs returned previously. Will have to add
6 * explicit reference counting if this turns out not to be acceptable.
11 #include <reactos/rossym.h>
12 #include "rossympriv.h"
19 #include "rossympriv.h"
22 static int parseabbrevs(Dwarf
*, ulong
, DwarfAbbrev
*, DwarfAttr
*, int*, int*);
23 DwarfAbbrev
*dwarfgetabbrev(Dwarf
*, ulong
, ulong
);
26 loadabbrevs(Dwarf
*d
, ulong off
, DwarfAbbrev
**aa
)
32 if(d
->acache
.off
== off
&& d
->acache
.na
){
37 /* two passes - once to count, then allocate, then a second to copy */
38 if(parseabbrevs(d
, off
, nil
, nil
, &nabbrev
, &nattr
) < 0) {
42 abbrev
= malloc(nabbrev
*sizeof(DwarfAbbrev
) + nattr
*sizeof(DwarfAttr
));
43 attr
= (DwarfAttr
*)(abbrev
+nabbrev
);
45 if(parseabbrevs(d
, off
, abbrev
, attr
, nil
, nil
) < 0){
52 d
->acache
.na
= nabbrev
;
60 parseabbrevs(Dwarf
*d
, ulong off
, DwarfAbbrev
*abbrev
, DwarfAttr
*attr
, int *pnabbrev
, int *pnattr
)
62 int i
, nabbrev
, nattr
, haskids
;
63 ulong num
, tag
, name
, form
;
66 if(off
>= d
->abbrev
.len
){
67 werrstr("bad abbrev section offset 0x%lux >= 0x%lux\n", off
, d
->abbrev
.len
);
71 memset(&b
, 0, sizeof b
);
72 b
.p
= d
->abbrev
.data
+ off
;
73 b
.ep
= d
->abbrev
.data
+ d
->abbrev
.len
;
79 werrstr("malformed abbrev data");
82 num
= dwarfget128(&b
);
85 tag
= dwarfget128(&b
);
86 haskids
= dwarfget1(&b
);
88 name
= dwarfget128(&b
);
89 form
= dwarfget128(&b
);
90 if(name
== 0 && form
== 0)
100 abbrev
->haskids
= haskids
;
117 findabbrev(DwarfAbbrev
*a
, int na
, ulong num
)
124 werrstr("abbrev not found");
129 dwarfgetabbrev(Dwarf
*d
, ulong off
, ulong num
)
134 if((na
= loadabbrevs(d
, off
, &a
)) < 0){
135 werrstr("loadabbrevs: %r");
138 return findabbrev(a
, na
, num
);