Quick Guide Debuggers

From bibbleWiki
Jump to navigation Jump to search

Introduction

This page is a page to remind me of how to use the cli debuggers for C++, Rails and Python

Debugging Commands Across Rails (rdbg), GDB, and Python (pdb)

Below are three separate MediaWiki tables — one for each debugger — covering: • Set breakpoint before starting • Set breakpoint inside debugger • Continue • Step • Step out • Print current source • Print/Evaluate expression

GDB

Action Command Notes
Set breakpoint before starting gdb --args ./program then break file.c:LINE Or break main.
Set breakpoint in debugger break file.c:LINE Can also break on functions.
Continue continue or c Runs until next breakpoint.
Step step or s Steps into function calls.
Step out finish Executes until current function returns.
Print current source list or l Shows source around current line.
Print/Evaluate expression print expr Evaluates C/C++ expressions.

Rails (rdbg)

Action Command Notes
Set breakpoint before starting rdbg -n --command "break file.rb:LINE" -- bin/rails runner script.rb Use -n to stop at the first breakpoint.
Set breakpoint in debugger break file.rb:LINE Or break Class#method.
Continue continue or c Runs until next breakpoint.
Step step or s Steps into method calls.
Step out finish Runs until current frame returns.
Print current source list or l Shows surrounding lines.
Print/Evaluate expression p expr or pp expr Ruby evaluation inside debugger.

Python (pdb)

Action Command Notes
Set breakpoint before starting python -m pdb script.py then b file.py:LINE Or insert breakpoint() in code.
Set breakpoint in debugger b file.py:LINE Or b function_name.
Continue continue or c Runs until next breakpoint.
Step step or s Steps into function calls.
Step out return or r Runs until current function returns.
Print current source list or l Shows surrounding lines.
Print/Evaluate expression p expr or pp expr Evaluates Python expressions.