我有一些代码在给出几行输出后出现段错误。但是当我像这样在 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 中断程序,找出它死锁的位置,修复错误。