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