Basic LLDB API Questions

If I wanted to make a graphical debugger based on LLDB, is the C++ API mentioned here what I should use? Is this like incorporating LLVM into a project, where the functionality of LLVM is implemented in a set of libraries, an API I can call, rather than forking a process to launch a separate lldb process?

Is there an example of how to use this API, like the Kaleidoscope example for LLVM?

Yes, SB API is the way to go if you want to use LLDB programmatically (from scripts or IDEs). LLDB provides a dynamic library liblldb.dll/so, which is the actual debugger implementation. The binary lldb is a driver which simply uses SB API to run and control the process and provide a UI to the user. Thus lldb itself is a good example of how to use the API :slight_smile:

Here’s another example from my project – lldb-eval/ at master · google/lldb-eval · GitHub. There isn’t much documentation, but the code should be easy to follow.

That said, if your goal is to implement graphical debugger based on LLDB, I would recommend looking at Debug Adapter Protocol (DAP) and lldb-vscode adapter (src). This adapter implements a “debugger protocol” and can be plugged into any client/IDE that supports this protocol. Many IDEs and editors already support it, e.g. VSCode, Visual Studio, Vim, Emacs.

It might be easier to implement this protocol in your graphical interface and then use lldb-vscode adapter (or vscode-lldb, which is a different implementation :smiley: ). This way you’ll have a lot of things for “free” and improving lldb-vscode itself will benefit all other users as well.

1 Like

Thanks. So I’d link against liblldb and call the C++ API. Awesome, thank you. I’m not sure I’m to do this any time soon, but it’s something I’ve thought about doing for literal decades (I even wrote my own DWARF parser at one point), and it’s never been easier. I wish Xcode were more pluggable and could be used for other targets and OSes, but alas, it can’t. And I absolutely hate using VS Code (even though I do, when forced to write web or Python apps).

Is DAP the same as DAP in CMSIS-DAP? That’s how OpenOCD communicates with my target, but OpenOCD doesn’t handle mapping source code (afaik).

As a rule, I dislike command-line interfaces to things, so I’ll probably stick with the API (or DAP, if that’s a linked API as well), rather than using the vscode options.

Thanks again!

I’m not familiar with CMSIS, but from the looks of it it’s a different thing.

Debug Adapter Protocol is not command-line based, it describes the structured messages/events that client/server use to communicate to each other. The “default” implementation is exchanging JSON messages through a pipe (or stdin/stdout).

Btw, even though lldb-vscode and vscode-lldb have vscode in their name they’re actually implementations of the debug adapter protocol server and they don’t have to be used with VSCode. They can be plugged into any IDE/client that implements the protocol.

Good to know!

Oh yeah, that was clear, my VS Code comment was in the context of not being able to use Xcode as a flexible IDE, which VS Code very much is.