Skip to content

Commit b5674cb

Browse files
authored
[lldb] print a notice when source list paging reaches the end of th… (#137515)
1 parent 7eafa5b commit b5674cb

File tree

5 files changed

+68
-4
lines changed

5 files changed

+68
-4
lines changed

lldb/include/lldb/Core/SourceManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ class SourceManager {
155155
~SourceManager();
156156

157157
FileSP GetLastFile() { return GetFile(m_last_support_file_sp); }
158+
bool AtLastLine(bool reverse) {
159+
return m_last_line == UINT32_MAX || (reverse && m_last_line == 1);
160+
}
158161

159162
size_t DisplaySourceLinesWithLineNumbers(
160163
lldb::SupportFileSP support_file_sp, uint32_t line, uint32_t column,

lldb/source/Commands/CommandObjectSource.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,7 +1067,16 @@ class CommandObjectSourceList : public CommandObjectParsed {
10671067
&result.GetOutputStream(), m_options.num_lines,
10681068
m_options.reverse, GetBreakpointLocations())) {
10691069
result.SetStatus(eReturnStatusSuccessFinishResult);
1070+
} else {
1071+
if (target.GetSourceManager().AtLastLine(m_options.reverse)) {
1072+
result.AppendNoteWithFormatv(
1073+
"Reached {0} of the file, no more to page",
1074+
m_options.reverse ? "beginning" : "end");
1075+
} else {
1076+
result.AppendNote("No source available");
1077+
}
10701078
}
1079+
10711080
} else {
10721081
if (m_options.num_lines == 0)
10731082
m_options.num_lines = 10;

lldb/source/Core/SourceManager.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,7 @@ size_t SourceManager::DisplayMoreWithLineNumbers(
360360
GetDefaultFileAndLine();
361361

362362
if (last_file_sp) {
363-
if (m_last_line == UINT32_MAX)
364-
return 0;
365-
366-
if (reverse && m_last_line == 1)
363+
if (AtLastLine(reverse))
367364
return 0;
368365

369366
if (count > 0)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# RUN: %clang_host -g -O0 %S/Inputs/sigchld.c -o %t.out
2+
# RUN: %lldb %t.out -b -s %s 2>&1 | FileCheck %s
3+
4+
list
5+
# CHECK: note: No source available
6+
7+
b main
8+
# CHECK: Breakpoint 1:
9+
10+
r
11+
# CHECK: int main()
12+
13+
list
14+
# CHECK: if (child_pid == 0)
15+
16+
list -
17+
# CHECK: int main()
18+
19+
list -10
20+
# CHECK: #include <assert.h>
21+
22+
list -
23+
# CHECK: note: Reached beginning of the file, no more to page
24+
25+
list -
26+
# CHECK: note: Reached beginning of the file, no more to page
27+
28+
list
29+
# CHECK: int main()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# RUN: %clang_host -g -O0 %S/Inputs/sigchld.c -o %t.out
2+
# RUN: %lldb %t.out -b -s %s 2>&1 | FileCheck %s
3+
4+
list
5+
# CHECK: note: No source available
6+
7+
b main
8+
# CHECK: Breakpoint 1:
9+
10+
r
11+
# CHECK: int main()
12+
13+
list
14+
# CHECK: if (child_pid == 0)
15+
16+
list
17+
# CHECK: printf("signo = %d\n", SIGCHLD);
18+
19+
list
20+
# CHECK: return 0;
21+
22+
list
23+
# CHECK: note: Reached end of the file, no more to page
24+
25+
list
26+
# CHECK: note: Reached end of the file, no more to page

0 commit comments

Comments
 (0)