1 //===-- DNBThreadResumeActions.cpp ------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // Created by Greg Clayton on 03/13/2010
11 //===----------------------------------------------------------------------===//
13 #include "DNBThreadResumeActions.h"
15 DNBThreadResumeActions::DNBThreadResumeActions()
16 : m_actions(), m_signal_handled() {}
18 DNBThreadResumeActions::DNBThreadResumeActions(
19 const DNBThreadResumeAction
*actions
, size_t num_actions
)
20 : m_actions(), m_signal_handled() {
21 if (actions
&& num_actions
) {
22 m_actions
.assign(actions
, actions
+ num_actions
);
23 m_signal_handled
.assign(num_actions
, false);
27 DNBThreadResumeActions::DNBThreadResumeActions(nub_state_t default_action
,
29 : m_actions(), m_signal_handled() {
30 SetDefaultThreadActionIfNeeded(default_action
, signal
);
33 void DNBThreadResumeActions::Append(const DNBThreadResumeAction
&action
) {
34 m_actions
.push_back(action
);
35 m_signal_handled
.push_back(false);
38 void DNBThreadResumeActions::AppendAction(nub_thread_t tid
, nub_state_t state
,
39 int signal
, nub_addr_t addr
) {
40 DNBThreadResumeAction action
= {tid
, state
, signal
, addr
};
44 const DNBThreadResumeAction
*
45 DNBThreadResumeActions::GetActionForThread(nub_thread_t tid
,
46 bool default_ok
) const {
47 const size_t num_actions
= m_actions
.size();
48 for (size_t i
= 0; i
< num_actions
; ++i
) {
49 if (m_actions
[i
].tid
== tid
)
52 if (default_ok
&& tid
!= INVALID_NUB_THREAD
)
53 return GetActionForThread(INVALID_NUB_THREAD
, false);
57 size_t DNBThreadResumeActions::NumActionsWithState(nub_state_t state
) const {
59 const size_t num_actions
= m_actions
.size();
60 for (size_t i
= 0; i
< num_actions
; ++i
) {
61 if (m_actions
[i
].state
== state
)
67 bool DNBThreadResumeActions::SetDefaultThreadActionIfNeeded(nub_state_t action
,
69 if (GetActionForThread(INVALID_NUB_THREAD
, true) == NULL
) {
70 // There isn't a default action so we do need to set it.
71 DNBThreadResumeAction default_action
= {INVALID_NUB_THREAD
, action
, signal
,
73 m_actions
.push_back(default_action
);
74 m_signal_handled
.push_back(false);
75 return true; // Return true as we did add the default action
80 void DNBThreadResumeActions::SetSignalHandledForThread(nub_thread_t tid
) const {
81 if (tid
!= INVALID_NUB_THREAD
) {
82 const size_t num_actions
= m_actions
.size();
83 for (size_t i
= 0; i
< num_actions
; ++i
) {
84 if (m_actions
[i
].tid
== tid
)
85 m_signal_handled
[i
] = true;