diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataEvaluateExpressionInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataEvaluateExpressionInfo.java index 1fae2a65119..dbd80a030a8 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataEvaluateExpressionInfo.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIDataEvaluateExpressionInfo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2012 QNX Software Systems and others. + * Copyright (c) 2000, 2014 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,6 +9,7 @@ * QNX Software Systems - Initial API and implementation * Wind River Systems - Modified for new DSF Reference Implementation * Mathias Kunter - use MIConst.getString which is for human consumption (Bug 307311) + * Vladimir Prus (Mentor Graphics) - use MIResultRecord.getMIValue *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command.output; @@ -27,15 +28,9 @@ public class MIDataEvaluateExpressionInfo extends MIInfo { MIOutput out = getMIOutput(); MIResultRecord outr = out.getMIResultRecord(); if (outr != null) { - MIResult[] results = outr.getMIResults(); - for (int i = 0; i < results.length; i++) { - String var = results[i].getVariable(); - if (var.equals("value")) { //$NON-NLS-1$ - MIValue value = results[i].getMIValue(); - if (value instanceof MIConst) { - fValue = ((MIConst)value).getString(); - } - } + MIValue value = outr.getField("value"); //$NON-NLS-1$ + if (value instanceof MIConst) { + fValue = ((MIConst)value).getString(); } } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIResultRecord.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIResultRecord.java index e2f52193619..d5fb51b566f 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIResultRecord.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIResultRecord.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2014 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation * Wind River Systems - Modified for new DSF Reference Implementation + * Vladimir Prus (Mentor Graphics) - Add getMIValue. *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command.output; @@ -23,10 +24,9 @@ public class MIResultRecord { public final static String ERROR ="error"; //$NON-NLS-1$ public final static String EXIT ="exit"; //$NON-NLS-1$ - static final MIResult[] nullResults = new MIResult[0]; - MIResult[] results = nullResults; String resultClass = ""; //$NON-NLS-1$ int token = -1; + MITuple value = new MITuple(); public int getToken() { return token; @@ -47,23 +47,30 @@ public class MIResultRecord { } public MIResult[] getMIResults() { - return results; + return value.getMIResults(); } public void setMIResults(MIResult[] res) { - results = res; + value.setMIResults(res); + } + + /** Return the value of the named field in this record. + * @since 4.6 + */ + public MIValue getField(String name) { + return value.getField(name); } @Override public String toString() { StringBuffer buffer = new StringBuffer(); if (token > 0) { - buffer.append(token); + buffer.append(token); } buffer.append('^').append(resultClass); - for (int i = 0; i < results.length; i++) { - buffer.append(',').append(results[i].toString()); - } + + if (value.getMIResults().length != 0) + buffer.append(value.toString(",", "")); //$NON-NLS-1$ //$NON-NLS-2$ return buffer.toString(); } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStackInfoDepthInfo.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStackInfoDepthInfo.java index 90e6306fe06..628d0363706 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStackInfoDepthInfo.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MIStackInfoDepthInfo.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Ericsson and others. + * Copyright (c) 2007, 2014 Ericsson and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,6 +7,7 @@ * * Contributors: * Ericsson - Initial Implementation + * Vladimir Prus (Mentor Graphics) - Use MITuple.getMIValue. *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command.output; @@ -27,19 +28,12 @@ public class MIStackInfoDepthInfo extends MIInfo { MIOutput out = getMIOutput(); MIResultRecord rr = out.getMIResultRecord(); if (rr != null) { - MIResult[] results = rr.getMIResults(); - for (int i = 0; i < results.length; i++) { - String var = results[i].getVariable(); - - if (var.equals("depth")) { //$NON-NLS-1$ - MIValue value = results[i].getMIValue(); - if (value instanceof MIConst) { - String str = ((MIConst)value).getString(); - try { - depth = Integer.parseInt(str.trim()); - } catch (NumberFormatException e) { - } - } + MIValue value = rr.getField("depth"); //$NON-NLS-1$ + if (value instanceof MIConst) { + String str = ((MIConst)value).getString(); + try { + depth = Integer.parseInt(str.trim()); + } catch (NumberFormatException e) { } } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java index 444a80a2847..682f5b341ac 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/mi/service/command/output/MITuple.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2014 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,19 +8,25 @@ * Contributors: * QNX Software Systems - Initial API and implementation * Wind River Systems - Modified for new DSF Reference Implementation + * Vladimir Prus (Mentor Graphics) - Add getMIValue method. *******************************************************************************/ package org.eclipse.cdt.dsf.mi.service.command.output; +import java.util.HashMap; +import java.util.Map; + /** * GDB/MI tuple value. */ public class MITuple extends MIValue { - final static MIResult[] nullResults = new MIResult[0]; - final static MIValue[] nullValues = new MIValue[0]; - MIResult[] results = nullResults; - MIValue[] values = nullValues; + final private static MIResult[] NULL_RESULTS = new MIResult[0]; + final private static MIValue[] NULL_VALUES = new MIValue[0]; + + private MIResult[] results = NULL_RESULTS; + private MIValue[] values = NULL_VALUES; + private Map name2value; public MIResult[] getMIResults() { return results; @@ -28,20 +34,43 @@ public class MITuple extends MIValue { public void setMIResults(MIResult[] res) { results = res; + name2value = null; } public MIValue[] getMIValues() { return values; } + /** Return the value of the specified field of this tuple. + * + * @since 4.6 + */ + public MIValue getField(String name) { + if (name2value == null) { + name2value = new HashMap(); + for (MIResult r : results) { + name2value.put(r.getVariable(), r.getMIValue()); + } + } + return name2value.get(name); + } + public void setMIValues(MIValue[] vals) { values = vals; } @Override public String toString() { + return toString("{", "}"); //$NON-NLS-1$ //$NON-NLS-2$ + } + + // Return comma-separated values, with start and end prepended and appended + // Intentionally package private, should only be used by ourselves and + // MIResultRecord. + String toString(String start, String end) + { StringBuffer buffer = new StringBuffer(); - buffer.append('{'); + buffer.append(start); for (int i = 0; i < results.length; i++) { if (i != 0) { buffer.append(','); @@ -54,7 +83,7 @@ public class MITuple extends MIValue { } buffer.append(values[i].toString()); } - buffer.append('}'); + buffer.append(end); return buffer.toString(); } }