Skip to content

Commit 756d174

Browse files
committed
debugpy: Enhance path mapping handling in PDB adapter and debug session.
Store both folder mappings from the debugger, and 1:1 file mappings . Signed-off-by: Jos Verlinde <[email protected]>
1 parent bb6dc8b commit 756d174

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

python-ecosys/debugpy/debugpy/server/debug_session.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,15 @@ def _handle_attach(self, seq, args):
252252

253253
self._debug_print(f"[DAP] Processing attach request with args: {args}")
254254
print(f"[DAP] Debug logging {'enabled' if self.debug_logging else 'disabled'} (logToFile={self.debug_logging})")
255+
256+
# get debugger root and debugee root from pathMappings
257+
for pm in args.get("pathMappings",[]):
258+
# debugee - debugger
259+
self.pdb.path_mappings.append(
260+
(pm.get("remoteRoot", "./"),
261+
pm.get("localRoot", "./"))
262+
)
263+
# # TODO: justMyCode, debugOptions ,
255264

256265
# Enable trace function
257266
self.pdb.set_trace_function(self._trace_function)

python-ecosys/debugpy/debugpy/server/pdb_adapter.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ def __init__(self):
4040
self.continue_event = False
4141
self.variables_cache = {} # frameId -> variables
4242
self.frame_id_counter = 1
43-
self.path_mappings : dict[str,str] = {} # runtime_path -> vscode_path mapping
43+
self.path_mappings : list[tuple[str,str]] = [] # runtime_path -> vscode_path mapping
44+
self.file_mappings : dict[str,str] = {} # runtime_path -> vscode_path mapping
4445

4546
def _debug_print(self, message):
4647
"""Print debug message only if debug logging is enabled."""
@@ -68,7 +69,7 @@ def set_trace_function(self, trace_func):
6869
else:
6970
raise RuntimeError("sys.settrace not available")
7071

71-
def set_breakpoints(self, filename, breakpoints):
72+
def set_breakpoints(self, filename, breakpoints:list[dict]):
7273
"""Set breakpoints for a file."""
7374
self.breakpoints[filename] = {}
7475
actual_breakpoints = []
@@ -105,7 +106,7 @@ def should_stop(self, frame, event:str, arg):
105106
if lineno in self.breakpoints[filename]:
106107
self._debug_print(f"[PDB] HIT BREAKPOINT (exact match) at {filename}:{lineno}")
107108
# Record the path mapping (in this case, they're already the same)
108-
self.path_mappings[filename] = filename
109+
self.file_mappings[filename] = filename
109110
self.hit_breakpoint = True
110111
return True
111112

@@ -119,7 +120,7 @@ def should_stop(self, frame, event:str, arg):
119120
if lineno in self.breakpoints[bp_file]:
120121
self._debug_print(f"[PDB] HIT BREAKPOINT (fallback basename match) at {filename}:{lineno} -> {bp_file}")
121122
# Record the path mapping so we can report the correct path in stack traces
122-
self.path_mappings[filename] = bp_file
123+
self.file_mappings[filename] = bp_file
123124
self.hit_breakpoint = True
124125
return True
125126

@@ -129,7 +130,7 @@ def should_stop(self, frame, event:str, arg):
129130
if lineno in self.breakpoints[bp_file]:
130131
self._debug_print(f"[PDB] HIT BREAKPOINT (relative path match) at {filename}:{lineno} -> {bp_file}")
131132
# Record the path mapping so we can report the correct path in stack traces
132-
self.path_mappings[filename] = bp_file
133+
self.file_mappings[filename] = bp_file
133134
self.hit_breakpoint = True
134135
return True
135136

@@ -216,7 +217,7 @@ def get_stack_trace(self):
216217
hint = 'normal'
217218

218219
# Use the VS Code path if we have a mapping, otherwise use the original path
219-
display_path = self.path_mappings.get(filename, filename)
220+
display_path = self.file_mappings.get(filename, filename)
220221
if filename != display_path:
221222
self._debug_print(f"[PDB] Stack trace path mapping: {filename} -> {display_path}")
222223
# Create StackFrame info

0 commit comments

Comments
 (0)