[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

llvm-svn: 373500
This commit is contained in:
Jonas Devlieghere 2019-10-02 18:02:32 +00:00
parent 7cb720dda0
commit 4f8151e62e
1 changed files with 16 additions and 19 deletions

View File

@ -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;
const auto triple_str =
matched_module_spec.GetArchitecture().GetTriple().getTriple();
const auto file_path = matched_module_spec.GetFileSpec().GetPath();
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));
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());