GDB - 与管道调试 [英] gdb - debugging with pipe

查看:639
本文介绍了GDB - 与管道调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个名为等等 RET 两个程序。我想调试的等等程序,通过I / O重定向收到 RET 程序输入。我如何在以下情况下用gdb调试的等等程序?

 庆典>沤|胡说


解决方案

起初,你可能会遇到由pid程序和调试。该溶液,当然,并不包括所有的情况

另一种方法是用于进程间通信的Linux能力。总之,您重定向 RET 的输出到一个FIFO特殊文件(命名管道),然后经由调试器FIFO读。下面是它是如何做。从bash中,运行:

  mkfifo子富

这会在您的目录中一个特殊的文件,该文件将作为的命名管道的。当你写文本文件(使用相同的语法回声你好>富),写程序将阻塞,直到有人从文件中读取数据(猫<富,例如)。在我们的情况下,GDB控制的过程将从这个文件中读取。

在您创建了一个FIFO,从bash的运行:

  RET>富&安培; #符号作为,因为没有人会从foo读它可能会阻塞
GDB嗒嗒

然后,在gdb的提示符下,运行

 运行 -  LT;富

和获得所需的效果。需要注意的是,你不能从FIFO(以及从通常的管道)读取数据两次:当你读过的所有数据中,等等进程死亡和你应该重复该命令写为foo(你可以从其他shell窗口做到这一点)。

当您完成后,取出FIFO与 RM富(或将其放入它会自动在系统重新启动被删除,如<$目录c $ C> / tmp目录)。

Say I have a two programs named blah and ret. I want to debug blah program which receives input from ret program via I/O redirection. How do I debug the blah program in the following case using gdb?

bash> ret | blah 

解决方案

At first, you may run the program and debug it by pid. This solution, of course, doesn't cover all cases.

Another approach is to use Linux capabilities for inter-process communication. In short, you redirect the output of ret to a FIFO special file ("named pipe") and then read from that FIFO via debugger. Here's how it's done. From bash, run:

mkfifo foo

This creates a special file in your directory that will serve as a named pipe. When you write text to this file (using the same syntax echo "Hello" >foo), the writing program will block until someone reads the data from the file (cat <foo, for instance). In our case, a gdb-controlled process will read from this file.

After you created a fifo, run from bash:

ret > foo &   # ampersand because it may block as nobody is reading from foo
gdb blah

Then, in gdb prompt, run

run <foo

And get the desired effect. Note that you can't read the data from the fifo (as well as from a usual pipe) twice: when you've read all the data, the blah process dies and you should repeat the command writing to foo (you may do it from the other shell window).

When you're done, remove the fifo with rm foo (or place it into the directory where it will automatically be removed upon system restart, such as /tmp).

这篇关于GDB - 与管道调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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