为什么GDB调试器没有回显,需要两次输入,或者无法与目标程序交互?

问题描述 投票:0回答:1

我刚刚开始用gdb调试(以前从未使用过) 一个简单的程序:

#include <stdio.h>

void main()
{
    char str[100];
    printf("Enter a string: ");
    scanf("%s", str);
    printf("You entered: %s", str);
}

运行:

PS D:\start_video\c> gcc -g temp.c -o temp
PS D:\start_video\c> gdb .\temp.exe
GNU gdb (GDB) (Cygwin 13.2-1) 13.2
Copyright (C) 2023 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 "x86_64-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://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 .\temp.exe...
(gdb) l
warning: Source file is more recent than executable.
1       #include <stdio.h>
2
3       void main()
4       {
5           char str[100];
6           printf("Enter a string: ");
7           scanf("%s", str);
8           printf("You entered: %s", str);
9       }
(gdb) run
Starting program: /cygdrive/d/start_video/c/.\temp.exe
[New Thread 14552.0x3b5c]
Enter a string: You entered: nsrfcs[Thread 14552.0x3b5c exited with code 19]

Program terminated with signal SIGCONT, Continued.
The program no longer exists.
(gdb)

我尝试更改代码,更大的问题出现了! 这个连接根本无法进入!我尝试在键盘上打字 没有任何反应! 稍等片刻,就会出现: [线程 3628.0x4644 退出,代码为 0]

为什么??? 这是我的问题还是gdb的问题?

#include <stdio.h>
#include <string.h>

int main() {
    char str[100];
    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);
    str[strcspn(str, "\n")] = 0; 
    printf("You entered: %s\n", str);
    return 0;
}
PS D:\start_video\c> gcc -g temp.c -o temp
PS D:\start_video\c> gdb .\temp.exe
GNU gdb (GDB) (Cygwin 13.2-1) 13.2
Copyright (C) 2023 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 "x86_64-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://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 .\temp.exe...
(gdb) run
Starting program: /cygdrive/d/start_video/c/.\temp.exe
[New Thread 17252.0x11d8]
qn trjry tring: You entered: sagagg
[Thread 17252.0x11d8 exited with code 0]
[Inferior 1 (process 17252) exited normally]
(gdb) run
Starting program: /cygdrive/d/start_video/c/.\temp.exe
[New Thread 9856.0x3f08]
Enter a string: [Thread 9856.0x3f08 exited with code 0]

c gdb
1个回答
0
投票

感谢ssbssa,我认为这是一个“Windows Terminal Preview”问题,因为我可以在cygwin终端中运行命令而不会出现上述问题

© www.soinside.com 2019 - 2024. All rights reserved.