1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2013, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef BASE_UNIT_H
7#define BASE_UNIT_H
8
9
10#include <String.h>
11
12#include <Array.h>
13
14#include "Types.h"
15
16
17class AbbreviationTable;
18class DebugInfoEntry;
19struct SourceLanguageInfo;
20
21
22enum dwarf_unit_kind {
23	dwarf_unit_kind_compilation = 0,
24	dwarf_unit_kind_type
25};
26
27
28class BaseUnit {
29public:
30								BaseUnit(off_t headerOffset,
31									off_t contentOffset,
32									off_t totalSize,
33									off_t abbreviationOffset,
34									uint8 addressSize, bool isBigEndian,
35									bool isDwarf64);
36	virtual						~BaseUnit();
37
38			off_t				HeaderOffset() const { return fHeaderOffset; }
39			off_t				ContentOffset() const { return fContentOffset; }
40			off_t 				RelativeContentOffset() const
41									{ return fContentOffset - fHeaderOffset; }
42			off_t				TotalSize() const	{ return fTotalSize; }
43			off_t				ContentSize() const
44									{ return fTotalSize
45										- RelativeContentOffset(); }
46			off_t				AbbreviationOffset() const
47									{ return fAbbreviationOffset; }
48
49			bool				ContainsAbsoluteOffset(off_t offset) const;
50
51			uint8				AddressSize() const	{ return fAddressSize; }
52			bool				IsBigEndian() const { return fIsBigEndian; }
53			bool				IsDwarf64() const	{ return fIsDwarf64; }
54
55			AbbreviationTable*	GetAbbreviationTable() const
56									{ return fAbbreviationTable; }
57			void				SetAbbreviationTable(
58									AbbreviationTable* abbreviationTable);
59
60			const SourceLanguageInfo* SourceLanguage() const
61									{ return fSourceLanguage; }
62			void				SetSourceLanguage(
63									const SourceLanguageInfo* language);
64
65			status_t			AddDebugInfoEntry(DebugInfoEntry* entry,
66									off_t offset);
67			int					CountEntries() const;
68			void				GetEntryAt(int index, DebugInfoEntry*& entry,
69									off_t& offset) const;
70			DebugInfoEntry*		EntryForOffset(off_t offset) const;
71
72	virtual	dwarf_unit_kind		Kind() const = 0;
73
74private:
75			off_t				fHeaderOffset;
76			off_t				fContentOffset;
77			off_t				fTotalSize;
78			off_t				fAbbreviationOffset;
79			AbbreviationTable*	fAbbreviationTable;
80			const SourceLanguageInfo* fSourceLanguage;
81			Array<DebugInfoEntry*> fEntries;
82			Array<off_t>		fEntryOffsets;
83			uint8				fAddressSize;
84			bool				fIsBigEndian;
85			bool				fIsDwarf64;
86};
87
88
89#endif	// BASE_UNIT_H
90