LLDB mainline
Trace.h
Go to the documentation of this file.
1//===-- Trace.h -------------------------------------------------*- 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#ifndef LLDB_TARGET_TRACE_H
10#define LLDB_TARGET_TRACE_H
11
12#include <optional>
13#include <unordered_map>
14
15#include "llvm/ADT/StringMap.h"
16#include "llvm/Support/JSON.h"
17
19#include "lldb/Target/Thread.h"
24#include "lldb/lldb-private.h"
25#include "lldb/lldb-types.h"
26
27namespace lldb_private {
28
29/// \class Trace Trace.h "lldb/Target/Trace.h"
30/// A plug-in interface definition class for trace information.
31///
32/// Trace plug-ins allow processor trace information to be loaded into LLDB so
33/// that the data can be dumped, used for reverse and forward stepping to allow
34/// introspection into the reason your process crashed or found its way to its
35/// current state.
36///
37/// Trace information can be loaded into a target without a process to allow
38/// introspection of the trace information during post mortem analysis, such as
39/// when loading core files.
40///
41/// Processor trace information can also be fetched through the process
42/// interfaces during a live debug session if your process supports gathering
43/// this information.
44///
45/// In order to support live tracing, the name of the plug-in should match the
46/// name of the tracing type returned by the gdb-remote packet
47/// \a jLLDBTraceSupported.
48class Trace : public PluginInterface,
49 public std::enable_shared_from_this<Trace> {
50public:
51 /// Dump the trace data that this plug-in has access to.
52 ///
53 /// This function will dump all of the trace data for all threads in a user
54 /// readable format. Options for dumping can be added as this API is iterated
55 /// on.
56 ///
57 /// \param[in] s
58 /// A stream object to dump the information to.
59 virtual void Dump(Stream *s) const = 0;
60
61 /// Save the trace to the specified directory, which will be created if
62 /// needed. This will also create a file \a <directory>/trace.json with the
63 /// main properties of the trace session, along with others files which
64 /// contain the actual trace data. The trace.json file can be used later as
65 /// input for the "trace load" command to load the trace in LLDB.
66 ///
67 /// \param[in] directory
68 /// The directory where the trace files will be saved.
69 ///
70 /// \param[in] compact
71 /// Try not to save to disk information irrelevant to the traced processes.
72 /// Each trace plug-in implements this in a different fashion.
73 ///
74 /// \return
75 /// A \a FileSpec pointing to the bundle description file, or an \a
76 /// llvm::Error otherwise.
77 virtual llvm::Expected<FileSpec> SaveToDisk(FileSpec directory,
78 bool compact) = 0;
79
80 /// Find a trace plug-in using JSON data.
81 ///
82 /// When loading trace data from disk, the information for the trace data
83 /// can be contained in multiple files and require plug-in specific
84 /// information about the CPU. Using data like JSON provides an
85 /// easy way to specify all of the settings and information that we will need
86 /// to load trace data into LLDB. This structured data can include:
87 /// - The plug-in name (this allows a specific plug-in to be selected)
88 /// - Architecture or target triple
89 /// - one or more paths to the trace data file on disk
90 /// - cpu trace data
91 /// - thread events or related information
92 /// - shared library load information to use for this trace data that
93 /// allows a target to be created so the trace information can be
94 /// symbolicated so that the trace information can be displayed to the
95 /// user
96 /// - shared library path
97 /// - load address
98 /// - information on how to fetch the shared library
99 /// - path to locally cached file on disk
100 /// - URL to download the file
101 /// - Any information needed to load the trace file
102 /// - CPU information
103 /// - Custom plug-in information needed to decode the trace information
104 /// correctly.
105 ///
106 /// \param[in] debugger
107 /// The debugger instance where new Targets will be created as part of the
108 /// JSON data parsing.
109 ///
110 /// \param[in] bundle_description
111 /// The trace bundle description object describing the trace session.
112 ///
113 /// \param[in] bundle_dir
114 /// The path to the directory that contains the trace bundle.
115 static llvm::Expected<lldb::TraceSP>
117 const llvm::json::Value &bundle_description,
118 llvm::StringRef session_file_dir);
119
120 /// Find a trace plug-in to trace a live process.
121 ///
122 /// \param[in] plugin_name
123 /// Plug-in name to search.
124 ///
125 /// \param[in] process
126 /// Live process to trace.
127 ///
128 /// \return
129 /// A \a TraceSP instance, or an \a llvm::Error if the plug-in name
130 /// doesn't match any registered plug-ins or tracing couldn't be
131 /// started.
132 static llvm::Expected<lldb::TraceSP>
133 FindPluginForLiveProcess(llvm::StringRef plugin_name, Process &process);
134
135 /// Get the schema of a Trace plug-in given its name.
136 ///
137 /// \param[in] plugin_name
138 /// Name of the trace plugin.
139 static llvm::Expected<llvm::StringRef>
140 FindPluginSchema(llvm::StringRef plugin_name);
141
142 /// Load a trace from a trace description file and create Targets,
143 /// Processes and Threads based on the contents of such file.
144 ///
145 /// \param[in] debugger
146 /// The debugger instance where new Targets will be created as part of the
147 /// JSON data parsing.
148 ///
149 /// \param[in] trace_description_file
150 /// The file containing the necessary information to load the trace.
151 ///
152 /// \return
153 /// A \a TraceSP instance, or an \a llvm::Error if loading the trace
154 /// fails.
155 static llvm::Expected<lldb::TraceSP>
157 const FileSpec &trace_description_file);
158
159 /// Get the command handle for the "process trace start" command.
162
163 /// Get the command handle for the "thread trace start" command.
166
167 /// \return
168 /// The JSON schema of this Trace plug-in.
169 virtual llvm::StringRef GetSchema() = 0;
170
171 /// Get a \a TraceCursor for the given thread's trace.
172 ///
173 /// \return
174 /// A \a TraceCursorSP. If the thread is not traced or its trace
175 /// information failed to load, an \a llvm::Error is returned.
176 virtual llvm::Expected<lldb::TraceCursorSP>
178
179 /// Dump general info about a given thread's trace. Each Trace plug-in
180 /// decides which data to show.
181 ///
182 /// \param[in] thread
183 /// The thread that owns the trace in question.
184 ///
185 /// \param[in] s
186 /// The stream object where the info will be printed printed.
187 ///
188 /// \param[in] verbose
189 /// If \b true, print detailed info
190 /// If \b false, print compact info
191 virtual void DumpTraceInfo(Thread &thread, Stream &s, bool verbose,
192 bool json) = 0;
193
194 /// Check if a thread is currently traced by this object.
195 ///
196 /// \param[in] tid
197 /// The id of the thread in question.
198 ///
199 /// \return
200 /// \b true if the thread is traced by this instance, \b false otherwise.
201 virtual bool IsTraced(lldb::tid_t tid) = 0;
202
203 /// \return
204 /// A description of the parameters to use for the \a Trace::Start method.
205 virtual const char *GetStartConfigurationHelp() = 0;
206
207 /// Start tracing a live process.
208 ///
209 /// \param[in] configuration
210 /// See \a SBTrace::Start(const lldb::SBStructuredData &) for more
211 /// information.
212 ///
213 /// \return
214 /// \a llvm::Error::success if the operation was successful, or
215 /// \a llvm::Error otherwise.
216 virtual llvm::Error Start(
218
219 /// Start tracing live threads.
220 ///
221 /// \param[in] tids
222 /// Threads to trace. This method tries to trace as many threads as
223 /// possible.
224 ///
225 /// \param[in] configuration
226 /// See \a SBTrace::Start(const lldb::SBThread &, const
227 /// lldb::SBStructuredData &) for more information.
228 ///
229 /// \return
230 /// \a llvm::Error::success if the operation was successful, or
231 /// \a llvm::Error otherwise.
232 virtual llvm::Error Start(
233 llvm::ArrayRef<lldb::tid_t> tids,
235
236 /// Stop tracing live threads.
237 ///
238 /// \param[in] tids
239 /// The threads to stop tracing on.
240 ///
241 /// \return
242 /// \a llvm::Error::success if the operation was successful, or
243 /// \a llvm::Error otherwise.
244 llvm::Error Stop(llvm::ArrayRef<lldb::tid_t> tids);
245
246 /// Stop tracing all current and future threads of a live process.
247 ///
248 /// \param[in] request
249 /// The information determining which threads or process to stop tracing.
250 ///
251 /// \return
252 /// \a llvm::Error::success if the operation was successful, or
253 /// \a llvm::Error otherwise.
254 llvm::Error Stop();
255
256 /// \return
257 /// The stop ID of the live process being traced, or an invalid stop ID
258 /// if the trace is in an error or invalid state.
259 uint32_t GetStopID();
260
262 std::function<llvm::Error(llvm::ArrayRef<uint8_t> data)>;
263 using OnCpusBinaryDataReadCallback = std::function<llvm::Error(
264 const llvm::DenseMap<lldb::cpu_id_t, llvm::ArrayRef<uint8_t>>
265 &cpu_to_data)>;
266
267 /// Fetch binary data associated with a thread, either live or postmortem, and
268 /// pass it to the given callback. The reason of having a callback is to free
269 /// the caller from having to manage the life cycle of the data and to hide
270 /// the different data fetching procedures that exist for live and post mortem
271 /// threads.
272 ///
273 /// The fetched data is not persisted after the callback is invoked.
274 ///
275 /// \param[in] tid
276 /// The tid who owns the data.
277 ///
278 /// \param[in] kind
279 /// The kind of data to read.
280 ///
281 /// \param[in] callback
282 /// The callback to be invoked once the data was successfully read. Its
283 /// return value, which is an \a llvm::Error, is returned by this
284 /// function.
285 ///
286 /// \return
287 /// An \a llvm::Error if the data couldn't be fetched, or the return value
288 /// of the callback, otherwise.
289 llvm::Error OnThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind,
290 OnBinaryDataReadCallback callback);
291
292 /// Fetch binary data associated with a cpu, either live or postmortem, and
293 /// pass it to the given callback. The reason of having a callback is to free
294 /// the caller from having to manage the life cycle of the data and to hide
295 /// the different data fetching procedures that exist for live and post mortem
296 /// cpus.
297 ///
298 /// The fetched data is not persisted after the callback is invoked.
299 ///
300 /// \param[in] cpu_id
301 /// The cpu who owns the data.
302 ///
303 /// \param[in] kind
304 /// The kind of data to read.
305 ///
306 /// \param[in] callback
307 /// The callback to be invoked once the data was successfully read. Its
308 /// return value, which is an \a llvm::Error, is returned by this
309 /// function.
310 ///
311 /// \return
312 /// An \a llvm::Error if the data couldn't be fetched, or the return value
313 /// of the callback, otherwise.
314 llvm::Error OnCpuBinaryDataRead(lldb::cpu_id_t cpu_id, llvm::StringRef kind,
315 OnBinaryDataReadCallback callback);
316
317 /// Similar to \a OnCpuBinaryDataRead but this is able to fetch the same data
318 /// from all cpus at once.
319 llvm::Error OnAllCpusBinaryDataRead(llvm::StringRef kind,
321
322 /// \return
323 /// All the currently traced processes.
324 std::vector<Process *> GetAllProcesses();
325
326 /// \return
327 /// The list of cpus being traced. Might be empty depending on the
328 /// plugin.
329 llvm::ArrayRef<lldb::cpu_id_t> GetTracedCpus();
330
331 /// Helper method for reading a data file and passing its data to the given
332 /// callback.
333 static llvm::Error OnDataFileRead(FileSpec file,
334 OnBinaryDataReadCallback callback);
335
336protected:
337 /// Get the currently traced live process.
338 ///
339 /// \return
340 /// If it's not a live process, return \a nullptr.
342
343 /// Get the currently traced postmortem processes.
344 ///
345 /// \return
346 /// If it's not a live process session, return an empty list.
347 llvm::ArrayRef<Process *> GetPostMortemProcesses();
348
349 /// Dispatcher for live trace data requests with some additional error
350 /// checking.
351 llvm::Expected<std::vector<uint8_t>>
353 uint64_t expected_size);
354
355 /// Implementation of \a OnThreadBinaryDataRead() for live threads.
356 llvm::Error OnLiveThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind,
357 OnBinaryDataReadCallback callback);
358
359 /// Implementation of \a OnLiveBinaryDataRead() for live cpus.
360 llvm::Error OnLiveCpuBinaryDataRead(lldb::cpu_id_t cpu, llvm::StringRef kind,
361 OnBinaryDataReadCallback callback);
362
363 /// Implementation of \a OnThreadBinaryDataRead() for post mortem threads.
364 llvm::Error
365 OnPostMortemThreadBinaryDataRead(lldb::tid_t tid, llvm::StringRef kind,
366 OnBinaryDataReadCallback callback);
367
368 /// Implementation of \a OnCpuBinaryDataRead() for post mortem cpus.
370 llvm::StringRef kind,
371 OnBinaryDataReadCallback callback);
372
373 /// Get the file path containing data of a postmortem thread given a data
374 /// identifier.
375 ///
376 /// \param[in] tid
377 /// The thread whose data is requested.
378 ///
379 /// \param[in] kind
380 /// The kind of data requested.
381 ///
382 /// \return
383 /// The file spec containing the requested data, or an \a llvm::Error in
384 /// case of failures.
385 llvm::Expected<FileSpec> GetPostMortemThreadDataFile(lldb::tid_t tid,
386 llvm::StringRef kind);
387
388 /// Get the file path containing data of a postmortem cpu given a data
389 /// identifier.
390 ///
391 /// \param[in] cpu_id
392 /// The cpu whose data is requested.
393 ///
394 /// \param[in] kind
395 /// The kind of data requested.
396 ///
397 /// \return
398 /// The file spec containing the requested data, or an \a llvm::Error in
399 /// case of failures.
400 llvm::Expected<FileSpec> GetPostMortemCpuDataFile(lldb::cpu_id_t cpu_id,
401 llvm::StringRef kind);
402
403 /// Associate a given thread with a data file using a data identifier.
404 ///
405 /// \param[in] tid
406 /// The thread associated with the data file.
407 ///
408 /// \param[in] kind
409 /// The kind of data being registered.
410 ///
411 /// \param[in] file_spec
412 /// The path of the data file.
413 void SetPostMortemThreadDataFile(lldb::tid_t tid, llvm::StringRef kind,
414 FileSpec file_spec);
415
416 /// Associate a given cpu with a data file using a data identifier.
417 ///
418 /// \param[in] cpu_id
419 /// The cpu associated with the data file.
420 ///
421 /// \param[in] kind
422 /// The kind of data being registered.
423 ///
424 /// \param[in] file_spec
425 /// The path of the data file.
426 void SetPostMortemCpuDataFile(lldb::cpu_id_t cpu_id, llvm::StringRef kind,
427 FileSpec file_spec);
428
429 /// Get binary data of a live thread given a data identifier.
430 ///
431 /// \param[in] tid
432 /// The thread whose data is requested.
433 ///
434 /// \param[in] kind
435 /// The kind of data requested.
436 ///
437 /// \return
438 /// A vector of bytes with the requested data, or an \a llvm::Error in
439 /// case of failures.
440 llvm::Expected<std::vector<uint8_t>>
441 GetLiveThreadBinaryData(lldb::tid_t tid, llvm::StringRef kind);
442
443 /// Get binary data of a live cpu given a data identifier.
444 ///
445 /// \param[in] cpu_id
446 /// The cpu whose data is requested.
447 ///
448 /// \param[in] kind
449 /// The kind of data requested.
450 ///
451 /// \return
452 /// A vector of bytes with the requested data, or an \a llvm::Error in
453 /// case of failures.
454 llvm::Expected<std::vector<uint8_t>>
455 GetLiveCpuBinaryData(lldb::cpu_id_t cpu_id, llvm::StringRef kind);
456
457 /// Get binary data of the current process given a data identifier.
458 ///
459 /// \param[in] kind
460 /// The kind of data requested.
461 ///
462 /// \return
463 /// A vector of bytes with the requested data, or an \a llvm::Error in
464 /// case of failures.
465 llvm::Expected<std::vector<uint8_t>>
466 GetLiveProcessBinaryData(llvm::StringRef kind);
467
468 /// Get the size of the data returned by \a GetLiveThreadBinaryData
469 std::optional<uint64_t> GetLiveThreadBinaryDataSize(lldb::tid_t tid,
470 llvm::StringRef kind);
471
472 /// Get the size of the data returned by \a GetLiveCpuBinaryData
473 std::optional<uint64_t> GetLiveCpuBinaryDataSize(lldb::cpu_id_t cpu_id,
474 llvm::StringRef kind);
475
476 /// Get the size of the data returned by \a GetLiveProcessBinaryData
477 std::optional<uint64_t> GetLiveProcessBinaryDataSize(llvm::StringRef kind);
478
479 /// Constructor for post mortem processes
480 Trace(llvm::ArrayRef<lldb::ProcessSP> postmortem_processes,
481 std::optional<std::vector<lldb::cpu_id_t>> postmortem_cpus);
482
483 /// Constructor for a live process
484 Trace(Process &live_process) : m_live_process(&live_process) {}
485
486 /// Start tracing a live process or its threads.
487 ///
488 /// \param[in] request
489 /// JSON object with the information necessary to start tracing. In the
490 /// case of gdb-remote processes, this JSON object should conform to the
491 /// jLLDBTraceStart packet.
492 ///
493 /// \return
494 /// \a llvm::Error::success if the operation was successful, or
495 /// \a llvm::Error otherwise.
496 llvm::Error Start(const llvm::json::Value &request);
497
498 /// Get the current tracing state of a live process and its threads.
499 ///
500 /// \return
501 /// A JSON object string with custom data depending on the trace
502 /// technology, or an \a llvm::Error in case of errors.
503 llvm::Expected<std::string> GetLiveProcessState();
504
505 /// Method to be overriden by the plug-in to refresh its own state.
506 ///
507 /// This is invoked by RefreshLiveProcessState when a new state is found.
508 ///
509 /// \param[in] state
510 /// The jLLDBTraceGetState response.
511 ///
512 /// \param[in] json_response
513 /// The original JSON response as a string. It might be useful to redecode
514 /// it if it contains custom data for a specific trace plug-in.
515 ///
516 /// \return
517 /// \b Error::success() if this operation succeedes, or an actual error
518 /// otherwise.
519 virtual llvm::Error
521 llvm::StringRef json_response) = 0;
522
523 /// Return the list of processes traced by this instance. None of the returned
524 /// pointers are invalid.
525 std::vector<Process *> GetTracedProcesses();
526
527 /// Method to be invoked by the plug-in to refresh the live process state. It
528 /// will invoked DoRefreshLiveProcessState at some point, which should be
529 /// implemented by the plug-in for custom state handling.
530 ///
531 /// The result is cached through the same process stop. Even in the case of
532 /// errors, it caches the error.
533 ///
534 /// \return
535 /// An error message if this operation failed, or \b nullptr otherwise.
536 const char *RefreshLiveProcessState();
537
538private:
540
541 /// Process traced by this object if doing live tracing. Otherwise it's null.
543
544 /// We package all the data that can change upon process stops to make sure
545 /// this contract is very visible.
546 /// This variable should only be accessed directly by constructores or live
547 /// process data refreshers.
548 struct Storage {
549 /// Portmortem processes traced by this object if doing non-live tracing.
550 /// Otherwise it's empty.
551 std::vector<Process *> postmortem_processes;
552
553 /// These data kinds are returned by lldb-server when fetching the state of
554 /// the tracing session. The size in bytes can be used later for fetching
555 /// the data in batches.
556 /// \{
557
558 /// tid -> data kind -> size
559 llvm::DenseMap<lldb::tid_t, llvm::StringMap<uint64_t>> live_thread_data;
560
561 /// cpu id -> data kind -> size
562 llvm::DenseMap<lldb::cpu_id_t, llvm::StringMap<uint64_t>>
564 /// cpu id -> data kind -> bytes
565 llvm::DenseMap<lldb::cpu_id_t, llvm::StringMap<std::vector<uint8_t>>>
567
568 /// data kind -> size
569 llvm::StringMap<uint64_t> live_process_data;
570 /// \}
571
572 /// The list of cpus being traced. Might be \b std::nullopt depending on the
573 /// plug-in.
574 std::optional<std::vector<lldb::cpu_id_t>> cpus;
575
576 /// Postmortem traces can specific additional data files, which are
577 /// represented in this variable using a data kind identifier for each file.
578 /// \{
579
580 /// tid -> data kind -> file
581 llvm::DenseMap<lldb::tid_t, llvm::StringMap<FileSpec>>
583
584 /// cpu id -> data kind -> file
585 llvm::DenseMap<lldb::cpu_id_t, llvm::StringMap<FileSpec>>
587
588 /// \}
589
590 std::optional<std::string> live_refresh_error;
592
593 /// Get the storage after refreshing the data in the case of a live process.
594 Storage &GetUpdatedStorage();
595};
596
597} // namespace lldb_private
598
599#endif // LLDB_TARGET_TRACE_H
A class to manage flag bits.
Definition Debugger.h:103
A file utility class.
Definition FileSpec.h:56
A plug-in interface definition class for debugging a process.
Definition Process.h:369
A stream class that can stream formatted output to a file.
Definition Stream.h:28
std::shared_ptr< Object > ObjectSP
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
virtual const char * GetStartConfigurationHelp()=0
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
virtual llvm::StringRef GetSchema()=0
Trace(Process &live_process)
Constructor for a live process.
Definition Trace.h:484
virtual lldb::CommandObjectSP GetThreadTraceStartCommand(CommandInterpreter &interpreter)=0
Get the command handle for the "thread trace start" command.
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
virtual void Dump(Stream *s) const =0
Dump the trace data that this plug-in has access to.
virtual void DumpTraceInfo(Thread &thread, Stream &s, bool verbose, bool json)=0
Dump general info about a given thread's trace.
virtual llvm::Expected< lldb::TraceCursorSP > CreateNewCursor(Thread &thread)=0
Get a TraceCursor for the given thread's trace.
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
virtual llvm::Error Start(llvm::ArrayRef< lldb::tid_t > tids, StructuredData::ObjectSP configuration=StructuredData::ObjectSP())=0
Start tracing live threads.
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
virtual llvm::Expected< FileSpec > SaveToDisk(FileSpec directory, bool compact)=0
Save the trace to the specified directory, which will be created if needed.
virtual lldb::CommandObjectSP GetProcessTraceStartCommand(CommandInterpreter &interpreter)=0
Get the command handle for the "process trace start" command.
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
virtual bool IsTraced(lldb::tid_t tid)=0
Check if a thread is currently traced by this object.
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
#define LLDB_INVALID_STOP_ID
Invalid value definitions.
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::CommandObject > CommandObjectSP
uint32_t cpu_id_t
Definition lldb-types.h:93
uint64_t tid_t
Definition lldb-types.h:85
jLLDBTraceGetBinaryData gdb-remote packet
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::optional< std::string > live_refresh_error
Definition Trace.h:590
std::vector< Process * > postmortem_processes
Portmortem processes traced by this object if doing non-live tracing.
Definition Trace.h:551