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