简体   繁体   English

Linux上的Netbeans C / C ++是否可以“进入” Linux C运行时代码?

[英]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? 在Linux上使用netbeans调试C / C ++代码时,是否可以像Windows上的Visual Studio一样“进入”本机C运行时库(以查看malloc()等的源代码)?

If not, can any Linux IDEs? 如果没有,可以使用任何Linux IDE吗?

malloc and many functions have compiler's specific implementation. malloc和许多函数具有编译器的特定实现。 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. 例如,在gcc / g ++中, malloc<cstdlib>声明,并作为.dll文件中的外部函数实现。

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 . 在Visual Studio中,您可以查看一些声明并查看一些奇怪的代码,但是它们只是一些用于调用实际 malloc的高级代码。 You can not see the real implementation of malloc . 您看不到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: 例如,在进入malloc之后的测试中,我看到下面的代码只是对内部函数的调用,依此类推……最终,您将看不到任何东西:

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. 如果在Debian或Ubuntu(或派生)发行版上,则可以安装libc6-dbg (或libc-dbg )软件包。

Then use the set debug-file-directory command of gdb 然后使用gdbset debug-file-directory命令

And since Linux is free software, you can study the source code of malloc ; 并且由于Linux是免费软件,因此您可以研究malloc的源代码。 your distribution is probably used some patched variant of GNU libc ; 您的发行版可能使用了一些GNU libc的补丁版本; you might also look into MUSL libc , whose source code seems more readable to me. 您还可以研究MUSL libc ,它的源代码对我而言似乎更易读。

FWIW, malloc(3) is certainly using syscalls like mmap(2) , etc... FWIW, malloc(3)当然正在使用mmap(2)等系统调用。

And on many distributions you can rebuild packaged software from source code (eg with apt-build ...) 在许多发行版中,您可以从源代码重建打包的软件(例如,使用apt-build ...)

But if you are a newbie, I don't recommend rebuilding libc because it is the central piece of almost all applications! 但是,如果您是新手,我不建议您重建libc因为它是几乎所有应用程序的核心部分!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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