3 ms·
GCC 4.8 comes with a built-in address sanitizer that prints nice stack traces for most memory-related errors. Basically you just add "-fsanitize=address" and l
by shared4you 14y ago
GCC 4.8 comes with a built-in address sanitizer that prints nice stack traces for most memory-related errors.
Basically you just add "-fsanitize=address" and link appropriately:
gcc -pthread -fno-omit-frame-pointer -g -fsanitize=address badass.c -lasan -ldl
./a.out
==22420== ERROR: AddressSanitizer crashed on address 0x0000200000703c18 at pc 0x401947
READ of size 1 at 0x0000200000703c18; shadow: 0x0000100000381e0c; mem: 0x0000000001c0f065 thread: 0x787d4720
#0 0x401947 main use-after-free.c:5
#1 0x7ff87792cc4d __libc_start_main ??:0
#2 0x401839 _start ??:0
0x0000000001c0f065 is located 5 bytes inside of 80-byte region [0x0000000001c0f060,0x0000000001c0f0b0)
freed by thread 0x787d4720 here:
#0 0x404b9b free asan_rtl.cc:1203
#1 0x40191b main use-after-free.c:5
#2 0x7ff87792cc4d __libc_start_main ??:0
#3 0x401839 _start ??:0
previously allocated by thread 0x787d4720 here:
#0 0x405c27 malloc asan_rtl.cc:1196
#1 0x401910 main use-after-free.c:3
#2 0x7ff87792cc4d __libc_start_main ??:0
#3 0x401839 _start ??:0
See the changelog [1] as well as the library [2] itself. Of course, the OP's project is certainly cool too.
[1]: http://gcc.gnu.org/gcc-4.8/changes.html http://gcc.gnu.org/gcc-4.8/changes.html
[2]: https://code.google.com/p/address-sanitizer/wiki/AddressSanitizer https://code.google.com/p/address-sanitizer/wiki/AddressSani...
- bombela 14y agoAuthor of the code here. Yes, this is cool, but it instruments your code "This tool is very fast. The average slowdown of the instrumented program is ~2x (see PerformanceNumbers).". backward-cpp doesn't change the generated code in any way. This is only using the debug informations. There is no performance impact, the binary code stays the same.
- shared4you 14y agoWow, that is as perfect as it can get :)