You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode调试器无法在Rust代码断点处停止问题求助

解决Mac OS下rustlings调试断点无法触发的问题

核心问题排查

  1. 单独rustc编译未生成调试信息:直接用rustc intro2.rs编译时,默认不包含调试符号,导致调试器无法识别断点位置。
  2. launch.json配置冲突:同时指定program和cargo字段时,CodeLLDB会优先走cargo构建流程,忽略手动指定的program路径,调试目标不符合预期。
  3. rustlings项目结构特殊性:单个exercise并非独立可执行文件,而是作为模块被rustlings主程序调用,直接调试主程序时需指定执行目标exercise的参数。

具体解决方案

方案1:单独调试单个exercise文件

  1. 重新编译intro2.rs并生成调试信息:

    rustc -g intro2.rs
    

    -g参数强制生成调试符号,确保调试器能关联代码与断点。

  2. 修改launch.json,添加单独调试该可执行文件的配置(移除冲突的cargo字段):

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "lldb",
                "request": "launch",
                "name": "Debug intro2",
                "program": "/Users/mo0dy/Desktop/.rustuff/rustlings/exercises/intro/intro2",
                "args": [],
                "cwd": "${workspaceFolder}/exercises/intro"
            }
            // 保留原有其他配置...
        ]
    }
    

    选择此配置启动调试,断点即可正常触发。

方案2:通过rustlings主程序调试目标exercise

  1. 确认已通过cargo build生成带调试信息的rustlings可执行文件(用户已完成,提示unoptimized + debuginfo说明编译正确)。

  2. 修改launch.json中调试rustlings的配置,添加执行目标exercise的参数,并移除冲突的program字段:

    {
        "type": "lldb",
        "request": "launch",
        "name": "Debug rustlings run intro2",
        "cargo": {
            "args": [
                "build",
                "--bin=rustlings",
                "--package=rustlings"
            ],
            "filter": {
                "name": "rustlings",
                "kind": "bin"
            }
        },
        "args": ["run", "intro2"], // 指定运行intro2 exercise
        "cwd": "${workspaceFolder}"
    }
    

    启动此配置后,rustlings主程序会执行intro2的代码,断点即可触发。

额外注意事项

  • 确认断点打在有效代码行上,避免空行、注释或编译器会优化掉的无副作用语句。
  • 检查rust-toolchain版本为稳定版,避免debug信息格式与LLDB不兼容。

内容的提问来源于stack exchange,提问作者m.o.0.d.y

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 06:55:42