From b6c030ac15cca40da1baef17fe563bbf5c98aac0 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Tue, 26 Aug 2025 23:44:47 +0800 Subject: [PATCH] fix OS macro for debugger --- CMakeLists.txt | 2 +- include/pocketpy/debugger/core.h | 4 ++++ include/pocketpy/pocketpy.h | 7 +++++++ src/debugger/core.c | 4 ++++ src/debugger/dap.c | 6 +++++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fd4aca2..d92008e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ endif() if(MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8 /jumptablerdata") - add_compile_options(/wd4267 /wd4244 /wd4146 /experimental:c11atomics) + add_compile_options(/wd4267 /wd4244 /wd4146 /wd4819 /experimental:c11atomics) if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Ox") diff --git a/include/pocketpy/debugger/core.h b/include/pocketpy/debugger/core.h index e36d7df7..74844820 100644 --- a/include/pocketpy/debugger/core.h +++ b/include/pocketpy/debugger/core.h @@ -5,6 +5,8 @@ #include "pocketpy/common/vector.h" #include "pocketpy/pocketpy.h" +#if PK_ENABLE_OS + typedef enum { C11_STEP_IN, C11_STEP_OVER, C11_STEP_OUT, C11_STEP_CONTINUE } C11_STEP_MODE; typedef enum { C11_DEBUGGER_NOSTOP, C11_DEBUGGER_STEP, C11_DEBUGGER_EXCEPTION, C11_DEBUGGER_BP} C11_STOP_REASON; typedef enum { @@ -26,3 +28,5 @@ int c11_debugger_setbreakpoint(const char* filename, int lineno); int c11_debugger_reset_breakpoints_by_source(const char* sourcesname); C11_STOP_REASON c11_debugger_should_pause(void); int c11_debugger_should_keep_pause(void); + +#endif // PK_ENABLE_OS \ No newline at end of file diff --git a/include/pocketpy/pocketpy.h b/include/pocketpy/pocketpy.h index 2f23c660..d9741ae5 100644 --- a/include/pocketpy/pocketpy.h +++ b/include/pocketpy/pocketpy.h @@ -708,10 +708,17 @@ PK_API void py_profiler_reset(); PK_API char* py_profiler_report(); /************* DAP *************/ +#if PK_ENABLE_OS PK_API void py_debugger_waitforattach(const char* hostname, unsigned short port); PK_API bool py_debugger_isattached(); PK_API void py_debugger_exceptionbreakpoint(py_Ref exc); PK_API void py_debugger_exit(int exitCode); +#else +#define py_debugger_waitforattach(hostname, port) +#define py_debugger_isattached() (false) +#define py_debugger_exceptionbreakpoint(exc) +#define py_debugger_exit(exitCode) +#endif /************* Unchecked Functions *************/ diff --git a/src/debugger/core.c b/src/debugger/core.c index 591c9cec..8d48b63c 100644 --- a/src/debugger/core.c +++ b/src/debugger/core.c @@ -3,6 +3,8 @@ #include "pocketpy/pocketpy.h" #include +#if PK_ENABLE_OS + #include "pocketpy/debugger/core.h" typedef struct c11_debugger_breakpoint { @@ -396,3 +398,5 @@ bool c11_debugger_unfold_var(int var_id, c11_sbuf* buffer) { } #undef python_vars + +#endif // PK_ENABLE_OS diff --git a/src/debugger/dap.c b/src/debugger/dap.c index 969b6eb7..7ad8bf51 100644 --- a/src/debugger/dap.c +++ b/src/debugger/dap.c @@ -6,6 +6,8 @@ #include "pocketpy/objects/exception.h" #include "pocketpy/pocketpy.h" +#if PK_ENABLE_OS + #define DAP_COMMAND_LIST(X) \ X(initialize) \ X(setBreakpoints) \ @@ -550,4 +552,6 @@ void py_debugger_exceptionbreakpoint(py_Ref exc) { c11_dap_handle_message(); } } -} \ No newline at end of file +} + +#endif // PK_ENABLE_OS \ No newline at end of file