#include #include extern Elf64_Dyn _DYNAMIC[]; static long long gdb_base_address = 0x555555554000; volatile int dynamic_section_cnt = 0; const char *address_to_name(void *fn) { static Elf64_Sym *sym_table = 0; static const char *string_sec = 0; char *base; if (sym_table == 0) { for (int i = 0; ; ++ i) { if (_DYNAMIC[i].d_tag == DT_NULL) break; if (_DYNAMIC[i].d_tag == DT_SYMTAB) sym_table = (Elf64_Sym *)_DYNAMIC[i].d_un.d_ptr; else if (_DYNAMIC[i].d_tag == DT_STRTAB) string_sec = (const char*)_DYNAMIC[i].d_un.d_ptr; } } for (Elf64_Sym *it = sym_table; (char*)it < (char*)sym_table + sizeof(Elf64_Sym) * dynamic_section_cnt; ++ it) { if (fn == (char*)it->st_value + gdb_base_address) return string_sec + it->st_name; } return 0; } void __cyg_profile_func_enter (void *this_fn, void *call_site) { fprintf(stderr, "b\t%s\n", address_to_name(this_fn)); } void __cyg_profile_func_exit (void *this_fn, void *call_site) { fprintf(stderr, "e\t%s\n", address_to_name(this_fn)); }