在不创建文件的情况下通过管道输入使用gdb [英] using gdb with piped input without creating file

查看:56
本文介绍了在不创建文件的情况下通过管道输入使用gdb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过管道输入的程序:

I have a program that takes in piped input:

bash> echo "something" | ./program 'seomthingelse'

如何在不创建新文件的情况下将此输入重定向到gdb?

How can I redirect this input into gdb, WITHOUT creating a new file?

推荐答案

如何在不创建新文件的情况下将此输入重定向到gdb?

How can I redirect this input into gdb, WITHOUT creating a new file?

  • 您可以创建一个命名管道(不确定是否将其视为新文件"-为什么要避免使用新文件?)
  • 您可以在程序中添加延迟,以 echo"something" |开始../program'seomthingelse',并在仍然处于延迟状态时从另一个窗口将其附加.
    • You can create a named pipe (not sure whether this counts as a "new file" or not -- why are you trying to avoid a new file?)
    • You can put a delay into the program, start it with echo "something" | ./program 'seomthingelse', and attach to it from another window while it is still being in the delay.
    • 第二种解决方案通常对于非常调用它们的程序非常有用,我发现以下实现可以很好地工作:

      The second solution is often quite useful for programs that are very particular about how they are invoked, and I find the following implementation to work well:

      int main(int argc, char *argv[])
      {
        if (getenv("WAIT_FOR_GDB") != NULL) {
          int done = 0;
          while (!done) sleep(1);
        }
        /* rest of main */
      }
      

      然后,您在环境中设置 WAIT_FOR_GDB ,并且可能花费任意时间来附加该过程.连接后,从 sleep 向上 up set var done = 1 ,设置所需的其他任何断点,然后 continue .

      Then you set WAIT_FOR_GDB in the environment, and can take arbitrary time to attach the process. Once attached, step up from sleep, set var done = 1, set any other breakpoints you need, and continue.

      这篇关于在不创建文件的情况下通过管道输入使用gdb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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