Using LLDB API on windows

Hey so I am developing a project using LLDB as a debugger and am looking to make it cross-platform.

As I see it, the LLDB API boots up an instance of lldb-server, but lldb-server isn’t available on windows. Is there a way to use the LLDB C++ API on windows?

On the status page I see the lldb commandline tool is OK for windows, which uses the LLDB API, how is this achieved?

-Russell

Hi Russell,

I assume you mean for SBTarget::Launch or LaunchSimple to launch a Windows application.

The short answer is, this already works.

SBTarget::Launch calls Target::Launch, which calls DebugProcess in the relevant platform. For cases where we use lldb-server, the platform make a call that eventually gets to GDBRemoteCommunication::StartDebugserverProcess to start up lldb-server. On Windows, PlatformWindows::DebugProcess calls Process::Launch, which (on Windows) will do the correct thing to start up and connect to a Windows process.

See PlatformWindows::DebugProcess in source\Plugins\Platform\Windows\PlatformWindows.cpp and ProcessLauncherWIndows::LaunchProcess in source\Host\windows\ProcessLauncherWindows.cpp .

Ted

That makes sense, and I’m sure it works great when using MSVC as a compiler, but I think LLDB recognizes mingw as a unix compiler and tries to do GDBRemoteCommunication::StartDebugserverProcess when it should be doing PlatformWindows::DebugProcess.

Not sure though. All I know is when I try to do a SBTarget::Launch on windows under mingw (msys2) it says cannot find lldb-server…

-Russell

I wonder if lldb isn’t using the windows platform. In the lldb command line, load up your target, then type “target list”. I’d like to see what plaform it chose, and what the triple is.

Interesting:

PS C:\Users\IEUser> C:\msys64\mingw64\bin\lldb.exe C:\msys64\home\IEUser\chigraph\build\bin\chi.exe
(lldb) target create “C:\msys64\home\IEUser\chigraph\build\bin\chi.exe”
Current executable set to ‘C:\msys64\home\IEUser\chigraph\build\bin\chi.exe’ (x86_64).
(lldb) target list
Current targets:

  • target #0: C:\msys64\home\IEUser\chigraph\build\bin\chi.exe ( arch=x86_64-pc-windows-msvc, platform=host )
    (lldb)

-Russell

Also, forgot to include this part: it’s pretty important:

PS C:\Users\IEUser> C:\msys64\mingw64\bin\lldb.exe C:\msys64\home\IEUser\chigraph\build\bin\chi.exe
(lldb) target create “C:\msys64\home\IEUser\chigraph\build\bin\chi.exe”
Current executable set to ‘C:\msys64\home\IEUser\chigraph\build\bin\chi.exe’ (x86_64).
(lldb) target list
Current targets:

  • target #0: C:\msys64\home\IEUser\chigraph\build\bin\chi.exe ( arch=x86_64-pc-windows-msvc, platform=host )
    (lldb) r
    error: process launch failed: unable to locate lldb-server
    (lldb)

-Russell

As the person who added most of the support for debugging Windows executables, I can tell you that I never tested a MinGW executable (nor was it one of my original goals). It doesn’t entirely surprise me that things are behaving this way, but I’m not sure what the exact cause would be off the top of my head. MinGW executables and msvc Win32 executables use an entirely different ABI, so I would exepct the non lldb-server path to be a little wonky since I always assumed MSVC ABI in my implementation. On the other hand, as you said there is no lldb-server.

If you’re interested in digging into the source code and trying to add a patch for MinGW support, I can give you some pointers.

Ooh, I’d definitely be interested.

Sounds like a very fun project.

I’ll have to familiarize myself with the internals (I’m currently learning the API, which seems to resemble the internals moderately well…)

I’ll start educating myself tomorrow morning when I wake.

-Russell

Date: Tue, 04 Apr 2017 03:00:21 +0000
From: Zachary Turner via lldb-dev <lldb-dev@lists.llvm.org>

As the person who added most of the support for debugging Windows executables, I can tell you that I never
tested a MinGW executable (nor was it one of my original goals). It doesn't entirely surprise me that things are
behaving this way, but I'm not sure what the exact cause would be off the top of my head. MinGW executables
and msvc Win32 executables use an entirely different ABI, so I would exepct the non lldb-server path to be a
little wonky since I always assumed MSVC ABI in my implementation.

Are you sure you are talking about MinGW and not Cygwin or MSYS?
Because MinGW executables are native Win32 programs, so much so that
you can load MSVC DLLs from a MinGW program and vice versa.

Or maybe I don't understand what you mean by "ABI".

I did try debugging MinGW-compiled executables with lldb, and it did
work for me, FWIW.

Apologies if by "MinGW" this thread means MSYS/MSYS2. MSYS is a fork
of Cygwin, and yes, it uses a different ABI, which attempts to emulate
a Posix system on top of Windows.

Well I would guess the main problem is lldb being compiled in a msys environment which I guess lldb recognizes to be so posix to try and launch lldb-server. The results I gave you are from the mingw-w64-x86_64-lldb package in msys2.

Pretty sure mingw and msvc have different ABIs though (at least for C++) they have completely different name mangling algos.

-Russell

From: Russell Greene <russellgreene8@gmail.com>
Date: Tue, 04 Apr 2017 14:50:23 +0000
Cc: ted.woodward@codeaurora.org, lldb-dev@lists.llvm.org

Well I would guess the main problem is lldb being compiled in a msys environment which I guess lldb
recognizes to be so posix to try and launch lldb-server. The results I gave you are from the
mingw-w64-x86_64-lldb package in msys2.

That's a native 64-bit build of lldb, AFAIU. It should be okay for
debugging native Windows programs, at least the 64-bit programs. (I
only ever used a 32-bit build of lldb for debugging 32-bit MinGW
programs, and it worked OK.)

Pretty sure mingw and msvc have different ABIs though (at least for C++) they have completely different
name mangling algos.

Yes, but that's not necessarily relevant for debugging, except that
you might see mangled names.