[英]How do I find where a string in is saved in my virtual memory? Using gdb to Debug .cc file
I have an executable file that was compiled from a.cc file.我有一个从 a.cc 文件编译的可执行文件。 I'm now debugging with the gdb.我现在正在使用 gdb 进行调试。 In line 66 of my code I have:在我的代码的第 66 行中,我有:
cout << "Mean: " << mean << endl;
I'm now trying to find where "Mean: " is saved in my virtual memory.我现在正试图找到“平均值:”保存在我的虚拟 memory 中的位置。 Any tips?有小费吗? I've tried different commands like find and print but have had no breakthroughs.我尝试了不同的命令,例如查找和打印,但没有任何突破。
Does anybody have any tips?有人有任何提示吗?
Here are a few ways you could find the string.以下是您可以找到字符串的几种方法。
Let's compile this test:让我们编译这个测试:
#include <iostream>
int main(int arch, char *argv[])
{
double mean = 0.5;
std::cout << "Mean: " << mean << std::endl;
}
std::cout
line:在std::cout
行设置断点:(gdb) run
Starting program: /tmp/a.out
Breakpoint 1, main (arch=1, argv=0x7fffffffe328) at t.cc:5
5 std::cout << "Mean: " << mean << std::endl;
(gdb) info line 5
Line 5 of "t.cc" starts at address 0x555555555191 <main(int, char**)+28> and ends at 0x5555555551a4 <main(int, char**)+47>.
(gdb) disas 0x555555555191,0x5555555551a4+1
Dump of assembler code from 0x555555555191 to 0x5555555551a5:
=> 0x0000555555555191 <main(int, char**)+28>: lea 0xe71(%rip),%rsi # 0x555555556009
0x0000555555555198 <main(int, char**)+35>: lea 0x2ec1(%rip),%rdi # 0x555555558060 <_ZSt4cout@@GLIBCXX_3.4>
0x000055555555519f <main(int, char**)+42>: callq 0x555555555040 <_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc@plt>
0x00005555555551a4 <main(int, char**)+47>: movsd -0x8(%rbp),%xmm0
End of assembler dump.
Above you can see register rsi
being loaded with value 0x555555556009
, which is passed as second argument to the std::operator<< ()
.上面你可以看到寄存器rsi
被加载了值0x555555556009
,它作为第二个参数传递给std::operator<< ()
。 It must contain the string.它必须包含字符串。 Indeed:的确:
(gdb) x/s 0x555555556009
0x555555556009: "Mean: "
info file
to find .rodata
section (in which this string resides) and find
commands:使用info file
查找.rodata
部分(此字符串所在的部分)并find
命令:(gdb) info file
Symbols from "/tmp/a.out".
Native process:
Using the running image of child process 905.
While running this, GDB does not access memory from...
Local exec file:
`/tmp/a.out', file type elf64-x86-64.
Entry point: 0x555555555090
0x00005555555542a8 - 0x00005555555542c4 is .interp
...
0x0000555555556000 - 0x0000555555556018 is .rodata
...
(gdb) find 0x0000555555556000, 0x0000555555556018, {char[6]}"Mean: "
0x555555556009
1 pattern found.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.