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