sanitizer

How to generate core dump on AddressSanitizer error

↘锁芯ラ 提交于 2019-12-04 12:20:45
I compiled my code like this to enable Asan: g++ -O0 -g -fsanitize=address -fno-omit-frame-pointer but it never generates a core dump so that I can later examine the details of the error. How can I generate it? You need to set environment variable to request coredumps export ASAN_OPTIONS=abort_on_error=1 This should really be default but due to historic reasons ASan just exits with non-zero error code instead. On 64-bit systems you might need to add export ASAN_OPTIONS=...:disable_coredump=0::unmap_shadow_on_exit=1 (coredumps are disabled by default there, in fear that they will be too large).

Why can't clang enable all sanitizers?

拜拜、爱过 提交于 2019-12-03 22:39:17
Clang has various sanitizers that can be turned on to catch problems at runtime. However, there are some sanitizers that I can't use together. Why is that? clang++-3.9 -std=c++1z -g -fsanitize=memory -fsanitize=address -o main main.cpp 1 clang: error: invalid argument '-fsanitize=address' not allowed with '-fsanitize=memory' It's not a big deal, but when I run my unit tests, it takes longer than it should, because I have create multiple binaries for the same tests, and run each of them separately. clang++-3.9 -std=c++1z -g -fsanitize=address -o test1 test.cpp clang++-3.9 -std=c++1z -g

How can I break on UBSan reports in gdb and continue?

空扰寡人 提交于 2019-12-03 04:45:58
问题 Recent versions of GCC and Clang feature Undefined Behavior Sanitizer (UBSan) which is a compile flag ( -fsanitize=undefined ) that adds runtime instrumentation code. On errors, a warning such as this one is shown: packet-ber.c:1917:23: runtime error: left shift of 54645397829836991 by 8 places cannot be represented in type 'long int' Now I would like to debug this and get a debug break on said line. For Address Sanitizer (ASAN) there is ASAN_OPTIONS=abort_on_error=1 which results in a fatal

How can I break on UBSan reports in gdb and continue?

纵饮孤独 提交于 2019-12-02 17:58:23
Recent versions of GCC and Clang feature Undefined Behavior Sanitizer (UBSan) which is a compile flag ( -fsanitize=undefined ) that adds runtime instrumentation code. On errors, a warning such as this one is shown: packet-ber.c:1917:23: runtime error: left shift of 54645397829836991 by 8 places cannot be represented in type 'long int' Now I would like to debug this and get a debug break on said line. For Address Sanitizer (ASAN) there is ASAN_OPTIONS=abort_on_error=1 which results in a fatal error that is catchable. The only UBSan option that seems usable is UBSAN_OPTIONS=print_stacktrace=1

Is this code really undefined, as Clang seems to indicate?

我的未来我决定 提交于 2019-12-01 02:53:54
I switched on -fsanitize=undefined on my project which uses Catch, the unit testing library. One line from Catch was signalled as causing undefined behaviour by this flag. I managed to make an isolated example: #include <iomanip> #include <sstream> int main() { std::ostringstream os; os << "0x" << std::setfill('0') << std::hex; } Compiled with: clang++ -fsanitize=undefined main.cpp If I run this, the following print is given: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/ios_base.h:96:24: runtime error: load of value 4294967221, which is not a valid

Is this code really undefined, as Clang seems to indicate?

混江龙づ霸主 提交于 2019-11-30 22:55:02
问题 I switched on -fsanitize=undefined on my project which uses Catch, the unit testing library. One line from Catch was signalled as causing undefined behaviour by this flag. I managed to make an isolated example: #include <iomanip> #include <sstream> int main() { std::ostringstream os; os << "0x" << std::setfill('0') << std::hex; } Compiled with: clang++ -fsanitize=undefined main.cpp If I run this, the following print is given: /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../..

Misaligned address using virtual inheritance

我怕爱的太早我们不能终老 提交于 2019-11-30 14:31:07
The following apparently valid code produces a misaligned address runtime error using the UndefinedBehaviorSanitizer sanitiser. #include <memory> #include <functional> struct A{ std::function<void()> data; // seems to occur only if data is a std::function } ; struct B{ char data; // occurs only if B contains a member variable }; struct C:public virtual A,public B{ }; struct D:public virtual C{ }; void test(){ std::make_shared<D>(); } int main(){ test(); return 0; } Compiling and executing on a macbook with clang++ -fsanitize=undefined --std=c++11 ./test.cpp && ./a.out produces the output

How I'm supposed to use the sanitizer in clang?

无人久伴 提交于 2019-11-27 23:34:28
I'm sorry if this is a uber-easy concept, but I find hard to acquire the right mindset in order to correctly use the sanitizer provided by clang . float foo(float f) { return (f / 0); } I compile this small snippet with clang++ -fsanitize=float-divide-by-zero -std=c++11 -stdlib=libc++ -c source.cpp -o osan and I also compile a "normal" version of my object without using the sanitizer clang++ -std=c++11 -stdlib=libc++ -c source.cpp -o onorm I was expecting some verbose output, or some error from the console, but when inspecting the file with nm I only found 1 difference nm o* --demangle onorm: