Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Piech2012-10-30 14:41:48 -0400
committerPawel Piech2012-10-30 14:43:00 -0400
commit4d02730830a61dbf5178db62807eaa465cb18e6b (patch)
treecb97f4592b8439751ea7d6737b562bbf1543b566 /dsf/org.eclipse.cdt.examples.dsf.pda
parent76b231ca15a925da14c240b1e49e7bd479e802b7 (diff)
downloadorg.eclipse.cdt-4d02730830a61dbf5178db62807eaa465cb18e6b.tar.gz
org.eclipse.cdt-4d02730830a61dbf5178db62807eaa465cb18e6b.tar.xz
org.eclipse.cdt-4d02730830a61dbf5178db62807eaa465cb18e6b.zip
DSF - Added support for arrays in PDA example.
Diffstat (limited to 'dsf/org.eclipse.cdt.examples.dsf.pda')
-rw-r--r--dsf/org.eclipse.cdt.examples.dsf.pda/pdavm/src/org/eclipse/cdt/examples/pdavm/PDAVirtualMachine.java76
-rw-r--r--dsf/org.eclipse.cdt.examples.dsf.pda/samples/arrays.pda14
-rw-r--r--dsf/org.eclipse.cdt.examples.dsf.pda/src/org/eclipse/cdt/examples/dsf/pda/service/PDAExpressions.java2
3 files changed, 87 insertions, 5 deletions
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda/pdavm/src/org/eclipse/cdt/examples/pdavm/PDAVirtualMachine.java b/dsf/org.eclipse.cdt.examples.dsf.pda/pdavm/src/org/eclipse/cdt/examples/pdavm/PDAVirtualMachine.java
index 949b439f6d..24bcb448e3 100644
--- a/dsf/org.eclipse.cdt.examples.dsf.pda/pdavm/src/org/eclipse/cdt/examples/pdavm/PDAVirtualMachine.java
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda/pdavm/src/org/eclipse/cdt/examples/pdavm/PDAVirtualMachine.java
@@ -197,9 +197,55 @@ public class PDAVirtualMachine {
fPC = pc;
}
+ private int parseArrayParam(String name) {
+ int lb = name.indexOf('[');
+ int rb = name.indexOf(']', lb);
+ if (rb < 0) return -1;
+ String paramStr = name.substring(lb + 1, rb);
+ if (paramStr.length() == 0) return -1;
+
+ try {
+ return Integer.parseInt(name.substring(lb + 1, rb));
+ } catch (NumberFormatException e) {} // Not a number
+
+ Object paramVar = fLocalVariables.get(paramStr);
+ if (paramVar instanceof Integer) {
+ return (Integer)paramVar;
+ }
+ return -1;
+ }
+
+ void declare(String name) {
+ Object value = Integer.valueOf(0);
+ if (name.startsWith("$")) {
+ setRegisterValue(name, value);
+ } else if (name.indexOf('[') >= 0) {
+ int size = parseArrayParam(name);
+ if (size >= 0) {
+ String arrayName = name.substring(0, name.indexOf('['));
+ Object[] array = new Object[size];
+ for (int i = 0; i < size; i++) {
+ array[i] = value;
+ }
+ fLocalVariables.put(arrayName, array);
+ }
+ } else {
+ fLocalVariables.put(name, value);
+ }
+ }
+
void set(String name, Object value) {
if (name.startsWith("$")) {
setRegisterValue(name, value);
+ } else if (name.indexOf('[') >= 0) {
+ int index = parseArrayParam(name);
+ if (index >=0) {
+ String arrayName = name.substring(0, name.indexOf('['));
+ Object array = fLocalVariables.get(arrayName);
+ if (array instanceof Object[] && ((Object[])array).length > index) {
+ ((Object[])array)[index] = value;
+ }
+ }
} else {
fLocalVariables.put(name, value);
}
@@ -208,6 +254,16 @@ public class PDAVirtualMachine {
Object get(String name) {
if (name.startsWith("$")) {
return getRegisterValue(name);
+ } else if (name.indexOf('[') >= 0) {
+ int index = parseArrayParam(name);
+ if (index >= 0) {
+ String arrayName = name.substring(0, name.indexOf('['));
+ Object array = fLocalVariables.get(arrayName);
+ if (array instanceof Object[] && ((Object[])array).length > index) {
+ return ((Object[])array)[index];
+ }
+ }
+ return null;
} else {
return fLocalVariables.get(name);
}
@@ -716,6 +772,14 @@ public class PDAVirtualMachine {
}
}
+ Object value = frame.fLocalVariables.get(var);
+ if (value instanceof Object[]) {
+ int size = ((Object[])value).length;
+ for (int i = 0; i < size; i++) {
+ children.add(var + "[" + Integer.toString(i) + "]");
+ }
+ }
+
StringBuffer result = new StringBuffer();
for (String child : children) {
result.append(child);
@@ -1032,10 +1096,12 @@ public class PDAVirtualMachine {
buf.append('|');
buf.append(frame.fFunction);
for (String var : frame.fLocalVariables.keySet()) {
- if (var.indexOf('.') == -1) {
- buf.append('|');
- buf.append(var);
+ if (var.indexOf('.') >= 0) continue;
+ if (var.indexOf('[') >= 0) {
+ var = var.substring(0, var.indexOf('['));
}
+ buf.append('|');
+ buf.append(var);
}
return buf.toString();
}
@@ -1153,6 +1219,8 @@ public class PDAVirtualMachine {
Object val = frame.get(var);
if (val == null) {
sendCommandResponse("error: variable undefined\n");
+ } else if (val instanceof Object[]) {
+ sendCommandResponse("[" + Integer.toString(((Object[])val).length) + "]" + "\n");
} else {
sendCommandResponse(val.toString() + "\n");
}
@@ -1362,7 +1430,7 @@ public class PDAVirtualMachine {
void iVar(PDAThread thread, Args args) {
String var = args.getNextStringArg();
- thread.fCurrentFrame.set(var, 0);
+ thread.fCurrentFrame.declare(var);
}
void iInternalEndEval(PDAThread thread, Args args) {
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda/samples/arrays.pda b/dsf/org.eclipse.cdt.examples.dsf.pda/samples/arrays.pda
new file mode 100644
index 0000000000..6c5056c6e3
--- /dev/null
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda/samples/arrays.pda
@@ -0,0 +1,14 @@
+var a[10000]
+var i
+push 10000
+pop $i
+:start
+push $i
+dec
+pop $i
+push $i
+pop $a[i]
+push $i
+branch_not_zero start
+halt
+
diff --git a/dsf/org.eclipse.cdt.examples.dsf.pda/src/org/eclipse/cdt/examples/dsf/pda/service/PDAExpressions.java b/dsf/org.eclipse.cdt.examples.dsf.pda/src/org/eclipse/cdt/examples/dsf/pda/service/PDAExpressions.java
index eebb3013c6..04b03b75a7 100644
--- a/dsf/org.eclipse.cdt.examples.dsf.pda/src/org/eclipse/cdt/examples/dsf/pda/service/PDAExpressions.java
+++ b/dsf/org.eclipse.cdt.examples.dsf.pda/src/org/eclipse/cdt/examples/dsf/pda/service/PDAExpressions.java
@@ -316,7 +316,7 @@ public class PDAExpressions extends AbstractDsfService implements ICachingServic
int end = lengthArg > 0 ? (start + lengthArg) : getData().fValues.length;
IExpressionDMContext[] contexts = new IExpressionDMContext[end - start];
for (int i = start; i < end && i < getData().fValues.length; i++) {
- contexts[i] = new ExpressionDMContext(
+ contexts[i - start] = new ExpressionDMContext(
getSession().getId(), frameCtx, getData().fValues[i]);
}
rm.setData(contexts);

Back to the top