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

GDB无法在main函数处断点的异常问题排查求助

GDB调试异常问题排查求助

我遇到了一个诡异的GDB调试问题,已简化为最小复现示例:

创建test.cc文件,内容如下:

#include <iostream>

int main(void) {
    std::cout << "this is ridiculous" << std::endl;
}

用g++编译:g++ test.cc -g -Og -o out

直接运行./out正常,但用GDB调试时行为异常:

~ gdb ./out
Reading symbols from ./out...
(gdb) b main
Breakpoint 1 at 0x11df: file test.cc, line 3.
(gdb) r
Starting program: /home/c/tmp/s/out
this is ridiculous
During startup program exited normally.

我哪里操作错了?

已做的检查

  • 符号存在:
    ~ objdump -x out | grep main
    000000000000120c l     F .text  000000000000001c              _GLOBAL__sub_I_main
    00000000000011df g     F .text  000000000000002d              main
    0000000000000000       F *UND*  0000000000000000              __libc_start_main@GLIBC_2.34
    
  • 汇编输出已确认
  • 多台机器均出现该问题:
    • ubuntu 22.04 with g++ 11.4.0
    • arch with clang 17
    • arch with g++ 13.2.1
  • GDB已正确解析符号:
    ~ gdb ./out
    (gdb) info functions
    All defined functions:
    
    File test.cc:
    3:  int main();
        static void _GLOBAL__sub_I_main();
        static void __static_initialization_and_destruction_0(int, int);
    
    Non-debugging symbols:
    0x0000000000001000  _init
    0x0000000000001070  __cxa_finalize@plt
    0x0000000000001080  std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)@plt
    0x0000000000001090  __cxa_atexit@plt
    0x00000000000010a0  std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)@plt
    0x00000000000010b0  std::ios_base::Init::Init()@plt
    0x00000000000010c0  _start
    0x00000000000010f0  deregister_tm_clones
    0x0000000000001120  register_tm_clones
    0x0000000000001160  __do_global_dtors_aux
    0x00000000000011a0  frame_dummy
    0x0000000000001228  _fini
    

补充调查

  • 纯C程序也存在相同问题
  • GDB的starti命令同样无效,表现与run一致
  • 在Debian Docker容器中运行一切正常

这让我怀疑是GDB的bug,但又觉得不合理:

  • 两台不同机器、不同版本GDB(12.1和13.2)均出现该问题
  • GDB均来自Ubuntu/Arch官方仓库,属于经过充分测试的软件

我还能进行哪些测试来定位问题?

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 06:33:18