process-cpp  3.0.0
A simple convenience library for handling processes in C++11.
backtrace.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Thomas Voß <thomas.voss@canonical.com>
17  */
18 
19 #ifndef CORE_POSIX_BACKTRACE_H_
20 #define CORE_POSIX_BACKTRACE_H_
21 
22 #include <core/posix/visibility.h>
23 
24 #include <functional>
25 #include <memory>
26 #include <string>
27 
28 namespace core
29 {
30 namespace posix
31 {
32 namespace backtrace
33 {
37 class Frame
38 {
39 public:
43  class Symbol
44  {
45  public:
46 
47  static std::shared_ptr<Symbol> for_testing_from_raw_symbol(const char* symbol);
48 
49  Symbol(const Symbol&) = delete;
50  virtual ~Symbol() = default;
51 
52  Symbol& operator=(const Symbol&) = delete;
53 
58  virtual bool is_cxx() const = 0;
59 
63  virtual std::string demangled() const = 0;
64 
69  virtual std::string raw() const = 0;
70 
71  protected:
72  Symbol() = default;
73  };
74 
75  Frame(const Frame&) = delete;
76  virtual ~Frame() = default;
77 
78  Frame& operator=(const Frame&) = delete;
79 
83  virtual std::size_t depth() const = 0;
84 
89  virtual void* frame_pointer() const = 0;
90 
94  virtual const Symbol& symbol() const = 0;
95 
96 protected:
97  Frame() = default;
98 };
99 
106 typedef std::function<bool(const Frame& frame)> FrameHandler;
107 
117 void visit_with_handler(const FrameHandler& handler);
118 }
119 }
120 }
121 
122 #endif // CORE_POSIX_BACKTRACE_H_
virtual std::size_t depth() const =0
depth returns the depth of this frame in the overall backtrace.
The Frame class models an individual frame of a backtrace.
Definition: backtrace.h:37
std::function< bool(const Frame &frame)> FrameHandler
FrameHandler is the functor invoked for every frame of a backtrace.
Definition: backtrace.h:106
void visit_with_handler(const FrameHandler &handler)
visit_with_handler iterates the backtrace of the calling program, invoking the handler for every fram...
Definition: backtrace.cpp:125
static std::shared_ptr< Symbol > for_testing_from_raw_symbol(const char *symbol)
Definition: backtrace.cpp:120
virtual const Symbol & symbol() const =0
symbol returns the symbolic representation of this frame.
The Symbol class models the symbolic representation of a frame pointer.
Definition: backtrace.h:43
virtual std::string raw() const =0
raw The raw symbolic representation of a frame pointer.
virtual std::string demangled() const =0
demangled returns the demangled C++ symbol name or raw.
virtual void * frame_pointer() const =0
frame_pointer returns the the raw frame pointer of this frame.
virtual bool is_cxx() const =0
is_cxx checks whether the symbol refers to a mangled C++ symbol.
Symbol & operator=(const Symbol &)=delete