blob: 203e082b2e18e5ed1b2d1b4e91d81df05f203a56 [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
Chaoren Lin18fe6402015-02-03 01:51:47 +000016#include <map>
Richard Smith7572caf2015-03-22 23:18:46 +000017#include <string>
Chaoren Lin18fe6402015-02-03 01:51:47 +000018
Tamas Berghammerdb264a62015-03-31 09:52:22 +000019namespace lldb_private {
20namespace process_linux {
21
Todd Fialaaf245d12014-06-30 21:05:18 +000022 class NativeProcessLinux;
23
24 class NativeThreadLinux : public NativeThreadProtocol
25 {
26 friend class NativeProcessLinux;
27
28 public:
29 NativeThreadLinux (NativeProcessLinux *process, lldb::tid_t tid);
30
31 // ---------------------------------------------------------------------
32 // NativeThreadProtocol Interface
33 // ---------------------------------------------------------------------
Todd Fiala7206c6d2014-09-12 22:51:49 +000034 std::string
Todd Fialaaf245d12014-06-30 21:05:18 +000035 GetName() override;
36
37 lldb::StateType
38 GetState () override;
39
40 bool
Chaoren Lin28e57422015-02-03 01:51:25 +000041 GetStopReason (ThreadStopInfo &stop_info, std::string& description) override;
Todd Fialaaf245d12014-06-30 21:05:18 +000042
43 NativeRegisterContextSP
44 GetRegisterContext () override;
45
46 Error
47 SetWatchpoint (lldb::addr_t addr, size_t size, uint32_t watch_flags, bool hardware) override;
48
49 Error
50 RemoveWatchpoint (lldb::addr_t addr) override;
51
Todd Fialaaf245d12014-06-30 21:05:18 +000052 private:
53 // ---------------------------------------------------------------------
54 // Interface for friend classes
55 // ---------------------------------------------------------------------
56 void
Todd Fialaaf245d12014-06-30 21:05:18 +000057 SetRunning ();
58
59 void
60 SetStepping ();
61
62 void
Pavel Labathc4e25c92015-05-29 10:13:03 +000063 SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
Todd Fialaaf245d12014-06-30 21:05:18 +000064
Todd Fiala511e5cd2014-09-11 23:29:14 +000065 /// Return true if the thread is stopped.
66 /// If stopped by a signal, indicate the signo in the signo argument.
67 /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.
68 bool
69 IsStopped (int *signo);
70
Todd Fialaaf245d12014-06-30 21:05:18 +000071 void
Todd Fialaa9882ce2014-08-28 15:46:54 +000072 SetStoppedByExec ();
73
74 void
Todd Fialaaf245d12014-06-30 21:05:18 +000075 SetStoppedByBreakpoint ();
76
Chaoren Lin18fe6402015-02-03 01:51:47 +000077 void
Chaoren Linc16f5dc2015-03-19 23:28:10 +000078 SetStoppedByWatchpoint (uint32_t wp_index);
Chaoren Lin18fe6402015-02-03 01:51:47 +000079
Todd Fialaaf245d12014-06-30 21:05:18 +000080 bool
81 IsStoppedAtBreakpoint ();
82
Chaoren Lin18fe6402015-02-03 01:51:47 +000083 bool
84 IsStoppedAtWatchpoint ();
85
Todd Fialaaf245d12014-06-30 21:05:18 +000086 void
Chaoren Lin28e57422015-02-03 01:51:25 +000087 SetStoppedByTrace ();
88
89 void
Pavel Labath05569f62015-07-23 09:09:29 +000090 SetStoppedWithNoReason ();
Todd Fialaaf245d12014-06-30 21:05:18 +000091
92 void
93 SetExited ();
94
Pavel Labath8c8ff7a2015-05-11 10:03:10 +000095 Error
96 RequestStop ();
97
98 typedef std::function<Error (lldb::tid_t tid, bool supress_signal)> ResumeThreadFunction;
99 struct ThreadContext
100 {
101 bool stop_requested = false;
102 ResumeThreadFunction request_resume_function;
103 };
104
105 ThreadContext &
106 GetThreadContext() { return m_thread_context; }
107
Todd Fialaaf245d12014-06-30 21:05:18 +0000108 // ---------------------------------------------------------------------
109 // Private interface
110 // ---------------------------------------------------------------------
111 void
112 MaybeLogStateChange (lldb::StateType new_state);
113
114 // ---------------------------------------------------------------------
115 // Member Variables
116 // ---------------------------------------------------------------------
117 lldb::StateType m_state;
118 ThreadStopInfo m_stop_info;
119 NativeRegisterContextSP m_reg_context_sp;
Chaoren Lin28e57422015-02-03 01:51:25 +0000120 std::string m_stop_description;
Chaoren Lin18fe6402015-02-03 01:51:47 +0000121 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
122 WatchpointIndexMap m_watchpoint_index_map;
Pavel Labath8c8ff7a2015-05-11 10:03:10 +0000123 ThreadContext m_thread_context;
Todd Fialaaf245d12014-06-30 21:05:18 +0000124 };
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000125
126} // namespace process_linux
127} // namespace lldb_private
Todd Fialaaf245d12014-06-30 21:05:18 +0000128
129#endif // #ifndef liblldb_NativeThreadLinux_H_