From 42297caad382c9c6f91b4a59c79c71916364960b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Tue, 13 Oct 2020 12:17:38 +0300 Subject: [PATCH] test: Add an option to hello-exception.cpp for causing crashes This is useful for testing the debugger. --- test/hello-exception.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/hello-exception.cpp b/test/hello-exception.cpp index c82ad7a..d883b15 100644 --- a/test/hello-exception.cpp +++ b/test/hello-exception.cpp @@ -18,6 +18,7 @@ #include #include +#include class RecurseClass { public: @@ -31,9 +32,13 @@ private: int val; }; +bool crash = false; + void recurse(int val) { RecurseClass obj(val); if (val == 0) { + if (crash) + *(volatile int*)NULL = 0x42; throw std::exception(); } if (val == 5) { @@ -49,6 +54,11 @@ void recurse(int val) { } int main(int argc, char* argv[]) { + if (argc > 1 && !strcmp(argv[1], "-crash")) { + /* This mode is useful for testing backtraces in a debugger. */ + crash = true; + printf("Crashing instead of throwing an exception\n"); + } recurse(10); return 0; }