如何使用 Gdb 调试器从数论库中查找 ZZ 对象的值?

How to use Gdb debugger to find value of ZZ object from Number Theory Library?

我使用 gdb 调试器打印 ZZ 类型变量的值。此数据类型在 Number Theory Library or NTL 中定义。当我使用 "print x" 找出我的变量的值时,我得到这样的东西:

print x 
 = {rep=0xab2cc54}. 

我猜这是我的 ZZ 对象的地址。我怎样才能打印它的价值?我应该提一下,我不知道这个 class.

的内部表示

我可以使用 NTL 和像 Eclipse 这样的编译器来更轻松地调试我的应用程序吗?

Can I use NTL with a compiler like Eclipse ...

首先:Eclipse 不是编译器,而是一个IDE,它为您封装了编译器和调试工具。

在调试模式下,IDE 能够解析您的源代码中使用的实际类型和内部表示,并让您遍历。

也就是说我很确定您可以使用 Eclipse CDT 来检查您的特定类型值。

… my ZZ object. How can I print its value ?

这有点难看,但有效:

(gdb) call NTL::operator<<(std::ostream&, NTL::ZZ const&)(cerr, x)
42 = (std::ostream &) @0x620020: <incomplete type>

(在本例中,变量 x 的值为 42)。
如果你不想要值后面的垃圾,你可以转换为 void:

(gdb) call (void)NTL::operator<<(std::ostream&, NTL::ZZ const&)(cerr, x)
42(gdb) 

(但请注意,值后没有换行符)。

如果你不是using namespace std,你可能需要写

(gdb) call NTL::operator<<(std::ostream&, NTL::ZZ const&)('std::cerr', x)

有时 cerr 可能不在范围内:

(gdb) call NTL::operator<<(std::ostream&, NTL::ZZ const&)(cerr, x)        
No symbol "cerr" in current context.

- 然后你可以尝试使用 cout,但它变得更丑陋,因为必须刷新缓冲输出:

(gdb) call NTL::operator<<(std::ostream&, NTL::ZZ const&)(cout, x)
(gdb) call 'std::basic_ostream<char, std::char_traits<char>>& std::operator<< <std::char_traits<char>>(std::basic_ostream<char, std::char_traits<char>>&, char const*)'(&cout, "\n")
42