diff --git a/libraries/AP_HAL_SITL/SITL_cmdline.cpp b/libraries/AP_HAL_SITL/SITL_cmdline.cpp index 162f464447..c32e810e59 100644 --- a/libraries/AP_HAL_SITL/SITL_cmdline.cpp +++ b/libraries/AP_HAL_SITL/SITL_cmdline.cpp @@ -53,6 +53,7 @@ static void _sig_fpe(int signum) { fprintf(stderr, "ERROR: Floating point exception - aborting\n"); AP_HAL::dump_stack_trace(); + AP_HAL::dump_core_file(); abort(); } @@ -61,6 +62,7 @@ static void _sig_segv(int signum) { fprintf(stderr, "ERROR: segmentation fault - aborting\n"); AP_HAL::dump_stack_trace(); + AP_HAL::dump_core_file(); abort(); } diff --git a/libraries/AP_HAL_SITL/system.cpp b/libraries/AP_HAL_SITL/system.cpp index c2be2f6b5e..4cf62433fc 100644 --- a/libraries/AP_HAL_SITL/system.cpp +++ b/libraries/AP_HAL_SITL/system.cpp @@ -37,6 +37,7 @@ void panic(const char *errormsg, ...) printf("\n"); dump_stack_trace(); + dump_core_file(); if (getenv("SITL_PANIC_EXIT")) { // this is used on the autotest server to prevent us waiting @@ -47,52 +48,54 @@ void panic(const char *errormsg, ...) } // partly flogged from: https://github.com/tridge/junkcode/blob/master/segv_handler/segv_handler.c -void dump_stack_trace() +void run_command_on_ownpid(const char *commandname) { // find dumpstack command: - const char *dumpstack = "dumpstack.sh"; // if we can't find it trust in PATH + const char *command_filepath = commandname; // if we can't find it trust in PATH struct stat statbuf; const char *paths[] { - "Tools/scripts/dumpstack.sh", - "APM/Tools/scripts/dumpstack.sh", // for autotest server - "../Tools/scripts/dumpstack.sh", // when run from e.g. ArduCopter subdirectory + "Tools/scripts/%s", + "APM/Tools/scripts/%s", // for autotest server + "../Tools/scripts/%s", // when run from e.g. ArduCopter subdirectory }; + char buffer[60]; for (uint8_t i=0; i%s 2>&1", - dumpstack, + command_filepath, (int)getpid(), output_filepath); fprintf(stderr, "Running: %s\n", cmd); @@ -101,8 +104,8 @@ void dump_stack_trace() fprintf(stderr, "Failed\n"); return; } - fprintf(stderr, "Stack dumped\n"); - + fprintf(stderr, "%s has been run. Output was:\n", commandname); + fprintf(stderr, "-------------- begin %s output ----------------\n", commandname); // print the trace on stderr: int fd = open(output_filepath, O_RDONLY); if (fd == -1) { @@ -124,8 +127,17 @@ void dump_stack_trace() break; } } + fprintf(stderr, "-------------- end %s output ----------------\n", commandname); close(fd); } +void dump_stack_trace() +{ + run_command_on_ownpid("dumpstack.sh"); +} +void dump_core_file() +{ + run_command_on_ownpid("dumpcore.sh"); +} uint32_t micros() {