[llvm] [llvm-dwarfdump] Added .debug_abbrev section for --output-style format (PR #227195)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 28 23:01:17 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-debuginfo
@llvm/pr-subscribers-llvm-binary-utilities
Author: arrowten
<details>
<summary>Changes</summary>
This PR adds support to `--output-style` format for the `.debug_abbrev` section.
---
Full diff: https://github.com/llvm/llvm-project/pull/227195.diff
3 Files Affected:
- (modified) llvm/docs/CommandGuide/llvm-dwarfdump.rst (+7)
- (added) llvm/test/tools/llvm-dwarfdump/output-style.test (+28)
- (modified) llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp (+32-1)
``````````diff
diff --git a/llvm/docs/CommandGuide/llvm-dwarfdump.rst b/llvm/docs/CommandGuide/llvm-dwarfdump.rst
index 22f2edfc30f57..fff1bede3dced 100644
--- a/llvm/docs/CommandGuide/llvm-dwarfdump.rst
+++ b/llvm/docs/CommandGuide/llvm-dwarfdump.rst
@@ -95,6 +95,13 @@ OPTIONS
Redirect output to a file specified by <path>, where `-` is the
standard output stream.
+.. option:: --output-style=<value>
+
+ Specify the format of the output. The supported values are:
+
+ `LLVM` - Output in the format used by llvm-dwarfdump. [default]
+ `JSON` - Output in JSON format.
+
.. option:: -p, --show-parents
Show a debug info entry's parents when selectively printing with
diff --git a/llvm/test/tools/llvm-dwarfdump/output-style.test b/llvm/test/tools/llvm-dwarfdump/output-style.test
new file mode 100644
index 0000000000000..27223f33333b0
--- /dev/null
+++ b/llvm/test/tools/llvm-dwarfdump/output-style.test
@@ -0,0 +1,28 @@
+## Show that --output-style=LLVM (the default) dumps normally.
+# RUN: yaml2obj %s -o %t.o
+# RUN: llvm-dwarfdump --output-style=LLVM %t.o | FileCheck %s --check-prefix=LLVM
+
+# LLVM: file format elf64-x86-64
+
+## Show that omitting --output-style is equivalent to passing --output-style=LLVM explicitly.
+# RUN: llvm-dwarfdump %t.o > %t.default.txt
+# RUN: llvm-dwarfdump --output-style=LLVM %t.o > %t.llvm.txt
+# RUN: cmp %t.default.txt %t.llvm.txt
+
+## Show that --output-style=JSON emits a warning, since JSON output is not yet implemented.
+# RUN: llvm-dwarfdump --output-style=JSON %t.o 2>&1 | FileCheck %s --check-prefix=JSON
+
+# JSON: file format elf64-x86-64
+# JSON-NEXT: warning: JSON output style is not yet implemented
+
+## Show that an unrecognized --output-style value is rejected.
+# RUN: not llvm-dwarfdump --output-style=YAML 2>&1 | FileCheck %s --check-prefix=INVALID
+
+# INVALID: error: --output-style value should be either 'LLVM' or 'JSON', but was 'YAML'
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
diff --git a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
index 4d7fc7e3108bf..b1260beac4845 100644
--- a/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
+++ b/llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp
@@ -16,6 +16,7 @@
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVectorExtras.h"
#include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/StringSwitch.h"
#include "llvm/DebugInfo/DIContext.h"
#include "llvm/DebugInfo/DWARF/DWARFAcceleratorTable.h"
#include "llvm/DebugInfo/DWARF/DWARFCompileUnit.h"
@@ -135,6 +136,8 @@ enum ErrorDetailLevel {
Unspecified
};
+enum class OutputStyleKind { LLVM, JSON, Unknown };
+
OptionCategory DwarfDumpCategory("Specific Options");
static list<std::string>
InputFilenames(Positional, desc("<input object files or .dSYM bundles>"),
@@ -334,6 +337,11 @@ static opt<bool> Verbose("verbose",
cat(DwarfDumpCategory));
static alias VerboseAlias("v", desc("Alias for --verbose."), aliasopt(Verbose),
cat(DwarfDumpCategory), cl::NotHidden);
+static opt<std::string>
+ OutputStyleOpt("output-style", init("LLVM"),
+ desc("Specify the format of the output (LLVM or JSON)"),
+ cat(DwarfDumpCategory));
+static OutputStyleKind Style = OutputStyleKind::LLVM;
static opt<bool>
ShowVariableCoverage("show-variable-coverage",
desc("Show per-variable coverage metrics."),
@@ -775,7 +783,19 @@ static bool dumpObjectFile(ObjectFile &Obj, DWARFContext &DICtx,
// Dump the complete DWARF structure.
auto DumpOpts = getDumpOpts(DICtx);
DumpOpts.GetNameForDWARFReg = GetRegName;
- DICtx.dump(OS, DumpOpts, DumpOffsets);
+ switch (Style) {
+ case OutputStyleKind::LLVM:
+ DICtx.dump(OS, DumpOpts, DumpOffsets);
+ break;
+ case OutputStyleKind::JSON:
+ WithColor::warning() << "JSON output style is not yet implemented\n";
+ break;
+ case OutputStyleKind::Unknown:
+ WithColor::error() << "--output-style value should be either 'LLVM' or "
+ "'JSON', but was '"
+ << OutputStyleOpt << "'\n";
+ return false;
+ }
return true;
}
@@ -889,6 +909,17 @@ int main(int argc, char **argv) {
"pretty-print DWARF debug information in object files"
" and debug info archives.\n");
+ Style = StringSwitch<OutputStyleKind>(OutputStyleOpt)
+ .Case("LLVM", OutputStyleKind::LLVM)
+ .Case("JSON", OutputStyleKind::JSON)
+ .Default(OutputStyleKind::Unknown);
+ if (Style == OutputStyleKind::Unknown) {
+ WithColor::error(errs(), sys::path::filename(argv[0]))
+ << "--output-style value should be either 'LLVM' or 'JSON', but was '"
+ << OutputStyleOpt << "'\n";
+ return 1;
+ }
+
// FIXME: Audit interactions between these two options and make them
// compatible.
if (Diff && Verbose) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/227195
More information about the llvm-commits
mailing list