简体   繁体   中英

Netbeans C/C++ on Linux “step in to” Linux C runtime code?

When debugging C/C++ code with netbeans on Linux, is it possible to "step in to" the native C runtime library (to see source code for malloc() etc), just like Visual Studio can on Windows?

If not, can any Linux IDEs?

malloc and many functions have compiler's specific implementation. Usually you can 't access to the source code of them in this way. For example in gcc/g++, malloc is declared in <cstdlib> and implemented as a external function in .dll file.

In Visual Studio, you can go through some declarations and see some weird codes, but they are just some high-level codes to invoke the real malloc . You can not see the real implementation of malloc .

For example, in my test after step into malloc , I saw below code which is just an call to an internal function, and so on... finally you will see nothing:

extern "C" _CRTIMP void * __cdecl malloc (
        size_t nSize
        )
{
        void *res = _nh_malloc_dbg(nSize, _newmode, _NORMAL_BLOCK, NULL, 0);

        RTCCALLBACK(_RTC_Allocate_hook, (res, nSize, 0));

        return res;
}

You could install the libc6-dbg (or libc-dbg ) package, if on Debian or Ubuntu (or derived) distribution.

Then use the set debug-file-directory command of gdb

And since Linux is free software, you can study the source code of malloc ; your distribution is probably used some patched variant of GNU libc ; you might also look into MUSL libc , whose source code seems more readable to me.

FWIW, malloc(3) is certainly using syscalls like mmap(2) , etc...

And on many distributions you can rebuild packaged software from source code (eg with apt-build ...)

But if you are a newbie, I don't recommend rebuilding libc because it is the central piece of almost all applications!

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