Fixed the debugger client to work in Eclipse 3.1.
authorstefanbjarni <stefanbjarni>
Sun, 3 Jul 2005 01:36:32 +0000 (01:36 +0000)
committerstefanbjarni <stefanbjarni>
Sun, 3 Jul 2005 01:36:32 +0000 (01:36 +0000)
The method of integration of the debugger model into the debugger view appears to have changed from 3.0 to 3.1. I added implementations of
getAdapter() for PHPDebugTarget and PHPThread to properly add Launch
(e.g. Debug) View tree nodes for targets, threads and stack frames.

Fixed a live leak resulting from PHPDebugTarget not deregistering itself from
listening to breakpoint and debug events.

Added utility log methods to net.sourceforge.phpeclipse.PHPeclipsePlugin.

net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPDebugTarget.java
net.sourceforge.phpeclipse.debug.core/src/net/sourceforge/phpdt/internal/debug/core/model/PHPThread.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java

index 4a9dccb..c2ffdee 100644 (file)
@@ -13,6 +13,7 @@ package net.sourceforge.phpdt.internal.debug.core.model;
 
 import net.sourceforge.phpdt.internal.debug.core.PHPDBGProxy;
 import net.sourceforge.phpdt.internal.debug.core.PHPDebugCorePlugin;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
 import org.eclipse.core.resources.IMarkerDelta;
 import org.eclipse.debug.core.DebugEvent;
@@ -26,7 +27,10 @@ import org.eclipse.debug.core.model.IBreakpoint;
 import org.eclipse.debug.core.model.IDebugTarget;
 import org.eclipse.debug.core.model.IMemoryBlock;
 import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IStackFrame;
 import org.eclipse.debug.core.model.IThread;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.model.IWorkbenchAdapter;
 
 /**
  * Debug target for PHP debug model.
@@ -68,6 +72,7 @@ public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener, IDebugE
                threads = updatedThreads;
 
                fireChangeEvent();
+               fireThreadCreateEvent(phpThread);
        }
 
        private void fireChangeEvent() {
@@ -75,6 +80,11 @@ public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener, IDebugE
                DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
        }
 
+       private void fireThreadCreateEvent(PHPThread phpThread) {
+               DebugEvent ev = new DebugEvent(phpThread, DebugEvent.CREATE);
+               DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { ev });
+       }
+
        protected PHPThread getThreadById(int id) {
                for (int i = 0; i < threads.length; i++) {
                        if (threads[i].getId() == id) {
@@ -134,6 +144,9 @@ public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener, IDebugE
                this.threads = new PHPThread[0];
                isTerminated = true;
                fireChangeEvent();
+               IBreakpointManager manager= DebugPlugin.getDefault().getBreakpointManager();
+               manager.removeBreakpointListener(this);
+               DebugPlugin.getDefault().removeDebugEventListener(this);
        }
 
        public boolean canResume() {
@@ -194,6 +207,35 @@ public class PHPDebugTarget implements IPHPDebugTarget, ILaunchListener, IDebugE
        }
 
        public Object getAdapter(Class arg0) {
+               if (IWorkbenchAdapter.class.equals(arg0)) {
+                       return new IWorkbenchAdapter() {
+                               public Object[] getChildren(Object o) {
+                                       Object[] children = null;
+                                       IThread[] threads = getThreads();
+                                       if (null != threads) {
+                                               children = new Object[threads.length];
+                                               for (int i = 0; i < threads.length; ++i) 
+                                                       children[i] = threads[i];
+                                       }
+                                       return children;
+                               }
+                               public ImageDescriptor getImageDescriptor(Object object) {
+                                       return null;
+                               }
+                               public String getLabel(Object o) {
+                                       String label = "(Unable to look up name... check error log)";
+                                       try {
+                                               label = getName();
+                                       } catch (DebugException x) {
+                                               PHPeclipsePlugin.log(label, x);
+                                       }
+                                       return label;
+                               }
+                               public Object getParent(Object o) {
+                                       return PHPDebugTarget.this.getLaunch();
+                               }
+                       };
+               }
                return null;
        }
 
index 2512b10..d630b3c 100644 (file)
@@ -11,6 +11,8 @@ Contributors:
 **********************************************************************/
 package net.sourceforge.phpdt.internal.debug.core.model;
 
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+
 import org.eclipse.debug.core.DebugEvent;
 import org.eclipse.debug.core.DebugException;
 import org.eclipse.debug.core.DebugPlugin;
@@ -19,6 +21,8 @@ import org.eclipse.debug.core.model.IBreakpoint;
 import org.eclipse.debug.core.model.IDebugTarget;
 import org.eclipse.debug.core.model.IStackFrame;
 import org.eclipse.debug.core.model.IThread;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.model.IWorkbenchAdapter;
 
 public class PHPThread implements IThread {
 
@@ -175,6 +179,33 @@ public class PHPThread implements IThread {
        }
 
        public Object getAdapter(Class arg0) {
+               if (IWorkbenchAdapter.class.equals(arg0)) {
+                       return new IWorkbenchAdapter() {
+                               public Object[] getChildren(Object o) {
+                                       Object[] children = null;
+                                       try {
+                                               IStackFrame[] frames = getStackFrames();
+                                               if (null != frames) {
+                                                       children = new Object[frames.length];
+                                                       for (int i = 0; i < frames.length; ++i) 
+                                                               children[i] = frames[i];
+                                               }
+                                       } catch (DebugException x) {
+                                               PHPeclipsePlugin.log("Unable to get stack frames.", x);
+                                       }
+                                       return children;
+                               }
+                               public ImageDescriptor getImageDescriptor(Object object) {
+                                       return null;
+                               }
+                               public String getLabel(Object o) {
+                                       throw new UnsupportedOperationException();
+                               }
+                               public Object getParent(Object o) {
+                                       return getDebugTarget();
+                               }
+                       };
+               }
                return null;
        }
 
index 6996224..19583f5 100644 (file)
@@ -560,8 +560,12 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
     getDefault().getLog().log(status);
   }
 
-  public static void log(Throwable e) {
-    log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, "PHPeclipsePlugin.internalErrorOccurred", e)); //$NON-NLS-1$
+  public static void log(Throwable t) {
+         log("PHPeclipsePlugin.internalErrorOccurred", t); //$NON-NLS-1$
+  }
+  
+  public static void log(String message, Throwable t) {
+    log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, t)); 
   }
 
   public static void logErrorMessage(String message) {