主叫接线员<<在 gdb 中 [英] calling operator&lt;&lt; in gdb

查看:14
本文介绍了主叫接线员<<在 gdb 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 gdb 内部调用 operator<<(std::ostream &os, const ClassX &x) ?

How do you call operator<<(std::ostream &os, const ClassX &x) from inside gdb ?

换句话说,如何在 gdb 中打印一个对象?

In other words, how do you print an object in gdb ?

call std::cout<<xcall operator<<(std::cout, x) 似乎对我不起作用!

call std::cout<<x or call operator<<(std::cout, x) don't seems to work for me!

有什么想法吗?

推荐答案

我找到的唯一方法是:

call 'operator<<(std::ostream&, myclass&)'(mycout, c)

由于某种原因 std::cout 对 gdb 不可见,我不得不像这样创建自己的:

Since std::cout wasn't visible to gdb for some reason, I had to resort to creating my own like this:

std::ostream mycout(std::cout.rdbuf());

您没有说明想要这样做的任何理由,但 print yourvariable 会不会更容易?

You haven't stated any reasons for wanting to do this but won't print yourvariable be easier?

如果这是绝对必须的,你可以在你的类中有一个 Print 方法并从 operator<< 调用它,然后调用 Print 来自 gdb 的对象上的方法.

If this is an absolute must you could have a Print method in your class and call that from operator<< and then call the Print method on your object from gdb.

请注意,stdout 可能在 gdb 中缓冲,因此除非您以某种方式重定向它,否则您将看不到任何输出.

Do take note that stdout is probably buffered in gdb so you won't be seeing any output unless you redirect it somehow.

请参阅 gdb 邮件存档中有关此问题的 this 讨论.

See this discussion from gdb's mailing archive regarding this issue.

这篇关于主叫接线员<<在 gdb 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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