blob: 289387bad724300835739236ed4bbfc3640ef9c3 [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
90 SetCrashedWithException (const siginfo_t& info);
Todd Fialaaf245d12014-06-30 21:05:18 +000091
92 void
93 SetSuspended ();
94
95 void
96 SetExited ();
97
Pavel Labath8c8ff7a2015-05-11 10:03:10 +000098 Error
99 RequestStop ();
100
101 typedef std::function<Error (lldb::tid_t tid, bool supress_signal)> ResumeThreadFunction;
102 struct ThreadContext
103 {
104 bool stop_requested = false;
105 ResumeThreadFunction request_resume_function;
106 };
107
108 ThreadContext &
109 GetThreadContext() { return m_thread_context; }
110
Todd Fialaaf245d12014-06-30 21:05:18 +0000111 // ---------------------------------------------------------------------
112 // Private interface
113 // ---------------------------------------------------------------------
114 void
115 MaybeLogStateChange (lldb::StateType new_state);
116
117 // ---------------------------------------------------------------------
118 // Member Variables
119 // ---------------------------------------------------------------------
120 lldb::StateType m_state;
121 ThreadStopInfo m_stop_info;
122 NativeRegisterContextSP m_reg_context_sp;
Chaoren Lin28e57422015-02-03 01:51:25 +0000123 std::string m_stop_description;
Chaoren Lin18fe6402015-02-03 01:51:47 +0000124 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
125 WatchpointIndexMap m_watchpoint_index_map;
Pavel Labath8c8ff7a2015-05-11 10:03:10 +0000126 ThreadContext m_thread_context;
Todd Fialaaf245d12014-06-30 21:05:18 +0000127 };
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000128
129} // namespace process_linux
130} // namespace lldb_private
Todd Fialaaf245d12014-06-30 21:05:18 +0000131
132#endif // #ifndef liblldb_NativeThreadLinux_H_