macOS下gcc编译程序后gdb调试出现DW_FORM_line_strp错误的含义
GDB调试报错"Dwarf Error: DW_FORM_line_strp used without required section"解析
问题场景
在macOS Sequoia 15.0系统上,用gcc 14.2.0编译的普通"Hello World"程序运行正常,但使用GDB 15.2调试时,执行list、break main等命令都会弹出错误:
Dwarf Error: DW_FORM_line_strp used without required section
编译及调试的完整操作日志如下:
bash-3.2$ cat hello.c #include <stdio.h> int main(void) { printf("Hello World\n"); return 0; } bash-3.2$ gcc-14 --version gcc-14 (Homebrew GCC 14.2.0) 14.2.0 Copyright (C) 2024 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. bash-3.2$ ./hello Hello World bash-3.2$ gdb ./hello GNU gdb (GDB) 15.2 Copyright (C) 2024 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-apple-darwin23.4.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./hello... Reading symbols from /Users/jianfeiye/test/ctest/hello.dSYM/Contents/Resources/DWARF/hello... (gdb) list Dwarf Error: DW_FORM_line_strp used without required section (gdb) break main Dwarf Error: DW_FORM_line_strp used without required section (gdb)
错误消息含义
DWARF是编译器生成的调试信息标准格式,DW_FORM_line_strp是DWARF中用于引用行号字符串表(.debug_line_str段)条目的一种格式标识。这个错误表示:
GDB在解析程序的调试信息时,发现编译器生成的DWARF数据里使用了DW_FORM_line_strp格式,但对应的.debug_line_str段缺失或未正确生成,导致GDB无法正常解析调试信息。
后续测试及现状
2025年12月28日更新:
- 尝试添加编译选项
-gdwarf-4(指定生成DWARF 4版本的调试信息),gcc 15.2.0搭配该选项仍无法解决问题; - 改用clang 17.0.0搭配
-gdwarf-4编译程序,GDB可以正常调试。
该问题属于GCC与GDB在macOS平台上的DWARF调试信息兼容性Bug,相关问题已在GNU的Bugzilla系统中记录,编号为32235。
临时解决办法
- 改用clang编译器,配合
-gdwarf-4选项编译程序,即可正常使用GDB调试; - 等待GCC或GDB的后续版本发布,修复该兼容性问题。
内容的提问来源于stack exchange,提问作者Victor
相关产品推荐
相关产品推荐

