Skip to content

Commit

Permalink
Start reading return and frame addresses with MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
ispeters committed Sep 11, 2024
1 parent 09f1e5c commit b3699ae
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
25 changes: 25 additions & 0 deletions include/unifex/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,4 +308,29 @@
# else
# define UNIFEX_NO_ASYNC_STACKS 0
# endif
#elif UNIFEX_NO_ASYNC_STACKS
// make sure the truthy value is 1
# undef UNIFEX_NO_ASYNC_STACKS
# define UNIFEX_NO_ASYNC_STACKS 1
#else
// make sure the falsey value is 0
# undef UNIFEX_NO_ASYNC_STACKS
# define UNIFEX_NO_ASYNC_STACKS 0
#endif // !defined(UNIFEX_NO_ASYNC_STACKS)

#if UNIFEX_HAS_BUILTIN(__builtin_return_address)
# define UNIFEX_RETURN_ADDRESS __builtin_return_address(0)
#elif defined(_MSC_VER)
# define UNIFEX_RETURN_ADDRESS _ReturnAddress()
#else
# define UNIFEX_RETURN_ADDRESS nullptr
#endif

#if UNIFEX_HAS_BUILTIN(__builtin_frame_address)
# define UNIFEX_FRAME_ADDRESS __builtin_frame_address(0)
#elif defined(_MSC_VER)
// not sure, yet, that this is right, but it's where we're starting
# define UNIFEX_FRAME_ADDRESS _AddressOfReturnAddress()
#else
# define UNIFEX_FRAME_ADDRESS nullptr
#endif
18 changes: 7 additions & 11 deletions include/unifex/tracing/async_stack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include <cassert>
#include <cstdint>

#if defined(_MSC_VER)
// needed for _ReturnAddress() and _AddressOfReturnAddress()
#include <intrin.h>
#endif

#include <unifex/detail/prologue.hpp>

namespace unifex {
Expand Down Expand Up @@ -273,13 +278,8 @@ struct instruction_ptr final {
// Generally a function that uses this macro should be declared FOLLY_NOINLINE
// to prevent this returning surprising results in cases where the function
// is inlined.
#if UNIFEX_HAS_BUILTIN(__builtin_return_address)
static constexpr instruction_ptr
read_return_address(void* p = __builtin_return_address(0)) noexcept {
#else
static constexpr instruction_ptr
read_return_address(void* p = nullptr) noexcept {
#endif
read_return_address(void* p = UNIFEX_RETURN_ADDRESS) noexcept {
return instruction_ptr{p};
}

Expand Down Expand Up @@ -311,12 +311,8 @@ struct frame_ptr {
// Generally a function that uses this macro should be declared FOLLY_NOINLINE
// to prevent this returning surprising results in cases where the function
// is inlined.
#if UNIFEX_HAS_BUILTIN(__builtin_frame_address)
static constexpr frame_ptr
read_frame_pointer(void* p = __builtin_frame_address(0)) noexcept {
#else
static constexpr frame_ptr read_frame_pointer(void* p = nullptr) noexcept {
#endif
read_frame_pointer(void* p = UNIFEX_FRAME_ADDRESS) noexcept {
return frame_ptr{p};
}

Expand Down

0 comments on commit b3699ae

Please sign in to comment.