Friday, August 10, 2007

Eclipse tip : How to get the current debug file ?

I think its trivial for a lot of people but I have been searching for a long time in google before to found how to do it. I suppose you have the current debug thread (for instance from a debug event).

the bad way (does not work):

PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
public void run() {
IEditorPart ed = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if (ed.getEditorInput() instanceof IFileEditorInput) {
String currentDebugFile = ((IFileEditorInput)ed.getEditorInput()).getFile().getLocation().toOSString();
}
}
});

the correct way :

Object o = thread.getLaunch().getSourceLocator().getSourceElement(thread.getTopStackFrame());
if (o instanceof IFile) {
String currentDebugFile = ((IFile) o).getLocation().toOSString();
}

1 comment:

garden arbours said...

Thanks for the code, it is always good to know.