Debugging with Nemiver

You're writing some C code that you just managed to compile. You are able to get it to build without errors, and you're ready to run. But then, something disastrous happens:

$ gcc main.c -o out
$ ./out
Segmentation fault

Great. Your application dies without so much as an explanation as to why. Nobody likes to debug code, but it has to be done at some point. If you compiled with the -g flag to gcc or g++, your program will have some debugging information included that special programs, like gdb, can use to assist you in solving the problem.

Nemiver is a graphical tool that can be used to take advantage of debugging information that uses gdb as a backend. It provides all of the features that the terminal-based gdb provides, but in a more sophisticated GUI interface that follows the code as it is executed. This means you can run code line-by-line, add breakpoints, view pointers, variables, memory registers, and see the call stack. In addition, you are also able to attach to a program over a network; so if your web server application goes down, you can run it over-the-wire with Nemiver to try to solve the problem.

Nemiver

To give it a test run, let's try it out with some code that segfaults in a normal run. First, after loading up the file, we'll run it line-by-line to find the problem.

Nemiver Line-By-Line

Okay, so the segmentation fault appears:

Nemiver Segfault

It's at a line where an object is attempting to "lock" another object. Let's take a look at the variables:

Nemiver Variable View

Yep, there's the problem. Surface isn't actually pointing to any real variable, hence the 0x1. You may also see 0x0, it also means a pointer is not assigned correctly.

Nemiver is a great tool to use for code problems as in the example above. It does have a few usability quirks; it can take a lot of clicks to get from one point to the next. Session saving in 0.5.2 also has its problems and usually results in an error or two. But 90% of the time, Nemiver works like a charm and is a nice breath of fresh air from trying to debug from a terminal. If you like to program in C or C++ and constantly have debugging errors or just want to try something new, Nemiver is a must.

Avatar for jacob Jacob Peddicord - http://jacob.peddicord.net/

Jacob is a web developer, student, and programmer from Ohio. He is a staff member at the Ubuntu Forums and is most likely a fanboy of the distribution. He loves to write in code and words, play video games, and rant about topics most would have abandoned long ago. Jacob uses GNOME and is never seen running stable software, much to the demise of his laptop.

Home » Articles »

Discussion: Debugging with Nemiver

  1. Pat Zearfoss (guest)

    # Posted on 28 April 2008 at 08:56 PM

    Has anyone tried this with kernel code? I would love something like this for my operating systems class.



  2. Dodji Seketeli (guest)

    # Posted on 29 April 2008 at 08:58 AM

    Hello,

    Thank you for this nice article. It is appreciated.

    I would like to add that the "jump to this execution location" feature is actually present in nemiver. You just have to right click on an instruction and select "Run to Cursor". It should do what you want. It would be nice if you could edit the article accordingly.

    Thank you very much.

    Dodji.

    <em>[ ah, thanks! I hadn't noticed that. -Jacob ]</em>



  3. Dodji Seketeli (guest)

    # Posted on 29 April 2008 at 12:40 PM

    Thank you very much Jacob for having edited your nice article according to my last comment :-)

    Cheers.



  4. santhosh (guest)

    # Posted on 05 May 2011 at 06:20 PM

    hello Please tellme installation steps of nemiver in ubuntu 10.04



Home » Articles » Debugging with Nemiver