Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

gdb

What are the most frequently used GDB commands?

Sadia Zubair

Introduction

GDB is a debugger that uses a command-line interface. It allows us to run the program up to a certain point, then stop and print out the values of selected variables at that point, or after every line step through the program. It also allows us to print the values of each variable after executing each line.

The commands that are most frequently used in GDB are listed in the table below:

Command

Description

b main

Puts a breakpoint at the beginning of the program

b

This command puts a break at the current line

b +N

This command puts a break at the Nth line

b func

This command puts a breakpoint at the beginning of the function func.

d M

This command deletes the breakpoint number M.

r

This command runs the program until a breakpoint/error.

c

kk

info break

This command list breakpoints.

f

This command funs until the current function is executed.

s

This command runs the next line of the program

s M

This command runs the next M lines of the program.

p val

This command prints the value currently stored in the variable val.

u

This command goes up a level in the stack

d

This command goes down a level in the stack


q

This command quits GDB.

info threads

This command display a summary of all threads currently in your program.

info registers

This command print the names along with values of all registers except floating-point registers 

x

This command uses the specified format to display the memory contents at a given address.

frame arg

This command allows you to move from one stack frame to another, and to print the stack frame you select. arg can either the stack frame number or frame's address. If no argument is passed, frame prints the current stack frame.

Note: More information about GDB can be found here.

RELATED TAGS

gdb

CONTRIBUTOR

Sadia Zubair
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring