Debugging Nemiver-无法引导标准输入

Debugging Nemiver-无法引导标准输入,debugging,redirect,input,Debugging,Redirect,Input,我喜欢nemiver的想法,但我不能让nemiver的这个基本功能发挥作用:将标准输入重定向到程序。因此,由于我的程序需要文件输入而不是手动输入,它通常采用以下形式: ./program < list.txt /program

我喜欢nemiver的想法,但我不能让nemiver的这个基本功能发挥作用:将标准输入重定向到程序。因此,由于我的程序需要文件输入而不是手动输入,它通常采用以下形式:

./program < list.txt
/program

但是很明显,nemiver不承认这种简单的重定向。并认为“作为一个快速而肮脏的解决方案,您可以在
main()
的开头添加如下内容

    {
 // programmatically redirect stdio
    const char * stdin_filename="input.txt", * stdout_filename="output.txt";
    assert( dup2(open(stdin_filename ,O_RDONLY),0) != -1 );
    assert( dup2(open(stdout_filename,O_WRONLY),1) != -1 );
    asm(" int3"); // optional breakpoint -- kills program when not debugging
    }
只需确保在不调试时禁用此功能(因为在这种情况下,您可能希望使用常规的重定向方法)

您还需要以下内容

#include <unistd.h>
#include <fcntl.h>
#包括
#包括

如果您只想进行事后分析(不需要单步),可以加载崩溃转储(core)文件,该文件可以在任何类型的管道/重定向场景下生成

( ulimit -c unlimited && ./yourapp <in.txt >out.txt ) || nemiver --load-core=core ./yourapp
(ulimit-c unlimited&./yourapp out.txt)| | nemiver--load core=core./yourapp

这仅在发生崩溃或断言时启动调试器。

相关:kdbg支持重定向。不幸的是,在最近的Ubuntu版本中。kdbg在Ubuntu 13.10中已修复!