3

我在 gdb 中执行了以下命令,控制台输出如下:

Rohan_gdb$ set $var = 15
Rohan_gdb$ p $var
$5 = 0xf
Rohan_gdb$ set $var = (int *)10
Rohan_gdb$ p $var
$6 = (int *) 0xa
Rohan_gdb$ set $char = "abc"
Rohan_gdb$ p $char
$7 = "abc"
Rohan_gdb$ set $char = (char *)"xyz"
evaluation of this expression requires the program to have a function "malloc".

(这里我有错误)

Rohan_gdb$ p $char
$8 = "abc"
Rohan_gdb$

在这里,我正在调试目标而不是本机调试。我正在使用 GNU gdb (GDB) 7.2 版本。是否可以使用脚本解决。

4

2 回答 2

3

I don't know how to solve your specific problem, but I ran across something similar. Given the age of the question, maybe this'll provide a clue.

The problem is that your script is trying to store away a value in a buffer and it must allocated a new buffer for that storage. The storage requirement is likely the result of the cast or because that second string is not in the constant strings within your binary.

To fix, either change your code to not require a malloc (which is a bit of hit or miss, as far as I can tell). Or make the malloc symbol available; load a symbol table that allows gdb to resolve the "_malloc" symbol.

于 2012-04-27T05:41:17.887 回答
0

所有值都以当前语言解释。这意味着,例如,如果当前源语言是 C/C++,那么搜索字符串“hello”包括结尾的\0. 可以使用强制转换从搜索中删除空终止符,例如:{char[5]}"hello".

https://sourceware.org/gdb/onlinedocs/gdb/Searching-Memory.html

示例: https ://github.com/PhoenixInteractiveNL/emuDownloadCenter/wiki/Emulator-wincpc <-> WinCPC 是名为 vbCPC 的 Amstrad CPC 仿真器的 Borland Delphi 端口

F:\flynns_WinCPC>gdb wincpc.exe<br>
GNU gdb (GDB) 7.6<br>
...<br>
This GDB was configured as "i686-pc-mingw32".<br>
...<br>
Reading symbols from F:\flynns_WinCPC\wincpc.exe...(no debugging symbols found)...done.<br>
(gdb) info files<br>
Symbols from "F:\flynns_WinCPC\wincpc.exe".<br>
Local exec file:<br>
&nbsp;&nbsp;  `F:\flynns_WinCPC\wincpc.exe', file type pei-i386.<br>
&nbsp;&nbsp;        Entry point: 0x558448<br>
&nbsp;&nbsp;        0x00401000 - 0x005587ec is CODE<br>
&nbsp;&nbsp;        0x00559000 - 0x0055f7f8 is DATA<br>
&nbsp;&nbsp;        0x007bf000 - 0x007c1b88 is .idata<br>
&nbsp;&nbsp;        0x007c3000 - 0x007c301f is .rdata<br>
&nbsp;&nbsp;        0x007c4000 - 0x007db530 is .reloc<br>
&nbsp;&nbsp;        0x007dc000 - 0x00861c00 is .rsrc<br>
(gdb) find 0x00401000,0x00861c00,'m','e','m','o','r','y'<br>
0x48b224<br>
0x48b2e8<br>
0x48b312<br>
0x48b33a<br>
0x48b354<br>
0x48c2cc<br>
0x48cfcb<br>
0x82d910<br>
0x841484<br>
0x8456f9<br>
10 patterns found.<br>
(gdb) find 0x00401000,0x00861c00, <strong>{char[6]}</strong> "memory"<br>
evaluation of this expression requires the program to have a function "malloc".<br>
于 2019-10-05T02:40:36.690 回答