1//===-- TraceGDBRemotePackets.cpp -------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "lldb/Utility/TraceGDBRemotePackets.h"
10
11using namespace llvm;
12using namespace llvm::json;
13
14namespace lldb_private {
15/// jLLDBTraceSupported
16/// \{
17bool fromJSON(const json::Value &value, TraceSupportedResponse &packet,
18 Path path) {
19 ObjectMapper o(value, path);
20 return o && o.map(Prop: "description", Out&: packet.description) &&
21 o.map(Prop: "name", Out&: packet.name);
22}
23
24json::Value toJSON(const TraceSupportedResponse &packet) {
25 return json::Value(
26 Object{{.K: "description", .V: packet.description}, {.K: "name", .V: packet.name}});
27}
28/// \}
29
30/// jLLDBTraceStart
31/// \{
32bool TraceStartRequest::IsProcessTracing() const { return !(bool)tids; }
33
34bool fromJSON(const json::Value &value, TraceStartRequest &packet, Path path) {
35 ObjectMapper o(value, path);
36 return o && o.map(Prop: "type", Out&: packet.type) && o.map(Prop: "tids", Out&: packet.tids);
37}
38
39json::Value toJSON(const TraceStartRequest &packet) {
40 return json::Value(Object{{.K: "tids", .V: packet.tids}, {.K: "type", .V: packet.type}});
41}
42/// \}
43
44/// jLLDBTraceStop
45/// \{
46TraceStopRequest::TraceStopRequest(llvm::StringRef type,
47 const std::vector<lldb::tid_t> &tids_)
48 : type(type) {
49 tids.emplace();
50 for (lldb::tid_t tid : tids_)
51 tids->push_back(x: tid);
52}
53
54bool TraceStopRequest::IsProcessTracing() const { return !(bool)tids; }
55
56bool fromJSON(const json::Value &value, TraceStopRequest &packet, Path path) {
57 ObjectMapper o(value, path);
58 return o && o.map(Prop: "type", Out&: packet.type) && o.map(Prop: "tids", Out&: packet.tids);
59}
60
61json::Value toJSON(const TraceStopRequest &packet) {
62 return json::Value(Object{{.K: "type", .V: packet.type}, {.K: "tids", .V: packet.tids}});
63}
64/// \}
65
66/// jLLDBTraceGetState
67/// \{
68bool fromJSON(const json::Value &value, TraceGetStateRequest &packet,
69 Path path) {
70 ObjectMapper o(value, path);
71 return o && o.map(Prop: "type", Out&: packet.type);
72}
73
74json::Value toJSON(const TraceGetStateRequest &packet) {
75 return json::Value(Object{{.K: "type", .V: packet.type}});
76}
77
78bool fromJSON(const json::Value &value, TraceBinaryData &packet, Path path) {
79 ObjectMapper o(value, path);
80 return o && o.map(Prop: "kind", Out&: packet.kind) && o.map(Prop: "size", Out&: packet.size);
81}
82
83json::Value toJSON(const TraceBinaryData &packet) {
84 return json::Value(Object{{.K: "kind", .V: packet.kind}, {.K: "size", .V: packet.size}});
85}
86
87bool fromJSON(const json::Value &value, TraceThreadState &packet, Path path) {
88 ObjectMapper o(value, path);
89 return o && o.map(Prop: "tid", Out&: packet.tid) &&
90 o.map(Prop: "binaryData", Out&: packet.binary_data);
91}
92
93json::Value toJSON(const TraceThreadState &packet) {
94 return json::Value(
95 Object{{.K: "tid", .V: packet.tid}, {.K: "binaryData", .V: packet.binary_data}});
96}
97
98bool fromJSON(const json::Value &value, TraceGetStateResponse &packet,
99 Path path) {
100 ObjectMapper o(value, path);
101 return o && o.map(Prop: "tracedThreads", Out&: packet.traced_threads) &&
102 o.map(Prop: "processBinaryData", Out&: packet.process_binary_data) &&
103 o.map(Prop: "cpus", Out&: packet.cpus) && o.map(Prop: "warnings", Out&: packet.warnings);
104}
105
106json::Value toJSON(const TraceGetStateResponse &packet) {
107 return json::Value(Object{{.K: "tracedThreads", .V: packet.traced_threads},
108 {.K: "processBinaryData", .V: packet.process_binary_data},
109 {.K: "cpus", .V: packet.cpus},
110 {.K: "warnings", .V: packet.warnings}});
111}
112
113void TraceGetStateResponse::AddWarning(StringRef warning) {
114 if (!warnings)
115 warnings.emplace();
116 warnings->push_back(x: warning.data());
117}
118
119bool fromJSON(const json::Value &value, TraceCpuState &packet,
120 json::Path path) {
121 ObjectMapper o(value, path);
122 uint64_t cpu_id;
123 if (!(o && o.map(Prop: "id", Out&: cpu_id) && o.map(Prop: "binaryData", Out&: packet.binary_data)))
124 return false;
125 packet.id = static_cast<lldb::cpu_id_t>(cpu_id);
126 return true;
127}
128
129json::Value toJSON(const TraceCpuState &packet) {
130 return json::Value(
131 Object{{.K: "id", .V: packet.id}, {.K: "binaryData", .V: packet.binary_data}});
132}
133/// \}
134
135/// jLLDBTraceGetBinaryData
136/// \{
137json::Value toJSON(const TraceGetBinaryDataRequest &packet) {
138 return json::Value(Object{{.K: "type", .V: packet.type},
139 {.K: "kind", .V: packet.kind},
140 {.K: "tid", .V: packet.tid},
141 {.K: "cpuId", .V: packet.cpu_id}});
142}
143
144bool fromJSON(const json::Value &value, TraceGetBinaryDataRequest &packet,
145 Path path) {
146 ObjectMapper o(value, path);
147 std::optional<uint64_t> cpu_id;
148 if (!(o && o.map(Prop: "type", Out&: packet.type) && o.map(Prop: "kind", Out&: packet.kind) &&
149 o.map(Prop: "tid", Out&: packet.tid) && o.map(Prop: "cpuId", Out&: cpu_id)))
150 return false;
151
152 if (cpu_id)
153 packet.cpu_id = static_cast<lldb::cpu_id_t>(*cpu_id);
154 return true;
155}
156/// \}
157
158} // namespace lldb_private
159

source code of lldb/source/Utility/TraceGDBRemotePackets.cpp