1 //===-- TraceCursor.cpp -----------------------------------------*- 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 #include "lldb/Target/TraceCursor.h"
10 
11 #include "lldb/Target/ExecutionContext.h"
12 
13 using namespace lldb;
14 using namespace lldb_private;
15 using namespace llvm;
16 
17 TraceCursor::TraceCursor(lldb::ThreadSP thread_sp)
18     : m_exe_ctx_ref(ExecutionContext(thread_sp)) {}
19 
20 ExecutionContextRef &TraceCursor::GetExecutionContextRef() {
21   return m_exe_ctx_ref;
22 }
23 
24 void TraceCursor::SetGranularity(
25     lldb::TraceInstructionControlFlowType granularity) {
26   m_granularity = granularity;
27 }
28 
29 void TraceCursor::SetIgnoreErrors(bool ignore_errors) {
30   m_ignore_errors = ignore_errors;
31 }
32 
33 void TraceCursor::SetForwards(bool forwards) { m_forwards = forwards; }
34 
35 bool TraceCursor::IsForwards() const { return m_forwards; }
36 
37 const char *trace_event_utils::EventToDisplayString(lldb::TraceEvents event) {
38   switch (event) {
39   case lldb::eTraceEventPaused:
40     return "paused";
41   }
42   return nullptr;
43 }
44 
45 void trace_event_utils::ForEachEvent(
46     lldb::TraceEvents events,
47     std::function<void(lldb::TraceEvents event)> callback) {
48   while (events) {
49     TraceEvents event = static_cast<TraceEvents>(events & ~(events - 1));
50     callback(event);
51     events &= ~event;
52   }
53 }
54