[llvm] Improve DWARFDebugLine::LineTable::lookupAddressRangeImpl(...) to act as exptected. (PR #226625)

Greg Clayton via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 6 17:09:57 PDT 2026


clayborg wrote:

> While it's admittedly been a while since I've looked at line tables, I do find this description to be pretty confusing - maybe a worked example in the descirption would make it clearer what the old contract was (perhaps describing that without mentioning the solution - currently current state, future state, and problems/solutions are all a bit interleaved, which I'm having trouble following), why it's a problem, and what the new contract is and how it addresses the problem?

Yeah, the current API is a bit tough to use for a few reason: the current version of this API will return all rows that match a specific address range even if those rows are in separate sequences. This means the results we get back are not guaranteed to be unique or abide by any DWARF line table rules, such as "all rows should monotonically increase". Right now if we have a compile unit line table with two sequences like:
```
Idx Addr  File/Line
--- ------ -----------------
0   0x1000 main.cpp:5
1    0x1010 main.cpp:6
2    0x1020 main.cpp:6 (end_sequence)
...
20  0x1000 foo.cpp:5
21  0x1010 foo.cpp:6
22 0x1020 foo.cpp:7 (no end sequence here)
...
```
(where functions from main.cpp and foo.cpp and were merged)

And if we ask for rows for [0x1000-0x2000) we get the following row indexes back as a result:
```
[0, 1, 20, 21]
```
which amounts to a line table search result that looks like:
```
Idx Addr  File/Line
--- ------ -----------------
0   0x1000 main.cpp:5
1    0x1010 main.cpp:6
20  0x1000 foo.cpp:5
21  0x1010 foo.cpp:6
```
Note that we don't get the end_sequence indexes 2 currently, but maybe we should for addresses that match the end address? But that still doesn't help us with the second "foo.cpp" case where there is no end_sequence for row index 22.


> 
> (also the mention of monotonically increasing line tables seems like a red herring - that's not possible for a line table to guarantee, really (even if it is what the DWARF spec says) because function ordering isn't guaranteed - functions can be linked in different orders I'm fairly sure, so even without ICF or DCE, you may not have a monotonically increasing line table)

It is a requirement within a sequence though. It is totally fine to have multiple different sequences with the same address ranges. The problem is the results of this function returns line table indexes and we don't know if they are actually in the same sequenc since the end_sequence  rows are not included in the results.

Maybe this function should return a vector of sequence rows, so a vector of a vector of row indexes:

```
std::vector<std::vector<uint32_t>> &Result
```
So each `std::vector<uint32_t>` could come from a different sequence, and this would make that clear. Then if we ask for rows for [0x1000-0x2000) we get the following row indexes back as a result:
```
[[0, 1], [20, 21]]
```
And the client can now reason about what to do with the results. Each row index vector now is guaranteed to be monotonically increasing, and the client can figure things out.
> 
> +1 to other mentions of patch title improvements to be made. Maybe something like "DWARF lookupAddressRangeImpl discard duplicate address ranges" or "only return the first row covering a given address in case of duplicates"

That works.

The current patch would return :
```
[0, 1]
```

This patch would also handle a discontiguous line table. Lets say we have a function with two ranges:
```
[0x1000-0x1020) and [0x1030-0x1040)
```
And if we have a line table like:
```
Idx Addr  File/Line
--- ------ -----------------
0   0x1000 main.cpp:5
1    0x1010 main.cpp:6
2    0x1020 main.cpp:6 (end_sequence)
...
20  0x1030 main.cpp:7
21  0x103a main.cpp:8
22 0x1040 main.cpp:9 (end_sequence)
...
```
For [0x1000-0x1020) we would get:
```
[0, 1]
```
For [0x1030-0x1040) we would get:
```
[20, 21]
```

Do we want to change the return value of this function to return multiple row vectors, one for rows in each different sequence?

https://github.com/llvm/llvm-project/pull/226625


More information about the llvm-commits mailing list