Skip to content
Merged
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
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ WARNFLAGS+=
EXTRA_CFLAGS=
EXTRA_CXXFLAGS=

-include ./v5dbg.mk

# Set to 1 to enable hot/cold linking
USE_PACKAGE:=1

Expand All @@ -33,12 +35,11 @@ VERSION:=0.2.1
# Exclude default main.cpp file
EXCLUDE_SRC_FROM_LIB= $(SRCDIR)/main.cpp
EXCLUDE_SRC_FROM_LIB+=$(foreach file, $(SRCDIR)/main,$(foreach cext,$(CEXTS),$(file).$(cext)) $(foreach cxxext,$(CXXEXTS),$(file).$(cxxext)))
TEMPLATE_FILES=$(INCDIR)/$(LIBNAME)/*.h $(INCDIR)/$(LIBNAME)/*.hpp
TEMPLATE_FILES=$(INCDIR)/$(LIBNAME)/*.h $(INCDIR)/$(LIBNAME)/*.hpp v5dbg.mk

.DEFAULT_GOAL=quick

################################################################################
################################################################################
########## Nothing below this line should be edited by typical users ###########
-include ./common.mk
-include ./stub.mk
-include ./common.mk
12 changes: 0 additions & 12 deletions include/v5dbg/config.h

This file was deleted.

11 changes: 11 additions & 0 deletions include/v5dbg/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,23 @@ class V5DbgAutoTask
v5dbg_thread_t *m_thread;
};

#ifdef V5DBG_DISABLE // Include stubbed info
#include "v5dbg/debug.stub.h"
#else

/**
* Begin a debuggable function
* @note Without this your function will not appear in stack traces and most debugger functions will not work
*/
// stub:macro=$function
#define $function static V5DbgStackMemory _v5dbg_stack_func_memory; V5DbgFunction _v5dbg_stack_func(__PRETTY_FUNCTION__, __FILE__, __LINE__, nullptr, &_v5dbg_stack_func_memory);


/**
* @brief Expose a scoped variable to the debugger, also handles pretty printer and pretty buffer allocation handles
* @note Can only be called within a debuggable function
*/
// stub:macro=$expose,target
#define $expose(target) \
constexpr int _v5dbg_var_line_##target = __LINE__; \
static v5dbg_variable_t _v5dbg_var_info_##target{}; \
Expand All @@ -50,14 +56,19 @@ class V5DbgAutoTask
auto _v5dbg_var_dealloc_##target = _v5dbg_stack_func.expose(_v5dbg_var_##target, _v5dbg_var_alloc_##target);

/// @brief Disabled by default breakpoint
// stub:macro=$break
#define $break { static v5dbg_breakpoint_t* _v5dbg_break_c = V5Dbg_Breakpoint(false, { .filePath = __FILE__, .lineNumber = __LINE__, .functionName = __PRETTY_FUNCTION__ }); \
V5Dbg_BreakpointMain(V5Dbg_GetCurrentServer(), _v5dbg_break_c); \
}

/// @brief Enabled by default conditional breakpoint
// stub:macro=$cbreak,value
#define $cbreak(...) { \
static v5dbg_breakpoint_t* _v5dbg_break_c = V5Dbg_BreakpointCond(true, { .filePath = __FILE__, .lineNumber = __LINE__, .functionName = __PRETTY_FUNCTION__ }, [&] () { return __VA_ARGS__; }); \
V5Dbg_BreakpointMain(V5Dbg_GetCurrentServer(), _v5dbg_break_c); \
}

// stub:macro=$ntask
#define $ntask V5DbgAutoTask _v5dbg_ctask;

#endif
11 changes: 11 additions & 0 deletions include/v5dbg/debug.stub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
/// Stubbed version of normal $function, automatically generated
#define $function
/// Stubbed version of normal $expose, automatically generated
#define $expose(target)
/// Stubbed version of normal $break, automatically generated
#define $break
/// Stubbed version of normal $cbreak, automatically generated
#define $cbreak(value)
/// Stubbed version of normal $ntask, automatically generated
#define $ntask
9 changes: 9 additions & 0 deletions include/v5dbg/pretty.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,20 @@ class V5DbgPrettyPrinterLinker
}
};

