Changeset 1bd82e0 for memlog.cpp
- Timestamp:
- 05/29/15 07:53:00 (9 years ago)
- Branches:
- master
- Children:
- e1b15ec
- Parents:
- 966f5de
- git-author:
- Hal Finkel <hfinkel@…> (05/29/15 07:53:00)
- git-committer:
- Hal Finkel <hfinkel@…> (05/29/15 07:53:00)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
memlog.cpp
r966f5de r1bd82e0 3 3 #endif 4 4 5 #include <stdlib.h> 6 #include <stdio.h> 5 #include <cstdlib> 6 #include <cstdio> 7 #include <cstring> 8 9 #include <unordered_map> 10 #include <utility> 11 7 12 #include <limits.h> 8 #include <string.h>9 10 13 #include <malloc.h> 11 14 #include <execinfo.h> … … 22 25 #include <dlfcn.h> 23 26 27 using namespace std; 28 24 29 // NOTE: When static linking, this depends on linker wrapping. 25 30 // Add to your LDFLAGS: … … 68 73 // dladdr is, relatively, quit slow. For this to work on a large application, 69 74 // we need to cache the lookup results. 70 static int dladdr_cached(void *addr, Dl_info *info) { 71 return dladdr(addr, info); 75 static int dladdr_cached(void * addr, Dl_info *info) { 76 static unordered_map<void *, Dl_info> dladdr_cache; 77 78 auto I = dladdr_cache.find(addr); 79 if (I == dladdr_cache.end()) { 80 int r; 81 if (!(r = dladdr(addr, info))) 82 memset(info, 0, sizeof(Dl_info)); 83 84 dladdr_cache.insert(make_pair(addr, *info)); 85 return r; 86 } 87 88 memcpy(info, &I->second, sizeof(Dl_info)); 89 return 1; 72 90 } 73 91 … … 176 194 // glibc exports its underlying malloc implementation under the name 177 195 // __libc_malloc so that hooks like this can use it. 196 extern "C" { 178 197 extern void *__libc_malloc(size_t size); 179 198 extern void *__libc_realloc(void *ptr, size_t size); … … 277 296 } 278 297 298 } // extern "C" 299
Note: See TracChangeset
for help on using the changeset viewer.