Assignment #3
An Introduction to the C Debugger xxgdb
CS371 Spring 2000
Date Issued 02/01/'00
Date Due 02/14/'00


Note: You have two weeks to submit this assignment.

Xxgdb
xxgdb is a source code debugging system , it is  a graphical user interface to the gdb debugger under the X Window System. Together these tools provides visual feedback and mouse input for the user to control program execution through breakpoints, to examine and traverse the function call stack, to display values of variables and data structures, and to browse source files and functions.

To use xxgdb the program must be compiled with the gcc compiler using the "-g" compiler flag set. For example, the command:

        gcc  -g prog.c -o prog

compiles the file prog.c. The "-g" flag causes the compiler to insert information into the executable file (named prog) that gdb and xxgdb require in order to work.
 

Compiling the Sample Program

Copy the sample program maxline.c and the sample input file  text_maxline into your directory. Click on the links to open the programs, then click on the File option of the menubar and click on Save as to save it in your directory.
Compile the program in debug mode (-g), creating an executable file called  maxline using the following command :

          gcc -g maxline.c -o maxline
 

Loading the Sample Program into xxgdb
 

  1.  Make the directory that contains maxline.c and the executable file maxline the current directory. Invoke xxgdb in the background by keying in  the following in the command prompt:
         xxgdb&

     A typical xxgdb screen is shown below. The main window can be thought as subdivided into three sub windows:
The first part is called the Source Window because the source file is displayed in this part. The second part is called the Command Window where essentially all the xxgdb command are present. To invoke any of them, simply click on the appropiate button. The third part is the Dialog Window which provides a typing interface to xxgdb.
 
 
















  2.   Open the executable file maxline for debugging by clicking the file  command button in the Command Window and selecting the executable file maxline. The source code of maxline.c appears on the window, as shown below:
 
 













3.   Key in the following command in the xxgdb dialog window
      help <command name>
      to know how to use the different commands. For example,  if you key in
          help run
      in the Dialog Window, you will get the description of the run command, as shown below.
 
 














 You can also get online help on xxgdb at : http://intranet/COG/Software/X11_Linux/man/progs/xxgdb.1.html
 

Stepping Through the Sample Program
 

  1.  Set a breakpoint in the main function by bringing the cursor to the beginning of  'main' in the Source Window of  xxgdb and clicking the break command button.  A hand sign appears at the first executable statement of the function main, which in this case is the printf statement.

  2.  Run the program by typing
         run<text_maxline
in the Dialog Window.
      We'll use the text file text_maxline as an input for the maxline program, the '<' symbol indicates that run command should take the text_maxline file as a standard input.
An arrow appears at the first executable statement of main, which is the printf statement here.
 
 













  3.  Execute the output line in main by clicking the next command button twice. The output statement will execute and print the following message in the Dialog Window:

           Hello! This is an output of program maxline.c

       Note: This text is printed by the program maxline and not by the debugger xxgdb. This is how the standard output will look like.

         The arrow will move to the next line as you can see.
 
 










4.  Click the next command button again and observe the arrow move to the next line.
5.   Click the next command button several times and observe the arrow move back to the first line of the while loop.
 
 

Stepping into a Function
 

  1.   Click the next command button until the arrow move to line 21 of the main function.
  2.   Click the step command button to step into the getline function rather than executing it as a whole. The arrow will now be point to the first line of getline body.
  3.   Click on the line next after the while statement header in the main function body and click the break button in the Command Button menu.This  will set a breakpoint at the beginning of if statement in the loop body.
  4.   Click cont button to resume execution. Now it stops at the recently set breakpoint.
 
 













Displaying the Value of Variables
 

      If you click on the locals command button, you will get the latest values of the local variables in the function. In the picture below, the values of the local variables in the main function are shown.













Removing Breakpoints
 

  1.   Now we want to remove the breakpoints that we've set in main.  Click the show brkpts command button to view the breakpoints that are currently set.
  2.   To delete breakpoints manually, type:
           delete 1
         in the xxgdb dialogue window. This will delete the first breakpoin i.e.the stop sign will disappear from the  beginning of the first breakpoint, indicating that the break point has been removed.
  4.   Click the show brkpts command button to verify that the breakpoint has been deleted.
 
 













Exiting from xxgdb

To exit from xxgdb, click the quit command button.
 

Lab Assignment

        Design and write the code in C, for the Mccabe complexity program specified in Lab2. Use xxgdb for debugging. There is a test example , which you can use to test your program.  Don't  send this test example .

Also , Note that the executable  program should take the input file as parameter(maccabe testfile.c).  The output should be on standard output.    Points will be  deducted for the programs which are not compiling.

       Your program should take into account at least the following test cases :

E-mail to theTA the source code  of the program. The submitted attachment file(s) should be named mylogin.c (and mylogin.h if you are using your header file ).
 
 

 cs371 Home | HW List |