Configure GDB debug Golang under Mac

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Configure GDB debug Golang under Mac

Original link Https://sourceware.org/gdb/wiki/BuildingOnDarwin

Building GDB for Darwin

Creating the binary for Darwin isn ' t very difficult. Download a release snapshot or get the current source via GIT/CVS/FTP, then configure and make as usual.

Building The 7.0 release unfortunately results in many "Warning:format not a string literal and no format arguments" warn Ings. This problem have been fixed in CVS. To avoid such warnings building 7.0, configure with--disable-intl.

Giving GDB permission to control other processes

If you try the your freshly built gdb, you'll get an error message such as:

Starting program:/x/y/fooUnable to find Mach task port for Process-id 28885: (os/kern) Failure (0x5).  (Please check that GDB is Codesigned-see taskgated (8)) 

This is because the Darwin kernel would refuse to allow GDB to debug another process if you don't have special rights, sinc E debugging a process means have full control over this process, and that isn ' t allowed by default since it would be exp Loitable by malware. (The kernel won ' t refuse if you is root, but the course you don ' t want to is root to debug.)

The most-up to date method-to-allow GDB-control another process is-to-sign it with any system-trusted code signing auth Ority. This was an easy process once you had a certificate (see the section below). If The certificate is known as Gdb-cert, just use:

$ codesign-s Gdb-cert gdb

Old Notes:in Tiger, the kernel would accept processes whose primary effective group is PROCMOD or Procview. That means this making gdb setgid procmod should work. Later versions of Darwin should accept this Convention provided that taskgated (the daemon, control the access) is INV oked with option '-P '. This daemon was configured by /system/library/launchdaemons/com.apple.taskgated.plist. I was able to use this rule provided that I am also a member of the Procmod group.

You also need to is in the Unix group _developer.

Creating a certificate

Start Keychain Access Application (/applications/utilities/keychain Access.app)

Open menu /keychain access/certificate assistant/create a Certificate ...

Choose a name (Gdb-cert in the example), set Identity Type to self signed Root, set Certifi Cate Type to Code Signing and select the Let me override defaults. Click several times on Continueuntil you get to the specify a location for the Certificate screens, then Set Keychain to System.

If you can ' t store the certificate in the System Keychain, create it in the login keychain and then exp Orted it. You can then imported it into the System Keychain.

Finally, using the contextual menu for the certificate, select Get Info, open the Trust item, and set code Signing to always Trust.

You must quit Keychain Access application on order to use the certificate and restart taskgated service by Killin G The current running taskgated process (so before using GDB).

Xcode comes with gdb that 6,golang needs gdb to be 7, so homebrew's

Brew Install HTTPS://RAW.GITHUB.COM/HOMEBREW/HOMEBREW-DUPES/MASTER/GDB.RB

Add a Certificate

Keychain Access, certificate assistant, select the second, certificate Assistant, create a certificate, the name is Gdb-cert, check the override default, the validity period can be changed a bit longer, step by step, note must choose Code signature, installation must be inside the system.

Configure the certificate, change all to trust mode, and the same way as goagent configuration

Signature

Codesign-s Gdb-cert/usr/local/cellar/gdb/7.7/bin/gdb

Liteide to configure GDB as a new path

Debugging when prompted to enter a password, seemingly entered once, as long as not restart, permanent effective, good

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.