# 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>                                                                        |
|                                                                                              |                                                            |                                                                                                                                       |
|                                                                                              |                                                            |                                                                                                                                       |
|                                                                                              |                                                            |                                                                                                                                       |
|                                                                                              |                                                            |                                                                                                                                       |
|                                                                                              |                                                            |                                                                                                                                       |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.m4lwhere.org/programming/c/gdb.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
