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 153 Monday, October 7, 2002 9:00 PM<br />

Displaying Variables 153<br />

5.5.2 Automatic Displaying Variables with Each Comm<strong>and</strong><br />

<strong>The</strong> display comm<strong>and</strong> displays the value of a variable <strong>and</strong> keeps a record of the variable<br />

so that its value is displayed after each comm<strong>and</strong>. <strong>The</strong> following session shows how this<br />

feature works. This is an easy way to closely watch the value of variables with the execution of<br />

each line of code. It is especially useful when you are tracing through a loop where you need to<br />

know the values of some variables in each cycle.<br />

[rr@conformix 5]$ gdb sum<br />

GNU gdb 5.0rh-5 Red Hat <strong>Linux</strong> 7.1<br />

Copyright 2001 Free Software Foundation, Inc.<br />

GDB is free software, covered by the GNU General Public<br />

License, <strong>and</strong> you are<br />

welcome to change it <strong>and</strong>/or distribute copies of it under<br />

certain conditions.<br />

Type "show copying" to see the conditions.<br />

<strong>The</strong>re is absolutely no warranty for GDB. Type "show warranty"<br />

for details.<br />

This GDB was configured as "i386-redhat-linux"...<br />

(gdb) break main<br />

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

(gdb) run<br />

Starting program: /home/rr/5/sum<br />

Breakpoint 1, main () at sum.c:6<br />

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

(gdb) display num1<br />

1: num1 = 134518424<br />

(gdb) disp total<br />

2: total = 134513777<br />

(gdb) n<br />

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

2: total = 134513777<br />

1: num1 = 134518424<br />

(gdb) n<br />

Enter first number : 3<br />

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

2: total = 134513777<br />

1: num1 = 3<br />

(gdb) n<br />

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

2: total = 134513777<br />

1: num1 = 3<br />

(gdb) n<br />

Enter second number : 67<br />

11 total = num1 + num2;<br />

2: total = 134513777<br />

1: num1 = 3

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

Saved successfully!

Ooh no, something went wrong!