aboutsummaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectSource.cpp
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2025-02-21 13:13:34 +0100
committerGitHub <noreply@github.com>2025-02-21 13:13:34 +0100
commit71af48fafdb6319da38ee7e5f04e16ff548fe57e (patch)
tree043c5dd8e875d3ed14410d6dd5701350a7941af1 /lldb/source/Commands/CommandObjectSource.cpp
parent8616c873350a2fd91c0c8028065daf8026ce515f (diff)
downloadllvm-71af48fafdb6319da38ee7e5f04e16ff548fe57e.zip
llvm-71af48fafdb6319da38ee7e5f04e16ff548fe57e.tar.gz
llvm-71af48fafdb6319da38ee7e5f04e16ff548fe57e.tar.bz2
[lldb] Fixing edge cases in "source list" (#126526)
While looking at how to make Function::GetEndLineSourceInfo (which is only used in "command source") work with discontinuous functions, I realized there are other corner cases that this function doesn't handle. The code assumed that the last line entry in the function will also correspond to the last source line. This is probably true for unoptimized code, but I don't think we can rely on the optimizer to preserve this property. What's worse, the code didn't check that the last line entry belonged to the same file as the first one, so if this line entry was the result of inlining, we could end up using a line from a completely different file. To fix this, I change the algorithm to iterate over all line entries in the function (which belong to the same file) and find the max line number out of those. This way we can naturally handle the discontinuous case as well. This implementation is going to be slower than the previous one, but I don't think that matters, because: - this command is only used rarely, and interactively - we have plenty of other code which iterates through the line table I added some basic tests for the function operation. I don't claim the tests to be comprehensive, or that the function handles all edge cases, but test framework created here could be used for testing other fixes/edge cases as well.
Diffstat (limited to 'lldb/source/Commands/CommandObjectSource.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectSource.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/lldb/source/Commands/CommandObjectSource.cpp b/lldb/source/Commands/CommandObjectSource.cpp
index 9367832..c205813 100644
--- a/lldb/source/Commands/CommandObjectSource.cpp
+++ b/lldb/source/Commands/CommandObjectSource.cpp
@@ -784,14 +784,14 @@ protected:
if (sc.block == nullptr) {
// Not an inlined function
- sc.function->GetStartLineSourceInfo(start_file, start_line);
- if (start_line == 0) {
- result.AppendErrorWithFormat("Could not find line information for "
- "start of function: \"%s\".\n",
- source_info.function.GetCString());
+ auto expected_info = sc.function->GetSourceInfo();
+ if (!expected_info) {
+ result.AppendError(llvm::toString(expected_info.takeError()));
return 0;
}
- sc.function->GetEndLineSourceInfo(end_file, end_line);
+ start_file = expected_info->first;
+ start_line = expected_info->second.GetRangeBase();
+ end_line = expected_info->second.GetRangeEnd();
} else {
// We have an inlined function
start_file = source_info.line_entry.file_sp;