From dadcf59a79735f1dc144c422de09404a882e20c5 Mon Sep 17 00:00:00 2001 From: interfiberschool <117294755+interfiberschool@users.noreply.github.com> Date: Tue, 18 Nov 2025 16:17:57 +0000 Subject: [PATCH 1/7] feat: init stub.py --- include/v5dbg/debug.h | 5 ++++ include/v5dbg/debug.stub.h | 11 ++++++++ stub.mk | 8 +++++- stub.py | 54 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 include/v5dbg/debug.stub.h create mode 100644 stub.py diff --git a/include/v5dbg/debug.h b/include/v5dbg/debug.h index 07e001b..4568647 100644 --- a/include/v5dbg/debug.h +++ b/include/v5dbg/debug.h @@ -26,6 +26,7 @@ class V5DbgAutoTask * 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); @@ -33,6 +34,7 @@ class V5DbgAutoTask * @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{}; \ @@ -50,14 +52,17 @@ 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; diff --git a/include/v5dbg/debug.stub.h b/include/v5dbg/debug.stub.h new file mode 100644 index 0000000..6ce1940 --- /dev/null +++ b/include/v5dbg/debug.stub.h @@ -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() \ No newline at end of file diff --git a/stub.mk b/stub.mk index 9bb5093..4f453f5 100644 --- a/stub.mk +++ b/stub.mk @@ -1 +1,7 @@ -# Handles generating the stubbed versions of functions when enabled via a config variable \ No newline at end of file +# Handles generating the stubbed versions of functions when enabled via a config variable + +define stub_generate_file() + src_file = $(1) + @echo "Generate stub: $(src_file)" +endef + diff --git a/stub.py b/stub.py new file mode 100644 index 0000000..844f5c9 --- /dev/null +++ b/stub.py @@ -0,0 +1,54 @@ +import os +import io + +""" +stub.py generates stub versions of macros and functions so you can easily disable the debugger +""" + +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}") + + return f"\n/// Stubbed version of normal {macro_name}, automatically generated\n#define {macro_name}({','.join(macro_params).strip()})" + +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() + +scan_file(open("include/v5dbg/debug.h", "r")) \ No newline at end of file From da26145bb1642c5116a0bab7e3d5d30c6b443764 Mon Sep 17 00:00:00 2001 From: Hunter Date: Tue, 18 Nov 2025 17:06:41 -0500 Subject: [PATCH 2/7] feat(stub): pretty.h generation + v5dbg.mk config file --- Makefile | 3 +-- include/v5dbg/debug.h | 6 ++++++ include/v5dbg/pretty.h | 9 +++++++++ include/v5dbg/pretty.stub.h | 8 ++++++++ stub.mk | 7 ------- stub.py | 8 +++++--- v5dbg.mk | 5 +++++ 7 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 include/v5dbg/pretty.stub.h delete mode 100644 stub.mk create mode 100644 v5dbg.mk diff --git a/Makefile b/Makefile index f1bd9fd..7a133ee 100644 --- a/Makefile +++ b/Makefile @@ -40,5 +40,4 @@ TEMPLATE_FILES=$(INCDIR)/$(LIBNAME)/*.h $(INCDIR)/$(LIBNAME)/*.hpp ################################################################################ ################################################################################ ########## Nothing below this line should be edited by typical users ########### --include ./common.mk --include ./stub.mk +-include ./common.mk \ No newline at end of file diff --git a/include/v5dbg/debug.h b/include/v5dbg/debug.h index 4568647..ba4e800 100644 --- a/include/v5dbg/debug.h +++ b/include/v5dbg/debug.h @@ -22,6 +22,10 @@ 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 @@ -66,3 +70,5 @@ class V5DbgAutoTask // stub:macro=$ntask #define $ntask V5DbgAutoTask _v5dbg_ctask; + +#endif \ No newline at end of file diff --git a/include/v5dbg/pretty.h b/include/v5dbg/pretty.h index f7c6524..ac7d0df 100644 --- a/include/v5dbg/pretty.h +++ b/include/v5dbg/pretty.h @@ -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 \ No newline at end of file diff --git a/include/v5dbg/pretty.stub.h b/include/v5dbg/pretty.stub.h new file mode 100644 index 0000000..e7cb49b --- /dev/null +++ b/include/v5dbg/pretty.stub.h @@ -0,0 +1,8 @@ +#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) diff --git a/stub.mk b/stub.mk deleted file mode 100644 index 4f453f5..0000000 --- a/stub.mk +++ /dev/null @@ -1,7 +0,0 @@ -# Handles generating the stubbed versions of functions when enabled via a config variable - -define stub_generate_file() - src_file = $(1) - @echo "Generate stub: $(src_file)" -endef - diff --git a/stub.py b/stub.py index 844f5c9..6fe04c0 100644 --- a/stub.py +++ b/stub.py @@ -1,8 +1,7 @@ -import os import io """ -stub.py generates stub versions of macros and functions so you can easily disable the debugger +stub.py generates stub versions of macros so you can easily disable the debugger with V5DBG_DISABLE """ def gen_macro(params: list[str]) -> str: @@ -51,4 +50,7 @@ def scan_file(file: io.FileIO): new_file_io.write(file_contents_new) new_file_io.close() -scan_file(open("include/v5dbg/debug.h", "r")) \ No newline at end of file +stubbed_files = ["debug.h", "pretty.h"] + +for file in stubbed_files: + scan_file(open(f"include/v5dbg/{file}", "r")) \ No newline at end of file diff --git a/v5dbg.mk b/v5dbg.mk new file mode 100644 index 0000000..8e8be69 --- /dev/null +++ b/v5dbg.mk @@ -0,0 +1,5 @@ +# V5dbg build configuration +# Makefiles are shit... 11/18/25 + +# Enable v5dbg? When disabled .stub.h files are included to overwrite macros +ENABLE_DEBUGGER := true \ No newline at end of file From b334a3884434e4381e47c38bfc5631ab2a626ed5 Mon Sep 17 00:00:00 2001 From: interfiberschool <117294755+interfiberschool@users.noreply.github.com> Date: Wed, 19 Nov 2025 13:55:19 +0000 Subject: [PATCH 3/7] feat(stub): fix stub generator output + impl v5dbg.mk config --- Makefile | 4 +++- include/v5dbg/debug.stub.h | 6 +++--- include/v5dbg/pretty.stub.h | 3 +-- stub.py | 5 ++++- v5dbg.mk | 6 +++++- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 7a133ee..c54f9db 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,8 @@ WARNFLAGS+= EXTRA_CFLAGS= EXTRA_CXXFLAGS= +-include ./v5dbg.mk + # Set to 1 to enable hot/cold linking USE_PACKAGE:=1 @@ -33,7 +35,7 @@ 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 diff --git a/include/v5dbg/debug.stub.h b/include/v5dbg/debug.stub.h index 6ce1940..0671170 100644 --- a/include/v5dbg/debug.stub.h +++ b/include/v5dbg/debug.stub.h @@ -1,11 +1,11 @@ #pragma once /// Stubbed version of normal $function, automatically generated -#define $function() +#define $function /// Stubbed version of normal $expose, automatically generated #define $expose(target) /// Stubbed version of normal $break, automatically generated -#define $break() +#define $break /// Stubbed version of normal $cbreak, automatically generated #define $cbreak(value) /// Stubbed version of normal $ntask, automatically generated -#define $ntask() \ No newline at end of file +#define $ntask \ No newline at end of file diff --git a/include/v5dbg/pretty.stub.h b/include/v5dbg/pretty.stub.h index e7cb49b..7bf0f45 100644 --- a/include/v5dbg/pretty.stub.h +++ b/include/v5dbg/pretty.stub.h @@ -1,8 +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) +#define $link_type_db(cpptype,etype) \ No newline at end of file diff --git a/stub.py b/stub.py index 6fe04c0..901ae7d 100644 --- a/stub.py +++ b/stub.py @@ -11,7 +11,10 @@ def gen_macro(params: list[str]) -> str: print(f"> stub macro: {macro_name}") print(f"> stub macro arguments: {macro_params}") - return f"\n/// Stubbed version of normal {macro_name}, automatically generated\n#define {macro_name}({','.join(macro_params).strip()})" + 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 = "" diff --git a/v5dbg.mk b/v5dbg.mk index 8e8be69..03c66da 100644 --- a/v5dbg.mk +++ b/v5dbg.mk @@ -2,4 +2,8 @@ # Makefiles are shit... 11/18/25 # Enable v5dbg? When disabled .stub.h files are included to overwrite macros -ENABLE_DEBUGGER := true \ No newline at end of file +ENABLE_DEBUGGER := false + +######## Apply configuration, DO NOT MODIFY ######## + +EXTRA_CXXFLAGS += $(if $(filter $(ENABLE_DEBUGGER),true),"",-DV5DBG_DISABLE) \ No newline at end of file From 5944c9707e305ae99e16302e737611c278c86793 Mon Sep 17 00:00:00 2001 From: interfiberschool <117294755+interfiberschool@users.noreply.github.com> Date: Wed, 19 Nov 2025 13:58:26 +0000 Subject: [PATCH 4/7] doc: v5dbg.mk --- v5dbg.mk | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/v5dbg.mk b/v5dbg.mk index 03c66da..99187da 100644 --- a/v5dbg.mk +++ b/v5dbg.mk @@ -1,9 +1,15 @@ # V5dbg build configuration # Makefiles are shit... 11/18/25 -# Enable v5dbg? When disabled .stub.h files are included to overwrite macros -ENABLE_DEBUGGER := false +# 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) \ No newline at end of file +EXTRA_CXXFLAGS += $(if $(filter $(ENABLE_DEBUGGER),true),"",-DV5DBG_DISABLE) + +stub: + @echo "Calling stub compiler..." + @python3 stub.py \ No newline at end of file From d5d1f18b9b77367a15449270173c9a13d32f64b1 Mon Sep 17 00:00:00 2001 From: interfiberschool <117294755+interfiberschool@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:01:27 +0000 Subject: [PATCH 5/7] feat+fix(stub+v5dbg): don't start server when disabled + fix linker error when debugger is enabled --- src/v5dbg/server/server.cpp | 5 +++++ v5dbg.mk | 3 +-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/v5dbg/server/server.cpp b/src/v5dbg/server/server.cpp index a470648..84f12fe 100644 --- a/src/v5dbg/server/server.cpp +++ b/src/v5dbg/server/server.cpp @@ -23,6 +23,11 @@ V5Dbg_AllocateServerState() void V5Dbg_StartServer(v5dbg_server_state_t* pState) { + #ifdef V5DBG_DISABLE + info("Debugger disable, refusing to start server. See v5dbg.mk for more information"); + return; + #endif + if (pState == nullptr) { info("Allocated state is nullptr"); diff --git a/v5dbg.mk b/v5dbg.mk index 99187da..a089f7e 100644 --- a/v5dbg.mk +++ b/v5dbg.mk @@ -1,5 +1,4 @@ # V5dbg build configuration -# Makefiles are shit... 11/18/25 # About: When 'true' debugger functionality is enabled, when 'false' its disabled # Cont: Enables the including of .stub.h files to replace debugger functionality @@ -8,7 +7,7 @@ ENABLE_DEBUGGER := true ######## Apply configuration, DO NOT MODIFY ######## -EXTRA_CXXFLAGS += $(if $(filter $(ENABLE_DEBUGGER),true),"",-DV5DBG_DISABLE) +EXTRA_CXXFLAGS += $(if $(filter $(ENABLE_DEBUGGER),true),,-DV5DBG_DISABLE) stub: @echo "Calling stub compiler..." From 204b2a64e7ac808601678993e40520750891a0e2 Mon Sep 17 00:00:00 2001 From: interfiberschool <117294755+interfiberschool@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:08:14 +0000 Subject: [PATCH 6/7] fix: spelling in server.cpp disabled message --- src/v5dbg/server/server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v5dbg/server/server.cpp b/src/v5dbg/server/server.cpp index 84f12fe..a47e56a 100644 --- a/src/v5dbg/server/server.cpp +++ b/src/v5dbg/server/server.cpp @@ -24,7 +24,7 @@ void V5Dbg_StartServer(v5dbg_server_state_t* pState) { #ifdef V5DBG_DISABLE - info("Debugger disable, refusing to start server. See v5dbg.mk for more information"); + info("Debugger disabled, refusing to start server. See v5dbg.mk for more information"); return; #endif From 97a5bb3b0a0ced62055b611a96dbd115ae180eb5 Mon Sep 17 00:00:00 2001 From: interfiberschool <117294755+interfiberschool@users.noreply.github.com> Date: Wed, 19 Nov 2025 14:09:39 +0000 Subject: [PATCH 7/7] rm: config.h, replaced with v5dbg.mk --- include/v5dbg/config.h | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 include/v5dbg/config.h diff --git a/include/v5dbg/config.h b/include/v5dbg/config.h deleted file mode 100644 index ddaa8dd..0000000 --- a/include/v5dbg/config.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -/* - * V5dbg debug server configuration - * Any changes made here require a recompile to take effect -*/ - -/** - * @brief Uncomment to disable all debugger functionality - * All debugger functions are replaced by stubbed versions located in src/stubs.cpp which is only compiled when this macro is defined -*/ -// #define V5DBG_DEBUGGER_DISABLE \ No newline at end of file