1

I'm running Mojave on my Macbook pro. I've installed gdb 8.3 via brew.

I've codesigned it following the instructions given in

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

I've also turned system integrity completely off and yet I'm having problems getting gdb to work.

I have a simple c program called test_sleep.c compiled with -g.

If I run

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

I get the usual codesigned error, even though I've codesigned gdb.

enter image description here

A partial workaround is to run run gdb with sudo

Then I can actually debug, but I first get a dozen warnings

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)

So my questions are (1) why doesn't gdb work without sudo and (2) why does running with sudo produce all the warnings?

Fortunately lldb works cleanly against a gcc built binary, so I'll probably give up on gdb and switch to lldb. But I'd still like to know why Apple makes something that works effortlessly on Linux, so complicated.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.