# GDB

## Cheatsheet

| Command                                                                                      | Shortcut                                                   | Purpose                                                                                                                               |
| -------------------------------------------------------------------------------------------- | ---------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| `list main`                                                                                  | `li main`                                                  | Shows source code of `main` function (only if compiled with `gcc -g`)                                                                 |
| <p><code>break main</code></p><p><code>break 10</code></p>                                   | <p><code>br main</code></p><p><code>br 10</code></p>       | Sets a break point at the start of the `main` function, sets break point at line 10 of provided source code (if compiled with source) |
| <p><code>run</code></p><p><code>run haha</code></p>                                          | <p><code>r</code></p><p><code>r haha</code></p>            | Runs the program from the beginning. Adds `haha` as a cmd line arg.                                                                   |
| `continue`                                                                                   | `c`                                                        | Continues the program execution after hitting a breakpoint                                                                            |
| `next instruction`                                                                           | `n i`                                                      | Go to the next instruction and stop execution                                                                                         |
| `inspect registers`                                                                          | <p><code>i r</code></p><p><code>i r esp ebp eip</code></p> | Inspect registers at the current point in execution. Can specify individual or multiple registers as well to reduce output on screen. |
| `examine/5instructions $eip`                                                                 | `x/5i $eip`                                                | Examine the next 5 instructions of the EIP register.                                                                                  |
| `x/8xb $eip`                                                                                 |                                                            | Examine the next 8 hex bytes of the EIP register                                                                                      |
| <p><code>x/6cb 0x8048484</code></p><p><code>x/s 0x8048484</code></p>                         | inspect chars and strings                                  | <p>Inspect the next six bytes as char and print their values</p><p>Inspect the string stored at the memory location</p>               |
| <p><code>x/o</code></p><p><code>x/x</code></p><p><code>x/u</code></p><p><code>x/t</code></p> | <p></p><p></p>                                             | <p>Octal</p><p>hex</p><p>Unsigned base-10 int</p><p>binary</p>                                                                        |
|                                                                                              |                                                            |                                                                                                                                       |
|                                                                                              |                                                            |                                                                                                                                       |
|                                                                                              |                                                            |                                                                                                                                       |
|                                                                                              |                                                            |                                                                                                                                       |
|                                                                                              |                                                            |                                                                                                                                       |
