[llvm] [llvm-debuginfo-analyzer] Add `--output-sort=(none|id)` option (PR #145761)
Javier Lopez-Gomez via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 16 08:55:05 PDT 2025
https://github.com/jalopezg-git updated https://github.com/llvm/llvm-project/pull/145761
>From 013a0970fe7888fabde3e1eb4716dd03d4072900 Mon Sep 17 00:00:00 2001
From: Graham Hunter <graham.hunter at arm.com>
Date: Tue, 16 Sep 2025 17:54:51 +0200
Subject: [PATCH 1/2] [NFC][LV] Improve ee with sideeffects legality test
(#158275)
Addressing postcommit comments for
54fc5367f63cca8e011d93bbd55764b0a7ecbbd5
---
llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst | 1 +
llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test | 1 +
llvm/tools/llvm-debuginfo-analyzer/Options.cpp | 4 +++-
3 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst b/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst
index 6a4e3483811d8..941e1f361d675 100644
--- a/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst
+++ b/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst
@@ -365,6 +365,7 @@ output for a single compilation unit.
.. code-block:: text
+ =none: Unsorted output (i.e. as read from input).
=kind: Sort by element kind.
=line: Sort by element line number.
=name: Sort by element name.
diff --git a/llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test b/llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test
index 7763426142476..97f0c35913830 100644
--- a/llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test
+++ b/llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test
@@ -110,6 +110,7 @@ HELP-ALL: --output-file=<filename> - Redirect output to the specified file.
HELP-ALL: --output-folder=<pathname> - Folder name for view splitting.
HELP-ALL: --output-level=<N> - Only print to a depth of N elements.
HELP-ALL: --output-sort=<value> - Primary key when ordering logical view (default: line).
+HELP-ALL: =none - Unsorted output (i.e. as read from input).
HELP-ALL: =kind - Sort by element kind.
HELP-ALL: =line - Sort by element line number.
HELP-ALL: =name - Sort by element name.
diff --git a/llvm/tools/llvm-debuginfo-analyzer/Options.cpp b/llvm/tools/llvm-debuginfo-analyzer/Options.cpp
index 79e2edccc50b8..b7e337bc21c61 100644
--- a/llvm/tools/llvm-debuginfo-analyzer/Options.cpp
+++ b/llvm/tools/llvm-debuginfo-analyzer/Options.cpp
@@ -198,7 +198,9 @@ static cl::opt<LVSortMode, true> OutputSort(
"output-sort", cl::cat(OutputCategory),
cl::desc("Primary key when ordering logical view (default: line)."),
cl::Hidden, cl::ZeroOrMore,
- values(clEnumValN(LVSortMode::Kind, "kind", "Sort by element kind."),
+ values(clEnumValN(LVSortMode::None, "none",
+ "Unsorted output (i.e. as read from input)."),
+ clEnumValN(LVSortMode::Kind, "kind", "Sort by element kind."),
clEnumValN(LVSortMode::Line, "line", "Sort by element line number."),
clEnumValN(LVSortMode::Name, "name", "Sort by element name."),
clEnumValN(LVSortMode::Offset, "offset", "Sort by element offset.")),
>From 9d7508dcb253ace08034bd756b0b253867c6df9d Mon Sep 17 00:00:00 2001
From: Javier Lopez-Gomez <javier.lopez.gomez at proton.me>
Date: Tue, 16 Sep 2025 17:54:51 +0200
Subject: [PATCH 2/2] [llvm-debuginfo-analyzer] Add `--output-sort=id` option
---
llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst | 1 +
.../include/llvm/DebugInfo/LogicalView/Core/LVSort.h | 2 ++
llvm/lib/DebugInfo/LogicalView/Core/LVSort.cpp | 12 +++++++++---
.../COFF/01-coff-print-basic-details.test | 8 ++++++++
.../DWARF/01-dwarf-print-basic-details.test | 8 ++++++++
llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test | 1 +
llvm/tools/llvm-debuginfo-analyzer/Options.cpp | 1 +
7 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst b/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst
index 941e1f361d675..6fcf8423e8125 100644
--- a/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst
+++ b/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst
@@ -366,6 +366,7 @@ output for a single compilation unit.
.. code-block:: text
=none: Unsorted output (i.e. as read from input).
+ =id: Sort by unique element ID.
=kind: Sort by element kind.
=line: Sort by element line number.
=name: Sort by element name.
diff --git a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSort.h b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSort.h
index c8c7310281566..72224e61e41db 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSort.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Core/LVSort.h
@@ -23,6 +23,7 @@ class LVObject;
// Object Sorting Mode.
enum class LVSortMode {
None = 0, // No given sort.
+ ID, // Sort by ID.
Kind, // Sort by kind.
Line, // Sort by line.
Name, // Sort by name.
@@ -38,6 +39,7 @@ using LVSortFunction = LVSortValue (*)(const LVObject *LHS,
LLVM_ABI LVSortFunction getSortFunction();
// Comparator functions that can be used for sorting.
+LLVM_ABI LVSortValue compareID(const LVObject *LHS, const LVObject *RHS);
LLVM_ABI LVSortValue compareKind(const LVObject *LHS, const LVObject *RHS);
LLVM_ABI LVSortValue compareLine(const LVObject *LHS, const LVObject *RHS);
LLVM_ABI LVSortValue compareName(const LVObject *LHS, const LVObject *RHS);
diff --git a/llvm/lib/DebugInfo/LogicalView/Core/LVSort.cpp b/llvm/lib/DebugInfo/LogicalView/Core/LVSort.cpp
index a58ba4b3cdfbf..93bb11205f554 100644
--- a/llvm/lib/DebugInfo/LogicalView/Core/LVSort.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/Core/LVSort.cpp
@@ -22,6 +22,12 @@ using namespace llvm::logicalview;
//===----------------------------------------------------------------------===//
// Callback functions to sort objects.
//===----------------------------------------------------------------------===//
+// Callback comparator based on ID.
+LVSortValue llvm::logicalview::compareID(const LVObject *LHS,
+ const LVObject *RHS) {
+ return LHS->getID() < RHS->getID();
+}
+
// Callback comparator based on kind.
LVSortValue llvm::logicalview::compareKind(const LVObject *LHS,
const LVObject *RHS) {
@@ -99,9 +105,9 @@ LVSortValue llvm::logicalview::sortByName(const LVObject *LHS,
LVSortFunction llvm::logicalview::getSortFunction() {
using LVSortInfo = std::map<LVSortMode, LVSortFunction>;
static LVSortInfo SortInfo = {
- {LVSortMode::None, nullptr}, {LVSortMode::Kind, sortByKind},
- {LVSortMode::Line, sortByLine}, {LVSortMode::Name, sortByName},
- {LVSortMode::Offset, compareOffset},
+ {LVSortMode::None, nullptr}, {LVSortMode::ID, compareID},
+ {LVSortMode::Kind, sortByKind}, {LVSortMode::Line, sortByLine},
+ {LVSortMode::Name, sortByName}, {LVSortMode::Offset, compareOffset},
};
LVSortFunction SortFunction = nullptr;
diff --git a/llvm/test/tools/llvm-debuginfo-analyzer/COFF/01-coff-print-basic-details.test b/llvm/test/tools/llvm-debuginfo-analyzer/COFF/01-coff-print-basic-details.test
index be2085a187eb9..ee977c17ae065 100644
--- a/llvm/test/tools/llvm-debuginfo-analyzer/COFF/01-coff-print-basic-details.test
+++ b/llvm/test/tools/llvm-debuginfo-analyzer/COFF/01-coff-print-basic-details.test
@@ -24,6 +24,14 @@
; RUN: %p/Inputs/test-codeview-clang.o 2>&1 | \
; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s
+; If `--output-sort=id`, elements are iterated in the order in which they were
+; added (which matches the increasing offset of the reference output).
+; RUN: llvm-debuginfo-analyzer --attribute=level,format \
+; RUN: --output-sort=id \
+; RUN: --print=scopes,symbols,types,lines,instructions \
+; RUN: %p/Inputs/test-codeview-clang.o 2>&1 | \
+; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s
+
; RUN: llvm-debuginfo-analyzer --attribute=level,format \
; RUN: --output-sort=offset \
; RUN: --print=elements \
diff --git a/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/01-dwarf-print-basic-details.test b/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/01-dwarf-print-basic-details.test
index 6d767eb9e883a..22434a88083da 100644
--- a/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/01-dwarf-print-basic-details.test
+++ b/llvm/test/tools/llvm-debuginfo-analyzer/DWARF/01-dwarf-print-basic-details.test
@@ -24,6 +24,14 @@
; RUN: %p/Inputs/test-dwarf-clang.o 2>&1 | \
; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s
+; If `--output-sort=id`, elements are iterated in the order in which they
+; were added (which matches the increasing offset of the reference output).
+; RUN: llvm-debuginfo-analyzer --attribute=level,format \
+; RUN: --output-sort=id \
+; RUN: --print=scopes,symbols,types,lines,instructions \
+; RUN: %p/Inputs/test-dwarf-clang.o 2>&1 | \
+; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s
+
; RUN: llvm-debuginfo-analyzer --attribute=level,format \
; RUN: --output-sort=offset \
; RUN: --print=elements \
diff --git a/llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test b/llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test
index 97f0c35913830..1b5c189f72e4c 100644
--- a/llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test
+++ b/llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test
@@ -111,6 +111,7 @@ HELP-ALL: --output-folder=<pathname> - Folder name for view splitting.
HELP-ALL: --output-level=<N> - Only print to a depth of N elements.
HELP-ALL: --output-sort=<value> - Primary key when ordering logical view (default: line).
HELP-ALL: =none - Unsorted output (i.e. as read from input).
+HELP-ALL: =id - Sort by unique element ID.
HELP-ALL: =kind - Sort by element kind.
HELP-ALL: =line - Sort by element line number.
HELP-ALL: =name - Sort by element name.
diff --git a/llvm/tools/llvm-debuginfo-analyzer/Options.cpp b/llvm/tools/llvm-debuginfo-analyzer/Options.cpp
index b7e337bc21c61..3d1373896f234 100644
--- a/llvm/tools/llvm-debuginfo-analyzer/Options.cpp
+++ b/llvm/tools/llvm-debuginfo-analyzer/Options.cpp
@@ -200,6 +200,7 @@ static cl::opt<LVSortMode, true> OutputSort(
cl::Hidden, cl::ZeroOrMore,
values(clEnumValN(LVSortMode::None, "none",
"Unsorted output (i.e. as read from input)."),
+ clEnumValN(LVSortMode::ID, "id", "Sort by unique element ID."),
clEnumValN(LVSortMode::Kind, "kind", "Sort by element kind."),
clEnumValN(LVSortMode::Line, "line", "Sort by element line number."),
clEnumValN(LVSortMode::Name, "name", "Sort by element name."),
More information about the llvm-commits
mailing list