2 * Copyright 2009-2016, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2010-2016, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
8 #include "DebuggerInterface.h"
12 #include <AutoDeleter.h>
14 #include "ElfSymbolLookup.h"
17 // #pragma mark - SymbolTableLookupSource
20 struct DebuggerInterface::SymbolTableLookupSource
: ElfSymbolLookupSource
{
22 SymbolTableLookupSource(const void* symbolTable
, size_t symbolTableSize
,
23 const char* stringTable
, size_t stringTableSize
)
25 fSymbolTable((const uint8
*)symbolTable
),
26 fStringTable(stringTable
),
27 fSymbolTableSize(symbolTableSize
),
28 fStringTableEnd(symbolTableSize
+ stringTableSize
)
32 virtual ssize_t
Read(uint64 address
, void* buffer
, size_t size
)
36 if (address
> fStringTableEnd
)
39 if (address
< fSymbolTableSize
) {
40 size_t toCopy
= std::min(size
, size_t(fSymbolTableSize
- address
));
41 memcpy(buffer
, fSymbolTable
+ address
, toCopy
);
47 if (address
< fStringTableEnd
) {
48 size_t toCopy
= std::min(size
, size_t(fStringTableEnd
- address
));
49 memcpy(buffer
, fStringTable
+ address
- fSymbolTableSize
, toCopy
);
59 const uint8
* fSymbolTable
;
60 const char* fStringTable
;
61 size_t fSymbolTableSize
;
62 size_t fStringTableEnd
;
66 // #pragma mark - DebuggerInterface
69 DebuggerInterface::~DebuggerInterface()
75 DebuggerInterface::IsPostMortem() const
77 // only true for core file interfaces
83 DebuggerInterface::GetElfSymbols(const char* filePath
, int64 textDelta
,
84 BObjectList
<SymbolInfo
>& infos
)
88 status_t error
= elfFile
.Init(filePath
);
92 // create the symbol lookup
93 ElfSymbolLookup
* symbolLookup
;
94 error
= elfFile
.CreateSymbolLookup(textDelta
, symbolLookup
);
98 ObjectDeleter
<ElfSymbolLookup
> symbolLookupDeleter(symbolLookup
);
101 return GetElfSymbols(symbolLookup
, infos
);
106 DebuggerInterface::GetElfSymbols(const void* symbolTable
, uint32 symbolCount
,
107 uint32 symbolTableEntrySize
, const char* stringTable
,
108 uint32 stringTableSize
, bool is64Bit
, bool swappedByteOrder
,
109 int64 textDelta
, BObjectList
<SymbolInfo
>& infos
)
111 size_t symbolTableSize
= symbolCount
* symbolTableEntrySize
;
112 SymbolTableLookupSource
* source
= new(std::nothrow
) SymbolTableLookupSource(
113 symbolTable
, symbolTableSize
, stringTable
, stringTableSize
);
116 BReference
<SymbolTableLookupSource
> sourceReference(source
, true);
118 ElfSymbolLookup
* symbolLookup
;
119 status_t error
= ElfSymbolLookup::Create(
120 source
, 0, 0, symbolTableSize
, symbolCount
, symbolTableEntrySize
,
121 textDelta
, is64Bit
, swappedByteOrder
, false, symbolLookup
);
125 ObjectDeleter
<ElfSymbolLookup
> symbolLookupDeleter(symbolLookup
);
128 return GetElfSymbols(symbolLookup
, infos
);
133 DebuggerInterface::GetElfSymbols(ElfSymbolLookup
* symbolLookup
,
134 BObjectList
<SymbolInfo
>& infos
)
136 SymbolInfo symbolInfo
;
138 while (symbolLookup
->NextSymbolInfo(index
, symbolInfo
) == B_OK
) {
139 SymbolInfo
* info
= new(std::nothrow
) SymbolInfo(symbolInfo
);
140 if (info
== NULL
|| !infos
.AddItem(info
)) {