C 在Windows终端中使用GDB有困难。GDB在运行程序后退出,而不等待我的进一步命令

C 在Windows终端中使用GDB有困难。GDB在运行程序后退出,而不等待我的进一步命令,c,gdb,C,Gdb,我在底部包含了我的源代码。我还复制粘贴我的终端下面的行号,我加上自己的粗体,试图让自己清楚。我希望(gdb)提示符在第10行中保持活动状态,但事实并非如此。它一直运行到第14行,如下所示。i、 e终端本身在第10行发出退出命令,并一直运行,直到在第14行停止。我怎样才能在10号线停下来?换句话说,我如何阻止终端向(gdb)发出“退出”命令 下面的终端复制粘贴 PS C:\Users\arunmozhi\Documents\Visual_Studio_C_Projects\Test> gdb

我在底部包含了我的源代码。我还复制粘贴我的终端下面的行号,我加上自己的粗体,试图让自己清楚。我希望(gdb)提示符在第10行中保持活动状态,但事实并非如此。它一直运行到第14行,如下所示。i、 e终端本身在第10行发出退出命令,并一直运行,直到在第14行停止。我怎样才能在10号线停下来?换句话说,我如何阻止终端向(gdb)发出“退出”命令

下面的终端复制粘贴

PS C:\Users\arunmozhi\Documents\Visual_Studio_C_Projects\Test> gdb a.exe
GNU gdb (GDB) Cygwin 7.9.1-1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"... 
Reading symbols from a.exe...done.
(gdb) run
Starting program: /cygdrive/c/Users/arunmozhi/Documents/Visual_Studio_C_Projects/Test/a.exe
**Line 1:**[New Thread 2136.0xdbc]
**Line 2:**[New Thread 2136.0x2958]
**Line 3:**[New Thread 2136.0xf20]
**Line 4:**[New Thread 2136.0x2a5c]
**Line 5:**[New Thread 2136.0x13f4]
**Line 6:**[New Thread 2136.0x109c]
**Line 7:** Program received signal SIGSEGV, Segmentation fault.
**Line 8:** 0x004011d4 in main () at test.c:8
**Line 9:** 8 sum+=data[i];
**Line 10:** (gdb) quit
**Line 11:** A debugging session is active.
**Line 12:** Inferior 1 [process 2136] will be killed.
**Line 13:** Quit anyway? (y or n) EOF [assumed Y]
**Line 14:** PS C:\Users\arunmozhi\Documents\Visual_Studio_C_Projects\Test>
#include<stdio.h>
int main()
{
    const int data[5]={1,2,3,4,5};
    int i=0, sum=0;
    for ( i=0; i>=0; i++)//incorrect code intentionally written to learn debugging with gdb
    {
        sum+=data[i];
    }
    printf("Sum = %d.\n",sum);
    return 0;
}
PS C:\Users\arunmozhi\Documents\Visual\u Studio\u C\u Projects\Test>gdb a.exe
GNU gdb(gdb)Cygwin 7.9.1-1
版权所有(C)2015免费软件基金会。
许可证GPLv3+:GNU GPL版本3或更高版本
这是自由软件:您可以自由更改和重新发布它。
在法律允许的范围内,不存在任何担保。键入“显示复制”
和“显示保修”了解详细信息。
此GDB配置为“i686 pc cygwin”。
键入“显示配置”以获取配置详细信息。
有关错误报告说明,请参阅:
.
在线查找GDB手册和其他文档资源,网址为:
.
要获得帮助,请键入“帮助”。
键入“apropos word”以搜索与“word”相关的命令。。。
从a.exe读取符号…完成。
(gdb)运行
启动程序:/cygdrive/c/Users/arunmozhi/Documents/Visual_Studio_c_Projects/Test/a.exe
**第1行:*[新线程2136.0xdbc]
**第2行:*[新螺纹2136.0x2958]
**第3行:*[新螺纹2136.0xf20]
**第4行:*[新螺纹2136.0x2a5c]
**第5行:*[新线程2136.0x13f4]
**第6行:*[新螺纹2136.0x109c]
**第7行:*程序接收信号SIGSEGV,分段故障。
**第8行:**0x004011d4位于test.c:8的main()中
**第9行:**8总和+=数据[i];
**第10行:*(gdb)退出
**第11行:*调试会话处于活动状态。
**第12行:**1[进程2136]将被终止。
**第13行:*还是退出?(y或n)EOF[假设y]
**第14行:*PS C:\Users\arunmozhi\Documents\Visual\u Studio\u C\u Projects\Test>
下面的源代码

