From c4a5e8b3103c5787f59e43b6643e8f6f76f7b777 Mon Sep 17 00:00:00 2001 From: Alex Lin Date: Wed, 20 Apr 2016 14:23:16 -0500 Subject: [PATCH] Debugger command on mac is now lldb not gdb Added a test to set the debugger command to gdb or lldb depending on availability. Created a new script for lldb to run. Modified the script for gdb to backtrace all threads. refs #227 --- bin/gdb_commands | 2 +- bin/lldb_commands | 2 + .../sim_services/Executive/src/Executive.cpp | 10 ++++- .../src/Executive_signal_handler.cpp | 42 ++++++++++--------- 4 files changed, 34 insertions(+), 22 deletions(-) create mode 100644 bin/lldb_commands diff --git a/bin/gdb_commands b/bin/gdb_commands index 15365d2d..e9f9f840 100644 --- a/bin/gdb_commands +++ b/bin/gdb_commands @@ -1,3 +1,3 @@ -where +thread apply all bt echo \n quit diff --git a/bin/lldb_commands b/bin/lldb_commands new file mode 100644 index 00000000..5774b9ae --- /dev/null +++ b/bin/lldb_commands @@ -0,0 +1,2 @@ +bt +quit diff --git a/trick_source/sim_services/Executive/src/Executive.cpp b/trick_source/sim_services/Executive/src/Executive.cpp index 288dc28f..ac48d22c 100644 --- a/trick_source/sim_services/Executive/src/Executive.cpp +++ b/trick_source/sim_services/Executive/src/Executive.cpp @@ -1,6 +1,7 @@ #include #include +#include #include "sim_services/Executive/include/Executive.hh" #include "sim_services/Executive/include/Exec_exception.hh" @@ -16,7 +17,14 @@ Trick::Executive::Executive() { advance_sim_time_job = NULL ; attach_debugger = false ; curr_job = NULL ; - debugger_command = std::string("/usr/bin/gdb") ; + + struct stat st ; + if ( stat("/usr/bin/gdb",&st) == 0 ) { + debugger_command = std::string("/usr/bin/gdb") ; + } else if ( stat("/usr/bin/lldb",&st) == 0 ) { + debugger_command = std::string("/usr/bin/lldb") ; + } + enable_freeze = false ; except_return = 0 ; exec_command = NoCmd ; diff --git a/trick_source/sim_services/Executive/src/Executive_signal_handler.cpp b/trick_source/sim_services/Executive/src/Executive_signal_handler.cpp index e827d1f5..9325f674 100644 --- a/trick_source/sim_services/Executive/src/Executive_signal_handler.cpp +++ b/trick_source/sim_services/Executive/src/Executive_signal_handler.cpp @@ -58,33 +58,35 @@ void Trick::Executive::signal_handler(int sig) { * Attempt to attach with debugger or print stack trace. Not a requirement. * sprintf and system are not async signal safe, but we don't have anything to lose. */ + if ( ! debugger_command.empty() ) { #if __linux - char command[1024]; - if (attach_debugger == true) { - sprintf(command, "%s -silent /proc/%d/exe %d", debugger_command.c_str(), getpid(), getpid()); - system(command); - } else if (stack_trace == true ) { - sprintf(command, "%s -silent -batch -x ${TRICK_HOME}/bin/gdb_commands " - "/proc/%d/exe %d | grep -A 20 \"signal handler\"", debugger_command.c_str(), getpid(), getpid()); - system(command); - } -#elif __APPLE__ - char command[2048]; - char path[1024] ; - uint32_t size = sizeof(path) ; - if (_NSGetExecutablePath(path, &size) == 0 ) { + char command[1024]; if (attach_debugger == true) { - write( 2 , "Attempting to attach debugger... standby.\n" , 41 ) ; - sprintf(command, "%s -silent %s %d", debugger_command.c_str(), path, getpid()); + sprintf(command, "%s -silent /proc/%d/exe %d", debugger_command.c_str(), getpid(), getpid()); system(command); } else if (stack_trace == true ) { - write( 2 , "Attempting to generate stack trace... standby.\n" , 47 ) ; - sprintf(command, "%s -batch -x ${TRICK_HOME}/bin/gdb_commands " - "%s %d", debugger_command.c_str(), path, getpid()); + sprintf(command, "%s -silent -batch -x ${TRICK_HOME}/share/trick/gdb_commands " + "/proc/%d/exe %d", debugger_command.c_str(), getpid(), getpid()); system(command); } - } +#elif __APPLE__ + char command[2048]; + char path[1024] ; + uint32_t size = sizeof(path) ; + if (_NSGetExecutablePath(path, &size) == 0 ) { + if (attach_debugger == true) { + write( 2 , "Attempting to attach debugger... standby.\n" , 41 ) ; + sprintf(command, "%s -silent %s %d", debugger_command.c_str(), path, getpid()); + system(command); + } else if (stack_trace == true ) { + write( 2 , "Attempting to generate stack trace... standby.\n" , 47 ) ; + sprintf(command, "%s -batch -s ${TRICK_HOME}/share/trick/lldb_commands -p %d", + debugger_command.c_str(), getpid()); + system(command); + } + } #endif + } // Sim state is unknown, don't return from handler. _exit(sig) ;