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