Solve the problem of gdb debugging on Mac system
On a Mac, you may encounter the following error when using gdb for the first time:
(gdb) run
Starting program: /usr/local/bin/order_monitor
Unable to find Mach task port for process-id 26551: (os/kern) failure (0x5).
(please check gdb is codesigned - see taskgated(8))
This is because the Darwin kernel does not allow debugging other processes without special permissions. Debugging a process means that you have full control over the process, so it is disabled by default to prevent malicious use. The best way to allow gdb to control other processes is to sign it with a certificate that the system trusts.
Create a certificate
Follow these steps to create a code signing certificate:
- Open the Keychain Access application
- Go to menu Keychain Access -> Certificate Assistant -> Create Certificate
-
Fill in the following information:
- Name: gdb_codesign (you can customize other names)
- Identity Type: Self-signed root certificate
- Certificate Type: Code Signing
- Check: Let me override these defaults
- Continue until you reach the step to specify the certificate location and select System
- Click "Create" and you will be prompted for the data system login password, and the creation is complete. (Note: If you select the system in the fourth step , the creation may fail. At this time, you can choose to log in in the fourth step to create it. After the creation is successful, just drag the newly created certificate directly into the system on the left . If you can create it directly by selecting the system , ignore this note)
- In the Keychain Access program, select System and My Certificates in the left column, find the gdb_codesign certificate you just created , double-click it to open the certificate information window, expand the Trust item, and set When using this certificate : Always trust .
- Close the certificate information window and the system will ask you to enter the system login password again.
Sign gdb
Execute the following command
codesign -fs gdb_codesign(上面创建的证书名称) $(which gdb)
Note: The above signing command is for Mac systems before version 10.14 (Mojave). If our system is after 10.14 (Mojave), we need to create a file gdb-entitlement.xml first , the content is as follows:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.cs.debugger</key> <true/> </dict> </plist> </pre>
Then execute
codesign --entitlements gdb-entitlement.xml -fs gdb_codesign $(which gdb)
After completion, be sure to restart the system, otherwise the signature will not take effect.
Solve the problem of gdb debugging failure
After the above operation, the gdb signature problem is solved. However, sometimes you may encounter the following problems.
(gdb) run
Starting program: /usr/local/bin/order_monitor
During startup program terminated with signal ?, Unknown signal.
The solution is very simple, just execute the following command
set startup-with-shell off
For convenience, this command can be written to the .gdbinit file in your personal directory.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
Creating a signature from Hash_hmac() and Sha256 in PHP
Publish Date:2025/04/13 Views:107 Category:PHP
-
PHP has one of the best encryption functions for data security. Hash_hmac() The encrypt function is one of the most famous encryptors. We'll show you how to use hash_hmac and sha256 encryptors to create 安全签名 one that you can store i
Running PHP on Mac
Publish Date:2025/04/12 Views:183 Category:PHP
-
In this article, we'll show you how to run PHP on your Mac. php -S Run PHP on Mac using command PHP is a server-side language. It runs on a server. Therefore, it requires a web server to run. There are different web servers like Apache HTTP
How to use clion to debug redis source code on mac system
Publish Date:2025/04/09 Views:172 Category:Redis
-
clion mainly uses cmake + make for compilation. So for redis4, the main thing is to write the CMakeLists.txt file first. CmakeLists.txt file redis4/CMakeLists.txt cmake_minimum_required (VERSION 3.15 ) project (redis4) set (CMAKE_BUILD_TYPE
Mac system uses clion to remotely debug redis4 source code
Publish Date:2025/04/09 Views:129 Category:Redis
-
The remote host uses the Linux system. The first step is definitely to establish a code synchronization mechanism on the local and remote hosts - sftp is the first choice. The second step is to write the CMakeLists.txt file of redis4. There
Mac Modify the host name and prompt in terminal and iterm
Publish Date:2025/04/07 Views:178 Category:OPERATING SYSTEM
-
Commonly used terminals on Mac are terminal and iterm. In many cases, we need to modify the host name displayed in these terminals. As shown in the figure above, we use the command hostname to view the current host name From the results we
PHPStorm shortcut keys for Win/Linux/Mac
Publish Date:2025/04/07 Views:125 Category:OPERATING SYSTEM
-
edit Win / Linux Mac Notes Frequency of use Ctrl + Space ⌃Space Code auto-completion (usually conflicts with input method) ★☆☆☆☆ Ctrl + Shift + Enter ⌘ ⇧ ↩ Intelligent code completion (such as: if ()) ★☆☆☆☆ Ctrl
Mac shuts down BaiduNetdiskSync service
Publish Date:2025/04/07 Views:193 Category:OPERATING SYSTEM
-
I don't know if you have installed Baidu Netdisk on your Mac. If you have installed and used it, we will find through Activity Monitor that there is a baiduNetdiskSync service that has always existed. It is very distressing. Let's shut down
Installing and configuring Redis on Mac OS X via Homebrew
Publish Date:2025/04/07 Views:108 Category:OPERATING SYSTEM
-
By using Homebrew, you can greatly reduce the cost of setting up and configuring a development environment on Mac OS X. Let's install Redis. $ brew install redis After installation, we will see some notifications about configuration conside
PBKDF2+HMAC Hash Conflict
Publish Date:2025/04/06 Views:56 Category:OPERATING SYSTEM
-
Cryptocurrency enthusiast Christian 'CodesInChaos' Winnerlein once wrote: plnlrtfpijpuhqylxbgqiiyipieyxvfsavzgxbbcfusqkozwpngsyejqlmjsytrmd and eBkXQTfuBqp'cTcarg* have the same PBKDF2-HMAC-SHA1 hash. This intrigued me, so I decided to find