dwarf-expert

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Overview

概述

This skill provides technical knowledge and expertise about the DWARF standard and how to interact with DWARF files. Tasks include answering questions about the DWARF standard, providing examples of various DWARF features, parsing and/or creating DWARF files, and writing/modifying/analyzing code that interacts with DWARF data.
本技能提供关于DWARF标准以及如何操作DWARF文件的技术知识与专业能力。涵盖的任务包括解答DWARF标准相关问题、提供各类DWARF特性示例、解析和/或创建DWARF文件,以及编写/修改/分析与DWARF数据交互的代码。

When to Use This Skill

适用场景

  • Understanding or parsing DWARF debug information from compiled binaries
  • Answering questions about the DWARF standard (v3, v4, v5)
  • Writing or reviewing code that interacts with DWARF data
  • Using
    dwarfdump
    or
    readelf
    to extract debug information
  • Verifying DWARF data integrity with
    llvm-dwarfdump --verify
  • Working with DWARF parsing libraries (libdwarf, pyelftools, gimli, etc.)
  • 理解或解析编译后二进制文件中的DWARF调试信息
  • 解答DWARF标准(v3、v4、v5)相关问题
  • 编写或审查与DWARF数据交互的代码
  • 使用
    dwarfdump
    readelf
    提取调试信息
  • 使用
    llvm-dwarfdump --verify
    验证DWARF数据完整性
  • 使用DWARF解析库(libdwarf、pyelftools、gimli等)

When NOT to Use This Skill

不适用场景

  • DWARF v1/v2 Analysis: Expertise limited to versions 3, 4, and 5.
  • General ELF Parsing: Use standard ELF tools if DWARF data isn't needed.
  • Executable Debugging: Use dedicated debugging tools (gdb, lldb, etc) for debugging executable code/runtime behavior.
  • Binary Reverse Engineering: Use dedicated RE tools (Ghidra, IDA) unless specifically analyzing DWARF sections.
  • Compiler Debugging: DWARF generation issues are compiler-specific, not covered here.
  • DWARF v1/v2分析:仅支持版本3、4和5的相关能力。
  • 通用ELF解析:若无需DWARF数据,请使用标准ELF工具。
  • 可执行程序调试:使用专用调试工具(gdb、lldb等)调试可执行代码/运行时行为。
  • 二进制逆向工程:除非专门分析DWARF段,否则使用专用逆向工程工具(Ghidra、IDA)。
  • 编译器调试:DWARF生成问题属于编译器特定问题,不在本技能覆盖范围内。

Authoritative Sources

权威资料

When specific DWARF standard information is needed, use these authoritative sources:
  1. Official DWARF Standards (dwarfstd.org): Use web search to find specific sections of the official DWARF specification at dwarfstd.org. Search queries like "DWARF5 DW_TAG_subprogram attributes site:dwarfstd.org" are effective.
  2. LLVM DWARF Implementation: The LLVM project's DWARF handling code at
    llvm/lib/DebugInfo/DWARF/
    serves as a reliable reference implementation. Key files include:
    • DWARFDie.cpp
      - DIE handling and attribute access
    • DWARFUnit.cpp
      - Compilation unit parsing
    • DWARFDebugLine.cpp
      - Line number information
    • DWARFVerifier.cpp
      - Validation logic
  3. libdwarf: The reference C implementation at github.com/davea42/libdwarf-code provides detailed handling of DWARF data structures.
当需要特定DWARF标准信息时,请使用以下权威来源:
  1. 官方DWARF Standards (dwarfstd.org):通过网页搜索在dwarfstd.org上查找官方DWARF规范的特定章节。例如使用「DWARF5 DW_TAG_subprogram attributes site:dwarfstd.org」这类搜索词会很有效。
  2. LLVM DWARF实现:LLVM项目中处理DWARF的代码位于
    llvm/lib/DebugInfo/DWARF/
    ,是可靠的参考实现。关键文件包括:
    • DWARFDie.cpp
      - DIE处理与属性访问
    • DWARFUnit.cpp
      - 编译单元解析
    • DWARFDebugLine.cpp
      - 行号信息
    • DWARFVerifier.cpp
      - 验证逻辑
  3. libdwarf:位于github.com/davea42/libdwarf-code的C语言参考实现,提供了对DWARF数据结构的详细处理方式。

Verification Workflows

验证工作流

Use
llvm-dwarfdump
verification options to validate DWARF data integrity:
使用
llvm-dwarfdump
的验证选项来校验DWARF数据的完整性:

Structural Validation

