Links:
https://www.ics.uci.edu/~pattis/common/handouts/macmingweclipse/allexperimental/mac-gdb-install.html
https://sourceware.org/gdb/wiki/BuildingOnDarwin ***IMPORTANT***
https://sourceware.org/gdb/wiki/BuildingOnDarwin ***IMPORTANT***
https://sourceware.org/gdb/wiki/PermissionsDarwin ***IMPORTANT***
https://www.youtube.com/watch?v=JdcpDOf5Sog
https://www.youtube.com/watch?v=JdcpDOf5Sog
Firstly, install gdb, this can be done using home-brew;
brew install gdb
Then we need to sign the gdb binary;
Keep clicking CONTINUE until the last screen and try to choose System, if this doesn't work, go through the process again and choose Login then simply drag the certificate to the System folder, the result should be like the below;
Refresh the certificate store (unsure if really required);
security find-certificate -c gdb-cert
Get Info for the certificate (double click works) and set Trust Code Signing to Always Trust as below;
##################################################
METHOD 1 START
This method has been tested to work
##################################################
1). Quit Keychain and do;
METHOD 1 START
This method has been tested to work
##################################################
1). Quit Keychain and do;
security dump-trust-settings -d
2). Create a file called gdb-entitlement.xml with the following;
<?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> </pre>
3). Sign gdb with the following;
codesign --entitlements gdb-entitlement.xml -fs gdb-cert $(which gdb)
##################################################
METHOD 1 END
##################################################
ALTERNATIVE METHOD FROM https://www.youtube.com/watch?v=JdcpDOf5Sog
##################################################
METHOD 2 START
##################################################
THIS METHOD SKIPS THE CREATION OF gdb-entitlement.xml AS SHOWN ABOVE AND ALSO THE SIGNING WITH;
codesign --entitlements gdb-entitlement.xml -fs gdb-cert $(which gdb)
1). Kill taskgated with;
sudo killall taskgated
2). Sign gdb with;
codesign -fs gdb-cert /usr/local/bin/gdb
3). Start taskgated daemon with;
launchctl load /System/Library/LaunchDaemons/com.apple.taskgated.plist
METHOD 2 END
##################################################
Create a file called .gdbinit in your home directory with the following in it;
set startup-with-shell off
Finally, if using with Eclipse and you probably are, you need to add the location to gdb in preferences;
NOTE: AS OF 19 JUNE 2020, THIS METHOD STILL DOES NOT ALLOW PROPER DEBUGGING IN EITHER ECLIPSE, REDHAT CODEREADY STUDIO OR NETBEANS.
gdb does however work from the command line and this can be tested as follows:
This tests that the gdb binary has indeed been tested properly
codesign --verify --verbose /usr/local/bin/gdb
Compile the source code as follows:
g++ test.cpp -g -Wall -Werror -o test.o
Then launch the debugger as follows:
gdb test.o
Set a breakpoint as follows:
break 5
Now run the program;
run
If you don't see for example:
Starting program: /Volumes/D_SLAVE/My Documents/My Projects/Code Ready Studio/C_test/src/test.o
Unable to find Mach task port for process-id 15719: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
then the gdb binary is indeed signed and working.You can then use next and step to go through the program line by line or function by function.
Note: You can use quit to quit the debugger.
See https://www.cprogramming.com/gdb.html for more details.
No comments:
Post a Comment
Note: only a member of this blog may post a comment.