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,
116 trace_description_file.GetDirectory().AsCString());
117}
118
120 Debugger &debugger, const json::Value &trace_bundle_description,
121 StringRef bundle_dir) {
123 json::Path::Root root("traceBundle");
124 if (!json::fromJSON(trace_bundle_description, json_bundle, root))
125 return root.getError();
126
127 if (auto create_callback =
129 return create_callback(trace_bundle_description, bundle_dir, debugger);
130
131 return createInvalidPlugInError(json_bundle.type);
132}
133
134Expected<lldb::TraceSP> Trace::FindPluginForLiveProcess(llvm::StringRef name,
135 Process &process) {
136 if (!process.IsLiveDebugSession())
137 return createStringError(inconvertibleErrorCode(),
138 "Can't trace non-live processes");
139
140 if (auto create_callback =
142 return create_callback(process);
143
144 return createInvalidPlugInError(name);
145}
146
147Expected<StringRef> Trace::FindPluginSchema(StringRef name) {
148 StringRef schema = PluginManager::GetTraceSchema(name);
149 if (!schema.empty())
150 return schema;
151
152 return createInvalidPlugInError(name);
153}
154
155Error Trace::Start(const llvm::json::Value &request) {
156 if (!m_live_process)
157 return createStringError(
158 inconvertibleErrorCode(),
159 "Attempted to start tracing without a live process.");
160 return m_live_process->TraceStart(request);
161}
162
164 if (!m_live_process)
165 return createStringError(
166 inconvertibleErrorCode(),
167 "Attempted to stop tracing without a live process.");
169}
170
171Error Trace::Stop(llvm::ArrayRef<lldb::tid_t> tids) {
172 if (!m_live_process)
173 return createStringError(
174 inconvertibleErrorCode(),
175 "Attempted to stop tracing without a live process.");
177}
178
179Expected<std::string> Trace::GetLiveProcessState() {
180 if (!m_live_process)
181 return createStringError(
182 inconvertibleErrorCode(),
183 "Attempted to fetch live trace information without a live process.");
185}
186
187std::optional<uint64_t>
189 Storage &storage = GetUpdatedStorage();
190 return Lookup(storage.live_thread_data, tid, ConstString(kind));
191}
192
193std::optional<uint64_t> Trace::GetLiveCpuBinaryDataSize(lldb::cpu_id_t cpu_id,
194 llvm::StringRef kind) {
195 Storage &storage = GetUpdatedStorage();
196 return Lookup(storage.live_cpu_data_sizes, cpu_id, ConstString(kind));
197}
198
199std::optional<uint64_t>
201 Storage &storage = GetUpdatedStorage();
202 return Lookup(storage.live_process_data, ConstString(kind));
203}
204
205Expected<std::vector<uint8_t>>
207 uint64_t expected_size) {
208 if (!m_live_process)
209 return createStringError(
210 inconvertibleErrorCode(),
211 formatv("Attempted to fetch live trace data without a live process. "
212 "Data kind = {0}, tid = {1}, cpu id = {2}.",
213 request.kind, request.tid, request.cpu_id));
214
215 Expected<std::vector<uint8_t>> data =
217
218 if (!data)
219 return data.takeError();
220
221 if (data->size() != expected_size)
222 return createStringError(
223 inconvertibleErrorCode(),
224 formatv("Got incomplete live trace data. Data kind = {0}, expected "
225 "size = {1}, actual size = {2}, tid = {3}, cpu id = {4}",
226 request.kind, expected_size, data->size(), request.tid,
227 request.cpu_id));
228
229 return data;
230}
231
232Expected<std::vector<uint8_t>>
233Trace::GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind) {
234 std::optional<uint64_t> size = GetLiveThreadBinaryDataSize(tid, kind);
235 if (!size)
236 return createStringError(
237 inconvertibleErrorCode(),
238 "Tracing data \"%s\" is not available for thread %" PRIu64 ".",
239 kind.data(), tid);
240
241 TraceGetBinaryDataRequest request{GetPluginName().str(), kind.str(), tid,
242 /*cpu_id=*/std::nullopt};
243 return GetLiveTraceBinaryData(request, *size);
244}
245
246Expected<std::vector<uint8_t>>
247Trace::GetLiveCpuBinaryData(lldb::cpu_id_t cpu_id, llvm::StringRef kind) {
248 if (!m_live_process)
249 return createStringError(
250 inconvertibleErrorCode(),
251 "Attempted to fetch live cpu data without a live process.");
252 std::optional<uint64_t> size = GetLiveCpuBinaryDataSize(cpu_id, kind);
253 if (!size)
254 return createStringError(
255 inconvertibleErrorCode(),
256 "Tracing data \"%s\" is not available for cpu_id %" PRIu64 ".",
257 kind.data(), cpu_id);
258
259 TraceGetBinaryDataRequest request{GetPluginName().str(), kind.str(),
260 /*tid=*/std::nullopt, cpu_id};
261 return m_live_process->TraceGetBinaryData(request);
262}
263
264Expected<std::vector<uint8_t>>
265Trace::GetLiveProcessBinaryData(llvm::StringRef kind) {
266 std::optional<uint64_t> size = GetLiveProcessBinaryDataSize(kind);
267 if (!size)
268 return createStringError(
269 inconvertibleErrorCode(),
270 "Tracing data \"%s\" is not available for the process.", kind.data());
271
272 TraceGetBinaryDataRequest request{GetPluginName().str(), kind.str(),
273 /*tid=*/std::nullopt,
274 /*cpu_id*/ std::nullopt};
275 return GetLiveTraceBinaryData(request, *size);
276}
277
280 return m_storage;
281}
282
284 if (!m_live_process)
285 return nullptr;
286
287 uint32_t new_stop_id = m_live_process->GetStopID();
288 if (new_stop_id == m_stop_id)
289 return nullptr;
290
291 Log *log = GetLog(LLDBLog::Target);
292 LLDB_LOG(log, "Trace::RefreshLiveProcessState invoked");
293
294 m_stop_id = new_stop_id;
296
297 auto do_refresh = [&]() -> Error {
298 Expected<std::string> json_string = GetLiveProcessState();
299 if (!json_string)
300 return json_string.takeError();
301
302 Expected<TraceGetStateResponse> live_process_state =
303 json::parse<TraceGetStateResponse>(*json_string,
304 "TraceGetStateResponse");
305 if (!live_process_state)
306 return live_process_state.takeError();
307
308 if (live_process_state->warnings) {
309 for (std::string &warning : *live_process_state->warnings)
310 LLDB_LOG(log, "== Warning when fetching the trace state: {0}", warning);
311 }
312
313 for (const TraceThreadState &thread_state :
314 live_process_state->traced_threads) {
315 for (const TraceBinaryData &item : thread_state.binary_data)
316 m_storage.live_thread_data[thread_state.tid].insert(
317 {ConstString(item.kind), item.size});
318 }
319
320 LLDB_LOG(log, "== Found {0} threads being traced",
321 live_process_state->traced_threads.size());
322
323 if (live_process_state->cpus) {
324 m_storage.cpus.emplace();
325 for (const TraceCpuState &cpu_state : *live_process_state->cpus) {
326 m_storage.cpus->push_back(cpu_state.id);
327 for (const TraceBinaryData &item : cpu_state.binary_data)
328 m_storage.live_cpu_data_sizes[cpu_state.id].insert(
329 {ConstString(item.kind), item.size});
330 }
331 LLDB_LOG(log, "== Found {0} cpu cpus being traced",
332 live_process_state->cpus->size());
333 }
334
335 for (const TraceBinaryData &item : live_process_state->process_binary_data)
336 m_storage.live_process_data.insert({ConstString(item.kind), item.size});
337
338 return DoRefreshLiveProcessState(std::move(*live_process_state),
339 *json_string);
340 };
341
342 if (Error err = do_refresh()) {
343 m_storage.live_refresh_error = toString(std::move(err));
344 return m_storage.live_refresh_error->c_str();
345 }
346
347 return nullptr;
348}
349
350Trace::Trace(ArrayRef<ProcessSP> postmortem_processes,
351 std::optional<std::vector<lldb::cpu_id_t>> postmortem_cpus) {
352 for (ProcessSP process_sp : postmortem_processes)
353 m_storage.postmortem_processes.push_back(process_sp.get());
354 m_storage.cpus = postmortem_cpus;
355}
356
358
359ArrayRef<Process *> Trace::GetPostMortemProcesses() {
361}
362
363std::vector<Process *> Trace::GetAllProcesses() {
364 if (Process *proc = GetLiveProcess())
365 return {proc};
366 return GetPostMortemProcesses();
367}
368
371 return m_stop_id;
372}
373
374llvm::Expected<FileSpec>
376 Storage &storage = GetUpdatedStorage();
377 if (std::optional<FileSpec> file =
378 Lookup(storage.postmortem_thread_data, tid, ConstString(kind)))
379 return *file;
380 else
381 return createStringError(
382 inconvertibleErrorCode(),
383 formatv("The thread with tid={0} doesn't have the tracing data {1}",
384 tid, kind));
385}
386
387llvm::Expected<FileSpec> Trace::GetPostMortemCpuDataFile(lldb::cpu_id_t cpu_id,
388 llvm::StringRef kind) {
389 Storage &storage = GetUpdatedStorage();
390 if (std::optional<FileSpec> file =
391 Lookup(storage.postmortem_cpu_data, cpu_id, ConstString(kind)))
392 return *file;
393 else
394 return createStringError(
395 inconvertibleErrorCode(),
396 formatv("The cpu with id={0} doesn't have the tracing data {1}", cpu_id,
397 kind));
398}
399
400void Trace::SetPostMortemThreadDataFile(lldb::tid_t tid, llvm::StringRef kind,
401 FileSpec file_spec) {
402 Storage &storage = GetUpdatedStorage();
403 storage.postmortem_thread_data[tid].insert({ConstString(kind), file_spec});
404}
405
407 llvm::StringRef kind, FileSpec file_spec) {
408 Storage &storage = GetUpdatedStorage();
409 storage.postmortem_cpu_data[cpu_id].insert({ConstString(kind), file_spec});
410}
411
412llvm::Error
414 OnBinaryDataReadCallback callback) {
415 Expected<std::vector<uint8_t>> data = GetLiveThreadBinaryData(tid, kind);
416 if (!data)
417 return data.takeError();
418 return callback(*data);
419}
420
422 llvm::StringRef kind,
423 OnBinaryDataReadCallback callback) {
424 Storage &storage = GetUpdatedStorage();
425 if (std::vector<uint8_t> *cpu_data =
426 LookupAsPtr(storage.live_cpu_data, cpu_id, ConstString(kind)))
427 return callback(*cpu_data);
428
429 Expected<std::vector<uint8_t>> data = GetLiveCpuBinaryData(cpu_id, kind);
430 if (!data)
431 return data.takeError();
432 auto it = storage.live_cpu_data[cpu_id].insert(
433 {ConstString(kind), std::move(*data)});
434 return callback(it.first->second);
435}
436
438 OnBinaryDataReadCallback callback) {
439 ErrorOr<std::unique_ptr<MemoryBuffer>> trace_or_error =
440 MemoryBuffer::getFile(file.GetPath());
441 if (std::error_code err = trace_or_error.getError())
442 return createStringError(
443 inconvertibleErrorCode(), "Failed fetching trace-related file %s. %s",
444 file.GetPath().c_str(), toString(errorCodeToError(err)).c_str());
445
446 MemoryBuffer &data = **trace_or_error;
447 ArrayRef<uint8_t> array_ref(
448 reinterpret_cast<const uint8_t *>(data.getBufferStart()),
449 data.getBufferSize());
450 return callback(array_ref);
451}
452
453llvm::Error
455 OnBinaryDataReadCallback callback) {
456 if (Expected<FileSpec> file = GetPostMortemThreadDataFile(tid, kind))
457 return OnDataFileRead(*file, callback);
458 else
459 return file.takeError();
460}
461
462llvm::Error
464 llvm::StringRef kind,
465 OnBinaryDataReadCallback callback) {
466 if (Expected<FileSpec> file = GetPostMortemCpuDataFile(cpu_id, kind))
467 return OnDataFileRead(*file, callback);
468 else
469 return file.takeError();
470}
471
472llvm::Error Trace::OnThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind,
473 OnBinaryDataReadCallback callback) {
474 if (m_live_process)
475 return OnLiveThreadBinaryDataRead(tid, kind, callback);
476 else
477 return OnPostMortemThreadBinaryDataRead(tid, kind, callback);
478}
479
480llvm::Error
483 DenseMap<cpu_id_t, ArrayRef<uint8_t>> buffers;
484 Storage &storage = GetUpdatedStorage();
485 if (!storage.cpus)
486 return Error::success();
487
488 std::function<Error(std::vector<cpu_id_t>::iterator)> process_cpu =
489 [&](std::vector<cpu_id_t>::iterator cpu_id) -> Error {
490 if (cpu_id == storage.cpus->end())
491 return callback(buffers);
492
493 return OnCpuBinaryDataRead(*cpu_id, kind,
494 [&](ArrayRef<uint8_t> data) -> Error {
495 buffers.try_emplace(*cpu_id, data);
496 auto next_id = cpu_id;
497 next_id++;
498 return process_cpu(next_id);
499 });
500 };
501 return process_cpu(storage.cpus->begin());
502}
503
505 llvm::StringRef kind,
506 OnBinaryDataReadCallback callback) {
507 if (m_live_process)
508 return OnLiveCpuBinaryDataRead(cpu_id, kind, callback);
509 else
510 return OnPostMortemCpuBinaryDataRead(cpu_id, kind, callback);
511}
512
513ArrayRef<lldb::cpu_id_t> Trace::GetTracedCpus() {
514 Storage &storage = GetUpdatedStorage();
515 if (storage.cpus)
516 return *storage.cpus;
517 return {};
518}
519
520std::vector<Process *> Trace::GetTracedProcesses() {
521 std::vector<Process *> processes;
522 Storage &storage = GetUpdatedStorage();
523
524 for (Process *proc : storage.postmortem_processes)
525 processes.push_back(proc);
526
527 if (m_live_process)
528 processes.push_back(m_live_process);
529 return processes;
530}
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:359
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
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
A class to manage flag bits.
Definition: Debugger.h:80
A file utility class.
Definition: FileSpec.h:56
const ConstString & GetDirectory() const
Directory string const get accessor.
Definition: FileSpec.h:223
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
Definition: FileSpec.cpp:367
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:341
virtual llvm::Expected< std::vector< uint8_t > > TraceGetBinaryData(const TraceGetBinaryDataRequest &request)
Get binary data given a trace technology and a data identifier.
Definition: Process.h:2792
virtual llvm::Error TraceStop(const TraceStopRequest &request)
Stop tracing a live process or its threads.
Definition: Process.h:2767
virtual llvm::Error TraceStart(const llvm::json::Value &request)
Start tracing a process or its threads.
Definition: Process.h:2755
uint32_t GetStopID() const
Definition: Process.h:1490
virtual bool IsLiveDebugSession() const
Definition: Process.h:1533
virtual llvm::Expected< std::string > TraceGetState(llvm::StringRef type)
Get the current tracing state of the process and its threads.
Definition: Process.h:2779
std::vector< Process * > GetTracedProcesses()
Return the list of processes traced by this instance.
Definition: Trace.cpp:520
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:437
llvm::Error OnPostMortemCpuBinaryDataRead(lldb::cpu_id_t cpu_id, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnCpuBinaryDataRead() for post mortem cpus.
Definition: Trace.cpp:463
virtual llvm::Error Start(StructuredData::ObjectSP configuration=StructuredData::ObjectSP())=0
Start tracing a live process.
std::function< llvm::Error(llvm::ArrayRef< uint8_t > data)> OnBinaryDataReadCallback
Definition: Trace.h:261
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:472
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:247
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:406
llvm::Expected< std::vector< uint8_t > > GetLiveProcessBinaryData(llvm::StringRef kind)
Get binary data of the current process given a data identifier.
Definition: Trace.cpp:265
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:375
Storage & GetUpdatedStorage()
Get the storage after refreshing the data in the case of a live process.
Definition: Trace.cpp:278
llvm::Error OnLiveCpuBinaryDataRead(lldb::cpu_id_t cpu, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnLiveBinaryDataRead() for live cpus.
Definition: Trace.cpp:421
llvm::Expected< std::string > GetLiveProcessState()
Get the current tracing state of a live process and its threads.
Definition: Trace.cpp:179
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:134
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:193
uint32_t GetStopID()
Definition: Trace.cpp:369
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:163
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:481
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:454
static llvm::Expected< llvm::StringRef > FindPluginSchema(llvm::StringRef plugin_name)
Get the schema of a Trace plug-in given its name.
Definition: Trace.cpp:147
uint32_t m_stop_id
Definition: Trace.h:538
llvm::ArrayRef< lldb::cpu_id_t > GetTracedCpus()
Definition: Trace.cpp:513
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:233
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:400
const char * RefreshLiveProcessState()
Method to be invoked by the plug-in to refresh the live process state.
Definition: Trace.cpp:283
std::vector< Process * > GetAllProcesses()
Definition: Trace.cpp:363
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:119
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:206
Process * GetLiveProcess()
Get the currently traced live process.
Definition: Trace.cpp:357
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:387
std::optional< uint64_t > GetLiveProcessBinaryDataSize(llvm::StringRef kind)
Get the size of the data returned by GetLiveProcessBinaryData.
Definition: Trace.cpp:200
llvm::ArrayRef< Process * > GetPostMortemProcesses()
Get the currently traced postmortem processes.
Definition: Trace.cpp:359
llvm::Error OnLiveThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind, OnBinaryDataReadCallback callback)
Implementation of OnThreadBinaryDataRead() for live threads.
Definition: Trace.cpp:413
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:504
std::optional< uint64_t > GetLiveThreadBinaryDataSize(lldb::tid_t tid, llvm::StringRef kind)
Get the size of the data returned by GetLiveThreadBinaryData.
Definition: Trace.cpp:188
std::function< llvm::Error(const llvm::DenseMap< lldb::cpu_id_t, llvm::ArrayRef< uint8_t > > &cpu_to_data)> OnCpusBinaryDataReadCallback
Definition: Trace.h:264
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:331
const char * toString(AppleArm64ExceptionClass EC)
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
uint32_t cpu_id_t
Definition: lldb-types.h:91
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:684
Definition: Debugger.h:54
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::optional< std::string > live_refresh_error
Definition: Trace.h:591
std::vector< Process * > postmortem_processes
Portmortem processes traced by this object if doing non-live tracing.
Definition: Trace.h:550