blob: f1b6a6e44782833aef98a6b0f25617219d28ab95 [file] [log] [blame]
Todd Fialaaf245d12014-06-30 21:05:18 +00001//===-- 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 Lin2fe1d0a2015-02-03 01:51:38 +000014#include "lldb/Host/common/NativeThreadProtocol.h"
Todd Fialaaf245d12014-06-30 21:05:18 +000015
Pavel Labath605b51b2016-02-23 13:56:30 +000016#include <sched.h>
17
Chaoren Lin18fe6402015-02-03 01:51:47 +000018#include <map>
Pavel Labath0e1d7292015-08-20 09:06:12 +000019#include <memory>
Richard Smith7572caf2015-03-22 23:18:46 +000020#include <string>
Chaoren Lin18fe6402015-02-03 01:51:47 +000021
Tamas Berghammerdb264a62015-03-31 09:52:22 +000022namespace lldb_private {
23namespace process_linux {
24
Todd Fialaaf245d12014-06-30 21:05:18 +000025 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 Fiala7206c6d2014-09-12 22:51:49 +000037 std::string
Todd Fialaaf245d12014-06-30 21:05:18 +000038 GetName() override;
39
40 lldb::StateType
41 GetState () override;
42
43 bool
Chaoren Lin28e57422015-02-03 01:51:25 +000044 GetStopReason (ThreadStopInfo &stop_info, std::string& description) override;
Todd Fialaaf245d12014-06-30 21:05:18 +000045
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 Fialaaf245d12014-06-30 21:05:18 +000055 private:
56 // ---------------------------------------------------------------------
57 // Interface for friend classes
58 // ---------------------------------------------------------------------
Todd Fialaaf245d12014-06-30 21:05:18 +000059
Pavel Labath605b51b2016-02-23 13:56:30 +000060 /// 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 Fialaaf245d12014-06-30 21:05:18 +000069
70 void
Pavel Labathc4e25c92015-05-29 10:13:03 +000071 SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
Todd Fialaaf245d12014-06-30 21:05:18 +000072
Todd Fiala511e5cd2014-09-11 23:29:14 +000073 /// 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 Fialaaf245d12014-06-30 21:05:18 +000079 void
Todd Fialaa9882ce2014-08-28 15:46:54 +000080 SetStoppedByExec ();
81
82 void
Todd Fialaaf245d12014-06-30 21:05:18 +000083 SetStoppedByBreakpoint ();
84
Chaoren Lin18fe6402015-02-03 01:51:47 +000085 void
Chaoren Linc16f5dc2015-03-19 23:28:10 +000086 SetStoppedByWatchpoint (uint32_t wp_index);
Chaoren Lin18fe6402015-02-03 01:51:47 +000087
Todd Fialaaf245d12014-06-30 21:05:18 +000088 bool
89 IsStoppedAtBreakpoint ();
90
Chaoren Lin18fe6402015-02-03 01:51:47 +000091 bool
92 IsStoppedAtWatchpoint ();
93
Todd Fialaaf245d12014-06-30 21:05:18 +000094 void
Chaoren Lin28e57422015-02-03 01:51:25 +000095 SetStoppedByTrace ();
96
97 void
Pavel Labath05569f62015-07-23 09:09:29 +000098 SetStoppedWithNoReason ();
Todd Fialaaf245d12014-06-30 21:05:18 +000099
100 void
101 SetExited ();
102
Pavel Labath8c8ff7a2015-05-11 10:03:10 +0000103 Error
104 RequestStop ();
105
Todd Fialaaf245d12014-06-30 21:05:18 +0000106 // ---------------------------------------------------------------------
107 // Private interface
108 // ---------------------------------------------------------------------
109 void
110 MaybeLogStateChange (lldb::StateType new_state);
111
Pavel Labath605b51b2016-02-23 13:56:30 +0000112 NativeProcessLinux &
113 GetProcess();
114
115 void
116 SetStopped();
117
118 inline void
119 MaybePrepareSingleStepWorkaround();
120
121 inline void
122 MaybeCleanupSingleStepWorkaround();
123
Todd Fialaaf245d12014-06-30 21:05:18 +0000124 // ---------------------------------------------------------------------
125 // Member Variables
126 // ---------------------------------------------------------------------
127 lldb::StateType m_state;
128 ThreadStopInfo m_stop_info;
129 NativeRegisterContextSP m_reg_context_sp;
Chaoren Lin28e57422015-02-03 01:51:25 +0000130 std::string m_stop_description;
Chaoren Lin18fe6402015-02-03 01:51:47 +0000131 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
132 WatchpointIndexMap m_watchpoint_index_map;
Pavel Labath605b51b2016-02-23 13:56:30 +0000133 cpu_set_t m_original_cpu_set; // For single-step workaround.
Todd Fialaaf245d12014-06-30 21:05:18 +0000134 };
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000135
Pavel Labath0e1d7292015-08-20 09:06:12 +0000136 typedef std::shared_ptr<NativeThreadLinux> NativeThreadLinuxSP;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000137} // namespace process_linux
138} // namespace lldb_private
Todd Fialaaf245d12014-06-30 21:05:18 +0000139
140#endif // #ifndef liblldb_NativeThreadLinux_H_