Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lldb/include/lldb/Core/SourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions lldb/source/Commands/CommandObjectSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions lldb/source/Core/SourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
26 changes: 26 additions & 0 deletions lldb/test/Shell/Commands/command-list-reach-end-of-file.test
Original file line number Diff line number Diff line change
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's good. There should also be a test for scrolling past the beginning of the file in reverse, since you added a good behavior for that.

Copy link
Contributor Author

@hapeeeeee hapeeeeee May 1, 2025

Choose a reason for hiding this comment

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

I added a test file command-list-reach-beginning-of-file.test for when the beginning of the file is reached, and ran the test twice, getting expected result both times.

# CHECK: note: Reached end of the file, no more to page
Loading