|
26 | 26 |
|
27 | 27 | #include "../dlMapper/dlMapper.h" |
28 | 28 |
|
| 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 | + |
29 | 43 | struct functionInfo functionInfo_loadHint(const char* functionName, const char* libraryName) { |
30 | 44 | struct functionInfo toReturn = (struct functionInfo) { 0, 0 }; |
31 | 45 |
|
32 | 46 | 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(); |
46 | 50 | } |
| 51 | + return toReturn; |
47 | 52 | } |
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 | + }) |
51 | 60 |
|
52 | 61 | if (callstack_autoClearCaches) { |
53 | 62 | callstack_clearCaches(); |
|
0 commit comments