UnixSignals.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #ifndef LLDB_TARGET_UNIXSIGNALS_H
  9. #define LLDB_TARGET_UNIXSIGNALS_H
  10. #include <map>
  11. #include <string>
  12. #include <vector>
  13. #include "lldb/Utility/ConstString.h"
  14. #include "lldb/lldb-private.h"
  15. #include "llvm/ADT/Optional.h"
  16. namespace lldb_private {
  17. class UnixSignals {
  18. public:
  19. static lldb::UnixSignalsSP Create(const ArchSpec &arch);
  20. static lldb::UnixSignalsSP CreateForHost();
  21. // Constructors and Destructors
  22. UnixSignals();
  23. virtual ~UnixSignals();
  24. const char *GetSignalAsCString(int32_t signo) const;
  25. bool SignalIsValid(int32_t signo) const;
  26. int32_t GetSignalNumberFromName(const char *name) const;
  27. const char *GetSignalInfo(int32_t signo, bool &should_suppress,
  28. bool &should_stop, bool &should_notify) const;
  29. bool GetShouldSuppress(int32_t signo) const;
  30. bool SetShouldSuppress(int32_t signo, bool value);
  31. bool SetShouldSuppress(const char *signal_name, bool value);
  32. bool GetShouldStop(int32_t signo) const;
  33. bool SetShouldStop(int32_t signo, bool value);
  34. bool SetShouldStop(const char *signal_name, bool value);
  35. bool GetShouldNotify(int32_t signo) const;
  36. bool SetShouldNotify(int32_t signo, bool value);
  37. bool SetShouldNotify(const char *signal_name, bool value);
  38. // These provide an iterator through the signals available on this system.
  39. // Call GetFirstSignalNumber to get the first entry, then iterate on
  40. // GetNextSignalNumber till you get back LLDB_INVALID_SIGNAL_NUMBER.
  41. int32_t GetFirstSignalNumber() const;
  42. int32_t GetNextSignalNumber(int32_t current_signal) const;
  43. int32_t GetNumSignals() const;
  44. int32_t GetSignalAtIndex(int32_t index) const;
  45. ConstString GetShortName(ConstString name) const;
  46. // We assume that the elements of this object are constant once it is
  47. // constructed, since a process should never need to add or remove symbols as
  48. // it runs. So don't call these functions anywhere but the constructor of
  49. // your subclass of UnixSignals or in your Process Plugin's GetUnixSignals
  50. // method before you return the UnixSignal object.
  51. void AddSignal(int signo, const char *name, bool default_suppress,
  52. bool default_stop, bool default_notify,
  53. const char *description, const char *alias = nullptr);
  54. void RemoveSignal(int signo);
  55. // Returns a current version of the data stored in this class. Version gets
  56. // incremented each time Set... method is called.
  57. uint64_t GetVersion() const;
  58. // Returns a vector of signals that meet criteria provided in arguments. Each
  59. // should_[suppress|stop|notify] flag can be None - no filtering by this
  60. // flag true - only signals that have it set to true are returned false -
  61. // only signals that have it set to true are returned
  62. std::vector<int32_t> GetFilteredSignals(llvm::Optional<bool> should_suppress,
  63. llvm::Optional<bool> should_stop,
  64. llvm::Optional<bool> should_notify);
  65. protected:
  66. // Classes that inherit from UnixSignals can see and modify these
  67. struct Signal {
  68. ConstString m_name;
  69. ConstString m_alias;
  70. std::string m_description;
  71. bool m_suppress : 1, m_stop : 1, m_notify : 1;
  72. Signal(const char *name, bool default_suppress, bool default_stop,
  73. bool default_notify, const char *description, const char *alias);
  74. ~Signal() {}
  75. };
  76. virtual void Reset();
  77. typedef std::map<int32_t, Signal> collection;
  78. collection m_signals;
  79. // This version gets incremented every time something is changing in this
  80. // class, including when we call AddSignal from the constructor. So after the
  81. // object is constructed m_version is going to be > 0 if it has at least one
  82. // signal registered in it.
  83. uint64_t m_version = 0;
  84. // GDBRemote signals need to be copyable.
  85. UnixSignals(const UnixSignals &rhs);
  86. const UnixSignals &operator=(const UnixSignals &rhs) = delete;
  87. };
  88. } // Namespace lldb
  89. #endif // LLDB_TARGET_UNIXSIGNALS_H