Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cmake debug option #3319

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ OPTION(WZ_ENABLE_BACKEND_VULKAN "Enable Vulkan backend" ON)
OPTION(WZ_ENABLE_BASIS_UNIVERSAL "Enable Basis Universal texture support" ON)
OPTION(WZ_DEBUG_GFX_API_LEAKS "Enable debugging for graphics API leaks" ON)
OPTION(WZ_FORCE_MINIMAL_OPUSFILE "Force a minimal build of Opusfile, since WZ does not need (or want) HTTP stream support" ON)
OPTION(WZ_MORE_DEBUG "Enable additional debug code" OFF)
mark_as_advanced(WZ_MORE_DEBUG)

# Dev options
OPTION(WZ_PROFILING_NVTX "Add NVTX-based profiling instrumentation to the code" OFF)
Expand Down
17 changes: 17 additions & 0 deletions lib/framework/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,19 @@
# include <stdio.h>
#endif

#ifdef _MSC_VER
#define DEBUG_BREAK __debugbreak()
#elif defined(WZ_OS_UNIX)
#include <signal.h>
#ifdef SIGTRAP
#define DEBUG_BREAK raise(SIGTRAP)
#else
#define DEBUG_BREAK raise(SIGABRT)
#endif
#else
#define DEBUG_BREAK
#endif

#define MAX_LEN_LOG_LINE 1024

char last_called_script_event[MAX_EVENT_NAME_LEN];
Expand Down Expand Up @@ -687,6 +700,10 @@ void debugDisableAssert()
assertEnabled = false;
}

void debugBreak() {
DEBUG_BREAK;
}

#include <sstream>

void _debug_multiline(int line, code_part part, const char *function, const std::string &multilineString)
Expand Down
3 changes: 3 additions & 0 deletions lib/framework/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,7 @@ bool debugPartEnabled(code_part codePart);

void debugDisableAssert();

/** Issue breakpoint in the debugger. */
void debugBreak();

#endif // __INCLUDED_LIB_FRAMEWORK_DEBUG_H__
7 changes: 7 additions & 0 deletions src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,11 @@
/* Enables usage of VTune-based instrumentation backend. */
#cmakedefine WZ_PROFILING_VTUNE

/* Enables additional debug code. */
#cmakedefine WZ_MORE_DEBUG
#ifdef WZ_MORE_DEBUG
// Remapping cmake variable into internal one. DEBUG is too popular name to be used as a variable in cmake.
#define DEBUG
#endif

#endif // __INCLUDED_WZ_GENERATED_CONFIG_H__
13 changes: 11 additions & 2 deletions src/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,22 @@ void console(const char *pFormat, ...); /// Print always to the ingame console
CONPRINTF("Hello %d", 123);
*/
template <typename... P>
static inline void CONPRINTF(P &&... params)
static inline void CONPRINTF(const char* format, P &&... params)
{
snprintf(ConsoleString, sizeof(ConsoleString), std::forward<P>(params)...);
/** Modern compilers can issue a warning/error if format is not string literal and there are no arguments.
* CONPRINTF overload with a single argument prevents that.
*/
std::snprintf(ConsoleString, sizeof(ConsoleString), format, std::forward<P>(params)...);
addConsoleMessage(ConsoleString, DEFAULT_JUSTIFY, INFO_MESSAGE);
}


static inline void CONPRINTF(const char* string)
{
addConsoleMessage(string, DEFAULT_JUSTIFY, INFO_MESSAGE);
}


#include <functional>

typedef std::function<void ()> CONSOLE_CALC_LAYOUT_FUNC;
Expand Down