Debuggers

20
Debuggers

description

Debuggers. Using a debugger. A primitive way of debugging is to insert print statements. Using a debugger. A primitive way of debugging is to insert print statements. That’s OK but a debugger is much more powerful. It’s a program that watches and controls another program as it runs!. - PowerPoint PPT Presentation

Transcript of Debuggers

Page 1: Debuggers

Debuggers

Page 2: Debuggers

Using a debugger A primitive way of debugging is to

insert print statements.

Page 3: Debuggers

Using a debugger A primitive way of debugging is to

insert print statements. That’s OK but a debugger is much

more powerful. It’s a program that watches and

controls another program as it runs!

Page 4: Debuggers

Using a debugger A primitive way of debugging is to

insert print statements. That’s OK but a debugger is much

more powerful. It’s a program that watches and

controls another program as it runs! It allows us to execute our code one line at a time. It allows us to set breakpoints (stop points) in our code. We can even examine and change the contents of

variables as our program runs!

Page 5: Debuggers

JGRASP

Page 6: Debuggers

Setting a breakpoint (jGRASP)

Page 7: Debuggers

Breakpoint is now set (jGRASP)

Page 8: Debuggers

Start the debugger (jGRASP)

Build -> Debug The program then runs and stops at our

first breakpoint.

Page 9: Debuggers

step over

step in

step out

variables (r-click to change value)

next line to be executed

end debugging

jGRASP

Page 10: Debuggers

VC++

Page 11: Debuggers

Setting a breakpoint (VC++)

Page 12: Debuggers

Starting the debugger (VC++)

Page 13: Debuggers

Watch variables (VC++)

Page 14: Debuggers

VC++ debugging options

Page 15: Debuggers

GDB

Page 16: Debuggers

Debugging with gdb (Unix/Linux)

Direct compiler to include debugging information with –g (ex. g++ -g test.cpp)

Run the debugger and indicate program to debug (ex. gdb ./a.out)

Page 17: Debuggers

Setting a breakpoint (gdb) in main and start running

Page 18: Debuggers

Print and set (change) var

Page 19: Debuggers

List source code

Page 20: Debuggers

Useful gdb commands b mainset breakpoint in func main b 10 set breakpoint at line #10 cont continue del break delete all breakpoints l (ell) list source code lines l <func> (ell) list source code lines for <func> n next (like step over) p <var> print contents of variable quit end execution run start running program s step (like step into) set <var>=value change var