调用MALLOC在GDB会话失败 [英] Call to malloc failing in gdb session

查看:251
本文介绍了调用MALLOC在GDB会话失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调试一个C程序和gdb告诉我有一个特定的功能的329线路段错误。所以我设置该功能的一个破发点,我想步吧。但是,每当我打68行我得到这样的投诉,GDB:

 (GDB)的步骤
68 next_bb =(basic_block *)malloc的(的sizeof(basic_block));
(GDB)的步骤
* __ GI___libc_malloc在malloc.c(字节= 40):3621
3621 malloc.c:没有这样的文件或目录。
在malloc.c

我不知道这意味着什么。该方案完美地运行在所有,但一组输入,所以这个电话清楚MALLOC在程序的其他执行成功。而且,当然,我有:

 的#include< stdlib.h中取代。

下面是源$ C ​​$ C:

  //座正在建造。
    basic_block * next_bb = NULL;
    //遍历在程序指令的列表。
    而(curr_instr!= NULL)
    {
        simple_op运code = curr_instr-> OP code;
        //如果我们目前没有建立一个basic_block那么我们就必须开始一个新的。
        //一个新块可以与任何类型的指令启动。
        如果(!in_block)
        {
            //创建一个新basic_block。
            next_bb =(basic_block *)malloc的(的sizeof(basic_block));


解决方案

您可以放心地忽略这一点。 GDB抱怨,它不具备的malloc源 - 它几乎可以肯定你不想步执行源

两个简单的解决方案:


  • 使用接下来,而不是一步 - 它不会陷入功能


  • 如果您不小心编入的函数已经使用完成运行到返回函数声明。


和另一种方法:


  • 您也可以在段错误之前打破了一下,而不是通过整个code步进。


      <:;行号> (例如源文件>
    • 您可以通过将一个断点在一个特定的符合破发&LT做到这一点打破foo.c的:320 来对文件foo.c的320线路断路)

    • 或者你可以打破与特定功能破<作用名称> (例如破富将在富()功能)的顶部突破。


I am trying to debug a C program and gdb is telling me there is a segfault on line 329 of a certain function. So I set a break point for that function and I am trying to step through it. However, whenever I hit line 68 I get this complaint from 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

I don't know what this means. The program runs perfectly on all but one set of inputs so this call to malloc clearly succeeds during other executions of the program. And, of course, I have:

#include <stdlib.h>.

Here is the source code:

    // 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));

解决方案

You can safely ignore this. gdb is complaining that it doesn't have the source for malloc - and it's almost certain you don't want to step through the source.

Two easy solutions:

  • Use next instead of step - it won't descend into functions

  • If you've accidentally steped into a function already, use finish to run to the return statement of the function.

And an alternative approach:

  • You could also break a bit before the segfault, rather than stepping through the whole code.

    • You can do this by putting a breakpoint on a particular line with break <source file>:<line num> (for example break foo.c:320 to break on line 320 of foo.c).
    • Or you can break on a particular function with break <function name> (for example break foo will break at the top of the foo() function).

这篇关于调用MALLOC在GDB会话失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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