我怎么能把一个断点放在“打印到终端上的东西”在gdb中? [英] how can I put a breakpoint on "something is printed to the terminal" in gdb?

查看:149
本文介绍了我怎么能把一个断点放在“打印到终端上的东西”在gdb中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道从一个巨大的应用程序中的哪个位置打印某个消息。该应用程序如此之大,以至于它使用了所有可以想象的将文本输出到终端的方式;例如printf(),fprintf(stdout,...)等。

我写write()系统调用时放置断点,但后来我被淹没因为使用write()的各种文件I / O操作也有太多的断点停止。



因此,基本上我希望gdb在程序打印某些内容时停止终端,但同时我不希望gdb在程序写入文件时停止。

解决方案

使用检查第一个参数的条件断点。在64位的x86系统上,条件是:

(gdb)b如果写1 == $ rdi



在32位系统上,它更复杂,因为参数在堆栈上,这意味着您需要将$ esp转换为int *并为fd参数编制索引。在这一点上的堆栈有返回地址,长度,缓冲区,最后是fd。

硬件平台之间差别很大。


I would like to know from where inside a huge application a certain message is printed. The application is so big and old that it uses all conceivable ways of printing text to the terminal; for example printf(), fprintf(stdout, ...) etc.

I write to put a breakpoint on the write() system call but then I'm flooded with too many breakpoint stops because of various file I/O operations that use write() as well.

So basically I want gdb to stop whenever the program prints something to the terminal but at the same time I don't want gdb to stop when the program writes something to a file.

解决方案

Use a conditional breakpoint that checks the first parameter. On 64-bit x86 systems the condition would be:

(gdb) b write if 1==$rdi

On 32-bit systems, it is more complex because the parameter is on the stack, meaning that you need to cast $esp to an int * and index the fd parameter. The stack at that point has the return address, the length, buffer and finally fd.

This varies greatly between hardware platforms.

这篇关于我怎么能把一个断点放在“打印到终端上的东西”在gdb中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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