结构验证

bash
undefined
bash
undefined

Verify DWARF structure (compile units, DIE relationships, address ranges)

验证DWARF结构(编译单元、DIE关系、地址范围)

llvm-dwarfdump --verify <binary>
llvm-dwarfdump --verify <binary>

Detailed error output with summary

带摘要的详细错误输出

llvm-dwarfdump --verify --error-display=full <binary>
llvm-dwarfdump --verify --error-display=full <binary>

Machine-readable JSON error summary

机器可读的JSON错误摘要

llvm-dwarfdump --verify --verify-json=errors.json <binary>
undefined
llvm-dwarfdump --verify --verify-json=errors.json <binary>
undefined

Quality Metrics

质量指标

bash
undefined
bash
undefined

Output debug info quality metrics as JSON

以JSON格式输出调试信息质量指标

llvm-dwarfdump --statistics <binary>

The `--statistics` output helps compare debug info quality across compiler versions and optimization levels.
llvm-dwarfdump --statistics <binary>

`--statistics`输出可用于比较不同编译器版本和优化级别下的调试信息质量。

Common Verification Patterns

常见验证场景

  • After compilation: Verify binaries have valid DWARF before distribution
  • Comparing builds: Use
    --statistics
    to detect debug info quality regressions
  • Debugging debuggers: Identify malformed DWARF causing debugger issues
  • DWARF tool development: Validate parser output against known-good binaries
  • 编译后:在分发二进制文件前验证其包含有效的DWARF数据
  • 构建对比:使用
    --statistics
    检测调试信息质量的退化
  • 调试器调试:识别导致调试器问题的畸形DWARF数据
  • DWARF工具开发:将解析器输出与已知正确的二进制文件进行对比验证

Parsing DWARF Debug Information

解析DWARF调试信息

readelf

readelf

ELF files can be parsed via the
readelf
command ({baseDir}/reference/readelf.md). Use this for general ELF information, but prefer
dwarfdump
for DWARF-specific parsing.
可通过
readelf
命令解析ELF文件({baseDir}/reference/readelf.md)。该工具适用于获取通用ELF信息,但针对DWARF特定解析,建议优先使用
dwarfdump

dwarfdump

dwarfdump

DWARF files can be parsed via the
dwarfdump
command, which is more effective at parsing and displaying complex DWARF information than
readelf
and should be used for most DWARF parsing tasks ({baseDir}/reference/dwarfdump.md).
可通过
dwarfdump
命令解析DWARF文件,该工具在解析和展示复杂DWARF信息方面比
readelf
更高效,大多数DWARF解析任务都应使用它({baseDir}/reference/dwarfdump.md)。

Working With Code

代码处理

This skill supports writing, modifying, and reviewing code that interacts with DWARF data. This may involve code that parses DWARF debug data from scratch or code that leverages libraries to parse and interact with DWARF data ({baseDir}/reference/coding.md).
本技能支持编写、修改和审查与DWARF数据交互的代码,包括从零开始解析DWARF调试数据的代码,以及借助库来解析和交互DWARF数据的代码({baseDir}/reference/coding.md)。

Choosing Your Approach

方法选择

┌─ Need to verify DWARF data integrity?
│   └─ Use `llvm-dwarfdump --verify` (see Verification Workflows above)
├─ Need to answer questions about the DWARF standard?
│   └─ Search dwarfstd.org or reference LLVM/libdwarf source
├─ Need simple section dump or general ELF info?
│   └─ Use `readelf` ({baseDir}/reference/readelf.md)
├─ Need to parse, search, and/or dump DWARF DIE nodes?
│   └─ Use `dwarfdump` ({baseDir}/reference/dwarfdump.md)
└─ Need to write, modify, or review code that interacts with DWARF data?
    └─ Refer to the coding reference ({baseDir}/reference/coding.md)
┌─ 需要验证DWARF数据完整性?
│   └─ 使用`llvm-dwarfdump --verify`(参见上方的验证工作流)
├─ 需要解答DWARF标准相关问题?
│   └─ 搜索dwarfstd.org或参考LLVM/libdwarf源码
├─ 需要简单的段导出或通用ELF信息?
│   └─ 使用`readelf`({baseDir}/reference/readelf.md)
├─ 需要解析、搜索和/或导出DWARF DIE节点?
│   └─ 使用`dwarfdump`({baseDir}/reference/dwarfdump.md)
└─ 需要编写、修改或审查与DWARF数据交互的代码?
    └─ 参考编码指南({baseDir}/reference/coding.md)