在gdb中输入重定向(MinGW) [英] Input redirection in gdb (MinGW)

查看:96
本文介绍了在gdb中输入重定向(MinGW)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让gdb运行带有输入重定向到stdin的程序。例如,如果没有gdb,我会运行一个这样的程序:

  prog< input.txt 

现在在gdb中,通常的做法是运行 run < input.txt中。然而,它不适用于我,当这样做时,没有任何东西被重定向到标准输入。



我在MinGW中使用Windows。可能是这样的问题?

解决方案

早在90年代末,破碎的命令行重定向就成了已知和假定的限制。我怀疑它仍然是这样,因为 mingw32 端口的 gdb 仍然愉快地逐字传递所有<$ c

运行参数(包括重定向)。


$ b $如果您可以选择更改命令行界面,则执行 bbadour 的建议
  • 否则,如果您可以在要调试的位置之前轻松挂起进程,请从shell中调用debian(使用重定向),并在其已经运行时附加到它上面。

  • 否则,如果您有符号( gcc -g ),或者您知道 main() gcc -Wl,-Map,mapfile )并且可以在那里设置一个断点,按照下面的方式进行(用 mingw gdb 6.8 。$ <$

     #gdb debugee.exe 
    (gdb)b main
    (gdb)运行非重定向参数 - 如果任何
    (gdb)p dup2(open(/ tm
    (gdb)c



  • I'm trying to get gdb to run programs with input redirection to stdin. For example, without gdb I would run a program like this:

    prog < input.txt
    

    Now in gdb, the usual way to do this is run < input.txt. However, it doesn't work for me and when doing this nothing gets redirected into stdin.

    I'm using Windows with MinGW. What could be the problem?

    解决方案

    As far back as the late '90s, broken command line redirection was a known and assumed limitation. My suspicion is that it remains that way, since the mingw32 port of gdb still gleefully passes on verbatim all run arguments (including redirects) to the debugee.

    Several possible workarounds:

    1. if you have the option to alter the command line interface, then implement bbadour's suggestion
    2. otherwise, if you can easily suspend the process before the point you want to debug at, invoke the debugee (with redirection) from a shell and attach to it while it is already running
    3. otherwise, if you have symbols for the debugee (gcc -g) or you know the address of main() (gcc -Wl,-Map,mapfile) and can set a breakpoint there, proceed in the following manner (tested with mingw gdb 6.8.0):

      # gdb debugee.exe
      (gdb) b main
      (gdb) run non-redirect-arguments-if-any
      (gdb) p dup2(open("/tmp/input.txt", 0), 0) 
      (gdb) c
      

    这篇关于在gdb中输入重定向(MinGW)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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