1fce4895dSRene Gollent /* 2fce4895dSRene Gollent * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3fce4895dSRene Gollent * Distributed under the terms of the MIT License. 4fce4895dSRene Gollent */ 5fce4895dSRene Gollent #ifndef ABBREVIATION_TABLE_H 6fce4895dSRene Gollent #define ABBREVIATION_TABLE_H 7fce4895dSRene Gollent 8fce4895dSRene Gollent #include <util/DoublyLinkedList.h> 9fce4895dSRene Gollent #include <util/OpenHashTable.h> 10fce4895dSRene Gollent 11fce4895dSRene Gollent #include "DataReader.h" 12fce4895dSRene Gollent #include "Dwarf.h" 13fce4895dSRene Gollent 14fce4895dSRene Gollent 15fce4895dSRene Gollent struct AbbreviationTableEntry { 16fce4895dSRene Gollent uint32 code; 17fce4895dSRene Gollent off_t offset; 18fce4895dSRene Gollent off_t size; 19fce4895dSRene Gollent AbbreviationTableEntry* next; 20fce4895dSRene Gollent AbbreviationTableEntryAbbreviationTableEntry21fce4895dSRene Gollent AbbreviationTableEntry(uint32 code, off_t offset, off_t size) 22fce4895dSRene Gollent : 23fce4895dSRene Gollent code(code), 24fce4895dSRene Gollent offset(offset), 25fce4895dSRene Gollent size(size) 26fce4895dSRene Gollent { 27fce4895dSRene Gollent } 28fce4895dSRene Gollent }; 29fce4895dSRene Gollent 30fce4895dSRene Gollent 31fce4895dSRene Gollent struct AbbreviationEntry { AbbreviationEntryAbbreviationEntry32fce4895dSRene Gollent AbbreviationEntry() 33fce4895dSRene Gollent { 34fce4895dSRene Gollent } 35fce4895dSRene Gollent AbbreviationEntryAbbreviationEntry36fce4895dSRene Gollent AbbreviationEntry(uint32 code, const void* data, off_t size) 37fce4895dSRene Gollent { 38fce4895dSRene Gollent SetTo(code, data, size); 39fce4895dSRene Gollent } 40fce4895dSRene Gollent SetToAbbreviationEntry41fce4895dSRene Gollent void SetTo(uint32 code, const void* data, off_t size) 42fce4895dSRene Gollent { 43fce4895dSRene Gollent fCode = code; 44*3c16ba4eSDavid Karoly fAttributesReader.SetTo(data, size, 4, false); 45*3c16ba4eSDavid Karoly // address size and endianness don't matter here 46fce4895dSRene Gollent fTag = fAttributesReader.ReadUnsignedLEB128(0); 47fce4895dSRene Gollent fHasChildren = fAttributesReader.Read<uint8>(0); 48fce4895dSRene Gollent fData = fAttributesReader.Data(); 49fce4895dSRene Gollent fSize = fAttributesReader.BytesRemaining(); 50fce4895dSRene Gollent } 51fce4895dSRene Gollent CodeAbbreviationEntry52fce4895dSRene Gollent uint32 Code() const { return fCode; } TagAbbreviationEntry53fce4895dSRene Gollent uint32 Tag() const { return fTag; } HasChildrenAbbreviationEntry54fce4895dSRene Gollent bool HasChildren() const { return fHasChildren == DW_CHILDREN_yes; } 55fce4895dSRene Gollent GetNextAttributeAbbreviationEntry56a5c358a6SDavid Karoly bool GetNextAttribute(uint32& name, uint32& form, int32& implicitConst) 57fce4895dSRene Gollent { 58fce4895dSRene Gollent name = fAttributesReader.ReadUnsignedLEB128(0); 59fce4895dSRene Gollent form = fAttributesReader.ReadUnsignedLEB128(0); 60a5c358a6SDavid Karoly if (form == DW_FORM_implicit_const) 61a5c358a6SDavid Karoly implicitConst = fAttributesReader.ReadSignedLEB128(0); 62fce4895dSRene Gollent return !fAttributesReader.HasOverflow() && (name != 0 || form != 0); 63fce4895dSRene Gollent } 64fce4895dSRene Gollent 65fce4895dSRene Gollent private: 66fce4895dSRene Gollent uint32 fCode; 67fce4895dSRene Gollent const void* fData; 68fce4895dSRene Gollent off_t fSize; 69fce4895dSRene Gollent uint32 fTag; 70fce4895dSRene Gollent uint8 fHasChildren; 71fce4895dSRene Gollent DataReader fAttributesReader; 72fce4895dSRene Gollent }; 73fce4895dSRene Gollent 74fce4895dSRene Gollent 75fce4895dSRene Gollent struct AbbreviationTableHashDefinition { 76fce4895dSRene Gollent typedef uint32 KeyType; 77fce4895dSRene Gollent typedef AbbreviationTableEntry ValueType; 78fce4895dSRene Gollent HashKeyAbbreviationTableHashDefinition79fce4895dSRene Gollent size_t HashKey(uint32 key) const 80fce4895dSRene Gollent { 81fce4895dSRene Gollent return (size_t)key; 82fce4895dSRene Gollent } 83fce4895dSRene Gollent HashAbbreviationTableHashDefinition84fce4895dSRene Gollent size_t Hash(AbbreviationTableEntry* value) const 85fce4895dSRene Gollent { 86fce4895dSRene Gollent return HashKey(value->code); 87fce4895dSRene Gollent } 88fce4895dSRene Gollent CompareAbbreviationTableHashDefinition89fce4895dSRene Gollent bool Compare(uint32 key, AbbreviationTableEntry* value) const 90fce4895dSRene Gollent { 91fce4895dSRene Gollent return value->code == key; 92fce4895dSRene Gollent } 93fce4895dSRene Gollent GetLinkAbbreviationTableHashDefinition94fce4895dSRene Gollent AbbreviationTableEntry*& GetLink(AbbreviationTableEntry* value) const 95fce4895dSRene Gollent { 96fce4895dSRene Gollent return value->next; 97fce4895dSRene Gollent } 98fce4895dSRene Gollent }; 99fce4895dSRene Gollent 100fce4895dSRene Gollent 101fce4895dSRene Gollent class AbbreviationTable : public DoublyLinkedListLinkImpl<AbbreviationTable> { 102fce4895dSRene Gollent public: 103fce4895dSRene Gollent AbbreviationTable(off_t offset); 104fce4895dSRene Gollent ~AbbreviationTable(); 105fce4895dSRene Gollent 106fce4895dSRene Gollent status_t Init(const void* section, off_t sectionSize); 107fce4895dSRene Gollent Offset()108fce4895dSRene Gollent off_t Offset() const { return fOffset; } 109fce4895dSRene Gollent 110fce4895dSRene Gollent bool GetAbbreviationEntry(uint32 code, 111fce4895dSRene Gollent AbbreviationEntry& entry); 112fce4895dSRene Gollent 113fce4895dSRene Gollent private: 114fce4895dSRene Gollent typedef BOpenHashTable<AbbreviationTableHashDefinition> EntryTable; 115fce4895dSRene Gollent 116fce4895dSRene Gollent private: 117fce4895dSRene Gollent status_t _ParseAbbreviationEntry( 118fce4895dSRene Gollent DataReader& abbrevReader, bool& _nullEntry); 119fce4895dSRene Gollent 120fce4895dSRene Gollent private: 121fce4895dSRene Gollent off_t fOffset; 122fce4895dSRene Gollent const uint8* fData; 123fce4895dSRene Gollent off_t fSize; 124fce4895dSRene Gollent EntryTable fEntryTable; 125fce4895dSRene Gollent }; 126fce4895dSRene Gollent 127fce4895dSRene Gollent 128fce4895dSRene Gollent #endif // ABBREVIATION_TABLE_H 129