[all-commits] [llvm/llvm-project] 71af48: [lldb] Fixing edge cases in "source list" (#126526)

Pavel Labath via All-commits all-commits at lists.llvm.org
Fri Feb 21 04:13:58 PST 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 71af48fafdb6319da38ee7e5f04e16ff548fe57e
      https://github.com/llvm/llvm-project/commit/71af48fafdb6319da38ee7e5f04e16ff548fe57e
  Author: Pavel Labath <pavel at labath.sk>
  Date:   2025-02-21 (Fri, 21 Feb 2025)

  Changed paths:
    M lldb/include/lldb/Symbol/Function.h
    M lldb/source/Commands/CommandObjectSource.cpp
    M lldb/source/Symbol/Function.cpp
    A lldb/test/Shell/Commands/command-source-list.s

  Log Message:
  -----------
  [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.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list