调试器gdb在Mac OS Catalina上调用`run`后挂起

8

系统:

mac osx catalina (10.15.5)
gfortran 9.3.0 (from homebrew)
gdb 9.2 (from homebrew)

我按照以下说明进行了操作:

https://sourceware.org/gdb/wiki/PermissionsDarwin

仅仅是为了学习而尝试调试此程序:

! test.f90
program main
  integer :: val
  val = 1
  print *, val
  val = 2
  print *, val
end program main

使用以下命令进行编译:

gfortran test.f90 -Og -g -o test

然后在终端输入

~/Coding/gdb
> ./test
           1
           2
~/Coding/gdb $
> gdb test
GNU gdb (GDB) 9.2
Copyright (C) 2020 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-darwin19.4.0".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://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 test...
Reading symbols from /Users/a3r7lzz/Coding/gdb/test.dSYM/Contents/Resources/DWARF/test...
(gdb) run
Starting program: /Users/a3r7lzz/Coding/gdb/test 
[New Thread 0x1803 of process 3054]

此时没有任何反应...程序卡住了,Ctrl-C也无法结束,必须通过活动监视器(kill gdb)来关闭。想知道我是否在设置上漏掉了什么,或者是否有其他人有任何其他想法,可能是为什么。


2
所以我尝试了你建议的方法,即ctrl-z,然后打开活动监视器将其终止,然后再次尝试,但对我来说,结果相同。 - Vince W.
4
我在Big Sur 11.0.1和gdb 10.1上得到了同样的结果。 - bric3
1
在 Big Sur 11.1 上遇到了同样的问题,但是如果按下 Ctrl+Z,退出第一个停止的程序,然后再次运行 gdb,那么它就可以工作了。 - giuspen
1
这个问题在这里详细讨论:https://sourceware.org/bugzilla/show_bug.cgi?id=24069;最好的解决方案是某人在他们分支版本的GDB中制作的补丁,他们说Mac兼容性不是gdb开发团队的重点。希望这个人制作的任何补丁已经被合并,如果还没有被合并,希望尽快合并。 - Jordan Mandel
1
@giuspen的技巧是按下ctrl+z,让损坏的gdb继续运行,然后启动另一个gdb,这对我也起作用了。 - Ivo Anjo
显示剩余5条评论
3个回答

13

在使用gdb之前,您需要在主目录中创建一个".gdbinit"文件。 现在每次启动gdb时,它都会执行此文件中的命令。".gdbinit"是一个文件,您可以将其放入主目录中,当gdb从命令行或Xcode内部启动时,gdb将解析它。


echo "set startup-with-shell off" >> ~/.gdbinit
运行此命令,使用run命令或r时,gdb不会挂起。

6
这对我起作用了(gdb 10.1和macOS Big Sur 11.2.3)。 - wvdgoot
1
这是唯一对我有效的方法,谢谢。 - Michaelpanicci

0

-1

你可以使用 Ctrl-Z 来终止程序的挂起。

如果设置正确,尝试多次运行它,它似乎只有时而有效。


4
Ctrl-Z并不会终止进程,它会将进程置于后台,并处于一种冻结状态。 - Vince W.
使用命令“ps”查看活动进程,并使用命令“kill PID”关闭特定进程。 - jorge saraiva

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接