将文件输入和Stdin传递到gdb [英] Pass File Input and Stdin to gdb

查看:101
本文介绍了将文件输入和Stdin传递到gdb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想用文件的内容作为参数在gdb中运行一个程序.然后,当命中EOF时,我希望能够再次输入用户输入.对于终端中的普通程序,我可以使用以下命令执行类似的操作.

So I want to run a program in gdb with the contents of a file as an argument. Then, when an EOF is hit, I want to be able to enter user input again. For a normal program in a terminal I can do something like this with the following command.

(cat input.txt; cat) | ./program

在gdb中,我可以像这样传递文件参数,但是到达文件末尾后,它将继续永远输入换行符.

In gdb I can pass in the file arguments like this, but it continues to enter newlines forever after the end of the file has been reached.

(gdb) run < input.txt

几乎就像没有将stdin传递回程序一样,类似于如果我只是这样做

It is almost as if stdin was not passed back to the program, similar to what happens if I simply do

(cat input.txt) | ./program

没有第二个 cat .甚至可以在gdb中做到这一点吗?

without the second cat. Is this even possible to do in gdb?

推荐答案

您可以在一个控制台中运行该程序,并在等待输入时将其与gdb附加到另一个控制台.因此,您将能够在第一个控制台中输入程序输入并在第二个控制台中对其进行调试.

You can run the program in one console and attach to it with gdb from another one when it is waiting for input. Therefore you will be able to enter program input in the 1st console and debug it in the 2nd.

这篇关于将文件输入和Stdin传递到gdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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