Skip to content

Support debugging python files executed with exec #627

@XYUU

Description

@XYUU

I expect that the source file can be specified in VSCode when prompted as follows:
Could not load source '<string>': Unable to retrieve source for <string>.

Expect to be able to debug myCode.py and pause at the breakpoint method,When VSCode cannot find the source file, the developer can manually specify the source file.

Test case:

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Eval Debug",
            "type": "python",
            "request": "attach",
            "listen": {
                "host": "localhost",
                "port": 5678
            },
            "pathMappings": [
                {
                    "localRoot": "${workspaceFolder}",
                    "remoteRoot": "."
                }
            ]
        }
    ]
}

myCode.py

import debugpy

print("Waiting for debugger attach")
debugpy.connect(('localhost', 5678))
debugpy.breakpoint()
print("Then End")

Test.py

f = open('./myCode.py')
code = f.read()
f.close()
compiled = compile(code,'<string>','exec')
exec(compiled)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions