Author: Zax
Date: 2025-05-08T07:01:16-07:00
New Revision: b5674cb7be1b010be181883601a3674ceef38683

URL: 
https://github.com/llvm/llvm-project/commit/b5674cb7be1b010be181883601a3674ceef38683
DIFF: 
https://github.com/llvm/llvm-project/commit/b5674cb7be1b010be181883601a3674ceef38683.diff

LOG: [lldb] print a notice when `source list` paging reaches the end of th… 
(#137515)

Added: 
    lldb/test/Shell/Commands/command-list-reach-beginning-of-file.test
    lldb/test/Shell/Commands/command-list-reach-end-of-file.test

Modified: 
    lldb/include/lldb/Core/SourceManager.h
    lldb/source/Commands/CommandObjectSource.cpp
    lldb/source/Core/SourceManager.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/include/lldb/Core/SourceManager.h 
b/lldb/include/lldb/Core/SourceManager.h
index d929f7bd9bf22..1244291596b73 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 AtLastLine(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..8c87af590a372 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -1067,7 +1067,16 @@ class CommandObjectSourceList : public 
CommandObjectParsed {
                 &result.GetOutputStream(), m_options.num_lines,
                 m_options.reverse, GetBreakpointLocations())) {
           result.SetStatus(eReturnStatusSuccessFinishResult);
+        } else {
+          if (target.GetSourceManager().AtLastLine(m_options.reverse)) {
+            result.AppendNoteWithFormatv(
+                "Reached {0} of the file, no more to page",
+                m_options.reverse ? "beginning" : "end");
+          } 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..f786866a18137 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 (AtLastLine(reverse))
       return 0;
 
     if (count > 0)

diff  --git 
a/lldb/test/Shell/Commands/command-list-reach-beginning-of-file.test 
b/lldb/test/Shell/Commands/command-list-reach-beginning-of-file.test
new file mode 100644
index 0000000000000..5ca1b5c2306a7
--- /dev/null
+++ b/lldb/test/Shell/Commands/command-list-reach-beginning-of-file.test
@@ -0,0 +1,29 @@
+# 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: int main()
+
+list -10
+# CHECK: #include <assert.h>
+
+list -
+# CHECK: note: Reached beginning of the file, no more to page
+
+list -
+# CHECK: note: Reached beginning of the file, no more to page
+
+list
+# CHECK: int main()

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


        
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to