Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging on Linux for Windows Developer

Primarily I've done basic (novice level) software development on a Windows machine, but I've always had MS Visual Studio to help me step through the process of debugging.

Now, however, it looks like I will be on Linux, so in order to get ready for the jump I want to make sure I have a tool/tools lined up to help me step through the code and debug.

Unfortunately when I've verbally asked folks how they go about debugging on Linux, I typically get the following answer, "Oh, I just put a bunch of print statements." OMG! No way you say, but yes that is their answer.

Since it is on Linux, and will be working with C++ code on the CentOS 32-bit OS, I am hoping here is a preferred OpenSource solution. So, I guess I asking for the preferred OpenSource IDE for C++ code on CentOS Linux.

Thanks for any insight and suggestions.

like image 898
JustADude Avatar asked Apr 14 '09 12:04

JustADude


3 Answers

Good question, of course, but its been done before:

  • https://stackoverflow.com/questions/408418/what-editor-ide-do-you-use-for-c-programming-on-linux-and-why-closed
  • https://stackoverflow.com/questions/86676/is-there-a-good-and-free-ide-for-c-c-in-linux
  • https://stackoverflow.com/questions/149321/what-ide-would-be-good-for-linux-kernel-driver-development
  • Lightweight IDE for Linux
  • Simple GUI IDE?

(from: https://stackoverflow.com/questions/579219/best-unix-linux-c-debuger-ide-closed)

like image 133
Reunanen Avatar answered Oct 06 '22 02:10

Reunanen


A few years ago I made the move from VS to an emacs/make type environment and I have never looked back.

The idea is to use a makefile to handle the project management side of an IDE and I use emacs+gdb for editing and debugging. It will take you a while to get used to emacs but if you stick at it it's well worth the effort. Once you've started emacs, press "Ctrl+H" followed by "t" and this will bring you to the tutorial page.

After you've mastered the basics, you can debug a program in a similar way to any IDE/debugger interface. I must admit that even after all this time, I still use a set of VS key mappings that I setup when I first moved to emacs!

(global-set-key [f7] 'compile)          ;; Run the compile command
(global-set-key [f4] 'next-error)       ;; The next compile error
(global-set-key [S-f4] 'previous-error) ;; The previous compile error
(global-set-key [f5] 'gdb)              ;; Start the debugger

The following sets the "VS" key mappings to the different GDB commands which you might use:

(add-hook 'gud-mode-hook
  '(lambda ()
     (define-key (current-local-map)
       [f10]
       'gud-next)
     (define-key (current-local-map)
       [f11]
       'gud-step)
     (define-key (current-local-map)
       [\S-f11]
       'gud-finish)
     (define-key (current-local-map)
       [f5]
       'gud-cont)
))

With the above keymappings, I press 'f5' which prompts me to run gdb (and to this command I add the binary I wish to debug). Once gdb is loaded, you press 'f5' to continue, 'f10' to step-over, 'f11' to step-into and 'shirt+f11' to step-out.

Finally, every time you start 'gdb', it will read a file called '.gdbinit' in your home directory. A different StackOverflow question had this answer which brought stl-views to my attention. stl-views is a set of helper functions for gdb that show you the contents of the different types of STL containers. The instructions for how to use it can be found at the top of the link.

like image 27
Richard Corden Avatar answered Oct 06 '22 04:10

Richard Corden


I would suggest using Eclipse

Eclipse is a mature IDE with plenty of support available.

There is also Code::Blocks if you want to try something different

like image 20
Shane O'Grady Avatar answered Oct 06 '22 04:10

Shane O'Grady