debug-optimized-builds

Diagnose optimized C and C++ binaries with GDB commands and compiler flags.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/awfixers-stuff/opencode-config --skill debug-optimized-builds-awfixers-stuff
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: debug-optimized-builds
Source: https://github.com/awfixers-stuff/opencode-config/tree/main/skills/debug-optimized-builds
Command: npx skills add https://github.com/awfixers-stuff/opencode-config --skill debug-optimized-builds-awfixers-stuff

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Debugging code compiled with optimization often hides variables, reorders lines, inlines functions, and produces "<optimized out>" values that make breakpoints and backtraces confusing; this Skill guides engineers to reliable techniques for diagnosing and understanding program behavior in RelWithDebInfo, -Og, and -O2 builds.

Core Features & Use Cases

  • Choose proper build flags: recommendations for -Og, -O0, -g, -gsplit-dwarf and CMake build types to balance performance and debuggability.
  • Diagnose optimized variables and inlined frames: step-by-step GDB workflows to inspect registers, navigate inlined frames, and interpret "value optimized out".
  • Optimized multi-thread and packaging workflows: use scheduler-locking for single-thread stepping and split-DWARF (.dwo/.dwp) guidance for faster link and symbol distribution.
  • Use Case: when a crash in a RelWithDebInfo binary shows incomplete locals and inlined call chains, follow the Skill to pick flags, inspect registers, view mixed source/asm, and package debug info for post-mortem analysis.

Quick Start

Ask for step-by-step guidance to diagnose a "value optimized out" variable and to recommend compiler flags and GDB commands for a RelWithDebInfo build.

Frequently Asked Questions about debug-optimized-builds

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does GDB show <value optimized out> for variables in an optimized release build?

GDB shows <value optimized out> because compiler optimizations eliminate or relocate local variables into registers, discarding their debug location info. You can diagnose these missing variables by inspecting registers and using specific GDB commands to trace inlined frames.

How do I debug inlined frames and missing line numbers in a RelWithDebInfo binary?

Debugging inlined frames in a RelWithDebInfo binary requires navigating inlined call chains in GDB and viewing mixed source/assembly output to interpret line-number discrepancies caused by code reordering and function inlining.

What are the best compiler flags to balance performance and debuggability in C++?

The best compiler flags for debuggable optimized builds are -Og for optimized debugging, -g for symbols, and -gsplit-dwarf for faster linking. Use CMake RelWithDebInfo build type to balance performance and debuggability.

How do I use split-DWARF packaging for post-mortem crash analysis?

Use split-DWARF packaging to separate debug info into .dwo/.dwp files for faster linking and symbol distribution. This allows you to package and load debug symbols separately during post-mortem analysis of optimized binaries.

Can I step through a single thread in GDB without affecting other threads in an optimized build?

Yes, you can step through a single thread in GDB during optimized multi-thread debugging by using the scheduler-locking feature, which prevents other threads from executing while you inspect the target thread.

Does GDB support stepping through C and C++ binaries compiled with -O2?

Yes, GDB supports stepping through -O2 binaries, but expect confusing breakpoints and backtraces due to aggressive optimizations. You can diagnose behavior by inspecting registers and navigating inlined frames.