C语言 使用调试器 gdb 时的未知结束信号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40110435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:30:32  来源:igfitidea点击:

Unknown ending signal when using debugger gdb

cmacosgdb

提问by Pierre P.

I have installed GDB on Mac OS X and to test that it works I have used this following C program.

我已经在 Mac OS X 上安装了 GDB 并测试它是否有效,我使用了以下 C 程序。

#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;

}

I have an error when compiling it, which is normal (segmentation fault)

我编译的时候报错,这是正常的(segmentation fault)

However, when adding the -g flagin the compiling command and running gdb on my compiled program, I have this message after launching the command run

但是,在编译命令中添加 -g 标志并在我编译的程序上运行 gdb 时,我在启动命令run后收到此消息

During startup program terminated with signal ?, Unknown signal.

Really don't know where it comes from. I have added a certificate to ensure that gdb works correctly on OS X but I have found nothing to fix this issue.

真的不知道从哪里来。我添加了一个证书以确保 gdb 在 OS X 上正常工作,但我没有找到解决这个问题的方法。

采纳答案by Houssem Nouira

If you're on Sierra , that's expected. GDB isn't compatible with macOS Sierra , even the last release (7.12).

如果你在 Sierra 上,那是意料之中的。GDB 与 macOS Sierra 不兼容,即使是最新版本 (7.12)。

We should maybe wait for another release of GDB , or for another update for macOS in order to get the bug fixed.

我们也许应该等待 GDB 的另一个版本,或者 macOS 的另一个更新,以便修复该错误。

回答by Parth Mehrotra

From this answer: https://stackoverflow.com/a/40437725/1060955

从这个答案: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

这就是我轻松解决问题的方法。[更新:根据收到的反馈尚未验证,该解决方案似乎适用于 macOS Sierra 10.12,但不适用于 macOS Sierra 10.12.2]

在此处查看视频说明

退出 gdb

使用您的文本编辑器,例如 Sublime Text,在您的用户文件夹中保存一个名为“.gdbinit”[排除引号] 的文件。

在文件中添加以下内容:“set startup-with-shell off” [排除引号]

保存文件

gdb 现在应该可以工作了

Sources

来源

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

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

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

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

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

.gdbinit 位于何处以及如何编辑它?

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

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

回答by Muhammad

I installed gdb via Homebrew. At the end of the installation it says:

我通过 Homebrew 安装了 gdb。在安装结束时,它说:

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

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

在 10.12 (Sierra) 或更高版本的 SIP 上,您需要运行以下命令:

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

This was necessary to make it work. Also I had to make sure the .gdbinitwas set in the Eclipse Debug configuration

这是使其工作所必需的。我还必须确保.gdbinit在 Eclipse Debug 配置中设置

回答by Pankaj

For me it worked perfectly on MacOS Sierra Version 10.12.4by just uninstalling and installing gdb as,

对我来说,它在MacOS Sierra 版本 10.12.4上运行完美,只需卸载和安装 gdb,

  1. Uninstall GDB
  1. 卸载 GDB

$ brew uninstall gdb

$ brew 卸载 gdb

  1. Install GDB
  1. 安装 GDB

$ brew install gdb

$ brew 安装 gdb

This will install latest gdb which is compatible with MacOS Sierra.

这将安装与 MacOS Sierra 兼容的最新 gdb。

Hope this help to anyone!

希望这对任何人都有帮助!

回答by audrow

Sierra (10.12) doesn't seem to support gdb. I tried following a tutorial that had me create a certificate. Afterwards, when I ran gdb, I got the same error mentioned.

Sierra (10.12) 似乎不支持gdb. 我尝试按照让我创建证书的教程进行操作。之后,当我运行时gdb,我遇到了同样的错误。

Apple uses lldb. It works well, and can integrate with Eclipse, I've been told. Here is a link.

苹果使用lldb. 有人告诉我,它运行良好,并且可以与 Eclipse 集成。这是一个链接