[llvm] [llvm-debuginfo-analyzer] Add support for WebAssembly binary format. (PR #82588)
    Carlos Alberto Enciso via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Tue Mar 12 05:23:44 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;
----------------
CarlosAlbertoEnciso wrote:
When we detect the `DW_AT_low_pc`, the `CurrentLowPC` is updated to reflect the WebAssembly code section offset.
```
  case dwarf::DW_AT_low_pc:
      FoundLowPC = true;
      ...
      if (FoundLowPC) {
        ...
        // Consider the case of WebAssembly.
        CurrentLowPC += WasmOffset;
        ...
      }
      break;
```
When we detect the DW_AT_high_pc:
```
  case dwarf::DW_AT_high_pc:
        ...
        // Don't add the WebAssembly offset if we have seen a DW_AT_low_pc.
        CurrentHighPC =
            (FoundLowPC ? CurrentLowPC - WasmOffset : CurrentLowPC) + *Offset;
        ...
      // Consider the case of WebAssembly.
      CurrentHighPC += WasmOffset;
        ...
    break;
```
Basically if we have seen a `DW_AT_low_pc`, the `CurrentLowPC` is already increased by the `WasmOffset` value; so for the calculation of `CurrentHighPC` the value of `CurrentLowPC` must be the original value (no addendums).
https://github.com/llvm/llvm-project/pull/82588
    
    
More information about the llvm-commits
mailing list