Skip to content

Commit db37a33

Browse files
committed
Fully implemented the function info getter system
1 parent 34dd2da commit db37a33

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

src/functionInfo/functionInfo.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,37 @@
2626

2727
#include "../dlMapper/dlMapper.h"
2828

29+
static inline bool functionInfo_getFrom(struct loadedLibInfo* info, const char* functionName, struct functionInfo* functionInfo) {
30+
if (info == NULL) return false;
31+
32+
if (info->associated == NULL) {
33+
info->associated = binaryFile_new(info->fileName, info->begin);
34+
}
35+
struct binaryFile* file = info->associated;
36+
if (file == NULL) return false;
37+
38+
file->relocationOffset = info->relocationOffset;
39+
file->inMemory = true;
40+
return file->getFunctionInfo(file, functionName, functionInfo);
41+
}
42+
2943
struct functionInfo functionInfo_loadHint(const char* functionName, const char* libraryName) {
3044
struct functionInfo toReturn = (struct functionInfo) { 0, 0 };
3145

3246
dlMapper_init();
33-
bool found = false;
34-
if (libraryName != NULL) {
35-
struct loadedLibInfo* info = dlMapper_libInfoForFileName(libraryName);
36-
if (info != NULL) {
37-
if (info->associated == NULL) {
38-
info->associated = binaryFile_new(info->fileName, info->begin);
39-
}
40-
struct binaryFile* file = info->associated;
41-
if (file != NULL) {
42-
file->relocationOffset = info->relocationOffset;
43-
file->inMemory = true;
44-
found = file->getFunctionInfo(file, functionName, &toReturn);
45-
}
47+
if (libraryName != NULL && functionInfo_getFrom(dlMapper_libInfoForFileName(libraryName), functionName, &toReturn)) {
48+
if (callstack_autoClearCaches) {
49+
callstack_clearCaches();
4650
}
51+
return toReturn;
4752
}
48-
if (!found) {
49-
// TODO: Search in all known binaries
50-
}
53+
54+
const vector_loadedLibInfo_t* libs = dlMapper_getLoadedLibraries();
55+
vector_iterate(struct loadedLibInfo, libs, {
56+
if (functionInfo_getFrom(element, functionName, &toReturn)) {
57+
break;
58+
}
59+
})
5160

5261
if (callstack_autoClearCaches) {
5362
callstack_clearCaches();

0 commit comments

Comments
 (0)