LLDB mainline
Trace.cpp
Go to the documentation of this file.
1//===-- Trace.cpp ---------------------------------------------------------===//
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/Target/Trace.h"
10
11#include "llvm/Support/Format.h"
12
13#include "lldb/Core/Module.h"
17#include "lldb/Target/Process.h"
19#include "lldb/Target/Thread.h"
21#include "lldb/Utility/Stream.h"
22#include <optional>
23
24using namespace lldb;
25using namespace lldb_private;
26using namespace llvm;
27
28// Helper structs used to extract the type of a JSON trace bundle description
29// object without having to parse the entire object.
30
32 std::string type;
33};
34
35namespace llvm {
36namespace json {
37
39 Path path) {
40 json::ObjectMapper o(value, path);
41 return o && o.map("type", bundle.type);
42}
43
44} // namespace json
45} // namespace llvm
46
47/// Helper functions for fetching data in maps and returning Optionals or
48/// pointers instead of iterators for simplicity. It's worth mentioning that the
49/// Optionals version can't return the inner data by reference because of
50/// limitations in move constructors.
51/// \{
52template <typename K, typename V>
53static std::optional<V> Lookup(DenseMap<K, V> &map, K k) {
54 auto it = map.find(k);
55 if (it == map.end())
56 return std::nullopt;
57 return it->second;
58}
59
60template <typename K, typename V>
61static V *LookupAsPtr(DenseMap<K, V> &map, K k) {
62 auto it = map.find(k);
63 if (it == map.end())
64 return nullptr;
65 return &it->second;
66}
67
68/// Similar to the methods above but it looks for an item in a map of maps.
69template <typename K1, typename K2, typename V>
70static std::optional<V> Lookup(DenseMap<K1, DenseMap<K2, V>> &map, K1 k1,
71 K2 k2) {
72 auto it = map.find(k1);
73 if (it == map.end())
74 return std::nullopt;
75 return Lookup(it->second, k2);
76}
77
78/// Similar to the methods above but it looks for an item in a map of maps.
79template <typename K1, typename K2, typename V>
80static V *LookupAsPtr(DenseMap<K1, DenseMap<K2, V>> &map, K1 k1, K2 k2) {
81 auto it = map.find(k1);
82 if (it == map.end())
83 return nullptr;
84 return LookupAsPtr(it->second, k2);
85}
86/// \}
87
88static Error createInvalidPlugInError(StringRef plugin_name) {
89 return createStringError(
90 std::errc::invalid_argument,
91 "no trace plug-in matches the specified type: \"%s\"",
92 plugin_name.data());
93}
94
95Expected<lldb::TraceSP>
97 const FileSpec &trace_description_file) {
98
99 auto buffer_or_error =
100 MemoryBuffer::getFile(trace_description_file.GetPath());
101 if (!buffer_or_error) {
102 return createStringError(std::errc::invalid_argument,
103 "could not open input file: %s - %s.",
104 trace_description_file.GetPath().c_str(),
105 buffer_or_error.getError().message().c_str());
106 }
107
108 Expected<json::Value> session_file =
109 json::parse(buffer_or_error.get()->getBuffer().str());
110 if (!session_file) {
111 return session_file.takeError();
112 }
113
115 debugger, *session_file, trace_description_file.GetDirectory());
116}
117
119 Debugger &debugger, const json::Value &trace_bundle_description,
120 StringRef bundle_dir) {
122 json::Path::Root root("traceBundle");
123 if (!json::fromJSON(trace_bundle_description, json_bundle, root))
124 return root.getError();
125
126 if (auto create_callback =
128 return create_callback(trace_bundle_description, bundle_dir, debugger);
129
130 return createInvalidPlugInError(json_bundle.type);
131}
132
133Expected<lldb::TraceSP> Trace::FindPluginForLiveProcess(llvm::StringRef name,
134 Process &process) {
135 if (!process.IsLiveDebugSession())
136 return createStringError(inconvertibleErrorCode(),
137 "Can't trace non-live processes");
138
139 if (auto create_callback =
141 return create_callback(process);
142
143 return createInvalidPlugInError(name);
144}
145
146Expected<StringRef> Trace::FindPluginSchema(StringRef name) {
147 StringRef schema = PluginManager::GetTraceSchema(name);
148 if (!schema.empty())
149 return schema;
150
151 return createInvalidPlugInError(name);
152}
153
154Error Trace::Start(const llvm::json::Value &request) {
155 if (!m_live_process)
156 return createStringError(
157 inconvertibleErrorCode(),
158 "Attempted to start tracing without a live process.");
159 return m_live_process->TraceStart(request);
160}
161
162Error Trace::Stop() {
163 if (!m_live_process)
164 return createStringError(
165 inconvertibleErrorCode(),
166 "Attempted to stop tracing without a live process.");
167 return m_live_process->TraceStop(TraceStopRequest(GetPluginName()));
168}
169
170Error Trace::Stop(llvm::ArrayRef<lldb::tid_t> tids) {
171 if (!m_live_process)
172 return createStringError(
173 inconvertibleErrorCode(),
174 "Attempted to stop tracing without a live process.");
175 return m_live_process->TraceStop(TraceStopRequest(GetPluginName(), tids));
176}
177
178Expected<std::string> Trace::GetLiveProcessState() {
179 if (!m_live_process)
180 return createStringError(
181 inconvertibleErrorCode(),
182 "Attempted to fetch live trace information without a live process.");
183 return m_live_process->TraceGetState(GetPluginName());
184}
185
186std::optional<uint64_t>
188 Storage &storage = GetUpdatedStorage();
189 return Lookup(storage.live_thread_data, tid, ConstString(kind));
190}
191
192std::optional<uint64_t> Trace::GetLiveCpuBinaryDataSize(lldb::cpu_id_t cpu_id,
193 llvm::StringRef kind) {
194 Storage &storage = GetUpdatedStorage();
195 return Lookup(storage.live_cpu_data_sizes, cpu_id, ConstString(kind));
196}
197
198std::optional<uint64_t>
200 Storage &storage = GetUpdatedStorage();
201 return Lookup(storage.live_process_data, ConstString(kind));
202}
203
204Expected<std::vector<uint8_t>>
206 uint64_t expected_size) {
207 if (!m_live_process)
208 return createStringError(
209 inconvertibleErrorCode(),
210 formatv("Attempted to fetch live trace data without a live process. "
211 "Data kind = {0}, tid = {1}, cpu id = {2}.",
212 request.kind, request.tid, request.cpu_id));
213
214 Expected<std::vector<uint8_t>> data =
215 m_live_process->TraceGetBinaryData(request);
216
217 if (!data)
218 return data.takeError();
219
220 if (data->size() != expected_size)
221 return createStringError(
222 inconvertibleErrorCode(),
223 formatv("Got incomplete live trace data. Data kind = {0}, expected "
224 "size = {1}, actual size = {2}, tid = {3}, cpu id = {4}",
225 request.kind, expected_size, data->size(), request.tid,
226 request.cpu_id));
227
228 return data;
229}
230
231Expected<std::vector<uint8_t>>
232Trace::GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind) {
233 std::optional<uint64_t> size = GetLiveThreadBinaryDataSize(tid, kind);
234 if (!size)
235 return createStringError(
236 inconvertibleErrorCode(),
237 "Tracing data \"%s\" is not available for thread %" PRIu64 ".",
238 kind.data(), tid);
239
240 TraceGetBinaryDataRequest request{GetPluginName().str(), kind.str(), tid,
241 /*cpu_id=*/std::nullopt};
242 return GetLiveTraceBinaryData(request, *size);
243}
244
245Expected<std::vector<uint8_t>>
246Trace::GetLiveCpuBinaryData(lldb::cpu_id_t cpu_id, llvm::StringRef kind) {
247 if (!m_live_process)
248 return createStringError(
249 inconvertibleErrorCode(),
250 "Attempted to fetch live cpu data without a live process.");
251 std::optional<uint64_t> size = GetLiveCpuBinaryDataSize(cpu_id, kind);
252 if (!size)
253 return createStringError(
254 inconvertibleErrorCode(),
255 "Tracing data \"%s\" is not available for cpu_id %" PRIu64 ".",
256 kind.data(), cpu_id);
257
258 TraceGetBinaryDataRequest request{GetPluginName().str(), kind.str(),
259 /*tid=*/std::nullopt, cpu_id};
260 return m_live_process->TraceGetBinaryData(request);
261}
262
263Expected<std::vector<uint8_t>>
264Trace::GetLiveProcessBinaryData(llvm::StringRef kind) {
265 std::optional<uint64_t> size = GetLiveProcessBinaryDataSize(kind);
266 if (!size)
267 return createStringError(
268 inconvertibleErrorCode(),
269 "Tracing data \"%s\" is not available for the process.", kind.data());
270
271 TraceGetBinaryDataRequest request{GetPluginName().str(), kind.str(),
272 /*tid=*/std::nullopt,
273 /*cpu_id*/ std::nullopt};
274 return GetLiveTraceBinaryData(request, *size);
275}
276
281
283 if (!m_live_process)
284 return nullptr;
285
286 uint32_t new_stop_id = m_live_process->GetStopID();
287 if (new_stop_id == m_stop_id)
288 return nullptr;
289
290 Log *log = GetLog(LLDBLog::Target);
291 LLDB_LOG(log, "Trace::RefreshLiveProcessState invoked");
292
293 m_stop_id = new_stop_id;
295
296 auto do_refresh = [&]() -> Error {
297 Expected<std::string> json_string = GetLiveProcessState();
298 if (!json_string)
299 return json_string.takeError();
300
301 Expected<TraceGetStateResponse> live_process_state =
302 json::parse<TraceGetStateResponse>(*json_string,
303 "TraceGetStateResponse");
304 if (!live_process_state)
305 return live_process_state.takeError();
306
307 if (live_process_state->warnings) {
308 for (std::string &warning : *live_process_state->warnings)
309 LLDB_LOG(log, "== Warning when fetching the trace state: {0}", warning);
310 }
311
312 for (const TraceThreadState &thread_state :
313 live_process_state->traced_threads) {
314 for (const TraceBinaryData &item : thread_state.binary_data)
315 m_storage.live_thread_data[thread_state.tid].insert(
316 {ConstString(item.kind), item.size});
317 }
318
319 LLDB_LOG(log, "== Found {0} threads being traced",
320 live_process_state->traced_threads.size());
321
322 if (live_process_state->cpus) {
323 m_storage.cpus.emplace();
324 for (const TraceCpuState &cpu_state : *live_process_state->cpus) {
325 m_storage.cpus->push_back(cpu_state.id);
326 for (const TraceBinaryData &item : cpu_state.binary_data)
327 m_storage.live_cpu_data_sizes[cpu_state.id].insert(
328 {ConstString(item.kind), item.size});
329 }
330 LLDB_LOG(log, "== Found {0} cpu cpus being traced",
331 live_process_state->cpus->size());
332 }
333
334 for (const TraceBinaryData &item : live_process_state->process_binary_data)
335 m_storage.live_process_data.insert({ConstString(item.kind), item.size});
336
337 return DoRefreshLiveProcessState(std::move(*live_process_state),
338 *json_string);
339 };
340
341 if (Error err = do_refresh()) {
342 m_storage.live_refresh_error = toString(std::move(err));
343 return m_storage.live_refresh_error->c_str();
344 }
345
346 return nullptr;
347}
348
349Trace::Trace(ArrayRef<ProcessSP> postmortem_processes,
350 std::optional<std::vector<lldb::cpu_id_t>> postmortem_cpus) {
351 for (ProcessSP process_sp : postmortem_processes)
352 m_storage.postmortem_processes.push_back(process_sp.get());
353 m_storage.cpus = postmortem_cpus;
354}
355
357
358ArrayRef<Process *> Trace::GetPostMortemProcesses() {
359 return m_storage.postmortem_processes;
360}
361
362std::vector<Process *> Trace::GetAllProcesses() {
363 if (Process *proc = GetLiveProcess())
364 return {proc};
365 return GetPostMortemProcesses();
366}
367
370 return m_stop_id;
371}
372
373llvm::Expected<FileSpec>
375 Storage &storage = GetUpdatedStorage();
376 if (std::optional<FileSpec> file =
377 Lookup(storage.postmortem_thread_data, tid, ConstString(kind)))
378 return *file;
379 else
380 return createStringError(
381 inconvertibleErrorCode(),
382 formatv("The thread with tid={0} doesn't have the tracing data {1}",
383 tid, kind));
384}
385
386llvm::Expected<FileSpec> Trace::GetPostMortemCpuDataFile(lldb::cpu_id_t cpu_id,
387 llvm::StringRef kind) {
388 Storage &storage = GetUpdatedStorage();
389 if (std::optional<FileSpec> file =
390 Lookup(storage.postmortem_cpu_data, cpu_id, ConstString(kind)))
391 return *file;
392 else
393 return createStringError(
394 inconvertibleErrorCode(),
395 formatv("The cpu with id={0} doesn't have the tracing data {1}", cpu_id,
396 kind));
397}
398
399void Trace::SetPostMortemThreadDataFile(lldb::tid_t tid, llvm::StringRef kind,
400 FileSpec file_spec) {
401 Storage &storage = GetUpdatedStorage();
402 storage.postmortem_thread_data[tid].insert({ConstString(kind), file_spec});
403}
404
406 llvm::StringRef kind, FileSpec file_spec) {
407 Storage &storage = GetUpdatedStorage();
408 storage.postmortem_cpu_data[cpu_id].insert({ConstString(kind), file_spec});
409}
410
411llvm::Error
413 OnBinaryDataReadCallback callback) {
414 Expected<std::vector<uint8_t>> data = GetLiveThreadBinaryData(tid, kind);
415 if (!data)
416 return data.takeError();
417 return callback(*data);
418}
419
421 llvm::StringRef kind,
422 OnBinaryDataReadCallback callback) {
423 Storage &storage = GetUpdatedStorage();
424 if (std::vector<uint8_t> *cpu_data =
425 LookupAsPtr(storage.live_cpu_data, cpu_id, ConstString(kind)))
426 return callback(*cpu_data);
427
428 Expected<std::vector<uint8_t>> data = GetLiveCpuBinaryData(cpu_id, kind);
429 if (!data)
430 return data.takeError();
431 auto it = storage.live_cpu_data[cpu_id].insert(
432 {ConstString(kind), std::move(*data)});
433 return callback(it.first->second);
434}
435
437 OnBinaryDataReadCallback callback) {
438 ErrorOr<std::unique_ptr<MemoryBuffer>> trace_or_error =
439 MemoryBuffer::getFile(file.GetPath());
440 if (std::error_code err = trace_or_error.getError())
441 return createStringError(
442 inconvertibleErrorCode(), "Failed fetching trace-related file %s. %s",
443 file.GetPath().c_str(), toString(errorCodeToError(err)).c_str());
444
445 MemoryBuffer &data = **trace_or_error;
446 ArrayRef<uint8_t> array_ref(
447 reinterpret_cast<const uint8_t *>(data.getBufferStart()),
448 data.getBufferSize());
449 return callback(array_ref);
450}
451
452llvm::Error
454 OnBinaryDataReadCallback callback) {
455 if (Expected<FileSpec> file = GetPostMortemThreadDataFile(tid, kind))
456 return OnDataFileRead(*file, callback);
457 else
458 return file.takeError();
459}
460
461llvm::Error
463 llvm::StringRef kind,
464 OnBinaryDataReadCallback callback) {
465 if (Expected<FileSpec> file = GetPostMortemCpuDataFile(cpu_id, kind))
466 return OnDataFileRead(*file, callback);
467 else
468 return file.takeError();
469}
470
471llvm::Error Trace::OnThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind,
472 OnBinaryDataReadCallback callback) {
473 if (m_live_process)
474 return OnLiveThreadBinaryDataRead(tid, kind, callback);
475 else
476 return OnPostMortemThreadBinaryDataRead(tid, kind, callback);
477}
478
479llvm::Error
482 DenseMap<cpu_id_t, ArrayRef<uint8_t>> buffers;
483 Storage &storage = GetUpdatedStorage();
484 if (!storage.cpus)
485 return Error::success();
486
487 std::function<Error(std::vector<cpu_id_t>::iterator)> process_cpu =
488 [&](std::vector<cpu_id_t>::iterator cpu_id) -> Error {
489 if (cpu_id == storage.cpus->end())
490 return callback(buffers);
491
492 return OnCpuBinaryDataRead(*cpu_id, kind,
493 [&](ArrayRef<uint8_t> data) -> Error {
494 buffers.try_emplace(*cpu_id, data);
495 auto next_id = cpu_id;
496 next_id++;
497 return process_cpu(next_id);
498 });
499 };
500 return process_cpu(storage.cpus->begin());
501}
502
504 llvm::StringRef kind,
505 OnBinaryDataReadCallback callback) {
506 if (m_live_process)
507 return OnLiveCpuBinaryDataRead(cpu_id, kind, callback);
508 else
509 return OnPostMortemCpuBinaryDataRead(cpu_id, kind, callback);
510}
511
512ArrayRef<lldb::cpu_id_t> Trace::GetTracedCpus() {
513 Storage &storage = GetUpdatedStorage();
514 if (storage.cpus)
515 return *storage.cpus;
516 return {};
517}
518
519std::vector<Process *> Trace::GetTracedProcesses() {
520 std::vector<Process *> processes;
521 Storage &storage = GetUpdatedStorage();
522
523 for (Process *proc : storage.postmortem_processes)
524 processes.push_back(proc);
525
526 if (m_live_process)
527 processes.push_back(m_live_process);
528 return processes;
529}
static llvm::raw_ostream & warning(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:376
static Error createInvalidPlugInError(StringRef plugin_name)
Definition Trace.cpp:88
static V * LookupAsPtr(DenseMap< K, V > &map, K k)
Definition Trace.cpp:61
static std::optional< V > Lookup(DenseMap< K, V > &map, K k)
Helper functions for fetching data in maps and returning Optionals or pointers instead of iterators f...
Definition Trace.cpp:53
llvm::Error Error
A uniqued constant string class.
Definition ConstString.h:40
A class to manage flag bits.
Definition Debugger.h:100
A file utility class.
Definition FileSpec.h:57
llvm::StringRef GetDirectory() const
Directory string const get accessor.
Definition FileSpec.h:234
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition FileSpec.cpp:376
virtual llvm::StringRef GetPluginName()=0
static llvm::StringRef GetTraceSchema(llvm::StringRef plugin_name)
Get the JSON schema for a trace bundle description file corresponding to the given plugin.
static TraceCreateInstanceForLiveProcess GetTraceCreateCallbackForLiveProcess(llvm::StringRef plugin_name)
static TraceCreateInstanceFromBundle GetTraceCreateCallback(llvm::StringRef plugin_name)
A plug-in interface definition class for debugging a process.
Definition Process.h:359
virtual bool IsLiveDebugSession() const
Check if a process is a live debug session, or a corefile/post-mortem.
Definition Process.h:1549
std::vector< Process * > GetTracedProcesses()
Return the list of processes traced by this instance.
Definition Trace.cpp:519
static llvm::Error OnDataFileRead(FileSpec file, OnBinaryDataReadCallback callback)
Helper method for reading a data file and passing its data to the given callback.
Definition Trace.cpp:436
llvm::Error OnPostMortemCpuBinaryDataRead(lldb::cpu_id_t cpu_id, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnCpuBinaryDataRead() for post mortem cpus.
Definition Trace.cpp:462
virtual llvm::Error Start(StructuredData::ObjectSP configuration=StructuredData::ObjectSP())=0
Start tracing a live process.
llvm::Error OnThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Fetch binary data associated with a thread, either live or postmortem, and pass it to the given callb...
Definition Trace.cpp:471
llvm::Expected< std::vector< uint8_t > > GetLiveCpuBinaryData(lldb::cpu_id_t cpu_id, llvm::StringRef kind)
Get binary data of a live cpu given a data identifier.
Definition Trace.cpp:246
void SetPostMortemCpuDataFile(lldb::cpu_id_t cpu_id, llvm::StringRef kind, FileSpec file_spec)
Associate a given cpu with a data file using a data identifier.
Definition Trace.cpp:405
llvm::Expected< std::vector< uint8_t > > GetLiveProcessBinaryData(llvm::StringRef kind)
Get binary data of the current process given a data identifier.
Definition Trace.cpp:264
llvm::Expected< FileSpec > GetPostMortemThreadDataFile(lldb::tid_t tid, llvm::StringRef kind)
Get the file path containing data of a postmortem thread given a data identifier.
Definition Trace.cpp:374
Storage & GetUpdatedStorage()
Get the storage after refreshing the data in the case of a live process.
Definition Trace.cpp:277
llvm::Error OnLiveCpuBinaryDataRead(lldb::cpu_id_t cpu, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnLiveBinaryDataRead() for live cpus.
Definition Trace.cpp:420
llvm::Expected< std::string > GetLiveProcessState()
Get the current tracing state of a live process and its threads.
Definition Trace.cpp:178
static llvm::Expected< lldb::TraceSP > FindPluginForLiveProcess(llvm::StringRef plugin_name, Process &process)
Find a trace plug-in to trace a live process.
Definition Trace.cpp:133
std::optional< uint64_t > GetLiveCpuBinaryDataSize(lldb::cpu_id_t cpu_id, llvm::StringRef kind)
Get the size of the data returned by GetLiveCpuBinaryData.
Definition Trace.cpp:192
uint32_t GetStopID()
Definition Trace.cpp:368
Process * m_live_process
Process traced by this object if doing live tracing. Otherwise it's null.
Definition Trace.h:541
llvm::Error Stop()
Stop tracing all current and future threads of a live process.
Definition Trace.cpp:162
llvm::Error OnAllCpusBinaryDataRead(llvm::StringRef kind, OnCpusBinaryDataReadCallback callback)
Similar to OnCpuBinaryDataRead but this is able to fetch the same data from all cpus at once.
Definition Trace.cpp:480
static llvm::Expected< lldb::TraceSP > LoadPostMortemTraceFromFile(Debugger &debugger, const FileSpec &trace_description_file)
Load a trace from a trace description file and create Targets, Processes and Threads based on the con...
Definition Trace.cpp:96
Trace(llvm::ArrayRef< lldb::ProcessSP > postmortem_processes, std::optional< std::vector< lldb::cpu_id_t > > postmortem_cpus)
Constructor for post mortem processes.
struct lldb_private::Trace::Storage m_storage
llvm::Error OnPostMortemThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnThreadBinaryDataRead() for post mortem threads.
Definition Trace.cpp:453
static llvm::Expected< llvm::StringRef > FindPluginSchema(llvm::StringRef plugin_name)
Get the schema of a Trace plug-in given its name.
Definition Trace.cpp:146
uint32_t m_stop_id
Definition Trace.h:538
llvm::ArrayRef< lldb::cpu_id_t > GetTracedCpus()
Definition Trace.cpp:512
llvm::Expected< std::vector< uint8_t > > GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind)
Get binary data of a live thread given a data identifier.
Definition Trace.cpp:232
void SetPostMortemThreadDataFile(lldb::tid_t tid, llvm::StringRef kind, FileSpec file_spec)
Associate a given thread with a data file using a data identifier.
Definition Trace.cpp:399
std::function< llvm::Error(llvm::ArrayRef< uint8_t > data)> OnBinaryDataReadCallback
Definition Trace.h:260
const char * RefreshLiveProcessState()
Method to be invoked by the plug-in to refresh the live process state.
Definition Trace.cpp:282
std::vector< Process * > GetAllProcesses()
Definition Trace.cpp:362
static llvm::Expected< lldb::TraceSP > FindPluginForPostMortemProcess(Debugger &debugger, const llvm::json::Value &bundle_description, llvm::StringRef session_file_dir)
Find a trace plug-in using JSON data.
Definition Trace.cpp:118
llvm::Expected< std::vector< uint8_t > > GetLiveTraceBinaryData(const TraceGetBinaryDataRequest &request, uint64_t expected_size)
Dispatcher for live trace data requests with some additional error checking.
Definition Trace.cpp:205
Process * GetLiveProcess()
Get the currently traced live process.
Definition Trace.cpp:356
llvm::Expected< FileSpec > GetPostMortemCpuDataFile(lldb::cpu_id_t cpu_id, llvm::StringRef kind)
Get the file path containing data of a postmortem cpu given a data identifier.
Definition Trace.cpp:386
std::optional< uint64_t > GetLiveProcessBinaryDataSize(llvm::StringRef kind)
Get the size of the data returned by GetLiveProcessBinaryData.
Definition Trace.cpp:199
llvm::ArrayRef< Process * > GetPostMortemProcesses()
Get the currently traced postmortem processes.
Definition Trace.cpp:358
std::function< llvm::Error( const llvm::DenseMap< lldb::cpu_id_t, llvm::ArrayRef< uint8_t > > &cpu_to_data)> OnCpusBinaryDataReadCallback
Definition Trace.h:262
llvm::Error OnLiveThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnThreadBinaryDataRead() for live threads.
Definition Trace.cpp:412
virtual llvm::Error DoRefreshLiveProcessState(TraceGetStateResponse state, llvm::StringRef json_response)=0
Method to be overriden by the plug-in to refresh its own state.
llvm::Error OnCpuBinaryDataRead(lldb::cpu_id_t cpu_id, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Fetch binary data associated with a cpu, either live or postmortem, and pass it to the given callback...
Definition Trace.cpp:503
std::optional< uint64_t > GetLiveThreadBinaryDataSize(lldb::tid_t tid, llvm::StringRef kind)
Get the size of the data returned by GetLiveThreadBinaryData.
Definition Trace.cpp:187
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:339
std::string toString(FormatterBytecode::OpCodes op)
std::shared_ptr< lldb_private::Process > ProcessSP
uint32_t cpu_id_t
Definition lldb-types.h:92
uint64_t tid_t
Definition lldb-types.h:84
bool fromJSON(const llvm::json::Value &value, lldb_private::JSONSection &section, llvm::json::Path path)
Definition Section.cpp:717
std::string kind
Identifier of data to fetch with jLLDBTraceGetBinaryData.
uint64_t size
Size in bytes for this data.
std::vector< TraceBinaryData > binary_data
List of binary data objects for this core.
jLLDBTraceGetBinaryData gdb-remote packet
std::optional< lldb::cpu_id_t > cpu_id
Optional core id if the data is related to a cpu core.
std::optional< lldb::tid_t > tid
Optional tid if the data is related to a thread.
std::string kind
Identifier for the data.
jLLDBTraceStop gdb-remote packet
std::vector< TraceBinaryData > binary_data
List of binary data objects for this thread.
We package all the data that can change upon process stops to make sure this contract is very visible...
Definition Trace.h:547
llvm::DenseMap< lldb::cpu_id_t, llvm::DenseMap< ConstString, uint64_t > > live_cpu_data_sizes
cpu id -> data kind -> size
Definition Trace.h:563
llvm::DenseMap< lldb::cpu_id_t, llvm::DenseMap< ConstString, std::vector< uint8_t > > > live_cpu_data
cpu id -> data kind -> bytes
Definition Trace.h:567
llvm::DenseMap< lldb::tid_t, llvm::DenseMap< ConstString, uint64_t > > live_thread_data
These data kinds are returned by lldb-server when fetching the state of the tracing session.
Definition Trace.h:559
llvm::DenseMap< lldb::tid_t, llvm::DenseMap< ConstString, FileSpec > > postmortem_thread_data
Postmortem traces can specific additional data files, which are represented in this variable using a ...
Definition Trace.h:583
llvm::DenseMap< ConstString, uint64_t > live_process_data
data kind -> size
Definition Trace.h:570
std::optional< std::vector< lldb::cpu_id_t > > cpus
The list of cpus being traced.
Definition Trace.h:575
llvm::DenseMap< lldb::cpu_id_t, llvm::DenseMap< ConstString, FileSpec > > postmortem_cpu_data
cpu id -> data kind -> file
Definition Trace.h:587
std::vector< Process * > postmortem_processes
Portmortem processes traced by this object if doing non-live tracing.
Definition Trace.h:550