mimic++ v6
Loading...
Searching...
No Matches
stacktrace

Contains stacktrace related functionalities. More...

Concepts

concept  mimicpp::stacktrace::backend
 Checks whether the given type satisfies the requirements of a stacktrace backend.
 

Classes

struct  mimicpp::stacktrace::backend_traits< Backend >
 Trait type for stacktrace backends. More...
 
class  mimicpp::Stacktrace
 A simple type-erase stacktrace abstraction. More...
 

Variables

constexpr detail::current_hook::current_fn mimicpp::stacktrace::current {}
 Function object, which generates the current-stacktrace.
 

Detailed Description

Contains stacktrace related functionalities.

As mimic++ is officially a C++20 framework, it can not rely on built-in stack trace support from the STL. However, stack traces are particularly valuable for users in the context of mocking, especially when expectations are violated. To address this, mimic++ introduces a simple stacktrace abstraction that can be used to integrate existing stacktrace implementations.

Note
The MIMICPP_CONFIG_EXPERIMENTAL_STACKTRACE macro must be defined to fully enable the support.
  • If the MIMICPP_CONFIG_EXPERIMENTAL_USE_CPPTRACE is defined, the cpptrace::stacktrace is selected as the default stacktrace-backend.
  • If std::stacktrace is available (i.e. c++23 is available), it's selected as the default stacktrace-backend.
  • Otherwise, the stacktrace::NullBackend is selected, which does not provide any valuable information.
Attention
The built-in backend-priority is skipped if a non-debug build-mode is detected (i.e. when NDEBUG is defined), because neither std::stacktrace nor cpptrace do provide correct information. In this case the stacktrace::NullBackend is chosen as the active stacktrace-backend.

Custom Stacktrace Backends

In any case, users can define mimicpp::custom::find_stacktrace_backend to enable their own stacktrace-backend, which will then be preferred over any other stacktrace-backend (even for non-debug builds). That type must contain at least a type member-alias, which denotes the desired stacktrace-backend implementation.

struct mimicpp::custom::find_stacktrace_backend
{
using type = MyStacktraceBackend;
};

Additionally, a specialization for the stacktrace::backend_traits template must be added, which defines at least the following functions:

template <>
struct mimicpp::stacktrace::backend_traits<MyStacktraceBackend>
{
static MyStacktraceBackend current(const std::size_t skip);
static std::size_t size(const MyStacktraceBackend& backend);
static bool empty(const MyStacktraceBackend& backend);
static std::string description(const MyStacktraceBackend& backend, const std::size_t index);
static std::string source_file(const MyStacktraceBackend& backend, const std::size_t index);
static std::size_t source_line(const MyStacktraceBackend& backend, const std::size_t index);
};
Trait type for stacktrace backends.
Definition Stacktrace.hpp:97
Note
The index param denotes the index of the selected stacktrace-entry.

Variable Documentation

◆ current

detail::current_hook::current_fn mimicpp::stacktrace::current {}
constexpr

Function object, which generates the current-stacktrace.

This function skips at least all internal stacktrace-entries. Callers may specify the optional skip parameter to remove additional entries.