7a77ddda0714db3eb98d63828ec8febe2e40a5e2
[iec.git] / src / type3_AndroidCloud / anbox-master / external / process-cpp-minimal / src / core / posix / backtrace.h
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 {
34 /**
35  * @brief The Frame class models an individual frame of a backtrace.
36  */
37 class Frame
38 {
39 public:
40     /**
41      * @brief The Symbol class models the symbolic representation of a frame pointer.
42      */
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
54         /**
55          * @brief is_cxx checks whether the symbol refers to a mangled C++ symbol.
56          * @return true iff the symbol refers to a mangled C++ symbol.
57          */
58         virtual bool is_cxx() const = 0;
59
60         /**
61          * @brief demangled returns the demangled C++ symbol name or raw.
62          */
63         virtual std::string demangled() const = 0;
64
65         /**
66          * @brief raw The raw symbolic representation of a frame pointer.
67          * @return
68          */
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
80     /**
81      * @brief depth returns the depth of this frame in the overall backtrace.
82      */
83     virtual std::size_t depth() const = 0;
84
85     /**
86      * @brief frame_pointer returns the the raw frame pointer of this frame.
87      * @return
88      */
89     virtual void* frame_pointer() const = 0;
90
91     /**
92      * @brief symbol returns the symbolic representation of this frame.
93      */
94     virtual const Symbol& symbol() const = 0;
95
96 protected:
97     Frame() = default;
98 };
99
100 /**
101  * @brief FrameHandler is the functor invoked for every frame of a backtrace.
102  *
103  * A FrameHandler should return true if it wants to continue walking the stack
104  * or false otherwise.
105  */
106 typedef std::function<bool(const Frame& frame)> FrameHandler;
107
108 /**
109  *@brief visit_with_handler iterates the backtrace of the calling program,
110  *invoking the handler for every frame.
111  *
112  * A FrameHandler should return true if it wants to continue walking the stack
113  * or false otherwise
114  *
115  * @param handler The handler invoked for every frame.
116  */
117 void CORE_POSIX_DLL_PUBLIC visit_with_handler(const FrameHandler& handler);
118 }
119 }
120 }
121
122 #endif // CORE_POSIX_BACKTRACE_H_