Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * Handle messages from debugger. |
| 19 | * |
| 20 | * GENERAL NOTE: we're not currently testing the message length for |
| 21 | * correctness. This is usually a bad idea, but here we can probably |
| 22 | * get away with it so long as the debugger isn't broken. We can |
| 23 | * change the "read" macros to use "dataLen" to avoid wandering into |
| 24 | * bad territory, and have a single "is dataLen correct" check at the |
| 25 | * end of each function. Not needed at this time. |
| 26 | */ |
| 27 | |
| 28 | #include "atomic.h" |
| 29 | #include "debugger.h" |
| 30 | #include "jdwp/jdwp_priv.h" |
| 31 | #include "jdwp/jdwp_handler.h" |
| 32 | #include "jdwp/jdwp_event.h" |
| 33 | #include "jdwp/jdwp_constants.h" |
| 34 | #include "jdwp/jdwp_expand_buf.h" |
| 35 | #include "logging.h" |
| 36 | #include "macros.h" |
| 37 | #include "stringprintf.h" |
| 38 | |
| 39 | #include <stdlib.h> |
| 40 | #include <string.h> |
| 41 | #include <unistd.h> |
| 42 | |
| 43 | namespace art { |
| 44 | |
| 45 | namespace JDWP { |
| 46 | |
| 47 | /* |
| 48 | * Helper function: read a "location" from an input buffer. |
| 49 | */ |
| 50 | static void jdwpReadLocation(const uint8_t** pBuf, JdwpLocation* pLoc) { |
| 51 | memset(pLoc, 0, sizeof(*pLoc)); /* allows memcmp() later */ |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 52 | pLoc->typeTag = ReadTypeTag(pBuf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 53 | pLoc->classId = ReadObjectId(pBuf); |
| 54 | pLoc->methodId = ReadMethodId(pBuf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 55 | pLoc->idx = Read8BE(pBuf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /* |
| 59 | * Helper function: write a "location" into the reply buffer. |
| 60 | */ |
| 61 | void AddLocation(ExpandBuf* pReply, const JdwpLocation* pLoc) { |
| 62 | expandBufAdd1(pReply, pLoc->typeTag); |
| 63 | expandBufAddObjectId(pReply, pLoc->classId); |
| 64 | expandBufAddMethodId(pReply, pLoc->methodId); |
| 65 | expandBufAdd8BE(pReply, pLoc->idx); |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * Helper function: read a variable-width value from the input buffer. |
| 70 | */ |
Elliott Hughes | dbb4079 | 2011-11-18 17:05:22 -0800 | [diff] [blame] | 71 | static uint64_t jdwpReadValue(const uint8_t** pBuf, size_t width) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 72 | uint64_t value = -1; |
| 73 | switch (width) { |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 74 | case 1: value = Read1(pBuf); break; |
| 75 | case 2: value = Read2BE(pBuf); break; |
| 76 | case 4: value = Read4BE(pBuf); break; |
| 77 | case 8: value = Read8BE(pBuf); break; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 78 | default: LOG(FATAL) << width; break; |
| 79 | } |
| 80 | return value; |
| 81 | } |
| 82 | |
| 83 | /* |
| 84 | * Helper function: write a variable-width value into the output input buffer. |
| 85 | */ |
| 86 | static void jdwpWriteValue(ExpandBuf* pReply, int width, uint64_t value) { |
| 87 | switch (width) { |
| 88 | case 1: expandBufAdd1(pReply, value); break; |
| 89 | case 2: expandBufAdd2BE(pReply, value); break; |
| 90 | case 4: expandBufAdd4BE(pReply, value); break; |
| 91 | case 8: expandBufAdd8BE(pReply, value); break; |
| 92 | default: LOG(FATAL) << width; break; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * Common code for *_InvokeMethod requests. |
| 98 | * |
| 99 | * If "isConstructor" is set, this returns "objectId" rather than the |
| 100 | * expected-to-be-void return value of the called function. |
| 101 | */ |
| 102 | static JdwpError finishInvoke(JdwpState* state, |
| 103 | const uint8_t* buf, int dataLen, ExpandBuf* pReply, |
| 104 | ObjectId threadId, ObjectId objectId, RefTypeId classId, MethodId methodId, |
| 105 | bool isConstructor) |
| 106 | { |
| 107 | CHECK(!isConstructor || objectId != 0); |
| 108 | |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 109 | uint32_t numArgs = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 110 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 111 | VLOG(jdwp) << StringPrintf(" --> threadId=%llx objectId=%llx", threadId, objectId); |
Elliott Hughes | c308a5d | 2012-02-16 17:12:06 -0800 | [diff] [blame] | 112 | VLOG(jdwp) << StringPrintf(" classId=%llx methodId=%x %s.%s", classId, methodId, Dbg::GetClassName(classId).c_str(), Dbg::GetMethodName(classId, methodId).c_str()); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 113 | VLOG(jdwp) << StringPrintf(" %d args:", numArgs); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 114 | |
| 115 | uint64_t* argArray = NULL; |
| 116 | if (numArgs > 0) { |
| 117 | argArray = (ObjectId*) malloc(sizeof(ObjectId) * numArgs); |
| 118 | } |
| 119 | |
| 120 | for (uint32_t i = 0; i < numArgs; i++) { |
Elliott Hughes | aed4be9 | 2011-12-02 16:16:23 -0800 | [diff] [blame] | 121 | JDWP::JdwpTag typeTag = ReadTag(&buf); |
Elliott Hughes | dbb4079 | 2011-11-18 17:05:22 -0800 | [diff] [blame] | 122 | size_t width = Dbg::GetTagWidth(typeTag); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 123 | uint64_t value = jdwpReadValue(&buf, width); |
| 124 | |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 125 | VLOG(jdwp) << " " << typeTag << StringPrintf("(%zd): 0x%llx", width, value); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 126 | argArray[i] = value; |
| 127 | } |
| 128 | |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 129 | uint32_t options = Read4BE(&buf); /* enum InvokeOptions bit flags */ |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 130 | VLOG(jdwp) << StringPrintf(" options=0x%04x%s%s", options, (options & INVOKE_SINGLE_THREADED) ? " (SINGLE_THREADED)" : "", (options & INVOKE_NONVIRTUAL) ? " (NONVIRTUAL)" : ""); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 131 | |
Elliott Hughes | aed4be9 | 2011-12-02 16:16:23 -0800 | [diff] [blame] | 132 | JDWP::JdwpTag resultTag; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 133 | uint64_t resultValue; |
| 134 | ObjectId exceptObjId; |
| 135 | JdwpError err = Dbg::InvokeMethod(threadId, objectId, classId, methodId, numArgs, argArray, options, &resultTag, &resultValue, &exceptObjId); |
| 136 | if (err != ERR_NONE) { |
| 137 | goto bail; |
| 138 | } |
| 139 | |
| 140 | if (err == ERR_NONE) { |
| 141 | if (isConstructor) { |
| 142 | expandBufAdd1(pReply, JT_OBJECT); |
| 143 | expandBufAddObjectId(pReply, objectId); |
| 144 | } else { |
Elliott Hughes | dbb4079 | 2011-11-18 17:05:22 -0800 | [diff] [blame] | 145 | size_t width = Dbg::GetTagWidth(resultTag); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 146 | |
| 147 | expandBufAdd1(pReply, resultTag); |
| 148 | if (width != 0) { |
| 149 | jdwpWriteValue(pReply, width, resultValue); |
| 150 | } |
| 151 | } |
| 152 | expandBufAdd1(pReply, JT_OBJECT); |
| 153 | expandBufAddObjectId(pReply, exceptObjId); |
| 154 | |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 155 | VLOG(jdwp) << " --> returned " << resultTag << StringPrintf(" 0x%llx (except=%08llx)", resultValue, exceptObjId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 156 | |
| 157 | /* show detailed debug output */ |
| 158 | if (resultTag == JT_STRING && exceptObjId == 0) { |
| 159 | if (resultValue != 0) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 160 | VLOG(jdwp) << " string '" << Dbg::StringToUtf8(resultValue) << "'"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 161 | } else { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 162 | VLOG(jdwp) << " string (null)"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | bail: |
| 168 | free(argArray); |
| 169 | return err; |
| 170 | } |
| 171 | |
| 172 | |
| 173 | /* |
| 174 | * Request for version info. |
| 175 | */ |
| 176 | static JdwpError handleVM_Version(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 177 | /* text information on runtime version */ |
| 178 | std::string version(StringPrintf("Android Runtime %s", Runtime::Current()->GetVersion())); |
Elliott Hughes | 4740cdf | 2011-12-07 14:07:12 -0800 | [diff] [blame] | 179 | expandBufAddUtf8String(pReply, version); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 180 | /* JDWP version numbers */ |
| 181 | expandBufAdd4BE(pReply, 1); // major |
| 182 | expandBufAdd4BE(pReply, 5); // minor |
| 183 | /* VM JRE version */ |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 184 | expandBufAddUtf8String(pReply, "1.6.0"); /* e.g. 1.6.0_22 */ |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 185 | /* target VM name */ |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 186 | expandBufAddUtf8String(pReply, "DalvikVM"); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 187 | |
| 188 | return ERR_NONE; |
| 189 | } |
| 190 | |
| 191 | /* |
| 192 | * Given a class JNI signature (e.g. "Ljava/lang/Error;"), return the |
| 193 | * referenceTypeID. We need to send back more than one if the class has |
| 194 | * been loaded by multiple class loaders. |
| 195 | */ |
| 196 | static JdwpError handleVM_ClassesBySignature(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 197 | std::string classDescriptor(ReadNewUtf8String(&buf)); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 198 | VLOG(jdwp) << " Req for class by signature '" << classDescriptor << "'"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 199 | |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 200 | std::vector<RefTypeId> ids; |
Elliott Hughes | c3b77c7 | 2011-12-15 20:56:48 -0800 | [diff] [blame] | 201 | Dbg::FindLoadedClassBySignature(classDescriptor.c_str(), ids); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 202 | |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 203 | expandBufAdd4BE(pReply, ids.size()); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 204 | |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 205 | for (size_t i = 0; i < ids.size(); ++i) { |
| 206 | // Get class vs. interface and status flags. |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 207 | JDWP::JdwpTypeTag type_tag; |
| 208 | uint32_t class_status; |
| 209 | JDWP::JdwpError status = Dbg::GetClassInfo(ids[i], &type_tag, &class_status, NULL); |
| 210 | if (status != ERR_NONE) { |
| 211 | return status; |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 212 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 213 | |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 214 | expandBufAdd1(pReply, type_tag); |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 215 | expandBufAddRefTypeId(pReply, ids[i]); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 216 | expandBufAdd4BE(pReply, class_status); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 217 | } |
| 218 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 219 | return ERR_NONE; |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | * Handle request for the thread IDs of all running threads. |
| 224 | * |
| 225 | * We exclude ourselves from the list, because we don't allow ourselves |
| 226 | * to be suspended, and that violates some JDWP expectations. |
| 227 | */ |
| 228 | static JdwpError handleVM_AllThreads(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 229 | ObjectId* pThreadIds; |
| 230 | uint32_t threadCount; |
| 231 | Dbg::GetAllThreads(&pThreadIds, &threadCount); |
| 232 | |
| 233 | expandBufAdd4BE(pReply, threadCount); |
| 234 | |
| 235 | ObjectId* walker = pThreadIds; |
| 236 | for (uint32_t i = 0; i < threadCount; i++) { |
| 237 | expandBufAddObjectId(pReply, *walker++); |
| 238 | } |
| 239 | |
| 240 | free(pThreadIds); |
| 241 | |
| 242 | return ERR_NONE; |
| 243 | } |
| 244 | |
| 245 | /* |
| 246 | * List all thread groups that do not have a parent. |
| 247 | */ |
| 248 | static JdwpError handleVM_TopLevelThreadGroups(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 249 | /* |
| 250 | * TODO: maintain a list of parentless thread groups in the VM. |
| 251 | * |
| 252 | * For now, just return "system". Application threads are created |
| 253 | * in "main", which is a child of "system". |
| 254 | */ |
| 255 | uint32_t groups = 1; |
| 256 | expandBufAdd4BE(pReply, groups); |
| 257 | //threadGroupId = debugGetMainThreadGroup(); |
| 258 | //expandBufAdd8BE(pReply, threadGroupId); |
| 259 | ObjectId threadGroupId = Dbg::GetSystemThreadGroupId(); |
| 260 | expandBufAddObjectId(pReply, threadGroupId); |
| 261 | |
| 262 | return ERR_NONE; |
| 263 | } |
| 264 | |
| 265 | /* |
| 266 | * Respond with the sizes of the basic debugger types. |
| 267 | * |
| 268 | * All IDs are 8 bytes. |
| 269 | */ |
| 270 | static JdwpError handleVM_IDSizes(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 271 | expandBufAdd4BE(pReply, sizeof(FieldId)); |
| 272 | expandBufAdd4BE(pReply, sizeof(MethodId)); |
| 273 | expandBufAdd4BE(pReply, sizeof(ObjectId)); |
| 274 | expandBufAdd4BE(pReply, sizeof(RefTypeId)); |
| 275 | expandBufAdd4BE(pReply, sizeof(FrameId)); |
| 276 | return ERR_NONE; |
| 277 | } |
| 278 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 279 | static JdwpError handleVM_Dispose(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 280 | Dbg::Disposed(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 281 | return ERR_NONE; |
| 282 | } |
| 283 | |
| 284 | /* |
| 285 | * Suspend the execution of the application running in the VM (i.e. suspend |
| 286 | * all threads). |
| 287 | * |
| 288 | * This needs to increment the "suspend count" on all threads. |
| 289 | */ |
| 290 | static JdwpError handleVM_Suspend(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
Elliott Hughes | 475fc23 | 2011-10-25 15:00:35 -0700 | [diff] [blame] | 291 | Dbg::SuspendVM(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 292 | return ERR_NONE; |
| 293 | } |
| 294 | |
| 295 | /* |
| 296 | * Resume execution. Decrements the "suspend count" of all threads. |
| 297 | */ |
| 298 | static JdwpError handleVM_Resume(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 299 | Dbg::ResumeVM(); |
| 300 | return ERR_NONE; |
| 301 | } |
| 302 | |
| 303 | /* |
| 304 | * The debugger wants the entire VM to exit. |
| 305 | */ |
| 306 | static JdwpError handleVM_Exit(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 307 | uint32_t exitCode = Get4BE(buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 308 | |
| 309 | LOG(WARNING) << "Debugger is telling the VM to exit with code=" << exitCode; |
| 310 | |
| 311 | Dbg::Exit(exitCode); |
| 312 | return ERR_NOT_IMPLEMENTED; // shouldn't get here |
| 313 | } |
| 314 | |
| 315 | /* |
| 316 | * Create a new string in the VM and return its ID. |
| 317 | * |
| 318 | * (Ctrl-Shift-I in Eclipse on an array of objects causes it to create the |
| 319 | * string "java.util.Arrays".) |
| 320 | */ |
| 321 | static JdwpError handleVM_CreateString(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 322 | std::string str(ReadNewUtf8String(&buf)); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 323 | VLOG(jdwp) << " Req to create string '" << str << "'"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 324 | ObjectId stringId = Dbg::CreateString(str); |
| 325 | if (stringId == 0) { |
| 326 | return ERR_OUT_OF_MEMORY; |
| 327 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 328 | expandBufAddObjectId(pReply, stringId); |
| 329 | return ERR_NONE; |
| 330 | } |
| 331 | |
| 332 | /* |
| 333 | * Tell the debugger what we are capable of. |
| 334 | */ |
| 335 | static JdwpError handleVM_Capabilities(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 336 | expandBufAdd1(pReply, false); /* canWatchFieldModification */ |
| 337 | expandBufAdd1(pReply, false); /* canWatchFieldAccess */ |
| 338 | expandBufAdd1(pReply, false); /* canGetBytecodes */ |
| 339 | expandBufAdd1(pReply, true); /* canGetSyntheticAttribute */ |
| 340 | expandBufAdd1(pReply, false); /* canGetOwnedMonitorInfo */ |
| 341 | expandBufAdd1(pReply, false); /* canGetCurrentContendedMonitor */ |
| 342 | expandBufAdd1(pReply, false); /* canGetMonitorInfo */ |
| 343 | return ERR_NONE; |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Return classpath and bootclasspath. |
| 348 | */ |
| 349 | static JdwpError handleVM_ClassPaths(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 350 | char baseDir[2] = "/"; |
| 351 | |
| 352 | /* |
| 353 | * TODO: make this real. Not important for remote debugging, but |
| 354 | * might be useful for local debugging. |
| 355 | */ |
| 356 | uint32_t classPaths = 1; |
| 357 | uint32_t bootClassPaths = 0; |
| 358 | |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 359 | expandBufAddUtf8String(pReply, baseDir); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 360 | expandBufAdd4BE(pReply, classPaths); |
| 361 | for (uint32_t i = 0; i < classPaths; i++) { |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 362 | expandBufAddUtf8String(pReply, "."); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | expandBufAdd4BE(pReply, bootClassPaths); |
| 366 | for (uint32_t i = 0; i < classPaths; i++) { |
| 367 | /* add bootclasspath components as strings */ |
| 368 | } |
| 369 | |
| 370 | return ERR_NONE; |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * Release a list of object IDs. (Seen in jdb.) |
| 375 | * |
| 376 | * Currently does nothing. |
| 377 | */ |
| 378 | static JdwpError HandleVM_DisposeObjects(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 379 | return ERR_NONE; |
| 380 | } |
| 381 | |
| 382 | /* |
| 383 | * Tell the debugger what we are capable of. |
| 384 | */ |
| 385 | static JdwpError handleVM_CapabilitiesNew(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 386 | expandBufAdd1(pReply, false); /* canWatchFieldModification */ |
| 387 | expandBufAdd1(pReply, false); /* canWatchFieldAccess */ |
| 388 | expandBufAdd1(pReply, false); /* canGetBytecodes */ |
| 389 | expandBufAdd1(pReply, true); /* canGetSyntheticAttribute */ |
| 390 | expandBufAdd1(pReply, false); /* canGetOwnedMonitorInfo */ |
| 391 | expandBufAdd1(pReply, false); /* canGetCurrentContendedMonitor */ |
| 392 | expandBufAdd1(pReply, false); /* canGetMonitorInfo */ |
| 393 | expandBufAdd1(pReply, false); /* canRedefineClasses */ |
| 394 | expandBufAdd1(pReply, false); /* canAddMethod */ |
| 395 | expandBufAdd1(pReply, false); /* canUnrestrictedlyRedefineClasses */ |
| 396 | expandBufAdd1(pReply, false); /* canPopFrames */ |
| 397 | expandBufAdd1(pReply, false); /* canUseInstanceFilters */ |
| 398 | expandBufAdd1(pReply, false); /* canGetSourceDebugExtension */ |
| 399 | expandBufAdd1(pReply, false); /* canRequestVMDeathEvent */ |
| 400 | expandBufAdd1(pReply, false); /* canSetDefaultStratum */ |
| 401 | expandBufAdd1(pReply, false); /* 1.6: canGetInstanceInfo */ |
| 402 | expandBufAdd1(pReply, false); /* 1.6: canRequestMonitorEvents */ |
| 403 | expandBufAdd1(pReply, false); /* 1.6: canGetMonitorFrameInfo */ |
| 404 | expandBufAdd1(pReply, false); /* 1.6: canUseSourceNameFilters */ |
| 405 | expandBufAdd1(pReply, false); /* 1.6: canGetConstantPool */ |
| 406 | expandBufAdd1(pReply, false); /* 1.6: canForceEarlyReturn */ |
| 407 | |
| 408 | /* fill in reserved22 through reserved32; note count started at 1 */ |
| 409 | for (int i = 22; i <= 32; i++) { |
| 410 | expandBufAdd1(pReply, false); /* reservedN */ |
| 411 | } |
| 412 | return ERR_NONE; |
| 413 | } |
| 414 | |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 415 | static JdwpError handleVM_AllClasses(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply, bool descriptor_and_status, bool generic) { |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 416 | std::vector<JDWP::RefTypeId> classes; |
| 417 | Dbg::GetClassList(classes); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 418 | |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 419 | expandBufAdd4BE(pReply, classes.size()); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 420 | |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 421 | for (size_t i = 0; i < classes.size(); ++i) { |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 422 | static const char genericSignature[1] = ""; |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 423 | JDWP::JdwpTypeTag type_tag; |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 424 | std::string descriptor; |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 425 | uint32_t class_status; |
| 426 | JDWP::JdwpError status = Dbg::GetClassInfo(classes[i], &type_tag, &class_status, &descriptor); |
| 427 | if (status != ERR_NONE) { |
| 428 | return status; |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 429 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 430 | |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 431 | expandBufAdd1(pReply, type_tag); |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 432 | expandBufAddRefTypeId(pReply, classes[i]); |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 433 | if (descriptor_and_status) { |
| 434 | expandBufAddUtf8String(pReply, descriptor); |
| 435 | if (generic) { |
| 436 | expandBufAddUtf8String(pReply, genericSignature); |
| 437 | } |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 438 | expandBufAdd4BE(pReply, class_status); |
Elliott Hughes | 1fe7afb | 2012-02-13 17:23:03 -0800 | [diff] [blame] | 439 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 442 | return ERR_NONE; |
| 443 | } |
| 444 | |
Elliott Hughes | 1fe7afb | 2012-02-13 17:23:03 -0800 | [diff] [blame] | 445 | static JdwpError handleVM_AllClasses(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 446 | return handleVM_AllClasses(state, buf, dataLen, pReply, true, false); |
Elliott Hughes | 1fe7afb | 2012-02-13 17:23:03 -0800 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static JdwpError handleVM_AllClassesWithGeneric(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 450 | return handleVM_AllClasses(state, buf, dataLen, pReply, true, true); |
Elliott Hughes | 1fe7afb | 2012-02-13 17:23:03 -0800 | [diff] [blame] | 451 | } |
| 452 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 453 | /* |
| 454 | * Given a referenceTypeID, return a string with the JNI reference type |
| 455 | * signature (e.g. "Ljava/lang/Error;"). |
| 456 | */ |
| 457 | static JdwpError handleRT_Signature(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 458 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
| 459 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 460 | VLOG(jdwp) << StringPrintf(" Req for signature of refTypeId=0x%llx", refTypeId); |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 461 | std::string signature; |
Elliott Hughes | 1fe7afb | 2012-02-13 17:23:03 -0800 | [diff] [blame] | 462 | |
| 463 | JdwpError status = Dbg::GetSignature(refTypeId, signature); |
| 464 | if (status != ERR_NONE) { |
| 465 | return status; |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 466 | } |
Elliott Hughes | 4740cdf | 2011-12-07 14:07:12 -0800 | [diff] [blame] | 467 | expandBufAddUtf8String(pReply, signature); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 468 | return ERR_NONE; |
| 469 | } |
| 470 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 471 | static JdwpError handleRT_Modifiers(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 472 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 473 | return Dbg::GetModifiers(refTypeId, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | /* |
| 477 | * Get values from static fields in a reference type. |
| 478 | */ |
| 479 | static JdwpError handleRT_GetValues(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 480 | ReadRefTypeId(&buf); // We don't need this, but we need to skip over it in the request. |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 481 | uint32_t numFields = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 482 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 483 | VLOG(jdwp) << " RT_GetValues " << numFields << ":"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 484 | |
| 485 | expandBufAdd4BE(pReply, numFields); |
| 486 | for (uint32_t i = 0; i < numFields; i++) { |
| 487 | FieldId fieldId = ReadFieldId(&buf); |
Elliott Hughes | 6fa602d | 2011-12-02 17:54:25 -0800 | [diff] [blame] | 488 | Dbg::GetStaticFieldValue(fieldId, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | return ERR_NONE; |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 | * Get the name of the source file in which a reference type was declared. |
| 496 | */ |
| 497 | static JdwpError handleRT_SourceFile(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 498 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
Elliott Hughes | 03181a8 | 2011-11-17 17:22:21 -0800 | [diff] [blame] | 499 | std::string source_file; |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 500 | JdwpError status = Dbg::GetSourceFile(refTypeId, source_file); |
| 501 | if (status != ERR_NONE) { |
| 502 | return status; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 503 | } |
Elliott Hughes | 4740cdf | 2011-12-07 14:07:12 -0800 | [diff] [blame] | 504 | expandBufAddUtf8String(pReply, source_file); |
Elliott Hughes | 03181a8 | 2011-11-17 17:22:21 -0800 | [diff] [blame] | 505 | return ERR_NONE; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | /* |
| 509 | * Return the current status of the reference type. |
| 510 | */ |
| 511 | static JdwpError handleRT_Status(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 512 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 513 | JDWP::JdwpTypeTag type_tag; |
| 514 | uint32_t class_status; |
| 515 | JDWP::JdwpError status = Dbg::GetClassInfo(refTypeId, &type_tag, &class_status, NULL); |
| 516 | if (status != ERR_NONE) { |
| 517 | return status; |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 518 | } |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 519 | expandBufAdd4BE(pReply, class_status); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 520 | return ERR_NONE; |
| 521 | } |
| 522 | |
| 523 | /* |
| 524 | * Return interfaces implemented directly by this class. |
| 525 | */ |
| 526 | static JdwpError handleRT_Interfaces(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 527 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
Elliott Hughes | c308a5d | 2012-02-16 17:12:06 -0800 | [diff] [blame] | 528 | VLOG(jdwp) << StringPrintf(" Req for interfaces in %llx (%s)", refTypeId, Dbg::GetClassName(refTypeId).c_str()); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 529 | return Dbg::OutputDeclaredInterfaces(refTypeId, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | /* |
| 533 | * Return the class object corresponding to this type. |
| 534 | */ |
| 535 | static JdwpError handleRT_ClassObject(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 536 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 537 | ObjectId classObjectId; |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 538 | JdwpError status = Dbg::GetClassObject(refTypeId, classObjectId); |
| 539 | if (status != ERR_NONE) { |
| 540 | return status; |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 541 | } |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 542 | VLOG(jdwp) << StringPrintf(" RefTypeId %llx -> ObjectId %llx", refTypeId, classObjectId); |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 543 | expandBufAddObjectId(pReply, classObjectId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 544 | return ERR_NONE; |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | * Returns the value of the SourceDebugExtension attribute. |
| 549 | * |
| 550 | * JDB seems interested, but DEX files don't currently support this. |
| 551 | */ |
| 552 | static JdwpError handleRT_SourceDebugExtension(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 553 | /* referenceTypeId in, string out */ |
| 554 | return ERR_ABSENT_INFORMATION; |
| 555 | } |
| 556 | |
| 557 | /* |
| 558 | * Like RT_Signature but with the possibility of a "generic signature". |
| 559 | */ |
| 560 | static JdwpError handleRT_SignatureWithGeneric(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 561 | static const char genericSignature[1] = ""; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 562 | |
| 563 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
| 564 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 565 | VLOG(jdwp) << StringPrintf(" Req for signature of refTypeId=0x%llx", refTypeId); |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 566 | std::string signature; |
| 567 | if (Dbg::GetSignature(refTypeId, signature)) { |
Elliott Hughes | 4740cdf | 2011-12-07 14:07:12 -0800 | [diff] [blame] | 568 | expandBufAddUtf8String(pReply, signature); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 569 | } else { |
| 570 | LOG(WARNING) << StringPrintf("No signature for refTypeId=0x%llx", refTypeId); |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 571 | expandBufAddUtf8String(pReply, "Lunknown;"); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 572 | } |
| 573 | expandBufAddUtf8String(pReply, genericSignature); |
| 574 | |
| 575 | return ERR_NONE; |
| 576 | } |
| 577 | |
| 578 | /* |
| 579 | * Return the instance of java.lang.ClassLoader that loaded the specified |
| 580 | * reference type, or null if it was loaded by the system loader. |
| 581 | */ |
| 582 | static JdwpError handleRT_ClassLoader(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 583 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 584 | return Dbg::GetClassLoader(refTypeId, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 587 | static std::string Describe(const RefTypeId& refTypeId) { |
| 588 | std::string signature("unknown"); |
| 589 | Dbg::GetSignature(refTypeId, signature); |
| 590 | return StringPrintf("refTypeId=0x%llx (%s)", refTypeId, signature.c_str()); |
| 591 | } |
| 592 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 593 | /* |
| 594 | * Given a referenceTypeId, return a block of stuff that describes the |
| 595 | * fields declared by a class. |
| 596 | */ |
| 597 | static JdwpError handleRT_FieldsWithGeneric(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 598 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 599 | VLOG(jdwp) << " Req for fields in " << Describe(refTypeId); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 600 | return Dbg::OutputDeclaredFields(refTypeId, true, pReply); |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | // Obsolete equivalent of FieldsWithGeneric, without the generic type information. |
| 604 | static JdwpError handleRT_Fields(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 605 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 606 | VLOG(jdwp) << " Req for fields in " << Describe(refTypeId); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 607 | return Dbg::OutputDeclaredFields(refTypeId, false, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | /* |
| 611 | * Given a referenceTypeID, return a block of goodies describing the |
| 612 | * methods declared by a class. |
| 613 | */ |
| 614 | static JdwpError handleRT_MethodsWithGeneric(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 615 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 616 | VLOG(jdwp) << " Req for methods in " << Describe(refTypeId); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 617 | return Dbg::OutputDeclaredMethods(refTypeId, true, pReply); |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 618 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 619 | |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 620 | // Obsolete equivalent of MethodsWithGeneric, without the generic type information. |
| 621 | static JdwpError handleRT_Methods(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 622 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 623 | VLOG(jdwp) << " Req for methods in " << Describe(refTypeId); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 624 | return Dbg::OutputDeclaredMethods(refTypeId, false, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | /* |
| 628 | * Return the immediate superclass of a class. |
| 629 | */ |
| 630 | static JdwpError handleCT_Superclass(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 631 | RefTypeId classId = ReadRefTypeId(&buf); |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 632 | RefTypeId superClassId; |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 633 | JdwpError status = Dbg::GetSuperclass(classId, superClassId); |
| 634 | if (status != ERR_NONE) { |
| 635 | return status; |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 636 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 637 | expandBufAddRefTypeId(pReply, superClassId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 638 | return ERR_NONE; |
| 639 | } |
| 640 | |
| 641 | /* |
| 642 | * Set static class values. |
| 643 | */ |
| 644 | static JdwpError handleCT_SetValues(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 645 | RefTypeId classId = ReadRefTypeId(&buf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 646 | uint32_t values = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 647 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 648 | VLOG(jdwp) << StringPrintf(" Req to set %d values in classId=%llx", values, classId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 649 | |
| 650 | for (uint32_t i = 0; i < values; i++) { |
| 651 | FieldId fieldId = ReadFieldId(&buf); |
Elliott Hughes | aed4be9 | 2011-12-02 16:16:23 -0800 | [diff] [blame] | 652 | JDWP::JdwpTag fieldTag = Dbg::GetStaticFieldBasicTag(fieldId); |
Elliott Hughes | dbb4079 | 2011-11-18 17:05:22 -0800 | [diff] [blame] | 653 | size_t width = Dbg::GetTagWidth(fieldTag); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 654 | uint64_t value = jdwpReadValue(&buf, width); |
| 655 | |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 656 | VLOG(jdwp) << " --> field=" << fieldId << " tag=" << fieldTag << " -> " << value; |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 657 | JdwpError status = Dbg::SetStaticFieldValue(fieldId, value, width); |
| 658 | if (status != ERR_NONE) { |
| 659 | return status; |
| 660 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | return ERR_NONE; |
| 664 | } |
| 665 | |
| 666 | /* |
| 667 | * Invoke a static method. |
| 668 | * |
| 669 | * Example: Eclipse sometimes uses java/lang/Class.forName(String s) on |
| 670 | * values in the "variables" display. |
| 671 | */ |
| 672 | static JdwpError handleCT_InvokeMethod(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 673 | RefTypeId classId = ReadRefTypeId(&buf); |
| 674 | ObjectId threadId = ReadObjectId(&buf); |
| 675 | MethodId methodId = ReadMethodId(&buf); |
| 676 | |
| 677 | return finishInvoke(state, buf, dataLen, pReply, threadId, 0, classId, methodId, false); |
| 678 | } |
| 679 | |
| 680 | /* |
| 681 | * Create a new object of the requested type, and invoke the specified |
| 682 | * constructor. |
| 683 | * |
| 684 | * Example: in IntelliJ, create a watch on "new String(myByteArray)" to |
| 685 | * see the contents of a byte[] as a string. |
| 686 | */ |
| 687 | static JdwpError handleCT_NewInstance(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 688 | RefTypeId classId = ReadRefTypeId(&buf); |
| 689 | ObjectId threadId = ReadObjectId(&buf); |
| 690 | MethodId methodId = ReadMethodId(&buf); |
| 691 | |
Elliott Hughes | c308a5d | 2012-02-16 17:12:06 -0800 | [diff] [blame] | 692 | VLOG(jdwp) << "Creating instance of " << Dbg::GetClassName(classId); |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 693 | ObjectId objectId; |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 694 | JdwpError status = Dbg::CreateObject(classId, objectId); |
| 695 | if (status != ERR_NONE) { |
| 696 | return status; |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 697 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 698 | if (objectId == 0) { |
| 699 | return ERR_OUT_OF_MEMORY; |
| 700 | } |
| 701 | return finishInvoke(state, buf, dataLen, pReply, threadId, objectId, classId, methodId, true); |
| 702 | } |
| 703 | |
| 704 | /* |
| 705 | * Create a new array object of the requested type and length. |
| 706 | */ |
| 707 | static JdwpError handleAT_newInstance(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 708 | RefTypeId arrayTypeId = ReadRefTypeId(&buf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 709 | uint32_t length = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 710 | |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 711 | VLOG(jdwp) << "Creating array " << Dbg::GetClassName(arrayTypeId) << "[" << length << "]"; |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 712 | ObjectId objectId; |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 713 | JdwpError status = Dbg::CreateArrayObject(arrayTypeId, length, objectId); |
| 714 | if (status != ERR_NONE) { |
| 715 | return status; |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 716 | } |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 717 | if (objectId == 0) { |
| 718 | return ERR_OUT_OF_MEMORY; |
| 719 | } |
| 720 | expandBufAdd1(pReply, JT_ARRAY); |
| 721 | expandBufAddObjectId(pReply, objectId); |
| 722 | return ERR_NONE; |
| 723 | } |
| 724 | |
| 725 | /* |
| 726 | * Return line number information for the method, if present. |
| 727 | */ |
| 728 | static JdwpError handleM_LineTable(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 729 | RefTypeId refTypeId = ReadRefTypeId(&buf); |
| 730 | MethodId methodId = ReadMethodId(&buf); |
| 731 | |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 732 | VLOG(jdwp) << " Req for line table in " << Dbg::GetClassName(refTypeId) << "." << Dbg::GetMethodName(refTypeId,methodId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 733 | |
| 734 | Dbg::OutputLineTable(refTypeId, methodId, pReply); |
| 735 | |
| 736 | return ERR_NONE; |
| 737 | } |
| 738 | |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 739 | static JdwpError handleM_VariableTable(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply, bool generic) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 740 | RefTypeId classId = ReadRefTypeId(&buf); |
| 741 | MethodId methodId = ReadMethodId(&buf); |
| 742 | |
Elliott Hughes | c308a5d | 2012-02-16 17:12:06 -0800 | [diff] [blame] | 743 | VLOG(jdwp) << StringPrintf(" Req for LocalVarTab in class=%s method=%s", Dbg::GetClassName(classId).c_str(), Dbg::GetMethodName(classId, methodId).c_str()); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 744 | |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 745 | // We could return ERR_ABSENT_INFORMATION here if the DEX file was built without local variable |
| 746 | // information. That will cause Eclipse to make a best-effort attempt at displaying local |
| 747 | // variables anonymously. However, the attempt isn't very good, so we're probably better off just |
| 748 | // not showing anything. |
| 749 | Dbg::OutputVariableTable(classId, methodId, generic, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 750 | return ERR_NONE; |
| 751 | } |
| 752 | |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 753 | static JdwpError handleM_VariableTable(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 754 | return handleM_VariableTable(state, buf, dataLen, pReply, false); |
| 755 | } |
| 756 | |
| 757 | static JdwpError handleM_VariableTableWithGeneric(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 758 | return handleM_VariableTable(state, buf, dataLen, pReply, true); |
| 759 | } |
| 760 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 761 | /* |
| 762 | * Given an object reference, return the runtime type of the object |
| 763 | * (class or array). |
| 764 | * |
| 765 | * This can get called on different things, e.g. threadId gets |
| 766 | * passed in here. |
| 767 | */ |
| 768 | static JdwpError handleOR_ReferenceType(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 769 | ObjectId objectId = ReadObjectId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 770 | VLOG(jdwp) << StringPrintf(" Req for type of objectId=0x%llx", objectId); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 771 | return Dbg::GetReferenceType(objectId, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | /* |
| 775 | * Get values from the fields of an object. |
| 776 | */ |
| 777 | static JdwpError handleOR_GetValues(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 778 | ObjectId objectId = ReadObjectId(&buf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 779 | uint32_t numFields = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 780 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 781 | VLOG(jdwp) << StringPrintf(" Req for %d fields from objectId=0x%llx", numFields, objectId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 782 | |
| 783 | expandBufAdd4BE(pReply, numFields); |
| 784 | |
| 785 | for (uint32_t i = 0; i < numFields; i++) { |
| 786 | FieldId fieldId = ReadFieldId(&buf); |
| 787 | Dbg::GetFieldValue(objectId, fieldId, pReply); |
| 788 | } |
| 789 | |
| 790 | return ERR_NONE; |
| 791 | } |
| 792 | |
| 793 | /* |
| 794 | * Set values in the fields of an object. |
| 795 | */ |
| 796 | static JdwpError handleOR_SetValues(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 797 | ObjectId objectId = ReadObjectId(&buf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 798 | uint32_t numFields = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 799 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 800 | VLOG(jdwp) << StringPrintf(" Req to set %d fields in objectId=0x%llx", numFields, objectId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 801 | |
| 802 | for (uint32_t i = 0; i < numFields; i++) { |
| 803 | FieldId fieldId = ReadFieldId(&buf); |
| 804 | |
Elliott Hughes | aed4be9 | 2011-12-02 16:16:23 -0800 | [diff] [blame] | 805 | JDWP::JdwpTag fieldTag = Dbg::GetFieldBasicTag(fieldId); |
Elliott Hughes | dbb4079 | 2011-11-18 17:05:22 -0800 | [diff] [blame] | 806 | size_t width = Dbg::GetTagWidth(fieldTag); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 807 | uint64_t value = jdwpReadValue(&buf, width); |
| 808 | |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 809 | VLOG(jdwp) << " --> fieldId=" << fieldId << " tag=" << fieldTag << "(" << width << ") value=" << value; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 810 | |
| 811 | Dbg::SetFieldValue(objectId, fieldId, value, width); |
| 812 | } |
| 813 | |
| 814 | return ERR_NONE; |
| 815 | } |
| 816 | |
| 817 | /* |
| 818 | * Invoke an instance method. The invocation must occur in the specified |
| 819 | * thread, which must have been suspended by an event. |
| 820 | * |
| 821 | * The call is synchronous. All threads in the VM are resumed, unless the |
| 822 | * SINGLE_THREADED flag is set. |
| 823 | * |
| 824 | * If you ask Eclipse to "inspect" an object (or ask JDB to "print" an |
| 825 | * object), it will try to invoke the object's toString() function. This |
| 826 | * feature becomes crucial when examining ArrayLists with Eclipse. |
| 827 | */ |
| 828 | static JdwpError handleOR_InvokeMethod(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 829 | ObjectId objectId = ReadObjectId(&buf); |
| 830 | ObjectId threadId = ReadObjectId(&buf); |
| 831 | RefTypeId classId = ReadRefTypeId(&buf); |
| 832 | MethodId methodId = ReadMethodId(&buf); |
| 833 | |
| 834 | return finishInvoke(state, buf, dataLen, pReply, threadId, objectId, classId, methodId, false); |
| 835 | } |
| 836 | |
| 837 | /* |
| 838 | * Disable garbage collection of the specified object. |
| 839 | */ |
| 840 | static JdwpError handleOR_DisableCollection(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 841 | // this is currently a no-op |
| 842 | return ERR_NONE; |
| 843 | } |
| 844 | |
| 845 | /* |
| 846 | * Enable garbage collection of the specified object. |
| 847 | */ |
| 848 | static JdwpError handleOR_EnableCollection(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 849 | // this is currently a no-op |
| 850 | return ERR_NONE; |
| 851 | } |
| 852 | |
| 853 | /* |
| 854 | * Determine whether an object has been garbage collected. |
| 855 | */ |
| 856 | static JdwpError handleOR_IsCollected(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 857 | ObjectId objectId; |
| 858 | |
| 859 | objectId = ReadObjectId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 860 | VLOG(jdwp) << StringPrintf(" Req IsCollected(0x%llx)", objectId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 861 | |
| 862 | // TODO: currently returning false; must integrate with GC |
| 863 | expandBufAdd1(pReply, 0); |
| 864 | |
| 865 | return ERR_NONE; |
| 866 | } |
| 867 | |
| 868 | /* |
| 869 | * Return the string value in a string object. |
| 870 | */ |
| 871 | static JdwpError handleSR_Value(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 872 | ObjectId stringObject = ReadObjectId(&buf); |
Elliott Hughes | 68fdbd0 | 2011-11-29 19:22:47 -0800 | [diff] [blame] | 873 | std::string str(Dbg::StringToUtf8(stringObject)); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 874 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 875 | VLOG(jdwp) << StringPrintf(" Req for str %llx --> '%s'", stringObject, PrintableString(str).c_str()); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 876 | |
Elliott Hughes | 4740cdf | 2011-12-07 14:07:12 -0800 | [diff] [blame] | 877 | expandBufAddUtf8String(pReply, str); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 878 | |
| 879 | return ERR_NONE; |
| 880 | } |
| 881 | |
| 882 | /* |
| 883 | * Return a thread's name. |
| 884 | */ |
| 885 | static JdwpError handleTR_Name(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 886 | ObjectId threadId = ReadObjectId(&buf); |
| 887 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 888 | VLOG(jdwp) << StringPrintf(" Req for name of thread 0x%llx", threadId); |
Elliott Hughes | a2e54f6 | 2011-11-17 13:01:30 -0800 | [diff] [blame] | 889 | std::string name; |
| 890 | if (!Dbg::GetThreadName(threadId, name)) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 891 | return ERR_INVALID_THREAD; |
| 892 | } |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 893 | VLOG(jdwp) << StringPrintf(" Name of thread 0x%llx is \"%s\"", threadId, name.c_str()); |
Elliott Hughes | 4740cdf | 2011-12-07 14:07:12 -0800 | [diff] [blame] | 894 | expandBufAddUtf8String(pReply, name); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 895 | |
| 896 | return ERR_NONE; |
| 897 | } |
| 898 | |
| 899 | /* |
| 900 | * Suspend the specified thread. |
| 901 | * |
| 902 | * It's supposed to remain suspended even if interpreted code wants to |
| 903 | * resume it; only the JDI is allowed to resume it. |
| 904 | */ |
| 905 | static JdwpError handleTR_Suspend(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 906 | ObjectId threadId = ReadObjectId(&buf); |
| 907 | |
| 908 | if (threadId == Dbg::GetThreadSelfId()) { |
| 909 | LOG(INFO) << " Warning: ignoring request to suspend self"; |
| 910 | return ERR_THREAD_NOT_SUSPENDED; |
| 911 | } |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 912 | VLOG(jdwp) << StringPrintf(" Req to suspend thread 0x%llx", threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 913 | Dbg::SuspendThread(threadId); |
| 914 | return ERR_NONE; |
| 915 | } |
| 916 | |
| 917 | /* |
| 918 | * Resume the specified thread. |
| 919 | */ |
| 920 | static JdwpError handleTR_Resume(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 921 | ObjectId threadId = ReadObjectId(&buf); |
| 922 | |
| 923 | if (threadId == Dbg::GetThreadSelfId()) { |
| 924 | LOG(INFO) << " Warning: ignoring request to resume self"; |
| 925 | return ERR_NONE; |
| 926 | } |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 927 | VLOG(jdwp) << StringPrintf(" Req to resume thread 0x%llx", threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 928 | Dbg::ResumeThread(threadId); |
| 929 | return ERR_NONE; |
| 930 | } |
| 931 | |
| 932 | /* |
| 933 | * Return status of specified thread. |
| 934 | */ |
| 935 | static JdwpError handleTR_Status(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 936 | ObjectId threadId = ReadObjectId(&buf); |
| 937 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 938 | VLOG(jdwp) << StringPrintf(" Req for status of thread 0x%llx", threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 939 | |
Elliott Hughes | 3d30d9b | 2011-12-07 17:35:48 -0800 | [diff] [blame] | 940 | JDWP::JdwpThreadStatus threadStatus; |
| 941 | JDWP::JdwpSuspendStatus suspendStatus; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 942 | if (!Dbg::GetThreadStatus(threadId, &threadStatus, &suspendStatus)) { |
| 943 | return ERR_INVALID_THREAD; |
| 944 | } |
| 945 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 946 | VLOG(jdwp) << " --> " << threadStatus << ", " << suspendStatus; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 947 | |
| 948 | expandBufAdd4BE(pReply, threadStatus); |
| 949 | expandBufAdd4BE(pReply, suspendStatus); |
| 950 | |
| 951 | return ERR_NONE; |
| 952 | } |
| 953 | |
| 954 | /* |
| 955 | * Return the thread group that the specified thread is a member of. |
| 956 | */ |
| 957 | static JdwpError handleTR_ThreadGroup(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 958 | ObjectId threadId = ReadObjectId(&buf); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 959 | return Dbg::GetThreadGroup(threadId, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | /* |
| 963 | * Return the current call stack of a suspended thread. |
| 964 | * |
| 965 | * If the thread isn't suspended, the error code isn't defined, but should |
| 966 | * be THREAD_NOT_SUSPENDED. |
| 967 | */ |
| 968 | static JdwpError handleTR_Frames(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 969 | ObjectId threadId = ReadObjectId(&buf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 970 | uint32_t startFrame = Read4BE(&buf); |
| 971 | uint32_t length = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 972 | |
| 973 | if (!Dbg::ThreadExists(threadId)) { |
| 974 | return ERR_INVALID_THREAD; |
| 975 | } |
| 976 | if (!Dbg::IsSuspended(threadId)) { |
Elliott Hughes | a2e54f6 | 2011-11-17 13:01:30 -0800 | [diff] [blame] | 977 | LOG(WARNING) << StringPrintf(" Rejecting req for frames in running thread %llx", threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 978 | return ERR_THREAD_NOT_SUSPENDED; |
| 979 | } |
| 980 | |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 981 | size_t frameCount = Dbg::GetThreadFrameCount(threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 982 | |
Elliott Hughes | abd04b9 | 2012-01-18 22:46:41 -0800 | [diff] [blame] | 983 | VLOG(jdwp) << StringPrintf(" Request for frames: threadId=%llx start=%d length=%d [count=%zd]", threadId, startFrame, length, frameCount); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 984 | if (frameCount <= 0) { |
| 985 | return ERR_THREAD_NOT_SUSPENDED; /* == 0 means 100% native */ |
| 986 | } |
| 987 | if (length == (uint32_t) -1) { |
| 988 | length = frameCount; |
| 989 | } |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 990 | CHECK_GE(startFrame, 0U); |
| 991 | CHECK_LT(startFrame, frameCount); |
| 992 | CHECK_LE(startFrame + length, frameCount); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 993 | |
| 994 | uint32_t frames = length; |
| 995 | expandBufAdd4BE(pReply, frames); |
| 996 | for (uint32_t i = startFrame; i < (startFrame+length); i++) { |
| 997 | FrameId frameId; |
| 998 | JdwpLocation loc; |
| 999 | |
| 1000 | Dbg::GetThreadFrame(threadId, i, &frameId, &loc); |
| 1001 | |
| 1002 | expandBufAdd8BE(pReply, frameId); |
| 1003 | AddLocation(pReply, &loc); |
| 1004 | |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 1005 | VLOG(jdwp) << StringPrintf(" Frame %d: id=%llx ", i, frameId) << loc; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | return ERR_NONE; |
| 1009 | } |
| 1010 | |
| 1011 | /* |
| 1012 | * Returns the #of frames on the specified thread, which must be suspended. |
| 1013 | */ |
| 1014 | static JdwpError handleTR_FrameCount(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1015 | ObjectId threadId = ReadObjectId(&buf); |
| 1016 | |
| 1017 | if (!Dbg::ThreadExists(threadId)) { |
| 1018 | return ERR_INVALID_THREAD; |
| 1019 | } |
| 1020 | if (!Dbg::IsSuspended(threadId)) { |
Elliott Hughes | a2e54f6 | 2011-11-17 13:01:30 -0800 | [diff] [blame] | 1021 | LOG(WARNING) << StringPrintf(" Rejecting req for frames in running thread %llx", threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1022 | return ERR_THREAD_NOT_SUSPENDED; |
| 1023 | } |
| 1024 | |
| 1025 | int frameCount = Dbg::GetThreadFrameCount(threadId); |
| 1026 | if (frameCount < 0) { |
| 1027 | return ERR_INVALID_THREAD; |
| 1028 | } |
| 1029 | expandBufAdd4BE(pReply, (uint32_t)frameCount); |
| 1030 | |
| 1031 | return ERR_NONE; |
| 1032 | } |
| 1033 | |
| 1034 | /* |
| 1035 | * Get the monitor that the thread is waiting on. |
| 1036 | */ |
| 1037 | static JdwpError handleTR_CurrentContendedMonitor(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1038 | ObjectId threadId; |
| 1039 | |
| 1040 | threadId = ReadObjectId(&buf); |
| 1041 | |
| 1042 | // TODO: create an Object to represent the monitor (we're currently |
| 1043 | // just using a raw Monitor struct in the VM) |
| 1044 | |
| 1045 | return ERR_NOT_IMPLEMENTED; |
| 1046 | } |
| 1047 | |
| 1048 | /* |
| 1049 | * Return the suspend count for the specified thread. |
| 1050 | * |
| 1051 | * (The thread *might* still be running -- it might not have examined |
| 1052 | * its suspend count recently.) |
| 1053 | */ |
| 1054 | static JdwpError handleTR_SuspendCount(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1055 | ObjectId threadId = ReadObjectId(&buf); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 1056 | return Dbg::GetThreadSuspendCount(threadId, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | /* |
| 1060 | * Return the name of a thread group. |
| 1061 | * |
| 1062 | * The Eclipse debugger recognizes "main" and "system" as special. |
| 1063 | */ |
| 1064 | static JdwpError handleTGR_Name(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1065 | ObjectId threadGroupId = ReadObjectId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1066 | VLOG(jdwp) << StringPrintf(" Req for name of threadGroupId=0x%llx", threadGroupId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1067 | |
Elliott Hughes | 4740cdf | 2011-12-07 14:07:12 -0800 | [diff] [blame] | 1068 | expandBufAddUtf8String(pReply, Dbg::GetThreadGroupName(threadGroupId)); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1069 | |
| 1070 | return ERR_NONE; |
| 1071 | } |
| 1072 | |
| 1073 | /* |
| 1074 | * Returns the thread group -- if any -- that contains the specified |
| 1075 | * thread group. |
| 1076 | */ |
| 1077 | static JdwpError handleTGR_Parent(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1078 | ObjectId groupId = ReadObjectId(&buf); |
| 1079 | |
| 1080 | ObjectId parentGroup = Dbg::GetThreadGroupParent(groupId); |
| 1081 | expandBufAddObjectId(pReply, parentGroup); |
| 1082 | |
| 1083 | return ERR_NONE; |
| 1084 | } |
| 1085 | |
| 1086 | /* |
| 1087 | * Return the active threads and thread groups that are part of the |
| 1088 | * specified thread group. |
| 1089 | */ |
| 1090 | static JdwpError handleTGR_Children(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1091 | ObjectId threadGroupId = ReadObjectId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1092 | VLOG(jdwp) << StringPrintf(" Req for threads in threadGroupId=0x%llx", threadGroupId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1093 | |
| 1094 | ObjectId* pThreadIds; |
| 1095 | uint32_t threadCount; |
| 1096 | Dbg::GetThreadGroupThreads(threadGroupId, &pThreadIds, &threadCount); |
| 1097 | |
| 1098 | expandBufAdd4BE(pReply, threadCount); |
| 1099 | |
| 1100 | for (uint32_t i = 0; i < threadCount; i++) { |
| 1101 | expandBufAddObjectId(pReply, pThreadIds[i]); |
| 1102 | } |
| 1103 | free(pThreadIds); |
| 1104 | |
| 1105 | /* |
| 1106 | * TODO: finish support for child groups |
| 1107 | * |
| 1108 | * For now, just show that "main" is a child of "system". |
| 1109 | */ |
| 1110 | if (threadGroupId == Dbg::GetSystemThreadGroupId()) { |
| 1111 | expandBufAdd4BE(pReply, 1); |
| 1112 | expandBufAddObjectId(pReply, Dbg::GetMainThreadGroupId()); |
| 1113 | } else { |
| 1114 | expandBufAdd4BE(pReply, 0); |
| 1115 | } |
| 1116 | |
| 1117 | return ERR_NONE; |
| 1118 | } |
| 1119 | |
| 1120 | /* |
| 1121 | * Return the #of components in the array. |
| 1122 | */ |
| 1123 | static JdwpError handleAR_Length(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1124 | ObjectId arrayId = ReadObjectId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1125 | VLOG(jdwp) << StringPrintf(" Req for length of array 0x%llx", arrayId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1126 | |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 1127 | int length; |
| 1128 | JdwpError status = Dbg::GetArrayLength(arrayId, length); |
| 1129 | if (status != ERR_NONE) { |
| 1130 | return status; |
| 1131 | } |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 1132 | VLOG(jdwp) << " --> " << length; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1133 | |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 1134 | expandBufAdd4BE(pReply, length); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1135 | |
| 1136 | return ERR_NONE; |
| 1137 | } |
| 1138 | |
| 1139 | /* |
| 1140 | * Return the values from an array. |
| 1141 | */ |
| 1142 | static JdwpError handleAR_GetValues(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1143 | ObjectId arrayId = ReadObjectId(&buf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1144 | uint32_t firstIndex = Read4BE(&buf); |
| 1145 | uint32_t length = Read4BE(&buf); |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 1146 | VLOG(jdwp) << StringPrintf(" Req for array values 0x%llx first=%d len=%d", arrayId, firstIndex, length); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1147 | |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 1148 | return Dbg::OutputArray(arrayId, firstIndex, length, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | /* |
| 1152 | * Set values in an array. |
| 1153 | */ |
| 1154 | static JdwpError handleAR_SetValues(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1155 | ObjectId arrayId = ReadObjectId(&buf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1156 | uint32_t firstIndex = Read4BE(&buf); |
| 1157 | uint32_t values = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1158 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1159 | VLOG(jdwp) << StringPrintf(" Req to set array values 0x%llx first=%d count=%d", arrayId, firstIndex, values); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1160 | |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 1161 | return Dbg::SetArrayElements(arrayId, firstIndex, values, buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1164 | static JdwpError handleCLR_VisibleClasses(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1165 | ObjectId classLoaderObject; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1166 | classLoaderObject = ReadObjectId(&buf); |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 1167 | // TODO: we should only return classes which have the given class loader as a defining or |
| 1168 | // initiating loader. The former would be easy; the latter is hard, because we don't have |
| 1169 | // any such notion. |
| 1170 | return handleVM_AllClasses(state, buf, dataLen, pReply, false, false); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | /* |
| 1174 | * Set an event trigger. |
| 1175 | * |
| 1176 | * Reply with a requestID. |
| 1177 | */ |
| 1178 | static JdwpError handleER_Set(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1179 | const uint8_t* origBuf = buf; |
| 1180 | |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1181 | uint8_t eventKind = Read1(&buf); |
| 1182 | uint8_t suspendPolicy = Read1(&buf); |
| 1183 | uint32_t modifierCount = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1184 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1185 | VLOG(jdwp) << " Set(kind=" << JdwpEventKind(eventKind) |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1186 | << " suspend=" << JdwpSuspendPolicy(suspendPolicy) |
| 1187 | << " mods=" << modifierCount << ")"; |
| 1188 | |
| 1189 | CHECK_LT(modifierCount, 256U); /* reasonableness check */ |
| 1190 | |
| 1191 | JdwpEvent* pEvent = EventAlloc(modifierCount); |
| 1192 | pEvent->eventKind = static_cast<JdwpEventKind>(eventKind); |
| 1193 | pEvent->suspendPolicy = static_cast<JdwpSuspendPolicy>(suspendPolicy); |
| 1194 | pEvent->modCount = modifierCount; |
| 1195 | |
| 1196 | /* |
| 1197 | * Read modifiers. Ordering may be significant (see explanation of Count |
| 1198 | * mods in JDWP doc). |
| 1199 | */ |
| 1200 | for (uint32_t idx = 0; idx < modifierCount; idx++) { |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 1201 | JdwpModKind modKind = static_cast<JdwpModKind>(Read1(&buf)); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1202 | |
| 1203 | pEvent->mods[idx].modKind = modKind; |
| 1204 | |
| 1205 | switch (modKind) { |
| 1206 | case MK_COUNT: /* report once, when "--count" reaches 0 */ |
| 1207 | { |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1208 | uint32_t count = Read4BE(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1209 | VLOG(jdwp) << " Count: " << count; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1210 | if (count == 0) { |
| 1211 | return ERR_INVALID_COUNT; |
| 1212 | } |
| 1213 | pEvent->mods[idx].count.count = count; |
| 1214 | } |
| 1215 | break; |
| 1216 | case MK_CONDITIONAL: /* conditional on expression) */ |
| 1217 | { |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1218 | uint32_t exprId = Read4BE(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1219 | VLOG(jdwp) << " Conditional: " << exprId; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1220 | pEvent->mods[idx].conditional.exprId = exprId; |
| 1221 | } |
| 1222 | break; |
| 1223 | case MK_THREAD_ONLY: /* only report events in specified thread */ |
| 1224 | { |
| 1225 | ObjectId threadId = ReadObjectId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1226 | VLOG(jdwp) << StringPrintf(" ThreadOnly: %llx", threadId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1227 | pEvent->mods[idx].threadOnly.threadId = threadId; |
| 1228 | } |
| 1229 | break; |
| 1230 | case MK_CLASS_ONLY: /* for ClassPrepare, MethodEntry */ |
| 1231 | { |
| 1232 | RefTypeId clazzId = ReadRefTypeId(&buf); |
Elliott Hughes | c308a5d | 2012-02-16 17:12:06 -0800 | [diff] [blame] | 1233 | VLOG(jdwp) << StringPrintf(" ClassOnly: %llx (%s)", clazzId, Dbg::GetClassName(clazzId).c_str()); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1234 | pEvent->mods[idx].classOnly.refTypeId = clazzId; |
| 1235 | } |
| 1236 | break; |
| 1237 | case MK_CLASS_MATCH: /* restrict events to matching classes */ |
| 1238 | { |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 1239 | // pattern is "java.foo.*", we want "java/foo/*". |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 1240 | std::string pattern(ReadNewUtf8String(&buf)); |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 1241 | std::replace(pattern.begin(), pattern.end(), '.', '/'); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 1242 | VLOG(jdwp) << " ClassMatch: '" << pattern << "'"; |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 1243 | pEvent->mods[idx].classMatch.classPattern = strdup(pattern.c_str()); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1244 | } |
| 1245 | break; |
| 1246 | case MK_CLASS_EXCLUDE: /* restrict events to non-matching classes */ |
| 1247 | { |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 1248 | // pattern is "java.foo.*", we want "java/foo/*". |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 1249 | std::string pattern(ReadNewUtf8String(&buf)); |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 1250 | std::replace(pattern.begin(), pattern.end(), '.', '/'); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 1251 | VLOG(jdwp) << " ClassExclude: '" << pattern << "'"; |
Elliott Hughes | 8696433 | 2012-02-15 19:37:42 -0800 | [diff] [blame] | 1252 | pEvent->mods[idx].classExclude.classPattern = strdup(pattern.c_str()); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1253 | } |
| 1254 | break; |
| 1255 | case MK_LOCATION_ONLY: /* restrict certain events based on loc */ |
| 1256 | { |
| 1257 | JdwpLocation loc; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1258 | jdwpReadLocation(&buf, &loc); |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 1259 | VLOG(jdwp) << " LocationOnly: " << loc; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1260 | pEvent->mods[idx].locationOnly.loc = loc; |
| 1261 | } |
| 1262 | break; |
| 1263 | case MK_EXCEPTION_ONLY: /* modifies EK_EXCEPTION events */ |
| 1264 | { |
| 1265 | RefTypeId exceptionOrNull; /* null == all exceptions */ |
| 1266 | uint8_t caught, uncaught; |
| 1267 | |
| 1268 | exceptionOrNull = ReadRefTypeId(&buf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1269 | caught = Read1(&buf); |
| 1270 | uncaught = Read1(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1271 | VLOG(jdwp) << StringPrintf(" ExceptionOnly: type=%llx(%s) caught=%d uncaught=%d", |
Elliott Hughes | c308a5d | 2012-02-16 17:12:06 -0800 | [diff] [blame] | 1272 | exceptionOrNull, (exceptionOrNull == 0) ? "null" : Dbg::GetClassName(exceptionOrNull).c_str(), caught, uncaught); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1273 | |
| 1274 | pEvent->mods[idx].exceptionOnly.refTypeId = exceptionOrNull; |
| 1275 | pEvent->mods[idx].exceptionOnly.caught = caught; |
| 1276 | pEvent->mods[idx].exceptionOnly.uncaught = uncaught; |
| 1277 | } |
| 1278 | break; |
| 1279 | case MK_FIELD_ONLY: /* for field access/mod events */ |
| 1280 | { |
| 1281 | RefTypeId declaring = ReadRefTypeId(&buf); |
| 1282 | FieldId fieldId = ReadFieldId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1283 | VLOG(jdwp) << StringPrintf(" FieldOnly: %llx %x", declaring, fieldId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1284 | pEvent->mods[idx].fieldOnly.refTypeId = declaring; |
| 1285 | pEvent->mods[idx].fieldOnly.fieldId = fieldId; |
| 1286 | } |
| 1287 | break; |
| 1288 | case MK_STEP: /* for use with EK_SINGLE_STEP */ |
| 1289 | { |
| 1290 | ObjectId threadId; |
| 1291 | uint32_t size, depth; |
| 1292 | |
| 1293 | threadId = ReadObjectId(&buf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1294 | size = Read4BE(&buf); |
| 1295 | depth = Read4BE(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1296 | VLOG(jdwp) << StringPrintf(" Step: thread=%llx", threadId) |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1297 | << " size=" << JdwpStepSize(size) << " depth=" << JdwpStepDepth(depth); |
| 1298 | |
| 1299 | pEvent->mods[idx].step.threadId = threadId; |
| 1300 | pEvent->mods[idx].step.size = size; |
| 1301 | pEvent->mods[idx].step.depth = depth; |
| 1302 | } |
| 1303 | break; |
| 1304 | case MK_INSTANCE_ONLY: /* report events related to a specific obj */ |
| 1305 | { |
| 1306 | ObjectId instance = ReadObjectId(&buf); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1307 | VLOG(jdwp) << StringPrintf(" InstanceOnly: %llx", instance); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1308 | pEvent->mods[idx].instanceOnly.objectId = instance; |
| 1309 | } |
| 1310 | break; |
| 1311 | default: |
| 1312 | LOG(WARNING) << "GLITCH: unsupported modKind=" << modKind; |
| 1313 | break; |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | /* |
| 1318 | * Make sure we consumed all data. It is possible that the remote side |
| 1319 | * has sent us bad stuff, but for now we blame ourselves. |
| 1320 | */ |
| 1321 | if (buf != origBuf + dataLen) { |
| 1322 | LOG(WARNING) << "GLITCH: dataLen is " << dataLen << ", we have consumed " << (buf - origBuf); |
| 1323 | } |
| 1324 | |
| 1325 | /* |
| 1326 | * We reply with an integer "requestID". |
| 1327 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 1328 | uint32_t requestId = state->NextEventSerial(); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1329 | expandBufAdd4BE(pReply, requestId); |
| 1330 | |
| 1331 | pEvent->requestId = requestId; |
| 1332 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1333 | VLOG(jdwp) << StringPrintf(" --> event requestId=%#x", requestId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1334 | |
| 1335 | /* add it to the list */ |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1336 | JdwpError err = state->RegisterEvent(pEvent); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1337 | if (err != ERR_NONE) { |
| 1338 | /* registration failed, probably because event is bogus */ |
| 1339 | EventFree(pEvent); |
| 1340 | LOG(WARNING) << "WARNING: event request rejected"; |
| 1341 | } |
| 1342 | return err; |
| 1343 | } |
| 1344 | |
| 1345 | /* |
| 1346 | * Clear an event. Failure to find an event with a matching ID is a no-op |
| 1347 | * and does not return an error. |
| 1348 | */ |
| 1349 | static JdwpError handleER_Clear(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1350 | uint8_t eventKind; |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1351 | eventKind = Read1(&buf); |
| 1352 | uint32_t requestId = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1353 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1354 | VLOG(jdwp) << StringPrintf(" Req to clear eventKind=%d requestId=%#x", eventKind, requestId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1355 | |
Elliott Hughes | 761928d | 2011-11-16 18:33:03 -0800 | [diff] [blame] | 1356 | state->UnregisterEventById(requestId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1357 | |
| 1358 | return ERR_NONE; |
| 1359 | } |
| 1360 | |
| 1361 | /* |
| 1362 | * Return the values of arguments and local variables. |
| 1363 | */ |
| 1364 | static JdwpError handleSF_GetValues(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1365 | ObjectId threadId = ReadObjectId(&buf); |
| 1366 | FrameId frameId = ReadFrameId(&buf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1367 | uint32_t slots = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1368 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1369 | VLOG(jdwp) << StringPrintf(" Req for %d slots in threadId=%llx frameId=%llx", slots, threadId, frameId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1370 | |
| 1371 | expandBufAdd4BE(pReply, slots); /* "int values" */ |
| 1372 | for (uint32_t i = 0; i < slots; i++) { |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1373 | uint32_t slot = Read4BE(&buf); |
Elliott Hughes | aed4be9 | 2011-12-02 16:16:23 -0800 | [diff] [blame] | 1374 | JDWP::JdwpTag reqSigByte = ReadTag(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1375 | |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 1376 | VLOG(jdwp) << " --> slot " << slot << " " << reqSigByte; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1377 | |
Elliott Hughes | dbb4079 | 2011-11-18 17:05:22 -0800 | [diff] [blame] | 1378 | size_t width = Dbg::GetTagWidth(reqSigByte); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1379 | uint8_t* ptr = expandBufAddSpace(pReply, width+1); |
| 1380 | Dbg::GetLocalValue(threadId, frameId, slot, reqSigByte, ptr, width); |
| 1381 | } |
| 1382 | |
| 1383 | return ERR_NONE; |
| 1384 | } |
| 1385 | |
| 1386 | /* |
| 1387 | * Set the values of arguments and local variables. |
| 1388 | */ |
| 1389 | static JdwpError handleSF_SetValues(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1390 | ObjectId threadId = ReadObjectId(&buf); |
| 1391 | FrameId frameId = ReadFrameId(&buf); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1392 | uint32_t slots = Read4BE(&buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1393 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1394 | VLOG(jdwp) << StringPrintf(" Req to set %d slots in threadId=%llx frameId=%llx", slots, threadId, frameId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1395 | |
| 1396 | for (uint32_t i = 0; i < slots; i++) { |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1397 | uint32_t slot = Read4BE(&buf); |
Elliott Hughes | aed4be9 | 2011-12-02 16:16:23 -0800 | [diff] [blame] | 1398 | JDWP::JdwpTag sigByte = ReadTag(&buf); |
Elliott Hughes | dbb4079 | 2011-11-18 17:05:22 -0800 | [diff] [blame] | 1399 | size_t width = Dbg::GetTagWidth(sigByte); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1400 | uint64_t value = jdwpReadValue(&buf, width); |
| 1401 | |
Elliott Hughes | 2435a57 | 2012-02-17 16:07:41 -0800 | [diff] [blame] | 1402 | VLOG(jdwp) << " --> slot " << slot << " " << sigByte << " " << value; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1403 | Dbg::SetLocalValue(threadId, frameId, slot, sigByte, value, width); |
| 1404 | } |
| 1405 | |
| 1406 | return ERR_NONE; |
| 1407 | } |
| 1408 | |
| 1409 | /* |
| 1410 | * Returns the value of "this" for the specified frame. |
| 1411 | */ |
| 1412 | static JdwpError handleSF_ThisObject(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
Elliott Hughes | d07986f | 2011-12-06 18:27:45 -0800 | [diff] [blame] | 1413 | ReadObjectId(&buf); // Skip thread id. |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1414 | FrameId frameId = ReadFrameId(&buf); |
| 1415 | |
| 1416 | ObjectId objectId; |
Elliott Hughes | 91bf6cd | 2012-02-14 17:27:48 -0800 | [diff] [blame] | 1417 | Dbg::GetThisObject(frameId, &objectId); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1418 | |
| 1419 | uint8_t objectTag = Dbg::GetObjectTag(objectId); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1420 | VLOG(jdwp) << StringPrintf(" Req for 'this' in frame=%llx --> %llx '%c'", frameId, objectId, (char)objectTag); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1421 | |
| 1422 | expandBufAdd1(pReply, objectTag); |
| 1423 | expandBufAddObjectId(pReply, objectId); |
| 1424 | |
| 1425 | return ERR_NONE; |
| 1426 | } |
| 1427 | |
| 1428 | /* |
| 1429 | * Return the reference type reflected by this class object. |
| 1430 | * |
| 1431 | * This appears to be required because ReferenceTypeId values are NEVER |
| 1432 | * reused, whereas ClassIds can be recycled like any other object. (Either |
| 1433 | * that, or I have no idea what this is for.) |
| 1434 | */ |
| 1435 | static JdwpError handleCOR_ReflectedType(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1436 | RefTypeId classObjectId = ReadRefTypeId(&buf); |
Elliott Hughes | c308a5d | 2012-02-16 17:12:06 -0800 | [diff] [blame] | 1437 | VLOG(jdwp) << StringPrintf(" Req for refTypeId for class=%llx (%s)", classObjectId, Dbg::GetClassName(classObjectId).c_str()); |
Elliott Hughes | 436e372 | 2012-02-17 20:01:47 -0800 | [diff] [blame^] | 1438 | return Dbg::GetReflectedType(classObjectId, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | /* |
| 1442 | * Handle a DDM packet with a single chunk in it. |
| 1443 | */ |
| 1444 | static JdwpError handleDDM_Chunk(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
| 1445 | uint8_t* replyBuf = NULL; |
| 1446 | int replyLen = -1; |
| 1447 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1448 | VLOG(jdwp) << StringPrintf(" Handling DDM packet (%.4s)", buf); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1449 | |
| 1450 | /* |
| 1451 | * On first DDM packet, notify all handlers that DDM is running. |
| 1452 | */ |
| 1453 | if (!state->ddmActive) { |
| 1454 | state->ddmActive = true; |
| 1455 | Dbg::DdmConnected(); |
| 1456 | } |
| 1457 | |
| 1458 | /* |
| 1459 | * If they want to send something back, we copy it into the buffer. |
| 1460 | * A no-copy approach would be nicer. |
| 1461 | * |
| 1462 | * TODO: consider altering the JDWP stuff to hold the packet header |
| 1463 | * in a separate buffer. That would allow us to writev() DDM traffic |
| 1464 | * instead of copying it into the expanding buffer. The reduction in |
| 1465 | * heap requirements is probably more valuable than the efficiency. |
| 1466 | */ |
| 1467 | if (Dbg::DdmHandlePacket(buf, dataLen, &replyBuf, &replyLen)) { |
| 1468 | CHECK(replyLen > 0 && replyLen < 1*1024*1024); |
| 1469 | memcpy(expandBufAddSpace(pReply, replyLen), replyBuf, replyLen); |
| 1470 | free(replyBuf); |
| 1471 | } |
| 1472 | return ERR_NONE; |
| 1473 | } |
| 1474 | |
| 1475 | /* |
| 1476 | * Handler map decl. |
| 1477 | */ |
| 1478 | typedef JdwpError (*JdwpRequestHandler)(JdwpState* state, const uint8_t* buf, int dataLen, ExpandBuf* reply); |
| 1479 | |
| 1480 | struct JdwpHandlerMap { |
| 1481 | uint8_t cmdSet; |
| 1482 | uint8_t cmd; |
| 1483 | JdwpRequestHandler func; |
| 1484 | const char* descr; |
| 1485 | }; |
| 1486 | |
| 1487 | /* |
| 1488 | * Map commands to functions. |
| 1489 | * |
| 1490 | * Command sets 0-63 are incoming requests, 64-127 are outbound requests, |
| 1491 | * and 128-256 are vendor-defined. |
| 1492 | */ |
| 1493 | static const JdwpHandlerMap gHandlerMap[] = { |
| 1494 | /* VirtualMachine command set (1) */ |
| 1495 | { 1, 1, handleVM_Version, "VirtualMachine.Version" }, |
| 1496 | { 1, 2, handleVM_ClassesBySignature, "VirtualMachine.ClassesBySignature" }, |
Elliott Hughes | 1fe7afb | 2012-02-13 17:23:03 -0800 | [diff] [blame] | 1497 | { 1, 3, handleVM_AllClasses, "VirtualMachine.AllClasses" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1498 | { 1, 4, handleVM_AllThreads, "VirtualMachine.AllThreads" }, |
| 1499 | { 1, 5, handleVM_TopLevelThreadGroups, "VirtualMachine.TopLevelThreadGroups" }, |
| 1500 | { 1, 6, handleVM_Dispose, "VirtualMachine.Dispose" }, |
| 1501 | { 1, 7, handleVM_IDSizes, "VirtualMachine.IDSizes" }, |
| 1502 | { 1, 8, handleVM_Suspend, "VirtualMachine.Suspend" }, |
| 1503 | { 1, 9, handleVM_Resume, "VirtualMachine.Resume" }, |
| 1504 | { 1, 10, handleVM_Exit, "VirtualMachine.Exit" }, |
| 1505 | { 1, 11, handleVM_CreateString, "VirtualMachine.CreateString" }, |
| 1506 | { 1, 12, handleVM_Capabilities, "VirtualMachine.Capabilities" }, |
| 1507 | { 1, 13, handleVM_ClassPaths, "VirtualMachine.ClassPaths" }, |
| 1508 | { 1, 14, HandleVM_DisposeObjects, "VirtualMachine.DisposeObjects" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1509 | { 1, 15, NULL, "VirtualMachine.HoldEvents" }, |
| 1510 | { 1, 16, NULL, "VirtualMachine.ReleaseEvents" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1511 | { 1, 17, handleVM_CapabilitiesNew, "VirtualMachine.CapabilitiesNew" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1512 | { 1, 18, NULL, "VirtualMachine.RedefineClasses" }, |
| 1513 | { 1, 19, NULL, "VirtualMachine.SetDefaultStratum" }, |
| 1514 | { 1, 20, handleVM_AllClassesWithGeneric, "VirtualMachine.AllClassesWithGeneric" }, |
| 1515 | { 1, 21, NULL, "VirtualMachine.InstanceCounts" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1516 | |
| 1517 | /* ReferenceType command set (2) */ |
| 1518 | { 2, 1, handleRT_Signature, "ReferenceType.Signature" }, |
| 1519 | { 2, 2, handleRT_ClassLoader, "ReferenceType.ClassLoader" }, |
| 1520 | { 2, 3, handleRT_Modifiers, "ReferenceType.Modifiers" }, |
Elliott Hughes | 7b3cdfc | 2011-12-08 21:28:17 -0800 | [diff] [blame] | 1521 | { 2, 4, handleRT_Fields, "ReferenceType.Fields" }, |
| 1522 | { 2, 5, handleRT_Methods, "ReferenceType.Methods" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1523 | { 2, 6, handleRT_GetValues, "ReferenceType.GetValues" }, |
| 1524 | { 2, 7, handleRT_SourceFile, "ReferenceType.SourceFile" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1525 | { 2, 8, NULL, "ReferenceType.NestedTypes" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1526 | { 2, 9, handleRT_Status, "ReferenceType.Status" }, |
| 1527 | { 2, 10, handleRT_Interfaces, "ReferenceType.Interfaces" }, |
| 1528 | { 2, 11, handleRT_ClassObject, "ReferenceType.ClassObject" }, |
| 1529 | { 2, 12, handleRT_SourceDebugExtension, "ReferenceType.SourceDebugExtension" }, |
| 1530 | { 2, 13, handleRT_SignatureWithGeneric, "ReferenceType.SignatureWithGeneric" }, |
| 1531 | { 2, 14, handleRT_FieldsWithGeneric, "ReferenceType.FieldsWithGeneric" }, |
| 1532 | { 2, 15, handleRT_MethodsWithGeneric, "ReferenceType.MethodsWithGeneric" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1533 | { 2, 16, NULL, "ReferenceType.Instances" }, |
| 1534 | { 2, 17, NULL, "ReferenceType.ClassFileVersion" }, |
| 1535 | { 2, 18, NULL, "ReferenceType.ConstantPool" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1536 | |
| 1537 | /* ClassType command set (3) */ |
| 1538 | { 3, 1, handleCT_Superclass, "ClassType.Superclass" }, |
| 1539 | { 3, 2, handleCT_SetValues, "ClassType.SetValues" }, |
| 1540 | { 3, 3, handleCT_InvokeMethod, "ClassType.InvokeMethod" }, |
| 1541 | { 3, 4, handleCT_NewInstance, "ClassType.NewInstance" }, |
| 1542 | |
| 1543 | /* ArrayType command set (4) */ |
| 1544 | { 4, 1, handleAT_newInstance, "ArrayType.NewInstance" }, |
| 1545 | |
| 1546 | /* InterfaceType command set (5) */ |
| 1547 | |
| 1548 | /* Method command set (6) */ |
| 1549 | { 6, 1, handleM_LineTable, "Method.LineTable" }, |
Elliott Hughes | 3d1ca6d | 2012-02-13 15:43:19 -0800 | [diff] [blame] | 1550 | { 6, 2, handleM_VariableTable, "Method.VariableTable" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1551 | { 6, 3, NULL, "Method.Bytecodes" }, |
| 1552 | { 6, 4, NULL, "Method.IsObsolete" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1553 | { 6, 5, handleM_VariableTableWithGeneric, "Method.VariableTableWithGeneric" }, |
| 1554 | |
| 1555 | /* Field command set (8) */ |
| 1556 | |
| 1557 | /* ObjectReference command set (9) */ |
| 1558 | { 9, 1, handleOR_ReferenceType, "ObjectReference.ReferenceType" }, |
| 1559 | { 9, 2, handleOR_GetValues, "ObjectReference.GetValues" }, |
| 1560 | { 9, 3, handleOR_SetValues, "ObjectReference.SetValues" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1561 | { 9, 4, NULL, "ObjectReference.UNUSED" }, |
| 1562 | { 9, 5, NULL, "ObjectReference.MonitorInfo" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1563 | { 9, 6, handleOR_InvokeMethod, "ObjectReference.InvokeMethod" }, |
| 1564 | { 9, 7, handleOR_DisableCollection, "ObjectReference.DisableCollection" }, |
| 1565 | { 9, 8, handleOR_EnableCollection, "ObjectReference.EnableCollection" }, |
| 1566 | { 9, 9, handleOR_IsCollected, "ObjectReference.IsCollected" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1567 | { 9, 10, NULL, "ObjectReference.ReferringObjects" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1568 | |
| 1569 | /* StringReference command set (10) */ |
| 1570 | { 10, 1, handleSR_Value, "StringReference.Value" }, |
| 1571 | |
| 1572 | /* ThreadReference command set (11) */ |
| 1573 | { 11, 1, handleTR_Name, "ThreadReference.Name" }, |
| 1574 | { 11, 2, handleTR_Suspend, "ThreadReference.Suspend" }, |
| 1575 | { 11, 3, handleTR_Resume, "ThreadReference.Resume" }, |
| 1576 | { 11, 4, handleTR_Status, "ThreadReference.Status" }, |
| 1577 | { 11, 5, handleTR_ThreadGroup, "ThreadReference.ThreadGroup" }, |
| 1578 | { 11, 6, handleTR_Frames, "ThreadReference.Frames" }, |
| 1579 | { 11, 7, handleTR_FrameCount, "ThreadReference.FrameCount" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1580 | { 11, 8, NULL, "ThreadReference.OwnedMonitors" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1581 | { 11, 9, handleTR_CurrentContendedMonitor, "ThreadReference.CurrentContendedMonitor" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1582 | { 11, 10, NULL, "ThreadReference.Stop" }, |
| 1583 | { 11, 11, NULL,"ThreadReference.Interrupt" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1584 | { 11, 12, handleTR_SuspendCount, "ThreadReference.SuspendCount" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1585 | { 11, 13, NULL, "ThreadReference.OwnedMonitorsStackDepthInfo" }, |
| 1586 | { 11, 14, NULL, "ThreadReference.ForceEarlyReturn" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1587 | |
| 1588 | /* ThreadGroupReference command set (12) */ |
| 1589 | { 12, 1, handleTGR_Name, "ThreadGroupReference.Name" }, |
| 1590 | { 12, 2, handleTGR_Parent, "ThreadGroupReference.Parent" }, |
| 1591 | { 12, 3, handleTGR_Children, "ThreadGroupReference.Children" }, |
| 1592 | |
| 1593 | /* ArrayReference command set (13) */ |
| 1594 | { 13, 1, handleAR_Length, "ArrayReference.Length" }, |
| 1595 | { 13, 2, handleAR_GetValues, "ArrayReference.GetValues" }, |
| 1596 | { 13, 3, handleAR_SetValues, "ArrayReference.SetValues" }, |
| 1597 | |
| 1598 | /* ClassLoaderReference command set (14) */ |
| 1599 | { 14, 1, handleCLR_VisibleClasses, "ClassLoaderReference.VisibleClasses" }, |
| 1600 | |
| 1601 | /* EventRequest command set (15) */ |
| 1602 | { 15, 1, handleER_Set, "EventRequest.Set" }, |
| 1603 | { 15, 2, handleER_Clear, "EventRequest.Clear" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1604 | { 15, 3, NULL, "EventRequest.ClearAllBreakpoints" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1605 | |
| 1606 | /* StackFrame command set (16) */ |
| 1607 | { 16, 1, handleSF_GetValues, "StackFrame.GetValues" }, |
| 1608 | { 16, 2, handleSF_SetValues, "StackFrame.SetValues" }, |
| 1609 | { 16, 3, handleSF_ThisObject, "StackFrame.ThisObject" }, |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1610 | { 16, 4, NULL, "StackFrame.PopFrames" }, |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1611 | |
| 1612 | /* ClassObjectReference command set (17) */ |
| 1613 | { 17, 1, handleCOR_ReflectedType,"ClassObjectReference.ReflectedType" }, |
| 1614 | |
| 1615 | /* Event command set (64) */ |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1616 | { 64, 100, NULL, "Event.Composite" }, // sent from VM to debugger, never received by VM |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1617 | |
| 1618 | { 199, 1, handleDDM_Chunk, "DDM.Chunk" }, |
| 1619 | }; |
| 1620 | |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1621 | static const char* GetCommandName(size_t cmdSet, size_t cmd) { |
| 1622 | for (int i = 0; i < (int) arraysize(gHandlerMap); i++) { |
| 1623 | if (gHandlerMap[i].cmdSet == cmdSet && gHandlerMap[i].cmd == cmd) { |
| 1624 | return gHandlerMap[i].descr; |
| 1625 | } |
| 1626 | } |
| 1627 | return "?UNKNOWN?"; |
| 1628 | } |
| 1629 | |
| 1630 | static std::string DescribeCommand(const JdwpReqHeader* pHeader, int dataLen) { |
| 1631 | std::string result; |
| 1632 | result += "REQ: "; |
| 1633 | result += GetCommandName(pHeader->cmdSet, pHeader->cmd); |
| 1634 | result += StringPrintf(" (dataLen=%d id=0x%06x)", dataLen, pHeader->id); |
| 1635 | return result; |
| 1636 | } |
| 1637 | |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1638 | /* |
| 1639 | * Process a request from the debugger. |
| 1640 | * |
| 1641 | * On entry, the JDWP thread is in VMWAIT. |
| 1642 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 1643 | void JdwpState::ProcessRequest(const JdwpReqHeader* pHeader, const uint8_t* buf, int dataLen, ExpandBuf* pReply) { |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1644 | JdwpError result = ERR_NONE; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1645 | |
| 1646 | if (pHeader->cmdSet != kJDWPDdmCmdSet) { |
| 1647 | /* |
| 1648 | * Activity from a debugger, not merely ddms. Mark us as having an |
| 1649 | * active debugger session, and zero out the last-activity timestamp |
| 1650 | * so waitForDebugger() doesn't return if we stall for a bit here. |
| 1651 | */ |
Elliott Hughes | a215526 | 2011-11-16 16:26:58 -0800 | [diff] [blame] | 1652 | Dbg::GoActive(); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 1653 | QuasiAtomicSwap64(0, &lastActivityWhen); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | /* |
| 1657 | * If a debugger event has fired in another thread, wait until the |
| 1658 | * initiating thread has suspended itself before processing messages |
| 1659 | * from the debugger. Otherwise we (the JDWP thread) could be told to |
| 1660 | * resume the thread before it has suspended. |
| 1661 | * |
| 1662 | * We call with an argument of zero to wait for the current event |
| 1663 | * thread to finish, and then clear the block. Depending on the thread |
| 1664 | * suspend policy, this may allow events in other threads to fire, |
| 1665 | * but those events have no bearing on what the debugger has sent us |
| 1666 | * in the current request. |
| 1667 | * |
| 1668 | * Note that we MUST clear the event token before waking the event |
| 1669 | * thread up, or risk waiting for the thread to suspend after we've |
| 1670 | * told it to resume. |
| 1671 | */ |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 1672 | SetWaitForEventThread(0); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1673 | |
| 1674 | /* |
| 1675 | * Tell the VM that we're running and shouldn't be interrupted by GC. |
| 1676 | * Do this after anything that can stall indefinitely. |
| 1677 | */ |
| 1678 | Dbg::ThreadRunning(); |
| 1679 | |
| 1680 | expandBufAddSpace(pReply, kJDWPHeaderLen); |
| 1681 | |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1682 | size_t i; |
| 1683 | for (i = 0; i < arraysize(gHandlerMap); i++) { |
| 1684 | if (gHandlerMap[i].cmdSet == pHeader->cmdSet && gHandlerMap[i].cmd == pHeader->cmd && gHandlerMap[i].func != NULL) { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 1685 | VLOG(jdwp) << DescribeCommand(pHeader, dataLen); |
Elliott Hughes | 376a7a0 | 2011-10-24 18:35:55 -0700 | [diff] [blame] | 1686 | result = (*gHandlerMap[i].func)(this, buf, dataLen, pReply); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1687 | break; |
| 1688 | } |
| 1689 | } |
| 1690 | if (i == arraysize(gHandlerMap)) { |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1691 | LOG(ERROR) << DescribeCommand(pHeader, dataLen); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1692 | if (dataLen > 0) { |
| 1693 | HexDump(buf, dataLen); |
| 1694 | } |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1695 | LOG(ERROR) << "command not implemented"; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1696 | result = ERR_NOT_IMPLEMENTED; |
| 1697 | } |
| 1698 | |
| 1699 | /* |
| 1700 | * Set up the reply header. |
| 1701 | * |
| 1702 | * If we encountered an error, only send the header back. |
| 1703 | */ |
| 1704 | uint8_t* replyBuf = expandBufGetBuffer(pReply); |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1705 | Set4BE(replyBuf + 4, pHeader->id); |
| 1706 | Set1(replyBuf + 8, kJDWPFlagReply); |
| 1707 | Set2BE(replyBuf + 9, result); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1708 | if (result == ERR_NONE) { |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1709 | Set4BE(replyBuf + 0, expandBufGetLength(pReply)); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1710 | } else { |
Elliott Hughes | f7c3b66 | 2011-10-27 12:04:56 -0700 | [diff] [blame] | 1711 | Set4BE(replyBuf + 0, kJDWPHeaderLen); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
Elliott Hughes | a3c24aa | 2011-12-07 15:34:09 -0800 | [diff] [blame] | 1714 | size_t respLen = expandBufGetLength(pReply) - kJDWPHeaderLen; |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1715 | if (false) { |
| 1716 | LOG(INFO) << "reply: dataLen=" << respLen << " err=" << result << (result != ERR_NONE ? " **FAILED**" : ""); |
| 1717 | if (respLen > 0) { |
| 1718 | HexDump(expandBufGetBuffer(pReply) + kJDWPHeaderLen, respLen); |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | /* |
| 1723 | * Update last-activity timestamp. We really only need this during |
| 1724 | * the initial setup. Only update if this is a non-DDMS packet. |
| 1725 | */ |
| 1726 | if (pHeader->cmdSet != kJDWPDdmCmdSet) { |
Elliott Hughes | 7162ad9 | 2011-10-27 14:08:42 -0700 | [diff] [blame] | 1727 | QuasiAtomicSwap64(MilliTime(), &lastActivityWhen); |
Elliott Hughes | 872d4ec | 2011-10-21 17:07:15 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | /* tell the VM that GC is okay again */ |
| 1731 | Dbg::ThreadWaiting(); |
| 1732 | } |
| 1733 | |
| 1734 | } // namespace JDWP |
| 1735 | |
| 1736 | } // namespace art |