Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/debug
diff options
context:
space:
mode:
authorMikhail Khodjaiants2004-06-14 20:46:18 +0000
committerMikhail Khodjaiants2004-06-14 20:46:18 +0000
commit9418154ba360139fe5f121e4fd5fb482d585911f (patch)
treeef27306cba01bfeac705cf8530e260e5261ef0de /debug
parent55cf39aba427ef25bf8e2c2581cfabceea9fc08d (diff)
downloadorg.eclipse.cdt-9418154ba360139fe5f121e4fd5fb482d585911f.tar.gz
org.eclipse.cdt-9418154ba360139fe5f121e4fd5fb482d585911f.tar.xz
org.eclipse.cdt-9418154ba360139fe5f121e4fd5fb482d585911f.zip
Implementation of the "Toggle Method Breakpoint" retargettable action.
Diffstat (limited to 'debug')
-rw-r--r--debug/org.eclipse.cdt.debug.ui/ChangeLog8
-rw-r--r--debug/org.eclipse.cdt.debug.ui/plugin.properties5
-rw-r--r--debug/org.eclipse.cdt.debug.ui/plugin.xml10
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties2
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageFunctionBreakpointActionDelegate.java158
-rw-r--r--debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java96
6 files changed, 164 insertions, 115 deletions
diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog
index 0bc7c5fb6da..5e779d8c2c9 100644
--- a/debug/org.eclipse.cdt.debug.ui/ChangeLog
+++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog
@@ -1,4 +1,12 @@
2004-06-14 Mikhail Khodjaiants
+ Implementation of the "Toggle Method Breakpoint" retargettable action.
+ * plugin.properties
+ * plugin.xml
+ * ActionMessages.properties
+ * ManageFunctionBreakpointActionDelegate.java
+ * ToggleBreakpointAdapter.java
+
+2004-06-14 Mikhail Khodjaiants
Added transparency to the icons.
* icons/full/cview16/sharedlibraries_view.gif
* icons/full/eview16/sharedlibraries_view.gif
diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.properties b/debug/org.eclipse.cdt.debug.ui/plugin.properties
index f51ad380d26..8d85c3e75b1 100644
--- a/debug/org.eclipse.cdt.debug.ui/plugin.properties
+++ b/debug/org.eclipse.cdt.debug.ui/plugin.properties
@@ -31,9 +31,8 @@ ShowDebuggerConsoleAction.tooltip=Show Debugger Console On Target Selection
AddBreakpoint.label=Toggle &Breakpoint
EnableBreakpoint.label=&Toggle Breakpoint Enabled
BreakpointProperties.label=Breakpoint P&roperties...
-GlobalManageBreakpointAction.label=Add/Remove Brea&kpoint (C/C++)
-ManageFunctionBreakpointAction.label=Add/Remove Breakpoint
-ManageFunctionBreakpointAction.tooltip=Add/Remove Function Breakpoint
+ManageFunctionBreakpointAction.label=Toggle Breakpoint
+ManageFunctionBreakpointAction.tooltip=Toggle Function/Method Breakpoint
BreakpointPropertiesAction.label=P&roperties...
GlobalManageWatchpointAction.label=Add &Watchpoint (C/C++)...
AddExpressionAction.label=Add &Expression...
diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml
index 4d2acf51f7c..694a5bcbbf4 100644
--- a/debug/org.eclipse.cdt.debug.ui/plugin.xml
+++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml
@@ -1349,6 +1349,16 @@
type="org.eclipse.debug.ui.actions.IRunToLineTarget">
</adapter>
</factory>
+ <factory
+ class="org.eclipse.cdt.debug.internal.ui.actions.RetargettableActionAdapterFactory"
+ adaptableType="org.eclipse.ui.views.contentoutline.ContentOutline">
+ <adapter
+ type="org.eclipse.debug.ui.actions.IToggleBreakpointsTarget">
+ </adapter>
+ <adapter
+ type="org.eclipse.debug.ui.actions.IRunToLineTarget">
+ </adapter>
+ </factory>
</extension>
<extension
point="org.eclipse.ui.themes">
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties
index 3d845c12f7c..8c744c0a61e 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ActionMessages.properties
@@ -41,3 +41,5 @@ ResumeAtLineActionDelegate.Operation_is_not_supported_1=Operation is not support
AddGlobalsActionDelegate.Error(s)_occured_adding_globals_1=Error(s) occured adding globals.
AbstractRefreshActionDelegate.Error_1=Error
AbstractRefreshActionDelegate.Error(s)_occurred_refreshing_the_view_1=Error(s) occurred refreshing the view.
+ManageFunctionBreakpointActionDelegate.Error_1=Error
+ManageFunctionBreakpointActionDelegate.Operation_failed_1=Operation failed.
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageFunctionBreakpointActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageFunctionBreakpointActionDelegate.java
index a904776ec88..e2877b9cc54 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageFunctionBreakpointActionDelegate.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ManageFunctionBreakpointActionDelegate.java
@@ -1,143 +1,81 @@
-/*
- *(c) Copyright QNX Software Systems Ltd. 2002.
- * All Rights Reserved.
+/**********************************************************************
+ * Copyright (c) 2004 QNX Software Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
*
- */
-
+ * Contributors:
+ * QNX Software Systems - Initial API and implementation
+ ***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
-import org.eclipse.cdt.core.model.ICElement;
-import org.eclipse.cdt.core.model.IFunction;
-import org.eclipse.cdt.core.model.IMethod;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionDelegate;
/**
- * Enter type comment.
- *
- * @since Apr 2, 2003
+ * The delegate of the "Toggle Function Breakpoint" action.
*/
-public class ManageFunctionBreakpointActionDelegate extends ActionDelegate
- implements IObjectActionDelegate
-{
-// private IFunction fFunction = null;
- private ICElement fElement = null;
+public class ManageFunctionBreakpointActionDelegate extends ActionDelegate implements IObjectActionDelegate {
- /**
- *
- */
- public ManageFunctionBreakpointActionDelegate()
- {
+ private ToggleBreakpointAdapter fBreakpointAdapter;
+
+ private IWorkbenchPart fTargetPart;
+
+ private ISelection fSelection;
+
+ public ManageFunctionBreakpointActionDelegate() {
+ fBreakpointAdapter = new ToggleBreakpointAdapter();
}
- /* (non-Javadoc)
+ /*(non-Javadoc)
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
*/
- public void setActivePart( IAction action, IWorkbenchPart targetPart )
- {
+ public void setActivePart( IAction action, IWorkbenchPart targetPart ) {
+ fTargetPart = targetPart;
}
- /* (non-Javadoc)
+ /*(non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
- public void run( IAction action )
- {
- if ( getMethod() != null )
- manageBreakpoint( getMethod() );
- else if ( getFunction() != null )
- manageBreakpoint( getFunction() );
+ public void run( IAction action ) {
+ try {
+ getBreakpointAdapter().toggleMethodBreakpoints( getTargetPart(), getSelection() );
+ }
+ catch( CoreException e ) {
+ DebugUIPlugin.errorDialog( getTargetPart().getSite().getShell(),
+ ActionMessages.getString( "ManageFunctionBreakpointActionDelegate.Error_1" ), //$NON-NLS-1$
+ ActionMessages.getString( "ManageFunctionBreakpointActionDelegate.Operation_failed_1" ), //$NON-NLS-1$
+ e.getStatus() );
+ }
}
- /* (non-Javadoc)
+ /*(non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
*/
- public void selectionChanged( IAction action, ISelection selection )
- {
- if ( selection instanceof IStructuredSelection )
- {
- Object element = ((IStructuredSelection)selection).getFirstElement();
- if ( element instanceof ICElement )
- {
- boolean enabled = enablesFor( (ICElement)element );
- action.setEnabled( enabled );
- if ( enabled )
- {
- setElement( (ICElement)element );
- return;
- }
- }
- }
- action.setEnabled( false );
- setElement( null );
+ public void selectionChanged( IAction action, ISelection selection ) {
+ setSelection( selection );
+ action.setEnabled( getBreakpointAdapter().canToggleMethodBreakpoints( getTargetPart(), getSelection() ) );
}
- public ICElement getElement()
- {
- return fElement;
+ private IWorkbenchPart getTargetPart() {
+ return fTargetPart;
}
- public void setElement( ICElement element )
- {
- fElement = element;
+ private ISelection getSelection() {
+ return fSelection;
}
- private boolean enablesFor( ICElement element )
- {
- // for now
- return true;
- }
-
- private void manageBreakpoint( IFunction function )
- {
-// try
-// {
-// ICFunctionBreakpoint breakpoint = CDebugModel.functionBreakpointExists( function );
-// if ( breakpoint != null )
-// {
-// DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
-// }
-// else
-// {
-// CDebugModel.createFunctionBreakpoint( function, true, 0, "", true ); //$NON-NLS-1$
-// }
-// }
-// catch( CoreException e )
-// {
-// CDebugUIPlugin.errorDialog( CDebugUIPlugin.getResourceString("internal.ui.actions.ManageFunctionBreakpointActionDelegate.Cannot_add_breakpoint"), e ); //$NON-NLS-1$
-// }
- }
-
- private IFunction getFunction()
- {
- return ( getElement() != null ) ? (IFunction)getElement().getAdapter( IFunction.class ) : null;
+ private ToggleBreakpointAdapter getBreakpointAdapter() {
+ return fBreakpointAdapter;
}
- private void manageBreakpoint( IMethod method )
- {
-// try
-// {
-// ICFunctionBreakpoint breakpoint = CDebugModel.methodBreakpointExists( method );
-// if ( breakpoint != null )
-// {
-// DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
-// }
-// else
-// {
-// CDebugModel.createMethodBreakpoint( method, true, 0, "", true ); //$NON-NLS-1$
-// }
-// }
-// catch( CoreException e )
-// {
-// CDebugUIPlugin.errorDialog( CDebugUIPlugin.getResourceString("internal.ui.actions.ManageFunctionBreakpointActionDelegate.Cannot_add_breakpoint"), e ); //$NON-NLS-1$
-// }
- }
-
- private IMethod getMethod()
- {
- return ( getElement() != null ) ? (IMethod)getElement().getAdapter( IMethod.class ) : null;
+ private void setSelection( ISelection selection ) {
+ fSelection = selection;
}
-}
+} \ No newline at end of file
diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java
index 11073baf53f..4eeeb1db2e9 100644
--- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java
+++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/ToggleBreakpointAdapter.java
@@ -10,8 +10,13 @@
***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
+import org.eclipse.cdt.core.model.CModelException;
+import org.eclipse.cdt.core.model.IFunction;
+import org.eclipse.cdt.core.model.ISourceRange;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.debug.core.CDIDebugModel;
import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint;
+import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.core.model.ICWatchpoint;
import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyEditorInput;
@@ -30,6 +35,7 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
@@ -152,13 +158,60 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/
public void toggleMethodBreakpoints( IWorkbenchPart part, ISelection selection ) throws CoreException {
- // TODO Auto-generated method stub
+ if ( selection instanceof IStructuredSelection ) {
+ IStructuredSelection ss = (IStructuredSelection)selection;
+ if ( ss.size() == 1 && ss.getFirstElement() instanceof IFunction ) {
+ IFunction function = (IFunction)ss.getFirstElement();
+ String sourceHandle = getSourceHandle( function );
+ IResource resource = getFunctionResource( function );
+ String functionName = getFunctionName( function );
+ ICFunctionBreakpoint breakpoint = CDIDebugModel.functionBreakpointExists( sourceHandle, resource, functionName );
+ if ( breakpoint != null ) {
+ DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
+ }
+ else {
+ int lineNumber = -1;
+ int charStart = -1;
+ int charEnd = -1;
+ try {
+ ISourceRange sourceRange = function.getSourceRange();
+ if ( sourceRange != null ) {
+ charStart = sourceRange.getStartPos();
+ charEnd = charStart + sourceRange.getLength();
+ // for now
+ if ( charEnd == 0 )
+ lineNumber = sourceRange.getStartLine();
+ }
+ }
+ catch( CModelException e ) {
+ DebugPlugin.log( e );
+ }
+ CDIDebugModel.createFunctionBreakpoint( sourceHandle,
+ resource,
+ functionName,
+ charStart,
+ charEnd,
+ lineNumber,
+ true,
+ 0,
+ "", //$NON-NLS-1$
+ true );
+ }
+ }
+ }
+
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/
public boolean canToggleMethodBreakpoints( IWorkbenchPart part, ISelection selection ) {
+ if ( selection instanceof IStructuredSelection ) {
+ IStructuredSelection ss = (IStructuredSelection)selection;
+ if ( ss.size() == 1 ) {
+ return ( ss.getFirstElement() instanceof IFunction );
+ }
+ }
return false;
}
@@ -254,7 +307,7 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
private String getSourceHandle( IEditorInput input ) throws CoreException {
if ( input instanceof IFileEditorInput ) {
- return ((IFileEditorInput)input).getFile().getFullPath().toOSString();
+ return ((IFileEditorInput)input).getFile().getLocation().toOSString();
}
if ( input instanceof IStorageEditorInput ) {
return ((IStorageEditorInput)input).getStorage().getName();
@@ -264,4 +317,43 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
}
return ""; //$NON-NLS-1$
}
+
+ private String getSourceHandle( IFunction function ) {
+ ITranslationUnit tu = function.getTranslationUnit();
+ if ( tu != null ) {
+ IResource resource = tu.getResource();
+ if ( resource != null ) {
+ return resource.getLocation().toOSString();
+ }
+ return tu.getPath().toOSString();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+ private IResource getFunctionResource( IFunction function ) {
+ ITranslationUnit tu = function.getTranslationUnit();
+ return (tu != null) ? tu.getResource() : function.getCProject().getProject();
+ }
+
+ private String getFunctionName( IFunction function ) {
+ String functionName = function.getElementName();
+ StringBuffer name = new StringBuffer( functionName );
+ if ( functionName.indexOf( "::" ) != -1 ) //$NON-NLS-1$
+ {
+ String[] params = function.getParameterTypes();
+ name.append( '(' );
+ if ( params.length == 0 ) {
+ name.append( "void" ); //$NON-NLS-1$
+ }
+ else {
+ for( int i = 0; i < params.length; ++i ) {
+ name.append( params[i] );
+ if ( i != params.length - 1 )
+ name.append( ',' );
+ }
+ }
+ name.append( ')' );
+ }
+ return name.toString();
+ }
}

Back to the top