如何加载程序读取标准输入并在 gdb 中获取参数? [英] How to load program reading stdin and taking parameters in gdb?

查看:24
本文介绍了如何加载程序读取标准输入并在 gdb 中获取参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序从stdin 并且还需要一些参数从命令行.它看起来像这样:

I have a program that takes input from stdin and also takes some parameters from command line. It looks like this:

cat input.txt > myprogram -path "/home/user/work"

我尝试用 gdb 调试代码在 emacs 中,通过 M-x gdb,我尝试使用命令加载程序:

I try to debug the code with gdb inside emacs, by M-x gdb, I try to load the program with the command:

gdb cat input.txt > myprogram -path "/home/user/work"

但是,gdb 不喜欢它.

However, gdb does not like it.

问题来自这里.不幸的是,我不了解解决方案,并且不确定除了使用 -g 选项编译和运行命令 M-x gdb 之外还能做什么.

Question cribbed from here. Unfortunately I don't understand the solution and am not sure what to do beyond compiling with the -g option and running the command M-x gdb.

推荐答案

如果你是从 shell 做的,你会这样做:

If you were doing it from a shell you'd do it like this:

% gdb myprogram
gdb> run params ... < input.txt

这似乎也适用于 emacs.

This seems to work within emacs too.

这篇关于如何加载程序读取标准输入并在 gdb 中获取参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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