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

    <tr>
        <th>Summary</th>
        <td>
            PDB single-step problem inline __asm Windows WinDbg
        </td>
    </tr>

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

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

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

<pre>
    Hi there, I'm following exercises by https://patterndiagnostics.com which use inline assembly (`__asm`) in their book. They use VC++ but I tried `clang` as this was much easier compared to all the `vcvarsall` intricacies in build scripts and gave a quick win.

Stepping through the code in `WinDbg` I encountered misbehavior and it took me like a day to figure it out doubting flags, assembler syntax and my skills as a beginner and what not. I also had a stupid bug (erroneous line) first which didn't make things easier.

- Load the compiled EXE with symbols (PDB) in `WinDbg` (launch executable, maybe `.reload /f`).
- Break on the first `lea` instruction (`bp main+0x12`).
- Try to single-step (`t`)

Expected behavior:

- Step to next instruction (`mov dword ptr [eax], 1`)

What actually happens:

- Ending up at `xor eax, eax` (which is already in the prologue of `clang`-generated code (which is `main+0x36`)

This doesn't happen with the `cl` tooling from `Visual Studio 2022`.

I figured that the compiled EXE is actually fine, you can debug it without symbols and tracing will work as expected.

As a result, something must be wrong with the PDB generated by `clang` vs. what `cl` does as it causes wrong code steps.

I'll try to put a ZIP with the files somewhere.

Compilation line: `clang -g -gcodeview -fasm-blocks --target=i386-windows-msvc -o PointersProjectCL86.exe PointersProject.cpp`

![image](https://github.com/llvm/llvm-project/assets/4944664/c23f5749-fc7a-45d0-9885-7875217c560e)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVcuO27oS_Bp605Ah05ZlL7wYzwN3gCwGSJBc3E3QotoSrylShw8__v6gKU8yzpzNAQYjQDK7qquqmxiC7izRTlR7UT3NMMXe-d3o3aHezhrXXnf_0RB78iTkI7wKWQ9wcM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