2 * Copyright 2005-2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2013, Rene Gollent, rene@gollent.com.
4 * Distributed under the terms of the MIT License.
7 #ifndef SYMBOL_LOOKUP_H
8 #define SYMBOL_LOOKUP_H
15 #include <util/DoublyLinkedList.h>
19 struct runtime_loader_debug_area
;
31 Exception(status_t error
)
36 Exception(const Exception
&other
)
37 : fError(other
.fError
)
41 status_t
Error() const { return fError
; }
49 class Area
: public DoublyLinkedListLinkImpl
<Area
> {
51 Area(area_id id
, const void *address
, int32 size
)
54 fRemoteAddress(address
),
63 delete_area(fLocalID
);
66 const void* RemoteAddress() const { return fRemoteAddress
; }
67 const void* LocalAddress() const { return fLocalAddress
; }
68 int32
Size() const { return fSize
; }
70 bool ContainsAddress(const void *address
, int32 size
) const
72 return ((addr_t
)fRemoteAddress
<= (addr_t
)address
73 && (addr_t
)address
+ size
<= (addr_t
)fRemoteAddress
+ fSize
);
76 bool ContainsLocalAddress(const void* address
) const
78 return (addr_t
)address
>= (addr_t
)fLocalAddress
79 && (addr_t
)address
< (addr_t
)fLocalAddress
+ fSize
;
82 const void *PrepareAddress(const void *address
);
87 const void *fRemoteAddress
;
93 // RemoteMemoryAccessor
94 class RemoteMemoryAccessor
{
96 RemoteMemoryAccessor(team_id team
);
97 ~RemoteMemoryAccessor();
101 const void *PrepareAddress(const void *remoteAddress
, int32 size
) const;
102 const void *PrepareAddressNoThrow(const void *remoteAddress
,
105 template<typename Type
> inline const Type
&Read(
106 const Type
&remoteData
) const
108 const void *remoteAddress
= &remoteData
;
109 const void *localAddress
= PrepareAddress(remoteAddress
,
111 return *(const Type
*)localAddress
;
114 Area
* AreaForLocalAddress(const void* address
) const;
117 Area
&_FindArea(const void *address
, int32 size
) const;
118 Area
* _FindAreaNoThrow(const void *address
, int32 size
) const;
120 typedef DoublyLinkedList
<Area
> AreaList
;
131 struct SymbolIterator
{
138 class SymbolLookup
: private RemoteMemoryAccessor
{
140 SymbolLookup(team_id team
, image_id image
);
145 status_t
LookupSymbolAddress(addr_t address
, addr_t
*_baseAddress
,
146 const char **_symbolName
, size_t *_symbolNameLen
,
147 const char **_imageName
, bool *_exactMatch
) const;
149 status_t
InitSymbolIterator(image_id imageID
,
150 SymbolIterator
& iterator
) const;
151 status_t
InitSymbolIteratorByAddress(addr_t address
,
152 SymbolIterator
& iterator
) const;
153 status_t
NextSymbol(SymbolIterator
& iterator
, const char** _symbolName
,
154 size_t* _symbolNameLen
, addr_t
* _symbolAddress
, size_t* _symbolSize
,
155 int32
* _symbolType
) const;
157 status_t
GetSymbol(image_id imageID
, const char* name
, int32 symbolType
,
158 void** _symbolLocation
, size_t* _symbolSize
, int32
* _symbolType
) const;
162 friend class LoadedImage
;
165 const image_t
* _FindLoadedImageAtAddress(addr_t address
) const;
166 const image_t
* _FindLoadedImageByID(image_id id
) const;
167 Image
* _FindImageAtAddress(addr_t address
) const;
168 Image
* _FindImageByID(image_id id
) const;
169 size_t _SymbolNameLen(const char* address
) const;
170 status_t
_LoadImageInfo(const image_info
& imageInfo
);
173 const runtime_loader_debug_area
*fDebugArea
;
174 DoublyLinkedList
<Image
> fImages
;
179 } // namespace BPrivate
181 using BPrivate::Debug::SymbolLookup
;
183 #endif // SYMBOL_LOOKUP_H