https://github.com/hapeeeeee updated https://github.com/llvm/llvm-project/pull/137515
>From 0d448180a569fa3730f3608a1584de24cf832c88 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 | 3 ++ lldb/source/Commands/CommandObjectSource.cpp | 9 ++++++ lldb/source/Core/SourceManager.cpp | 5 +--- .../command-list-reach-beginning-of-file.test | 29 +++++++++++++++++++ .../command-list-reach-end-of-file.test | 26 +++++++++++++++++ 5 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 lldb/test/Shell/Commands/command-list-reach-beginning-of-file.test 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..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