Programmatically start debugger
Hi everyone,
I'm developing an IntelliJ IDEA Plugin in which at some point I need to start the debugger. The scenario is as follows:
- Programmatically set a breakpoint (at a specific line of a specific file).
- Show the run/debug configurations to the user (and let him select one).
- Programmatically execute the selected run/debug configuration.
This lets me print the run/debug configurations of the project to the console:
final Project project = event.getProject();
final RunManager runManager = RunManager.getInstance(project);
List<RunConfiguration> runConfigurations = runManager.getAllConfigurationsList();
for (RunConfiguration runConfiguration : runConfigurations) {
System.out.println(runConfiguration.getName());
}
I already read the following blog post to run the configuration but unfortunately, it didn't help:
Thanks for your help in advance,
Alex
Please sign in to leave a comment.
To add a breakpoint you can use XBreakpointManager.addLineBreakpoint,
to debug a configuration - ExecutionEnvironmentBuilder.create(project, DefaultDebugExecutor.getDebugExecutorInstance(), runConf).buildAndExecute()
To toggle a line breakpoint you can use XDebuggerUtil.toggleLineBreakpoint
Hi Egor,
thanks for your reply!
I'm able to execute the run configuration but still struggling with setting a breakpoint.
The following code snippet shows what I'm working on (and failing). I assume there needs to be a much simpler way:
Cheers,
Alex
Thanks for your support Egor.
Here is the solution that worked for me, if someone else tries to implement something similar:
1. Programmatically set a breakpoint (at a specific line of a specific file).
2. Show the run/debug configurations to the user (and let him select one).
3. Programmatically execute the selected run/debug configuration.
Finally, run it: