Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
mohitmishra786 avatar

Gdb

  • 511 installs
  • 155 repo stars
  • Updated June 27, 2026
  • mohitmishra786/low-level-dev-skills

gdb is an agent skill that diagnoses crashes, segfaults, deadlocks, and incorrect state in native C/C++ binaries using breakpoints and backtraces for developers who debug systems code during development and incidents.

About

gdb is a low-level developer skill from mohitmishra786/low-level-dev-skills that guides GNU Debugger workflows for native C and C++ binaries. The skill helps developers set breakpoints, inspect stacks, read memory and registers, trace thread deadlocks, and analyze segfaults when programs crash during development or after release. Developers reach for gdb when core dumps, intermittent crashes, or corrupted state require interactive debugging beyond printf logging or sanitizer reports alone. The workflow covers launching gdb against failing binaries, capturing backtraces at fault points, stepping through suspect functions, and correlating register and heap state with source lines. Use it during bring-up of systems software, game engines, embedded firmware, or any native module where production incidents demand fast root-cause isolation.

  • Breakpoint and watchpoint workflows
  • Core dump and live-process attach
  • Backtrace and frame-local variable inspection
  • Conditional breaks for race reproduction
  • Remote gdbserver debugging

Gdb by the numbers

  • 511 all-time installs (skills.sh)
  • +39 installs in the week ending Aug 4, 2026 (Skillselion tracking)
  • Ranked #84 of 596 Debugging skills by installs in the Skillselion catalog
  • Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill gdb

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs511
repo stars155
Last updatedJune 27, 2026
Repositorymohitmishra786/low-level-dev-skills

How do you debug C/C++ segfaults with GDB?

Diagnose crashes, segfaults, deadlocks, and incorrect state in native C/C++ binaries during development and post-release incident response with breakpoints and backtraces.

Who is it for?

Systems and native C/C++ developers investigating crashes, deadlocks, or memory corruption in binaries or core dumps.

Skip if: Web, mobile, or interpreted-language debugging where GDB does not attach to the runtime.

When should I use this skill?

The user reports segfaults, deadlocks, core dumps, or incorrect native C/C++ state and needs GDB breakpoint or backtrace analysis.

What you get

Root-cause backtraces, breakpoint traces, register and memory snapshots, and a fixed native binary patch plan

  • Backtrace report
  • Breakpoint reproduction steps
  • Root-cause analysis notes

Files

SKILL.mdMarkdownGitHub ↗

GDB

Purpose

Walk agents through GDB sessions from first launch to advanced workflows: crash diagnosis, reverse debugging, remote debugging, and multi-thread inspection.

Triggers

  • "My program segfaults / crashes — how do I debug it?"
  • "How do I set a breakpoint on condition X?"
  • "How do I inspect memory / variables in GDB?"
  • "How do I debug a remote embedded target?"
  • "GDB shows ?? frames / no source"
  • "How do I replay a bug deterministically?" (record/replay)

Workflow

1. Prerequisite: compile with debug info

Always compile with -g (GCC/Clang). Use -Og or -O0 for most debuggable code.

gcc -g -Og -o prog main.c

For release builds: use -g -O2 and keep the binary with symbols (strip separately with objcopy).

2. Start GDB

gdb ./prog                          # load binary
gdb ./prog core                     # load with core dump
gdb -p 12345                        # attach to running process
gdb --args ./prog arg1 arg2         # pass arguments
gdb -batch -ex 'run' -ex 'bt' ./prog  # non-interactive (CI)

3. Essential commands

CommandShortcutEffect
run [args]rStart the program
continuecResume after break
nextnStep over (source line)
stepsStep into
nextiniStep over (instruction)
stepisiStep into (instruction)
finishRun to end of current function
until NRun to line N
return [val]Force return from function
quitqExit GDB

4. Breakpoints and watchpoints

break main                          # break at function
break file.c:42                     # break at line
break *0x400abc                     # break at address
break foo if x > 10                 # conditional break
tbreak foo                          # temporary breakpoint (fires once)
rbreak ^mylib_.*                    # regex breakpoint on all matching functions

watch x                             # watchpoint: break when x changes
watch *(int*)0x601060               # watch memory address
rwatch x                            # break when x is read
awatch x                            # break on read or write

info breakpoints                    # list all breakpoints
delete 3                            # delete breakpoint 3
disable 3                           # disable without deleting
enable 3

5. Inspect state

print x                             # print variable
print/x x                           # print in hex
print *ptr                          # dereference pointer
print arr[0]@10                     # print 10 elements of array
display x                           # auto-print x on every stop
undisplay 1

info locals                         # all local variables
info args                           # function arguments
info registers                      # all CPU registers
info registers rip rsp rbp          # specific registers
x/10wx 0x7fff0000                   # examine 10 words at address
x/s 0x400abc                        # examine as string
x/i $rip                            # examine current instruction

backtrace                           # call stack (bt)
bt full                             # bt + local vars
frame 2                             # switch to frame 2
up / down                           # move up/down the stack

6. Multi-thread debugging

info threads                        # list threads
thread 3                            # switch to thread 3
thread apply all bt                 # backtrace all threads
thread apply all bt full            # full bt all threads
set scheduler-locking on            # pause other threads while stepping

7. Reverse debugging (record/replay)

Record requires target record-full or target record-btrace (Intel PT):

# Software record (slow but universal)
record                              # start recording
run
# ... trigger the bug ...
reverse-continue                    # go back to last break
reverse-next                        # step backwards
reverse-step
reverse-finish

# Intel Processor Trace (fast, hardware)
target record-btrace pt
run
# view instruction history
record instruction-history

8. Remote debugging with gdbserver

On target:

gdbserver :1234 ./prog
# Or attach:
gdbserver :1234 --attach 5678

On host:

gdb ./prog
(gdb) target remote 192.168.1.10:1234
(gdb) break main
(gdb) continue

For cross-compilation: use aarch64-linux-gnu-gdb on the host.

9. Common problems

SymptomCauseFix
No symbol tableBinary not compiled with -gRecompile with -g
?? frames in backtraceMissing debug info or stack corruptionInstall debuginfo package; check for stack smash
Cannot access memory at addressNull dereference / freed memoryCheck pointer before deref; use ASan
SIGABRT in backtraceabort() or assertion failureGo up frames to find the assertion
GDB hangs on runBinary waiting for inputRedirect stdin: run < /dev/null
Breakpoint in wrong placeOptimiser moved codeCompile with -Og; or use nexti

10. GDB init file (~/.gdbinit)

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

For a command cheatsheet, see references/cheatsheet.md. For pretty-printers and Python scripting, see references/scripting.md.

Related skills

  • Use skills/debuggers/core-dumps for loading core files
  • Use skills/debuggers/lldb for LLDB-based workflows
  • Use skills/runtimes/sanitizers to catch bugs before needing the debugger
  • Use skills/compilers/gcc for -g flag details

Related skills

FAQ

What problems does the gdb skill address?

The gdb skill addresses native C and C++ crashes, segfaults, deadlocks, and incorrect runtime state using GNU Debugger breakpoints, backtraces, and interactive inspection during development and incident response.

When should developers invoke the gdb skill?

Developers should invoke the gdb skill when a native binary crashes, produces a core dump, deadlocks across threads, or enters incorrect state that requires GDB backtrace and breakpoint analysis beyond logging alone.

Debuggingbackendtesting

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.