Go to the documentation of this file.
51 static Debugger *signals[
NSIG];
76 for (
int i = 0; i <
NSIG; i++) {
77 if (
mysigs_[i]) signals[i] =
nullptr;
94 for (
int i = 0; i <
NSIG; i++) {
100 static void handler(
int sig) {
101 if (signals[sig]) signals[sig]->
got_signal(sig);
106 if (sig >=
NSIG)
return;
107 typedef void (*handler_type)(int);
108 signal(sig, (handler_type)handler);
114 if (sig >=
NSIG)
return;
115 signal(sig, SIG_DFL);
116 signals[sig] =
nullptr;
168 sprintf(p,
"%3d: ", i);
173 int has_x11_display = (getenv(
"DISPLAY") != 0);
175 if (has_x11_display) {
182 void Debugger::resolve_cmd_alias() {
183 if (
cmd_ ==
"gdb_xterm") {
185 "xterm -title \"$(PREFIX)$(EXEC)\" -e gdb -ex \"set variable "
186 "debugger_ready_=1\" --pid=$(PID) $(EXEC) &";
187 }
else if (
cmd_ ==
"lldb_xterm") {
189 "xterm -title \"$(PREFIX)$(EXEC)\" -e lldb -p $(PID) -o \"expr "
190 "debugger_ready_=1\" &";
204 std::cout <<
prefix_ <<
"Debugger::debug: ";
208 std::cout <<
"no reason given";
209 std::cout << std::endl;
214 std::string cmd =
cmd_;
215 std::string::size_type pos;
216 std::string pidvar(
"$(PID)");
217 while ((pos = cmd.find(pidvar)) != std::string::npos) {
219 pidstr += std::to_string(pid);
220 cmd.replace(pos, pidvar.size(), pidstr);
222 std::string execvar(
"$(EXEC)");
223 while ((pos = cmd.find(execvar)) != std::string::npos) {
224 cmd.replace(pos, execvar.size(),
exec_);
226 std::string prefixvar(
"$(PREFIX)");
227 while ((pos = cmd.find(prefixvar)) != std::string::npos) {
228 cmd.replace(pos, prefixvar.size(),
prefix_);
235 std::cout <<
prefix_ <<
"Debugger: starting \"" << cmd <<
"\"" << std::endl;
237 const auto system_retvalue = system(cmd.c_str());
238 if (system_retvalue != 0) {
240 <<
"Failed debugger launch: system() did not succeed ..."
246 <<
" seconds to wait for debugger ..." << std::endl;
250 std::string make_ready_message;
251 if (
cmd_.find(
" gdb ") != std::string::npos ||
252 cmd_.find(
" lldb ") != std::string::npos) {
254 " configure debugging session (set breakpoints/watchpoints, "
255 "etc.) then type 'c' to continue running";
258 std::cout <<
prefix_ <<
": waiting for the user ..."
259 << make_ready_message << std::endl;
271 else if (sig == SIGFPE)
273 else if (sig == SIGHUP)
275 else if (sig == SIGINT)
277 else if (sig == SIGABRT)
280 else if (sig == SIGBUS)
283 else if (sig == SIGTRAP)
286 signame =
"UNKNOWN SIGNAL";
296 std::cout <<
prefix_ <<
"Debugger: exiting" << std::endl;
299 std::cout <<
prefix_ <<
"Debugger: continuing" << std::endl;
321 #define SIMPLE_STACK \
322 (defined(linux) && defined(i386)) || (defined(__OSF1__) && defined(i860))
330 const size_t nframes_to_skip = 2;
331 #if defined(HAVE_LIBUNWIND)
332 std::cout << prefix <<
"Debugger::traceback(using libunwind):";
333 #elif defined(HAVE_BACKTRACE) // !HAVE_LIBUNWIND
334 std::cout << prefix <<
"Debugger::traceback(using backtrace):";
335 #else // !HAVE_LIBUNWIND && !HAVE_BACKTRACE
336 #if defined(SIMPLE_STACK)
337 std::cout << prefix <<
"Debugger::traceback:";
339 std::cout << prefix <<
"traceback not available for this arch" << std::endl;
341 #endif // SIMPLE_STACK
342 #endif // HAVE_LIBUNWIND, HAVE_BACKTRACE
347 std::cout <<
"no reason given";
348 std::cout << std::endl;
351 std::cout << prefix <<
"backtrace returned no state information"
354 std::cout << result.
str(nframes_to_skip) << std::endl;
358 auto debugger = std::make_shared<TiledArray::Debugger>();
359 debugger->debug(
"Starting gdb ...");
363 auto debugger = std::make_shared<TiledArray::Debugger>();
364 debugger->set_cmd(
"xterm -title \"$(PREFIX)$(EXEC)\" -e lldb -p $(PID) &");
365 debugger->debug(
"Starting lldb ...");
void launch_gdb_xterm()
Use this to launch GNU debugger in xterm.
virtual void set_cmd(const char *)
static std::shared_ptr< Debugger > default_debugger()
Return the global default debugger.
virtual void set_traceback_on_signal(int)
Turn on or off traceback on a signel. The default is on.
virtual void set_prefix(const char *p)
This sets a prefix which preceeds all messages printing by Debugger.
volatile int debugger_ready_
virtual void set_debug_on_signal(int)
Turn on or off debugging on a signel. The default is on.
static std::shared_ptr< Debugger > default_debugger_
virtual void set_exit_on_signal(int)
Turn on or off exit after a signel. The default is on.
std::string str(const size_t nframes_to_skip=0) const
virtual void debug(const char *reason)
virtual void set_exec(const char *)
virtual void traceback(const char *reason)
virtual void default_cmd()
Calls set_cmd with a hopefully suitable default.
virtual void handle(int sig)
The Debugger will be activated when sig is caught.
static void __traceback(const std::string &prefix, const char *reason=nullptr)
virtual void release(int sig)
Debugger(const char *exec=nullptr)
Programmatic construction of Debugger.
virtual void got_signal(int sig)
Called when signal sig is received. This is mainly for internal use.
virtual void set_wait_for_debugger(int)
void launch_lldb_xterm()
Use this to launch LLVM debugger in xterm.
static void set_default_debugger(const std::shared_ptr< Debugger > &)
Set the global default debugger. The initial value is null.
virtual void handle_defaults()
This calls handle(int) with all of the major signals.