Changeset 69850c8
- Timestamp:
- 05/28/15 12:09:35 (9 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
memlog.c
r134408c r69850c8 27 27 static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; 28 28 29 // The malloc hook might use functions that call malloc, and we need to make 30 // sure this does not cause an infinite loop. 31 static __thread int in_malloc = 0; 32 29 33 __attribute__((__constructor__)) 30 34 static void record_init() { … … 44 48 return; 45 49 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 46 54 (void) fflush(log_file); 47 55 (void) fclose(log_file); … … 67 75 68 76 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 69 124 unw_word_t off; 70 125 char proc_name[PATH_MAX]; … … 114 169 fprintf(log_file, "\t%s (%s+0x%x) [%p]", file_name, proc_name, (int) off, 115 170 (void *) (pip.start_ip + off)); 171 #endif 116 172 } 117 173 … … 159 215 extern void __libc_free(void *ptr); 160 216 161 // The malloc hook might use functions that call malloc, and we need to make162 // sure this does not cause an infinite loop.163 static __thread int in_malloc = 0;164 165 217 void *malloc(size_t size) { 166 218 if (in_malloc)
Note: See TracChangeset
for help on using the changeset viewer.