/
GDB Basics What is  gdb ? GDB Basics What is  gdb ?

GDB Basics What is gdb ? - PowerPoint Presentation

morgan
morgan . @morgan
Follow
342 views
Uploaded On 2022-06-28

GDB Basics What is gdb ? - PPT Presentation

G nu D e b ugger A command line tool for debugging your code You can step through the code line by line Set breakpoints Check variables values And lots more Basic commands gdb ID: 926604

balance gdb int line gdb balance line int main target year run breakpoint rate file executable demo code set

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "GDB Basics What is gdb ?" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

GDB Basics

Slide2

What is

gdb

?

G

nu

D

e

b

ugger

A command line tool for debugging your code

You can step through the code (line by line)

Set breakpoints

Check variables/ values

And lots more …

Slide3

Basic commands

gdb

<filename>

//The executable, not the source file

(

gdb

) b main

//Break point on the main() function

Breakpoint 1 at 0x8c5f66979c8: file

gdb_demo.c

, line 5.

(

gdb

) l

// List 10 lines

(

gdb

) run

//Runs the executable till the breakpoint (if any)

Starting program: /home/faculty/krabb/250_test/demos/

gdb

/

gdb_demo

Breakpoint 1, main () at gdb_demo.c:5

5 int balance=100;

(

gdb

) n

//Go to the next line

(

gdb

) quit

//Exit!

Slide4

Example

Compile your code with ‘-g’ switch

Run it, and notice the result doesn’t make sense!

Run

gdb

on your executable (

gdb

myApp)Set a breakpoint (at main)Run and step to line 13Print value of balance, rate, interestStep until we reach to line 15Print value of target, year, balanceSo, condition is wrong here. It should be balance < target.

/* File:

buggy.c

*/

#include <

stdio.h

>

int main()

{

int balance=100;

int target=1000;

float rate = 0.1;

int year = 0;

do

{

float interest = balance * rate;

balance = balance + interest;

year++;

} while ( balance >= target );

printf

("%d No. of years to achieve target balance.\n", year);

return 0;