2016-10-18 43 views
20

我在Mac OS X上安裝了GDB,並測試它的工作原理我已經使用了下面這個C程序。使用調試器gdb時出現未知的結束信號

#include <stdio.h> 
#include <stdlib.h> 

int main(int argc, char *argv[]) { 

    int *my_array = (int *) malloc(5 * sizeof(int)); 
    int i; 
    for (i = 0; i < 1000000; i++) { 
     my_array[i] = i; 
    } 

    free(my_array); 

    return 0; 

} 

我編譯時有一個錯誤,這是正常的(分段錯誤)

然而,當加入-g標誌在編譯命令,並在我的編譯的程序運行gdb的,我有啓動命令運行

During startup program terminated with signal ?, Unknown signal. 

後,此消息真的不知道它從何而來。我已經添加了一個證書來確保gdb在OS X上正常工作,但是我沒有找到解決這個問題的方法。

+0

您應該嘗試下面的解決方案並指出哪一個可以幫助您解決問題。 –

回答

19

如果你在塞拉利昂,這是預期的。 GDB與macOS Sierra不兼容,即使是最後一個版本(7.12)。

我們也許應該等待另一個版本的GDB,或者爲了修復macOS的另一個更新。

+7

請參閱http://stackoverflow.com/questions/39702871/gdb-kind-of-doesnt-work-on-macos-sierra。 – dbrank0

+1

一定要向下滾動,可能有下面列出的解決方案 –

+0

這不再是完全正確的(謝天謝地)。 –

23

從這樣的回答:https://stackoverflow.com/a/40437725/1060955

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

Quit gdb

Using your text editor e.g. Sublime Text, save a file called 「.gdbinit」 [Exclude the quotation marks] in your user folder.

In the file add the following: 「set startup-with-shell off」 [Exclude the quotation marks]

Save the file

gdb should now work

來源

https://stackoverflow.com/a/40437725/1060955

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

哪裏.gdbinit位於以及如何修改呢?

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

+0

簽署gdb後爲我工作。爲了簡化,你可以在Terminal裏運行這些命令:'touch〜/ .gdbinit;設置startup-with-shell off>〜/ .gdbinit' –

+2

這個命令是錯誤的。 'touch〜/ .gdbinit; echo「set startup-with-shell off」>〜/ .gdbinit'是對的 – user3875388

1

塞拉利昂(10.12)似乎並不支持gdb。我試着按照一個教程,讓我創建一個證書。之後,當我運行gdb時,我遇到了同樣的錯誤。

Apple使用lldb。它運行良好,並且可以與Eclipse集成,據我所知。這是一個link

3

對我來說非常完美的塞拉利昂的MacOS版本10.12.4僅通過卸載並安裝GDB的,

  1. 卸載GDB

$ brew uninstall gdb

  • 安裝GDB
  • $ brew install gdb

    這將安裝與MacOS Sierra兼容的最新gdb。

    希望對任何人都有幫助!

    4

    我通過Homebrew安裝了gdb。 在安裝結束時,它說:

    On 10.12 (Sierra) or later with SIP, you need to run this:

    echo "set startup-with-shell off" >> ~/.gdbinit 
    

    這是必要的,使其工作。另外,我必須確保在Eclipse Debug配置中設置了.gdbinit

    +0

    它與High Sierra 10.13.2以及gdb 8.0(從源代碼安裝)和Visual Studio Code一起工作。 – msk