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