diff options
Diffstat (limited to 'runtime/debugger.cc')
-rw-r--r-- | runtime/debugger.cc | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/runtime/debugger.cc b/runtime/debugger.cc index 9f3c2aa89b..6ed44fc5c4 100644 --- a/runtime/debugger.cc +++ b/runtime/debugger.cc @@ -28,6 +28,7 @@ #include "class_linker.h" #include "class_linker-inl.h" #include "dex_file-inl.h" +#include "dex_file_annotations.h" #include "dex_instruction.h" #include "entrypoints/runtime_asm_entrypoints.h" #include "gc/accounting/card_table-inl.h" @@ -1760,22 +1761,32 @@ static JDWP::JdwpError GetFieldValueImpl(JDWP::RefTypeId ref_type_id, JDWP::Obje return error; } - mirror::Object* o = Dbg::GetObjectRegistry()->Get<mirror::Object*>(object_id, &error); - if ((!is_static && o == nullptr) || error != JDWP::ERR_NONE) { + Thread* self = Thread::Current(); + StackHandleScope<2> hs(self); + MutableHandle<mirror::Object> + o(hs.NewHandle(Dbg::GetObjectRegistry()->Get<mirror::Object*>(object_id, &error))); + if ((!is_static && o.Get() == nullptr) || error != JDWP::ERR_NONE) { return JDWP::ERR_INVALID_OBJECT; } ArtField* f = FromFieldId(field_id); mirror::Class* receiver_class = c; - if (receiver_class == nullptr && o != nullptr) { + if (receiver_class == nullptr && o.Get() != nullptr) { receiver_class = o->GetClass(); } + // TODO: should we give up now if receiver_class is null? if (receiver_class != nullptr && !f->GetDeclaringClass()->IsAssignableFrom(receiver_class)) { LOG(INFO) << "ERR_INVALID_FIELDID: " << PrettyField(f) << " " << PrettyClass(receiver_class); return JDWP::ERR_INVALID_FIELDID; } + // Ensure the field's class is initialized. + Handle<mirror::Class> klass(hs.NewHandle(f->GetDeclaringClass())); + if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, klass, true, false)) { + LOG(WARNING) << "Not able to initialize class for SetValues: " << PrettyClass(klass.Get()); + } + // The RI only enforces the static/non-static mismatch in one direction. // TODO: should we change the tests and check both? if (is_static) { @@ -1789,10 +1800,10 @@ static JDWP::JdwpError GetFieldValueImpl(JDWP::RefTypeId ref_type_id, JDWP::Obje } } if (f->IsStatic()) { - o = f->GetDeclaringClass(); + o.Assign(f->GetDeclaringClass()); } - JValue field_value(GetArtFieldValue(f, o)); + JValue field_value(GetArtFieldValue(f, o.Get())); JDWP::JdwpTag tag = BasicTagFromDescriptor(f->GetTypeDescriptor()); Dbg::OutputJValue(tag, &field_value, pReply); return JDWP::ERR_NONE; @@ -1882,12 +1893,21 @@ static JDWP::JdwpError SetFieldValueImpl(JDWP::ObjectId object_id, JDWP::FieldId uint64_t value, int width, bool is_static) REQUIRES_SHARED(Locks::mutator_lock_) { JDWP::JdwpError error; - mirror::Object* o = Dbg::GetObjectRegistry()->Get<mirror::Object*>(object_id, &error); - if ((!is_static && o == nullptr) || error != JDWP::ERR_NONE) { + Thread* self = Thread::Current(); + StackHandleScope<2> hs(self); + MutableHandle<mirror::Object> + o(hs.NewHandle(Dbg::GetObjectRegistry()->Get<mirror::Object*>(object_id, &error))); + if ((!is_static && o.Get() == nullptr) || error != JDWP::ERR_NONE) { return JDWP::ERR_INVALID_OBJECT; } ArtField* f = FromFieldId(field_id); + // Ensure the field's class is initialized. + Handle<mirror::Class> klass(hs.NewHandle(f->GetDeclaringClass())); + if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, klass, true, false)) { + LOG(WARNING) << "Not able to initialize class for SetValues: " << PrettyClass(klass.Get()); + } + // The RI only enforces the static/non-static mismatch in one direction. // TODO: should we change the tests and check both? if (is_static) { @@ -1901,9 +1921,9 @@ static JDWP::JdwpError SetFieldValueImpl(JDWP::ObjectId object_id, JDWP::FieldId } } if (f->IsStatic()) { - o = f->GetDeclaringClass(); + o.Assign(f->GetDeclaringClass()); } - return SetArtFieldValue(f, o, value, width); + return SetArtFieldValue(f, o.Get(), value, width); } JDWP::JdwpError Dbg::SetFieldValue(JDWP::ObjectId object_id, JDWP::FieldId field_id, uint64_t value, @@ -1986,7 +2006,7 @@ JDWP::JdwpError Dbg::GetThreadGroup(JDWP::ObjectId thread_id, JDWP::ExpandBuf* p if (error != JDWP::ERR_NONE) { return JDWP::ERR_INVALID_OBJECT; } - ScopedAssertNoThreadSuspension ants(soa.Self(), "Debugger: GetThreadGroup"); + ScopedAssertNoThreadSuspension ants("Debugger: GetThreadGroup"); // Okay, so it's an object, but is it actually a thread? DecodeThread(soa, thread_id, &error); if (error == JDWP::ERR_THREAD_NOT_ALIVE) { @@ -2036,7 +2056,7 @@ JDWP::JdwpError Dbg::GetThreadGroupName(JDWP::ObjectId thread_group_id, JDWP::Ex if (error != JDWP::ERR_NONE) { return error; } - ScopedAssertNoThreadSuspension ants(soa.Self(), "Debugger: GetThreadGroupName"); + ScopedAssertNoThreadSuspension ants("Debugger: GetThreadGroupName"); ArtField* f = soa.DecodeField(WellKnownClasses::java_lang_ThreadGroup_name); CHECK(f != nullptr); mirror::String* s = reinterpret_cast<mirror::String*>(f->GetObject(thread_group)); @@ -2055,7 +2075,7 @@ JDWP::JdwpError Dbg::GetThreadGroupParent(JDWP::ObjectId thread_group_id, JDWP:: } mirror::Object* parent; { - ScopedAssertNoThreadSuspension ants(soa.Self(), "Debugger: GetThreadGroupParent"); + ScopedAssertNoThreadSuspension ants("Debugger: GetThreadGroupParent"); ArtField* f = soa.DecodeField(WellKnownClasses::java_lang_ThreadGroup_parent); CHECK(f != nullptr); parent = f->GetObject(thread_group); @@ -3694,8 +3714,8 @@ JDWP::JdwpError Dbg::ConfigureStep(JDWP::ObjectId thread_id, JDWP::JdwpStepSize mirror::DexCache* dex_cache = m->GetDeclaringClass()->GetDexCache(); method = m; if (dex_cache != nullptr) { - const DexFile& dex_file = *dex_cache->GetDexFile(); - line_number = dex_file.GetLineNumFromPC(m, GetDexPc()); + const DexFile* dex_file = dex_cache->GetDexFile(); + line_number = annotations::GetLineNumFromPC(dex_file, m, GetDexPc()); } } } |