MPQC  3.0.0-alpha
bug.h
1 //
2 // bug.h
3 //
4 // Copyright (C) 1996 Limit Point Systems, Inc.
5 //
6 // Author: Curtis Janssen <cljanss@limitpt.com>
7 // Maintainer: LPS
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _util_misc_bug_h
29 #define _util_misc_bug_h
30 
31 #include <string>
32 #include <vector>
33 #include <util/class/class.h>
34 #include <util/state/state.h>
35 #include <util/ref/ref.h>
36 
37 namespace sc {
38 
46 class Debugger: public SavableState {
47  protected:
48  std::string prefix_;
49  std::string exec_;
50  std::string cmd_;
51  volatile int debugger_ready_;
52 
53  int debug_;
54  int traceback_;
55  int exit_on_signal_;
56  int sleep_;
57  int wait_for_debugger_;
58  int handle_sigint_;
59  int *mysigs_;
60 
61  void init();
62 
63  static Debugger *default_debugger_;
64 
71  static void __traceback(const std::string& prefix, const char *reason = 0);
72  public:
73  Debugger(const char *exec = 0);
74 
104  Debugger(const Ref<KeyVal>&);
105 
106  Debugger(StateIn&);
107  ~Debugger();
108 
123  class Backtrace {
124  public:
128  Backtrace(const std::string& prefix = std::string(""));
129  Backtrace(const Backtrace&);
130 
134  bool empty() const {
135  return frames_.empty();
136  }
137 
143  std::string str(const size_t nframes_to_skip = 0) const;
144 
145  private:
147  std::vector<std::string> frames_;
149  std::string prefix_;
150 
152  static std::string __demangle(const std::string& symbol);
153  };
154 
157  virtual void debug(const char *reason = 0);
165  virtual void traceback(const char *reason = 0);
167  virtual void set_debug_on_signal(int);
169  virtual void set_traceback_on_signal(int);
171  virtual void set_exit_on_signal(int);
175  virtual void set_wait_for_debugger(int);
176 
178  virtual void handle(int sig);
180  virtual void handle_defaults();
181 
183  virtual void set_prefix(const char *p);
185  virtual void set_prefix(int p);
186 
192  virtual void set_cmd(const char *);
194  virtual void default_cmd();
198  virtual void set_exec(const char *);
199 
201  virtual void got_signal(int sig);
202 
204  static void set_default_debugger(const Ref<Debugger> &);
206  static Debugger *default_debugger();
207 
208  void save_data_state(StateOut&);
209 };
210 
211 }
212 
213 #endif
214 
215 // Local Variables:
216 // mode: c++
217 // c-file-style: "CLJ"
218 // End:
sc::Debugger::Backtrace
Creates a backtrace of a running program/thread.
Definition: bug.h:123
sc::Debugger::set_cmd
virtual void set_cmd(const char *)
Sets the command to be exectuted when debug is called.
sc::Debugger::set_prefix
virtual void set_prefix(const char *p)
This sets a prefix which preceeds all messages printing by Debugger.
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::Debugger::set_default_debugger
static void set_default_debugger(const Ref< Debugger > &)
Set the global default debugger. The initial value is null.
sc::Debugger::handle_defaults
virtual void handle_defaults()
This calls handle(int) with all of the major signals.
sc::Debugger::traceback
virtual void traceback(const char *reason=0)
The traceback member attempts to produce a Backtrace for the current process.
sc::Debugger::Backtrace::str
std::string str(const size_t nframes_to_skip=0) const
converts to a string
sc::StateIn
Definition: statein.h:79
sc::Debugger
The Debugger class describes what should be done when a catastrophic error causes unexpected program ...
Definition: bug.h:46
sc::Debugger::set_exec
virtual void set_exec(const char *)
Set the name of the exectuble for the current process.
sc::Debugger::debug
virtual void debug(const char *reason=0)
The debug member attempts to start a debugger running on the current process.
sc::Debugger::default_cmd
virtual void default_cmd()
Calls set_cmd with a hopefully suitable default.
sc::Debugger::save_data_state
void save_data_state(StateOut &)
Save the base classes (with save_data_state) and the members in the same order that the StateIn CTOR ...
sc::Debugger::Backtrace::empty
bool empty() const
Definition: bug.h:134
sc::StateOut
Definition: stateout.h:71
sc::Debugger::__traceback
static void __traceback(const std::string &prefix, const char *reason=0)
prints out a backtrace
sc::Debugger::set_wait_for_debugger
virtual void set_wait_for_debugger(int)
Turn on or off running an infinite loop after the debugger is started.
sc::Debugger::Backtrace::Backtrace
Backtrace(const std::string &prefix=std::string(""))
sc::Debugger::set_debug_on_signal
virtual void set_debug_on_signal(int)
Turn on or off debugging on a signel. The default is on.
sc::Debugger::handle
virtual void handle(int sig)
The Debugger will be actived when sig is caught.
sc::SavableState
Base class for objects that can save/restore state.
Definition: state.h:45
sc::Debugger::default_debugger
static Debugger * default_debugger()
Return the global default debugger.
sc::Debugger::got_signal
virtual void got_signal(int sig)
Called when signal sig is received. This is mainly for internal use.
sc::Debugger::set_traceback_on_signal
virtual void set_traceback_on_signal(int)
Turn on or off traceback on a signel. The default is on.
sc::Debugger::set_exit_on_signal
virtual void set_exit_on_signal(int)
Turn on or off exit after a signel. The default is on.
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14

Generated at Sun Jan 26 2020 23:24:01 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.