Is there any way to do IDE-style code trace C/C++ debugging in Linux?
Or is printf/cout seriously the only way?
-
Any decent IDE should be able to do this.
What compiler are you using?
For example, you can use Eclipse with gcc/g++ and (Intel) icc/icpc -
Theres gdb.
It's a bit hard to get to use it, but after you get it it's awesome. And I'd say it is full featured.
I mainly use it to debug segfaults these days. On a 4 line tutorial it goes like this to see a function stack backtrace:
Code:gdb prog r bt q
-
GDB can do all of that, you just have to learn the commands.
Run - run program till end
Step - run one line
Break X - set breakpoint at line X
Backtrace - print out list of functions that lead to where you are
Display X - display variable X
Examine X - examine memory at location X -
-
getting back a bit late to your thread...
many linux distros only have the Eclipse IDE for Java developers in their repository. What you want to do instead is download the Eclipse IDE for C/C++ developers from the eclipse.org website. Make sure you grab the right version (32bit or 64bit).
Unpack the archive and copy it to wherever you like (I use /usr/share/eclipse). Note that there is no package or anything you need to install (and there's no source code you need to build).
Run Eclipse by executing the file "eclipse" within the main eclipse folder (or create a symlink in /usr/bin).
in the end, eclipse uses nothing but gdb for debugging. but it's completely under the hood. It's fantastic, you just use the GUI and you don't need to know *anything* about how gdb works. -
The first time was just an abysmal experience. The plugin did just about nothing to hide the Java-specific aspects of the IDE - for example, the autocompletion feature still offered Java keywords.
The second time I used it, it was much better in that at least on the surface, Eclipse was a C/C++ IDE, but even then there was still an obvious the-Java-way-of-doing-things mindset entrenched into the program. At any rate, it was a crappy experience compared to VS 2005.
Since that time I've pretty much sworn it off for good, especially since I've found replacements for everything that a C/C++ IDE can provide over the years except the debugger. Now that I know of a decent debugger, I don't see any reason to move (back) to Eclipse. -
ok, didn't realize you don't like eclipse. (personally, i think eclipse's c/c++ perspective is awesome; as is its handling of versioning systems.)
but even if eclipse is a no-no, there's no need for you to learn the full set of gdb commands. moreover, a gui is still preferable since it can visualize variables and arrays in a more appealing way. a simple alternative graphical debugger I suggest looking into is DDD (data display debugger). -
Thanks for the DDD suggestion though, I'm Googling that up as I type this
Debugging in Linux
Discussion in 'Linux Compatibility and Software' started by Peon, Feb 18, 2010.