How would you diagnose a reproducible C++ crash or undefined behavior using warnings, a debugger, sanitizers, and a minimized test?
Show answer and explanation
First preserve the failing input, build options, environment, and a deterministic reproduction. Rebuild with debug information and strict warnings, then use a debugger or core dump to inspect the first relevant stack frame, threads, arguments, and invariants rather than only the final crash site. Run focused builds with AddressSanitizer plus UndefinedBehaviorSanitizer, and use ThreadSanitizer separately for suspected data races. Reduce the program while continuously retaining the failure, then turn the reproducer into a regression test. Because undefined behavior can move or disappear under optimization, compare suitable debug and optimized builds and fix the earliest proven contract violation, not merely the last symptom.
First preserve the failing input, build options, environment, and a deterministic reproduction. Rebuild with debug information and strict warnings, then use a debugger or core dump to inspect the first relevant stack frame, threads, arguments, and invariants rather than only the final crash site. Run focused builds with AddressSanitizer plus UndefinedBehaviorSanitizer, and use ThreadSanitizer separately for suspected data races. Reduce the program while continuously retaining the failure, then turn the reproducer into a regression test. Because undefined behavior can move or disappear under optimization, compare suitable debug and optimized builds and fix the earliest proven contract violation, not merely the last symptom.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.