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