Skip to content

Commit

Permalink
feat: add Debug
Browse files Browse the repository at this point in the history
Signed-off-by: Zone.N <[email protected]>
  • Loading branch information
MRNIU committed Jul 31, 2024
1 parent b1dae9c commit 7aa7de0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmake/compile_config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ list(APPEND COMMON_LINK_LIB

# 通用宏定义
list(APPEND COMMON_DEFINITIONS
$<$<CONFIG:Release>:RELEASE>
$<$<CONFIG:Debug>:DEBUG>
)

list(APPEND DEFAULT_BOOT_DEFINITIONS
Expand Down
12 changes: 12 additions & 0 deletions src/kernel/include/kernel_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdarg.h>

#include "cstdio"
#include "../../project_config.h"

namespace {

Expand All @@ -38,6 +39,17 @@ static constexpr const auto kWhite = "\033[37m";
/**
* @brief 与 printf 类似,只是颜色不同
*/
extern "C" inline void Debug(const char* format, ...) {
#ifdef DEBUG_LOG
va_list args;
va_start(args, format);
printf("%s", kMagenta);
vprintf(format, args);
printf("%s", kReset);
va_end(args);
#endif
}

extern "C" inline void Info(const char* format, ...) {
va_list args;
va_start(args, format);
Expand Down
4 changes: 4 additions & 0 deletions src/project_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@

#define KERNEL_NAME (wchar_t *)L"kernel.elf"

#ifdef DEBUG
#define DEBUG_LOG
#endif

#endif /* SIMPLEKERNEL_SRC_PROJECT_CONFIG_H_ */
4 changes: 4 additions & 0 deletions tools/project_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@

#define KERNEL_NAME (wchar_t *)L"@KERNEL_ELF_OUTPUT_NAME@"

#ifdef DEBUG
#define DEBUG_LOG
#endif

#endif /* SIMPLEKERNEL_SRC_PROJECT_CONFIG_H_ */

0 comments on commit 7aa7de0

Please sign in to comment.