Skip to content

Commit f086f18

Browse files
committed
Replaced the function pointer by a direct call
1 parent 33587de commit f086f18

File tree

7 files changed

+30
-23
lines changed

7 files changed

+30
-23
lines changed

src/functionInfo/functionInfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static inline bool functionInfo_getFrom(struct loadedLibInfo* info, const char*
3737

3838
file->relocationOffset = info->relocationOffset;
3939
file->inMemory = true;
40-
return functionInfo->found = file->getFunctionInfo(file, functionName, functionInfo);
40+
return functionInfo->found = binaryFile_getFunctionInfo(file, functionName, functionInfo);
4141
}
4242

4343
struct functionInfo functionInfo_loadHint(const char* functionName, const char* libraryName) {

src/parser/file/binaryFile.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,21 @@ struct binaryFile* binaryFile_new(const char* fileName, const void* startAddress
5252
return toReturn;
5353
}
5454

55+
bool binaryFile_getFunctionInfo(struct binaryFile* self, const char* functionName, struct functionInfo* info) {
56+
bool result = false;
57+
58+
#ifdef LCS_MACHO
59+
result = machoFile_getFunctionInfo(self->concrete, functionName, info);
60+
#elif defined(LCS_ELF)
61+
result = elfFile_getFunctionInfo(self->concrete, functionName, info);
62+
#endif
63+
64+
if (result) {
65+
info->imageBegin = (uintptr_t) self->startAddress;
66+
}
67+
return result;
68+
}
69+
5570
void binaryFile_clearCaches(void) {
5671
#ifdef LCS_MACHO
5772
machoFile_clearCaches();

src/parser/file/binaryFile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ struct binaryFile {
7070
* Returns whether the address could be translated.
7171
*/
7272
bool (*addr2String)(struct binaryFile*, void*, struct callstack_frame*);
73-
bool (*getFunctionInfo)(struct binaryFile*, const char*, struct functionInfo*);
7473
/** The appropriate deinitializing method. */
7574
void (*destroy)(struct binaryFile*);
7675
/** The appropriate deleting method. */
@@ -96,6 +95,8 @@ static inline void binaryFile_create(struct binaryFile* self) {
9695
self->inMemory = false;
9796
}
9897

98+
bool binaryFile_getFunctionInfo(struct binaryFile* self, const char* functionName, struct functionInfo* info);
99+
99100
/**
100101
* Clears the caches created by the binary file implementations.
101102
*/

src/parser/file/elf/elfFile.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ void elfFile_create(struct elfFile* self) {
4949
self->_.type = ELF_FILE;
5050
self->_.concrete = self;
5151

52-
self->_.getFunctionInfo = &elfFile_getFunctionInfo;
53-
self->_.addr2String = &elfFile_addr2String;
54-
self->_.destroy = &elfFile_destroy;
55-
self->_.deleter = &elfFile_delete;
52+
self->_.addr2String = &elfFile_addr2String;
53+
self->_.destroy = &elfFile_destroy;
54+
self->_.deleter = &elfFile_delete;
5655

5756
lcs_section_create(&self->debugLine);
5857
lcs_section_create(&self->debugLineStr);
@@ -365,12 +364,9 @@ static inline optional_debugInfo_t elfFile_getDebugInfo(struct elfFile* self, vo
365364
return toReturn;
366365
}
367366

368-
bool elfFile_getFunctionInfo(struct binaryFile* me, const char* functionName, struct functionInfo* info) {
369-
struct elfFile* self = elfFileOrNull(me);
370-
if (self == NULL) return false;
371-
372-
if (!me->parsed &&
373-
!(me->parsed = elfFile_loadFile(self))) {
367+
bool elfFile_getFunctionInfo(struct elfFile* self, const char* functionName, struct functionInfo* info) {
368+
if (!self->_.parsed &&
369+
!(self->_.parsed = elfFile_loadFile(self))) {
374370
return false;
375371
}
376372

src/parser/file/elf/elfFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static inline struct elfFile* elfFileOrNull(struct binaryFile * self) {
9292
*/
9393
bool elfFile_addr2String(struct binaryFile* self, void* address, struct callstack_frame* frame);
9494

95-
bool elfFile_getFunctionInfo(struct binaryFile* self, const char* functionName, struct functionInfo* info);
95+
bool elfFile_getFunctionInfo(struct elfFile* self, const char* functionName, struct functionInfo* info);
9696

9797
/**
9898
* Deinitializes the given binary file structure, if it is an ELF file structure.

src/parser/file/macho/machoFile.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@ void machoFile_create(struct machoFile* self) {
5454
self->_.type = MACHO_FILE;
5555
self->_.concrete = self;
5656

57-
self->_.getFunctionInfo = &machoFile_getFunctionInfo;
58-
self->_.addr2String = &machoFile_addr2String;
59-
self->_.destroy = &machoFile_destroy;
60-
self->_.deleter = &machoFile_delete;
57+
self->_.addr2String = &machoFile_addr2String;
58+
self->_.destroy = &machoFile_destroy;
59+
self->_.deleter = &machoFile_delete;
6160

6261
self->addressOffset = 0;
6362
self->linkedit_fileoff = 0;
@@ -376,11 +375,7 @@ static inline bool machoFile_loadFile(struct machoFile* self) {
376375
return success;
377376
}
378377

379-
bool machoFile_getFunctionInfo(struct binaryFile* me, const char* functionName, struct functionInfo* info) {
380-
struct machoFile* self = machoFileOrNull(me);
381-
if (self == NULL) {
382-
return false;
383-
}
378+
bool machoFile_getFunctionInfo(struct machoFile* self, const char* functionName, struct functionInfo* info) {
384379
if (!self->_.parsed &&
385380
!(self->_.parsed = machoFile_loadFile(self))) {
386381
return false;

src/parser/file/macho/machoFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ static inline struct machoFile* machoFileOrNull(struct binaryFile * self) {
9797
*/
9898
bool machoFile_addr2String(struct binaryFile* self, void* address, struct callstack_frame* frame);
9999

100-
bool machoFile_getFunctionInfo(struct binaryFile* self, const char* functionName, struct functionInfo* info);
100+
bool machoFile_getFunctionInfo(struct machoFile* self, const char* functionName, struct functionInfo* info);
101101

102102
/**
103103
* Deinitializes the given binary file structure if it is a Mach-O file structure.

0 commit comments

Comments
 (0)