01.09.2014 Views

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

The Linux Development Platform Configuring, Using, and ... - Classes

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CH05.fm Page 156 Monday, October 7, 2002 9:00 PM<br />

156 Chapter 5 • Working with GNU Debugger<br />

(gdb) n<br />

Enter second number : 12<br />

14 total = sum(num1, num2);<br />

(gdb) print num1<br />

$1 = 34<br />

(gdb) set num1=11<br />

(gdb) print num1<br />

$2 = 11<br />

(gdb) print num2<br />

$3 = 12<br />

(gdb) n<br />

Calculation complete. Returning ...<br />

15 printf("\n<strong>The</strong> sum is : %d\n", total);<br />

(gdb) n<br />

<strong>The</strong> sum is : 23<br />

16 }<br />

(gdb)<br />

5.6 Adding Break Points<br />

When you start debugging a program, you use the run comm<strong>and</strong>. This comm<strong>and</strong> executes the<br />

program until the end of the program or a break point is met. A break point is a place in your<br />

source code file where you temporarily want to stop execution of the program being debugged.<br />

Break points in GNU debugger can be placed using the break comm<strong>and</strong>. Look at the following<br />

list of the source code file sum.c which you already have used:<br />

(gdb) list<br />

1 #include <br />

2 main ()<br />

3 {<br />

4 int num1, num2, total ;<br />

5<br />

6 printf("Enter first number : ");<br />

7 scanf("%d", &num1);<br />

8 printf("Enter second number : ");<br />

9 scanf("%d", &num2);<br />

10<br />

(gdb)<br />

To place a break point at line number 6 in file sum.c (displayed above), you can use the<br />

following comm<strong>and</strong>:<br />

(gdb) break sum.c:6<br />

Breakpoint 1 at 0x8048496: file sum.c, line 6.<br />

(gdb)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!