重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
gdb by mohitmishra786/low-level-dev-skills
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill gdb引导代理完成从初次启动到高级工作流程的 GDB 会话:崩溃诊断、反向调试、远程调试和多线程检查。
?? 帧/无源代码"始终使用 -g(GCC/Clang)进行编译。对于最易调试的代码,使用 -Og 或 -O0。
gcc -g -Og -o prog main.c
对于发布版本:使用 -g -O2 并保留带符号的二进制文件(使用 objcopy 单独剥离符号)。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
gdb ./prog # 加载二进制文件
gdb ./prog core # 加载核心转储文件
gdb -p 12345 # 附加到正在运行的进程
gdb --args ./prog arg1 arg2 # 传递参数
gdb -batch -ex 'run' -ex 'bt' ./prog # 非交互式(CI)
| 命令 | 快捷键 | 效果 |
|---|---|---|
run [args] | r | 启动程序 |
continue | c | 中断后恢复执行 |
next | n | 单步跳过(源代码行) |
step | s | 单步进入 |
nexti | ni | 单步跳过(指令) |
stepi | si | 单步进入(指令) |
finish | 运行到当前函数结束 | |
until N | 运行到第 N 行 | |
return [val] | 强制从函数返回 | |
quit | q | 退出 GDB |
break main # 在函数处中断
break file.c:42 # 在行号处中断
break *0x400abc # 在地址处中断
break foo if x > 10 # 条件断点
tbreak foo # 临时断点(仅触发一次)
rbreak ^mylib_.* # 在所有匹配函数上设置正则表达式断点
watch x # 观察点:当 x 改变时中断
watch *(int*)0x601060 # 观察内存地址
rwatch x # 当 x 被读取时中断
awatch x # 当 x 被读取或写入时中断
info breakpoints # 列出所有断点
delete 3 # 删除断点 3
disable 3 # 禁用而不删除
enable 3
print x # 打印变量
print/x x # 以十六进制打印
print *ptr # 解引用指针
print arr[0]@10 # 打印数组的前 10 个元素
display x # 每次停止时自动打印 x
undisplay 1
info locals # 所有局部变量
info args # 函数参数
info registers # 所有 CPU 寄存器
info registers rip rsp rbp # 特定寄存器
x/10wx 0x7fff0000 # 检查地址处的 10 个字
x/s 0x400abc # 以字符串形式检查
x/i $rip # 检查当前指令
backtrace # 调用栈(bt)
bt full # bt + 局部变量
frame 2 # 切换到帧 2
up / down # 在栈中向上/向下移动
info threads # 列出线程
thread 3 # 切换到线程 3
thread apply all bt # 对所有线程执行 backtrace
thread apply all bt full # 对所有线程执行 full backtrace
set scheduler-locking on # 单步执行时暂停其他线程
记录需要 target record-full 或 target record-btrace(Intel PT):
# 软件记录(速度慢但通用)
record # 开始记录
run
# ... 触发错误 ...
reverse-continue # 回到上一个断点
reverse-next # 向后单步
reverse-step
reverse-finish
# Intel 处理器追踪(快速,硬件支持)
target record-btrace pt
run
# 查看指令历史
record instruction-history
在目标机器上:
gdbserver :1234 ./prog
# 或者附加到进程:
gdbserver :1234 --attach 5678
在主机上:
gdb ./prog
(gdb) target remote 192.168.1.10:1234
(gdb) break main
(gdb) continue
对于交叉编译:在主机上使用 aarch64-linux-gnu-gdb。
| 症状 | 原因 | 解决方法 |
|---|---|---|
No symbol table | 二进制文件未使用 -g 编译 | 使用 -g 重新编译 |
调用栈中出现 ?? 帧 | 缺少调试信息或栈损坏 | 安装 debuginfo 包;检查栈溢出 |
Cannot access memory at address | 空指针解引用 / 已释放内存 | 解引用前检查指针;使用 ASan |
调用栈中出现 SIGABRT | abort() 或断言失败 | 向上查看栈帧以找到断言 |
GDB 在 run 时挂起 | 二进制文件等待输入 | 重定向标准输入:run < /dev/null |
| 断点位置错误 | 优化器移动了代码 | 使用 -Og 编译;或使用 nexti |
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
有关命令速查表,请参阅 references/cheatsheet.md。有关美化打印器和 Python 脚本编写,请参阅 references/scripting.md。
skills/debuggers/core-dumps 加载核心转储文件skills/debuggers/lldb 处理基于 LLDB 的工作流程skills/runtimes/sanitizers 在需要调试器之前捕获错误skills/compilers/gcc 了解 -g 标志的详细信息每周安装次数
60
代码仓库
GitHub 星标数
34
首次出现
2026年2月20日
安全审计
安装于
codex59
opencode58
gemini-cli58
github-copilot58
amp58
cline58
Walk agents through GDB sessions from first launch to advanced workflows: crash diagnosis, reverse debugging, remote debugging, and multi-thread inspection.
?? frames / no source"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).
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)
| Command | Shortcut | Effect |
|---|---|---|
run [args] | r | Start the program |
continue | c | Resume after break |
next | n | Step over (source line) |
step |
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
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
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
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
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.
| Symptom | Cause | Fix |
|---|---|---|
No symbol table | Binary not compiled with -g | Recompile with -g |
?? frames in backtrace | Missing debug info or stack corruption | Install debuginfo package; check for stack smash |
Cannot access memory at address | Null dereference / freed memory | Check pointer before deref; use ASan |
SIGABRT in backtrace |
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.
skills/debuggers/core-dumps for loading core filesskills/debuggers/lldb for LLDB-based workflowsskills/runtimes/sanitizers to catch bugs before needing the debuggerskills/compilers/gcc for -g flag detailsWeekly Installs
60
Repository
GitHub Stars
34
First Seen
Feb 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex59
opencode58
gemini-cli58
github-copilot58
amp58
cline58
Ghostling libghostty 终端模拟器 - 基于 libghostty-vt 的轻量级终端实现
430 周安装
Terraform Cloud Plan JSON 下载与分析工具 - 详细资源变更解析
56 周安装
iOS专家技能:SwiftUI开发最佳实践、项目结构与铁律指南(2024最新)
56 周安装
Slidev点击动画教程:v-click、v-after、v-clicks、v-switch和motion指令详解
56 周安装
注意力管理动画原则:运用迪士尼动画原理优化UI/UX设计,提升用户引导效果
56 周安装
Prowler-Commit:遵循Conventional Commits规范的Git提交助手,提升代码提交质量
56 周安装
动画晕动症预防指南:运用迪士尼动画原理优化用户体验,解决头晕恶心问题
56 周安装
s |
| Step into |
nexti | ni | Step over (instruction) |
stepi | si | Step into (instruction) |
finish | Run to end of current function |
until N | Run to line N |
return [val] | Force return from function |
quit | q | Exit GDB |
abort() or assertion failure |
| Go up frames to find the assertion |
GDB hangs on run | Binary waiting for input | Redirect stdin: run < /dev/null |
| Breakpoint in wrong place | Optimiser moved code | Compile with -Og; or use nexti |