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

>From cc39f344a5284c16e2b446cde796681f1daa2888 Mon Sep 17 00:00:00 2001
From: hapeeeeee <623151...@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        |  1 +
 lldb/source/Commands/CommandObjectSource.cpp  |  9 ++++++++
 .../command-list-reach-end-of-file.test       | 23 +++++++++++++++++++
 3 files changed, 33 insertions(+)
 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..8645bd04aae70 100644
--- a/lldb/include/lldb/Core/SourceManager.h
+++ b/lldb/include/lldb/Core/SourceManager.h
@@ -155,6 +155,7 @@ class SourceManager {
   ~SourceManager();
 
   FileSP GetLastFile() { return GetFile(m_last_support_file_sp); }
+  uint32_t GetLastLine() { return m_last_line; }
 
   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..ec509ed2f6dc9 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 {
+          uint32_t last_line = target.GetSourceManager().GetLastLine();
+          if (last_line == UINT32_MAX ||
+              (last_line == 1 && 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/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..2859f9b8b59a1
--- /dev/null
+++ b/lldb/test/Shell/Commands/command-list-reach-end-of-file.test
@@ -0,0 +1,23 @@
+# 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
\ 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