8

system:

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

went through and followed these instructions: https://sourceware.org/gdb/wiki/PermissionsDarwin

trying to debug on this program just to learn:

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

compile with:

gfortran test.f90 -Og -g -o test

then at the terminal

~/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]

at this point nothing happens... it just hangs and can't kill it with Ctrl-C, I have to go to the activity monitor to kill gdb. Wondering if I have missed something in my setup, or if anyone has any other ideas why this might be

Vince W.
  • 3,561
  • 3
  • 31
  • 59
  • Researching [this question](https://stackoverflow.com/questions/61240533/gdb-frozen-on-macos-catalina) I saw similar behavior. But if I control-z and then kill that task and then try again, it worked for me. – Rob Jun 19 '20 at 16:15
  • 2
    So I tried what you suggested, namely ctrl-z, then open activity monitor to kill it, then try again, but for me, same result – Vince W. Jun 19 '20 at 16:31
  • I have this same issue. It seems to work every other time. – user3746195 Jul 31 '20 at 01:07
  • Yup, interestingly, this issue occurs the first time you use "run". In subsequent times, it seems to work fine. Guess, this is an issue with gdb. – Shaswat Lenka Sep 16 '20 at 05:08
  • 4
    I got the same on Big Sur 11.0.1, gdb 10.1 – bric3 Nov 24 '20 at 15:50
  • 1
    same issue on big sur 11.1 but if you press Ctrl+Z, leave the first stopped, then run gdb again then it works – giuspen Feb 01 '21 at 21:33
  • I've the same problem with Big Sur 11.2.3 and gdb 10.1 – borgomeister Apr 23 '21 at 18:17
  • 1
    This issue is discussed in detail here: https://sourceware.org/bugzilla/show_bug.cgi?id=24069 ; The best solution is a patch that someone made in their forked version of GDB, and they say mac compatibility isn't a focus of the gdb development team. Hopefully whatever patch this guy made gets incorporatied, if it's not already in HEAD. – Jordan Mandel Jul 04 '21 at 13:52
  • 1
    @giuspen's hack of pressing ctrl+z, leaving the broken gdb running, and then starting another gdb also worked for me. – Ivo Anjo Jul 06 '21 at 10:36
  • @JordanMandel So disappointing to lose GDB support on macOS. Issue persists with Monterey. Aparently LLDB is now the macOS CLI debugger. Rats. – PeterT Oct 29 '21 at 20:42

3 Answers3

12

so before using gdb you have to create a ".gdbinit" file in your home directory. Now every time gdb starts it will execute the commands in this file. ".gdbinit" is a file you can drop in your home directory that gdb will parse when gdb launches, either from the command line or from within Xcode.

echo "set startup-with-shell off" >> ~/.gdbinit

run this command and gdb won't hang when you use run command aur r.

Will Da Silva
  • 6,386
  • 2
  • 27
  • 52
0

This hang hits gdb bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24069

You can install gdb from this source with patch:

brew install --force --build-from-source domq/gdb/gdb  # a patched version based on 10.1

or you can

brew update
brew install gdb # use gdb 12.1

It works for me, and I found it from this link: https://gist.github.com/mike-myers-tob/9a6013124bad7ff074d3297db2c98247

lutaoact
  • 4,149
  • 6
  • 29
  • 41
-1

You can kill the hang with Ctrl-Z.

Try running it several times, when setup correctly it seems to only work sometimes.