Lab 6: Debuggers GDB Breakpoints Inspection TUI mode - - PowerPoint PPT Presentation

lab 6 debuggers
SMART_READER_LITE
LIVE PREVIEW

Lab 6: Debuggers GDB Breakpoints Inspection TUI mode - - PowerPoint PPT Presentation

Debuggers Lab 6: Debuggers GDB Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous Comp Sci 1585 Data Structures Lab: Tools for Computer Scientists Outline Debuggers GDB Breakpoints Inspection TUI


slide-1
SLIDE 1

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Lab 6: Debuggers

Comp Sci 1585 Data Structures Lab: Tools for Computer Scientists

slide-2
SLIDE 2

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Outline

1

Debuggers

2

GDB Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

slide-3
SLIDE 3

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Debuggers

  • Step through code one line at a time
  • Inspect variables, including structs and classes
  • View disassembly
  • Check the call stack
  • $ gdb Command-line debugger
  • $ kdbg GUI frontend for gdb
slide-4
SLIDE 4

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Outline

1

Debuggers

2

GDB Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

slide-5
SLIDE 5

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Using $ gdb

  • $ gdb your-program launches the debugger
  • Note: You will want to compile with $ g++ -g
  • (gdb) run arg1 arg2 ... runs the command with

command line arguments

  • (gdb) backtrace or (gdb) bt shows the call stack
slide-6
SLIDE 6

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Outline

1

Debuggers

2

GDB Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

slide-7
SLIDE 7

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Setting breakpoints with $ gdb

  • (gdb) break filename.cpp:10 will stop execution

whenever line 10 in ‘filename.cpp’ is reached.

  • (gdb) continue resumes running as normal.
  • (gdb) step runs one more line of code.
  • (gdb) next runs until execution is on the next line.
  • (gdb) finish runs until the current function returns.
  • (gdb) delete removes all breakpoints.
  • More on breakpoints
slide-8
SLIDE 8

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Outline

1

Debuggers

2

GDB Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

slide-9
SLIDE 9

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Looking at variables with $ gdb

  • (gdb) p variable prints the contents of ‘variable’.
  • (gdb) p also works with expressions of just about any

sort.

  • (gdb) x address examines one word memory at a

given address.

  • (gdb) x/2 address examines two words of memory.
  • More on examining memory
  • (gdb) info registers lists all register values.
  • (gdb) p $regname prints the value of a register.
slide-10
SLIDE 10

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Outline

1

Debuggers

2

GDB Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

slide-11
SLIDE 11

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Text User Interface (TUI) mode

  • $ gdb a.out -tui
  • r
  • (gdb) tui enable
  • (gdb) help layout
  • (gdb) layout

Most useful: (gdb) start followed by (gdb) layout src

slide-12
SLIDE 12

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Outline

1

Debuggers

2

GDB Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

slide-13
SLIDE 13

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Code::Blocks plugin

1 make a project, accepting defaults for debug target 2 add your files 3 use the debug menu to run/start/step 4 right click on variables to watch them

slide-14
SLIDE 14

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Outline

1

Debuggers

2

GDB Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

slide-15
SLIDE 15

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

KDevelop and KDbg

Both good options for another graphical interface

slide-16
SLIDE 16

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Outline

1

Debuggers

2

GDB Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

slide-17
SLIDE 17

Debuggers GDB

Breakpoints Inspection TUI mode Code::Blocks plugin KDevelop and KDbg Miscellaneous

Miscellaneous

Conditional Breakpoints: (gdb) condition breakpoint number expression Editing variables with $ gdb :

  • (gdb) set var VARIABLE NAME = value assigns

‘value’ to ‘VARIABLE NAME’

  • (gdb) set {int}0x1234 = 4 writes 4 as an integer to

the memory address 0x1234 Disassembling code: (gdb) disassemble function prints the assembly for a function.