#ifdef V5DBG_DISABLE
#include "v5dbg/pretty.stub.h"
#else

/// @brief Register a pretty printer with a memory type
// stub:macro=$pretty_printer,func,type
#define $pretty_printer(func, type) static V5DbgPrettyPrinterLinker _v5dbg_pretty_printer_##type(type, &func);

/// @brief Register a pretty printer allocator with a memory type
// stub:macro=$pretty_printer_allocator,func,type
#define $pretty_printer_allocator(func, type) static V5DbgPrettyPrinterLinker _v5dbg_pretty_printer_buf_##type(type, nullptr, &func);

/// @brief Link a memory type and C++ typename
// stub:macro=$link_type_db,cpptype,etype
#define $link_type_db(cpptype, etype) static V5DbgPrettyPrinterLinker _v5dbg_pretty_printer_typedb_##etype(typeid(cpptype), etype);

#endif
7 changes: 7 additions & 0 deletions include/v5dbg/pretty.stub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
/// Stubbed version of normal $pretty_printer, automatically generated
#define $pretty_printer(func,type)
/// Stubbed version of normal $pretty_printer_allocator, automatically generated
#define $pretty_printer_allocator(func,type)
/// Stubbed version of normal $link_type_db, automatically generated
#define $link_type_db(cpptype,etype)
5 changes: 5 additions & 0 deletions src/v5dbg/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ V5Dbg_AllocateServerState()
void
V5Dbg_StartServer(v5dbg_server_state_t* pState)
{
#ifdef V5DBG_DISABLE
info("Debugger disabled, refusing to start server. See v5dbg.mk for more information");
return;
#endif

if (pState == nullptr)
{
info("Allocated state is nullptr");
Expand Down
1 change: 0 additions & 1 deletion stub.mk

This file was deleted.

59 changes: 59 additions & 0 deletions stub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import io

"""
stub.py generates stub versions of macros so you can easily disable the debugger with V5DBG_DISABLE
"""

def gen_macro(params: list[str]) -> str:
macro_name = params[0].strip()
macro_params = params[1:len(params)] # Collect rest of the macro params

print(f"> stub macro: {macro_name}")
print(f"> stub macro arguments: {macro_params}")

result = f"\n/// Stubbed version of normal {macro_name}, automatically generated\n#define {macro_name}({','.join(macro_params).strip()})"
result = result.replace("()", "") # Replace empty parenthesis with nothing as they cause compiler errors

return result

def gen_stub(stub_str: str) -> str:
result = ""

stub_str = stub_str.replace("// stub:", "")

if stub_str.startswith("macro="):
stub_str = stub_str.replace("macro=", "")
result = gen_macro(stub_str.split(","))
else:
print("gen_stub found invalid expression")

return result

def scan_file(file: io.FileIO):
# Load all lines from this file
lines = file.readlines()

file_contents_new = "#pragma once"

for line in lines:
if line.startswith("// stub:"):
# Handle macro stubbing

file_contents_new += gen_stub(line)

# File must have an extension
file_split = file.name.split(".")
ext = file_split[1]

new_file = file_split[0] + ".stub." + ext

print(f"> stub write to: {new_file}")

new_file_io = open(new_file, "w")
new_file_io.write(file_contents_new)
new_file_io.close()

stubbed_files = ["debug.h", "pretty.h"]

for file in stubbed_files:
scan_file(open(f"include/v5dbg/{file}", "r"))
14 changes: 14 additions & 0 deletions v5dbg.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# V5dbg build configuration

# About: When 'true' debugger functionality is enabled, when 'false' its disabled
# Cont: Enables the including of .stub.h files to replace debugger functionality
# Note: Enable this for a final competition build!
ENABLE_DEBUGGER := true

######## Apply configuration, DO NOT MODIFY ########

EXTRA_CXXFLAGS += $(if $(filter $(ENABLE_DEBUGGER),true),,-DV5DBG_DISABLE)

stub:
@echo "Calling stub compiler..."
@python3 stub.py
Loading