我很难让 gdb 在莫哈韦沙漠上工作

我很难让 gdb 在莫哈韦沙漠上工作

我在 Macbook pro 上运行 Mojave。我已经通过brew安装了gdb 8.3。

我已经按照中给出的说明对其进行了代码签名

https://sourceware.org/gdb/wiki/PermissionsDarwin

我还完全关闭了系统完整性,但在让 gdb 工作时遇到问题。

我有一个简单的 c 程序,名为 test_sleep.c,用 -g 编译。

如果我跑

cs_mac > gdb -q  sleep_test
Reading symbols from sleep_test...
Reading symbols from /Users/richard/home/richard/programming_tests/mac/c_tests/examples/sleep_test.dSYM/Contents/Resources/DWARF/sleep_test...
(gdb) b main
Breakpoint 1 at 0x100000f2f: file sleep_test.c, line 7.
(gdb) r
Starting program: /Users/richard/home/richard/programming_tests/mac/c_tests/examples/sleep_test
Unable to find Mach task port for process-id 2590: (os/kern) failure (0x5).
 (please check gdb is codesigned - see taskgated(8))
(gdb

尽管我已经对 gdb 进行了代码签名,但我还是收到了常见的代码签名错误。

在此输入图像描述

部分解决方法是使用 sudo 运行 run gdb

然后我可以实际调试,但我首先收到十几个警告

cs_mac > sudo /usr/local/bin/gdb -q sleep_test
Password:
Reading symbols from sleep_test...
Reading symbols from /Users/richard/home/richard/programming_tests/mac/c_tests/examples/sleep_test.dSYM/Contents/Resources/DWARF/sleep_test...
(gdb) b main
Breakpoint 1 at 0x100000f2f: file sleep_test.c, line 7.
(gdb) r
Starting program: /Users/richard/home/richard/programming_tests/mac/c_tests/examples/sleep_test
[New Thread 0x1003 of process 2646]
[New Thread 0xe03 of process 2646]
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/bsd.o': can't open to read symbols: No such file or directory.
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/darwin_vers.o': can't open to read symbols: No such file or directory.
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/dirstat.o': can't open to read symbols: No such file or directory.
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/dirstat_collection.o': can't open to read symbols: No such file or directory.
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/err.o': can't open to read symbols: No such file or directory.
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/exception.o': can't open to read symbols: No such file or directory.
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/init.o': can't open to read symbols: No such file or directory.
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/mach.o': can't open to read symbols: No such file or directory.
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/stdio.o': can't open to read symbols: No such file or directory.
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/stdlib.o': can't open to read symbols: No such file or directory.
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/string.o': can't open to read symbols: No such file or directory.
warning: `/BuildRoot/Library/Caches/com.apple.xbs/Binaries/Libc_darwin/install/TempContent/Objects/Libc.build/libsystem_darwin.dylib.build/Objects-normal/x86_64/variant.o': can't open to read symbols: No such file or directory.

Thread 2 hit Breakpoint 1, main () at sleep_test.c:7
7    for (i=0;i<10;i++)
(gdb) l
2    #include <unistd.h>
3
4    int main()
5    {
6    int i;
7    for (i=0;i<10;i++)
8        {
9             printf("%d \n",i);
10             sleep(1);
11       }
(gdb) n
9             printf("%d \n",i);
(gdb)

所以我的问题是(1)为什么 gdb 没有 sudo 就不能工作以及(2)为什么使用 sudo 运行时会产生所有警告?

幸运的是,lldb 可以完美地对抗 gcc 构建的二进制文件,因此我可能会放弃 gdb 并切换到 lldb。但我仍然想知道为什么 Apple 将在 Linux 上轻松运行的东西做得如此复杂。

相关内容