Skip to content

Conversation

@jalopezg-git
Copy link
Contributor

@jalopezg-git jalopezg-git commented Jun 25, 2025

Add the =none and =id values for the --output-sort option. A couple of interesting observations below,

  • The output for --output-sort=id matches --output-sort=offset for the available readers. Tests were updated accordingly.
  • For --output-sort=none, and per LVReader::sortScopes(), LVScope::sort() is called on the root scope. LVScope::sort() has no effect if getSortFunction() == nullptr, and thus the elements are currently traversed in the order in which they were initially added.
    This is expected to change, however, in [llvm-debuginfo-analyzer] Remove LVScope::Children container #144750, when LVScope::Children is removed.

@llvmbot
Copy link
Member

llvmbot commented Jun 25, 2025

@llvm/pr-subscribers-debuginfo

Author: Javier Lopez-Gomez (jalopezg-git)

Changes

Add the --output-sort=none option. Per LVReader::sortScopes(),
LVScope::sort() is called on the root scope. LVScope::sort() has no
effect if getSortFunction() == nullptr, and thus the elements are traversed
in the order in which they were initially created.

For the available readers, this matches --output-sort=offset. Tests were
updated accordingly.


Full diff: https://github.com/llvm/llvm-project/pull/145761.diff

5 Files Affected:

  • (modified) llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst (+1)
  • (modified) llvm/test/tools/llvm-debuginfo-analyzer/COFF/01-coff-print-basic-details.test (+9)
  • (modified) llvm/test/tools/llvm-debuginfo-analyzer/DWARF/01-dwarf-print-basic-details.test (+9)
  • (modified) llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test (+1)
  • (modified) llvm/tools/llvm-debuginfo-analyzer/Options.cpp (+3-1)
diff --git a/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst b/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst
index 1264f80206618..3d9b53c2c5a0d 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/COFF/01-coff-print-basic-details.test b/llvm/test/tools/llvm-debuginfo-analyzer/COFF/01-coff-print-basic-details.test
index be2085a187eb9..763d31ec54754 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,15 @@
 ; RUN:                         %p/Inputs/test-codeview-clang.o 2>&1 | \
 ; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s
 
+; If `--output-sort=none`, LVReader::sortScopes() has no effect and 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=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 \
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 54dbd7466e4f6..4b17f1d6063d4 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,15 @@
 ; RUN:                         %p/Inputs/test-dwarf-clang.o 2>&1 | \
 ; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s
 
+; If `--output-sort=none`, LVReader::sortScopes() has no effect and 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=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 \
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.")),

@llvmbot
Copy link
Member

llvmbot commented Jun 25, 2025

@llvm/pr-subscribers-llvm-binary-utilities

Author: Javier Lopez-Gomez (jalopezg-git)

Changes

Add the --output-sort=none option. Per LVReader::sortScopes(),
LVScope::sort() is called on the root scope. LVScope::sort() has no
effect if getSortFunction() == nullptr, and thus the elements are traversed
in the order in which they were initially created.

For the available readers, this matches --output-sort=offset. Tests were
updated accordingly.


Full diff: https://github.com/llvm/llvm-project/pull/145761.diff

5 Files Affected:

  • (modified) llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst (+1)
  • (modified) llvm/test/tools/llvm-debuginfo-analyzer/COFF/01-coff-print-basic-details.test (+9)
  • (modified) llvm/test/tools/llvm-debuginfo-analyzer/DWARF/01-dwarf-print-basic-details.test (+9)
  • (modified) llvm/test/tools/llvm-debuginfo-analyzer/cmdline.test (+1)
  • (modified) llvm/tools/llvm-debuginfo-analyzer/Options.cpp (+3-1)
diff --git a/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst b/llvm/docs/CommandGuide/llvm-debuginfo-analyzer.rst
index 1264f80206618..3d9b53c2c5a0d 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/COFF/01-coff-print-basic-details.test b/llvm/test/tools/llvm-debuginfo-analyzer/COFF/01-coff-print-basic-details.test
index be2085a187eb9..763d31ec54754 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,15 @@
 ; RUN:                         %p/Inputs/test-codeview-clang.o 2>&1 | \
 ; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s
 
+; If `--output-sort=none`, LVReader::sortScopes() has no effect and 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=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 \
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 54dbd7466e4f6..4b17f1d6063d4 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,15 @@
 ; RUN:                         %p/Inputs/test-dwarf-clang.o 2>&1 | \
 ; RUN: FileCheck --strict-whitespace -check-prefix=ONE %s
 
+; If `--output-sort=none`, LVReader::sortScopes() has no effect and 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=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 \
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.")),

@jalopezg-git jalopezg-git requested a review from OCHyams June 25, 2025 18:42
@jalopezg-git jalopezg-git force-pushed the jalopezg-logicalview-outputsort_none branch 2 times, most recently from fe5f200 to 1698198 Compare September 16, 2025 15:30
@jalopezg-git jalopezg-git changed the title [llvm-debuginfo-analyzer] Add --output-sort=none option [llvm-debuginfo-analyzer] Add --output-sort=(none|id) option Sep 16, 2025
@jalopezg-git
Copy link
Contributor Author

@CarlosAlbertoEnciso, this PR has been updated w/ the requested changes (i.e., support for =none and =id for --output-sort). PR description has been updated; PTAL.

This pull request is now ready for review 👍.

@jalopezg-git jalopezg-git force-pushed the jalopezg-logicalview-outputsort_none branch 3 times, most recently from 9d7508d to 690e92d Compare September 16, 2025 18:05
@jalopezg-git jalopezg-git force-pushed the jalopezg-logicalview-outputsort_none branch from 690e92d to 1fd22c9 Compare September 16, 2025 23:47
@jalopezg-git
Copy link
Contributor Author

@OCHyams CCing you, just in case you want to also have a look 🙂!

Copy link
Member

@CarlosAlbertoEnciso CarlosAlbertoEnciso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good. LGTM.

@jalopezg-git
Copy link
Contributor Author

Thanks for the review, @CarlosAlbertoEnciso!

@jalopezg-git jalopezg-git merged commit 4d197c8 into llvm:main Sep 19, 2025
10 checks passed
@jalopezg-git jalopezg-git deleted the jalopezg-logicalview-outputsort_none branch September 19, 2025 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants