CARMA C++
Backtrace.h
Go to the documentation of this file.
1 #ifndef CARMA_UTIL_BACKTRACE_H
2 #define CARMA_UTIL_BACKTRACE_H
3 
6 
7 #include <string>
8 #include <vector>
9 
10 
11 namespace carma {
12 namespace util {
13 
14 
16 class Backtrace {
17  public:
21  explicit Backtrace( );
22 
24  ~Backtrace( );
25 
26  bool captured() const;
27  bool capturedAndValid() const;
28 
34  bool captureNoThrow( );
35 
36  bool captureNoThrow( size_t maxDepth );
37 
38  bool captureNoThrow( bool convertToSymbols );
39 
40  bool captureNoThrow( size_t maxDepth,
41  bool convertToSymbols );
42 
43  void convertToSymbols( );
44 
49  ::std::string formattedAsString( ) const;
50 
57  ::std::string formattedAsString( const char * linePrefix,
58  const char * lineSuffix ) const;
59 
66  ::std::string
67  formattedAsString( const ::std::string & linePrefix,
68  const ::std::string & lineSuffix ) const;
69 
71  static ::std::string captureAsString( );
72 
76  static ::std::string captureAsString( const char * linePrefix,
77  const char * lineSuffix );
78 
82  static ::std::string
83  captureAsString( const ::std::string & linePrefix,
84  const ::std::string & lineSuffix );
85 
86  static void demangleSymbolLineInPlace( ::std::string & line );
87 
88  static ::std::string demangleSymbolLine( const ::std::string & line );
89 
90  static ::std::string demangleSymbolLine( const char * line );
91 
92  private:
93  typedef enum {
94  NOT_CAPTURED_STATE,
95  INVALID_CAPTURE_STATE,
96  NUMERIC_STATE,
97  MANGLED_STATE,
98  DEMANGLED_STATE
99  } State;
100 
101 
102  State state_;
103  bool complete_;
104  ::std::vector< void * > numeric_;
105  ::std::vector< ::std::string> symbolic_;
106 };
107 
108 
109 } // namespace carma::util
110 } // namespace carma
111 
112 
113 #endif
~Backtrace()
Destructor.
bool captureNoThrow()
Method that captures a backtrace if it can and stores it in this instance.
Backtrace()
Constructor that sets this instance to invalid.
Class to hold a captured call stack backtrace.
Definition: Backtrace.h:16
::std::string captureAsString()
Capture backtrace for the active call stack as a string.
::std::string formattedAsString() const
Returns a formatted multiline string representation of any valid backtrace stored in this instance...