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