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