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

    <tr>
        <th>Summary</th>
        <td>
            [lldb] Using `.debug_frame` unwind info for IPs without symbol/function info
        </td>
    </tr>

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

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

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

<pre>
    The mechanical reproduction for this issue as I encountered is somewhat complex, here are the ingredients:
1) Windows host, or otherwise ensuring that the "default" unwind plan is wrong for `FW` below.
2) Stepping into a function _without_ debug info (`FN`) from a function _with_ debug info (`FW`). The debug info format is DWARF.
3) Both functions have correct unwinding information recorded in `.debug_frame`, but there is no `.eh_frame`.

Under these very specific conditions, step-in behavior will be wrong (we expect a graceful step-over), with "how wrong" depending on how wrong the default unwind plan is for `FN` calling `FW`. In my case (wasmtime-transformed DWARF, `FN` is a WASM function with WASM-level DWARF, `FW` - without), the step-over resulted in returning to the caller of `FN`, due to the CFI essentially being computed for `FN` instead of `FW`.

It is easier to explain the problem with looking through the code responsible for finding the unwind plan in this case. First, we get into `InitializeZerothFrame` and fail to get a symbol context:

https://github.com/llvm/llvm-project/blob/0383e545d1f6a5ccd1fc8177c9a9e52f5809c4f3/lldb/source/Target/RegisterContextUnwind.cpp#L163-L176

Then we get into `GetFullUnwindPlanForFrame`:

https://github.com/llvm/llvm-project/blob/0383e545d1f6a5ccd1fc8177c9a9e52f5809c4f3/lldb/source/Target/RegisterContextUnwind.cpp#L850-L878

Here, since `m_sym_ctx_valid == false`, we don't get to `GetFuncUnwindersContainingAddress`, which would find our PC in the `.debug_frame` table, and there is no `.eh_frame`, so we return the default unwind plan.

Looking a bit more at the code, it seems it would be possible to remove the `m_sym_ctx_valid` check, and always ask `GetFuncUnwindersContainingAddress` for the unwind plan, since its callees can handle a missing symbol context (by getting the code range from the unwinding sections).
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzMVk1v4zYQ_TX0ZRBDpix_HHzwJlAbIC0W-4EAvQQUObLYpUiBpKy4v74YUk422bZobz05iDgzb96bN6QIQZ8s4oFVH1h1txBj7Jw_fNb2ZPAopceonV00Tl0OXzqEHmUnrJbCgMfBOzVKOgCt8xA7HUCHMCKIAPeAVrrRRvSoQAcIrsepExGk6weDz4zfQoceQXiE2CFoe_KoNNoYWHlkxXHF-B4etVVuCtC5ECnEeXCxQz_pgIA2jF7bE0RKTEkY5wpbMZrIOIfRTtoqGIywBGHyzp4SVrYp6ke2KaBB46YlK46cin2OOAyUT9voQEA72tzf06Rj58b4BAqbkb63DhjfUZ5f2aag4Na7_oeYvwp4zAFLIEa_-9w634tIQO8ej59qQlVS4g8udi9pA3TijCCd9yjj3GGGnOOptEfpvCLeLbW6TEWeWi96TLVvoRkTXx6pnHXpFHYvR6g2K45frUISFgPCGf0FwoBSt1qCdFbphIeyhYjDjbbQYCfO2nmYtDHQ4Mw447sJAZ8HQizg5IXEdjQ5zJ3RM76nNEQYKdi5KUeShgoHzB06Cy9fktiz0u9lvgpMwoAUxlDwlfgl3FvoLyBFwARMhD7qHm-iFzYQhagy_4ToJY0OIODx-PmXV30TWvrXjcEzmrdBabhuYB6buT_C_NIzeAyjiVkkj3H0Nk2yS8cINnpwLbyO2C2oEa8Hbut7wBDQRi2MuUCDFE3eGinnGw60DRGFumZ7fBX4Po0biqBJZ0caGaFtqjB41xjsc5_GuW_ZaN6Npy5jdAqpi8HZoBuDqWg7jyMdeKOLzQuCeF9CrX2284Rwwpj9xjbFvdXUj_4Df0PvYlfP8wjCKmiFNgSSAgSES984Q4MY8TnmjcGKYxfjkPYHrxmvTzp2Y7OUrme8NuZ8_bkZvPsdZWS8boxrGK-Lcldita7Uqt2ISkq1auVutd3KvdhjxdtqV-zlui1TAkURwY1eIuP1F-FPSKk-4UmHiP42Y_qa2l_KYWC8fFhtypuH1XaT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