From 884cd427f504a6e105059199c3eeadd51a8b9c6e Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Mon, 19 Jul 2010 13:51:36 -0700 Subject: [PATCH] Implement JDWP ArrayType.NewInstance. With this, you can go into the Eclipse "Display" view and evaluate "new byte[5]" to get "(byte[]) [0, 0, 0, 0, 0]". Change-Id: Id110c5701a9de12222760be6623585b5f7e28023 --- vm/Debugger.c | 14 ++++++++++++++ vm/Debugger.h | 1 + vm/jdwp/JdwpHandler.c | 26 +++++++++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/vm/Debugger.c b/vm/Debugger.c index dc54d76b8..94029114b 100644 --- a/vm/Debugger.c +++ b/vm/Debugger.c @@ -1169,6 +1169,20 @@ ObjectId dvmDbgCreateObject(RefTypeId classId) } /* + * Allocate a new array object of the specified type and length. The + * type is the array type, not the element type. + * + * Add it to the registry to prevent it from being GCed. + */ +ObjectId dvmDbgCreateArrayObject(RefTypeId arrayTypeId, u4 length) +{ + ClassObject* clazz = refTypeIdToClassObject(arrayTypeId); + Object* newObj = (Object*) dvmAllocArrayByClass(clazz, length, ALLOC_DEFAULT); + dvmReleaseTrackedAlloc(newObj, NULL); + return objectToObjectId(newObj); +} + +/* * Determine if "instClassId" is an instance of "classId". */ bool dvmDbgMatchType(RefTypeId instClassId, RefTypeId classId) diff --git a/vm/Debugger.h b/vm/Debugger.h index 04477fb52..d7221604f 100644 --- a/vm/Debugger.h +++ b/vm/Debugger.h @@ -191,6 +191,7 @@ bool dvmDbgSetArrayElements(ObjectId arrayId, int firstIndex, int count, ObjectId dvmDbgCreateString(const char* str); ObjectId dvmDbgCreateObject(RefTypeId classId); +ObjectId dvmDbgCreateArrayObject(RefTypeId arrayTypeId, u4 length); bool dvmDbgMatchType(RefTypeId instClassId, RefTypeId classId); diff --git a/vm/jdwp/JdwpHandler.c b/vm/jdwp/JdwpHandler.c index 69fe51077..d2a657dea 100644 --- a/vm/jdwp/JdwpHandler.c +++ b/vm/jdwp/JdwpHandler.c @@ -896,6 +896,30 @@ static JdwpError handleCT_NewInstance(JdwpState* state, } /* + * Create a new array object of the requested type and length. + */ +static JdwpError handleAT_newInstance(JdwpState* state, + const u1* buf, int dataLen, ExpandBuf* pReply) +{ + RefTypeId arrayTypeId; + u4 length; + ObjectId objectId; + + arrayTypeId = dvmReadRefTypeId(&buf); + length = read4BE(&buf); + + LOGV("Creating array %s[%u]\n", + dvmDbgGetClassDescriptor(arrayTypeId), length); + objectId = dvmDbgCreateArrayObject(arrayTypeId, length); + if (objectId == 0) + return ERR_OUT_OF_MEMORY; + + expandBufAdd1(pReply, JT_ARRAY); + expandBufAddObjectId(pReply, objectId); + return ERR_NONE; +} + +/* * Return line number information for the method, if present. */ static JdwpError handleM_LineTable(JdwpState* state, @@ -2012,7 +2036,7 @@ static const JdwpHandlerMap gHandlerMap[] = { { 3, 4, handleCT_NewInstance, "ClassType.NewInstance" }, /* ArrayType command set (4) */ - //4, 1, NewInstance + { 4, 1, handleAT_newInstance, "ArrayType.NewInstance" }, /* InterfaceType command set (5) */ -- 2.11.0