2 * Copyright 2016, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
14 struct CoreFileTeamInfo
{
16 void Init(int32 id
, int32 uid
, int32 gid
,
19 int32
Id() const { return fId
; }
20 const BString
& Arguments() const { return fArgs
; }
30 struct CoreFileAreaInfo
{
31 CoreFileAreaInfo(ElfSegment
* segment
, int32 id
,
32 uint64 baseAddress
, uint64 size
,
33 uint64 ramSize
, uint32 locking
,
34 uint32 protection
, const BString
& name
);
36 uint64
BaseAddress() const { return fBaseAddress
; }
37 uint64
Size() const { return fSize
; }
38 uint64
EndAddress() const
39 { return fBaseAddress
+ fSize
; }
40 uint32
Locking() const { return fLocking
; }
41 uint32
Protection() const { return fProtection
; }
43 ElfSegment
* Segment() const { return fSegment
; }
57 struct CoreFileSymbolsInfo
{
58 CoreFileSymbolsInfo();
59 ~CoreFileSymbolsInfo();
61 bool Init(const void* symbolTable
,
63 uint32 symbolTableEntrySize
,
64 const char* stringTable
,
65 uint32 stringTableSize
);
67 const void* SymbolTable() const { return fSymbolTable
; }
68 const char* StringTable() const { return fStringTable
; }
69 uint32
SymbolCount() const { return fSymbolCount
; }
70 uint32
SymbolTableEntrySize() const
71 { return fSymbolTableEntrySize
; }
72 uint32
StringTableSize() const
73 { return fStringTableSize
; }
79 uint32 fSymbolTableEntrySize
;
80 uint32 fStringTableSize
;
84 struct CoreFileImageInfo
{
85 CoreFileImageInfo(int32 id
, int32 type
,
86 uint64 initRoutine
, uint64 termRoutine
,
87 uint64 textBase
, uint64 textSize
,
89 uint64 dataBase
, uint64 dataSize
,
90 int32 deviceId
, int64 nodeId
,
91 uint64 symbolTable
, uint64 symbolHash
,
93 CoreFileAreaInfo
* textArea
,
94 CoreFileAreaInfo
* dataArea
,
98 int32
Id() const { return fId
; }
99 int32
Type() const { return fType
; }
100 uint64
TextBase() const { return fTextBase
; }
101 uint64
TextSize() const { return fTextSize
; }
102 int64
TextDelta() const { return fTextDelta
; }
103 uint64
DataBase() const { return fDataBase
; }
104 uint64
DataSize() const { return fDataSize
; }
105 uint64
SymbolTable() const { return fSymbolTable
; }
106 uint64
SymbolHash() const { return fSymbolHash
; }
107 uint64
StringTable() const { return fStringTable
; }
108 const BString
& Name() const { return fName
; }
109 CoreFileAreaInfo
* TextArea() const { return fTextArea
; }
110 CoreFileAreaInfo
* DataArea() const { return fDataArea
; }
112 const CoreFileSymbolsInfo
* SymbolsInfo() const
113 { return fSymbolsInfo
; }
115 CoreFileSymbolsInfo
* symbolsInfo
);
132 CoreFileAreaInfo
* fTextArea
;
133 CoreFileAreaInfo
* fDataArea
;
135 CoreFileSymbolsInfo
* fSymbolsInfo
;
139 struct CoreFileThreadInfo
{
140 CoreFileThreadInfo(int32 id
, int32 state
,
141 int32 priority
, uint64 stackBase
,
142 uint64 stackEnd
, const BString
& name
);
143 ~CoreFileThreadInfo();
145 bool SetCpuState(const void* state
, size_t size
);
146 const void* GetCpuState() const
147 { return fCpuState
; }
148 size_t CpuStateSize() const
149 { return fCpuStateSize
; }
151 int32
Id() const { return fId
; }
152 const BString
& Name() const { return fName
; }
162 size_t fCpuStateSize
;
171 status_t
Init(const char* fileName
);
173 ElfFile
& GetElfFile()
176 const CoreFileTeamInfo
& GetTeamInfo() const
177 { return fTeamInfo
; }
179 int32
CountAreaInfos() const
180 { return fAreaInfos
.CountItems(); }
181 const CoreFileAreaInfo
* AreaInfoAt(int32 index
) const
182 { return fAreaInfos
.ItemAt(index
); }
183 const CoreFileAreaInfo
* AreaInfoForAddress(uint64 address
) const
184 { return _FindArea(address
); }
186 int32
CountImageInfos() const
187 { return fImageInfos
.CountItems(); }
188 const CoreFileImageInfo
* ImageInfoAt(int32 index
) const
189 { return fImageInfos
.ItemAt(index
); }
190 const CoreFileImageInfo
* ImageInfoForId(int32 id
) const
191 { return _ImageInfoForId(id
); }
193 int32
CountThreadInfos() const
194 { return fThreadInfos
.CountItems(); }
195 const CoreFileThreadInfo
* ThreadInfoAt(int32 index
) const
196 { return fThreadInfos
.ItemAt(index
); }
197 const CoreFileThreadInfo
* ThreadInfoForId(int32 id
) const;
199 status_t
CreateSymbolLookup(
200 const CoreFileImageInfo
* imageInfo
,
201 ElfSymbolLookup
*& _lookup
);
204 typedef BObjectList
<CoreFileAreaInfo
> AreaInfoList
;
205 typedef BObjectList
<CoreFileImageInfo
> ImageInfoList
;
206 typedef BObjectList
<CoreFileThreadInfo
> ThreadInfoList
;
209 template<typename ElfClass
>
212 template<typename ElfClass
>
213 status_t
_ReadNotes();
214 template<typename ElfClass
>
215 status_t
_ReadNotes(ElfSegment
* segment
);
216 template<typename ElfClass
>
217 status_t
_ReadNote(const char* name
, uint32 type
,
218 const void* data
, uint32 dataSize
);
219 template<typename ElfClass
>
220 status_t
_ReadTeamNote(const void* data
,
222 template<typename ElfClass
>
223 status_t
_ReadAreasNote(const void* data
,
225 template<typename ElfClass
>
226 status_t
_ReadImagesNote(const void* data
,
228 template<typename ElfClass
>
229 status_t
_ReadSymbolsNote(const void* data
,
231 template<typename ElfClass
>
232 status_t
_ReadThreadsNote(const void* data
,
235 CoreFileAreaInfo
* _FindArea(uint64 address
) const;
236 ElfSegment
* _FindAreaSegment(uint64 address
) const;
238 CoreFileImageInfo
* _ImageInfoForId(int32 id
) const;
240 template<typename Type
>
241 Type
_ReadValue(const void*& data
, uint32
& dataSize
);
242 template<typename Entry
>
243 void _ReadEntry(const void*& data
, uint32
& dataSize
,
244 Entry
& entry
, size_t entrySize
);
245 void _Advance(const void*& data
, uint32
& dataSize
,
248 template<typename Value
>
249 Value
Get(const Value
& value
) const
250 { return fElfFile
.Get(value
); }
254 CoreFileTeamInfo fTeamInfo
;
255 AreaInfoList fAreaInfos
;
256 ImageInfoList fImageInfos
;
257 ThreadInfoList fThreadInfos
;
261 #endif // CORE_FILE_H