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

VSCode+GDB调试AT&T汇编代码时断点失效问题排查

解决AT&T汇编调试断点不触发的配置修改

核心问题原因

断点未触发的关键原因是编译时未生成调试符号信息,GDB无法定位到汇编代码中的断点位置。同时需要确保编译参数适配AT&T汇编的调试需求。


修改后的task.json配置

需要在gcc的编译参数中添加-g(生成调试符号),这是让断点生效的必要条件:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "gcc",
            "args": [
                "-g",          // 生成调试符号,必须添加
                "-nostdlib",   // 不使用标准库(按需保留)
                "-o",          // 指定输出文件名
                "${fileDirname}/${fileBasenameNoExtension}",
                "${fileDirname}/${fileBasenameNoExtension}.s"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": {
                "pattern": {
                  "regexp": "error"
                }
              },
            "presentation": {
                "reveal": "silent",
                "panel": "dedicated",
                "focus": true,
                "clear": true
              }
        }
    ]
}

修改后的launch.json配置

调整stopAtEntry并添加AT&T汇编语法适配命令,确保调试环境匹配:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "启动程序",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": true,  // 程序启动时停在入口点,便于验证调试是否生效
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为GDB启用漂亮打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "设置GDB使用AT&T汇编语法显示",
                    "text": "set disassembly-flavor att",
                    "ignoreFailures": false
                }
            ],
            "preLaunchTask": "build",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

额外注意事项

  • 若你的汇编代码是32位架构,需在gcc的args中添加-m32参数,同时安装32位编译依赖:sudo apt install gcc-multilib gdb-multiarch
  • 断点要设置在有效指令行上,避免空行或注释行
  • 调试前清理旧编译产物,重新执行build任务,确保生成带调试符号的可执行文件

内容的提问来源于stack exchange,提问作者Netchaiev

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 04:53:32