From bbbdab6e27c6219e6af5be14cb6fd9fc9e3a642e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Mon, 25 Jan 2021 14:54:31 +0200 Subject: [PATCH] test: Add an option for triggering a breakpoint with hello-exception.cpp --- test/hello-exception.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/test/hello-exception.cpp b/test/hello-exception.cpp index 3a4bd49..9e36045 100644 --- a/test/hello-exception.cpp +++ b/test/hello-exception.cpp @@ -35,13 +35,17 @@ private: }; bool crash = false; +bool breakpoint = false; void recurse(int val) { RecurseClass obj(val); if (val == 0) { if (crash) *(volatile int*)NULL = 0x42; - throw std::exception(); + else if (breakpoint) + __debugbreak(); + else + throw std::exception(); } if (val == 5) { try { @@ -58,10 +62,15 @@ 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; - fprintf(stderr, "Crashing instead of throwing an exception\n"); + for (int i = 1; i < argc; i++) { + /* These modes are useful for testing backtraces in a debugger. */ + if (!strcmp(argv[i], "-crash")) { + crash = true; + fprintf(stderr, "Crashing instead of throwing an exception\n"); + } else if (!strcmp(argv[i], "-breakpoint")) { + breakpoint = true; + fprintf(stderr, "Triggering breakpoint instead of throwing an exception\n"); + } } recurse(10); return 0;