-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[lldb] print a notice when source list
paging reaches the end of th…
#137515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-lldb Author: None (hapeeeeee) ChangesThis PR fixes the issue where the Full diff: https://github.com/llvm/llvm-project/pull/137515.diff 2 Files Affected:
diff --git a/lldb/source/Core/SourceManager.cpp b/lldb/source/Core/SourceManager.cpp
index d63d42de14e80..b57d8b3e20316 100644
--- a/lldb/source/Core/SourceManager.cpp
+++ b/lldb/source/Core/SourceManager.cpp
@@ -360,8 +360,11 @@ size_t SourceManager::DisplayMoreWithLineNumbers(
GetDefaultFileAndLine();
if (last_file_sp) {
- if (m_last_line == UINT32_MAX)
- return 0;
+ if (m_last_line == UINT32_MAX) {
+ Stream::ByteDelta delta(*s);
+ s->Printf("note: reached the end of current file, no more to page\n");
+ return *delta;
+ }
if (reverse && m_last_line == 1)
return 0;
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..61237ce4af542
--- /dev/null
+++ b/lldb/test/Shell/Commands/command-list-reach-end-of-file.test
@@ -0,0 +1,16 @@
+# RUN: %clang_host -g -O0 %S/Inputs/sigchld.c -o %t.out
+# RUN: %lldb %t.out -b -s %s | FileCheck %s
+
+b main
+r
+list
+# CHECK: assert (child_pid != -1);
+
+list
+# CHECK: printf("signo = %d\n", SIGCHLD);
+
+list
+# CHECK: return 0;
+
+list
+# CHECK: note: reached the end of current file, no more to page
|
It seems wrong to have the source manager pretend there are more lines in the file with the content "there are no more lines in this file". At some point, someone is going to want to know that there are no more lines and this artificial content will be confusing. It would be better to have the source manager return some kind of error and have the printer cons up the user-facing message. |
2d66140
to
cc39f34
Compare
I believe you are correct. I have updated the code so that the prompt output is now returned by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's better, but checking something the SourceManager calls the last line against UINT32_MAX seem to me too much implementation detail. I also can't see any other reason why m_last_line would be useful outside the SourceManager.
So maybe a better API would be
bool SourceManager::AtLastLine() { return m_last_line == UINT32_MAX; }
Then client code doesn't have to know how the SourceManager manages its paging through the source file.
Also, it would be good in your test to page twice past the end of the source buffer, not just once. That SHOULD just present the same error again, but it would be good to assert that it does.
cc39f34
to
edd562c
Compare
As you suggested, I’ve encapsulated the
I added a second Could you please review my commit again? @jimingham |
@@ -1067,7 +1067,14 @@ class CommandObjectSourceList : public CommandObjectParsed { | |||
&result.GetOutputStream(), m_options.num_lines, | |||
m_options.reverse, GetBreakpointLocations())) { | |||
result.SetStatus(eReturnStatusSuccessFinishResult); | |||
} else { | |||
if (target.GetSourceManager().AsLastLine(m_options.reverse)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you go in reverse and try to page past the beginning of the file we really shouldn't print "Reached the end to the file". Maybe:
result.AppendNoteWithFormat("Reached {0} of the file, no more to page", m_options.reverse ? "beginning" : "end");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you go in reverse and try to page past the beginning of the file we really shouldn't print "Reached the end to the file". Maybe:如果您反向操作并尝试翻页超过文件开头,我们真的不应该打印 "已到达文件末尾"。或许:
result.AppendNoteWithFormat("Reached {0} of the file, no more to page", m_options.reverse ? "beginning" : "end");result.AppendNoteWithFormat("已到达文件的第{0}处,没有更多可翻页", m_options.reverse ? "开始" : "结束");
I have already added different prompt messages based on reverse printing.
list | ||
# CHECK: note: Reached end of the file, no more to page | ||
|
||
list |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
edd562c
to
3c0bd90
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -155,6 +155,9 @@ class SourceManager { | |||
~SourceManager(); | |||
|
|||
FileSP GetLastFile() { return GetFile(m_last_support_file_sp); } | |||
bool AsLastLine(bool reverse) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a typo?
bool AsLastLine(bool reverse) { | |
bool AtLastLine(bool reverse) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a typo?
Yes, it is a mistake. I have fixed it. Could you please review my commit again? @JDevlieghere
3c0bd90
to
0d44818
Compare
Hi @JDevlieghere , I've corrected the typos. Could you please review my changes again? |
Hi @JDevlieghere @jinmingjian , all required checks have passed and the PR has received approvals. Would you mind helping merge this PR? Thanks! |
@hapeeeeee Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Added in #137515, as the source uses unistd.h which isn't present there. | C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Commands/Inputs/sigchld.c:4:10: fatal error: 'unistd.h' file not found | 4 | #include <unistd.h> | | ^~~~~~~~~~ | 1 error generated.
I've skipped the new tests on Windows because we don't have the headers the sigchld example uses. (no notification of the failure was sent because we were already failing some lldb-dap tests) |
Added in llvm/llvm-project#137515, as the source uses unistd.h which isn't present there. | C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\Shell\Commands/Inputs/sigchld.c:4:10: fatal error: 'unistd.h' file not found | 4 | #include <unistd.h> | | ^~~~~~~~~~ | 1 error generated.
The new tests are only applied to the command line, and they should be cross-platform. Maybe I should choose a more general source code for testing? |
That would be great if you can, there isn't one in that folder right now but you can find another elsewhere, or add a new file. I didn't want to go changing all the check lines myself in case I broke something. |
If I modified the test file, should I create a new PR to fix it? |
Yes please. |
This PR fixes the issue where the
list
command does not output a prompt when reaching the end of the file.Closes #128507.