GDB kind of doesn't work on macOS Sierra

前端 未结 8 727
梦毁少年i
梦毁少年i 2020-12-02 07:55

It is a problem that appeared when I first updated to macOS Sierra yesterday.

GDB itself is running OK. However, somehow, it cannot run my program. When I type \'run

相关标签:
8条回答
  • 2020-12-02 08:06

    Multiple solutions that worked for Sierra 10.12.0 do not work with Sierra 10.12.1. With this version, you need an updated version of GDB (patch committed at FSF on Nov 9), in addition to disabling spawning of shell with 'set startup-with-shell off'. See instructions at http://blog.adacore.com/gnat-on-macos-sierra

    0 讨论(0)
  • 2020-12-02 08:09

    This is due to a Runtime Integrity Protection feature in Sierra - you can deactivate it by following the instructions here.

    1. Reboot your system Keep command+R pressed until the Apple logo appears on the screen.
    2. Select the menu Utilities/Terminal Type "csrutil enable --without debug" in the terminal
    3. Finally, reboot your machine again

    Note that disabling this will lower the security of your system, so doing the above should really be your decision.

    Another impact of this change is that the DYLD_LIBRARY_PATH variable is no longer reset when spawning new processes via the shell. This variable is used by the dynamic linker to find dynamic libraries. It takes precedence over the search path coded in the executables, so is considered as unsafe by the OS. As a result, macOS by default unsets the variable so that the executable you spawn uses its own libraries. We recommend using the DYLD_FALLBACK_LIBRARY_PATH instead, which comes after the application's library search path, in case some libraries are still not found.

    0 讨论(0)
  • 2020-12-02 08:09

    This works for me:

    • Unlink current gdb: brew unlink gdb

    • Install gdb 8.0.1: brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/9ec9fb27a33698fc7636afce5c1c16787e9ce3f3/Formula/gdb.rb

    • Optional: avoid upgrade gdb with brew pin gdb

    0 讨论(0)
  • 2020-12-02 08:10

    I know my answer is not specifically related to GDB, but since I also had some difficulties making GDB to work myself, I'd like to recommend you to give a try on LLDB. For me, it worked like a charm:

    https://developer.apple.com/library/content/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/lldb-terminal-workflow-tutorial.html

    Since Xcode itself now uses LLDB instead of GDB, this can be a more convenient alternative for Mac users. And, in my particular case, it integrated much easier in Eclipse than GDB:

    https://wiki.eclipse.org/CDT/User/FAQ#How_do_I_get_the_LLDB_debugger.3F

    0 讨论(0)
  • 2020-12-02 08:11

    assume your MacOS version is 10.12.6.

    1. upgrade your gdb to version 8.0.1 brew upgrade gdb
    2. execute echo "set startup-with-shell off" >> ~/.gdbinit ( I saw this command when I installed gdb by brew )
    3. create a certificate with name gdb-cert and trust this certificate in code signing option
    4. reboot your mac
    5. execute sudo codesign -s gdb-cert /usr/local/bin/gdb
    6. done! have a fun ~

    BTW,you can use lldb to replace gdb .

    0 讨论(0)
  • 2020-12-02 08:12

    This is how I easily fixed the issue. [Update: based on feedback received and yet to be verified, it seems that this solution works with macOS Sierra 10.12 but not with macOS Sierra 10.12.2]

    See video instructions here

    1. Quit gdb
    2. Using your text editor e.g. Sublime Text, save a file called .gdbinit in your user folder.
    3. In the file add the following: set startup-with-shell off
    4. Save the file
    5. gdb should now work

    Sources

    https://discussions.apple.com/thread/7684629?start=0&tstart=0

    Where is .gdbinit is located and how can I edit it?

    https://sourceware.org/gdb/onlinedocs/gdb/Starting.html

    0 讨论(0)
提交回复
热议问题