16 return ::IsDebuggerPresent() != 0;
18 std::FILE* pStatus = std::fopen(
"/proc/thread-self/status",
"r");
24 while (std::fgets(buffer,
sizeof(buffer), pStatus))
26 if (std::sscanf(buffer,
"TracerPid: %d", &nTracerPid) == 1)
30 return nTracerPid != 0;
31 #elif QX_MACOS && (QX_WITH_DEBUG_INFO)
32 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
34 size_t nSize =
sizeof(info);
35 return sysctl(mib, 4, &info, &nSize,
nullptr, 0) == 0 && (info.kp_proc.p_flag & P_TRACED) != 0;
42 string_view svCondition,
44 assert_type eAssertType,
46 string_view svFunction,
52 std::shared_lock lock(m_Mutex);
54 if (interceptor.callback(svCondition,
category, eAssertType, sUserMessage, svFunction, svFile, nLine))
57 currentConfig = m_Config;
60 if (currentConfig.bLogAssertion)
62 QX_LOG_REF(
category, currentConfig.getVerbosity(eAssertType),
"[{}] {}", svCondition, sUserMessage);
67 std::shared_lock _(
get_logger().get_streams_mutex());
68 if (
auto* pStream =
get_logger().get_stream<error_context_stream>())
69 pStream->on_error(std::this_thread::get_id());
72 if (currentConfig.onAssertion)
73 currentConfig.onAssertion(svCondition,
category, eAssertType, sUserMessage, svFunction, svFile, nLine);
81 if (currentConfig.onExit)
82 currentConfig.onExit(
category, eAssertType);
87 std::shared_lock lock(m_Mutex);
93 std::unique_lock lock(m_Mutex);
94 m_Config = std::move(
config);
99 std::unique_lock lock(m_Mutex);
100 m_Interceptors.push_back({ pOwner, std::move(interceptor) });
105 std::unique_lock lock(m_Mutex);
110 return entry.pOwner == pOwner;
bool is_debugger_present() noexcept
Check whether the current process or thread is being traced by a debugger.
void set_config(config config)
Set config.
void exit(const category &category, assert_type eAssertType)
Called in fatal assertions to exit the application.
void add_interceptor(const void *pOwner, interceptor_func interceptor)
Register an assertion interceptor.
void remove_interceptor(const void *pOwner)
Remove an interceptor, waiting for callbacks already in progress.
bool do_assert(string_view svCondition, const category &category, assert_type eAssertType, string sUserMessage, string_view svFunction, string_view svFile, i32 nLine)
An entry point for all assertions.
config get_config() const
Get config.
A category is a class that identifies a particular piece of code. This code can be located in differe...
virtual void flush()
Flush all streams.
logger & get_logger() noexcept
Get the logger instance used in QX_LOG macros.
#define QX_LOG_REF(category, eVerbosity,...)
Log with category and with non compile time category check.
std::int32_t i32
− 9 223 372 036 854 775 808 .. 9 223 372 036 854 775 807