Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/util/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void set_default_debug_action(debug_action a) {
}

debug_action ask_debug_action(std::istream& in) {
std::cerr << "(C)ontinue, (A)bort, (S)top, (T)hrow exception, Invoke (G)DB\n";
std::cerr << "(C)ontinue, (A)bort, (S)top, (T)hrow exception, Invoke (G)DB, Invoke (L)LDB\n";
char result;
bool ok = bool(in >> result);
if (!ok)
Expand All @@ -137,15 +137,18 @@ debug_action ask_debug_action(std::istream& in) {
return debug_action::throw_exception;
case 'G':
case 'g':
return debug_action::invoke_debugger;
return debug_action::invoke_gdb;
case 'L':
case 'l':
return debug_action::invoke_lldb;
default:
std::cerr << "INVALID COMMAND\n";
return debug_action::ask;
}
}

#if !defined(_WINDOWS) && !defined(NO_Z3_DEBUGGER)
void invoke_gdb() {
void invoke_debugger() {
std::string buffer;
int *x = nullptr;
debug_action a = get_default_debug_action();
Expand All @@ -161,7 +164,7 @@ void invoke_gdb() {
return;
case debug_action::throw_exception:
throw default_exception("assertion violation");
case debug_action::invoke_debugger:
case debug_action::invoke_gdb:
buffer = "gdb -nw /proc/" + std::to_string(getpid()) + "/exe " + std::to_string(getpid());
std::cerr << "invoking GDB...\n";
if (system(buffer.c_str()) == 0) {
Expand All @@ -174,6 +177,19 @@ void invoke_gdb() {
*x = 0;
}
return;
case debug_action::invoke_lldb:
buffer = "lldb -p " + std::to_string(getpid());
std::cerr << "invoking LLDB...\n";
if (system(buffer.c_str()) == 0) {
std::cerr << "continuing the execution...\n";
}
else {
std::cerr << "error starting LLDB...\n";
// forcing seg fault.
int *x = nullptr;
*x = 0;
}
return;
case debug_action::ask:
default:
a = ask_debug_action(std::cin);
Expand Down
7 changes: 4 additions & 3 deletions src/util/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ enum class debug_action {
abort,
stop,
throw_exception,
invoke_debugger,
invoke_gdb,
invoke_lldb
};
debug_action get_default_debug_action();
void set_default_debug_action(debug_action a);
Expand Down Expand Up @@ -69,8 +70,8 @@ void invoke_exit_action(unsigned int code);
#ifdef _WINDOWS
#define INVOKE_DEBUGGER() __debugbreak()
#else
void invoke_gdb();
#define INVOKE_DEBUGGER() invoke_gdb()
void invoke_debugger();
#define INVOKE_DEBUGGER() invoke_debugger()
#endif
#endif

Expand Down