Skip to content

Commit d7d5e39

Browse files
committed
Introduce a new define to control LogTrace and friends
Defining `_DEBUG` changes which MSVC runtime library needs to be linked which breaks clients attempting to use the C++ API with `RelWithDebInfo`. To fix this we define a new private `BN_ENABLE_LOG_TRACE` macro and use that within log.cpp where it was previously using `_DEBUG`. Fixes #7288.
1 parent eef93b9 commit d7d5e39

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ if(BN_REF_COUNT_DEBUG)
6363
endif()
6464

6565
if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES RelWithDebInfo)
66-
target_compile_definitions(binaryninjaapi PRIVATE _DEBUG)
67-
else()
68-
target_compile_definitions(binaryninjaapi PRIVATE NDEBUG)
66+
target_compile_definitions(binaryninjaapi PRIVATE BN_ENABLE_LOG_TRACE)
6967
endif()
7068

7169
add_subdirectory(vendor/fmt EXCLUDE_FROM_ALL)

log.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void BinaryNinja::Log(BNLogLevel level, const char* fmt, ...)
215215

216216
void BinaryNinja::LogTrace(const char* fmt, ...)
217217
{
218-
#ifdef _DEBUG
218+
#ifdef BN_ENABLE_LOG_TRACE
219219
va_list args;
220220
va_start(args, fmt);
221221
PerformLog(0, DebugLog, "", 0, fmt, args);
@@ -280,7 +280,7 @@ void BinaryNinja::LogForException(BNLogLevel level, const std::exception& e, con
280280

281281
void BinaryNinja::LogTraceForException(const std::exception& e, const char* fmt, ...)
282282
{
283-
#ifdef _DEBUG
283+
#ifdef BN_ENABLE_LOG_TRACE
284284
va_list args;
285285
va_start(args, fmt);
286286
PerformLogForException(0, DebugLog, "", 0, e, fmt, args);
@@ -345,12 +345,12 @@ void BinaryNinja::LogWithStackTrace(BNLogLevel level, const char* fmt, ...)
345345

346346
void BinaryNinja::LogTraceWithStackTrace(const char* fmt, ...)
347347
{
348-
#ifdef _DEBUG
348+
#ifdef BN_ENABLE_LOG_TRACE
349349
va_list args;
350350
va_start(args, fmt);
351351
PerformLogWithStackTrace(0, DebugLog, "", 0, fmt, args);
352352
va_end(args);
353-
#endif
353+
#endif
354354
}
355355

356356

@@ -493,7 +493,7 @@ void Logger::Log(BNLogLevel level, const char* fmt, ...)
493493

494494
void Logger::LogTrace(const char* fmt, ...)
495495
{
496-
#ifdef _DEBUG
496+
#ifdef BN_ENABLE_LOG_TRACE
497497
va_list args;
498498
va_start(args, fmt);
499499
PerformLog(GetSessionId(), DebugLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
@@ -559,7 +559,7 @@ void Logger::LogForException(BNLogLevel level, const std::exception& e, const ch
559559

560560
void Logger::LogTraceForException(const std::exception& e, const char* fmt, ...)
561561
{
562-
#ifdef _DEBUG
562+
#ifdef BN_ENABLE_LOG_TRACE
563563
va_list args;
564564
va_start(args, fmt);
565565
PerformLogForException(
@@ -631,13 +631,13 @@ void Logger::LogWithStackTrace(BNLogLevel level, const char* fmt, ...)
631631

632632
void Logger::LogTraceWithStackTrace(const char* fmt, ...)
633633
{
634-
#ifdef _DEBUG
634+
#ifdef BN_ENABLE_LOG_TRACE
635635
va_list args;
636636
va_start(args, fmt);
637637
PerformLogWithStackTrace(
638638
GetSessionId(), DebugLog, GetName(), GetThreadId(), fmt::format("{}{}", GetIndent(), fmt).c_str(), args);
639639
va_end(args);
640-
#endif
640+
#endif
641641
}
642642

643643

0 commit comments

Comments
 (0)