Debugging with Nemiver

  • April 28, 2008
  • Avatar for jacob
    Jacob
    Peddicord

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

Home » Articles »