test: Add an option to hello-exception.cpp for causing crashes
This is useful for testing the debugger.
This commit is contained in:
1 parent
8a60836d87
commit
42297caad3
1 file changed
+10
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include <exception>
|
#include <exception>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
class RecurseClass {
|
class RecurseClass {
|
||||||
public:
|
public:
|
||||||
@@ -31,9 +32,13 @@ private:
|
|||||||
int val;
|
int val;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool crash = false;
|
||||||
|
|
||||||
void recurse(int val) {
|
void recurse(int val) {
|
||||||
RecurseClass obj(val);
|
RecurseClass obj(val);
|
||||||
if (val == 0) {
|
if (val == 0) {
|
||||||
|
if (crash)
|
||||||
|
*(volatile int*)NULL = 0x42;
|
||||||
throw std::exception();
|
throw std::exception();
|
||||||
}
|
}
|
||||||
if (val == 5) {
|
if (val == 5) {
|
||||||
@@ -49,6 +54,11 @@ void recurse(int val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
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);
|
recurse(10);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user