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