c++ found - “please check gdb is codesigned - see taskgated(8)” - How to get gdb installed with homebrew code signed?





identity no (7)


This may not be related. You can use lldb on macos instead of gdb. You don't need this hassle to install gdb.

lldb(http://lldb.llvm.org) is already installed by default in High Sierra

I'm under osx 10.8.4 and have installed gdb 7.5.1 with homebrew (motivation get a new gdb with new features such as --with-python etc... )

Long story short when I run debug within a c++ Eclipse project I get :

Error in final launch sequence
Failed to execute MI command:
-exec-run
Error message from debugger back end:
Unable to find Mach task port for process-id 46234: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))
Unable to find Mach task port for process-id 46234: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))

I have followed various suggestions for code signing

So I did:

  1. Set up the certificate
  2. Sign the gdb -> codesign -s gdb-cert /usr/local/bin/gdb

When I re-run debugging in Eclipse I get same error as above "(please check gdb is codesigned - see taskgated(8))".

If I set back the gdb to the older gdb (in the gdb preferences of Eclipse) /usr/libexec/gdb/gdb-i386-apple-darwin the debugging runs as expected.

Any solutions / hints out there ?

Thx

Pelle




I wonder if the global change in the highest voted answer here has some unintended consequences.

Rather than enabling the old Tiger convention, taskgated does allow signed code to run. So it might be better to just get a signed cert for gdb, similar to the answer here.

After this I was able to sudo use gdb. If you need to use gdb w/o sudo then perhaps this link will help though, disclaimer, I haven't tried it yet because using sudo is an ok solution for now`.




I experienced the same issue with GDB. I am running under Mac OS X 10.8.5 aka Mountain Lion. I am using GDB version 7.7.1.

I compiled my test program with following command:

g++ -o gdb-sample.out -g gdb-sample.cpp    

If I entered the command gdb sample.out, I get the same cryptic error message:

"Unable to find Mach task port for process-id 46234: (os/kern) failure (0x5). (please check gdb is codesigned - see taskgated(8))"

This error message however is a red herring.

The solution I found that worked for me was to simply invoke GDB using the superuser acct:

sudo gdb sample.out. 

That works fine for me.

And that from that point I could run GDB example.out without using sudo.

Hope this helps and works for others. RSVP if it doesn't.




This error occurs because OSX implements a pid access policy which requires a digital signature for binaries to access other processes pids. To enable gdb access to other processes, we must first code sign the binary. This signature depends on a particular certificate, which the user must create and register with the system.

To create a code signing certificate, open the Keychain Access application. Choose menu Keychain Access -> Certificate Assistant -> Create a Certificate…

Choose a name for the certificate (e.g., gdb-cert), 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.

Double click on the certificate, open Trust section, and set Code Signing to Always Trust. Exit Keychain Access application.

Restart the taskgated service, and sign the binary.

$ sudo killall taskgated
$ codesign -fs gdb-cert "$(which gdb)"

source http://andresabino.com/2015/04/14/codesign-gdb-on-mac-os-x-yosemite-10-10-2/

On macOS 10.12 (Sierra) and later, you must also

Use gdb 7.12.1 or later Additionally prevent gdb from using a shell to start the program to be debugged. You can use the following command for this inside gdb:

set startup-with-shell off

You can also put this last command in a file called .gdbinit in your home directory, in which case it will be applied automatically every time you start gdb

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

SOURCE: https://sourceware.org/gdb/wiki/BuildingOnDarwin




None of this worked for me and I had to go with a long run. Here is a full list of steps I've done to get it working.

  1. Create a certificate to sign the gdb.

Unfortunately, system certificate gave me Unknown Error = -2,147,414,007 which is very helpful, so I had to go with a workaround. KeyChain Assistant -> Create certificate ->

Pick login, gdb-cert, Code Signing

Copy/move certificate to the System keychain (enter password)

  1. Select certificate (gdb-cert) click Get info -> Trust Always
  2. Disable startup-with-shell

Enter in console: set startup-with-shell off

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

  1. Enable Root User

Go to System Preferences -> Users & Groups -> Unlock it -> Login Options -> Network Account Server -> Join -> Unlock it -> Edit (menu) -> Enable Root User

  1. sudo killall taskgated
  2. Finally sign gdb

codesign -fs gdb-cert "$(which gdb)"

  1. Disable Root User (Step 4)
  2. Reboot if still does not work. (if nothing else works, most likely it works already)

PS. I end up using lldb because it just works (tutorial)




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. If you installed it with mac ports then you must use 'ggdb' command. Or made an alias in your config file:

alias gdb='ggdb'

and use 'gdb' command then.




I would use the builtin QtWebKit. Don't know how it does in terms of performance, but I think it should catch all "bad" HTML. Something like:

class MyPageLoader : public QObject
{
  Q_OBJECT

public:
  MyPageLoader();
  void loadPage(const QUrl&);

public slots:
  void replyFinished(bool);

private:
  QWebView* m_view;
};

MyPageLoader::MyPageLoader()
{
  m_view = new QWebView();

  connect(m_view, SIGNAL(loadFinished(bool)),
          this, SLOT(replyFinished(bool)));
}

void MyPageLoader::loadPage(const QUrl& url)
{
  m_view->load(url);
}

void MyPageLoader::replyFinished(bool ok)
{
  QWebElementCollection elements = m_view->page()->mainFrame()->findAllElements("a");

  foreach (QWebElement e, elements) {
    // Process element e
  }
}

To use the class

MyPageLoader loader;
loader.loadPage("http://www.example.com")

and then do whatever you like with the collection.





c++ eclipse macos gdb homebrew