如何调试一个程序,从stdin接受用户输入和GDB? [英] How to debug a program that takes user input from stdin with GDB?

查看:234
本文介绍了如何调试一个程序,从stdin接受用户输入和GDB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,我正在尝试使用gdb进行调试。在程序内部,我有一些方法需要用户使用stdin输入输入。我在gdb时如何输入这个输入?所以我可以跟踪我的方法是如何工作的?

I have a program and I am trying to debug it using gdb. Inside the program I have methods that require the user to enter an input using stdin. How can I enter this input when I am in gdb? So that I can trace how my methods work?

推荐答案

$ cat >foo <<EOF
something
EOF
$ gdb -quiet /bin/cat
Reading symbols from /bin/cat...(no debugging symbols found)...done.
Missing separate debuginfos, use: debuginfo-install coreutils-8.12-7.fc16.x86_64
(gdb) run <foo
Starting program: /bin/cat <foo
something
[Inferior 1 (process 22436) exited normally]
(gdb) 

这篇关于如何调试一个程序,从stdin接受用户输入和GDB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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