=============
== Lroolle ==
=============

MacOS Catalina GDB Setup

macos gdb debug

The Codesigned:

(please check gdb is codesigned - see taskgated(8))

1 Install GDB

brew install gdb

2 Cerfificate

-> Keychain access -> Certificate assistance -> Create a certificate

  • Name: gdb
  • Identity Type: Self Signed Root
  • Certificate Type: Code Signing
    • Let me override defaults

-> continue -> until “Specify a Location for Certificate”

  • System

-> Keychain access -> search “gdb”

  • Trust: check all “Always trust”

3 Codesign

  • Create file “gdb-entitlement.xml”

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>com.apple.security.cs.debugger</key>
        <true/>
    </dict>
    </plist>
    
    <!-- 作者:勥巭炛 -->
    <!-- 链接:https://zhuanlan.zhihu.com/p/68398728 -->
    <!-- 来源:知乎 -->
    <!-- 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。 -->
    
  • Codesign

codesign -entitlements gdb-entitlement.xml -fs gdb /usr/local/Cellar/gdb/{version}/bin/gdb

4 Change default GDB bin

default is /usr/local/bin/gdb

alias ggdb='/usr/local/Cellar/gdb/{version}/bin/gdb'

5 Create .gdbinit

~/.gdbinit

set startup-with-shell off
define g
python
import subprocess as p
cmd = [“go”, “env”, “GOROOT”]
gdb_cmd = “source %s/src/runtime/runtime-gdb.py” %   p.check_output(cmd)[:-1]
gdb.execute(gdb_cmd)

If run stuck like this

>run
Starting program: ./main
[New Thread 0x2903 of process 3257]
[New Thread 0x1c03 of process 3257]

Then echo this to .gdbinit

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

If stucks, then try sudo gdb ./main, or try another Terminal like iTerm

6 References