<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58372>58372</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            DWARFContext::getEHFrame() caches its data into the wrong member
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          cmannett85
      </td>
    </tr>
</table>

<pre>
    [DWARFContext::getEHFrame()](https://llvm.org/doxygen/DWARFContext_8cpp_source.html#l00886) is implemented like this (at the time of writing):
```
 Expected<const DWARFDebugFrame *> DWARFContext::getEHFrame() {
   if (EHFrame)
     return EHFrame.get();
  
   const DWARFSection &DS = DObj->getEHFrameSection();
   DWARFDataExtractor DebugFrameData(*DObj, DS, isLittleEndian(),
                                     DObj->getAddressSize());
  
   auto DF =
       std::make_unique<DWARFDebugFrame>(getArch(), /*IsEH=*/true, DS.Address);
   if (Error E = DF->parse(DebugFrameData))
     return std::move(E);
   DebugFrame.swap(DF);
   return DebugFrame.get();
 }
```
If the EH frame data has been gathered before then it is returned by the top conditional, the problem though is that member is never initialised because the generated data (`DF`) is applied to the `DebugFrame` member instead.

The next time `DWARFContext::getDebugFrame()` is called EH frame data is returned.  Although in my experience so far, it's worse because the data seems to be corrupted when read through a debugger - can't see a reason why that would be the case though.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVV2PqzYQ_TXwYi3iIwnkgYfchWivVKlSt1IfVwYm4HuNTW2z2fTXd8Zhk2wa6TZCxDDjM2fOzJhGd6cyWH-r_tr9sX_WysGHC7IdXj24-mVv-AhBWgTpNlhXuBicmyw5pHu8pHwfI216XHb649SDwtUt1FvRTtOb1bNpIRrcKIM0k3FcFBtEZMIyMU4SRkDnjknxE5gb8C0G4g6X-ChGYPrAjkY4oXrigcHjKoh3wSZeLv_I6o8JWsQJsudWK-uYJ1JB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