add public API
This commit is contained in:
parent
a72ba8066c
commit
7112c1cccf
|
@ -326,4 +326,38 @@ const char* rvprof_symbols_lookup(void* addr){
|
||||||
// fallback to addresses if we cannot resolve symbols
|
// fallback to addresses if we cannot resolve symbols
|
||||||
snprintf(g_tmp_func_name, sizeof(g_tmp_func_name), "func_%p", addr);
|
snprintf(g_tmp_func_name, sizeof(g_tmp_func_name), "func_%p", addr);
|
||||||
return g_tmp_func_name;
|
return g_tmp_func_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public API
|
||||||
|
rvprof_error_t rvprof_symbols_init(const char* program_path){
|
||||||
|
// option 1: provided path
|
||||||
|
if (program_path && parse_elf_symbols(program_path) == 0){
|
||||||
|
return RVPROF_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// option 2: try /proc/self/exe (Linux only)
|
||||||
|
if (parse_elf_symbols("/proc/self/exe") == 0){
|
||||||
|
return RVPROF_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// option 3: try typical paths
|
||||||
|
const char* fallbacks[] = {
|
||||||
|
"a.out",
|
||||||
|
"./a.out",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i=0; fallbacks[i]; i++){
|
||||||
|
if (parse_elf_symbols(fallbacks[i]) == 0){
|
||||||
|
return RVPROF_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// symbol loading failed, fall back to addresses
|
||||||
|
return RVPROF_ERROR_SYMBOLS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void rvprof_symbols_cleanup(void){
|
||||||
|
symbol_array_cleanup(&g_rvprof.symbols);
|
||||||
|
g_rvprof.symbols_loaded = 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue