test: Add options -noop and -wait to the hello-exception test program
This allows easier testing of continuing from manually set breakpoints. Also fix compilation for non-windows platforms where __debugbreak() isn't defined.
This commit is contained in:
1 parent
fc1b1ba110
commit
84462c92b0
1 file changed
+28
-2
@@ -19,6 +19,8 @@
|
|||||||
#include <exception>
|
#include <exception>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <thread>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
class RecurseClass {
|
class RecurseClass {
|
||||||
public:
|
public:
|
||||||
@@ -36,18 +38,26 @@ private:
|
|||||||
|
|
||||||
bool crash = false;
|
bool crash = false;
|
||||||
bool breakpoint = false;
|
bool breakpoint = false;
|
||||||
|
bool noop = false;
|
||||||
|
bool wait = false;
|
||||||
|
|
||||||
|
void done() {
|
||||||
|
}
|
||||||
|
|
||||||
void recurse(int val) {
|
void recurse(int val) {
|
||||||
RecurseClass obj(val);
|
RecurseClass obj(val);
|
||||||
if (val == 0) {
|
if (val == 0) {
|
||||||
if (crash)
|
if (crash)
|
||||||
*(volatile int*)NULL = 0x42;
|
*(volatile int*)NULL = 0x42;
|
||||||
|
#ifdef _WIN32
|
||||||
else if (breakpoint)
|
else if (breakpoint)
|
||||||
__debugbreak();
|
__debugbreak();
|
||||||
|
#endif
|
||||||
|
else if (noop)
|
||||||
|
done();
|
||||||
else
|
else
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
} else if (val == 5) {
|
||||||
if (val == 5) {
|
|
||||||
try {
|
try {
|
||||||
recurse(val - 1);
|
recurse(val - 1);
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
@@ -68,10 +78,26 @@ int main(int argc, char* argv[]) {
|
|||||||
crash = true;
|
crash = true;
|
||||||
fprintf(stderr, "Crashing instead of throwing an exception\n");
|
fprintf(stderr, "Crashing instead of throwing an exception\n");
|
||||||
} else if (!strcmp(argv[i], "-breakpoint")) {
|
} else if (!strcmp(argv[i], "-breakpoint")) {
|
||||||
|
#ifdef _WIN32
|
||||||
breakpoint = true;
|
breakpoint = true;
|
||||||
fprintf(stderr, "Triggering breakpoint instead of throwing an exception\n");
|
fprintf(stderr, "Triggering breakpoint instead of throwing an exception\n");
|
||||||
|
#else
|
||||||
|
fprintf(stderr, "Programmatic breakpoints not supported\n");
|
||||||
|
#endif
|
||||||
|
} else if (!strcmp(argv[i], "-noop")) {
|
||||||
|
noop = true;
|
||||||
|
fprintf(stderr, "Calling the function 'done' when recursion stops\n");
|
||||||
|
} else if (!strcmp(argv[i], "-wait")) {
|
||||||
|
wait = true;
|
||||||
|
fprintf(stderr, "Waiting before exiting\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recurse(10);
|
recurse(10);
|
||||||
|
if (wait) {
|
||||||
|
fprintf(stderr, "Waiting\n");
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
std::this_thread::sleep_for(10s);
|
||||||
|
fprintf(stderr, "Exiting\n");
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user