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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

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

Table 5-1 Common gdb comm<strong>and</strong>s<br />

Comm<strong>and</strong><br />

run<br />

quit<br />

print expr<br />

next<br />

step<br />

continue<br />

Description<br />

Start a program execution inside gdb from the beginning<br />

Quit gdb<br />

Print expression, where expression may be a variable name<br />

Go to next line<br />

Step into next line<br />

Continue from the current place until end of program reaches or you find a break<br />

point<br />

call, it will not go into the function code <strong>and</strong> you will not see what happens inside the function<br />

code. This is equivalent to the step over action used in many debuggers. On the other h<strong>and</strong> if you<br />

use the step comm<strong>and</strong>, it will move to the next line but if the current line is a function call, it<br />

will go into the function code <strong>and</strong> will take you to the first line inside the function. This is also<br />

called a step into action in some debuggers.<br />

5.2.2 A Sample Session with gdb<br />

In this section you go through a sample gdb session. You will use the following C code in<br />

this session <strong>and</strong> will step through the code from top to bottom. This code is saved in a file<br />

sum.c <strong>and</strong> the output executable file is sum. <strong>The</strong> sum.c file is listed below.<br />

#include <br />

main ()<br />

{<br />

int num1, num2, total ;<br />

}<br />

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

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

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

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

total = num1 + num2;<br />

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

As you can see, the sum.c file takes two numbers as input. It then calculates the sum <strong>and</strong><br />

displays it as st<strong>and</strong>ard output. <strong>The</strong> compilation is done using the following comm<strong>and</strong>.<br />

gcc –g sum.c –o sum

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

Saved successfully!

Ooh no, something went wrong!