14
14
VARREF_GLOBALS_SPECIAL = 4
15
15
16
16
17
+ # Also try checking by basename for path mismatches
18
+ def basename (path :str ):
19
+ return path .split ('/' )[- 1 ] if '/' in path else path
20
+
21
+ # Check if this might be a relative path match
22
+ def ends_with_path (full_path :str , relative_path :str ):
23
+ """Check if full_path ends with relative_path components."""
24
+ full_parts = full_path .replace ('\\ ' , '/' ).split ('/' )
25
+ rel_parts = relative_path .replace ('\\ ' , '/' ).split ('/' )
26
+ if len (rel_parts ) > len (full_parts ):
27
+ return False
28
+ return full_parts [- len (rel_parts ):] == rel_parts
29
+
17
30
class PdbAdapter :
18
31
"""Adapter between DAP protocol and MicroPython's sys.settrace functionality."""
19
32
@@ -27,14 +40,14 @@ def __init__(self):
27
40
self .continue_event = False
28
41
self .variables_cache = {} # frameId -> variables
29
42
self .frame_id_counter = 1
30
- self .path_mapping = {} # runtime_path -> vscode_path mapping
43
+ self .path_mappings : dict [ str , str ] = {} # runtime_path -> vscode_path mapping
31
44
32
45
def _debug_print (self , message ):
33
46
"""Print debug message only if debug logging is enabled."""
34
47
if hasattr (self , '_debug_session' ) and self ._debug_session .debug_logging : # type: ignore
35
48
print (message )
36
49
37
- def _normalize_path (self , path ):
50
+ def _normalize_path (self , path : str ):
38
51
"""Normalize a file path for consistent comparisons."""
39
52
# Convert to absolute path if possible
40
53
try :
@@ -44,7 +57,6 @@ def _normalize_path(self, path):
44
57
path = os .path .realpath (path )
45
58
except :
46
59
pass
47
-
48
60
# Ensure consistent separators
49
61
path = path .replace ('\\ ' , '/' )
50
62
return path
@@ -80,42 +92,23 @@ def set_breakpoints(self, filename, breakpoints):
80
92
81
93
return actual_breakpoints
82
94
83
- def should_stop (self , frame , event , arg ):
95
+ def should_stop (self , frame , event : str , arg ):
84
96
"""Determine if execution should stop at this point."""
85
97
self .current_frame = frame
86
98
self .hit_breakpoint = False
87
99
88
100
# Get frame information
89
101
filename = frame .f_code .co_filename
90
102
lineno = frame .f_lineno
91
-
92
- # Debug: print filename and line for debugging
93
- if event == TRACE_LINE and lineno in [20 , 21 , 22 , 23 , 24 ]: # Only log lines near our breakpoints
94
- self ._debug_print (f"[PDB] Checking { filename } :{ lineno } (event={ event } )" )
95
- self ._debug_print (f"[PDB] Available breakpoint files: { list (self .breakpoints .keys ())} " )
96
-
97
103
# Check for exact filename match first
98
104
if filename in self .breakpoints :
99
105
if lineno in self .breakpoints [filename ]:
100
106
self ._debug_print (f"[PDB] HIT BREAKPOINT (exact match) at { filename } :{ lineno } " )
101
107
# Record the path mapping (in this case, they're already the same)
102
- self .path_mapping [filename ] = filename
108
+ self .path_mappings [filename ] = filename
103
109
self .hit_breakpoint = True
104
110
return True
105
111
106
- # Also try checking by basename for path mismatches
107
- def basename (path ):
108
- return path .split ('/' )[- 1 ] if '/' in path else path
109
-
110
- # Check if this might be a relative path match
111
- def ends_with_path (full_path , relative_path ):
112
- """Check if full_path ends with relative_path components."""
113
- full_parts = full_path .replace ('\\ ' , '/' ).split ('/' )
114
- rel_parts = relative_path .replace ('\\ ' , '/' ).split ('/' )
115
- if len (rel_parts ) > len (full_parts ):
116
- return False
117
- return full_parts [- len (rel_parts ):] == rel_parts
118
-
119
112
file_basename = basename (filename )
120
113
self ._debug_print (f"[PDB] Fallback basename match: '{ file_basename } ' vs available files" )
121
114
for bp_file in self .breakpoints :
@@ -126,7 +119,7 @@ def ends_with_path(full_path, relative_path):
126
119
if lineno in self .breakpoints [bp_file ]:
127
120
self ._debug_print (f"[PDB] HIT BREAKPOINT (fallback basename match) at { filename } :{ lineno } -> { bp_file } " )
128
121
# Record the path mapping so we can report the correct path in stack traces
129
- self .path_mapping [filename ] = bp_file
122
+ self .path_mappings [filename ] = bp_file
130
123
self .hit_breakpoint = True
131
124
return True
132
125
@@ -136,7 +129,7 @@ def ends_with_path(full_path, relative_path):
136
129
if lineno in self .breakpoints [bp_file ]:
137
130
self ._debug_print (f"[PDB] HIT BREAKPOINT (relative path match) at { filename } :{ lineno } -> { bp_file } " )
138
131
# Record the path mapping so we can report the correct path in stack traces
139
- self .path_mapping [filename ] = bp_file
132
+ self .path_mappings [filename ] = bp_file
140
133
self .hit_breakpoint = True
141
134
return True
142
135
@@ -223,7 +216,7 @@ def get_stack_trace(self):
223
216
hint = 'normal'
224
217
225
218
# Use the VS Code path if we have a mapping, otherwise use the original path
226
- display_path = self .path_mapping .get (filename , filename )
219
+ display_path = self .path_mappings .get (filename , filename )
227
220
if filename != display_path :
228
221
self ._debug_print (f"[PDB] Stack trace path mapping: { filename } -> { display_path } " )
229
222
# Create StackFrame info
0 commit comments