Skip to content

Commit 77492bc

Browse files
committed
Added constructor to frame that accepts function addresses
1 parent 576a535 commit 77492bc

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

example/debug_function.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
#include <cstdlib> // std::exit
1212

1313
void print_signal_handler_and_exit() {
14-
void* p = reinterpret_cast<void*>(::signal(SIGSEGV, SIG_DFL));
15-
boost::stacktrace::frame f(p);
14+
typedef void(*function_t)(int);
15+
16+
function_t old_signal_function = ::signal(SIGSEGV, SIG_DFL);
17+
boost::stacktrace::frame f(old_signal_function);
1618
std::cout << f << std::endl;
1719
std::exit(0);
1820
}

include/boost/stacktrace/detail/frame_decl.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <boost/core/explicit_operator_bool.hpp>
1919

2020
#include <boost/stacktrace/safe_dump_to.hpp> // boost::stacktrace::detail::native_frame_ptr_t
21+
#include <boost/stacktrace/detail/void_ptr_cast.hpp>
2122

2223
#include <boost/stacktrace/detail/push_options.pp>
2324

@@ -82,6 +83,17 @@ class frame {
8283
: addr_(addr)
8384
{}
8485

86+
/// @brief Constructs frame that references function_addr and could later generate information about that function using platform specific features.
87+
///
88+
/// @b Complexity: O(1).
89+
///
90+
/// @b Async-Handler-Safety: Safe.
91+
/// @throws Nothing.
92+
template <class T>
93+
explicit frame(T* function_addr) BOOST_NOEXCEPT
94+
: addr_(boost::stacktrace::detail::void_ptr_cast<native_frame_ptr_t>(function_addr))
95+
{}
96+
8597
/// @returns Name of the frame (function name in a human readable form).
8698
///
8799
/// @b Complexity: unknown (lots of platform specific work).

0 commit comments

Comments
 (0)