[Lldb-commits] [lldb] [lldb] print a notice when `source list` paging reaches the end of th… (PR #137515)

via lldb-commits lldb-commits at lists.llvm.org
Tue Apr 29 18:36:47 PDT 2025


https://github.com/hapeeeeee updated https://github.com/llvm/llvm-project/pull/137515

>From edd562c3dcaab5e6faee8392a431e517f4207d61 Mon Sep 17 00:00:00 2001
From: hapeeeeee <623151737 at qq.com>
Date: Sun, 27 Apr 2025 18:27:04 +0800
Subject: [PATCH] [lldb] print a notice when `source list` paging reaches the
 end of the file

---
 lldb/include/lldb/Core/SourceManager.h        |  3 +++
 lldb/source/Commands/CommandObjectSource.cpp  |  7 +++++
 lldb/source/Core/SourceManager.cpp            |  5 +---
 .../command-list-reach-end-of-file.test       | 26 +++++++++++++++++++
 4 files changed, 37 insertions(+), 4 deletions(-)
 create mode 100644 lldb/test/Shell/Commands/command-list-reach-end-of-file.test

diff --git a/lldb/include/lldb/Core/SourceManager.h b/lldb/include/lldb/Core/SourceManager.h
index d929f7bd9bf22..008f80fc7ac6f 100644
--- a/lldb/include/lldb/Core/SourceManager.h
+++ b/lldb/include/lldb/Core/SourceManager.h
@@ -155,6 +155,9 @@ class SourceManager {
   ~SourceManager();
 
   FileSP GetLastFile() { return GetFile(m_last_support_file_sp); }
+  bool AsLastLine(bool reverse) {
+    return m_last_line == UINT32_MAX || (reverse && m_last_line == 1);
+  }
 
   size_t DisplaySourceLinesWithLineNumbers(
       lldb::SupportFileSP support_file_sp, uint32_t line, uint32_t column,
diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp
index c205813565d52..b6692f3d8f553 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -1067,7 +1067,14 @@ class CommandObjectSourceList : public CommandObjectParsed {
                 &result.GetOutputStream(), m_options.num_lines,
                 m_options.reverse, GetBreakpointLocations())) {
           result.SetStatus(eReturnStatusSuccessFinishResult);
+        } else {
+          if (target.GetSourceManager().AsLastLine(m_options.reverse)) {
+            result.AppendNote("Reached end of the file, no more to page");
+          } else {
+            result.AppendNote("No source available");
+          }
         }
+
       } else {
         if (m_options.num_lines == 0)
           m_options.num_lines = 10;
diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp
index d63d42de14e80..8268a5d462ed8 100644
--- a/lldb/source/Core/SourceManager.cpp
+++ b/lldb/source/Core/SourceManager.cpp
@@ -360,10 +360,7 @@ size_t SourceManager::DisplayMoreWithLineNumbers(
     GetDefaultFileAndLine();
 
   if (last_file_sp) {
-    if (m_last_line == UINT32_MAX)
-      return 0;
-
-    if (reverse && m_last_line == 1)
+    if (AsLastLine(reverse))
       return 0;
 
     if (count > 0)
diff --git a/lldb/test/Shell/Commands/command-list-reach-end-of-file.test b/lldb/test/Shell/Commands/command-list-reach-end-of-file.test
new file mode 100644
index 0000000000000..c5e9c8169e7d9
--- /dev/null
+++ b/lldb/test/Shell/Commands/command-list-reach-end-of-file.test
@@ -0,0 +1,26 @@
+# RUN: %clang_host -g -O0 %S/Inputs/sigchld.c -o %t.out
+# RUN: %lldb %t.out -b -s %s 2>&1 | FileCheck %s
+
+list
+# CHECK: note: No source available 
+
+b main
+# CHECK: Breakpoint 1:
+
+r
+# CHECK: int main()
+
+list
+# CHECK: if (child_pid == 0)
+
+list
+# CHECK: printf("signo = %d\n", SIGCHLD);
+
+list
+# CHECK: return 0;
+
+list 
+# CHECK: note: Reached end of the file, no more to page
+
+list 
+# CHECK: note: Reached end of the file, no more to page
\ No newline at end of file



More information about the lldb-commits mailing list