Przejdź do treści
Biblioteka skilli
Programowanie · Analiza

gdb

/gdb

Prowadzi debugowanie w GDB: punkty przerwania, obserwatory, awarie segmentacji, zawieszenia, zdalny gdbserver i pliki zrzutów.

Repozytorium
dalcom-skills ↗
Licencja
Apache-2.0
Ostatnia zmiana repozytorium
10.11.2026

Ocena i bezpieczeństwo

95/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść30 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
4
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 10.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

Co robi i kiedy

Prowadzi debugowanie w GDB: punkty przerwania, obserwatory, awarie segmentacji, zawieszenia, zdalny gdbserver i pliki zrzutów.

Oryginalny opis (EN)

Use when running GDB: breakpoints, watchpoints, segfault or hang debugging, reverse debugging, remote gdbserver, core dumps, pretty-printers, Python scripting, or multi-threaded debugging.

Jak działa

  1. Build so the debugger can see
  2. Open the session
  3. Stop where it matters
  4. Read the state at the stop
  5. Untangle threads
  6. Walk backward when forward misses
  7. Drive a remote or embedded target
  8. Make defaults stick
  9. When GDB fights back
Sekcje z nagłówków SKILL.md, w oryginale · 163 linii, 940 słów
Podgląd SKILL.md
---
name: gdb
description: 'Use when running GDB: breakpoints, watchpoints, segfault or hang debugging, reverse debugging, remote gdbserver, core dumps, pretty-printers, Python scripting, or multi-threaded debugging.'
---

# GDB

GDB stops a C or C++ program where it misbehaves and shows the state at that point. Reach for it for breakpoints, watchpoints, stepping, crash or hang diagnosis, reverse debugging, remote debugging with gdbserver, core files, or Python scripting. This skill is read only. It emits analysis and commands for you to run on the target, writes nothing, and mutates no remote machine.

Tell me the binary (built with `-g`; `-Og` or `-O0` gives the most debuggable code) and the symptom: crash, hang, wrong value, or a question about program state. Add the core file, PID, or remote target when the workflow is post mortem, attach, or gdbserver.

## Build so the debugger can see

```bash
gcc -g -Og -o prog main.c
```

For release builds use `-g -O2` and keep an unstripped copy. To ship stripped binaries while keeping debuggability, split the symbols and link them back:

```bash
objcopy --only-keep-debug prog prog.debug
strip prog
objcopy --add-gnu-debuglink=prog.debug prog
```

The binary should carry debug info before any session starts.

## Open the session

```bash
gdb ./prog                            # load a binary
gdb ./prog core                       # binary plus core dump
gdb -p 12345                          # attach to a running process
gdb --args ./prog arg1 arg2           # pass arguments
gdb -batch -ex 'run' -ex 'bt' ./prog  # non-interactive, for CI
```

Continue once GDB holds a live inferior or a loaded core.

## Stop where it matters

| Command | Shortcut | Effect |
|---|---|---|
| `run [args]` | `r` | Start the program |
| `continue` | `c` | Resume after a stop |
| `next` | `n` | Step over, source line |
| `step` | `s` | Step into, source line |
| `nexti` | `ni` | Step over, one instruction |
| `stepi` | `si` | Step into, one instruction |
| `finish` | | Run to the end of the function |
| `until N` | | Run to line N |
| `return [val]` | | Force a return from the function |
| `quit` | `q` | Exit |

Set the stop condition next:

```gdb
break main                          # function
break file.c:42                     # line
break *0x400abc                     # address
break foo if x > 10                 # conditional
tbreak foo                          # fires once
rbreak ^mylib_.*                    # regex over function names
catch throw                         # C++ exception
catch syscall mmap                  # syscall

watch x                             # break when x is written
watch *(int*)0x601060               # watch an address
rwatch x                            # break on read
awatch x                            # break on read or write

info breakpoints
delete 3 / disable 3 / enable 3
ignore 3 100                        # skip the next 100 hits
commands 3 ... end                  # run commands on each hit
```

Execution should stop at the condition that matters before you move on.

## Read the state at the stop

