You are on page 1of 3

CS2400

Laboratory Assignment #6 Debugging via Emacs and more void


Functions
(50 pts)
This lab assignment will show you how to use the debugger with emacs. Also how to
step into functions and you will get even better understanding what gets passed into
functions when the parameters are call by value vs. call by reference. One part of the lab
will be converting value-returning function into void functions and the last part consists
of manually tracing a program and writing out the output.

Step 1: First create a subdirectory called lab6 as before.


Step 2: Then copy min_sum.cc from the course account lab6 directory.
Step 3: Debugging via Emacs
1. Here you will be using min_sum.cc to step through line by line using the gdb
debugger.
2. Open the file min_sum.cc in emacs using the command
emacsmin_sum.cc
if the window is split into two click on File menu and click on remove other
windows.
3. In the Tools menu in emacs, select the compile option. You will see the following
at the bottom Compilecommand:makek . Remove makek and type
the follow command g++gmin_sum.cc and hit enter.
(g option tells the compiler to save the information the debugger needs)
4. In the Tools menu in emacs, select the Debugger(GUD) option. (You will
see the following at the bottom
Rungdb(likethis):gdbi=mia.out
Hit enter to use gdb debugger.
5. After you hit enter you will see something like the following:
GNUgdb(GDB)7.5.1
Copyright(C)2012FreeSoftwareFoundation,Inc.
LicenseGPLv3+:GNUGPLversion3orlater
<http://gnu.org/licenses/gpl.html>
Thisisfreesoftware:youarefreetochangeandredistribute
it.

ThereisNOWARRANTY,totheextentpermittedbylaw.Type"show
copying"
and"showwarranty"fordetails.
ThisGDBwasconfiguredas"i386pcsolaris2.10".
Forbugreportinginstructions,pleasesee:
<http://www.gnu.org/software/gdb/bugs/>...

6. Set a break point. The underlined part is what you type.


(gdb)breakmin_sum.cc:18
Breakpoint1at0x8048a55:filemin_sum.cc,line18.
7. Click on the Gud menu and select the GDBMI sub menu item, then select
displayotherwindows. After this, there will be a lot of windows open for
your session of emacs. One window will show the code, one will show the
debugger (gdb), the top right window will show local variables, and below that is the
input/output window, finally the bottom right window shows the breakpoints youve
set, so far, just one at line 18 of main.
8. Enter the command run in the gdb sub window (top-left).
(gdb)run
Startingprogram:/home/<yourusername>/lab6/a.out
[Threaddebuggingusinglibthread_dbenabled]
[NewThread1(LWP1)]
[SwitchingtoThread1(LWP1)]
Breakpoint1,main()atmin_sum.cc:18
18
intsum=0;
(you should see your source code in the bottom half of the window)
(gdb)n
(notice that the local variable sum changes value after the intsum=0; statement.
(gdb)n
Answer question 1 on the answer sheet. (hint look at the input/output window).
Notice the arrow (code display window) is pointing at the function Get_Num. Also
notice the red dot next to the intsum=0; statement. The red dot indicates you
have set a breakpoint here. (a break point is where you tell the debugger you want to
temporarily stop the execution of the program to take a look at something.
Step into the function by doing the following
(gdb)s

Answer questions 2 and 3 on the answer sheet.


(gdb)n
(gdb)n
When the arrow is pointing at cin you will see the prompt in the input/output window.
Click in this window, and enter the number 15:
Enteranumberandenter1toquit15
Go back to the debugger window (click there), and do the following:
(gdb)n
main () at min_sum.cc:24
24
minimum = number;
Answer question 4 on the answer sheet.
(gdb) n
(gdb) n
Step into the Find_min and Sum_All function the same way as before.
Answer questions 5 7 on the answer sheet.

Step 4 and Step 5 Look at the answer sheet

You might also like