簡體   English   中英

在 Windows 終端使用 GDB 有困難。 GDB 在運行程序后自行退出,無需等待我的進一步命令

[英]Difficulty using GDB in Windows terminal. GDB quits itself after running the program without waiting for my further commands

我在底部包含了我的源代碼。 我還在下面復制粘貼我的終端,其中包含我用粗體添加的行號,以試圖讓自己清楚。 我希望 (gdb) 提示在第 10 行中保持活動狀態,但事實並非如此。 它一直運行到第 14 行,如下所示。 即終端本身在第 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;
}

設法弄清楚如何解決此問題。 它所需要的只是將 cygwin gdb package 從https://cygwin.com/install.html更新到當前版本。 我的操作系統是 Windows 10 32 位,所以我使用了 setup-x86.exe。 更新 package 只用了不到 5 分鍾,它就像一種享受,但要達到更新 package 的地步需要 5 天的頭腦麻木的研究。 不起作用的舊版本是 7.9.7-1 (2015)。 新版本為 9.2-1 (2020)。 現在 (gdb) 在運行命令后不會自行退出,它會等待我告訴它該做什么。 我能夠傳遞listprint等命令並能夠獲得預期的響應。 解決問題后,我正在復制粘貼下面的終端。

Microsoft Windows [Version 10.0.19041.685]
(c) 2020 Microsoft Corporation. All rights reserved.
C:\Users\arunmozhi>cd documents
C:\Users\arunmozhi\Documents>cd visual_studio_c_projects
C:\Users\arunmozhi\Documents\Visual_Studio_C_Projects>cd test
C:\Users\arunmozhi\Documents\Visual_Studio_C_Projects\Test>ls
Test.c  a.exe
C:\Users\arunmozhi\Documents\Visual_Studio_C_Projects\Test>gdb a.exe
GNU gdb (GDB) (Cygwin 9.2-1) 9.2
Copyright (C) 2020 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...
(gdb) run
Starting program: 
/cygdrive/c/Users/arunmozhi/Documents/Visual_Studio_C_Projects/Test/a.exe
[New Thread 10188.0xe98]
[New Thread 10188.0x195c]
[New Thread 10188.0x2c8c]
[New Thread 10188.0x14c0]
[New Thread 10188.0x3eac]

Thread 1 "a" received signal SIGSEGV, Segmentation fault.
0x004011d4 in main () at test.c:8
8               sum+=data[i];
(gdb) list 5
1       #include<stdio.h>
2       int main()
3       {
4           const int data[5]={1,2,3,4,5};
5           int i=0, sum=0;
6           for ( i=0; i>=0; i++)
7           {
8               sum+=data[i];
9           }
10          printf("Sum = %d.\n",sum);
(gdb)
11          return 0;
12      }
(gdb) print i
$1 = 209155
(gdb) print sum
$2 = -532459950
(gdb) set var i=2
(gdb) print i
$3 = 2
(gdb)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM