LLDB  mainline
Debug.h
Go to the documentation of this file.
1 //===-- Debug.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_HOST_DEBUG_H
10 #define LLDB_HOST_DEBUG_H
11 
12 #include <vector>
13 
14 #include "lldb/lldb-private.h"
15 
16 namespace lldb_private {
17 
18 // Tells a thread what it needs to do when the process is resumed.
19 struct ResumeAction {
20  lldb::tid_t tid; // The thread ID that this action applies to,
21  // LLDB_INVALID_THREAD_ID for the default thread
22  // action
23  lldb::StateType state; // Valid values are eStateStopped/eStateSuspended,
24  // eStateRunning, and eStateStepping.
25  int signal; // When resuming this thread, resume it with this signal if this
26  // value is > 0
27 };
28 
29 // A class that contains instructions for all threads for
30 // NativeProcessProtocol::Resume(). Each thread can either run, stay suspended,
31 // or step when the process is resumed. We optionally have the ability to also
32 // send a signal to the thread when the action is run or step.
34 public:
36 
37  ResumeActionList(lldb::StateType default_action, int signal)
39  SetDefaultThreadActionIfNeeded(default_action, signal);
40  }
41 
42  ResumeActionList(const ResumeAction *actions, size_t num_actions)
44  if (actions && num_actions) {
45  m_actions.assign(actions, actions + num_actions);
46  m_signal_handled.assign(num_actions, false);
47  }
48  }
49 
50  ~ResumeActionList() = default;
51 
52  bool IsEmpty() const { return m_actions.empty(); }
53 
54  void Append(const ResumeAction &action) {
55  m_actions.push_back(action);
56  m_signal_handled.push_back(false);
57  }
58 
59  void AppendAction(lldb::tid_t tid, lldb::StateType state, int signal = 0) {
60  ResumeAction action = {tid, state, signal};
61  Append(action);
62  }
63 
64  void AppendResumeAll() {
66  }
67 
70  }
71 
72  void AppendStepAll() {
74  }
75 
77  bool default_ok) const {
78  const size_t num_actions = m_actions.size();
79  for (size_t i = 0; i < num_actions; ++i) {
80  if (m_actions[i].tid == tid)
81  return &m_actions[i];
82  }
83  if (default_ok && tid != LLDB_INVALID_THREAD_ID)
85  return nullptr;
86  }
87 
88  size_t NumActionsWithState(lldb::StateType state) const {
89  size_t count = 0;
90  const size_t num_actions = m_actions.size();
91  for (size_t i = 0; i < num_actions; ++i) {
92  if (m_actions[i].state == state)
93  ++count;
94  }
95  return count;
96  }
97 
99  if (GetActionForThread(LLDB_INVALID_THREAD_ID, true) == nullptr) {
100  // There isn't a default action so we do need to set it.
101  ResumeAction default_action = {LLDB_INVALID_THREAD_ID, action, signal};
102  m_actions.push_back(default_action);
103  m_signal_handled.push_back(false);
104  return true; // Return true as we did add the default action
105  }
106  return false;
107  }
108 
110  if (tid != LLDB_INVALID_THREAD_ID) {
111  const size_t num_actions = m_actions.size();
112  for (size_t i = 0; i < num_actions; ++i) {
113  if (m_actions[i].tid == tid)
114  m_signal_handled[i] = true;
115  }
116  }
117  }
118 
119  const ResumeAction *GetFirst() const { return m_actions.data(); }
120 
121  size_t GetSize() const { return m_actions.size(); }
122 
123  void Clear() {
124  m_actions.clear();
125  m_signal_handled.clear();
126  }
127 
128 protected:
129  std::vector<ResumeAction> m_actions;
130  mutable std::vector<bool> m_signal_handled;
131 };
132 
135  union {
136  // eStopReasonSignal
137  struct {
139  } signal;
140 
141  // eStopReasonException
142  struct {
143  uint64_t type;
146  } exception;
147 
148  // eStopReasonFork / eStopReasonVFork
149  struct {
152  } fork;
153  } details;
154 };
155 }
156 
157 #endif // LLDB_HOST_DEBUG_H
lldb_private::ResumeActionList::AppendSuspendAll
void AppendSuspendAll()
Definition: Debug.h:68
lldb_private::ResumeActionList::NumActionsWithState
size_t NumActionsWithState(lldb::StateType state) const
Definition: Debug.h:88
lldb_private::ResumeActionList::ResumeActionList
ResumeActionList()
Definition: Debug.h:35
lldb_private::ResumeActionList::ResumeActionList
ResumeActionList(const ResumeAction *actions, size_t num_actions)
Definition: Debug.h:42
lldb_private::ResumeActionList::SetSignalHandledForThread
void SetSignalHandledForThread(lldb::tid_t tid) const
Definition: Debug.h:109
lldb_private::ResumeActionList::IsEmpty
bool IsEmpty() const
Definition: Debug.h:52
lldb_private::ResumeActionList::m_actions
std::vector< ResumeAction > m_actions
Definition: Debug.h:129
lldb_private::ThreadStopInfo::data_count
uint32_t data_count
Definition: Debug.h:144
lldb::StopReason
StopReason
Thread stop reasons.
Definition: lldb-enumerations.h:239
lldb_private::ResumeAction
Definition: Debug.h:19
lldb_private::ThreadStopInfo::details
union lldb_private::ThreadStopInfo::@13 details
lldb_private::ResumeAction::signal
int signal
Definition: Debug.h:25
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::ResumeActionList::ResumeActionList
ResumeActionList(lldb::StateType default_action, int signal)
Definition: Debug.h:37
lldb_private::ResumeActionList::AppendAction
void AppendAction(lldb::tid_t tid, lldb::StateType state, int signal=0)
Definition: Debug.h:59
lldb_private::ResumeActionList::AppendResumeAll
void AppendResumeAll()
Definition: Debug.h:64
lldb_private::ResumeActionList::GetActionForThread
const ResumeAction * GetActionForThread(lldb::tid_t tid, bool default_ok) const
Definition: Debug.h:76
lldb::eStateStopped
@ eStateStopped
Process or thread is stopped and can be examined.
Definition: lldb-enumerations.h:84
lldb_private::ResumeActionList::~ResumeActionList
~ResumeActionList()=default
lldb_private::ResumeAction::state
lldb::StateType state
Definition: Debug.h:23
lldb_private::ThreadStopInfo::child_tid
lldb::tid_t child_tid
Definition: Debug.h:151
lldb_private::ResumeActionList::AppendStepAll
void AppendStepAll()
Definition: Debug.h:72
lldb_private::ThreadStopInfo::reason
lldb::StopReason reason
Definition: Debug.h:134
lldb_private::ResumeActionList::m_signal_handled
std::vector< bool > m_signal_handled
Definition: Debug.h:130
lldb_private::ThreadStopInfo::exception
struct lldb_private::ThreadStopInfo::@13::@15 exception
lldb_private::ThreadStopInfo::signal
struct lldb_private::ThreadStopInfo::@13::@14 signal
lldb_private::ThreadStopInfo::type
uint64_t type
Definition: Debug.h:143
lldb_private::ThreadStopInfo
Definition: Debug.h:133
lldb_private::ResumeActionList::GetSize
size_t GetSize() const
Definition: Debug.h:121
lldb_private::ThreadStopInfo::child_pid
lldb::pid_t child_pid
Definition: Debug.h:150
lldb-private.h
lldb::eStateStepping
@ eStateStepping
Process or thread is in the process of stepping and can not be examined.
Definition: lldb-enumerations.h:86
lldb_private::ResumeActionList::Clear
void Clear()
Definition: Debug.h:123
uint32_t
lldb::pid_t
uint64_t pid_t
Definition: lldb-types.h:85
lldb_private::ResumeAction::tid
lldb::tid_t tid
Definition: Debug.h:20
lldb_private::ThreadStopInfo::signo
uint32_t signo
Definition: Debug.h:138
lldb_private::ThreadStopInfo::fork
struct lldb_private::ThreadStopInfo::@13::@16 fork
lldb_private::ResumeActionList
Definition: Debug.h:33
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
LLDB_INVALID_THREAD_ID
#define LLDB_INVALID_THREAD_ID
Definition: lldb-defines.h:94
lldb::StateType
StateType
Process and Thread States.
Definition: lldb-enumerations.h:73
lldb_private::ThreadStopInfo::data
lldb::addr_t data[8]
Definition: Debug.h:145
lldb_private::ResumeActionList::GetFirst
const ResumeAction * GetFirst() const
Definition: Debug.h:119
lldb::eStateRunning
@ eStateRunning
Process or thread is running and can't be examined.
Definition: lldb-enumerations.h:85
lldb_private::ResumeActionList::Append
void Append(const ResumeAction &action)
Definition: Debug.h:54
lldb_private::ResumeActionList::SetDefaultThreadActionIfNeeded
bool SetDefaultThreadActionIfNeeded(lldb::StateType action, int signal)
Definition: Debug.h:98
lldb::tid_t
uint64_t tid_t
Definition: lldb-types.h:86