tinycodinglm / cpp /cpp-debug-ubsan.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
1.08 kB
opencode trace
System You are an expert debugger.

You are an expert debugger.

User

How to debug C++ undefined behavior using sanitizers?

Assistant

UB Sanitizer (UBSAN): -fsanitize=undefined -fno-sanitize-recover=all
Catches: signed integer overflow, null pointer dereference, out-of-bounds, misaligned pointer, strict aliasing, uninitialized value, shift overflow, divide by zero.

Address Sanitizer (ASAN): -fsanitize=address
Catches: heap/stack buffer overflow, use-after-free/return, double-free, memory leaks.

Thread Sanitizer (TSAN): -fsanitize=thread
Catches: data races, lock-order inversions, deadlocks.

Memory Sanitizer (MSAN): -fsanitize=memory
Catches: uninitialized memory reads.

Build: g++ -fsanitize=address,undefined -fno-sanitize-recover=all -g -O1 program.cpp
ASAN_OPTIONS=detect_leaks=1 ./a.out