gdb抛出错误说程序有一个函数“malloc”

时间:2012-02-27 14:44:46

标签: gdb gdbserver

我在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版本。是否可以使用脚本解决。

2 个答案:

答案 0 :(得分:3)

我不知道如何解决您的具体问题,但我碰到了类似的问题。鉴于问题的年龄,也许这会提供一个线索。

问题是您的脚本试图将值存储在缓冲区中,并且必须为该存储分配新的缓冲区。存储要求可能是转换的结果,或者因为第二个字符串不在二进制文件中的常量字符串中。

要修复,要么将代码更改为不需要malloc(据我所知,这有点受欢迎)。或者使malloc符号可用;加载一个允许gdb解析“_malloc”符号的符号表。

答案 1 :(得分: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>