How Do You Install Gdb For Mac

broken image


Question or issue on macOS:

Because I need a Python-enabled gdb, I installed another version via

I want to use this gdb with Eclipse CDT, where I entered the path to the binary in the Debugging settings. However, launching a program for debugging fails with the following message:

So you can sit back and have cup of coffee for a while. Once it is completed, you can locate gdb binary located at gdb-7.11/gdb/gdb. Step-4: Install GDB. Step 7 microwin 4.0 free download. $ make install By default this will install gdb binaries in /usr/local/bin and libs in /usr/local/lib Congratulation, you have successfully compiled and installed GDB. I'm having lots of problems with GDB; usually crashes and starts using 100% CPU until I kill the process using the activity monitor on the Mac (using Mavericks). How do I remove GDB from my machine (using GDB 7.6.1)? I plan to install an older version (GDB 6.x.x) after uninstalling this version. I'd really like to use GDB (GNU debugger), I've downloaded it from the website etc, but can't seem to find any way of installing it, there doesn't seem to be a file to do that. I have a feeling it's not the kind of program you install in that way, as obviously you're expected to know a lot about computers to use it, but well I don't!

What does 'codesigned' mean in this context? How can I get this gdbrunning?

How to solve this problem?

Solution no. 1:

It would seem you need to sign the executable. See these links for more information. You should be able to get away with self signing if you don't plan on redistributing that version of gdb.

Alternatively, you could disable code signing on your system, although this presents a security risk. To do so try running sudo spctl --master-disable in the Terminal.

Solution no. 2:


I.1 Codesigning the Debugger
The Darwin Kernel requires the debugger to have special permissions
before it is allowed to control other processes. These permissions are
granted by codesigning the GDB executable. Without these permissions,
the debugger will report error messages such as:
Starting program: /x/y/foo
Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5).
(please check gdb is codesigned – see taskgated(8))

Codesigning requires a certificate. The following procedure explains how to create one:

Start the Keychain Access application (in /Applications/Utilities/Keychain Access.app)
Select the Keychain
Access -> Certificate Assistant -> Create a Certificate… menu
Then:

Choose a name for the new certificate (this procedure will use
'gdb-cert' as an example)
Set 'Identity Type' to 'Self Signed Root'
Set 'Certificate Type' to 'Code Signing'
Activate the 'Let me override defaults' option

Click several times on 'Continue' until the 'Specify
a Location For The Certificate' screen appears, then set 'Keychain' to 'System'
Click on 'Continue' until the certificate is created
Finally, in the view, double-click on the new certificate, and set 'When using
this certificate' to 'Always Trust'
Exit the Keychain Access application and restart the computer (this is unfortunately required)

Once a certificate has been created, the debugger can be codesigned as
follow. In a Terminal, run the following command…
codesign -f -s 'gdb-cert' /bin/gdb

… where 'gdb-cert' should be replaced by the actual certificate name
chosen above, and should be replaced by the
location where you installed GNAT.

source: https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gnat_ugn_unw/Codesigning-the-Debugger.html

UPDATE: High-Sierra (Certificate Assistant – Unknown Error)
https://apple.stackexchange.com/questions/309017/unknown-error-2-147-414-007-on-creating-certificate-with-certificate-assist

Solution no. 3:

I made gdb work on OSX 10.9 without codesigning this way (described here):

  1. Install gdb with macports. (may be you can skip it)

  2. sudo nano /System/Library/LaunchDaemons/com.apple.taskgated.plist

    change option string from -s to -sp at line 22, col 27.

  3. reboot the computer.

  4. Use gdb

Solution no. 4:

Check the trust of the cert, it must be trusted for code signing (on yosemite that is the third last in the trust section of the cert view in the keychain access).

At first the cert was not known for codesigning to the keychain, because there was the Extension purpose 'Code Signing' missing, you can find this if you look into the keychain and double click on the certificate:

I fixed that:

Then I added the certificate to the trusted signing certificates, after I had drag&dropped the certificate from the keychain to my desktop, which created the ~/Desktop/gdb-cert.cer:

For

