about summary refs log tree commit diff stats
path: root/src/os/symbolfuncs_linux.c
blob: 7fa11705589dcd6250f522314a5ee1372769c9a6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "symbolfuncs.h"
#include "elfloader.h"
#include "debug.h"
#include "box64context.h"

int PrintFunctionAddr(uintptr_t nextaddr, const char* text)
{
    uint64_t sz = 0;
    uintptr_t start = 0;
    const char* symbname = FindNearestSymbolName(FindElfAddress(my_context, nextaddr), (void*)nextaddr, &start, &sz);
    if(!sz) sz=0x100;   // arbitrary value...
    if(symbname && nextaddr>=start && (nextaddr<(start+sz) || !sz)) {
        if(nextaddr==start)
            printf_log_prefix(0, LOG_NONE, " (%s%s:%s)", text, ElfName(FindElfAddress(my_context, nextaddr)), symbname);
        else
            printf_log_prefix(0, LOG_NONE, " (%s%s:%s + 0x%lx)", text, ElfName(FindElfAddress(my_context, nextaddr)), symbname, nextaddr - start);
        return 1;
    }
    return 0;
}