Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDB single-step problem inline __asm Windows WinDbg #91861

Open
prof79 opened this issue May 11, 2024 · 5 comments
Open

PDB single-step problem inline __asm Windows WinDbg #91861

prof79 opened this issue May 11, 2024 · 5 comments

Comments

@prof79
Copy link

prof79 commented May 11, 2024

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

@prof79
Copy link
Author

prof79 commented May 11, 2024

Demo files - code plus binaries:

https://1drv.ms/f/s!Apk3bQT52ViAlugnQFKde1saMC1fow?e=pG3f10

@prof79
Copy link
Author

prof79 commented May 11, 2024

Sorry, I forgot (Win11 23H2 22635.3570):

C:\> clang --version
clang version 18.1.4
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
C:\>

@llvmbot
Copy link
Collaborator

llvmbot commented May 11, 2024

@llvm/issue-subscribers-debuginfo

Author: Markus M. Egger (prof79)

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

@dwblaikie
Copy link
Collaborator

@zmodem perhaps you can get this to some interested folks

@zmodem
Copy link
Collaborator

zmodem commented May 14, 2024

@amykhuang @ZequanWu could you take a look? It sounds like there's something wrong with line info for inline asm perhaps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants