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