Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计通过

debug-optimized-builds调试优化构建

Agent Skill

debug-optimized-builds 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

1,740

周安装

74

GitHub Stars

80

下载量

610
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:debug-optimized-builds(调试优化构建)
来源仓库:https://github.com/mohitmishra786/low-level-dev-skills
仓库路径:skills/debug-optimized-builds
安装命令:
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill debug-optimized-builds
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill debug-optimized-builds

简介

指导如何调试经过优化的二进制代码并解决 'value optimized out' 等问题。

  • 适用于发布版本 bug 定位,需选择 -Og 优化级别保留足够调试符号。
  • 利用 split-DWARF 技术加速大型项目的调试构建过程。
  • GDB 中需启用 inlined-frames 选项查看内联函数调用栈信息。
  • debug-optimized-builds 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Debugging Optimized Builds

Purpose

Guide agents through debugging code compiled with optimization: choosing the right debug-friendly optimization level, reading inlined frames, diagnosing "value optimized out", using split-DWARF for faster debug builds, and applying GDB techniques specific to optimized code.

Triggers

  • "GDB says 'value optimized out' — what does that mean?"
  • "How do I debug a release build?"
  • "How do I see inlined function frames in GDB?"
  • "What's the difference between -O0 and -Og for debugging?"
  • "How do I use RelWithDebInfo with CMake?"
  • "Breakpoints in optimized code land on wrong lines"

Workflow

1. Choose the right build configuration

Goal?
├── Full debuggability, no optimization
│   → -O0 -g                        (slowest, all vars visible)
├── Debuggable, some optimization (recommended for most dev work)
│   → -Og -g                        (-Og keeps debug experience good)
├── Release build with debug info (shipped, debuggable crashes)
│   → -O2 -g -gsplit-dwarf          (or -O2 -g1 for lighter info)
└── Full release (no debug symbols)
    → -O2 -DNDEBUG

-Og: GCC's "debug-friendly optimization" — enables optimizations that don't interfere with debugging. Variables stay in registers where GDB can see them. Line numbers stay accurate. Best balance for development.

# GCC / Clang
gcc -Og -g -Wall main.c -o prog

# CMake build types
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug          # -O0 -g
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo # -O2 -g -DNDEBUG
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release        # -O2 -DNDEBUG

2. "Value optimized out" — causes and workarounds

(gdb) print my_variable
$1 = <optimized out>

This means the compiler decided the variable's value doesn't need to be stored at this point — it might be:

  • Kept only in a register (not the one GDB is looking at)
  • Folded into a constant by constant propagation
  • Eliminated because it's not used after this point
  • Replaced by a later optimized value

Workarounds:

// 1. Mark variable volatile (prevents optimization away)
volatile int counter = 0;
// Use sparingly — changes semantics

// 2. Use GCC attribute
int counter __attribute__((used)) = 0;

// 3. Compile problematic TU at lower optimization
// In CMake:
set_source_files_properties(tricky.c PROPERTIES COMPILE_FLAGS "-O0")

// 4. Use -Og instead of -O2 for the whole build

// 5. Look at register values directly
// (gdb) info registers
// (gdb) p/x $rax       # value may be in a register

3. Reading inlined frames in GDB

With optimization, frequently-called small functions get inlined. GDB shows these as extra frames:

(gdb) bt
#0  process_packet (data=0x7ff..., len=<optimized out>)
    at network.c:45
#1  0x0000... in dispatch_handler (pkt=0x7ff...)
    at handler.c:102
#2  (inlined by) event_loop () at main.c:78
#3  0x0000... in main () at main.c:200

# (inlined by) frames are virtual — they show the call chain
# that was inlined into the actual frame above
# Navigate inlined frames
(gdb) frame 2          # jump to the inlined frame
(gdb) up               # move up through frames (including inlined)
(gdb) down             # move down

# Show all frames including inlined
(gdb) backtrace full

# Set breakpoint inside inlined function
(gdb) break network.c:45      # may hit multiple inlined call sites
(gdb) break process_packet    # hits all inline expansions

4. Line number discrepancies

Optimizers reorder instructions, so the "current line" in GDB may jump around:

# See which instructions map to which source lines
(gdb) disassemble /s function_name    # interleaved source and asm

# Step by machine instruction (more accurate in optimized code)
(gdb) si        # stepi — one machine instruction
(gdb) ni        # nexti — one machine instruction (no step into)

# Show mixed source/asm at current point
(gdb) layout split   # TUI mode: source + asm side by side
(gdb) set disassemble-next-line on

# Jump to specific address (when line stepping is unreliable)
(gdb) jump *0x400a2c

5. GDB scheduler-locking for optimized multithreaded code

With optimization, threads may race in unexpected ways when stepping:

# Lock the scheduler — only the current thread runs while stepping
(gdb) set scheduler-locking on

# Modes:
# off      — all threads run freely (default)
# on       — only current thread runs while stepping
# step     — only current thread runs while single-stepping
#            (all run on continue)
# replay   — for reverse debugging

# Common debugging session
(gdb) set scheduler-locking step    # prevent other threads interfering with step
(gdb) break my_function
(gdb) continue
(gdb) set scheduler-locking on     # lock while examining
(gdb) next
(gdb) set scheduler-locking off    # unlock to continue normally

6. split-DWARF — faster debug builds

Split DWARF offloads debug info to .dwo files, reducing linker input:

# Compile with split DWARF
gcc -g -gsplit-dwarf -O2 -c file.c -o file.o
# Creates: file.o (object) + file.dwo (DWARF sidecar)

# Link — no debug info in final binary, just references
gcc -g -gsplit-dwarf file.o -o prog

# GDB finds .dwo files via the path embedded in the binary
gdb prog    # works automatically if .dwo files are next to the binary

# Package all .dwo into a single .dwp for distribution
dwp -o prog.dwp prog    # GNU dwp tool
gdb prog    # with .dwp in same directory

# CMake
add_compile_options(-gsplit-dwarf)

7. Useful GDB commands for optimized builds

# Show where variables actually live (register vs stack)
(gdb) info locals           # all locals (may show <optimized out>)
(gdb) info args             # function arguments

# Force evaluation of an expression
(gdb) call (int)my_func(42)  # call actual function to get value

# Watch a memory address directly (not a variable name)
(gdb) watch *0x7fffffffe430

# Print memory contents
(gdb) x/10xw $rsp           # 10 words at stack pointer (hex)
(gdb) x/s 0x4008a0          # string at address

# Catch crashes without debug symbols
(gdb) bt             # backtrace — shows addresses even without symbols
(gdb) info sharedlibrary    # shows loaded libs for symbol resolution

# .gdbinit helpers for optimized debugging
# set print pretty on
# set print array on
# set disassembly-flavor intel

Related skills

  • Use skills/debuggers/gdb for full GDB session management
  • Use skills/debuggers/dwarf-debug-format for DWARF debug info details
  • Use skills/debuggers/core-dumps for post-mortem debugging of optimized crashes
  • Use skills/compilers/gcc for -Og, -g, and debug flag selection

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.08%
按下载量换算208

Claude

28.67%
按下载量换算175

Cursor

18.7%
按下载量换算114

Gemini CLI

10.16%
按下载量换算62

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills