Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:48

0001 //===-- Debug.h -------------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_HOST_DEBUG_H
0010 #define LLDB_HOST_DEBUG_H
0011 
0012 #include <vector>
0013 
0014 #include "lldb/lldb-private.h"
0015 
0016 namespace lldb_private {
0017 
0018 // Tells a thread what it needs to do when the process is resumed.
0019 struct ResumeAction {
0020   lldb::tid_t tid;       // The thread ID that this action applies to,
0021                          // LLDB_INVALID_THREAD_ID for the default thread
0022                          // action
0023   lldb::StateType state; // Valid values are eStateStopped/eStateSuspended,
0024                          // eStateRunning, and eStateStepping.
0025   int signal; // When resuming this thread, resume it with this signal if this
0026               // value is > 0
0027 };
0028 
0029 // A class that contains instructions for all threads for
0030 // NativeProcessProtocol::Resume(). Each thread can either run, stay suspended,
0031 // or step when the process is resumed. We optionally have the ability to also
0032 // send a signal to the thread when the action is run or step.
0033 class ResumeActionList {
0034 public:
0035   ResumeActionList() = default;
0036 
0037   ResumeActionList(lldb::StateType default_action, int signal) {
0038     SetDefaultThreadActionIfNeeded(default_action, signal);
0039   }
0040 
0041   ResumeActionList(const ResumeAction *actions, size_t num_actions) {
0042     if (actions && num_actions) {
0043       m_actions.assign(actions, actions + num_actions);
0044       m_signal_handled.assign(num_actions, false);
0045     }
0046   }
0047 
0048   ~ResumeActionList() = default;
0049 
0050   bool IsEmpty() const { return m_actions.empty(); }
0051 
0052   void Append(const ResumeAction &action) {
0053     m_actions.push_back(action);
0054     m_signal_handled.push_back(false);
0055   }
0056 
0057   void AppendAction(lldb::tid_t tid, lldb::StateType state, int signal = 0) {
0058     ResumeAction action = {tid, state, signal};
0059     Append(action);
0060   }
0061 
0062   void AppendResumeAll() {
0063     AppendAction(LLDB_INVALID_THREAD_ID, lldb::eStateRunning);
0064   }
0065 
0066   void AppendSuspendAll() {
0067     AppendAction(LLDB_INVALID_THREAD_ID, lldb::eStateStopped);
0068   }
0069 
0070   void AppendStepAll() {
0071     AppendAction(LLDB_INVALID_THREAD_ID, lldb::eStateStepping);
0072   }
0073 
0074   const ResumeAction *GetActionForThread(lldb::tid_t tid,
0075                                          bool default_ok) const {
0076     const size_t num_actions = m_actions.size();
0077     for (size_t i = 0; i < num_actions; ++i) {
0078       if (m_actions[i].tid == tid)
0079         return &m_actions[i];
0080     }
0081     if (default_ok && tid != LLDB_INVALID_THREAD_ID)
0082       return GetActionForThread(LLDB_INVALID_THREAD_ID, false);
0083     return nullptr;
0084   }
0085 
0086   size_t NumActionsWithState(lldb::StateType state) const {
0087     size_t count = 0;
0088     const size_t num_actions = m_actions.size();
0089     for (size_t i = 0; i < num_actions; ++i) {
0090       if (m_actions[i].state == state)
0091         ++count;
0092     }
0093     return count;
0094   }
0095 
0096   bool SetDefaultThreadActionIfNeeded(lldb::StateType action, int signal) {
0097     if (GetActionForThread(LLDB_INVALID_THREAD_ID, true) == nullptr) {
0098       // There isn't a default action so we do need to set it.
0099       ResumeAction default_action = {LLDB_INVALID_THREAD_ID, action, signal};
0100       m_actions.push_back(default_action);
0101       m_signal_handled.push_back(false);
0102       return true; // Return true as we did add the default action
0103     }
0104     return false;
0105   }
0106 
0107   void SetSignalHandledForThread(lldb::tid_t tid) const {
0108     if (tid != LLDB_INVALID_THREAD_ID) {
0109       const size_t num_actions = m_actions.size();
0110       for (size_t i = 0; i < num_actions; ++i) {
0111         if (m_actions[i].tid == tid)
0112           m_signal_handled[i] = true;
0113       }
0114     }
0115   }
0116 
0117   const ResumeAction *GetFirst() const { return m_actions.data(); }
0118 
0119   size_t GetSize() const { return m_actions.size(); }
0120 
0121   void Clear() {
0122     m_actions.clear();
0123     m_signal_handled.clear();
0124   }
0125 
0126 protected:
0127   std::vector<ResumeAction> m_actions;
0128   mutable std::vector<bool> m_signal_handled;
0129 };
0130 
0131 struct ThreadStopInfo {
0132   lldb::StopReason reason;
0133   uint32_t signo;
0134   union {
0135     // eStopReasonException
0136     struct {
0137       uint64_t type;
0138       uint32_t data_count;
0139       lldb::addr_t data[8];
0140     } exception;
0141 
0142     // eStopReasonFork / eStopReasonVFork
0143     struct {
0144       lldb::pid_t child_pid;
0145       lldb::tid_t child_tid;
0146     } fork;
0147   } details;
0148 };
0149 }
0150 
0151 #endif // LLDB_HOST_DEBUG_H