GDB on Windows?

Newbie question.

(I have Windows 10)
I’ve been able to build Krita following the official guide (Building Krita from Source — Krita Manual 5.2.0 documentation) and now I wanted to set up debugging.

I’m seeing a few references to people successfully doing it.
I found this guide (Developing Krita in Visual Studio Code, part 3 | Amyspark) for setting it up with VSCode, but it tells me to use “gdb.exe” that’s packaged with the compiler. However, the installation from https://github.com/mstorsjo/llvm-mingw/releases/download/20220906/llvm-mingw-20220906-ucrt-x86_64.zip does not contain a gdb.exe
(and actually, neither does the llvm-mingw-20220323-ucrt-x86_64.zip that’s mentioned in the guide)

Is there somewhere else I should be getting gdb from? Any way to ensure it’s compatible?

Thanks!

GNU Project Debugger →

https://sourceware.org/gdb/

By the way… … and before forgetting it: Welcome to the forum @Vita! :slight_smile:

Michelist

1 Like

Alternatively you could try using the lldb debugger which comes with llvm, bin/lldb.exe.

3 Likes

Thank you for this!

It seems there’s no executable distribution, I should download a release (for example “https://ftp.gnu.org/gnu/gdb/gdb-14.1.tar.xz”) and compile it myself?

Just figuring out how to do that. Looks like I can install msys2 and then do
./configure
make
make install

Trying that now, it is taking a while :slight_smile:

That would be the usual way. I never thought about it, but perhaps GDB from Lazarus would do too? For my understanding, GDB should be GDB, no matter where it comes from, and I know GDB is part of Lazarus, Sourceforge even offers it as a separate download out of the Lazarus-Package, that link starts the download directly:

https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Alternative%20GDB/GDB%209.2%20-%20Modified%20for%20unicode/gdb.exe/download

Michelist

1 Like

Yay! It works! Thank you so much!
(I’ve hit a snag trying to build it myself, apparently simply building under msys2 and running outside results in missing dlls so I’m glad to be able to get an executable and not worry about making it work!)

1 Like

Hi, in my experience debugging on Windows with QtCreator has been a bit of the pain. It’s better if you compile a Debug config rather than RelWithDebInfo, but I often get weird hangs when stepping.

On Windows we are supposed to use the specific LLVM toolchain and then it’s best to use the bundled llvm debugger instead. You don’t need gdb.

For my development setup, I followed Dmitry’s Qt tutorial and use QtCreator. I wish it was possible to use Visual Studio, but I never had enough mental fortitude and spare time to try to make it work.

Hhm, yes, I spoke too soon.

I was able to run Krita under gdb but not really debug. I ended up unable to set any breakpoints, I’m getting errors:

C:\env3>C:\gdb\gdb.exe i\bin\krita.exe
GNU gdb unicode (GDB) 9.2
[...]
(gdb) break 1
Breakpoint 1 at 0x140001476: file C:\env3\krita\krita/windows_stub_main.cpp, line 13.
(gdb) run
Starting program: C:\env3\i\bin\krita.exe
[New Thread 26668.0x66dc]
[New Thread 26668.0x40f8]
[New Thread 26668.0x6fcc]
Warning:
Cannot insert breakpoint 1.
Cannot access memory at address 0x140001476

Command aborted.

The llvm-mingw has bin/lldb.exe, I’ll try and see if I can make it work.

As a first test I’ve tried:

C:\env3>C:\llvm-mingw\llvm-mingw-20220906-ucrt-x86_64\bin\lldb.exe i\bin\krita.exe
(lldb) target create "i\\bin\\krita.exe"
Current executable set to 'C:\env3\i\bin\krita.exe' (x86_64).
(lldb) run

And I’m not seeing any output after that, it’s either stuck or very slow or I’m doing something wrong.

To compile a Debug config I’m assuming I need to find a way to replace “-DCMAKE_BUILD_TYPE=Debug”?

I found a line in build.cmd

set CMAKE_BUILD_TYPE=RelWithDebInfo

I’ll try just replacing it with “set CMAKE_BUILD_TYPE=Debug”

Debug will work with the default build. However, yes, for better experience you can replace it with Debug in that line. That’s what I do.

However, a true debug build will be very slow, so maybe don’t do it unless you need to see every variable. Breakpoints and stepping should work with RelWithDebInfo as well.

1 Like

Yay! I finally have the debugger working!
Thank you everyone for your advice!

For posterity: I used the lldb.exe that is in the bin/ directory of the MingW distribution referenced in the bulid docs.

I ended up using QtCreator.
VS Code does not have built-in support for LLDB, and the extension I installed (CodeLLDB) kept crashing as soon as I reached a breakpoint :frowning:

I did follow Dmitry’s amazing tutorial for setting up Krita https://www.youtube.com/watch?v=jxIhFlGbPbs (I did end up breaking the build, but rebuilding Krita under QtCreator isn’t that bad)

I did encounter an issue with QtCreator saying “Unable to create a debugging engine”.
Following advice in this thread I started QtCreator from a terminal with an empty path and it worked.

2 Likes

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.