VSCode Debug调试

让远程调试生效:

VScode Remote 远程开发与调试 - 简书 (jianshu.com)

安装Remote Development插件;

ctrl+shift+p打开设置Remote-SSH-Settings,设置Remote.SSH:Show Login Terminal为true;

安装完插件后左下角会出现一个绿色的图标,点击选择,然后在最上方命令窗口Connect to Host

输入密码

 

让Step into(F11)生效:

在config文件里,加一条:

"justMyCode": false

 

{
    // 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: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal",
            "stopOnEntry": true,
            "justMyCode": false
        }
    ]
}

调试tensorboard plugin:

plugin要用python setup.py develop来安装

代码里,子线程、子进程的代码,必须用pdb.set_trace()来设置断点;(提前import pdb)

which tensorboard找到其路径

python -m pdb <tensorboard路径> --logdir=./samples --port=XXXX --bind_all

pdb里面,用“b <文件绝对路径>:<行号>”来设断点


用VSCode来调试tensorboard plugin:

plugin要用python setup.py develop来安装

pip install debugpy

代码里不要使用pdb.set_trace();直接在代码上设断点;

which tensorboard找到其路径

python -m debugpy --listen 5678 /home/gaoteng/anaconda3/envs/pytorch_debug_0412/bin/tensorboard --logdir=./samples --bind_all --port 6013

launch.json:

{
    // 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: Attach using Process Id",
            "type": "python",
            "request": "attach",
            "processId": "${command:pickProcess}",
            "connect": {
                "host": "localhost",
                "port": 5678
            }
        }
    ]
}

有3个进程,attach进程id在中间的那个;


如何Debug PyTorch的Python&C++:

如何对Pytorch进行“深入”的DEBUG - Oldpan的个人博客

可以使用python -m pdb my_pytorch_model.py来代替文中提到的pycharm,来启动python程序;

文中提到的launch.json,是在打开pytorch源码目录之后,Debug时,手动填写的;

注意:Attach到该进程时,要等待一两分钟,才能attach完成并继续执行,看上去像死机了一样;

填写的launch.json:

{
    // 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": "(gdb) Attach",
            "type": "cppdbg",
            "request": "attach",
            "program": "/home/gaoteng/anaconda3/envs/pytorch_debug_0412/bin/python",
            "processId": "${command:pickProcess}",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]            
        }
    ]
}

需要安装C++ Extension Pack,才能支持pdb的debug:

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值