Eclipse Debugger Events - eclipse

In my Eclipse plugin, I would like to be notified on debugger events (e.g. when stepping or a breakpoint is hit). I've managed to get this working in a JDT environment by subscribing to debug events using this code:
DebugPlugin.getDefault().addDebugEventListener(this);
Which gives this event handler:
public void handleDebugEvents(DebugEvent[] events)
{
}
In JDT this is fired on Breakpoint or Suspend events and I was hoping the behaviour would be the same in CDT. However, it is not. I only get two Create events at the start of the debug session:
DebugEvent[org.eclipse.cdt.dsf.gdb.launching.GDBProcess#ae0aae, CREATE, UNSPECIFIED]
DebugEvent[org.eclipse.debug.core.model.RuntimeProcess#920d5d, CREATE, UNSPECIFIED]
Is there a generic solution that wouldn't require specific dependencies on JDT or CDT?
Thanks,
Alan

I did find a solution and have answered my other question here: Eclipse plugin - handling events when stepping or breaking
Alan

I think what you want can't be achieved (generic, implementation-independent solution) without listening and digging through every single action in the Eclipse environment, as I understand that the Eclipse generic debug plug-in is just the framework on which to build a implementation-specific debugger, like Java's own debugger.
The static call you're making to DebugPlugin is a call to this basic 'framework' on which the CDT or JDT is running. For example, if I wanted to register a breakpoint listener to the Java debugger, I would call JDIDebugModel.addJavaBreakpointListener(<Your Java breakpoint listener class>);.
P.S. If there is a way to maybe listen to just the events fired from/under the generic platform debug plug-in, which would include the events fired from plug-ins that extend from this generic debugger, that may ease the task you seek to accomplish.

Related

How to add logging to an existing Eclipse plugin to work in 2019-12?

I'm trying to fix a problem in an Eclipse plugin at https://github.com/davidmichaelkarr/e4macs . The repo is a fork of the original application, which is now abandonware.
I have a couple problems with this, but I'm going to limit the scope of the question, hopefully making it simpler for someone to provide an answer.
The main problem I'm having with the plugin is that some operations (the operation "split-window-vertically" in particular) simply do nothing when I execute them. This didn't used to be the case. In some recent versions of Eclipse, this was working fine. It stopped working about 2019-09.
What I want to do first is add log statements that show it's at least getting to the handler method. I've concluded that I don't know how to add logging to an Eclipse plugin. The existing code for the plugin doesn't do any logging, so I don't have an example to go by. I've searched the net for documentation on how to do this, but all the articles I've found are either incomplete or just don't work.
I know of at least one handler that IS working properly. I added what I thought was the correct logging code to that handler, and it never appeared in the ".metadata/.log" file, so I assume that that was not the correct way to do logging.
I saw a reference to using "Activator.getDefault()", but that posting didn't say what the FQCN is, and all the completion offerings I found didn't have a "getDefault()" method.
Update:
I added something like the following to two classes:
private ILog logger = Platform.getLog(<ContainingClass>.class);
And then in a method in each of these classes, I used logger.info("message");
I ran this in my debug instance and tested the operations in both classes. The log messages appeared.
I then uninstalled the plugin from the main installation, then built the plugin in my RPC instance, then reinstalled the plugin in the main installation, from the local update site defined by the "...Update" project.
I then tested both operations, and I saw nothing in the log.
I may have solved my logging problem at this point, but I'm still having some sort of problem with deployment. I have a feeling that the process I went through to reinstall the changed plugin is not working.
To get an activator with a getDefault() method you must specify that the plugin contributes to the UI when you create it and that you want an Activator to be created. This should create an activator class extending AbstractUIPlugin and with a getDefault() static method.
In any plugin you can always use:
IStatus status = new Status(....);
ILog log = Platform.getLog(getClass());
log.log(status);
to log a status object.
Status has numerous constructors. A simple one just to log a message is:
new Status(IStatus.INFO, "plugin id", "message");
Platform is org.eclipse.core.runtime.Platform
Status is org.eclipse.core.runtime.Status

Eclipse-Plugin: Program Counter position

I am about to break here into pieces. I asked in the forum community, I asked the developer list and I already asked on stackoverflow.
Where is that code-line that just moves that program-counter annotation to that line that I want it to move?
Speaking of highlighting the line which is currently executed during debug.
I've checked out
org.eclipse.cdt.debug.core
org.eclipse.cdt.debug.ui
org.eclipse.cdt.dsf.gdb
org.eclipse.cdt.dsf.gdb.multicorevisualizer.ui
org.eclipse.cdt.dsf.gdb.ui
org.eclipse.cdt.tests.dsf.gdb
org.eclipse.cdt.ui
org.eclipse.cdt.visualizer.core
org.eclipse.cdt.visualizer.ui
but I coldn't find a line that just does this.
foo = new ObjectThatDoesWhatINeed();
foo.highlightLine(lineNumber);`
I'm freaking out here since I stuck there for a week now and this should not be such a huge thing since I suppose that Eclipse is designed to re-use functionalities, right?
How about adding a breakpointListener and then using AST to identify current cursor position?
From the extension point description (bold mark by me):
Allow clients to contribute listeners for Java breakpoint
notifications. For example, listeners are called when a breakpoint is
hit and about to suspend execution. The listener can vote to resume or
suspend the debug session. Listeners can be programmatically added to
and removed from specific Java breakpoints (specified by breakpoint
listener identifers), or be registered to listen for notifications for
all Java breakpoints.
The Extension Point is called:
org.eclipse.jdt.debug.breakpointListeners
That visualization is not specific to the CDT plugin, so you will surely find it in the generic org.eclipse.debug.ui instead.
Looking at the extensions defined in that plugins manifest.mf, there is an annotation type called org.eclipse.debug.ui.currentIP, which might be the one for the current instruction pointer. But this is just guessing.

Debug Eclipse from the moment plugin starts running

I am trying to debug an Eclipse plugin, but I can't figure out where to place the breakpoints.
Is there anyway to set Eclipse to Debug every single expression so that from the moment I execute the plugin, the first expression is a breakpoint?
If you have an Activator class, you can start with that. Otherwise it's really a matter of what extensions you're contributing and when those will be called by someone else. Plug-ins aren't like applications. Set your breakpoints in your code, they'll trigger when code from your plug-in is triggered.
A plugin is more than code and the code it might have doesn't need to be Java, but if it's Java code you want to debug, try setting class load breakpoints on all of your plugin's classes.

Full trace in eclipse debugging session

I have a question about eclipse debugging. I would like to have, in an output file, all the calls of methods for a debugging session. I would like to track the methods called, all of theme, just like the in debug view but not only for a break point but for all the debug session.
Using breakpoints does not allow to know which methods were called before. Knowing that could help placing break points efficiently.
The Eclipse Java debugger has no tracing capabilities. You need to look at other tools like the Yourkit profiler (which I used often for traces and benchmarking) or JProfiler.

Eclipse plugin - handling events when stepping or breaking

Is there a generic way of receiving event notifications from the Eclipse debugger. Specifically I would just like to know when the user steps over/into and when a breakpoint is hit.
I have already got this working in JDT (see my other question: Eclipse Debugger Events) but the same technique doesn't work in CDT (I am using DebugPlugin.addDebugEventListener).
If there is no generic way of doing this, then is there a way to avoid the CDT dependencies from breaking the plugin when it is run in JDT?
Thanks,
Alan
OK, I've found an alternative that may be of use for others. You can use the method outlined above to listen for debug events when the session is created and terminated.
For any stepping events, one way I found was to register an IExecutionListener to be notified of all commands that take place in the Eclipse workspace. You can register an execution listener by getting hold of an ICommandService as follows:
ICommandService commandService = (ICommandService)PlatformUI.getWorkbench().getService(ICommandService.class)
Then add an execution listener:
commandService.addExecutionListener(this);
This will give you various event handlers (notHandled, postExecuteFailure, postExecuteSuccess, preExecute) from which you can filter by the commandId value.
I hope this helps someone else.
Alan