如何在GDB模式下传递输入数据以进行C编程.已传递的参数和运行程序 [英] How to passing input data in GDB mode for programming C. Already passed parameters and run program

查看:31
本文介绍了如何在GDB模式下传递输入数据以进行C编程.已传递的参数和运行程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经知道如何通过运行运行参数"以GDB模式传递参数.但是,当继续通过使用n或s进行调试时,我想将数据传递到程序中,比如说一个文本/字符串.例如,我想向程序发送一个字符串"Testing",因为我的程序总是等待从控制台接收命令.如果我键入"Testing",它将显示未定义的命令:"Testing".尝试帮助".

I already know how to pass parameters in GDB mode by running: "run parameters". However, when continuing to debug by using n or s to go, I would like to pass data to my program, let say a text/string. For example, I want to send a string as "Testing" to my program because my program always waits to receive command from console. If I type "Testing" it will say "undefined command: "Testing". Try help".

(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时,如何将该文本发送到程序中呢?非常感谢.

So how can I do to send this text to my program while debugging GDB in step mode? Thanks very much.

推荐答案

实际上,只需将其键入即可.示例会话:

For real, just type it in. Sample session:

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) 

通常第一次输入 n 后的 Hello,world!.

这篇关于如何在GDB模式下传递输入数据以进行C编程.已传递的参数和运行程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