主叫接线员<<在 gdb 中

calling operatorlt;lt; in gdb(主叫接线员在 gdb 中)
本文介绍了主叫接线员<<在 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 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)