Wednesday, December 5, 2012

DDD: Best Visual Debugger

Debugging is the most important activity in the software and program development. In order to remove or identify the logical errors in the program; debugging is done. Linux uses the utility of ‘gdb’ (GNU Debugger) to debug the programs. It has a strong instruction set but lacking in visual GUI debugging utility. 
 
DDD or Data Display Debugger is a visual debugger made available under GNU public license uses the gdb activities with GUI at foreground! Not only gdb but ddd has in-built command-line debuggers such as DBX, JDB, HP Wildebeest Debugger (WDB), XDB, the Perl debugger, the Bash debugger, the Python debugger, and the GNU Make debugger etc. So, by this visual debugger you can debug programs of C, C++, Java, Shell, Perl, Python etc.
 
Here I am giving a small tutorial to show how to use ddd to debug the C programs. The advanced tutorials will be given afterwards.
 
Let’s start… As I told ddd is available under GPL, so you can download the debugger using following command directly by debian version Linux.
 
sudo apt-get install ddd
 
or you may go to ‘Ubuntu Software Centre’ and search for ‘ddd’ as shown in the picture 1 below. You may get information about it and install from there.
[Note: If images are not visible, click on it to view large] 
 
Picture 1: DDD entry in Ubuntu Software Centre
For example, you have written a C program code named ‘basic.c’. Compile it using gcc in the following fashion:
 
gcc –g –o basic basic.c
 
here, -o suggests the name of the output file that you will create after compilation of ‘basic.c’ and –g suggests that you are giving ability to debug this program. If the –g is missing your program can’t be debugged by gdb or ddd. After compilation you will get an executable file named ‘basic’ (without extension). Note: you may give any name to your executable file at the time of compilation after option –o.
 
Your program will be compiled successfully as shown in the picture 2 below.
 
Picture 2: Compilation of program for debugging
Now, open your ‘ddd’ by simply typing ‘ddd’ on the terminal.
 
Open your program ‘basic.’c by using ‘File’ menu -> open program option. Your program will be opened as shown in the picture 3 below.
 
Picture 3: The ddd windows
Your program will be visible in ‘Program Window’. Below of it, you may find ‘Assembly Code Window’, where the assembly equivalent code is shown. And below of this window, your gdb command line debugger is shown. You may instruct program directly by using gdb also! 
 
In order to set a breakpoint inside the program move your mouse on to respective line and press right click. You may get options as shown in the picture 4 below.
Picture 4 : Setting a breakpoint
The any number of breakpoints can be set in a single program. It is used for executing the program till that point. From that line onwards, you may execute program step-by-step. The breakpoints in the function can be set by typing the command ‘b main’ in the ‘gdb window’ also! Or ‘b 12’ can also be written. Here 12 is the line number in the program.
Now, go to ‘Program’ menu and click on the ‘Run’. Your program will get executed till the first breakpoint set. See the picture 5 below:
Picture 5: Watch variable values by F6
The green arrow shows the line which is in execution currently. Red dot shows the breakpoint. Now, from here onwards you may execute step-by-step just by pressing function key ‘F6’. The program execution will be processed step-by-step as you go on pressing ‘F6’. You may find arrow is traversing with the lines of execution. When you move the mouse on any variable used in the program, you may get the value of the variable on current execution. In the picture 5, you may see the values inside array ‘a’ is shown by the ‘ddd’ at mouse position. By this way you can check the contents of the variable at any point in the program.
 
You may check the content by typing the command in the ‘gdb window’ as shown in the picture 6 below. It has shown the contents of a[i] by typing ‘print a[i]’ in the gdb window.
Picture 6: Use gdb window.
The features of ‘ddd’ are not limited with this. It has a rich set of applications. Just find the options given in the ‘ddd’s menu. You will learn a lot!

Sunday, April 29, 2012

Installing netbeans on Linux


NetBeans 6.5 IDE
NetBeans is one of the best integrated development environment (IDE) for developing with Java, JavaScript, PHP, Python, Groovy, C, C++, Scala, Clojure, as well as object oriented modeling and designs. It is open source and freely available IDE. It comes in a shell package on the internet. Many times we get confused about the installation of NetBeans for Linux OS.
In order to install Java oriented NetBeans, we must have installed JVM on our computer. Following are the steps to install offline NetBeans on the Linux system:

To install NetBeans IDE:

1.  Download the IDE setup file (extension .sh) from http://netbeans.org/downloads/

2.   Open the terminal and navigate to the directory that contains the installer file with .sh extention.

3.   Change the installer file's permissions to make the binary executable by typing from a command prompt:

        $ chmod +x executable_shell_file_name

        This will make your executable_shell_file_name executable. By
typing ‘ ls –a ‘ command, you can check the rwx permissions of the
file.

4.   Launch the installer by typing:

        $ ./executable_shell_file_name

5.   The installer searches for installed JDKs and prompts you to specify which the installer should use. You can also specify which JDK the installer should use from the command line. For example:

  $ ./ executable_shell_file_name -is:javahome path_to_your_jdk

6.   The installer will ask the directory to install. Choose it and press next.
  
Launching NetBeans IDE

To start the IDE:

    Navigate to the bin subdirectory of your installation.
    Execute the launcher script by typing ./netbeans.   

Depending on the Linux distro that you are using, you can find the installed file in the ‘applications’.

Saturday, April 7, 2012

Creating 'root' in Ubuntu


First time, when I used the Ubuntu operating system I found that the setup does not ask for the ‘root’ or its password! It accepts any user name that we want and then we may give any password to it. After installation it shows all accounts that we have created at the startup screen. I was wondered about the ‘root’ and its password also. It was my mistake that I have not searched the process to create the root on internet. I thought the main admin will be our root. But, I know that there is no any Linux distro without ‘root’.

Last month, when I was writing the RPC (Remote Procedure Call) programs on my Ubuntu system, it was not working and refusing the connections again and again. The same program I got executed on Redhat enterprise linux in my college! I tried lot of things and searched on the internet also but I did not find any solution to run the RPC on Ubuntu system. Finally, I mailed this to Prof. Chitrakant Banchhor in SCOE, Pune. He has given me the solution to create the root on Ubuntu. Then, my RPC worked under Ubuntu! We need to have admin (root) rights to run any RPC program under any Ubuntu or Debian distributions!

Here is the process to create it:

1.   Open the terminal in any administrator.
2.   Type:                sudo passwd root
3.   It will ask for your current admin password. After typing it, it will ask to type new root password twice!
4.   After typing it, your root will get established!
5.   We may switch to root temporarily by
su
<typing password>     
6.  In order to login to root, we need to choose the option ‘other’ at user login screen. Type ‘root’ at login name and then password.