Changeset 69850c8


Ignore:
Timestamp:
05/28/15 12:09:35 (9 years ago)
Author:
Hal Finkel <hfinkel@…>
Branches:
master
Children:
a736d81
Parents:
134408c
git-author:
Hal Finkel <hfinkel@…> (05/28/15 12:09:35)
git-committer:
Hal Finkel <hfinkel@…> (05/28/15 12:09:35)
Message:

trying to avoid using unw_get_proc_name, etc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • memlog.c

    r134408c r69850c8  
    2727static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; 
    2828 
     29// The malloc hook might use functions that call malloc, and we need to make 
     30// sure this does not cause an infinite loop. 
     31static __thread int in_malloc = 0; 
     32 
    2933__attribute__((__constructor__)) 
    3034static void record_init() { 
     
    4448    return; 
    4549 
     50  // These functions might call free, but we're shutting down, so don't try to 
     51  // unwind the stack from here... 
     52  in_malloc = 1; 
     53 
    4654  (void) fflush(log_file); 
    4755  (void) fclose(log_file); 
     
    6775 
    6876  while ((r = unw_step(&cursor)) > 0) { 
     77    unw_word_t pc; 
     78    if ((r = unw_get_reg(&cursor, UNW_REG_IP, &pc))) { 
     79      fprintf(stderr, "unw_get_reg UNW_REG_IP failed: %s [%d]\n", 
     80              unw_strerror(r), r); 
     81      return; 
     82    } 
     83 
     84    if (!pc) 
     85      break; 
     86 
     87    unw_word_t off, relpc; 
     88    const char *proc_name; 
     89    const char *file_name; 
     90    Dl_info dlinfo; 
     91    if (dladdr((void *) pc, &dlinfo) && dlinfo.dli_fname && 
     92        *dlinfo.dli_fname) { 
     93      unw_word_t saddr = (unw_word_t) dlinfo.dli_saddr; 
     94      if (saddr) { 
     95#if defined(__powerpc64__) && !defined(__powerpc64le__) 
     96        // On PPC64 ELFv1, the symbol address points to the function descriptor, not 
     97        // the actual starting address. 
     98        saddr = *(unw_word_t*) saddr; 
     99#endif 
     100 
     101        off = pc - saddr; 
     102        relpc = pc - ((unw_word_t) dlinfo.dli_fbase); 
     103      } else { 
     104        off = 0; 
     105        relpc = 0; 
     106      } 
     107 
     108      proc_name = dlinfo.dli_sname; 
     109      if (!proc_name) 
     110        proc_name = "?"; 
     111 
     112      file_name = dlinfo.dli_fname; 
     113    } else { 
     114      off = pc; 
     115      relpc = pc; 
     116      proc_name = "?"; 
     117      file_name = "?"; 
     118    } 
     119 
     120    fprintf(log_file, "\t%s (%s+0x%x) [0x%lx (0x%lx)]", file_name, proc_name, (int) off, 
     121            (long) pc, (long) relpc); 
     122 
     123#if 0 
    69124    unw_word_t off; 
    70125    char proc_name[PATH_MAX]; 
     
    114169    fprintf(log_file, "\t%s (%s+0x%x) [%p]", file_name, proc_name, (int) off, 
    115170            (void *) (pip.start_ip + off)); 
     171#endif 
    116172  } 
    117173 
     
    159215extern void __libc_free(void *ptr); 
    160216 
    161 // The malloc hook might use functions that call malloc, and we need to make 
    162 // sure this does not cause an infinite loop. 
    163 static __thread int in_malloc = 0; 
    164  
    165217void *malloc(size_t size) { 
    166218  if (in_malloc) 
Note: See TracChangeset for help on using the changeset viewer.