Index: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp =================================================================== --- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp @@ -30,11 +30,12 @@ #include "lldb/Target/Platform.h" #include "lldb/Utility/Endian.h" #include "lldb/Utility/GDBRemote.h" -#include "lldb/Utility/JSON.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/StreamString.h" #include "lldb/Utility/StructuredData.h" +#include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" +#include "llvm/Support/JSON.h" #include "ProcessGDBRemoteLog.h" #include "lldb/Utility/StringExtractorGDBRemote.h" @@ -43,11 +44,10 @@ #include "lldb/Host/android/HostInfoAndroid.h" #endif -#include "llvm/ADT/StringSwitch.h" using namespace lldb; -using namespace lldb_private; using namespace lldb_private::process_gdb_remote; +using namespace lldb_private; #ifdef __ANDROID__ const static uint32_t g_default_packet_timeout_sec = 20; // seconds @@ -1120,6 +1120,8 @@ GDBRemoteCommunication::PacketResult GDBRemoteCommunicationServerCommon::Handle_jModulesInfo( StringExtractorGDBRemote &packet) { + namespace json = llvm::json; + packet.SetFilePos(::strlen("jModulesInfo:")); StructuredData::ObjectSP object_sp = StructuredData::ParseJSON(packet.Peek()); @@ -1130,7 +1132,7 @@ if (!packet_array) return SendErrorResponse(2); - JSONArray::SP response_array_sp = std::make_shared(); + json::Array response_array; for (size_t i = 0; i < packet_array->GetSize(); ++i) { StructuredData::Dictionary *query = packet_array->GetItemAtIndex(i)->GetAsDictionary(); @@ -1148,27 +1150,22 @@ const auto file_offset = matched_module_spec.GetObjectOffset(); const auto file_size = matched_module_spec.GetObjectSize(); const auto uuid_str = matched_module_spec.GetUUID().GetAsString(""); - if (uuid_str.empty()) continue; - - JSONObject::SP response = std::make_shared(); - response_array_sp->AppendObject(response); - response->SetObject("uuid", std::make_shared(uuid_str)); - response->SetObject( - "triple", - std::make_shared( - matched_module_spec.GetArchitecture().GetTriple().getTriple())); - response->SetObject("file_path", - std::make_shared( - matched_module_spec.GetFileSpec().GetPath())); - response->SetObject("file_offset", - std::make_shared(file_offset)); - response->SetObject("file_size", std::make_shared(file_size)); + const auto triple_str = + matched_module_spec.GetArchitecture().GetTriple().getTriple(); + const auto file_path = matched_module_spec.GetFileSpec().GetPath(); + + json::Object response{{"uuid", uuid_str}, + {"triple", triple_str}, + {"file_path", file_path}, + {"file_offset", static_cast(file_offset)}, + {"file_size", static_cast(file_size)}}; + response_array.push_back(std::move(response)); } StreamString response; - response_array_sp->Write(response); + response.AsRawOstream() << std::move(response_array); StreamGDBRemote escaped_response; escaped_response.PutEscapedBytes(response.GetString().data(), response.GetSize());