Labels

Android (1) bash (2) boost (2) C (34) C++ (2) cheatsheet (2) CLion (6) css (3) Debian (33) DL (17) Docker (1) Dreamweaver (2) Eclipse (3) fail2ban (4) git (5) GitHub (4) Hacking (3) html (8) http (1) iOS (1) iPad (1) IRC (1) Java (30) javascript (3) Linux (164) Mac (19) Machine Learning (1) mySQL (47) Netbeans (4) Networking (1) Nexus (1) OpenVMS (6) Oracle (1) Pandas (3) php (16) Postgresql (8) Python (9) raid (1) RedHat (14) Samba (2) Slackware (45) SQL (14) svn (1) tar (1) ThinkPad (1) Virtualbox (3) Visual Basic (1) Visual Studio (1) Windows (2)

Tuesday 9 June 2020

Install and sign gdb - The GNU Debugger for Mac using Homebrew.

The below details 2 slightly different methods on how to install and sign gdb on a Mac

Links:




Firstly, install gdb, this can be done using home-brew;

brew install gdb

Then we need to sign the gdb binary;
Open the Keychain app and do CERTIFICATE ASSISTANT > CREATE CERTIFICATE



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;

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.