如何检查GDB中的std :: string没有源代码? [英] How to inspect std::string in GDB with no source code?

查看:458
本文介绍了如何检查GDB中的std :: string没有源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调试一个没有可用源代码的程序,我需要看看它存储在std :: string中的内容。我一直在谷歌搜索和看这里,我已经找到了一些关于输出STL容器的信息,但它都是指变量,没有源或调试信息,我拥有的是类数据的内存偏移量。有没有办法做到这一点?

I'm trying to debug a program that has no source code available, and I need to look at what it has stored in a std::string. I've been Googling and looking on here, and I've found some information about outputting STL containers, but all of it refers to variables, with no source or debug information all I have is a memory offset of the class data. Is there any way to do this?

推荐答案

每个 std :: string 实现有一个指向其中的原始字符的指针。对于 g ++ 4.x ,该指针位于偏移量 0 中。

Every std::string implementation has a pointer to the raw characters in it somewhere. For g++ 4.x, that pointer is at offset 0 into the string.

如果您知道该字符串驻留在例如 0x7fffffffda88 ,然后

If you know that the string resides at e.g. 0x7fffffffda88, then

print *(char**)0x7fffffffda88

就是您需要的。

这篇关于如何检查GDB中的std :: string没有源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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