Random thoughts shooting out of volatile mind
GDB's GUI "insight" Tutorial
I already have written a blog mentioning about a GUI for gdb. Today I'm going to give a brief tutorial of how to install insight and some basics for using the insight in debugging your programs. As I mentioned earlier this program can be downloaded from this link.
 To install insight you first need to extract the insight folder from archive using following command
[root@localhost ~]# tar -xvf filename
Once extracting is done enter the insight's directory and use following commands for installing
[root@localhost insight]# ./configure 
[root@localhost insight]# make
[root@localhost insight]# make install

Note that all these commands will take some time to finish so have pateince till they finish :)
To begin with any executable file that you want to debug  must contain a debugging information in it, this info is generated by compiler when we specify -ggdb or -g switch to the compiler either it is c(gcc) or c++(g++) . To launch insight you just have to type insight in shell prompt. The GUI version of gdb will be  launched and you can have a look at it in the following image.
To load your executable file click on File tab and click Open as shown above this will open up a file browsing window from where you can select your executable file. See image below.
Once the file is loaded you can see your program in the main window with "-" symbol at place where you can insert break points. When you insert break points you can see a "red" square dot to specify break points. See image below
You can see a animation of a man running in the top left corner in the tool bar it is the button for running your program click on it program will star and stop at your first break point. You can make out this by seeing the color of break point line which will now turn into green. The button next is to step that is line by line execution and the one next to it is for next instruction of gdb difference between next and step is that if current instruction is a function call step will  step into function where as next executes entire function and stops at instruction next to function call.  The  next 2 buttons are finish and continue. Finish resumes normal execution ignoring all further break points where as continue executes all instruction till next break point is encountered. Next to buttons are for assembly language executing. Which is not required by normal users (it is for developer designig inbuilt functions or system calls).
Thinking of how to see and modify variable value? Well click on the view tab you have a set of options there. 
I'll start from basic one Local Variables. Click on this option a window consisting of all local variable of currently executing routine will open up. If you want to change any variable value you just need to right click(hold) and click on edit which will make a text box to appear where you can enter new value or modify existing one. See following images.

Next let us see the Watch Expression option. When you use you will notice that some variables which are globals are not listed. For global variables we use Watch expression. Here you can even enter expression like root[i] (say) and find their value during each step in execution. You can edit values using similar steps as local variables which I mentioned above.
 As you can see in image array variables are collapsible structures to see their values, one in the image is multi dimensional array. 

Other options:
1.Stack Trace can be used to keep track of nested function calls especially helpful in recursive functions.
2.Memory Dump provides you with memory lay out of the program you can see where in the memory are variables are stored using this.
3.Registers provide you with CPU register contents useful if you are using register like key word.
4.Console: this for the one who is missing old command line GDB :)
5.Function Browser provides details of set of functions declared in current program.
6.Breakpoints provides list of break points in current program.
7.Thread List for thread programmers.
Below are some snap shots of some of these options.

You have to remember this unlike other debuggers in Linux(kdbg) insight should be launched from  shell console otherwise you won't be able to recive inputs or see outputs of an interactive program. Following screen shot displays insight utilizing shell console to get the input.
insight also helps in advanced debugging as you can see in first image of this article, at top right corner of tool bar a drop down list is provided with following views.
  1. Source (Normal user)
  2. Assembly 
  3. Source + Assembly (split view)
  4. Mixed (assembly language version for each high level language instructions)
Following image is of assembly language version of a program I was debugging when I took this screen shots.
So now tell me isn't it easy to debug your code with this tool ? Any way HAppy Debugging :) 

Posted by: copyninja on Thursday, 30 October 2008

blog comments powered by Disqus
Fork me on GitHub