• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- ThreadPlanTracer.h --------------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLDB_TARGET_THREADPLANTRACER_H
11 #define LLDB_TARGET_THREADPLANTRACER_H
12 
13 #include "lldb/Symbol/TaggedASTType.h"
14 #include "lldb/Target/Thread.h"
15 #include "lldb/Utility/RegisterValue.h"
16 #include "lldb/lldb-private.h"
17 
18 namespace lldb_private {
19 
20 class ThreadPlanTracer {
21   friend class ThreadPlan;
22 
23 public:
24   enum ThreadPlanTracerStyle {
25     eLocation = 0,
26     eStateChange,
27     eCheckFrames,
28     ePython
29   };
30 
31   ThreadPlanTracer(Thread &thread, lldb::StreamSP &stream_sp);
32   ThreadPlanTracer(Thread &thread);
33 
34   virtual ~ThreadPlanTracer() = default;
35 
TracingStarted()36   virtual void TracingStarted() {}
37 
TracingEnded()38   virtual void TracingEnded() {}
39 
EnableTracing(bool value)40   bool EnableTracing(bool value) {
41     bool old_value = m_enabled;
42     m_enabled = value;
43     if (old_value == false && value == true)
44       TracingStarted();
45     else if (old_value == true && value == false)
46       TracingEnded();
47 
48     return old_value;
49   }
50 
TracingEnabled()51   bool TracingEnabled() { return m_enabled; }
52 
EnableSingleStep(bool value)53   bool EnableSingleStep(bool value) {
54     bool old_value = m_single_step;
55     m_single_step = value;
56     return old_value;
57   }
58 
SingleStepEnabled()59   bool SingleStepEnabled() { return m_single_step; }
60 
61   Thread &GetThread();
62 
63 protected:
64   Process &m_process;
65   lldb::tid_t m_tid;
66 
67   Stream *GetLogStream();
68 
69   virtual void Log();
70 
71 private:
72   bool TracerExplainsStop();
73 
74   bool m_single_step;
75   bool m_enabled;
76   lldb::StreamSP m_stream_sp;
77   Thread *m_thread;
78 };
79 
80 class ThreadPlanAssemblyTracer : public ThreadPlanTracer {
81 public:
82   ThreadPlanAssemblyTracer(Thread &thread, lldb::StreamSP &stream_sp);
83   ThreadPlanAssemblyTracer(Thread &thread);
84   ~ThreadPlanAssemblyTracer() override;
85 
86   void TracingStarted() override;
87   void TracingEnded() override;
88   void Log() override;
89 
90 private:
91   Disassembler *GetDisassembler();
92 
93   TypeFromUser GetIntPointerType();
94 
95   lldb::DisassemblerSP m_disassembler_sp;
96   TypeFromUser m_intptr_type;
97   std::vector<RegisterValue> m_register_values;
98   lldb::DataBufferSP m_buffer_sp;
99 };
100 
101 } // namespace lldb_private
102 
103 #endif // LLDB_TARGET_THREADPLANTRACER_H
104