Eclipse plugin - handling events when stepping or breaking - eclipse

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

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

Moodle 3.1- Event Handler Debugging

Before I get into it I'm sorry for the newbie question but I'm new to Moodle and php development. I'm attempting to figure out how to debug the code in event handlers.
Really what I'm looking for is how to debug code in an event handler since I don't call the page directly and am not able to get output from the functions that it's running (that I'm currently aware of).
I know this is likely off topic for this forum but I'm not really sure where to turn for this.
Make sure xdebug is installed on the development computer where you are testing this, then open up your IDE and put a breakpoint at the start of your event handler. If that isn't hit, put a breakpoint on the code that triggers the event and step through it.
If, for some reason, you really can't install xdebug and step through the code (which is something that is essential for any serious PHP development), try using fopen and fwrite to dump information into a log file, whilst the event is happening.

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.

Eclipse Debugger Events

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.

find conflicts with subversive API

I am writing an eclipse plug-in to update some projects in my workspace. After the update, there may be conflicts. I want to show a dialog to the user if there are some conflicts in the updated project(s).
To update, I use the UpdateOperation, then I do a IResource.refreshLocal() on the updated project. To look for conflicts I use FileUtility.checkForResourcesPresenceRecursive(resources, IStateFilter.SF_CONFLICTING). Also tryed with IStateFilter.SF_CONTENT_CONFLICTING and IStateFilter.SF_TREE_CONFLICTING. Normally they return false.
When I run in debug mode, the first two return true. That brings me to think that there is some event that gets fired after the refresh and with the loss of time in debug mode, Subversive gets to know about it. Am I right ? What event is this ? It is not IResourceChangeEvent. Tryed to listen for POST_CHANGED with no luck.
Do you have a hint for me ? Thank you.
It was easier than I expected. The UpdateOperation (and also the CommitOperation and the MergeOperation) class extends AbstractConflictDetectionOperation that offers the hasUnresolvedConflicts() method. That does the trick ;)