diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-08-29 11:10:45 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2024-08-29 11:10:45 +0200 |
| commit | 4cdd46819fec91bdbdad4f7c50b665d43ec6f4a8 (patch) | |
| tree | e432705fc61a434e2405b2a6fda9611cdd4ea714 /src | |
| parent | 0450371e282bd5c4dbbceaeca590626304609036 (diff) | |
| download | box64-4cdd46819fec91bdbdad4f7c50b665d43ec6f4a8.tar.gz box64-4cdd46819fec91bdbdad4f7c50b665d43ec6f4a8.zip | |
[TRACE] Improved trace on symbol name
Diffstat (limited to 'src')
| -rw-r--r-- | src/core.c | 63 | ||||
| -rw-r--r-- | src/elfs/elfloader.c | 19 | ||||
| -rw-r--r-- | src/elfs/elfloader32.c | 9 | ||||
| -rw-r--r-- | src/include/elfloader.h | 3 | ||||
| -rw-r--r-- | src/include/librarian.h | 1 | ||||
| -rw-r--r-- | src/librarian/librarian.c | 16 |
6 files changed, 74 insertions, 37 deletions
diff --git a/src/core.c b/src/core.c index 5d85d08c..db4ea773 100644 --- a/src/core.c +++ b/src/core.c @@ -1551,10 +1551,16 @@ void setupTraceInit() if(s_trace_start || s_trace_end) SetTraceEmu(s_trace_start, s_trace_end); } else { - if (GetGlobalSymbolStartEnd(my_context->maplib, p, &s_trace_start, &s_trace_end, NULL, -1, NULL, 0, NULL)) { - SetTraceEmu(s_trace_start, s_trace_end); - printf_log(LOG_INFO, "TRACE on %s only (%p-%p)\n", p, (void*)s_trace_start, (void*)s_trace_end); - } else if(GetLocalSymbolStartEnd(my_context->maplib, p, &s_trace_start, &s_trace_end, NULL, -1, NULL, 0, NULL)) { + int veropt = 1; + int ver = 0; + const char* vername = NULL; + int search = 0; + for(int i=0; i<my_context->elfsize && !search; ++i) { + search = ElfGetSymbolStartEnd(my_context->elfs[i], &s_trace_start, &s_trace_end, p, &ver, &vername, 1, &veropt)?1:0; + if(!search) + search = ElfGetSymTabStartEnd(my_context->elfs[i], &s_trace_start, &s_trace_end, p); + } + if(search) { SetTraceEmu(s_trace_start, s_trace_end); printf_log(LOG_INFO, "TRACE on %s only (%p-%p)\n", p, (void*)s_trace_start, (void*)s_trace_end); } else { @@ -1578,42 +1584,19 @@ void setupTraceMapLib(lib_t* maplib) return; char* p = trace_func; uintptr_t s_trace_start=0, s_trace_end=0; - if(maplib) { - if (GetGlobalSymbolStartEnd(maplib, p, &s_trace_start, &s_trace_end, NULL, -1, NULL, 0, NULL)) { - SetTraceEmu(s_trace_start, s_trace_end); - printf_log(LOG_INFO, "TRACE on %s only (%p-%p)\n", p, (void*)s_trace_start, (void*)s_trace_end); - box_free(trace_func); - trace_func = NULL; - return; - } else if(GetLocalSymbolStartEnd(maplib, p, &s_trace_start, &s_trace_end, NULL, -1, NULL, 0, NULL)) { - SetTraceEmu(s_trace_start, s_trace_end); - printf_log(LOG_INFO, "TRACE on %s only (%p-%p)\n", p, (void*)s_trace_start, (void*)s_trace_end); - box_free(trace_func); - trace_func = NULL; - return; - } else if(GetSymTabStartEnd(maplib, p, &s_trace_start, &s_trace_end)) { - SetTraceEmu(s_trace_start, s_trace_end); - printf_log(LOG_INFO, "TRACE on %s only (%p-%p)\n", p, (void*)s_trace_start, (void*)s_trace_end); - box_free(trace_func); - trace_func = NULL; - return; - } - } - if (my_context->elfs && GetGlobalSymbolStartEnd(my_context->maplib, p, &s_trace_start, &s_trace_end, NULL, -1, NULL, 0, NULL)) { + void* search = NULL; + if(GetAnySymbolStartEnd(maplib, p, &s_trace_start, &s_trace_end, 0, NULL, 1)) { SetTraceEmu(s_trace_start, s_trace_end); printf_log(LOG_INFO, "TRACE on %s only (%p-%p)\n", p, (void*)s_trace_start, (void*)s_trace_end); box_free(trace_func); trace_func = NULL; - } else if(my_context->elfs && GetLocalSymbolStartEnd(my_context->maplib, p, &s_trace_start, &s_trace_end, NULL, -1, NULL, 0, NULL)) { - SetTraceEmu(s_trace_start, s_trace_end); - printf_log(LOG_INFO, "TRACE on %s only (%p-%p)\n", p, (void*)s_trace_start, (void*)s_trace_end); - box_free(trace_func); - trace_func = NULL; - } else if(GetSymTabStartEnd(my_context->maplib, p, &s_trace_start, &s_trace_end)) { + return; + } else if(GetSymTabStartEnd(maplib, p, &s_trace_start, &s_trace_end)) { SetTraceEmu(s_trace_start, s_trace_end); printf_log(LOG_INFO, "TRACE on %s only (%p-%p)\n", p, (void*)s_trace_start, (void*)s_trace_end); box_free(trace_func); trace_func = NULL; + return; } else { printf_log(LOG_NONE, "Warning, Symbol to trace (\"%s\") not found. Trying to set trace later\n", p); SetTraceEmu(0, 1); // disabling trace, mostly @@ -1645,10 +1628,18 @@ void setupTrace() } } } else { - if (my_context->elfs && GetGlobalSymbolStartEnd(my_context->maplib, p, &s_trace_start, &s_trace_end, NULL, -1, NULL, 0, NULL)) { - SetTraceEmu(s_trace_start, s_trace_end); - printf_log(LOG_INFO, "TRACE on %s only (%p-%p)\n", p, (void*)s_trace_start, (void*)s_trace_end); - } else if(my_context->elfs && GetLocalSymbolStartEnd(my_context->maplib, p, &s_trace_start, &s_trace_end, NULL, -1, NULL, 0, NULL)) { + int search = 0; + if (my_context->elfs) { + int veropt = 1; + int ver = 0; + const char* vername = NULL; + for(int i=0; i<my_context->elfsize && !search; ++i) { + search = ElfGetSymbolStartEnd(my_context->elfs[i], &s_trace_start, &s_trace_end, p, &ver, &vername, 1, &veropt)?1:0; + if(!search) + search = ElfGetSymTabStartEnd(my_context->elfs[i], &s_trace_start, &s_trace_end, p); + } + } + if(search) { SetTraceEmu(s_trace_start, s_trace_end); printf_log(LOG_INFO, "TRACE on %s only (%p-%p)\n", p, (void*)s_trace_start, (void*)s_trace_end); } else { diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index d251abaa..9a7266f9 100644 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -1712,6 +1712,25 @@ void* ElfGetWeakSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *en return box64_is32bits?ElfGetWeakSymbolStartEnd32(head, offs, end, symname, ver, vername, local, veropt):ElfGetWeakSymbolStartEnd64(head, offs, end, symname, ver, vername, local, veropt); } +void* ElfGetSymbolStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) +#ifndef BOX32 +{ return NULL; } +#else + ; +#endif +void* ElfGetSymbolStartEnd64(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) +{ + Elf64_Sym* sym = ElfLocateSymbol(head, offs, end, symname, ver, vername, local, veropt); + if(!sym) return NULL; + if(offs) *offs = sym->st_value + head->delta; + if(end) *end = sym->st_value + head->delta + sym->st_size; + return sym; +} +void* ElfGetSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) +{ + return box64_is32bits?ElfGetSymbolStartEnd32(head, offs, end, symname, ver, vername, local, veropt):ElfGetSymbolStartEnd64(head, offs, end, symname, ver, vername, local, veropt); +} + int ElfGetSymTabStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname) #ifndef BOX32 { return 0; } diff --git a/src/elfs/elfloader32.c b/src/elfs/elfloader32.c index 2902dcc9..9f2dfa45 100644 --- a/src/elfs/elfloader32.c +++ b/src/elfs/elfloader32.c @@ -805,6 +805,15 @@ void* ElfGetWeakSymbolStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t * return sym; } +void* ElfGetSymbolStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt) +{ + Elf32_Sym* sym = ElfLocateSymbol(head, offs, end, symname, ver, vername, local, veropt); + if(!sym) return NULL; + if(offs) *offs = sym->st_value + head->delta; + if(end) *end = sym->st_value + head->delta + sym->st_size; + return sym; +} + int ElfGetSymTabStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname) { Elf32_Sym* sym = ElfSymTabLookup32(head, symname); diff --git a/src/include/elfloader.h b/src/include/elfloader.h index edaf9771..cec7195d 100644 --- a/src/include/elfloader.h +++ b/src/include/elfloader.h @@ -90,6 +90,9 @@ int GetNeededVersionForLib(elfheader_t* h, const char* libname, const char* ver) void* ElfGetLocalSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *sz, const char* symname, int* ver, const char** vername, int local, int* veropt); void* ElfGetGlobalSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *sz, const char* symname, int* ver, const char** vername, int local, int* veropt); void* ElfGetWeakSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *sz, const char* symname, int* ver, const char** vername, int local, int* veropt); +void* ElfGetSymbolStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname, int* ver, const char** vername, int local, int* veropt); +int ElfGetSymTabStartEnd(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname); +int ElfGetSymTabStartEnd32(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname); int ElfGetSymTabStartEnd64(elfheader_t* head, uintptr_t *offs, uintptr_t *end, const char* symname); void* GetNativeSymbolUnversioned(void* lib, const char* name); diff --git a/src/include/librarian.h b/src/include/librarian.h index 74a94373..710c3d43 100644 --- a/src/include/librarian.h +++ b/src/include/librarian.h @@ -36,6 +36,7 @@ int GetGlobalNoWeakSymbolStartEnd(lib_t *maplib, const char* name, uintptr_t* st int GetLocalSymbolStartEnd(lib_t *maplib, const char* name, uintptr_t* start, uintptr_t* end, elfheader_t *self, int version, const char* vername, int veropt, void** elfsym); elfheader_t* GetGlobalSymbolElf(lib_t *maplib, const char* name, int version, const char* vername, int veropt); int IsGlobalNoWeakSymbolInNative(lib_t *maplib, const char* name, int version, const char* vername, int veropt); +int GetAnySymbolStartEnd(lib_t *maplib, const char* name, uintptr_t* start, uintptr_t* end, int version, const char* vername, int veropt); int GetSymTabStartEnd(lib_t* maplib, const char* name, uintptr_t* start, uintptr_t* end); void MapLibRemoveLib(lib_t* maplib, library_t* lib); diff --git a/src/librarian/librarian.c b/src/librarian/librarian.c index 259f7e0c..ddeb063b 100644 --- a/src/librarian/librarian.c +++ b/src/librarian/librarian.c @@ -722,6 +722,19 @@ int GetLocalSymbolStartEnd(lib_t *maplib, const char* name, uintptr_t* start, ui return 0; } +int GetAnySymbolStartEnd(lib_t *maplib, const char* name, uintptr_t* start, uintptr_t* end, int version, const char* vername, int veropt) +{ + if(!maplib) + return 0; + for(int i=0; i<maplib->libsz; ++i) { + elfheader_t* h = GetElf(maplib->libraries[i]); + if(h && ElfGetSymbolStartEnd(h, start, end, name, NULL, NULL, 1, &veropt)) + return 1; + } + return 0; + +} + int GetSymTabStartEnd(lib_t* maplib, const char* name, uintptr_t* start, uintptr_t* end) { if(!maplib) @@ -729,7 +742,8 @@ int GetSymTabStartEnd(lib_t* maplib, const char* name, uintptr_t* start, uintptr for(int i=0; i<maplib->libsz; ++i) { elfheader_t* h = GetElf(maplib->libraries[i]); if(box64_is32bits) { - /* TODO */ + if(h && ElfGetSymTabStartEnd32(h, start, end, name)) + return 1; } else { if(h && ElfGetSymTabStartEnd64(h, start, end, name)) return 1; |