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