Advertisement
Guest User

Untitled

a guest
Jun 1st, 2021
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <elf.h>
  3.  
  4.  
  5. extern Elf64_Dyn _DYNAMIC[];
  6. static long long gdb_base_address = 0x555555554000;
  7. volatile int dynamic_section_cnt = 0;
  8. const char *address_to_name(void *fn)
  9. {
  10.     static Elf64_Sym *sym_table = 0;
  11.     static const char *string_sec = 0;
  12.     char *base;
  13.     if (sym_table == 0) {
  14.         for (int i = 0;  ; ++ i) {
  15.             if (_DYNAMIC[i].d_tag == DT_NULL)
  16.                 break; 
  17.             if (_DYNAMIC[i].d_tag == DT_SYMTAB)
  18.                 sym_table = (Elf64_Sym *)_DYNAMIC[i].d_un.d_ptr;
  19.             else if (_DYNAMIC[i].d_tag == DT_STRTAB)
  20.                 string_sec = (const char*)_DYNAMIC[i].d_un.d_ptr;
  21.         }
  22.     }
  23.     for (Elf64_Sym *it = sym_table;
  24.         (char*)it < (char*)sym_table + sizeof(Elf64_Sym) * dynamic_section_cnt;
  25.         ++ it) {
  26.         if (fn == (char*)it->st_value + gdb_base_address)
  27.             return string_sec + it->st_name;
  28.     }
  29.     return 0;
  30. }
  31. void __cyg_profile_func_enter (void *this_fn, void *call_site)
  32. {
  33.     fprintf(stderr, "b\t%s\n", address_to_name(this_fn));
  34. }
  35. void __cyg_profile_func_exit  (void *this_fn, void *call_site)
  36. {
  37.     fprintf(stderr, "e\t%s\n", address_to_name(this_fn));
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement