2 * Copyright © 2014 Canonical Ltd.
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.
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.
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/>.
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
19 #ifndef CORE_POSIX_BACKTRACE_H_
20 #define CORE_POSIX_BACKTRACE_H_
22 #include <core/posix/visibility.h>
35 * @brief The Frame class models an individual frame of a backtrace.
41 * @brief The Symbol class models the symbolic representation of a frame pointer.
47 static std::shared_ptr<Symbol> for_testing_from_raw_symbol(const char* symbol);
49 Symbol(const Symbol&) = delete;
50 virtual ~Symbol() = default;
52 Symbol& operator=(const Symbol&) = delete;
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.
58 virtual bool is_cxx() const = 0;
61 * @brief demangled returns the demangled C++ symbol name or raw.
63 virtual std::string demangled() const = 0;
66 * @brief raw The raw symbolic representation of a frame pointer.
69 virtual std::string raw() const = 0;
75 Frame(const Frame&) = delete;
76 virtual ~Frame() = default;
78 Frame& operator=(const Frame&) = delete;
81 * @brief depth returns the depth of this frame in the overall backtrace.
83 virtual std::size_t depth() const = 0;
86 * @brief frame_pointer returns the the raw frame pointer of this frame.
89 virtual void* frame_pointer() const = 0;
92 * @brief symbol returns the symbolic representation of this frame.
94 virtual const Symbol& symbol() const = 0;
101 * @brief FrameHandler is the functor invoked for every frame of a backtrace.
103 * A FrameHandler should return true if it wants to continue walking the stack
104 * or false otherwise.
106 typedef std::function<bool(const Frame& frame)> FrameHandler;
109 *@brief visit_with_handler iterates the backtrace of the calling program,
110 *invoking the handler for every frame.
112 * A FrameHandler should return true if it wants to continue walking the stack
115 * @param handler The handler invoked for every frame.
117 void CORE_POSIX_DLL_PUBLIC visit_with_handler(const FrameHandler& handler);
122 #endif // CORE_POSIX_BACKTRACE_H_