step into system, CRTL functions with Eclipse in Linux

后端 未结 2 1950
抹茶落季
抹茶落季 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: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...

提交回复
热议问题