当前位置:  开发笔记 > 编程语言 > 正文

如何使用gdb与输入重定向?

如何解决《如何使用gdb与输入重定向?》经验,为你挑选了2个好方法。

在终端,我有

    myapp < myfileinput

但如果我想使用gdb,

    gdb myapp < myfileinput

它运行不正常.

如何在这里使用gdb?



1> Abhishek..:
~$ gdb 

GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
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 "i686-linux-gnu".
For bug reporting instructions, please see:
...
Reading symbols from /home/abhishek/maxtest...done.

(gdb) run < input.txt

这对我来说很有用.想知道这是不是你想要的.



2> sarnold..:

尝试从gdb中运行您的应用程序?

(gdb) file /usr/bin/head
Reading symbols from /usr/bin/head...(no debugging symbols found)...done.
(gdb) run -2 < /etc/passwd
Starting program: /usr/bin/head -2 < /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh

Program exited normally.
(gdb)

编辑:或者:

gdb -q -ex 'set args -2 < /etc/passwd' /usr/bin/head
Reading symbols from /usr/bin/head...done.

(gdb) run
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh

Program exited normally.
(gdb) quit

推荐阅读
家具销售_903
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有