Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ 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.
Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/DebugInfo/LogicalView/Core/LVSort.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions llvm/lib/DebugInfo/LogicalView/Core/LVSort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@
; 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

; If `--output-sort=none`, `LVScope::Children` is not sorted; it, however,
; reflects the order in which elements were added (same as `--output-sort=id`).
; This is expected to change once #69160 is resolved though.
; RUN: llvm-debuginfo-analyzer --attribute=level,format \
; RUN: --output-sort=none \
; 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 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@
; 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

; If `--output-sort=none`, `LVScope::Children` is not sorted; it, however,
; reflects the order in which elements were added (same as `--output-sort=id`).
; This is expected to change once #69160 is resolved though.
; RUN: llvm-debuginfo-analyzer --attribute=level,format \
; RUN: --output-sort=none \
; 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 \
Expand Down
2 changes: 2 additions & 0 deletions llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ 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: =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.
Expand Down
5 changes: 4 additions & 1 deletion llvm/tools/llvm-debuginfo-analyzer/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ 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::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."),
clEnumValN(LVSortMode::Offset, "offset", "Sort by element offset.")),
Expand Down