Skip to content

Commit

Permalink
make logging, trace-logging and asserts optional during compile-time
Browse files Browse the repository at this point in the history
  • Loading branch information
wbenny committed Jan 6, 2020
1 parent 50fd7bb commit cfe3d32
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/hvpp/hvpp/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
//
#define HVPP_MAX_CPU 256

//
// Disable logging (DbgPrintEx) and/or ETW logging.
//

// #define HVPP_DISABLE_LOG

// #define HVPP_DISABLE_TRACELOG

//
// Disable asserts (hvpp_assert()).
//

// #define HVPP_DISABLE_ASSERT

//
// Uncomment this if you plan to intercept I/O ports 0x5658/0x5659
// in VMWare and you don't want the VMWare Tools to crash.
Expand Down
7 changes: 4 additions & 3 deletions src/hvpp/hvpp/lib/assert.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#pragma once
#include "debugger.h"
#include "../config.h"

#if 1
#if defined(HVPP_DISABLE_ASSERT)
# define hvpp_assert(expression)
#else
# define hvpp_assert(expression) \
do \
{ \
if (!(expression)) { \
debugger::breakpoint(); \
} \
} while (0)
#else
# define hvpp_assert(expression)
#endif
23 changes: 18 additions & 5 deletions src/hvpp/hvpp/lib/log.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
#pragma once
#include "enum.h"
#include "error.h"
#include "../config.h"

#include <cstdint>

#define hvpp_trace(format, ...) ::logger::print(::logger::level_t::trace, __FUNCTION__, format, __VA_ARGS__)
#define hvpp_debug(format, ...) ::logger::print(::logger::level_t::debug, __FUNCTION__, format, __VA_ARGS__)
#define hvpp_info(format, ...) ::logger::print(::logger::level_t::info, __FUNCTION__, format, __VA_ARGS__)
#define hvpp_warn(format, ...) ::logger::print(::logger::level_t::warn, __FUNCTION__, format, __VA_ARGS__)
#define hvpp_error(format, ...) ::logger::print(::logger::level_t::error, __FUNCTION__, format, __VA_ARGS__)
#if defined(HVPP_DISABLE_TRACELOG)
# define hvpp_trace(format, ...)
#else
# define hvpp_trace(format, ...) ::logger::print(::logger::level_t::trace, __FUNCTION__, format, __VA_ARGS__)
#endif

#if defined(HVPP_DISABLE_LOG)
# define hvpp_debug(format, ...)
# define hvpp_info(format, ...)
# define hvpp_warn(format, ...)
# define hvpp_error(format, ...)
#else
# define hvpp_debug(format, ...) ::logger::print(::logger::level_t::debug, __FUNCTION__, format, __VA_ARGS__)
# define hvpp_info(format, ...) ::logger::print(::logger::level_t::info, __FUNCTION__, format, __VA_ARGS__)
# define hvpp_warn(format, ...) ::logger::print(::logger::level_t::warn, __FUNCTION__, format, __VA_ARGS__)
# define hvpp_error(format, ...) ::logger::print(::logger::level_t::error, __FUNCTION__, format, __VA_ARGS__)
#endif

namespace logger
{
Expand Down
3 changes: 2 additions & 1 deletion src/hvpp/hvpp/lib/mm/mtrr_descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ namespace mm

void dump() const noexcept
{
auto dump_range = [](int i, const mtrr_range& mtrr) noexcept
auto dump_range = []([[maybe_unused]] int i,
[[maybe_unused]] const mtrr_range& mtrr) noexcept
{
hvpp_info(
" %3i) %s [%016" PRIx64 " - %016" PRIx64 "] (%8u kb)", i,
Expand Down

0 comments on commit cfe3d32

Please sign in to comment.