diff options
-rw-r--r-- | runtime/debugger.cc | 22 | ||||
-rw-r--r-- | runtime/debugger.h | 2 | ||||
-rw-r--r-- | runtime/jdwp/jdwp_handler.cc | 13 |
3 files changed, 30 insertions, 7 deletions
diff --git a/runtime/debugger.cc b/runtime/debugger.cc index 001032ce1e..df51973b38 100644 --- a/runtime/debugger.cc +++ b/runtime/debugger.cc @@ -1886,11 +1886,25 @@ JDWP::JdwpError Dbg::SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, return SetFieldValueImpl(0, field_id, value, width, true); } -std::string Dbg::StringToUtf8(JDWP::ObjectId string_id) { +JDWP::JdwpError Dbg::StringToUtf8(JDWP::ObjectId string_id, std::string* str) { JDWP::JdwpError error; - mirror::String* s = gRegistry->Get<mirror::String*>(string_id, &error); - CHECK(s != nullptr) << error; - return s->ToModifiedUtf8(); + mirror::Object* obj = gRegistry->Get<mirror::Object*>(string_id, &error); + if (error != JDWP::ERR_NONE) { + return error; + } + if (obj == nullptr) { + return JDWP::ERR_INVALID_OBJECT; + } + { + ScopedObjectAccessUnchecked soa(Thread::Current()); + mirror::Class* java_lang_String = soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_String); + if (!java_lang_String->IsAssignableFrom(obj->GetClass())) { + // This isn't a string. + return JDWP::ERR_INVALID_STRING; + } + } + *str = obj->AsString()->ToModifiedUtf8(); + return JDWP::ERR_NONE; } void Dbg::OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply) { diff --git a/runtime/debugger.h b/runtime/debugger.h index ab758caf69..e171d7854f 100644 --- a/runtime/debugger.h +++ b/runtime/debugger.h @@ -381,7 +381,7 @@ class Dbg { static JDWP::JdwpError SetStaticFieldValue(JDWP::FieldId field_id, uint64_t value, int width) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); - static std::string StringToUtf8(JDWP::ObjectId string_id) + static JDWP::JdwpError StringToUtf8(JDWP::ObjectId string_id, std::string* str) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); static void OutputJValue(JDWP::JdwpTag tag, const JValue* return_value, JDWP::ExpandBuf* pReply) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); diff --git a/runtime/jdwp/jdwp_handler.cc b/runtime/jdwp/jdwp_handler.cc index 8560cb5bc8..e0a83f607b 100644 --- a/runtime/jdwp/jdwp_handler.cc +++ b/runtime/jdwp/jdwp_handler.cc @@ -151,7 +151,12 @@ static JdwpError FinishInvoke(JdwpState*, Request* request, ExpandBuf* pReply, /* show detailed debug output */ if (resultTag == JT_STRING && exceptObjId == 0) { if (resultValue != 0) { - VLOG(jdwp) << " string '" << Dbg::StringToUtf8(resultValue) << "'"; + if (VLOG_IS_ON(jdwp)) { + std::string result_string; + JDWP::JdwpError error = Dbg::StringToUtf8(resultValue, &result_string); + CHECK_EQ(error, JDWP::ERR_NONE); + VLOG(jdwp) << " string '" << result_string << "'"; + } } else { VLOG(jdwp) << " string (null)"; } @@ -919,7 +924,11 @@ static JdwpError OR_ReferringObjects(JdwpState*, Request* request, ExpandBuf* re static JdwpError SR_Value(JdwpState*, Request* request, ExpandBuf* pReply) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { ObjectId stringObject = request->ReadObjectId(); - std::string str(Dbg::StringToUtf8(stringObject)); + std::string str; + JDWP::JdwpError error = Dbg::StringToUtf8(stringObject, &str); + if (error != JDWP::ERR_NONE) { + return error; + } VLOG(jdwp) << StringPrintf(" --> %s", PrintableString(str.c_str()).c_str()); |