vscode debug ssh

1. 安装python debugger

2. work directory新建.vscode/launch.json

3. 配置

{
    // 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: b01",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}/src/main.py",
            "console": "integratedTerminal",
            "args": [
                "--file", "/home/quzhi/Desktop/VeriCodegen/bench/b01/b01.v",
                "--top", "b01",
                "--output", "/home/quzhi/Desktop/VeriCodegen/bench/b01/f.sv"
            ]
        },
        {
            "name": "VeriCodeGen: or1200",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}/src/main.py",
            "args": [
                "--filelist",
                "/home/ziyue/researchlib/Micro_Eletronic/VeriCodegen/bench/or1200/filelist.f",
                "--top",
                "or1200_cpu",
                "--output",
                "/home/ziyue/researchlib/Micro_Eletronic/VeriCodegen/bench/or1200/f_or1200.v",
                "--force"
            ],
            "console": "integratedTerminal"
        },
    ]
}

4. 打断点运行
单步跳过(Step Over)
作用:执行当前这一行代码,但如果这一行是函数调用,则不进入函数内部。 F10  
单步进入(Step Into)
作用:执行当前行代码,并且如果是函数调用,就会跳进函数体内继续调试。 F11
单步跳出(Step Out)
作用:当前在函数内部时,执行完当前函数剩下的内容并跳回调用处。 Shift + F11
继续运行到下一个断点(Continue) F5

### 配置 VSCode 使用 Remote SSH 调试 Python 代码 为了在 VSCode 中通过 Remote SSH 调试 Python 代码,可以按照以下方法操作: #### 安装必要的扩展 首先,在本地安装 **Remote - SSH** 扩展以及 **Python** 扩展。这可以通过打开 VSCode 的扩展市场并搜索 `Remote - SSH` 和 `Python` 来完成[^2]。 #### 设置 SSH 连接 创建一个新的连接配置文件 `.ssh/config` 或编辑现有的配置文件以添加目标服务器的信息。例如: ```plaintext Host myserver HostName example.com User username Port 22 ``` 确保能够成功通过命令行使用 `ssh myserver` 登录到远程主机。如果遇到指纹验证提示,运行以下命令来确认服务器的真实性: ```bash ssh-keygen -l -f /etc/ssh/ssh_host_key.pub ``` 并将显示的指纹与 Visual Studio Code 提供的一致性进行核对。 #### 在远程环境中设置 Python 解释器 登录到远程机器后,需确保已正确安装 Python 并可被识别。可通过执行以下命令检查版本: ```bash python --version ``` 或者对于 Python 3.x 版本: ```bash python3 --version ``` 接着,在 VSCode 内部选择合适的解释器路径。通常情况下,VSCode 自动检测可用的 Python 环境;如果没有自动检测,则手动指定解释器位置[^1]。 #### 创建调试配置 在项目根目录下找到或新建 `.vscode/launch.json` 文件,定义调试会话参数如下所示: ```json { "version": "0.2.0", "configurations": [ { "name": "Python: Remote Attach", "type": "python", "request": "attach", "connect": { "host": "localhost", "port": 5678 }, "pathMappings": [ { "localRoot": "${workspaceFolder}", "remoteRoot": "/path/to/your/project/on/server" } ] } ] } ``` 上述 JSON 块中的端口号 (`port`) 应匹配实际使用的调试监听端口,而映射路径则应反映本地工作区与远程服务上的对应关系。 #### 启动远程调试模式 最后一步是在远程终端启动调试服务器。假设已经安装好 `ptvsd`(Python Tools for Visual Studio Debugger),那么可以用下面的方式激活它: ```python import ptvsd # Allow other computers to attach to ptvsd at this IP address and port. ptvsd.enable_attach(address=('0.0.0.0', 5678), redirect_output=True) print("Waiting for debugger attach") ptvsd.wait_for_attach() ``` 这段脚本会在程序暂停等待直到有客户端附加为止。 当所有组件都准备就绪之后,点击 VSCode 左侧工具栏里的绿色三角形按钮即可触发调试过程。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值