diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2019-10-02 18:02:32 +0000 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2019-10-02 18:02:32 +0000 |
commit | 2e9dd1f5dfb58ad0edc16beed08be202b9621e72 (patch) | |
tree | 4d9abfbf1652465b2d7dd368811943e442503aba /source | |
parent | 75f80cd66ddc72039673437799620d432c1eee19 (diff) | |
download | lldb-2e9dd1f5dfb58ad0edc16beed08be202b9621e72.tar.gz |
[JSON] Use LLVM's library for encoding JSON in GDBRemoteCommunicationServerCommon
This patch replaces the LLDB's JSON implementation with the one from
LLVM in GDBRemoteCommunicationServerCommon.
Differential revision: https://reviews.llvm.org/D68304
git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@373500 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'source')
-rw-r--r-- | source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp index f60991034..c5a07a88d 100644 --- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp +++ b/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 @@ GDBRemoteCommunicationServerCommon::Handle_qModuleInfo( 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 @@ GDBRemoteCommunicationServerCommon::Handle_jModulesInfo( if (!packet_array) return SendErrorResponse(2); - JSONArray::SP response_array_sp = std::make_shared<JSONArray>(); + 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 @@ GDBRemoteCommunicationServerCommon::Handle_jModulesInfo( 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<JSONObject>(); - response_array_sp->AppendObject(response); - response->SetObject("uuid", std::make_shared<JSONString>(uuid_str)); - response->SetObject( - "triple", - std::make_shared<JSONString>( - matched_module_spec.GetArchitecture().GetTriple().getTriple())); - response->SetObject("file_path", - std::make_shared<JSONString>( - matched_module_spec.GetFileSpec().GetPath())); - response->SetObject("file_offset", - std::make_shared<JSONNumber>(file_offset)); - response->SetObject("file_size", std::make_shared<JSONNumber>(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<int64_t>(file_offset)}, + {"file_size", static_cast<int64_t>(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()); |