-
Notifications
You must be signed in to change notification settings - Fork 182
Description
UPDATED: #627 is marked as closed and indicates support for in-memory code that is represented in linecache, but this doesn't work with the defaults. VSCode is confused by linecache entries unless justMyCode is set to false in launch.json. The entry doesn't appear at all in the default config, so it's difficult to know it even exists, much less what it does, or what to set it to in order to get the desired behavior.
Environment data
- debugpy version: 1.5.1
- OS and version: Mac 11.6.1
- Python version (& distribution if applicable, e.g. Anaconda): 3.9.10
- Using VS Code or Visual Studio: 1.63.2
Test file:
# test_case.py
import linecache
import debugpy
print(debugpy.__version__)
func_def = """
def final_countdown(arg, count: int = 10):
print(count)
if count <= 0:
return were_leaving_together(arg)
else:
return final_countdown(arg, count - 1)
""".strip()
def were_leaving_together(arg):
print(repr(arg))
breakpoint()
filename = "<myfile>"
code_obj = compile(func_def, filename, "single")
linecache.cache[filename] = (
len(func_def),
None,
func_def.splitlines(keepends=True),
filename,
)
exec(code_obj, globals(), globals())
final_countdown("but it's still farewell")Works well (as expected) in pdb:
% python test_case.py
1.5.1
10
9
8
7
6
5
4
3
2
1
0
"but it's still farewell"
--Return--
> /Users/matt/dev/dyce/test_case.py(20)were_leaving_together()->None
-> breakpoint()
(Pdb) bt
/Users/matt/dev/dyce/test_case.py(33)<module>()
-> final_countdown("but it's still farewell")
<myfile>(6)final_countdown()
-> return final_countdown(arg, count - 1)
<myfile>(6)final_countdown()
-> return final_countdown(arg, count - 1)
<myfile>(6)final_countdown()
-> return final_countdown(arg, count - 1)
<myfile>(6)final_countdown()
-> return final_countdown(arg, count - 1)
<myfile>(6)final_countdown()
-> return final_countdown(arg, count - 1)
<myfile>(6)final_countdown()
-> return final_countdown(arg, count - 1)
<myfile>(6)final_countdown()
-> return final_countdown(arg, count - 1)
<myfile>(6)final_countdown()
-> return final_countdown(arg, count - 1)
<myfile>(6)final_countdown()
-> return final_countdown(arg, count - 1)
<myfile>(6)final_countdown()
-> return final_countdown(arg, count - 1)
<myfile>(4)final_countdown()
-> return were_leaving_together(arg)
> /Users/matt/dev/dyce/test_case.py(20)were_leaving_together()->None
-> breakpoint()
(Pdb) u
> <myfile>(4)final_countdown()
-> return were_leaving_together(arg)
(Pdb) u
> <myfile>(6)final_countdown()
-> return final_countdown(arg, count - 1)
(Pdb) l
1 def final_countdown(arg, count: int = 10):
2 print(count)
3 if count <= 0:
4 return were_leaving_together(arg)
5 else:
6 -> return final_countdown(arg, count - 1)
[EOF]
(Pdb) n
--Return--
> <myfile>(6)final_countdown()->None
-> return final_countdown(arg, count - 1)
(Pdb) l
1 def final_countdown(arg, count: int = 10):
2 print(count)
3 if count <= 0:
4 return were_leaving_together(arg)
5 else:
6 -> return final_countdown(arg, count - 1)
[EOF]
(Pdb) count
1
(Pdb) arg
"but it's still farewell"
(Pdb) cAlso works as expected with PYTHONBREAKPOINT=IPython.core.debugger.set_trace ipython test_case.py (not shown, but substantially similar to pdb above).
But VSCode gets confused:
% python -m debugpy --listen 5678 --wait-for-client test_case.pyUpon connection, VSCode breaks on line 33 (which is incorrect) and shows nothing on the stack (which is also incorrect):
From there, hitting step-over ends the program, which is also not expected.
Remote debug config:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "."
}
]
}
]
}