c++ - 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.
其次是程序的常规输出。那很奇怪。
解决方案
真的,我不知道这里可能有什么can't open to read symbols: No such file or directory.
看起来它们是默认目标,也许重建和重新链接您的来源可能会有所帮助。
但是我找到了某种解决方法来欺骗这个东西New Thread
。
*0-2 是从零开始的基本准备 *
echo "set startup-with-shell off" >> ~/.gdbinit
- 确保你的*s gdb 是代码签名的,达尔文需要它。
-g
使用选项编译代码- 运行你的 gdb
- 加载符号
file "your app name"
- 设置断点,例如,
main
通过执行b main
run
通过在 gdb 中执行来运行您的程序。- 调试愉快。
代码设计链接: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)
推荐阅读
- apache-kafka - Kafka - 根据预定时间将消息移动到队列前面
- azure - Azure IoT 中心 - “订阅”代码不起作用:“连接被拒绝”
- sql - postgresql - 按数字分组并返回最大值
- iis - 为什么 IIS CORS 模块“访问控制允许来源”似乎被缓存?
- jmeter - JMeter 如果控制器不工作
- javascript - 与外部 react.js 捆绑不起作用 - 可能缺少一些全局变量?
- java - 无法从此列表中找到要调用的 maven() 方法:
- sql - 将数据加载到 PDW 上的临时表中
- python - 跟随抓取的链接
- r - 将 data.frames 列表中的列表取消列出到单个 data.frame