简体   繁体   中英

Eclipse Debugging C

Environment:

  • Eclipse IDE for C/C++ Developers Version: Mars Release (4.5.0)
  • Ubuntu 14.04

I have a problem with 'Debug mode' under Eclipse. I tried to debug a simple program as an experiment:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
    char *s = malloc(1);
    free(s);
    s = NULL;
    return 0;
}

The program is building correctly and is working without any Errors/Warnings but during debugging I am receiving following error: 在此处输入图片说明

I have searched my entire hard drive and file malloc.c is not present.

The questions:

  1. If the file malloc.c can not be found, why the program can be build and is running correctly?

  2. Why the debugger has a problems with functions visible to the compiler?

  3. Has anyone saw this issue in the past and knows the solution?

  4. What kind of programming environment with debug mode are you using other than Eclipse?

I have found a couple similar topics, but without the general issue solution:

  1. How can i Escape from "no source available" errors when stepping OVER a stdio function in eclipse (C language, using CDT)
  2. GDB on eclipse debug mode can't find stdlib/rand.c

Running commands:

# apt-get install libc6-dbg
# apt-get source libc6

Does not solve the problem.

To get the source file malloc.c you need the source code for glibc.

If you have to debug into glibc, odds are you do are a glibc developer. In nearly every other case, you are better served by stepping over glibc. When you set your breakpoint, I highly suggest that you step over the glibc calls.

Glibc is generally implemented not by a lot of C code, but by a lot of machine specific code lightly wrapped in C APIs, and the machine specific code is different for every machine.

Also, the debugger isn't having a problem, it is reporting that it doesn't have the source code for a library (glibc in this case) and is happy to keep debugging (but it can't show you a line number until it steps out of the glibc malloc call).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM