runtime_loader: Add imageName and exactMatch to symbol lookup.

Extend the get_nearest_symbol_at_address() private runtime_loader
export to include imageName and exactMatch arguments.

The imageName holds the SONAME of the image, if available, so cannot
neccessarily be extracted from the image path.

Whether or not there was an exact match, i.e. the symbol with its size
contains the address, is now returned in exactMatch.
This commit is contained in:
Michael Lotz
2015-04-11 11:18:50 +02:00
parent 215756b065
commit ebdc1d480e
4 changed files with 15 additions and 9 deletions
@@ -38,8 +38,8 @@ struct rld_export {
char *symbolName, int32 *nameLength, int32 *symbolType, char *symbolName, int32 *nameLength, int32 *symbolType,
void **_location); void **_location);
status_t (*get_nearest_symbol_at_address)(void* address, status_t (*get_nearest_symbol_at_address)(void* address,
image_id* _imageID, char** _imagePath, char** _symbolName, image_id* _imageID, char** _imagePath, char** _imageName,
int32* _type, void** _location); char** _symbolName, int32* _type, void** _location, bool* _exactMatch);
status_t (*test_executable)(const char *path, char *interpreter); status_t (*test_executable)(const char *path, char *interpreter);
status_t (*get_executable_architecture)(const char *path, status_t (*get_executable_architecture)(const char *path,
const char** _architecture); const char** _architecture);
+1 -1
View File
@@ -81,7 +81,7 @@ dladdr(void *address, Dl_info *info)
image_info imageInfo; image_info imageInfo;
sStatus = __gRuntimeLoader->get_nearest_symbol_at_address(address, &image, sStatus = __gRuntimeLoader->get_nearest_symbol_at_address(address, &image,
&imagePath, &symbolName, NULL, &location); &imagePath, NULL, &symbolName, NULL, &location, NULL);
if (sStatus != B_OK) if (sStatus != B_OK)
return 0; return 0;
+10 -5
View File
@@ -713,7 +713,8 @@ out:
status_t status_t
get_nearest_symbol_at_address(void* address, image_id* _imageID, get_nearest_symbol_at_address(void* address, image_id* _imageID,
char** _imagePath, char** _symbolName, int32* _type, void** _location) char** _imagePath, char** _imageName, char** _symbolName, int32* _type,
void** _location, bool* _exactMatch)
{ {
rld_lock(); rld_lock();
@@ -723,11 +724,11 @@ get_nearest_symbol_at_address(void* address, image_id* _imageID,
return B_BAD_VALUE; return B_BAD_VALUE;
} }
bool exactMatch = false;
elf_sym* foundSymbol = NULL; elf_sym* foundSymbol = NULL;
addr_t foundLocation = (addr_t)NULL; addr_t foundLocation = (addr_t)NULL;
bool found = false; for (uint32 i = 0; i < HASHTABSIZE(image) && !exactMatch; i++) {
for (uint32 i = 0; i < HASHTABSIZE(image) && !found; i++) {
for (int32 j = HASHBUCKETS(image)[i]; j != STN_UNDEF; for (int32 j = HASHBUCKETS(image)[i]; j != STN_UNDEF;
j = HASHCHAINS(image)[j]) { j = HASHCHAINS(image)[j]) {
elf_sym *symbol = &image->syms[j]; elf_sym *symbol = &image->syms[j];
@@ -738,8 +739,8 @@ get_nearest_symbol_at_address(void* address, image_id* _imageID,
foundLocation = location; foundLocation = location;
// jump out if we have an exact match // jump out if we have an exact match
if (foundLocation == (addr_t)address) { if (location + symbol->st_size > (addr_t)address) {
found = true; exactMatch = true;
break; break;
} }
} }
@@ -750,6 +751,10 @@ get_nearest_symbol_at_address(void* address, image_id* _imageID,
*_imageID = image->id; *_imageID = image->id;
if (_imagePath != NULL) if (_imagePath != NULL)
*_imagePath = image->path; *_imagePath = image->path;
if (_imageName != NULL)
*_imageName = image->name;
if (_exactMatch != NULL)
*_exactMatch = exactMatch;
if (foundSymbol != NULL) { if (foundSymbol != NULL) {
*_symbolName = SYMNAME(image, foundSymbol); *_symbolName = SYMNAME(image, foundSymbol);
@@ -68,7 +68,8 @@ status_t unload_library(void* handle, image_id imageID, bool addOn);
status_t get_nth_symbol(image_id imageID, int32 num, char* nameBuffer, status_t get_nth_symbol(image_id imageID, int32 num, char* nameBuffer,
int32* _nameLength, int32* _type, void** _location); int32* _nameLength, int32* _type, void** _location);
status_t get_nearest_symbol_at_address(void* address, image_id* _imageID, status_t get_nearest_symbol_at_address(void* address, image_id* _imageID,
char** _imagePath, char** _symbolName, int32* _type, void** _location); char** _imagePath, char** _imageName, char** _symbolName, int32* _type,
void** _location, bool* _exactMatch);
status_t get_symbol(image_id imageID, char const* symbolName, int32 symbolType, status_t get_symbol(image_id imageID, char const* symbolName, int32 symbolType,
bool recursive, image_id* _inImage, void** _location); bool recursive, image_id* _inImage, void** _location);
status_t get_library_symbol(void* handle, void* caller, const char* symbolName, status_t get_library_symbol(void* handle, void* caller, const char* symbolName,