GDB-如何打破“将某些内容写入提示"? [英] GDB - How to break on "something is written to cout"?

查看:97
本文介绍了GDB-如何打破“将某些内容写入提示"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置一个断点,该断点在每次通过cout流将内容写入stdout时触发,但是我很难找到该断点的可能位置.

I would like to set a breakpoint that triggers every time something is written to stdout via the cout stream, but I'm having trouble finding a possible position for this breakpoint.

如何在gdb中执行此操作?

How can I do this in gdb?

推荐答案

这是依赖于平台的方式.如果您使用的是x86_64,并且使用gcc进行构建,则写入std :: cout会导致调用fwrite.回溯看起来像这样:

This is a platform dependent way. If you are on x86_64 and building with gcc writing to std::cout results in calling fwrite. Backtrace looks like this:

#0  0x0000003c2fc622a0 in fwrite () from /lib64/libc.so.6
#1  0x0000003c43289655 in std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_int<long>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const () from /usr/lib64/libstdc++.so.6
#2  0x0000003c432898c7 in std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, long) const () from /usr/lib64/libstdc++.so.6
#3  0x0000003c43291e5c in std::basic_ostream<char, std::char_traits<char> >::operator<<(int) () from /usr/lib64/libstdc++.so.6

因此,这是一种中断写入std :: cout(std :: cout为

So this is a possible way to break on writing to std::cout (std::cout is http://refspecs.linuxfoundation.org/LSB_1.1.0/gLSB/baselib--io-2-1-stdout--.html):

b fwrite if $rcx==&_IO_2_1_stdout_

这是一种中断写入std :: cerr的方法(std :: cerr为

And this is a way to break on writing to std::cerr (std::cerr is http://refspecs.linuxfoundation.org/LSB_1.0.0/gLSB/baselib--io-2-1-stderr--.html):

b fwrite if $rcx==&_IO_2_1_stderr_

这篇关于GDB-如何打破“将某些内容写入提示"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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