add a signal handler and backtrace

Tweak the signal handler and force non-release build
Increase ulimit locked memory value
Update the singal handler to use bfd symbol resolution.
Include configure logic to find bfd functions.
Add optionally c++ function name demangling
このコミットが含まれているのは:
Edgar
2022-04-04 18:51:07 -04:00
コミット 2bf6d254b6
5個のファイルの変更340行の追加0行の削除
+55
ファイルの表示
@@ -5,7 +5,15 @@
************************************************************************/
#include "TestBedChild.hpp"
#include "config.h"
#ifdef HAVE_BFD
#include "BfdBacktrace.hpp"
#endif
#include <thread>
#include <signal.h>
#include <execinfo.h>
#define CHILD_NCCL_CALL(cmd, msg) \
{ \
@@ -21,6 +29,47 @@
#define PIPE_READ(val) \
if (read(childReadFd, &val, sizeof(val)) != sizeof(val)) return TEST_FAIL;
void sig_handler(int signum){
printf("\n [%d] Inside handler function signal is %d\n", getpid(), signum);
#ifdef HAVE_BFD
void *addresses[BACKTRACE_MAX];
int num_addresses = backtrace(addresses, BACKTRACE_MAX);
struct backtrace_file file;
backtrace_line line;
backtrace_h bckt;
bckt.size = 0;
for (int i = 0; i < num_addresses; ++i) {
file.dl.address = (unsigned long)addresses[i];
if (dl_lookup_address(&file.dl) && load_file(&file)) {
bckt.size += get_line_info(&file, 1,
bckt.lines + bckt.size,
BACKTRACE_MAX - bckt.size);
unload_file(&file);
}
}
for (int i=0; i<BACKTRACE_MAX; i++ ){
if ((char*)bckt.lines[i].address == NULL) break;
printf("%p %s : %s line %u\n", (char*)bckt.lines[i].address, bckt.lines[i].file, bckt.lines[i].function, bckt.lines[i].lineno);
}
#else
#define BT_BUF_SIZE 1024
void *buffer[BT_BUF_SIZE];
char **strings;
int nptrs = backtrace(buffer, BT_BUF_SIZE);
strings = backtrace_symbols(buffer, nptrs);
for (int j = 0; j < nptrs; j++)
printf("%s\n", strings[j]);
free (strings);
#endif
exit (-1);
}
namespace RcclUnitTesting
{
TestBedChild::TestBedChild(int const childId, bool const verbose, int const printValues)
@@ -28,6 +77,11 @@ namespace RcclUnitTesting
this->childId = childId;
this->verbose = verbose;
this->printValues = printValues;
signal(SIGILL, sig_handler);
signal(SIGBUS, sig_handler);
signal(SIGFPE, sig_handler);
signal(SIGSEGV, sig_handler);
}
int TestBedChild::InitPipes()
@@ -51,6 +105,7 @@ namespace RcclUnitTesting
}
this->parentReadFd = pipefd[0];
this->childWriteFd = pipefd[1];
return TEST_SUCCESS;
}