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

GDB调试遇内部错误:引入自定义头文件后断点失效

GDB调试触发内部错误的解决求助

环境信息

  • 系统:Linux Mint 21 x64(AMD处理器)
  • 开发环境:VS Code,搭配C/C++插件、CMake插件
  • 编译工具:g++
  • GDB版本:12.0.90

问题现象

代码中引入自定义头文件TVk-core.h(该头文件已包含<iostream>,且CMakeLists.txt已正确配置头文件路径),通过g++编译可正常运行,但在std::cout行设置断点调试时,GDB触发内部错误,调试直接终止。若直接在代码中引入<iostream>则无此问题。

相关代码与配置

测试代码

#include "TVk-core.h"

int main()
{
    std::cout << "Hello World!" << std::endl;
    ...
    return 0;
}

GDB报错信息

Execute debugger commands using "-exec ", for example "-exec info registers" will list registers in use (when GDB is the debugger)
/build/gdb-wIRHdd/gdb-12.0.90/gdb/value.c:1731: internal-error: value_copy: Assertion arg->contents != nullptr' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. Quit this debugging session? (y or n) [answered Y; input not from terminal] /build/gdb-wIRHdd/gdb-12.0.90/gdb/value.c:1731: internal-error: value_copy: Assertion arg->contents != nullptr' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) [answered Y; input not from terminal]
ERROR: GDB exited unexpectedly. Debugging will now abort.
The program '/media/luh0/PARA/Projects/Thesis-Vk/build/tests/test1' has exited with code -1 (0xffffffff).

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) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/tests/test1",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description":  "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

C/C++配置(c_cpp_properties.json)

{
    "configurations": [
        {
            "name": "Mint64",
            "includePath": [
                "${workspaceFolder}/src/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "/usr/bin/cmake",
            "intelliSenseMode": "linux-gcc-x64",
            "cStandard": "gnu17",
            "cppStandard": "gnu++17"
        },
        {
            "name": "Ubuntu64",
            "includePath": [
                "${workspaceFolder}/src/**",
                "${workspaceFolder}/dependencies/*/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "/bin/g++",
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

排查与解决建议

  1. 修复C/C++配置错误

    • Mint64配置的compilerPath设为了/usr/bin/cmake,这是错误的,应改为g++路径(如/usr/bin/g++),否则IntelliSense无法正确解析编译器特性,可能间接影响调试符号生成。
  2. 禁用GDB的pretty-printing

    • GDB的pretty-printing可能与自定义头文件或STL对象结构冲突,导致内部错误。可在launch.json的setupCommands中修改为:
      {
          "description": "Disable pretty-printing for gdb",
          "text": "-disable-pretty-printing",
          "ignoreFailures": true
      }
      
  3. 确保调试符号完整生成

    • 在CMakeLists.txt中添加调试符号生成配置:
      set(CMAKE_BUILD_TYPE Debug)
      set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
      
    • 重新构建项目,保证可执行文件包含完整调试信息。
  4. 更新GDB到稳定版本

    • 当前使用的GDB 12.0.90是开发版,存在bug概率较高。通过包管理器安装稳定版:
      sudo apt update && sudo apt install gdb
      
  5. 检查自定义头文件包含逻辑

    • 给TVk-core.h添加头文件保护,避免重复包含或宏冲突:
      #ifndef TVK_CORE_H
      #define TVK_CORE_H
      #include <iostream>
      // 其他头文件与代码
      #endif
      

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 00:15:42