mstorsjo / llvm-mingw

An LLVM/Clang/LLD based mingw-w64 toolchain
Other
1.97k stars 188 forks source link

lldb python support #73

Closed cristianadam closed 3 years ago

cristianadam commented 4 years ago

Qt Creator requires python support from gdb / lldb debugger.

It would be great to have a fully toolchain on Windows 😄

RussellHaley commented 3 years ago

Thanks everyone!

longnguyen2004 commented 3 years ago

This is not done though, I'm waiting for the removal of distutils in the future, so we won't have to build a native Python anymore.

longnguyen2004 commented 3 years ago

@mstorsjo I think we can close this now, I'll try to keep the branch updated.

cristianadam commented 3 years ago

I gave https://martin.st/temp/llvm-mingw-lldbtest-x86_64.zip a try and built with it Qt 5.15.2 (with a small patch for D3D12), llvm 12 and Qt Creator master. This would make it a full clean Qt Creator build and its dependencies.

Then I registered a Kit with the compiler / qt version / debugger and with a console hello world it worked!!! I could set a breakpoint and then I could see the value of my variable.

But then I tried to load a hello world qt application the debugging session stopped abruptly with a NOTE: INFERIOR SPONTANEOUS STOP. The whole log is here.

The standard c++ example that worked when the program finishes the debugging session doesn't end, so I have to click "Abort Debugging" from the menu.

longnguyen2004 commented 3 years ago

Can you get the output of the debugger itself? This is the log of the communication between Qt Creator and LLDB, and I can't really see what's wrong from it.

cristianadam commented 3 years ago

Running lldb.exe with the executable worked fine:

C:\Projects\c++\build-hello-qt-Clang_MinGW-Debug
$ set PATH=c:\Qt\5.15.2\llvmmingw12_64\bin;%PATH%

C:\Projects\c++\build-hello-qt-Clang_MinGW-Debug
$ lldb hello-qt.exe
(lldb) target create "hello-qt.exe"
Current executable set to 'C:\Projects\c++\build-hello-qt-Clang_MinGW-Debug\hello-qt.exe' (x86_64).
(lldb) breakpoint set --file c:\Projects\c++\hello-qt\main.cpp --line 7
Breakpoint 1: where = hello-qt.exe`main + 49 at main.cpp:7:26, address = 0x00000001400017c1
(lldb) run
Process 18196 launched: 'C:\Projects\c++\build-hello-qt-Clang_MinGW-Debug\hello-qt.exe' (x86_64)
Process 18196 stopped
* thread #1, stop reason = breakpoint 1.1
    frame #0: 0x00007ff7e3e017c1 hello-qt.exe`main(argc=1, argv=0x0000026951eb5350) at main.cpp:7:26
   4
   5    int main(int argc, char *argv[])
   6    {
-> 7        QApplication a(argc, argv);
   8        MainWindow w;
   9        w.show();
   10       return a.exec();

Then it's a problem with Qt Creator and the communication with lldb.exe

cristianadam commented 3 years ago

I've tried also with Qt Creator 4.15.1 and it seems with this version there is more information about the failure: https://paste.ubuntu.com/p/gxXWtVGVN4/

cristianadam commented 3 years ago

And a version with the normal hello world that works but hangs at the end https://paste.ubuntu.com/p/YTQXYrFtQP/

cristianadam commented 3 years ago

But this bugreport could be closed when we have a llvm-mingw release. The lldb bugs could be reported upstream with testcases for the lldb developers to reproduce / fix.

longnguyen2004 commented 3 years ago

Alright...I'm downloading Qt Creator. I'm gonna try reproducing the C++ hello world test.

cristianadam commented 3 years ago

You could also... build Qt Creator 😄

I've put a 7z archive, 513MiB in size containing the LLVM MinGW Toolchain, Qt 5.15.2 built with the toolchain, Clang 12 with patches for Qt Creator and a CMake script that would clone Qt Creator, configure, build and install Qt Creator.

longnguyen2004 commented 3 years ago

Oh thanks, I'm too afraid to build Qt on my dying computer :) Anyway, they did offer prebuilt binaries for Qt Creator, so I don't have to build anything.

longnguyen2004 commented 3 years ago

I did observe the hang on Qt Creator. I think I also observed it in Visual Studio Code with the C++ extension, but I need to test again.

mstorsjo commented 3 years ago

@cristianadam I made a proper release now (based on LLVM 13.0.0 RC1 though) that includes python hooked up in LLDB. There’s one known gotcha about using it with Qt though, there’s one test in qtbase that fails to compile, see https://llvm.org/PR51442 and https://codereview.qt-project.org/c/qt/qt5/+/364211 if you’re interested.

cristianadam commented 3 years ago

I took the proper release mentioned above, compiled clang for Qt Creator, Qt 5.15.2 (had to apply a patch for Qt Declarative), and then Qt Creator 5.0 with it.

The artifacts, including the toolchain, and a script to build Qt Creator from scratch could be found here: llvm-mingw-13-qt-clang.7z (344MiB).

This release can debug Qt applications, it worked fine with Qt Creator itself! The debugger hang at the end of the session, but I think it's more of a Qt Creator problem.

I'm happy with the release, debugging works, I consider this bug closed! Thank you.

mstorsjo commented 3 years ago

Thanks for letting me know, that's great to hear that the toolchain fulfills this usecase now too!