Home | History | Annotate | Download | only in source
      1 //===-- DNBThreadResumeActions.cpp ------------------------------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 //  Created by Greg Clayton on 03/13/2010
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "DNBThreadResumeActions.h"
     15 
     16 DNBThreadResumeActions::DNBThreadResumeActions() :
     17     m_actions (),
     18     m_signal_handled ()
     19 {
     20 }
     21 
     22 DNBThreadResumeActions::DNBThreadResumeActions (const DNBThreadResumeAction *actions, size_t num_actions) :
     23     m_actions (),
     24     m_signal_handled ()
     25 {
     26     if (actions && num_actions)
     27     {
     28         m_actions.assign (actions, actions + num_actions);
     29         m_signal_handled.assign (num_actions, false);
     30     }
     31 }
     32 
     33 DNBThreadResumeActions::DNBThreadResumeActions (nub_state_t default_action, int signal) :
     34     m_actions(),
     35     m_signal_handled ()
     36 {
     37     SetDefaultThreadActionIfNeeded (default_action, signal);
     38 }
     39 
     40 void
     41 DNBThreadResumeActions::Append (const DNBThreadResumeAction &action)
     42 {
     43     m_actions.push_back (action);
     44     m_signal_handled.push_back (false);
     45 }
     46 
     47 void
     48 DNBThreadResumeActions::AppendAction
     49 (
     50     nub_thread_t tid,
     51     nub_state_t state,
     52     int signal,
     53     nub_addr_t addr
     54 )
     55 {
     56     DNBThreadResumeAction action = { tid, state, signal, addr };
     57     Append (action);
     58 }
     59 
     60 
     61 const DNBThreadResumeAction *
     62 DNBThreadResumeActions::GetActionForThread (nub_thread_t tid, bool default_ok) const
     63 {
     64     const size_t num_actions = m_actions.size();
     65     for (size_t i=0; i<num_actions; ++i)
     66     {
     67         if (m_actions[i].tid == tid)
     68             return &m_actions[i];
     69     }
     70     if (default_ok && tid != INVALID_NUB_THREAD)
     71         return GetActionForThread (INVALID_NUB_THREAD, false);
     72     return NULL;
     73 }
     74 
     75 size_t
     76 DNBThreadResumeActions::NumActionsWithState (nub_state_t state) const
     77 {
     78     size_t count = 0;
     79     const size_t num_actions = m_actions.size();
     80     for (size_t i=0; i<num_actions; ++i)
     81     {
     82         if (m_actions[i].state == state)
     83             ++count;
     84     }
     85     return count;
     86 }
     87 
     88 
     89 bool
     90 DNBThreadResumeActions::SetDefaultThreadActionIfNeeded (nub_state_t action, int signal)
     91 {
     92     if (GetActionForThread (INVALID_NUB_THREAD, true) == NULL)
     93     {
     94         // There isn't a default action so we do need to set it.
     95         DNBThreadResumeAction default_action = {INVALID_NUB_THREAD, action, signal, INVALID_NUB_ADDRESS };
     96         m_actions.push_back (default_action);
     97         m_signal_handled.push_back (false);
     98         return true; // Return true as we did add the default action
     99     }
    100     return false;
    101 }
    102 
    103 
    104 void
    105 DNBThreadResumeActions::SetSignalHandledForThread (nub_thread_t tid) const
    106 {
    107     if (tid != INVALID_NUB_THREAD)
    108     {
    109         const size_t num_actions = m_actions.size();
    110         for (size_t i=0; i<num_actions; ++i)
    111         {
    112             if (m_actions[i].tid == tid)
    113                 m_signal_handled[i] = true;
    114         }
    115     }
    116 }
    117