Skip to content

Instantly share code, notes, and snippets.

@huilapman
Last active June 2, 2017 16:22
Show Gist options
  • Save huilapman/1cb87524928487a805ca910c93bde743 to your computer and use it in GitHub Desktop.
Save huilapman/1cb87524928487a805ca910c93bde743 to your computer and use it in GitHub Desktop.
gdb on macOS Sierra
#include <iostream>
using namespace std;  

int divint(int, int);  
int main() 
{ 
   int x = 5, y = 2; 
   cout << divint(x, y); 
   
   x =3; y = 0; 
   cout << divint(x, y); 
   
   return 0; 
}  

int divint(int a, int b) 
{ 
   return a / b; 
}   

$g++ -g crash.cc -o crash

Floating point exception (core dumped)

If you are getting this in gdb on OSX while trying to run a program:

Unable to find Mach task port for process-id 57573: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))
  1. Open Keychain Access
  2. In menu, open Keychain Access > Certificate Assistant > Create a certificate
  3. Give it a name (e.g. gdbc)
  • Identity type: Self Signed Root
  • Certificate type: Code Signing
  • Check: let me override defaults
  1. Continue until "specify a location for..."
  2. Keychain = System
  3. Close. Find certificate in System keychains.
  4. Get Info
  5. Expand Trust, set Code signing to always trust
  6. killall taskgated
  7. Enable root account:
  8. Open System Preferences
  9. Go to User & Groups > Unlock
  10. Login Options > "Join" (next to Network Account Server)
  11. Click "Open Directory Utility"
  12. Go up to Edit > Enable Root User
  13. codesign -fs gdbc /usr/local/bin/gdb -- asks for root password
  14. Disable root account

gdb crashes with the information: During startup program terminated with signal SIG113, Real-time event 113.

Quit gdb

  1. Using your text editor e.g. Sublime Text, save a file called “.gdbinit” [Exclude the quotation marks] in your user folder.
  2. In the file add the following: “set startup-with-shell off” [Exclude the quotation marks]
  3. Save the file
  4. gdb should now workv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment