mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
Bug 306555: Support for Cast To Type and Display As Array for DSF-GDB
This commit is contained in:
parent
709e637157
commit
61d7272149
4 changed files with 118 additions and 5 deletions
|
@ -7,9 +7,11 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Freescale Semiconductor - initial API and implementation
|
* Freescale Semiconductor - initial API and implementation
|
||||||
|
* Axel Mueller - Bug 306555 - Add support for cast to type / view as array (IExpressions2)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.dsf.gdb.internal.ui.viewmodel;
|
package org.eclipse.cdt.dsf.gdb.internal.ui.viewmodel;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.dsf.debug.internal.ui.viewmodel.DsfCastToTypeSupport;
|
||||||
import org.eclipse.cdt.dsf.debug.ui.IDsfDebugUIConstants;
|
import org.eclipse.cdt.dsf.debug.ui.IDsfDebugUIConstants;
|
||||||
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.DisabledExpressionVMNode;
|
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.DisabledExpressionVMNode;
|
||||||
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.ExpressionManagerVMNode;
|
import org.eclipse.cdt.dsf.debug.ui.viewmodel.expression.ExpressionManagerVMNode;
|
||||||
|
@ -21,6 +23,7 @@ import org.eclipse.cdt.dsf.debug.ui.viewmodel.register.RegisterGroupVMNode;
|
||||||
import org.eclipse.cdt.dsf.debug.ui.viewmodel.register.RegisterVMNode;
|
import org.eclipse.cdt.dsf.debug.ui.viewmodel.register.RegisterVMNode;
|
||||||
import org.eclipse.cdt.dsf.debug.ui.viewmodel.register.SyncRegisterDataAccess;
|
import org.eclipse.cdt.dsf.debug.ui.viewmodel.register.SyncRegisterDataAccess;
|
||||||
import org.eclipse.cdt.dsf.debug.ui.viewmodel.variable.SyncVariableDataAccess;
|
import org.eclipse.cdt.dsf.debug.ui.viewmodel.variable.SyncVariableDataAccess;
|
||||||
|
import org.eclipse.cdt.dsf.debug.ui.viewmodel.variable.VariableVMNode;
|
||||||
import org.eclipse.cdt.dsf.service.DsfSession;
|
import org.eclipse.cdt.dsf.service.DsfSession;
|
||||||
import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMAdapter;
|
import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMAdapter;
|
||||||
import org.eclipse.cdt.dsf.ui.viewmodel.IRootVMNode;
|
import org.eclipse.cdt.dsf.ui.viewmodel.IRootVMNode;
|
||||||
|
@ -32,6 +35,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationCont
|
||||||
* A specialization of ExpressionVMProvider that uses a GDB-specific variable VM
|
* A specialization of ExpressionVMProvider that uses a GDB-specific variable VM
|
||||||
* node. To understand why this is necessary, see GdbVariableVMNode.
|
* node. To understand why this is necessary, see GdbVariableVMNode.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("restriction")
|
||||||
public class GdbExpressionVMProvider extends ExpressionVMProvider {
|
public class GdbExpressionVMProvider extends ExpressionVMProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,6 +103,11 @@ public class GdbExpressionVMProvider extends ExpressionVMProvider {
|
||||||
IExpressionVMNode variableNode = new GdbVariableVMNode(this, getSession(), syncvarDataAccess);
|
IExpressionVMNode variableNode = new GdbVariableVMNode(this, getSession(), syncvarDataAccess);
|
||||||
addChildNodes(variableNode, new IExpressionVMNode[] {variableNode});
|
addChildNodes(variableNode, new IExpressionVMNode[] {variableNode});
|
||||||
|
|
||||||
|
/* Wire up the casting support. IExpressions2 service is always available
|
||||||
|
* for gdb. No need to call hookUpCastingSupport */
|
||||||
|
((VariableVMNode) variableNode).setCastToTypeSupport(
|
||||||
|
new DsfCastToTypeSupport(getSession(), GdbExpressionVMProvider.this, syncvarDataAccess));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tell the expression node which sub-nodes it will directly support. It is very important
|
* Tell the expression node which sub-nodes it will directly support. It is very important
|
||||||
* that the variables node be the last in this chain. The model assumes that there is some
|
* that the variables node be the last in this chain. The model assumes that there is some
|
||||||
|
|
|
@ -7,10 +7,13 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Freescale Semiconductor - initial API and implementation
|
* Freescale Semiconductor - initial API and implementation
|
||||||
|
* Axel Mueller - Bug 306555 - Add support for cast to type / view as array (IExpressions2)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.dsf.gdb.internal.ui.viewmodel;
|
package org.eclipse.cdt.dsf.gdb.internal.ui.viewmodel;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.dsf.debug.internal.ui.viewmodel.DsfCastToTypeSupport;
|
||||||
import org.eclipse.cdt.dsf.debug.ui.viewmodel.variable.SyncVariableDataAccess;
|
import org.eclipse.cdt.dsf.debug.ui.viewmodel.variable.SyncVariableDataAccess;
|
||||||
|
import org.eclipse.cdt.dsf.debug.ui.viewmodel.variable.VariableVMNode;
|
||||||
import org.eclipse.cdt.dsf.debug.ui.viewmodel.variable.VariableVMProvider;
|
import org.eclipse.cdt.dsf.debug.ui.viewmodel.variable.VariableVMProvider;
|
||||||
import org.eclipse.cdt.dsf.service.DsfSession;
|
import org.eclipse.cdt.dsf.service.DsfSession;
|
||||||
import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMAdapter;
|
import org.eclipse.cdt.dsf.ui.viewmodel.AbstractVMAdapter;
|
||||||
|
@ -23,6 +26,7 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationCont
|
||||||
* A specialization of VariableVMProvider that uses a GDB-specific variable VM
|
* A specialization of VariableVMProvider that uses a GDB-specific variable VM
|
||||||
* node. To understand why this is necessary, see GdbVariableVMNode.
|
* node. To understand why this is necessary, see GdbVariableVMNode.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("restriction")
|
||||||
public class GdbVariableVMProvider extends VariableVMProvider {
|
public class GdbVariableVMProvider extends VariableVMProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,6 +53,11 @@ public class GdbVariableVMProvider extends VariableVMProvider {
|
||||||
IVMNode subExpressioNode = new GdbVariableVMNode(this, getSession(), varAccess);
|
IVMNode subExpressioNode = new GdbVariableVMNode(this, getSession(), varAccess);
|
||||||
addChildNodes(rootNode, new IVMNode[] { subExpressioNode });
|
addChildNodes(rootNode, new IVMNode[] { subExpressioNode });
|
||||||
|
|
||||||
|
/* Wire up the casting support. IExpressions2 service is always available
|
||||||
|
* for gdb. No need to call hookUpCastingSupport */
|
||||||
|
((VariableVMNode) subExpressioNode).setCastToTypeSupport(
|
||||||
|
new DsfCastToTypeSupport(getSession(), GdbVariableVMProvider.this, varAccess));
|
||||||
|
|
||||||
// Configure the sub-expression node to be a child of itself. This way the content
|
// Configure the sub-expression node to be a child of itself. This way the content
|
||||||
// provider will recursively drill-down the variable hierarchy.
|
// provider will recursively drill-down the variable hierarchy.
|
||||||
addChildNodes(subExpressioNode, new IVMNode[] { subExpressioNode });
|
addChildNodes(subExpressioNode, new IVMNode[] { subExpressioNode });
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Wind River Systems - initial API and implementation
|
* Wind River Systems - initial API and implementation
|
||||||
* Ericsson - Modified for handling of multiple execution contexts
|
* Ericsson - Modified for handling of multiple execution contexts
|
||||||
|
* Axel Mueller - Bug 306555 - Add support for cast to type / view as array (IExpressions2)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.dsf.mi.service;
|
package org.eclipse.cdt.dsf.mi.service;
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ import org.eclipse.cdt.dsf.datamodel.DMContexts;
|
||||||
import org.eclipse.cdt.dsf.datamodel.IDMContext;
|
import org.eclipse.cdt.dsf.datamodel.IDMContext;
|
||||||
import org.eclipse.cdt.dsf.debug.service.ICachingService;
|
import org.eclipse.cdt.dsf.debug.service.ICachingService;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IExpressions;
|
import org.eclipse.cdt.dsf.debug.service.IExpressions;
|
||||||
|
import org.eclipse.cdt.dsf.debug.service.IExpressions2;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
|
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IRunControl;
|
import org.eclipse.cdt.dsf.debug.service.IRunControl;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryChangedEvent;
|
import org.eclipse.cdt.dsf.debug.service.IMemory.IMemoryChangedEvent;
|
||||||
|
@ -65,7 +67,7 @@ import org.osgi.framework.BundleContext;
|
||||||
*
|
*
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
*/
|
*/
|
||||||
public class MIExpressions extends AbstractDsfService implements IExpressions, ICachingService {
|
public class MIExpressions extends AbstractDsfService implements IExpressions2, ICachingService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A format that gives more details about an expression and supports pretty-printing
|
* A format that gives more details about an expression and supports pretty-printing
|
||||||
|
@ -478,6 +480,7 @@ public class MIExpressions extends AbstractDsfService implements IExpressions, I
|
||||||
|
|
||||||
// Register this service.
|
// Register this service.
|
||||||
register(new String[] { IExpressions.class.getName(),
|
register(new String[] { IExpressions.class.getName(),
|
||||||
|
IExpressions2.class.getName(),
|
||||||
MIExpressions.class.getName() },
|
MIExpressions.class.getName() },
|
||||||
new Hashtable<String, String>());
|
new Hashtable<String, String>());
|
||||||
|
|
||||||
|
@ -1043,4 +1046,82 @@ public class MIExpressions extends AbstractDsfService implements IExpressions, I
|
||||||
varManager.markAllOutOfDate();
|
varManager.markAllOutOfDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A casted or array-displayed expression.
|
||||||
|
* @since 3.0 */
|
||||||
|
public class CastedExpressionDMC extends MIExpressionDMC implements ICastedExpressionDMContext {
|
||||||
|
|
||||||
|
private final CastInfo castInfo;
|
||||||
|
/** if non-null, interpret result as this type rather than the raw expression's type */
|
||||||
|
private String expression;
|
||||||
|
|
||||||
|
public CastedExpressionDMC(MIExpressionDMC exprDMC, CastInfo castInfo) {
|
||||||
|
super(getSession().getId(), exprDMC.getExpression(), exprDMC.getRelativeExpression(), exprDMC);
|
||||||
|
this.castInfo = castInfo;
|
||||||
|
|
||||||
|
String castType = castInfo.getTypeString();
|
||||||
|
String castExpression = exprDMC.getExpression();
|
||||||
|
int castingLength = castInfo.getArrayCount();
|
||||||
|
int castingIndex = castInfo.getArrayStartIndex();
|
||||||
|
|
||||||
|
// cast to type
|
||||||
|
if (castType != null) {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append('(').append(castType).append(')');
|
||||||
|
buffer.append('(').append(castExpression).append(')');
|
||||||
|
castExpression = buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// cast to array (can be in addition to cast to type)
|
||||||
|
if (castingLength > 0) {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("*("); //$NON-NLS-1$
|
||||||
|
buffer.append('(').append(castExpression).append(')');
|
||||||
|
buffer.append('+').append(castingIndex).append(')');
|
||||||
|
buffer.append('@').append(castingLength);
|
||||||
|
castExpression = buffer.toString();
|
||||||
|
}
|
||||||
|
this.expression = castExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.dsf.debug.service.IExpressions2.ICastedExpressionDMContext#getCastInfo()
|
||||||
|
*/
|
||||||
|
public CastInfo getCastInfo() {
|
||||||
|
return castInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.dsf.mi.service.MIExpressions.java#getExpression()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getExpression() {
|
||||||
|
return expression;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return True if the two objects are equal, false otherwise.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
return super.equals(other)
|
||||||
|
&& castInfo.equals(((CastedExpressionDMC) other).castInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.dsf.debug.service.IExpressions2#createCastedExpression(org.eclipse.cdt.dsf.datamodel.IDMContext, java.lang.String, org.eclipse.cdt.dsf.debug.service.IExpressions2.ICastedExpressionDMContext)
|
||||||
|
*/
|
||||||
|
/** @since 3.0 */
|
||||||
|
public ICastedExpressionDMContext createCastedExpression(
|
||||||
|
IExpressionDMContext exprDMC, CastInfo castInfo) {
|
||||||
|
if (exprDMC instanceof MIExpressionDMC) {
|
||||||
|
CastedExpressionDMC castedDMC = new CastedExpressionDMC(
|
||||||
|
(MIExpressionDMC) exprDMC, castInfo);
|
||||||
|
return castedDMC;
|
||||||
|
} else {
|
||||||
|
assert false;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
* Ericsson - Modified for handling of multiple execution contexts
|
* Ericsson - Modified for handling of multiple execution contexts
|
||||||
* Ericsson - Major updates for GDB/MI implementation
|
* Ericsson - Major updates for GDB/MI implementation
|
||||||
* Ericsson - Major re-factoring to deal with children
|
* Ericsson - Major re-factoring to deal with children
|
||||||
|
* Axel Mueller - Bug 306555 - Add support for cast to type / view as array (IExpressions2)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.dsf.mi.service;
|
package org.eclipse.cdt.dsf.mi.service;
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
|
||||||
import org.eclipse.cdt.dsf.datamodel.DMContexts;
|
import org.eclipse.cdt.dsf.datamodel.DMContexts;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IExpressions;
|
import org.eclipse.cdt.dsf.debug.service.IExpressions;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
|
import org.eclipse.cdt.dsf.debug.service.IExpressions.IExpressionDMContext;
|
||||||
|
import org.eclipse.cdt.dsf.debug.service.IExpressions2.CastInfo;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
|
import org.eclipse.cdt.dsf.debug.service.IFormattedValues;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext;
|
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMContext;
|
||||||
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData;
|
import org.eclipse.cdt.dsf.debug.service.IFormattedValues.FormattedValueDMData;
|
||||||
|
@ -47,6 +49,7 @@ import org.eclipse.cdt.dsf.gdb.GDBTypeParser;
|
||||||
import org.eclipse.cdt.dsf.gdb.GDBTypeParser.GDBType;
|
import org.eclipse.cdt.dsf.gdb.GDBTypeParser.GDBType;
|
||||||
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
|
import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin;
|
||||||
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl.ITraceRecordSelectedChangedDMEvent;
|
import org.eclipse.cdt.dsf.gdb.service.IGDBTraceControl.ITraceRecordSelectedChangedDMEvent;
|
||||||
|
import org.eclipse.cdt.dsf.mi.service.MIExpressions.CastedExpressionDMC;
|
||||||
import org.eclipse.cdt.dsf.mi.service.MIExpressions.ExpressionInfo;
|
import org.eclipse.cdt.dsf.mi.service.MIExpressions.ExpressionInfo;
|
||||||
import org.eclipse.cdt.dsf.mi.service.MIExpressions.MIExpressionDMC;
|
import org.eclipse.cdt.dsf.mi.service.MIExpressions.MIExpressionDMC;
|
||||||
import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
|
import org.eclipse.cdt.dsf.mi.service.command.CommandFactory;
|
||||||
|
@ -645,10 +648,21 @@ public class MIVariableManager implements ICommandControl {
|
||||||
if (isArray()) {
|
if (isArray()) {
|
||||||
// We can trust the numChildrenHint value for arrays.
|
// We can trust the numChildrenHint value for arrays.
|
||||||
ExpressionInfo[] childrenOfArray = new ExpressionInfo[getNumChildrenHint()];
|
ExpressionInfo[] childrenOfArray = new ExpressionInfo[getNumChildrenHint()];
|
||||||
|
String exprName = exprDmc.getExpression();
|
||||||
|
|
||||||
|
int castingLength = 0;
|
||||||
|
int castingIndex = 0;
|
||||||
|
// in case of casts, need to resolve that before dereferencing, to be safe
|
||||||
|
if ( exprDmc instanceof CastedExpressionDMC ) {
|
||||||
|
CastInfo castInfo = ((CastedExpressionDMC)exprDmc).getCastInfo();
|
||||||
|
castingLength = castInfo.getArrayCount();
|
||||||
|
castingIndex = castInfo.getArrayStartIndex();
|
||||||
|
if (castingLength > 0)
|
||||||
|
exprName = '(' + exprName + ')';
|
||||||
|
}
|
||||||
for (int i= 0; i < childrenOfArray.length; i++) {
|
for (int i= 0; i < childrenOfArray.length; i++) {
|
||||||
String indexStr = "[" + i + "]";//$NON-NLS-1$//$NON-NLS-2$
|
String fullExpr = exprName + "[" + i + "]";//$NON-NLS-1$//$NON-NLS-2$
|
||||||
String fullExpr = exprDmc.getExpression() + indexStr;
|
String relExpr = exprDmc.getRelativeExpression() + "[" + (castingIndex + i) + "]";//$NON-NLS-1$//$NON-NLS-2$
|
||||||
String relExpr = exprDmc.getRelativeExpression() + indexStr;
|
|
||||||
|
|
||||||
childrenOfArray[i] = new ExpressionInfo(fullExpr, relExpr);
|
childrenOfArray[i] = new ExpressionInfo(fullExpr, relExpr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue