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