在 macos Mojave 10.14 上使用 gdb 时出现代码错误

codesigned errors when using gdb on macos Mojave 10.14

我有 MacOS Mojave 10.14。
GNU gdb (GDB) 8.2.1

我读了很多关于这个的帖子,但我想知道 2019 年是否有什么变化,因为大多数文章都是旧的。
从: Eclipse GDB MacOSX Mavericks

我做到了:

Start Keychain Access application (/Applications/Utilities/Keychain Access.app)
Open menu /Keychain Access/Certificate Assistant/Create a Certificate (TOP MENU BAR)

Choose a name (gdb-cert in the example) 3.1 Set "Identity Type" to "Self Signed Root" 3.2 Set "Certificate Type" to "Code Signing" 3.3 Check the flag "Let me override defaults" 3.4 Click several times on "Continue" until you get to the "Specify a Location For The Certificate screen" then set Keychain to "System" 3.6 Make sure you have the "gdb-cert" in your "System" (left top window)

Select "Get Info" by pressing twice on the fresh made certificate (gdb-cert),

Open the "Trust" item, and set "Code Signing to Always Trust" Close Keychain Access application

Restart "taskgated" application (kill -9) and finally
codesign -s gdb-cert /usr/local/bin/gdb

但我仍然得到错误:

lee@l7:~/eclipse-workspace-cdt/my-proj/build$ ./my-proj
Hello world
(the exe works fine)
lee@l7:~/eclipse-workspace-cdt/my-proj/build$ gdb my-proj
GNU gdb (GDB) 8.2.1 Copyright (C) 2018 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-darwin18.2.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/.

For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from my-proj...done.

(gdb) run

Starting program: /Users/lefla/eclipse-workspace-cdt/my-proj/build/my-proj Unable to find Mach task port for process-id 12808: (os/kern) failure (0x5). (please check gdb is codesigned - see taskgated(8))

(gdb) run

Starting program: /Users/lefla/eclipse-workspace-cdt/my-proj/build/my-proj Unable to find Mach task port for process-id 12819: (os/kern) failure (0x5). (please check gdb is codesigned - see taskgated(8))

如果 gdb 已签名,它应该能够派生其他进程。 killing "taskgated" 是否足够(一些文章提到重启机器)?有什么问题吗?

______ 编辑 1
正在关注
https://sourceware.org/gdb/wiki/PermissionsDarwin
驱使我走得更远。然后我遇到了这个问题:
gdb terminated with signal ?, unknown signal
所以我创建了 .gdbinit,现在我得到:

(gdb) run
Starting program: /Users/lefla/eclipse-workspace-cdt/my-proj/build/my-proj
[New Thread 0x1a03 of process 14140]
[New Thread 0x2603 of process 14140]
During startup program terminated with signal SIGTRAP, Trace/breakpoint trap.

______ 编辑 2
使用 gdb 8.0.1 时,我得到:

my-proj": not in executable format: File format not recognized

似乎与以下相关:
https://sourceware.org/bugzilla/show_bug.cgi?id=23746
但是 gdb 8.3 刚刚发布,它终于可以与 gdb 8.3

一起使用了

gdb 协同设计在 10.14+ 中需要适当的权利: https://sourceware.org/gdb/wiki/PermissionsDarwin

编辑:现在您可能正在重复此错误,需要降级 gdb … 答案有说明。

编辑 2:看起来升级到 gdb 8.3 现在应该适合您了。