Run lldb command in the running lldb instance


I want to implement a CLion plugin that runs a custom command in the current lldb instance. How can I access the running lldb instance from Kotlin?

1 comment


First of all, please keep in mind that there's no official public API for CLion-specific parts. While this should work, things can change under the hood in a way that could make third-party integrations break in the future. We try not to break things without a real need, but can't guarantee that it won't happen, alas.

Having said that, and given that you want to implement an action, or you have other means to retrieve the current debug session, this could look roughly like this:

// I assume you have a service bound to your plugin's lifecycle already defined somewhere
class MyAwesomePluginService(val project: Project,
                             internal val coroutineScope: CoroutineScope) {
  companion object {
    fun getInstance(project: Project): MyAwesomePluginService = project.service()

class ExecuteCustomNativeDebuggerConsoleAction : DumbAwareAction() {
  override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT

  override fun update(e: AnActionEvent) {
    val debugProcess = DebuggerUIUtil.getSession(e)?.debugProcess as? CidrDebugProcess
    e.presentation.isVisible = (debugProcess != null)
    e.presentation.isEnabled = debugProcess?.driverName == "LLDB"

  override fun actionPerformed(e: AnActionEvent) {
    val session = DebuggerUIUtil.getSession(e) ?: return
    val debugProcess = session.debugProcess as? CidrDebugProcess ?: return
    val threadId = (session.currentStackFrame as? CidrStackFrame)?.threadId ?: return
    val frameIndex = (session.currentStackFrame as? CidrStackFrame)?.frameIndex ?: return

    MyAwesomePluginService.getInstance(session.project).coroutineScope.launch {
      @NonNls val output = debugProcess.debuggerCommandExecutor.executeCommand(canExecuteWhileRunning = false) { driver ->
        driver.executeInterpreterCommand(threadId, frameIndex, "script print \"hello\"")
      withContext(Dispatchers.EDT + ModalityState.any().asContextElement()) {
        session.reportMessage(output, MessageType.INFO)

Please sign in to leave a comment.