JetBrains / clion-debugger-plugin-stub

Minimalistic plugin with custom debugger stub

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Minimalistic plugin with custom debugger stub

incubator JetBrains project

Compatibility Disclaimer

This is an educational example, compatible with CLion 2023.3. Neither the example author nor JetBrains guarantees compatibility with upcoming versions.

HOW2USE

  • Download and install CLion.
  • Follow the steps described at Develop plugins for CLion.
  • Open the project and click Debug Plugin. This will start CLion with the plugin installed.
  • In CLion:
    • Create a project of type C++ Executable.
    • Configure the toolchain as described here.
    • Create a Run Configuration of type Debugger-Stub

Functionality Testing

  • Start the debugger: Click the Debug button
  • Pausing the debugger and disassembly: Click Pause Program button The execution is interrupted, and fake disassembly is shown
  • Execution stepping: Click Step Over button several times
  • Variables access: Evaluate foo expression. A string value bar is shown
  • Resume execution: Click Resume program button
  • Stop the debugger: Click the Stop button

Implementation details

There are two approaches to adding new debugger integrations in CLion.

Using the IntelliJ API

The official way for all IntelliJ-based IDEs is to:

  • implement com.intellij.xdebugger.XDebugProcess together with the necessary com.intellij.execution.runners.ProgramRunner for the "Debug" action to pick up your debugger,
  • register a new com.intellij.xdebugger.breakpoints.XLineBreakpointType so that users can put breakpoints in the desired file types,
  • implement com.intellij.xdebugger.attach.XAttachDebuggerProvider for attaching to already running processes, and
  • make lots of other small customizations along the way.

The benefit is that you control each and every little detail, and use the official and stable platform API, which is also open-source. Of course, the downside is that it's a huge amount of work with little to no relation to the real task - making a new native debugger work in CLion. Also, the whole new debugger stack should be integrated with the existing CLion C/C++ file types and run configurations, which is a whole other task on its own.

Using the CIDR / CLion API

This is the approach demonstrated in this example plugin. Instead of re-implementing the high-level code responsible for integration with the IntelliJ Platform, here we implement a com.jetbrains.cidr.execution.debugger.backend.DebuggerDriver subclass, which is a lower-level API responsible for communication with the actual debugger process.

The pros and cons of this approach are the opposite: you only implement the relevant business logic, but in order to do that, you have to use the "unofficial" API, which is subject to change, as already stated before.

Further development steps

Major functionality:

  • Implement all the //todos in com.jetbrains.clion.bugeater.debugger.BugEaterDriver class

Minor things:

  • Update resources/META-INF/plugin.xml with an actual name, description, etc.
  • Update resources/META-INF/pluginIcon.svg.
  • Update resources/icons/bugEaterRunConfig.svg. Please keep the size unchanged (16x16 px).

About

Minimalistic plugin with custom debugger stub

License:Apache License 2.0


Languages

Language:Java 100.0%