LLDB  mainline
UnixSignals.h
Go to the documentation of this file.
1 //===-- UnixSignals.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_TARGET_UNIXSIGNALS_H
10 #define LLDB_TARGET_UNIXSIGNALS_H
11 
12 #include <map>
13 #include <string>
14 #include <vector>
15 
17 #include "lldb/lldb-private.h"
18 #include "llvm/ADT/Optional.h"
19 #include "llvm/Support/JSON.h"
20 
21 namespace lldb_private {
22 
23 class UnixSignals {
24 public:
25  static lldb::UnixSignalsSP Create(const ArchSpec &arch);
26  static lldb::UnixSignalsSP CreateForHost();
27 
28  // Constructors and Destructors
29  UnixSignals();
30 
31  virtual ~UnixSignals();
32 
33  const char *GetSignalAsCString(int32_t signo) const;
34 
35  bool SignalIsValid(int32_t signo) const;
36 
37  int32_t GetSignalNumberFromName(const char *name) const;
38 
39  const char *GetSignalInfo(int32_t signo, bool &should_suppress,
40  bool &should_stop, bool &should_notify) const;
41 
42  bool GetShouldSuppress(int32_t signo) const;
43 
44  bool SetShouldSuppress(int32_t signo, bool value);
45 
46  bool SetShouldSuppress(const char *signal_name, bool value);
47 
48  bool GetShouldStop(int32_t signo) const;
49 
50  bool SetShouldStop(int32_t signo, bool value);
51  bool SetShouldStop(const char *signal_name, bool value);
52 
53  bool GetShouldNotify(int32_t signo) const;
54 
55  bool SetShouldNotify(int32_t signo, bool value);
56 
57  bool SetShouldNotify(const char *signal_name, bool value);
58 
59  bool ResetSignal(int32_t signo, bool reset_stop = true,
60  bool reset_notify = true, bool reset_suppress = true);
61 
62  // These provide an iterator through the signals available on this system.
63  // Call GetFirstSignalNumber to get the first entry, then iterate on
64  // GetNextSignalNumber till you get back LLDB_INVALID_SIGNAL_NUMBER.
65  int32_t GetFirstSignalNumber() const;
66 
67  int32_t GetNextSignalNumber(int32_t current_signal) const;
68 
69  int32_t GetNumSignals() const;
70 
71  int32_t GetSignalAtIndex(int32_t index) const;
72 
74 
75  // We assume that the elements of this object are constant once it is
76  // constructed, since a process should never need to add or remove symbols as
77  // it runs. So don't call these functions anywhere but the constructor of
78  // your subclass of UnixSignals or in your Process Plugin's GetUnixSignals
79  // method before you return the UnixSignal object.
80 
81  void AddSignal(int signo, const char *name, bool default_suppress,
82  bool default_stop, bool default_notify,
83  const char *description, const char *alias = nullptr);
84 
85  void RemoveSignal(int signo);
86 
87  /// Track how many times signals are hit as stop reasons.
88  void IncrementSignalHitCount(int signo);
89 
90  /// Get the hit count statistics for signals.
91  ///
92  /// Gettings statistics on the hit counts of signals can help explain why some
93  /// debug sessions are slow since each stop takes a few hundred ms and some
94  /// software use signals a lot and can cause slow debugging performance if
95  /// they are used too often. Even if a signal is not stopped at, it will auto
96  /// continue the process and a delay will happen.
97  llvm::json::Value GetHitCountStatistics() const;
98 
99  // Returns a current version of the data stored in this class. Version gets
100  // incremented each time Set... method is called.
101  uint64_t GetVersion() const;
102 
103  // Returns a vector of signals that meet criteria provided in arguments. Each
104  // should_[suppress|stop|notify] flag can be None - no filtering by this
105  // flag true - only signals that have it set to true are returned false -
106  // only signals that have it set to true are returned
107  std::vector<int32_t> GetFilteredSignals(llvm::Optional<bool> should_suppress,
108  llvm::Optional<bool> should_stop,
109  llvm::Optional<bool> should_notify);
110 
111 protected:
112  // Classes that inherit from UnixSignals can see and modify these
113 
114  struct Signal {
119  bool m_suppress : 1, m_stop : 1, m_notify : 1;
121 
122  Signal(const char *name, bool default_suppress, bool default_stop,
123  bool default_notify, const char *description, const char *alias);
124 
125  ~Signal() = default;
126  void Reset(bool reset_stop, bool reset_notify, bool reset_suppress);
127  };
128 
129  virtual void Reset();
130 
131  typedef std::map<int32_t, Signal> collection;
132 
134 
135  // This version gets incremented every time something is changing in this
136  // class, including when we call AddSignal from the constructor. So after the
137  // object is constructed m_version is going to be > 0 if it has at least one
138  // signal registered in it.
139  uint64_t m_version = 0;
140 
141  // GDBRemote signals need to be copyable.
142  UnixSignals(const UnixSignals &rhs);
143 
144  const UnixSignals &operator=(const UnixSignals &rhs) = delete;
145 };
146 
147 } // Namespace lldb
148 #endif // LLDB_TARGET_UNIXSIGNALS_H
lldb_private::UnixSignals::UnixSignals
UnixSignals()
Definition: UnixSignals.cpp:63
lldb_private::UnixSignals::Signal::~Signal
~Signal()=default
lldb_private::ArchSpec
Definition: ArchSpec.h:32
lldb_private::UnixSignals::Signal::m_default_suppress
bool m_default_suppress
Definition: UnixSignals.h:120
lldb_private::UnixSignals::GetShouldStop
bool GetShouldStop(int32_t signo) const
Definition: UnixSignals.cpp:227
lldb_private::UnixSignals::AddSignal
void AddSignal(int signo, const char *name, bool default_suppress, bool default_stop, bool default_notify, const char *description, const char *alias=nullptr)
Definition: UnixSignals.cpp:115
lldb_private::UnixSignals::Reset
virtual void Reset()
Definition: UnixSignals.cpp:69
lldb_private::UnixSignals::GetSignalNumberFromName
int32_t GetSignalNumberFromName(const char *name) const
Definition: UnixSignals.cpp:149
lldb_private::UnixSignals::RemoveSignal
void RemoveSignal(int signo)
Definition: UnixSignals.cpp:124
lldb_private::UnixSignals::IncrementSignalHitCount
void IncrementSignalHitCount(int signo)
Track how many times signals are hit as stop reasons.
Definition: UnixSignals.cpp:318
lldb_private::UnixSignals::Signal::m_hit_count
uint32_t m_hit_count
Definition: UnixSignals.h:118
lldb_private::UnixSignals::collection
std::map< int32_t, Signal > collection
Definition: UnixSignals.h:131
lldb_private::UnixSignals::SetShouldSuppress
bool SetShouldSuppress(int32_t signo, bool value)
lldb_private::UnixSignals::Signal::Reset
void Reset(bool reset_stop, bool reset_notify, bool reset_suppress)
Definition: UnixSignals.cpp:335
lldb_private::UnixSignals::GetShouldSuppress
bool GetShouldSuppress(int32_t signo) const
Definition: UnixSignals.cpp:203
lldb_private::UnixSignals::operator=
const UnixSignals & operator=(const UnixSignals &rhs)=delete
lldb_private::UnixSignals::GetHitCountStatistics
llvm::json::Value GetHitCountStatistics() const
Get the hit count statistics for signals.
Definition: UnixSignals.cpp:324
lldb_private::UnixSignals::~UnixSignals
virtual ~UnixSignals()
lldb_private::UnixSignals::GetShouldNotify
bool GetShouldNotify(int32_t signo) const
Definition: UnixSignals.cpp:251
lldb_private::UnixSignals::Signal::Signal
Signal(const char *name, bool default_suppress, bool default_stop, bool default_notify, const char *description, const char *alias)
Definition: UnixSignals.cpp:20
lldb_private::UnixSignals::GetNumSignals
int32_t GetNumSignals() const
Definition: UnixSignals.cpp:275
lldb_private::UnixSignals::GetFirstSignalNumber
int32_t GetFirstSignalNumber() const
Definition: UnixSignals.cpp:167
lldb_private::UnixSignals::m_version
uint64_t m_version
Definition: UnixSignals.h:139
lldb_private::UnixSignals::GetSignalAtIndex
int32_t GetSignalAtIndex(int32_t index) const
Definition: UnixSignals.cpp:277
lldb_private::UnixSignals::Signal::m_name
ConstString m_name
Definition: UnixSignals.h:115
lldb_private::UnixSignals::SetShouldStop
bool SetShouldStop(int32_t signo, bool value)
lldb_private::UnixSignals::GetShortName
ConstString GetShortName(ConstString name) const
Definition: UnixSignals.cpp:143
lldb_private::UnixSignals::CreateForHost
static lldb::UnixSignalsSP CreateForHost()
Definition: UnixSignals.cpp:56
lldb_private::ConstString
Definition: ConstString.h:39
lldb_private::UnixSignals::GetVersion
uint64_t GetVersion() const
Definition: UnixSignals.cpp:285
lldb_private::UnixSignals::Signal::m_notify
bool m_notify
Definition: UnixSignals.h:119
lldb_private::UnixSignals
Definition: UnixSignals.h:23
lldb_private::UnixSignals::Signal
Definition: UnixSignals.h:114
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::UnixSignals::Signal::m_stop
bool m_stop
Definition: UnixSignals.h:119
lldb-private.h
lldb_private::UnixSignals::GetSignalInfo
const char * GetSignalInfo(int32_t signo, bool &should_suppress, bool &should_stop, bool &should_notify) const
Definition: UnixSignals.cpp:188
lldb_private::UnixSignals::GetNextSignalNumber
int32_t GetNextSignalNumber(int32_t current_signal) const
Definition: UnixSignals.cpp:174
uint32_t
lldb_private::UnixSignals::GetFilteredSignals
std::vector< int32_t > GetFilteredSignals(llvm::Optional< bool > should_suppress, llvm::Optional< bool > should_stop, llvm::Optional< bool > should_notify)
Definition: UnixSignals.cpp:288
lldb_private::UnixSignals::SignalIsValid
bool SignalIsValid(int32_t signo) const
Definition: UnixSignals.cpp:139
lldb_private::UnixSignals::Signal::m_alias
ConstString m_alias
Definition: UnixSignals.h:116
lldb_private::UnixSignals::Signal::m_suppress
bool m_suppress
Definition: UnixSignals.h:119
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::UnixSignals::GetSignalAsCString
const char * GetSignalAsCString(int32_t signo) const
Definition: UnixSignals.cpp:131
lldb_private::UnixSignals::Signal::m_default_notify
bool m_default_notify
Definition: UnixSignals.h:120
ConstString.h
lldb_private::UnixSignals::SetShouldNotify
bool SetShouldNotify(int32_t signo, bool value)
lldb_private::UnixSignals::ResetSignal
bool ResetSignal(int32_t signo, bool reset_stop=true, bool reset_notify=true, bool reset_suppress=true)
Definition: UnixSignals.cpp:345
lldb_private::UnixSignals::Signal::m_description
std::string m_description
Definition: UnixSignals.h:117
lldb_private::UnixSignals::m_signals
collection m_signals
Definition: UnixSignals.h:133
lldb_private::UnixSignals::Signal::m_default_stop
bool m_default_stop
Definition: UnixSignals.h:120
lldb_private::UnixSignals::Create
static lldb::UnixSignalsSP Create(const ArchSpec &arch)
Definition: UnixSignals.cpp:32