GDB 输出启动线程,但给出输出
gdb output starts threads but gives on output
我有一些代码在给出几行输出后出现段错误。但是当我像这样在 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.
看起来它们是默认目标,也许重建和重新链接 Your 的来源可能会有所帮助。
但是我找到了某种解决方法来欺骗这个东西粘在New Thread
上。
*0-2是从头开始的基本准备*
echo "set startup-with-shell off" >> ~/.gdbinit
- 确保你的gdb是共同设计的,达尔文需要它。
- 使用
-g
选项编译代码 - 运行你的 gdb
- 按
file "your app name"
加载符号 - 例如,通过执行断点在
main
上设置断点b main
- 通过在 gdb 中执行
run
来运行程序。 - 调试愉快。
共同设计链接: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)
当 gdb 无法打开对象文件来运行程序时,通常会发生此问题。解决此问题的一种方法 -
- 使用目标文件启动 gdb
gdb <executable for example a.out>
- 这将调用 gdb 提示符。然后,在 gdb 提示符
b <function name for example b main>
设置断点 - 然后
run <executable for example run a.out>
这应该启动在调试模式下运行程序的 gdb,并且可以根据需要逐步执行和使用 gdb。
gdb 只是卡在这里。
最可能的原因是:您的程序有一个错误(我们已经知道它有,因为它崩溃了(,并且在 GDB 下运行时出现死锁(并不意外:GDB 会影响线程的计时(。
如何解决这个问题?
使用 Control-C 中断程序,找出它死锁的位置,修复错误。
相关文章:
- 并发/多线程:是否可以以这种方式生成相同的输出?
- 为什么分离线程没有得到输出消息
- GDB 输出启动线程,但给出输出
- 控制多线程程序中的输出流
- 线程的意外输出
- 主函数跳过线程并且不加入以显示所需的输出
- 在 Valgrind 输出中仍然可以访问 std 线程向量的块
- 多线程使用者未产生与使用升压环形缓冲区的输入相同的输出
- 从线程输出简单向量
- 调试器看到的输出线程 ID
- C 两个线程一个用于输入,一个用于输出
- 干净取消在输入/输出调用中被阻止的 std::线程
- 将线程之间的标准输入/输出重定向
- 多线程中的不明确输出
- 当许多线程的输出是可变长度时,我应该如何合并它?
- 如何为 OpenMP 中任意数量的线程获取相同的并行化输出,以便 if-else,增量
- 为什么重新执行我的多线程代码后输出不一样
- 多线程环境中的输出字符串流出现问题
- 提升线程在Stdout上没有输出
- 来自不同线程的同步输出流