Skip to content

Commit

Permalink
Purged many of the debug code in Release build
Browse files Browse the repository at this point in the history
  • Loading branch information
Anivice committed Jan 14, 2025
1 parent c85f278 commit 84fd375
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,13 @@ string(REPLACE "\n" "\\n" SYSDARFT_INFO_CONTENT_ESCAPED "${SYSDARFT_INFO_CONTENT
add_compile_definitions(
SYSDARFT_VERSION="0.0.1"
SYSDARFT_INFORMATION="${SYSDARFT_INFO_CONTENT_ESCAPED}"
__DEBUG__
__CLEAN_OUTPUT__
)

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
add_compile_definitions(__DEBUG__)
endif ()

# Define include directories globally (can be refined per target)
include_directories(src/include)

Expand Down
4 changes: 4 additions & 0 deletions src/SysdarftDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,11 @@ std::string initialize_error_msg(const std::string& msg, const int _errno)

SysdarftBaseError::SysdarftBaseError(
const std::string& msg)
#ifdef __DEBUG__
: runtime_error(initialize_error_msg(msg, errno))
#else
: runtime_error(msg + "errno: " + std::to_string(errno))
#endif
, cur_errno(errno)
{
}
Expand Down
8 changes: 4 additions & 4 deletions src/cpu/OutputCurrentContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void SysdarftCPUInstructionExecutor::show_context()
// SHOW DB:DP (128 bytes)
////////////////////////////////////////////////////////////////////////////////
log("==============================================================================\n");
log("[DB:DP]:\n")
log("[DB:DP]:\n");
auto data_off = SysdarftRegister::load<DataBaseType>() + SysdarftRegister::load<DataPointerType>();
auto data_len = std::min(TotalMemory - data_off, 128ul);
std::vector<uint8_t> data_buffer;
Expand All @@ -279,7 +279,7 @@ void SysdarftCPUInstructionExecutor::show_context()
// SHOW EB:EP (128 bytes)
////////////////////////////////////////////////////////////////////////////////
log("==============================================================================\n");
log("[EB:EP]:\n")
log("[EB:EP]:\n");
auto ext_off = SysdarftRegister::load<ExtendedBaseType>() + SysdarftRegister::load<ExtendedPointerType>();
auto ext_len = std::min(TotalMemory - ext_off, 128ul);
std::vector<uint8_t> ext_buffer;
Expand All @@ -294,7 +294,7 @@ void SysdarftCPUInstructionExecutor::show_context()
// SHOW SB:SP (128 bytes)
////////////////////////////////////////////////////////////////////////////////
log("==============================================================================\n");
log("[SB:SP]:\n")
log("[SB:SP]:\n");
auto stack_off = SysdarftRegister::load<StackBaseType>() + SysdarftRegister::load<StackPointerType>();
auto stack_len = std::min(TotalMemory - stack_off, 128ul);
std::vector<uint8_t> stack_buffer;
Expand All @@ -309,7 +309,7 @@ void SysdarftCPUInstructionExecutor::show_context()
// SHOW NEXT 8 INSTRUCTIONS
////////////////////////////////////////////////////////////////////////////////
log("==============================================================================\n");
log("Following instructions:\n")
log("Following instructions:\n");
std::vector<std::string> next_8_instructions;
const uint64_t offset =
SysdarftRegister::load<CodeBaseType>()
Expand Down
8 changes: 5 additions & 3 deletions src/include/SysdarftDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ namespace debug
}
}

#if !defined(__DEBUG__) || defined(__CLEAN_OUTPUT__)
#define log(...) ::debug::_log(__VA_ARGS__);
#if defined(__DEBUG__) && defined(__CLEAN_OUTPUT__)
#define log(...) ::debug::_log(__VA_ARGS__)
#elif defined(__DEBUG__) && !defined(__CLEAN_OUTPUT__)
#define log(...) ::debug::_log(__FILE__, ":", __LINE__, ":", __PRETTY_FUNCTION__, ": ", __VA_ARGS__)
#else
#define log(...) ::debug::_log(__FILE__, ":", __LINE__, ":", __PRETTY_FUNCTION__, ": ", __VA_ARGS__);
#define log(...) __asm__("nop")
#endif

/**
Expand Down

0 comments on commit 84fd375

Please sign in to comment.