The Notebook Review forums were hosted by TechTarget, who shut down them down on January 31, 2022. This static read-only archive was pulled by NBR forum users between January 20 and January 31, 2022, in an effort to make sure that the valuable technical information that had been posted on the forums is preserved. For current discussions, many NBR forum users moved over to NotebookTalk.net after the shutdown.
Problems? See this thread at archive.org.

    Debugging in Linux

    Discussion in 'Linux Compatibility and Software' started by Peon, Feb 18, 2010.

  1. Peon

    Peon Notebook Virtuoso

    Reputations:
    406
    Messages:
    2,007
    Likes Received:
    128
    Trophy Points:
    81
    Is there any way to do IDE-style code trace C/C++ debugging in Linux?

    Or is printf/cout seriously the only way?
     
  2. jasperjones

    jasperjones Notebook Evangelist

    Reputations:
    293
    Messages:
    427
    Likes Received:
    4
    Trophy Points:
    31
    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
     
  3. Enunes

    Enunes Notebook Consultant

    Reputations:
    156
    Messages:
    204
    Likes Received:
    0
    Trophy Points:
    30
    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
    On gcc, don't forget to compile with the -g flag :)
     
  4. Lithus

    Lithus NBR Janitor

    Reputations:
    5,504
    Messages:
    9,788
    Likes Received:
    0
    Trophy Points:
    205
    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
     
  5. Peon

    Peon Notebook Virtuoso

    Reputations:
    406
    Messages:
    2,007
    Likes Received:
    128
    Trophy Points:
    81
    gcc/g++, but I could never get used to Eclipse for anything other than Java.

    I don't mind learning something new as long as it works well. This is Linux, after all :)
     
  6. jasperjones

    jasperjones Notebook Evangelist

    Reputations:
    293
    Messages:
    427
    Likes Received:
    4
    Trophy Points:
    31
    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.
     
  7. Peon

    Peon Notebook Virtuoso

    Reputations:
    406
    Messages:
    2,007
    Likes Received:
    128
    Trophy Points:
    81
    I tried Eclipse for C/C++ back when it was just a plugin for the then-monolithic Eclipse IDE, and tried it again when they split Eclipse up into 10 different versions (one of which was the C/C++ version) sometime around 2007.

    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.
     
  8. jasperjones

    jasperjones Notebook Evangelist

    Reputations:
    293
    Messages:
    427
    Likes Received:
    4
    Trophy Points:
    31
    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).
     
  9. Peon

    Peon Notebook Virtuoso

    Reputations:
    406
    Messages:
    2,007
    Likes Received:
    128
    Trophy Points:
    81
    Oh, I love Eclipse - for Java. What I don't like as much was the second class citizen treatment that Eclipse gave C/C++, and even if that's changed since then, I'm so used to (and happy with) my assortment of alternative tools nowadays that it would take some hard to justify time and effort on my part to get used to Eclipse (again).

    Thanks for the DDD suggestion though, I'm Googling that up as I type this ;)