首页 > 解决方案 > gdb 输出启动线程但给出输出

问题描述

我有一些代码在给出几行输出后会出现段错误。但是当我像这样在 gdb 上运行代码时:

(gdb) r < err.in

我得到以下

Starting program: /Users/prikshetsharma/Downloads/parser/parse < err.in                                                                   
[New Thread 0xf03 of process 39241]                                                                                             
[New Thread 0xc03 of process 39241]   

而 gdb 只是一直卡在这里。并且它在定期运行时没有给出它给出的输出。如何解决这个问题?

- 编辑 -

一件有趣的事情正在发生。有时 gdb 会给出输出,有时则不会,即使我什么也没做。当它确实给出输出时,它会执行以下操作:

Starting program: /Users/prikshetsharma/Downloads/parser/parse < err.in                                                                                                                                                                                                                                                       
[New Thread 0x1003 of process 39841]                                                                                                                                                                                                                                                                                          
[New Thread 0x1103 of process 39841]                                                                                                                                                                                                                                                                                          
[New Thread 0x1503 of process 39841]                                                                                                                                                                                                                                                                                          
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/bsd.o': can't open to read symbols: No such file or directory.                                                                                               
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/darwin_vers.o': can't open to read symbols: No such file or directory.                                                                                       
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/dirstat.o': can't open to read symbols: No such file or directory.                                                                                           
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/dirstat_collection.o': can't open to read symbols: No such file or directory.                                                                                
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/err.o': can't open to read symbols: No such file or directory.                                                                                               
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/exception.o': can't open to read symbols: No such file or directory.                                                                                         
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/init.o': can't open to read symbols: No such file or directory.                                                                                              
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/mach.o': can't open to read symbols: No such file or directory.                                                                                              
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/stdio.o': can't open to read symbols: No such file or directory.                                                                                             
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/stdlib.o': can't open to read symbols: No such file or directory.                                                                                            
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/string.o': can't open to read symbols: No such file or directory.                                                                                            
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/variant.o': can't open to read symbols: No such file or directory.      

其次是程序的常规输出。那很奇怪。

标签: c++macosgdb

解决方案


真的,我不知道这里可能有什么can't open to read symbols: No such file or directory. 看起来它们是默认目标,也许重建和重新链接您的来源可能会有所帮助。

但是我找到了某种解决方法来欺骗这个东西New Thread

*0-2 是从零开始的基本准备 *

  1. echo "set startup-with-shell off" >> ~/.gdbinit
  2. 确保你的*s gdb 是代码签名的,达尔文需要它。
  3. -g使用选项编译代码
  4. 运行你的 gdb
  5. 加载符号file "your app name"
  6. 设置断点,例如, main通过执行b main
  7. run通过在 gdb 中执行来运行您的程序。
  8. 调试愉快。

代码设计链接:https ://superuser.com/questions/1436370/how-to-codesign-gdb-on-os-x-mojave

笔记:

My gdb is updated to the `9.1_1` version and codesigned. 

MacOS version: Catalina(10.15.4)

推荐阅读