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