18
我想調試一個C程序,gdb告訴我在某個函數的第329行有段錯誤。所以我爲這個功能設定了一箇中斷點,並且我試圖通過它。然而,無論何時我擊中第68行,我都會收到gdb的投訴:調用malloc在gdb會話中失敗
(gdb) step
68 next_bb = (basic_block *)malloc(sizeof(basic_block));
(gdb) step
*__GI___libc_malloc (bytes=40) at malloc.c:3621
3621 malloc.c: No such file or directory.
in malloc.c
我不知道這是什麼意思。程序在除了一組輸入以外的所有組件上運行都很完美,所以這個對malloc的調用在程序的其他執行過程中明顯成功。而且,當然,我有:
#include <stdlib.h>.
這裏是源代碼:
// Block currently being built.
basic_block *next_bb = NULL;
// Traverse the list of instructions in the procedure.
while (curr_instr != NULL)
{
simple_op opcode = curr_instr->opcode;
// If we are not currently building a basic_block then we must start a new one.
// A new block can be started with any kind of instruction.
if (!in_block)
{
// Create a new basic_block.
next_bb = (basic_block *)malloc(sizeof(basic_block));
如果malloc失敗,最可能的原因是堆損壞。你有沒有嘗試在valgrind下運行你的程序? – JaredPar 2012-02-10 00:03:45
使用'下一步'而不是'步驟'。你正在嘗試進入malloc,並且gdb抱怨說它無法訪問malloc的源代碼。你真的不想步入malloc。 – 2012-02-10 00:12:42
啊,謝謝,'接下來'修好了。 – Schemer 2012-02-10 00:23:10