Skip to content

Commit 4f8151e

Browse files
committed
[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
1 parent 7cb720d commit 4f8151e

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationServerCommon.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@
3030
#include "lldb/Target/Platform.h"
3131
#include "lldb/Utility/Endian.h"
3232
#include "lldb/Utility/GDBRemote.h"
33-
#include "lldb/Utility/JSON.h"
3433
#include "lldb/Utility/Log.h"
3534
#include "lldb/Utility/StreamString.h"
3635
#include "lldb/Utility/StructuredData.h"
36+
#include "llvm/ADT/StringSwitch.h"
3737
#include "llvm/ADT/Triple.h"
38+
#include "llvm/Support/JSON.h"
3839

3940
#include "ProcessGDBRemoteLog.h"
4041
#include "lldb/Utility/StringExtractorGDBRemote.h"
@@ -43,11 +44,10 @@
4344
#include "lldb/Host/android/HostInfoAndroid.h"
4445
#endif
4546

46-
#include "llvm/ADT/StringSwitch.h"
4747

4848
using namespace lldb;
49-
using namespace lldb_private;
5049
using namespace lldb_private::process_gdb_remote;
50+
using namespace lldb_private;
5151

5252
#ifdef __ANDROID__
5353
const static uint32_t g_default_packet_timeout_sec = 20; // seconds
@@ -1120,6 +1120,8 @@ GDBRemoteCommunicationServerCommon::Handle_qModuleInfo(
11201120
GDBRemoteCommunication::PacketResult
11211121
GDBRemoteCommunicationServerCommon::Handle_jModulesInfo(
11221122
StringExtractorGDBRemote &packet) {
1123+
namespace json = llvm::json;
1124+
11231125
packet.SetFilePos(::strlen("jModulesInfo:"));
11241126

11251127
StructuredData::ObjectSP object_sp = StructuredData::ParseJSON(packet.Peek());
@@ -1130,7 +1132,7 @@ GDBRemoteCommunicationServerCommon::Handle_jModulesInfo(
11301132
if (!packet_array)
11311133
return SendErrorResponse(2);
11321134

1133-
JSONArray::SP response_array_sp = std::make_shared<JSONArray>();
1135+
json::Array response_array;
11341136
for (size_t i = 0; i < packet_array->GetSize(); ++i) {
11351137
StructuredData::Dictionary *query =
11361138
packet_array->GetItemAtIndex(i)->GetAsDictionary();
@@ -1148,27 +1150,22 @@ GDBRemoteCommunicationServerCommon::Handle_jModulesInfo(
11481150
const auto file_offset = matched_module_spec.GetObjectOffset();
11491151
const auto file_size = matched_module_spec.GetObjectSize();
11501152
const auto uuid_str = matched_module_spec.GetUUID().GetAsString("");
1151-
11521153
if (uuid_str.empty())
11531154
continue;
1154-
1155-
JSONObject::SP response = std::make_shared<JSONObject>();
1156-
response_array_sp->AppendObject(response);
1157-
response->SetObject("uuid", std::make_shared<JSONString>(uuid_str));
1158-
response->SetObject(
1159-
"triple",
1160-
std::make_shared<JSONString>(
1161-
matched_module_spec.GetArchitecture().GetTriple().getTriple()));
1162-
response->SetObject("file_path",
1163-
std::make_shared<JSONString>(
1164-
matched_module_spec.GetFileSpec().GetPath()));
1165-
response->SetObject("file_offset",
1166-
std::make_shared<JSONNumber>(file_offset));
1167-
response->SetObject("file_size", std::make_shared<JSONNumber>(file_size));
1155+
const auto triple_str =
1156+
matched_module_spec.GetArchitecture().GetTriple().getTriple();
1157+
const auto file_path = matched_module_spec.GetFileSpec().GetPath();
1158+
1159+
json::Object response{{"uuid", uuid_str},
1160+
{"triple", triple_str},
1161+
{"file_path", file_path},
1162+
{"file_offset", static_cast<int64_t>(file_offset)},
1163+
{"file_size", static_cast<int64_t>(file_size)}};
1164+
response_array.push_back(std::move(response));
11681165
}
11691166

11701167
StreamString response;
1171-
response_array_sp->Write(response);
1168+
response.AsRawOstream() << std::move(response_array);
11721169
StreamGDBRemote escaped_response;
11731170
escaped_response.PutEscapedBytes(response.GetString().data(),
11741171
response.GetSize());

0 commit comments

Comments
 (0)