This was a bit tricky because I was mislead by some internet posts and did not look at the man page. Some said you should use add-trust (https://llvm.org/svn/llvm-project/lldb/trunk/docs/code-signing.txt). The terrible bit was that the command succeeded, but did not do what it 'should' (well, it was the wrong command, but it should have told me it was wrong).

After that I found the new cert in the trusted certs like so:

In my case the apple cert is expired, but the one I was using to sign gdb was not (well, I just created it myself). Also be aware that the policy is named differently for the 'security add-trusted-cert'(-p codeSign) and the 'security find-identity' command (-p codesigning). I then went on to sign gdb and I also always got:

because I was under the impression that I had to give the file name of the cert file to the –sign option, but that in fact was the CN of the certificate that I should have provided and should be in the trust store. You can find the CN here when double clicking on the cert in the keychain:

or in the above output of 'security find-identity -p codesigning'. Then I went on to sign and I had to give it the right keychain:

I had to enter the root password to allow access to the keychain.

That then gave me a working gdb and it should give you a signed application.

Solution no. 5:

If using gdb isn't a hard requirement you can also use lldb as an alternative. It is already on your system and doesn't need to be code signed:

Here's a table converting gdb to lldb commands http://lldb.llvm.org/lldb-gdb.html

Solution no. 6:

I ended up having to follow these directions instead of the directions suggested by others.

I'm still not sure if it was the act of killall taskgated or the process of enabling root user that made the difference.

Some have said rebooting is necessary. I find that with the above instructions, that may not be the case.

I did also make the change recommended by @klm123, so this may also have contributed.

Note that I use homebrew, not macports.

Solution no. 7:

It's a very old topic, but I am adding a response, because out of many available instructions, only one contained just the right steps to make a self-signed debugger work.

You have to create a self-signed root certificate and then sign the gdb executable with it, but many people complained that it did not work for them. Neither did it for me until I stumbled upon this link.

The key point missing in other manuals is that you have to restart your computer for the changes to take effect. Once I did that, everything worked as intended.

I hope, this will help others.

Solution no. 8:

This is an older question but none of the solutions seemed to work for me (I was using Mojave). Converting to lldb isn't the solution to the question – its just a work around.

After trying several solutions, the one I found to work was located here: https://gist.github.com/gravitylow/fb595186ce6068537a6e9da6d8b5b96d#gistcomment-2891198

Which references this site: https://sourceware.org/gdb/wiki/PermissionsDarwin#Sign_and_entitle_the_gdb_binary

The solution involves a slightly modified version of the code signing. Essentially, the main difference is when signing the certificate, an entitlements XML file must be passed when codesigning. Below I copy/pasted the contents of the sourceware website for all of the steps from beginning to end.


1.1. Create a certificate in the System Keychain
Start Keychain Access application (/Applications/Utilities/Keychain
Access.app)
Open the menu item /Keychain Access/Certificate Assistant/Create a
Certificate…
Choose a name (gdb-cert in the example), set Identity Type to Self
Signed Root, set Certificate Type to Code Signing and select the Let
me override defaults. Click several times on Continue until you get to
the Specify a Location For The Certificate screen, then set Keychain
to System.
💡 If you cannot store the certificate in the System keychain: create
it in the login keychain instead, then export it. You can then import
it into the System keychain.
Finally, quit the Keychain Access application to refresh the
certificate store.
Control: in the terminal type
security find-certificate -c gdb-cert

This should display some details about your newly minted certificate,
e.g.
keychain: '/Library/Keychains/System.keychain' version: 256 class:
0x80001000 attributes:
'alis'='gdb-cert' […]
Make sure that keychain: is the System keychain, as shown.
Also, make sure that your certificate is not expired yet:
security find-certificate -p -c gdb-cert | openssl x509 -checkend 0

💡If you want to inspect the entire X509 data structure, you can type
security find-certificate -p -c gdb-cert |openssl x509 -noout -text

1.2. Trust the certificate for code signing
Start Keychain Access again. Using the contextual menu for the
certificate, select Get Info, open the Trust item, and set Code
Signing to Always Trust.
Finally, quit the Keychain Access application once more to refresh the
certificate store.
Control: in the terminal type
security dump-trust-settings -d

This should show the gdb-cert certificate (perhaps among others) and
its trust settings, including Code Signing.
1.3. Sign and entitle the gdb binary
(Mac OS X 10.14 and later) Create a gdb-entitlement.xml file containing the following:

com.apple.security.cs.debugger

If the certificate you generated in the previous section is known as gdb-cert, use:
codesign –entitlements gdb-entitlement.xml -fs gdb-cert $(which gdb)

or before Mojave (10.14), just
codesign -fs gdb-cert $(which gdb)

💡 You may have to prepend this command with sudo if the gdb binary is
located in a place that is not writable by regular users.
If you plan to build gdb frequently, this step can be automated by
passing –enable-codesign=gdb-cert (assuming, again, that gdb-cert is
the name of the certificate) to configure.
Control: in the terminal type
codesign -vv $(which gdb)

And for 10.14 (Mojave) onwards, also check the entitlements:
codesign -d –entitlements – $(which gdb)

1.4. Refresh the system's certificates and code-signing data
The most reliable way is to reboot your system.
A less invasive way is to and restart taskgated service by killing the
current running taskgated process (at any time in the process, but no
later than before trying to run gdb again):
sudo killall taskgated

However, sometimes the taskgated service will not restart successfully
after killing it, so ensure that it is alive after this step by
checking e.g. ps $(pgrep -f taskgated). Or just reboot your system, as
mentioned above.

How Do You Install Gdb For Mac Pro

Solution no. 9:

I followed the instructions with codesigning, but gdb would still give me the same error. It turned out that it did work when gdb is run as root (sudo gdb). I'm using Sierra osx.

How Do You Install Gdb For Mac Free

Hope this helps!





broken image