[llvm] [llvm-debuginfo-analyzer] Add support for WebAssembly binary format. (PR #82588)

Heejin Ahn via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 12 18:30:33 PDT 2024


================
@@ -429,10 +431,14 @@ void LVELFReader::processOneAttribute(const DWARFDie &Die, LVOffset *OffsetPtr,
         CurrentHighPC = *Address;
       if (std::optional<uint64_t> Offset = FormValue.getAsUnsignedConstant())
         // High PC is an offset from LowPC.
-        CurrentHighPC = CurrentLowPC + *Offset;
+        // Don't add the WebAssembly offset if we have seen a DW_AT_low_pc.
+        CurrentHighPC =
+            (FoundLowPC ? CurrentLowPC - WasmOffset : CurrentLowPC) + *Offset;
----------------
aheejin wrote:

Please correct me where I'm mistaken.

Whether `CurrentLowPC` already contains the `WasmOffset` or not, `CurrentHighPC` should be higher than `CurrentLowPC`, right? The comment says
```cpp
// High PC is an offset from LowPC.
```
So if the high PC is 50 and the low PC is 40, the offset should be 10. (without `WasmOffset`)

Now add the `WasmOffset`. Suppose `WasmOffset` is 100, and `CurrentLowPC` is 140. And if we want to calculate `CurrentHighPC`, I think it still should be just
```cpp
CurrentHighPC = CurrentLowPC + *Offset;
```
So that `CurrentHighPC` is `CurrentLowPC ` (140) + `Offset` (10) = 150.

But this equation subtracts `WasmOffset` from it, so that
```cpp
CurrentHighPC = (CurrentLowPC - WasmOffset) + *Offset;
```
Here `CurrentHighPC` will be 140 - 100 + 10 = 50, whereas `CurrentLowPC` is 140, which is, `CurrentLowPC` contains `WasmOffset`, while `CurrentHighPC` does not.

I think this is strange. But given that your tool works, I must be mistaken somewhere. Can you point out where?

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


More information about the llvm-commits mailing list