2

I tried to compile a 7.x Version of gdb without any luck. I codesigned the executable(http://sourceware.org/gdb/wiki/BuildingOnDarwin).

With following version there were these problems.

7.5,7.4,git clone: unknown load command 0x2a (and others) for my application and different system libraries when starting gbd. When trying to print a vector for example i always get: Could not find the frame base for "main(int, char**)"

7.3 (macports and from gdb-website): on starting the application it fails to set the breakpoint and continues to run.

(gdb) start
Temporary breakpoint 1 at 0x100000950: file ../src/main.cpp, line 15.
Starting program: [...]
BFD: unable to read unknown load command 0x24
BFD: unable to read unknown load command 0x2a
BFD: unable to read unknown load command 0x26
Error in re-setting breakpoint 1: Cannot access memory at address 0x100000950
[application continues]

I used the system llvm-gcc, gcc4.7 and svn-gcc4.8 to compile. Has anybody succeeded in installing gdb on Mountain Lion?

dlangenk
  • 340
  • 2
  • 3
  • 10
  • Why not just use the version of gdb that comes with Xcode ? – Paul R Aug 21 '12 at 08:12
  • 4
    Xcode's gdb is 6.3.x which is pretty old. I want to use the pretty printing of stl containers feature of gdb 7.x. – dlangenk Aug 21 '12 at 09:08
  • Did you try lldb ? Is that any better at printing STL containers ? – Paul R Aug 21 '12 at 09:42
  • lldb is quite comfortable for this task but unfortunately i want to use gdb with eclipse IDE which only supports gdb. – dlangenk Aug 21 '12 at 13:11
  • I ran into the same problem on Lion. It worth noticing that the executable `/usr/bin/gdb` is not signed at all (check by `codesign -d /usr/bin/gdb`), instead, when debugging anything using /usr/bin/gdb, a popup will appear to request permission to debug. Maybe gdb7.5 should somehow request permission like this too. – Tianyi Cui Sep 02 '12 at 07:22
  • /usr/bin/gdb is a shell script which tries to find the correct debugger instance for the given architecture. The x86 debugger is under /usr/libexec/gdb and it is signed. Verify with codesign -d --verbose=4 /usr/libexec/gdb/gdb-i386-apple-darwin – magiconair Mar 03 '13 at 23:31

4 Answers4

11

i installed gdb 7.5 on mountain lion without problems...

  1. those steps might help you: ./configure --prefix=/usr/local --enable-targets=x86_64-apple-darwin10 --enable-64-bit-bfd --disable-werror --build=x86_64-apple-darwin10 --host=x86_64-apple-darwin10 --target=x86_64-apple-darwin10

  2. then make install gdb.

  3. create your own certificate like discribed here and sign the gdb http://sourceware.org/gdb/wiki/BuildingOnDarwin

  4. you have to explicitly state: codesign -s gdb-cert /usr/local/gdb before you sign the gdb make sure you already set your certificate to trusted. also close the keychain before signing your gdb.

hope this also works for your

khr055
  • 28,690
  • 16
  • 36
  • 48
aviak
  • 111
  • 2
  • Thanks, this works perfectly for me. I think I've been missing the _close the keychain before signing your gdb_ step. – Tianyi Cui Sep 15 '12 at 09:11
  • That didn't solve the problem for me. make check still fails and the unknown load command errors are still there. Probably there's something wrong with my compiler. – dlangenk Sep 20 '12 at 11:23
  • Unfortunately this doesn't work for me either. I'd been doing steps 2-4 correctly with no success and thought step 1 might solve the problem but sadly it didn't work. [This homebrew pull request (for a gdb formula)](https://github.com/Homebrew/homebrew-dupes/pull/69) mentions the above *"BFD: unable to read unknown load command"* stuff as a gdb issue on Mountain Lion. – nitsas Nov 07 '12 at 19:09
  • This also doesn't work for me with GCC 4.9 and GDB 7.7.1 on Mavericks. After doing the four steps, I can set breakpoints perform related GDB functions without problems, but I cannot query the values of variables. GDB always reports that it `could not find the frame base` for some functions. If I use Eclipse rather than a terminal, then when I want to inspect the value of a variable, Eclipse would complain that it `failed to execute mi command`. – user740006 Aug 04 '14 at 17:13
5

I resolved this issue by following the steps tried here: http://coding.derkeiler.com/Archive/Ada/comp.lang.ada/2012-09/msg00305.html

Steps

  1. sudo chgrp procmod /usr/local/bin/gdb
  2. sudo chmod g+s /usr/local/bin/gdb
  3. Edit /System/Library/LaunchDaemons/com.apple.taskgated.plist and add +p argument to taskgated process
  4. Force kill taskgated process (it will restart)
  5. Try again

Other links:

  1. https://blogs.oracle.com/dns/entry/understanding_the_authorization_framework_on
Matthew Purland
  • 290
  • 3
  • 5
  • I've followed the steps in Matthew Purland's answer, but after codesigning my newly minted gdb binary the permissions string given by 'ls -l' doesn't include the '@' character I'd expect to see. Sure enough, the command 'xattr -l' also shows no extended attributes, though the xcode-supplied version of gdb in '/usr/bin/gdb' is fine. Any thoughts on why not? – neobobkrause Dec 10 '12 at 21:09
  • how to force kill task gated? – klm123 Nov 18 '13 at 12:17
  • @klm123 kill -9 [pid] – coanor Nov 30 '13 at 09:28
  • 1
    @klm123 `ps ax | grep taskgated`, then you will get the PID, normally, the PID for _taskated_ is very small. – coanor Nov 30 '13 at 13:43
2

it doesn't seem to work for me... same issue as with the default homebrew settings

v1:src zeph$ brew install gdb
==> Downloading http://ftpmirror.gnu.org/gdb/gdb-7.5.tar.bz2
Already downloaded: /Library/Caches/Homebrew/gdb-7.5.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/gdb/7.5 --with-python=/usr --with-system-readline --enable-targets=x86_64-apple-darwin10 --enable-64-bit-bfd --disable-werror --build=x86_64-apple-darwin10 --hos
==> make
==> make install
==> Caveats
gdb requires special privileges to access Mach ports.
You will need to codesign the binary. For instructions, see:

  http://sourceware.org/gdb/wiki/BuildingOnDarwin
==> Summary
/usr/local/Cellar/gdb/7.5: 62 files, 9.3M, built in 119 seconds
v1:src zeph$ codesign -s gdb-cert /usr/local/Cellar/gdb/7.5/bin/gdb 
v1:src zeph$ /usr/local/Cellar/gdb/7.5/bin/gdb --args /Users/zeph/tmp/CouchBase/src/install/bin/memcached -d -u root -P /tmp/0libmemcached_memc.pid -t 1 -p 11221 -U 11221 -m 128
GNU gdb (GDB) 7.5
Copyright (C) 2012 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-darwin10".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
BFD: /Users/zeph/tmp/CouchBase/src/install/bin/memcached: unknown load command 0x29
BFD: /Users/zeph/tmp/CouchBase/src/install/bin/memcached: unknown load command 0x29
Reading symbols from /Users/zeph/tmp/CouchBase/src/install/bin/memcached...done.
(gdb) run
Starting program: /Users/zeph/tmp/CouchBase/src/install/bin/memcached -d -u root -P /tmp/0libmemcached_memc.pid -t 1 -p 11221 -U 11221 -m 128
Unable to find Mach task port for process-id 28755: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))
(gdb) 

k, I had to re-sign it after having TRUSTED the certificate all across the board

codesign -fs gdb-cert /usr/local/Cellar/gdb/7.5/bin/gdb

  • 4
    does it work for you? c>codesign -s gdb-cert /usr/local/bin/gdb /usr/local/bin/gdb: is already signed but it still gives me the error message Unable to find Mach task port for process-id 838: (os/kern) failure (0x5). (please check gdb is codesigned - see taskgated(8)) – bobzhang Feb 02 '13 at 05:07
  • This also does not work for me. I've signed the binary multiple times with different certificates but still no luck. Not sure what I'm doing wrong. – magiconair Mar 03 '13 at 23:33
2

There were two issues in the OP's question. The one regarding signing the executable or modifying taskgated and using setgid procmod has been covered. The second issue is the warnings about unknown load commands. I too ran into this and after a bunch of searching came across the following patches, that fix it:

https://gist.github.com/davidbalbert/4197567

Kean
  • 592
  • 5
  • 10