1 //===-- TraceGDBRemotePackets.cpp -------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Utility/TraceGDBRemotePackets.h"
12 using namespace llvm::json
;
14 namespace lldb_private
{
15 /// jLLDBTraceSupported
17 bool fromJSON(const json::Value
&value
, TraceSupportedResponse
&packet
,
19 ObjectMapper
o(value
, path
);
20 return o
&& o
.map("description", packet
.description
) &&
21 o
.map("name", packet
.name
);
24 json::Value
toJSON(const TraceSupportedResponse
&packet
) {
26 Object
{{"description", packet
.description
}, {"name", packet
.name
}});
32 bool TraceStartRequest::IsProcessTracing() const { return !(bool)tids
; }
34 bool fromJSON(const json::Value
&value
, TraceStartRequest
&packet
, Path path
) {
35 ObjectMapper
o(value
, path
);
36 return o
&& o
.map("type", packet
.type
) && o
.map("tids", packet
.tids
);
39 json::Value
toJSON(const TraceStartRequest
&packet
) {
40 return json::Value(Object
{{"tids", packet
.tids
}, {"type", packet
.type
}});
46 TraceStopRequest::TraceStopRequest(llvm::StringRef type
,
47 const std::vector
<lldb::tid_t
> &tids_
)
50 for (lldb::tid_t tid
: tids_
)
54 bool TraceStopRequest::IsProcessTracing() const { return !(bool)tids
; }
56 bool fromJSON(const json::Value
&value
, TraceStopRequest
&packet
, Path path
) {
57 ObjectMapper
o(value
, path
);
58 return o
&& o
.map("type", packet
.type
) && o
.map("tids", packet
.tids
);
61 json::Value
toJSON(const TraceStopRequest
&packet
) {
62 return json::Value(Object
{{"type", packet
.type
}, {"tids", packet
.tids
}});
66 /// jLLDBTraceGetState
68 bool fromJSON(const json::Value
&value
, TraceGetStateRequest
&packet
,
70 ObjectMapper
o(value
, path
);
71 return o
&& o
.map("type", packet
.type
);
74 json::Value
toJSON(const TraceGetStateRequest
&packet
) {
75 return json::Value(Object
{{"type", packet
.type
}});
78 bool fromJSON(const json::Value
&value
, TraceBinaryData
&packet
, Path path
) {
79 ObjectMapper
o(value
, path
);
80 return o
&& o
.map("kind", packet
.kind
) && o
.map("size", packet
.size
);
83 json::Value
toJSON(const TraceBinaryData
&packet
) {
84 return json::Value(Object
{{"kind", packet
.kind
}, {"size", packet
.size
}});
87 bool fromJSON(const json::Value
&value
, TraceThreadState
&packet
, Path path
) {
88 ObjectMapper
o(value
, path
);
89 return o
&& o
.map("tid", packet
.tid
) &&
90 o
.map("binaryData", packet
.binary_data
);
93 json::Value
toJSON(const TraceThreadState
&packet
) {
95 Object
{{"tid", packet
.tid
}, {"binaryData", packet
.binary_data
}});
98 bool fromJSON(const json::Value
&value
, TraceGetStateResponse
&packet
,
100 ObjectMapper
o(value
, path
);
101 return o
&& o
.map("tracedThreads", packet
.traced_threads
) &&
102 o
.map("processBinaryData", packet
.process_binary_data
) &&
103 o
.map("cpus", packet
.cpus
) && o
.map("warnings", packet
.warnings
);
106 json::Value
toJSON(const TraceGetStateResponse
&packet
) {
107 return json::Value(Object
{{"tracedThreads", packet
.traced_threads
},
108 {"processBinaryData", packet
.process_binary_data
},
109 {"cpus", packet
.cpus
},
110 {"warnings", packet
.warnings
}});
113 void TraceGetStateResponse::AddWarning(StringRef warning
) {
116 warnings
->push_back(warning
.data());
119 bool fromJSON(const json::Value
&value
, TraceCpuState
&packet
,
121 ObjectMapper
o(value
, path
);
123 if (!(o
&& o
.map("id", cpu_id
) && o
.map("binaryData", packet
.binary_data
)))
125 packet
.id
= static_cast<lldb::cpu_id_t
>(cpu_id
);
129 json::Value
toJSON(const TraceCpuState
&packet
) {
131 Object
{{"id", packet
.id
}, {"binaryData", packet
.binary_data
}});
135 /// jLLDBTraceGetBinaryData
137 json::Value
toJSON(const TraceGetBinaryDataRequest
&packet
) {
138 return json::Value(Object
{{"type", packet
.type
},
139 {"kind", packet
.kind
},
141 {"cpuId", packet
.cpu_id
}});
144 bool fromJSON(const json::Value
&value
, TraceGetBinaryDataRequest
&packet
,
146 ObjectMapper
o(value
, path
);
147 std::optional
<uint64_t> cpu_id
;
148 if (!(o
&& o
.map("type", packet
.type
) && o
.map("kind", packet
.kind
) &&
149 o
.map("tid", packet
.tid
) && o
.map("cpuId", cpu_id
)))
153 packet
.cpu_id
= static_cast<lldb::cpu_id_t
>(*cpu_id
);
158 } // namespace lldb_private