From 3d636125a6dc10550102603fa8622802f18a6c10 Mon Sep 17 00:00:00 2001 From: arjxn-py Date: Thu, 4 Dec 2025 17:58:32 +0530 Subject: [PATCH 1/2] Implement debugger options for `just-my-code` and internal frame filtering --- include/xeus-python/xdebugger.hpp | 4 ++++ src/xdebugger.cpp | 38 +++++++++++++++++++++++++++++++ src/xinterpreter.cpp | 15 ++++++++++++ 3 files changed, 57 insertions(+) diff --git a/include/xeus-python/xdebugger.hpp b/include/xeus-python/xdebugger.hpp index a7268818..9645c6ea 100644 --- a/include/xeus-python/xdebugger.hpp +++ b/include/xeus-python/xdebugger.hpp @@ -72,6 +72,10 @@ namespace xpyt py::object m_pydebugger; xeus::xthread m_client_runner; bool m_copy_to_globals_available; + + bool m_just_my_code = false; + bool m_filter_internal_frames = false; + std::vector m_internal_modules; }; XEUS_PYTHON_API diff --git a/src/xdebugger.cpp b/src/xdebugger.cpp index 700e4702..ea282dc3 100644 --- a/src/xdebugger.cpp +++ b/src/xdebugger.cpp @@ -60,6 +60,7 @@ namespace xpyt , m_debugpy_port("") , m_debugger_config(debugger_config) { + std::cout << "Debugger Config: " << m_debugger_config << std::endl; m_debugpy_port = xeus::find_free_port(100, 5678, 5900); register_request_handler("inspectVariables", std::bind(&debugger::inspect_variables_request, this, _1), false); register_request_handler("richInspectVariables", std::bind(&debugger::rich_inspect_variables_request, this, _1), false); @@ -68,6 +69,25 @@ namespace xpyt register_request_handler("copyToGlobals", std::bind(&debugger::copy_to_globals_request, this, _1), true); register_request_handler("modules", std::bind(&debugger::modules, this, _1), false); + // Load internal module paths from debugger_config + if (m_debugger_config.contains("internalModulePaths")) + { + for (const auto& p : m_debugger_config["internalModulePaths"]) + { + m_internal_modules.push_back(p.get()); + } + } + + // Load options + if (m_debugger_config.contains("justMyCode")) + { + m_just_my_code = m_debugger_config["justMyCode"].get(); + } + + if (m_debugger_config.contains("filterInternalFrames")) + { + m_filter_internal_frames = m_debugger_config["filterInternalFrames"].get(); + } } debugger::~debugger() @@ -176,6 +196,24 @@ namespace xpyt {"port", std::stoi(m_debugpy_port)} }; new_message["arguments"]["logToFile"] = true; + + // Add DebugStdLib when not just-my-code + if (!m_just_my_code) + { + new_message["arguments"]["debugOptions"] = {"DebugStdLib"}; + } + + // Dynamic skip rules + if (m_filter_internal_frames) + { + nl::json rules = nl::json::array(); + for (const auto& path : m_internal_modules) + { + rules.push_back({{"path", path}, {"include", false}}); + } + new_message["arguments"]["rules"] = rules; + } + return forward_message(new_message); } diff --git a/src/xinterpreter.cpp b/src/xinterpreter.cpp index ff210b2d..4fe2d99d 100644 --- a/src/xinterpreter.cpp +++ b/src/xinterpreter.cpp @@ -81,6 +81,21 @@ namespace xpyt instanciate_ipython_shell(); + py::dict modules = sys.attr("modules"); + std::vector internal_mod_paths; + internal_mod_paths.reserve(len(modules)); + + for (auto item : modules) + { + py::object mod = py::reinterpret_borrow(item.second); + if (py::hasattr(mod, "__file__")) + { + std::string path = mod.attr("__file__").cast(); + internal_mod_paths.push_back(path); + } + } + + m_ipython_shell_app.attr("initialize")(use_jedi_for_completion()); m_ipython_shell = m_ipython_shell_app.attr("shell"); From 40d3beb4ad652a8a65d3ede93a48e5fe56d593fb Mon Sep 17 00:00:00 2001 From: arjxn-py Date: Wed, 10 Dec 2025 16:26:24 +0530 Subject: [PATCH 2/2] remove explicit config loading and add module collection in raw interpreter as well --- src/xdebugger.cpp | 22 ++-------------------- src/xinterpreter_raw.cpp | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/xdebugger.cpp b/src/xdebugger.cpp index ea282dc3..c8c04e65 100644 --- a/src/xdebugger.cpp +++ b/src/xdebugger.cpp @@ -59,6 +59,8 @@ namespace xpyt , m_debugpy_host("127.0.0.1") , m_debugpy_port("") , m_debugger_config(debugger_config) + , m_just_my_code(false) + , m_filter_internal_frames(true) { std::cout << "Debugger Config: " << m_debugger_config << std::endl; m_debugpy_port = xeus::find_free_port(100, 5678, 5900); @@ -68,26 +70,6 @@ namespace xpyt register_request_handler("configurationDone", std::bind(&debugger::configuration_done_request, this, _1), true); register_request_handler("copyToGlobals", std::bind(&debugger::copy_to_globals_request, this, _1), true); register_request_handler("modules", std::bind(&debugger::modules, this, _1), false); - - // Load internal module paths from debugger_config - if (m_debugger_config.contains("internalModulePaths")) - { - for (const auto& p : m_debugger_config["internalModulePaths"]) - { - m_internal_modules.push_back(p.get()); - } - } - - // Load options - if (m_debugger_config.contains("justMyCode")) - { - m_just_my_code = m_debugger_config["justMyCode"].get(); - } - - if (m_debugger_config.contains("filterInternalFrames")) - { - m_filter_internal_frames = m_debugger_config["filterInternalFrames"].get(); - } } debugger::~debugger() diff --git a/src/xinterpreter_raw.cpp b/src/xinterpreter_raw.cpp index 0282f454..6ced62ce 100644 --- a/src/xinterpreter_raw.cpp +++ b/src/xinterpreter_raw.cpp @@ -71,6 +71,20 @@ namespace xpyt py::gil_scoped_acquire acquire; py::module sys = py::module::import("sys"); + + py::dict modules = sys.attr("modules"); + std::vector internal_mod_paths; + internal_mod_paths.reserve(py::len(modules)); + + for (auto item : modules) + { + py::object mod = py::reinterpret_borrow(item.second); + if (py::hasattr(mod, "__file__")) + { + std::string path = mod.attr("__file__").cast(); + internal_mod_paths.push_back(path); + } + } py::module jedi = py::module::import("jedi"); jedi.attr("api").attr("environment").attr("get_default_environment") = py::cpp_function([jedi]() { jedi.attr("api").attr("environment").attr("SameEnvironment")();