我已经知道如何通过运行以下命令在GDB模式下传递参数:"运行参数"。但是,当继续使用n或s进行调试时,我想将数据传递给我的程序,比方说文本/字符串。例如,我想发送一个字符串作为"测试"到我的程序,因为我的程序总是等待从控制台接收命令。如果我输入"测试"它会说"未定义的命令:"测试"。尝试帮助"。
(gdb) b 100
(gdb) run "pass parameters to program here"
(gdb) n
(gdb) Now I want to send a string to my program, how can I do it?
那么在步骤模式下调试GDB时,如何将此文本发送到我的程序呢?非常感谢。
答案 0 :(得分:1)
如果是真的,只需输入。示例会话:
paul@local:~/src/c/scratch$ gdb ./deb
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 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-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/paul/src/c/scratch/deb...done.
(gdb) list
1 #include <stdio.h>
2
3 int main(void) {
4 char buffer[100];
5 fgets(buffer, 100, stdin);
6 printf("You entered: %s", buffer);
7 return 0;
8 }
(gdb) break 4
Breakpoint 1 at 0x400644: file deb.c, line 4.
(gdb) run
Starting program: /home/paul/src/c/scratch/deb
Breakpoint 1, main () at deb.c:5
5 fgets(buffer, 100, stdin);
(gdb) n
Hello, world!
6 printf("You entered: %s", buffer);
(gdb) n
You entered: Hello, world!
7 return 0;
(gdb) continue
Continuing.
[Inferior 1 (process 4290) exited normally]
(gdb)
第一个Hello, world!
之后的n
只是正常输入。