Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 1 | //===-- NativeThreadLinux.h ----------------------------------- -*- 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 | #ifndef liblldb_NativeThreadLinux_H_ |
| 11 | #define liblldb_NativeThreadLinux_H_ |
| 12 | |
| 13 | #include "lldb/lldb-private-forward.h" |
Chaoren Lin | 2fe1d0a | 2015-02-03 01:51:38 +0000 | [diff] [blame] | 14 | #include "lldb/Host/common/NativeThreadProtocol.h" |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 15 | |
Pavel Labath | 605b51b | 2016-02-23 13:56:30 +0000 | [diff] [blame^] | 16 | #include <sched.h> |
| 17 | |
Chaoren Lin | 18fe640 | 2015-02-03 01:51:47 +0000 | [diff] [blame] | 18 | #include <map> |
Pavel Labath | 0e1d729 | 2015-08-20 09:06:12 +0000 | [diff] [blame] | 19 | #include <memory> |
Richard Smith | 7572caf | 2015-03-22 23:18:46 +0000 | [diff] [blame] | 20 | #include <string> |
Chaoren Lin | 18fe640 | 2015-02-03 01:51:47 +0000 | [diff] [blame] | 21 | |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 22 | namespace lldb_private { |
| 23 | namespace process_linux { |
| 24 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 25 | class NativeProcessLinux; |
| 26 | |
| 27 | class NativeThreadLinux : public NativeThreadProtocol |
| 28 | { |
| 29 | friend class NativeProcessLinux; |
| 30 | |
| 31 | public: |
| 32 | NativeThreadLinux (NativeProcessLinux *process, lldb::tid_t tid); |
| 33 | |
| 34 | // --------------------------------------------------------------------- |
| 35 | // NativeThreadProtocol Interface |
| 36 | // --------------------------------------------------------------------- |
Todd Fiala | 7206c6d | 2014-09-12 22:51:49 +0000 | [diff] [blame] | 37 | std::string |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 38 | GetName() override; |
| 39 | |
| 40 | lldb::StateType |
| 41 | GetState () override; |
| 42 | |
| 43 | bool |
Chaoren Lin | 28e5742 | 2015-02-03 01:51:25 +0000 | [diff] [blame] | 44 | GetStopReason (ThreadStopInfo &stop_info, std::string& description) override; |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 45 | |
| 46 | NativeRegisterContextSP |
| 47 | GetRegisterContext () override; |
| 48 | |
| 49 | Error |
| 50 | SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware) override; |
| 51 | |
| 52 | Error |
| 53 | RemoveWatchpoint (lldb::addr_t addr) override; |
| 54 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 55 | private: |
| 56 | // --------------------------------------------------------------------- |
| 57 | // Interface for friend classes |
| 58 | // --------------------------------------------------------------------- |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 59 | |
Pavel Labath | 605b51b | 2016-02-23 13:56:30 +0000 | [diff] [blame^] | 60 | /// Resumes the thread. If @p signo is anything but |
| 61 | /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. |
| 62 | Error |
| 63 | Resume(uint32_t signo); |
| 64 | |
| 65 | /// Single steps the thread. If @p signo is anything but |
| 66 | /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread. |
| 67 | Error |
| 68 | SingleStep(uint32_t signo); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 69 | |
| 70 | void |
Pavel Labath | c4e25c9 | 2015-05-29 10:13:03 +0000 | [diff] [blame] | 71 | SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 72 | |
Todd Fiala | 511e5cd | 2014-09-11 23:29:14 +0000 | [diff] [blame] | 73 | /// Return true if the thread is stopped. |
| 74 | /// If stopped by a signal, indicate the signo in the signo argument. |
| 75 | /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER. |
| 76 | bool |
| 77 | IsStopped (int *signo); |
| 78 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 79 | void |
Todd Fiala | a9882ce | 2014-08-28 15:46:54 +0000 | [diff] [blame] | 80 | SetStoppedByExec (); |
| 81 | |
| 82 | void |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 83 | SetStoppedByBreakpoint (); |
| 84 | |
Chaoren Lin | 18fe640 | 2015-02-03 01:51:47 +0000 | [diff] [blame] | 85 | void |
Chaoren Lin | c16f5dc | 2015-03-19 23:28:10 +0000 | [diff] [blame] | 86 | SetStoppedByWatchpoint (uint32_t wp_index); |
Chaoren Lin | 18fe640 | 2015-02-03 01:51:47 +0000 | [diff] [blame] | 87 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 88 | bool |
| 89 | IsStoppedAtBreakpoint (); |
| 90 | |
Chaoren Lin | 18fe640 | 2015-02-03 01:51:47 +0000 | [diff] [blame] | 91 | bool |
| 92 | IsStoppedAtWatchpoint (); |
| 93 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 94 | void |
Chaoren Lin | 28e5742 | 2015-02-03 01:51:25 +0000 | [diff] [blame] | 95 | SetStoppedByTrace (); |
| 96 | |
| 97 | void |
Pavel Labath | 05569f6 | 2015-07-23 09:09:29 +0000 | [diff] [blame] | 98 | SetStoppedWithNoReason (); |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 99 | |
| 100 | void |
| 101 | SetExited (); |
| 102 | |
Pavel Labath | 8c8ff7a | 2015-05-11 10:03:10 +0000 | [diff] [blame] | 103 | Error |
| 104 | RequestStop (); |
| 105 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 106 | // --------------------------------------------------------------------- |
| 107 | // Private interface |
| 108 | // --------------------------------------------------------------------- |
| 109 | void |
| 110 | MaybeLogStateChange (lldb::StateType new_state); |
| 111 | |
Pavel Labath | 605b51b | 2016-02-23 13:56:30 +0000 | [diff] [blame^] | 112 | NativeProcessLinux & |
| 113 | GetProcess(); |
| 114 | |
| 115 | void |
| 116 | SetStopped(); |
| 117 | |
| 118 | inline void |
| 119 | MaybePrepareSingleStepWorkaround(); |
| 120 | |
| 121 | inline void |
| 122 | MaybeCleanupSingleStepWorkaround(); |
| 123 | |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 124 | // --------------------------------------------------------------------- |
| 125 | // Member Variables |
| 126 | // --------------------------------------------------------------------- |
| 127 | lldb::StateType m_state; |
| 128 | ThreadStopInfo m_stop_info; |
| 129 | NativeRegisterContextSP m_reg_context_sp; |
Chaoren Lin | 28e5742 | 2015-02-03 01:51:25 +0000 | [diff] [blame] | 130 | std::string m_stop_description; |
Chaoren Lin | 18fe640 | 2015-02-03 01:51:47 +0000 | [diff] [blame] | 131 | using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>; |
| 132 | WatchpointIndexMap m_watchpoint_index_map; |
Pavel Labath | 605b51b | 2016-02-23 13:56:30 +0000 | [diff] [blame^] | 133 | cpu_set_t m_original_cpu_set; // For single-step workaround. |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 134 | }; |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 135 | |
Pavel Labath | 0e1d729 | 2015-08-20 09:06:12 +0000 | [diff] [blame] | 136 | typedef std::shared_ptr<NativeThreadLinux> NativeThreadLinuxSP; |
Tamas Berghammer | db264a6 | 2015-03-31 09:52:22 +0000 | [diff] [blame] | 137 | } // namespace process_linux |
| 138 | } // namespace lldb_private |
Todd Fiala | af245d1 | 2014-06-30 21:05:18 +0000 | [diff] [blame] | 139 | |
| 140 | #endif // #ifndef liblldb_NativeThreadLinux_H_ |