【问题标题】:How to use gdb with pipes and stdin如何将 gdb 与管道和标准输入一起使用
【发布时间】:2017-12-10 16:43:41
【问题描述】:

您好,我正在尝试调试使用命令运行的程序

cat 1.txt - | ./game

我不确定如何使用该命令启动gdb。我已经看到了有关如何通过管道传输到gdb 的答案,但是当我首先想通过管道传输文件内容然后使用标准输入(这就是破折号所代表的)时,它似乎不起作用。有人可以帮忙吗?

【问题讨论】:

    标签: bash debugging gdb pipe stdin


    【解决方案1】:

    cat 1.txt - | ./game

    这个cat 毫无意义,你可以很容易地做到这一点:./game < 1.txt

    这也可以用来在GDB下运行game

    gdb ./game
    (gdb) run < 1.txt
    

    另见this answer

    【讨论】:

    • cat 并非毫无意义。如果没有破折号,程序会循环打印消息并等待输入,因为代码看起来像这样:while (1) { printf("message"); if (scanf("%d", &amp;var) &gt; 0 &amp;&amp; var &gt;= 0 ) { break; } getchar();}
    猜你喜欢
    • 2011-11-05
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 1970-01-01
    • 2014-05-13
    • 1970-01-01
    • 2013-11-04
    • 2012-02-23
    相关资源
    最近更新 更多