PS C:\Users\arunmozhi\Documents\Visual_Studio_C_Projects\Test> gdb a.exe
GNU gdb (GDB) Cygwin 7.9.1-1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"... 
Reading symbols from a.exe...done.
(gdb) run
Starting program: /cygdrive/c/Users/arunmozhi/Documents/Visual_Studio_C_Projects/Test/a.exe
**Line 1:**[New Thread 2136.0xdbc]
**Line 2:**[New Thread 2136.0x2958]
**Line 3:**[New Thread 2136.0xf20]
**Line 4:**[New Thread 2136.0x2a5c]
**Line 5:**[New Thread 2136.0x13f4]
**Line 6:**[New Thread 2136.0x109c]
**Line 7:** Program received signal SIGSEGV, Segmentation fault.
**Line 8:** 0x004011d4 in main () at test.c:8
**Line 9:** 8 sum+=data[i];
**Line 10:** (gdb) quit
**Line 11:** A debugging session is active.
**Line 12:** Inferior 1 [process 2136] will be killed.
**Line 13:** Quit anyway? (y or n) EOF [assumed Y]
**Line 14:** PS C:\Users\arunmozhi\Documents\Visual_Studio_C_Projects\Test>
#include<stdio.h>
int main()
{
    const int data[5]={1,2,3,4,5};
    int i=0, sum=0;
    for ( i=0; i>=0; i++)//incorrect code intentionally written to learn debugging with gdb
    {
        sum+=data[i];
    }
    printf("Sum = %d.\n",sum);
    return 0;
}
#包括
int main()
{
const int data[5]={1,2,3,4,5};
int i=0,sum=0;
for(i=0;i>=0;i++)//为学习使用gdb进行调试而故意编写的错误代码
{
总和+=数据[i];
}
printf(“总和=%d.\n”,总和);
返回0;
}

设法解决了这个问题。它所需要的只是将cygwin gdb包从更新到当前版本。我的操作系统是Windows 10 32位,所以我使用了setup-x86.exe。更新软件包只花了不到5分钟,效果很好,但更新软件包却花了5天的时间。旧版本是7.9.7-1(2015年),但不起作用。新版本是9.2-1(2020)。现在(gdb)在run命令后不会自动退出,它会等待我告诉它该怎么做。我能够传递诸如列表、打印等命令,并能够得到预期的响应。修复问题后,我正在复制粘贴下面的终端

Microsoft Windows[版本10.0.19041.685] (c) 2020年微软公司。版权所有

C:\Users\arunmozhi>cd文档

C:\Users\arunmozhi\Documents>cd visual studio\U C\U项目

C:\Users\arunmozhi\Documents\Visual Studio\U C\U Projects>cd测试

C:\Users\arunmozhi\Documents\Visual\u Studio\u C\u Projects\Test>ls Test.ca.exe

C:\Users\arunmozhi\Documents\Visual\u Studio\u C\u Projects\Test>gdb a.exe

GNU gdb(gdb)(Cygwin 9.2-1)9.2

版权(C)2020免费软件基金会,公司< /P> 许可证GPLv3+:GNU GPL版本3或更高版本

这是自由软件:您可以自由更改和重新发布它

在法律允许的范围内,不存在任何担保

有关详细信息,请键入“显示复制”和“显示保修”

此GDB配置为“i686 pc cygwin”

键入“显示配置”以获取配置详细信息

有关错误报告说明,请参阅:

在线查找GDB手册和其他文档资源,网址为:

<http://www.gnu.org/software/gdb/documentation/>.
要获得帮助,请键入“帮助”

键入“apropos word”以搜索与“word”相关的命令

正在从a.exe读取符号

(gdb)运行

启动程序:

/cygdrive/c/Users/arunmozhi/Documents/Visual_Studio_c_Projects/Test/a.exe

[新线程10188.0xe98]

[新螺纹10188.0x195c]

[新螺纹10188.0x2c8c]

[新螺纹10188.0x14c0]

[新线程10188.0x3eac]

线程1“a”接收到信号SIGSEGV,分段故障

测试c:8处的main()中的0x004011d4

8总和+=数据[i]

(gdb)清单5

1#包括

2 int main()

三,{

4常量int数据[5]={1,2,3,4,5}

5整数i=0,和=0

6表示(i=0;i>=0;i++)

七,{

8总和+=数据[i]

9}

10 printf(“总和=%d.\n”,总和)

(gdb)

11返回0

12}

(gdb)打印i

$1=209155

(gdb)打印金额

$2=-532459950

(gdb)设置变量i=2

(gdb)打印i

$3=2


(gdb)

设法解决了这个问题。它所需要的只是将cygwin gdb包从更新到当前版本。我的操作系统是Windows 10 32位,所以我使用了setup-x86.exe。更新软件包只花了不到5分钟,效果很好,但更新软件包却花了5天的时间。旧版本是7.9.7-1(2015年),但不起作用。新版本是9.2-1(2020)。现在(gdb)在run命令后不会自动退出,它会等待我告诉它该怎么做。我能够传递诸如列表、打印等命令,并能够得到预期的响应。修复问题后,我正在复制粘贴下面的终端

Microsoft Windows[版本10.0.19041.685] (c) 2020微