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