Skip to content

Commit 3d63612

Browse files
arjxn-pymartinRenou
authored andcommitted
Implement debugger options for just-my-code and internal frame filtering
1 parent 5e5fd29 commit 3d63612

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

include/xeus-python/xdebugger.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ namespace xpyt
7272
py::object m_pydebugger;
7373
xeus::xthread m_client_runner;
7474
bool m_copy_to_globals_available;
75+
76+
bool m_just_my_code = false;
77+
bool m_filter_internal_frames = false;
78+
std::vector<std::string> m_internal_modules;
7579
};
7680

7781
XEUS_PYTHON_API

src/xdebugger.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ namespace xpyt
6060
, m_debugpy_port("")
6161
, m_debugger_config(debugger_config)
6262
{
63+
std::cout << "Debugger Config: " << m_debugger_config << std::endl;
6364
m_debugpy_port = xeus::find_free_port(100, 5678, 5900);
6465
register_request_handler("inspectVariables", std::bind(&debugger::inspect_variables_request, this, _1), false);
6566
register_request_handler("richInspectVariables", std::bind(&debugger::rich_inspect_variables_request, this, _1), false);
@@ -68,6 +69,25 @@ namespace xpyt
6869
register_request_handler("copyToGlobals", std::bind(&debugger::copy_to_globals_request, this, _1), true);
6970
register_request_handler("modules", std::bind(&debugger::modules, this, _1), false);
7071

72+
// Load internal module paths from debugger_config
73+
if (m_debugger_config.contains("internalModulePaths"))
74+
{
75+
for (const auto& p : m_debugger_config["internalModulePaths"])
76+
{
77+
m_internal_modules.push_back(p.get<std::string>());
78+
}
79+
}
80+
81+
// Load options
82+
if (m_debugger_config.contains("justMyCode"))
83+
{
84+
m_just_my_code = m_debugger_config["justMyCode"].get<bool>();
85+
}
86+
87+
if (m_debugger_config.contains("filterInternalFrames"))
88+
{
89+
m_filter_internal_frames = m_debugger_config["filterInternalFrames"].get<bool>();
90+
}
7191
}
7292

7393
debugger::~debugger()
@@ -176,6 +196,24 @@ namespace xpyt
176196
{"port", std::stoi(m_debugpy_port)}
177197
};
178198
new_message["arguments"]["logToFile"] = true;
199+
200+
// Add DebugStdLib when not just-my-code
201+
if (!m_just_my_code)
202+
{
203+
new_message["arguments"]["debugOptions"] = {"DebugStdLib"};
204+
}
205+
206+
// Dynamic skip rules
207+
if (m_filter_internal_frames)
208+
{
209+
nl::json rules = nl::json::array();
210+
for (const auto& path : m_internal_modules)
211+
{
212+
rules.push_back({{"path", path}, {"include", false}});
213+
}
214+
new_message["arguments"]["rules"] = rules;
215+
}
216+
179217
return forward_message(new_message);
180218
}
181219

src/xinterpreter.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ namespace xpyt
8181

8282
instanciate_ipython_shell();
8383

84+
py::dict modules = sys.attr("modules");
85+
std::vector<std::string> internal_mod_paths;
86+
internal_mod_paths.reserve(len(modules));
87+
88+
for (auto item : modules)
89+
{
90+
py::object mod = py::reinterpret_borrow<py::object>(item.second);
91+
if (py::hasattr(mod, "__file__"))
92+
{
93+
std::string path = mod.attr("__file__").cast<std::string>();
94+
internal_mod_paths.push_back(path);
95+
}
96+
}
97+
98+
8499
m_ipython_shell_app.attr("initialize")(use_jedi_for_completion());
85100
m_ipython_shell = m_ipython_shell_app.attr("shell");
86101

0 commit comments

Comments
 (0)