Changeset 5a9481e
- Timestamp:
- 05/29/15 04:19:35 (9 years ago)
- Branches:
- master
- Children:
- 966f5de
- Parents:
- bdaf020
- git-author:
- Hal Finkel <hfinkel@…> (05/29/15 04:19:35)
- git-committer:
- Hal Finkel <hfinkel@…> (05/29/15 04:19:35)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
memlog.c
r1e5cce6 r5a9481e 59 59 in_malloc = 1; 60 60 61 // Avoid any racing by obtaining the lock. 62 if (pthread_mutex_lock(&log_mutex)) 63 return; 64 61 65 (void) fflush(log_file); 62 66 (void) fclose(log_file); 67 } 68 69 // dladdr is, relatively, quit slow. For this to work on a large application, 70 // we need to cache the lookup results. 71 static int dladdr_cached(void *addr, Dl_info *info) { 72 return dladdr(addr, info); 63 73 } 64 74 … … 80 90 81 91 int found_caller = 0; 82 caller = __builtin_extract_return_addr((void*) caller);83 92 for (int pci = 0; pci < num_pcs; ++pci) { 84 93 intptr_t pc = (intptr_t) pcs[pci]; … … 98 107 const char *file_name; 99 108 Dl_info dlinfo; 100 if (dladdr ((void *) pc, &dlinfo) && dlinfo.dli_fname &&109 if (dladdr_cached((void *) pc, &dlinfo) && dlinfo.dli_fname && 101 110 *dlinfo.dli_fname) { 102 111 intptr_t saddr = (intptr_t) dlinfo.dli_saddr; … … 181 190 182 191 void *FUNC(malloc)(size_t size) { 183 const void *caller = __builtin_return_address(0); 192 const void *caller = 193 __builtin_extract_return_addr(__builtin_return_address(0)); 184 194 185 195 if (in_malloc) … … 197 207 198 208 void *FUNC(realloc)(void *ptr, size_t size) { 199 const void *caller = __builtin_return_address(0); 209 const void *caller = 210 __builtin_extract_return_addr(__builtin_return_address(0)); 200 211 201 212 if (in_malloc) … … 216 227 217 228 void *FUNC(calloc)(size_t nmemb, size_t size) { 218 const void *caller = __builtin_return_address(0); 229 const void *caller = 230 __builtin_extract_return_addr(__builtin_return_address(0)); 219 231 220 232 if (in_malloc) … … 233 245 234 246 void *FUNC(memalign)(size_t boundary, size_t size) { 235 const void *caller = __builtin_return_address(0); 247 const void *caller = 248 __builtin_extract_return_addr(__builtin_return_address(0)); 236 249 237 250 if (in_malloc) … … 250 263 251 264 void FUNC(free)(void *ptr) { 252 const void *caller = __builtin_return_address(0); 265 const void *caller = 266 __builtin_extract_return_addr(__builtin_return_address(0)); 253 267 254 268 if (in_malloc || !ptr)
Note: See TracChangeset
for help on using the changeset viewer.