2 * Copyright 2009-2012, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
6 #include "AbbreviationTable.h"
13 AbbreviationTable::AbbreviationTable(off_t offset
)
22 AbbreviationTable::~AbbreviationTable()
28 AbbreviationTable::Init(const void* section
, off_t sectionSize
)
30 if (fOffset
< 0 || fOffset
>= sectionSize
)
33 fData
= (uint8
*)section
+ fOffset
;
34 fSize
= sectionSize
- fOffset
;
35 // That's only the maximum size. Will be adjusted at the end.
37 status_t error
= fEntryTable
.Init();
41 DataReader
abbrevReader(fData
, fSize
, 4);
42 // address size doesn't matter here
46 status_t error
= _ParseAbbreviationEntry(abbrevReader
, nullEntry
);
54 fSize
-= abbrevReader
.BytesRemaining();
61 AbbreviationTable::GetAbbreviationEntry(uint32 code
, AbbreviationEntry
& entry
)
63 AbbreviationTableEntry
* tableEntry
= fEntryTable
.Lookup(code
);
64 if (tableEntry
== NULL
)
67 entry
.SetTo(code
, fData
+ tableEntry
->offset
, tableEntry
->size
);
73 AbbreviationTable::_ParseAbbreviationEntry(DataReader
& abbrevReader
,
76 uint32 code
= abbrevReader
.ReadUnsignedLEB128(0);
78 if (abbrevReader
.HasOverflow()) {
79 fprintf(stderr
, "Invalid abbreviation table 1!\n");
86 off_t remaining
= abbrevReader
.BytesRemaining();
88 /* uint32 tag =*/ abbrevReader
.ReadUnsignedLEB128(0);
89 /* uint8 hasChildren =*/ abbrevReader
.Read
<uint8
>(DW_CHILDREN_no
);
91 // printf("entry: %lu, tag: %lu, children: %d\n", code, tag,
94 // parse attribute specifications
96 uint32 attributeName
= abbrevReader
.ReadUnsignedLEB128(0);
97 uint32 attributeForm
= abbrevReader
.ReadUnsignedLEB128(0);
98 if (abbrevReader
.HasOverflow()) {
99 fprintf(stderr
, "Invalid abbreviation table 2!\n");
103 if (attributeName
== 0 && attributeForm
== 0)
106 // printf(" attr: name: %lu, form: %lu\n", attributeName,
111 if (fEntryTable
.Lookup(code
) == NULL
) {
112 AbbreviationTableEntry
* entry
= new(std::nothrow
)
113 AbbreviationTableEntry(code
, fSize
- remaining
,
114 remaining
- abbrevReader
.BytesRemaining());
118 fEntryTable
.Insert(entry
);
120 fprintf(stderr
, "Duplicate abbreviation table entry %" B_PRIu32
"!\n",