GNU Debugger (GDB): Difference between revisions

From mylearnings
Jump to navigationJump to search
Created page with "* Find start address and end address of a function <pre> info line <Function Name> </pre> * To view the instruction at a specific address. <pre> x/i <Address> </pre> * Print string pointed by a register. <pre> x/s $rdi </pre> * Disassemble a specific range of address. <pre> disass <start address> <end address> </pre>"
 
No edit summary
Line 1: Line 1:
= Basic Commands =
* Find start address and end address of a function
* Find start address and end address of a function
<pre>
<pre>
Line 17: Line 19:
<pre>
<pre>
disass <start address> <end address>
disass <start address> <end address>
</pre>
* Display the local variables
<pre>
info locals
</pre>
* Run GDB until the end of current function
<pre>
finish
</pre>
* Break out of a loop
<pre>
until
</pre>
* Get line number from address
<pre>
info symbol <address>
</pre>
= Watchpoints and Breakpoints
* Stop when foo is modified
<pre>
gdb> watch foo
</pre>
* Watch location
<pre>
gdb> watch -l foo
</pre>
* Stop when foo is read
<pre>
gdb> rwatch foo
</pre>
* Stop when thread 3 modifies foo
<pre>
gdb> watch foo thread 3
</pre>
* Stop when foo is > 10
<pre>
gdb> watch foo if foo > 10
</pre>
* Enable a break point.
<pre>
gdb> enable <comma separated break point numbers..>
</pre>
* Disable break points.
<pre>
gdb> disable <comma separated break point numbers..>
</pre>
* List all break points.
<pre>
gdb> info b
</pre>
= Debugging a multithreaded program =
* List all the threads.
<pre>
gdb> info threads
</pre>
</pre>

Revision as of 15:18, 7 July 2025

Basic Commands

  • Find start address and end address of a function
info line <Function Name>
  • To view the instruction at a specific address.
x/i <Address>
  • Print string pointed by a register.
x/s $rdi
  • Disassemble a specific range of address.
disass <start address> <end address>
  • Display the local variables
info locals
  • Run GDB until the end of current function
finish
  • Break out of a loop
until
  • Get line number from address
info symbol <address>

= Watchpoints and Breakpoints

  • Stop when foo is modified
gdb> watch foo
  • Watch location
gdb> watch -l foo
  • Stop when foo is read
gdb> rwatch foo
  • Stop when thread 3 modifies foo
gdb> watch foo thread 3
  • Stop when foo is > 10
gdb> watch foo if foo > 10
  • Enable a break point.
gdb> enable <comma separated break point numbers..>
  • Disable break points.
gdb> disable <comma separated break point numbers..>
  • List all break points.
gdb> info b


Debugging a multithreaded program

  • List all the threads.
gdb> info threads