私はMacbook ProでMojaveを実行しています。 Brew経由でgdb 8.3をインストールしました。
次の指示に従ってコードに署名しました。
https://sourceware.org/gdb/wiki/PermissionsDarwin
また、システムの完全性を完全にオフにしてgdbを操作するのにも問題があります。
-gでコンパイルされたtest_sleep.cという単純なCプログラムがあります。
走れば
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を使用してgdbを実行することです。
その後、実際にデバッグできますが、最初に12の警告が表示されます。
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)sudoなしでgdbが機能しない理由と、(2)sudoで実行するとすべての警告が生成されるのはなぜですか?
幸いなことに、lldbはgccベースのバイナリに対して完全に機能するため、おそらくgdbをあきらめてlldbに切り替えます。しかし、私はなぜAppleがLinux上で実行しやすいものをとても複雑にするのかはまだ疑問に思っています。