step into system, CRTL functions with Eclipse in Linux

后端 未结 2 1899
抹茶落季
抹茶落季 2021-01-29 07:49

I\'m a whiz with Visual C++, but Linux development is new to me. In Visual Studio, it\'s easy to trace into any code implemented by the C run time libraries. I just need to mak

相关标签:
2条回答
  • 2021-01-29 08:14

    Whilst, as a Kernel developer on Linux, I do agree that using the individual tools separately will be a good thing to learn, and as such Basile's answer is usefuel.

    However, the stepping into C runtime libraries should be equally possible with Eclipse. But just because the OS is open source doesn't mean that it supports you clambering around inside it willy nilly - in fact, you CAN NOT step into the OS itself from user-mode code. You nee KGDB (google it), and you definitely need a second computer to attach to the one being debugged, because when you step into the kernel, you will essentially lock up the machine, at the very least in the context you are stepping, but most likely also prevent other work from being done until you get back out from the kernel, so for example, if you step into open(), at some point the entire filesystem may well stop working altogether until you are back out of whatever lock you are holding. This wll certainly upset some software. Note that this is just an example of how things may work unexpectedly when debugging the kernel, not strictly "I've done this and it happened" - I have debugged kernels with debuggers several times, and you do have to be careful with what you do, and you certainly can not run the debugger on the same machine, as the machine STOPS when you are debugging.

    Going back to the usermode, which you CAN debug via Eclipse, essentially all you need to do is install the source code for the runtime library you are interested in, and go... Same principle as on Windows with visual studio - except that nearly all software you ever run on a Linux system is available as source code. You may need to recompile some libraries with debugging symbols, and just like in Windows, you need to make sure the debugger knows how to find the source code. Everything else should be handled by the debugger in Eclipse. I spent about three years using Eclipse for both local and remote debugging, and in general, it works. There are quirks in places, but that's the case with almost any debugger.

    Good luck.

    0 讨论(0)
  • 2021-01-29 08:17

    First, you don't need Eclipse to develop software on Linux. You should better learn to do that with independent tools (command line) like emacs or gedit (as editor), git (version control), make (builder) which runs the gcc or g++ compiler (both gcc & g++ are part of GCC, the Gnu Compiler Collection).

    really, you'll learn a lot more by not depending upon Eclipse; it may just hide you the real commands which are doing the job, and you should understand what they really are.

    You want to pass the -g -Wall options to GCC. The -g option asks for debug information, and the -Wall options asks for almost all warnings. Improve your code till no warnings are given.

    And the operating system is providing syscalls (which are operations provided by the kernel to applications; from the application's point of view, a syscall is atomic so you cannot step into it; however strace may show you all the syscalls done by some execution). If you wanted to step by step inside system libraries like libc you need the debugging variant of it (e.g. some libc6-dbg package). But there is usually no need to dive inside system libraries.

    See http://advancedlinuxprogramming.com/

    Then, you will use gdb to debug the binary program.

    So, step by step instructions inside a terminal:

    • edit your source files with emacs or gedit

    • learn how to use GCC: for a single source C++ program compile it with g++ -Wall -g source.cc -o progbin and type ./progbin in your terminal to run it. Only when the program is debugged and satisfactory would you compile it with optimizations (by giving the -O or -O2 flag to gcc or g++)

    • Use gdb to debug a program (compiled with -g).

    • for a multi-file C++ program, consider learning how to use make

    • use a version control system like git

    For beginners, I suggest to avoid Eclipse, because it just hides to you what is really happening underneath (Eclipse is simply running other tools like the above commands)

    Software development under Linux requires a different mindset than under Windows: you really are using your own loose combination of independent tools, so better to learn a bit each of them.

    NB. to step inside "system" functions like malloc (which is above syscalls like mmap) you need the debug variant of the libc package with aptitude install libc6-dbg, and you need to set LD_LIBRARY_PATH to /usr/lib/debug etc...

    0 讨论(0)
提交回复
热议问题