```gdb
print x / print/x x                 # value, hex
print *ptr                          # dereference
print arr[0]@10                     # ten elements from arr[0]
display x                           # print on every stop
info locals / info args
info registers rip rsp rbp
x/10wx 0x7fff0000                   # examine memory: count/format/unit
x/s 0x400abc                        # as string
x/i $rip                            # current instruction
backtrace / bt full
frame 2 / up / down
```

Read the variable, register, or memory region in question before concluding anything.

## Untangle threads

```gdb
info threads
thread 3
thread apply all bt full
set scheduler-locking on            # only the current thread runs while stepping
```

Know each thread state before naming a cause. Deadlock cycles and race reports belong to `concurrency-debugging`, which this skill hands off to once single thread state is read.

## Walk backward when forward misses

```gdb
(gdb) record                        # software record, slow but universal
(gdb) run
(gdb) reverse-continue              # back to the last event
(gdb) reverse-next / reverse-step / reverse-finish
(gdb) record btrace                 # hardware branch trace (Intel PT or BTS)
(gdb) record instruction-history    # replay recorded instructions
```

Use reverse debugging when the bug is easier to catch going backward. Stop when the execution history reaches the state before the bug.

## Drive a remote or embedded target

On the target:

```bash
gdbserver :1234 ./prog              # on the target
gdbserver :1234 --attach 5678       # attach variant
```

On the host:

```gdb
(gdb) target remote 192.168.1.10:1234
```

For cross compiled targets use the matching GDB, for example `aarch64-linux-gnu-gdb`. The host GDB should control the target process before you debug further.

## Make defaults stick

Put session defaults in `~/.gdbinit` once:

```gdb
set history save on
set history size 1000
set print pretty on
set print array on
set print array-indexes on
set pagination off
set confirm off
```

The full command cheatsheet lives in `references/cheatsheet.md`. Pretty printers and the Python API live in `references/scripting.md`.

## When GDB fights back

| Symptom | Cause | Fix |
|---|---|---|
| `No symbol table` | Built without `-g` | Rebuild with `-g` |
| `??` frames in the backtrace | Missing debug info or stack corruption | Install the debug package; suspect a stack smash |
| `Cannot access memory at address` | Null or freed pointer | Check the pointer; run under ASan |
| `SIGABRT` in the backtrace | `abort()` or a failed assertion | Walk up frames to the check |
| GDB hangs on `run` | Program waits on stdin | `run < /dev/null` |
| Breakpoint lands wrong | Optimizer moved the code | Rebuild with `-Og`, or step with `nexti` |

Hand back the bug localized to a frame, variable, register, or instruction, with the commands that produced the evidence. When a blocker stops the session (no symbols, no core, unreachable target), name it with its fix instead.
Pliki w paczce (4)
  • SKILL.md 6 KB
  • agents/openai.yaml 1 KB
  • references/cheatsheet.md 7 KB
  • references/scripting.md 2 KB

Wersje

RepozytoriumWynikLicencja
Ta strona · gosuda/dalcom-skills95Apache-2.0
OutlineDriven/outline-driven-development100Apache-2.0
mohitmishra786/low-level-dev-skills100MIT

Migawka bazy z 13.11.2026 · wersja paczki 07bbf89b3c1e (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100tizen-gdb-debug
    Debuguje zdalnie natywne aplikacje Tizen w GDB: uruchamia gdbserver, przekierowuje porty i dołącza klienta na hoście.
  • 100rust-debugging
    Debuguje programy Rust w GDB lub LLDB: pretty-printery, paniki, backtrace, async z tokio-console i kod no_std.
  • 100pwndbg
    Prowadzi debugowanie programu w GDB przez pwndbg MCP: rejestry, pamięć, stos i lokalizację awarii na zdalnej maszynie.
  • 100tizen-gdb-debug
    Zdalnie debuguje natywne aplikacje Tizen przez GDB: sprawdza urządzenie, przekierowuje porty i generuje polecenie podłączenia, pomijając projekty WebApp.
  • 90rust-debugging
    Debuguje binarki Rust w GDB lub LLDB, interpretuje paniki i śledzenia stosu oraz diagnozuje async przez tokio-console.
  • 90rust-debugging
    Pomaga debugować binaria Rust w GDB lub LLDB, włączać pretty-printery, czytać paniki i backtrace'y, debugować async z tokio-console i przechodzić kod no_std.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.