Changeset 1bd82e0
- Timestamp:
- 05/29/15 07:53:00 (10 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)
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
Makefile
r493cb97 r1bd82e0 1 C C = /soft/compilers/bgclang/wbin/bgclang2 C FLAGS = -std=gnu99-O3 -g1 CXX = /soft/compilers/bgclang/wbin/bgclang++ 2 CXXFLAGS = -std=gnu++11 -O3 -g 3 3 4 4 CPPFLAGS = … … 7 7 all: libmemlog.so memlog_s.o 8 8 9 memlog_s.o: memlog.c 10 $(C C) $(CPPFLAGS) $(CFLAGS) -c -o memlog_s.o memlog.c9 memlog_s.o: memlog.cpp 10 $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o memlog_s.o memlog.cpp 11 11 12 libmemlog.so: memlog.c 13 $(C C) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -fPIC -shared -o libmemlog.so memlog.c12 libmemlog.so: memlog.cpp 13 $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -fPIC -shared -o libmemlog.so memlog.cpp 14 14 15 15 clean: -
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 -
memlog2dot
rbdaf020 r1bd82e0 206 206 chomp($func); 207 207 208 # It sometimes happens that addr2line is a bit too smart: when debugging 209 # information is available, it might print a local alias for the 210 # function instead of the full name (for example, printing 'List' 211 # instead of 'Foo::List<int>::List(int, int const&)'). 212 if ($node->{'proc_name'} ne '?') { 213 my $proc_name = $node->{'proc_name'}; 214 $proc_name = `c++filt '$proc_name'`; 215 chomp($proc_name); 216 217 if (length($proc_name) > length($func)) { 218 $func = $proc_name; 219 } 220 } 221 208 222 $ret .= $func . '\n'; 209 223
Note: See TracChangeset
for help on using the changeset viewer.