blob: 01b54d9ec47ebb6433faf0ca3b180d24150889d5 [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
Pavel Labath8abd34f2017-01-25 11:19:45 +000013#include "SingleStepCheck.h"
Chaoren Lin2fe1d0a2015-02-03 01:51:38 +000014#include "lldb/Host/common/NativeThreadProtocol.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000015#include "lldb/lldb-private-forward.h"
Todd Fialaaf245d12014-06-30 21:05:18 +000016
Pavel Labathb6dbe9a2017-07-18 13:14:01 +000017#include <csignal>
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
Kate Stoneb9c1b512016-09-06 20:57:50 +000025class NativeProcessLinux;
Todd Fialaaf245d12014-06-30 21:05:18 +000026
Kate Stoneb9c1b512016-09-06 20:57:50 +000027class NativeThreadLinux : public NativeThreadProtocol {
28 friend class NativeProcessLinux;
Todd Fialaaf245d12014-06-30 21:05:18 +000029
Kate Stoneb9c1b512016-09-06 20:57:50 +000030public:
Pavel Labath82abefa2017-07-18 09:24:48 +000031 NativeThreadLinux(NativeProcessLinux &process, lldb::tid_t tid);
Todd Fialaaf245d12014-06-30 21:05:18 +000032
Kate Stoneb9c1b512016-09-06 20:57:50 +000033 // ---------------------------------------------------------------------
34 // NativeThreadProtocol Interface
35 // ---------------------------------------------------------------------
36 std::string GetName() override;
Todd Fialaaf245d12014-06-30 21:05:18 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 lldb::StateType GetState() override;
Todd Fialaaf245d12014-06-30 21:05:18 +000039
Kate Stoneb9c1b512016-09-06 20:57:50 +000040 bool GetStopReason(ThreadStopInfo &stop_info,
41 std::string &description) override;
Todd Fialaaf245d12014-06-30 21:05:18 +000042
Kate Stoneb9c1b512016-09-06 20:57:50 +000043 NativeRegisterContextSP GetRegisterContext() override;
Todd Fialaaf245d12014-06-30 21:05:18 +000044
Zachary Turner97206d52017-05-12 04:51:55 +000045 Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags,
46 bool hardware) override;
Todd Fialaaf245d12014-06-30 21:05:18 +000047
Zachary Turner97206d52017-05-12 04:51:55 +000048 Status RemoveWatchpoint(lldb::addr_t addr) override;
Todd Fialaaf245d12014-06-30 21:05:18 +000049
Zachary Turner97206d52017-05-12 04:51:55 +000050 Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override;
Omair Javaidd5ffbad2017-02-24 13:27:31 +000051
Zachary Turner97206d52017-05-12 04:51:55 +000052 Status RemoveHardwareBreakpoint(lldb::addr_t addr) override;
Omair Javaidd5ffbad2017-02-24 13:27:31 +000053
Kate Stoneb9c1b512016-09-06 20:57:50 +000054private:
55 // ---------------------------------------------------------------------
56 // Interface for friend classes
57 // ---------------------------------------------------------------------
Todd Fialaaf245d12014-06-30 21:05:18 +000058
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 /// Resumes the thread. If @p signo is anything but
60 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
Zachary Turner97206d52017-05-12 04:51:55 +000061 Status Resume(uint32_t signo);
Pavel Labath605b51b2016-02-23 13:56:30 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 /// Single steps the thread. If @p signo is anything but
64 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
Zachary Turner97206d52017-05-12 04:51:55 +000065 Status SingleStep(uint32_t signo);
Todd Fialaaf245d12014-06-30 21:05:18 +000066
Kate Stoneb9c1b512016-09-06 20:57:50 +000067 void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
Todd Fialaaf245d12014-06-30 21:05:18 +000068
Kate Stoneb9c1b512016-09-06 20:57:50 +000069 /// Return true if the thread is stopped.
70 /// If stopped by a signal, indicate the signo in the signo argument.
71 /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.
72 bool IsStopped(int *signo);
Todd Fiala511e5cd2014-09-11 23:29:14 +000073
Kate Stoneb9c1b512016-09-06 20:57:50 +000074 void SetStoppedByExec();
Todd Fialaa9882ce2014-08-28 15:46:54 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 void SetStoppedByBreakpoint();
Todd Fialaaf245d12014-06-30 21:05:18 +000077
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 void SetStoppedByWatchpoint(uint32_t wp_index);
Chaoren Lin18fe6402015-02-03 01:51:47 +000079
Kate Stoneb9c1b512016-09-06 20:57:50 +000080 bool IsStoppedAtBreakpoint();
Todd Fialaaf245d12014-06-30 21:05:18 +000081
Kate Stoneb9c1b512016-09-06 20:57:50 +000082 bool IsStoppedAtWatchpoint();
Chaoren Lin18fe6402015-02-03 01:51:47 +000083
Kate Stoneb9c1b512016-09-06 20:57:50 +000084 void SetStoppedByTrace();
Chaoren Lin28e57422015-02-03 01:51:25 +000085
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 void SetStoppedWithNoReason();
Todd Fialaaf245d12014-06-30 21:05:18 +000087
Kate Stoneb9c1b512016-09-06 20:57:50 +000088 void SetExited();
Todd Fialaaf245d12014-06-30 21:05:18 +000089
Zachary Turner97206d52017-05-12 04:51:55 +000090 Status RequestStop();
Pavel Labath8c8ff7a2015-05-11 10:03:10 +000091
Kate Stoneb9c1b512016-09-06 20:57:50 +000092 // ---------------------------------------------------------------------
93 // Private interface
94 // ---------------------------------------------------------------------
95 void MaybeLogStateChange(lldb::StateType new_state);
Todd Fialaaf245d12014-06-30 21:05:18 +000096
Kate Stoneb9c1b512016-09-06 20:57:50 +000097 NativeProcessLinux &GetProcess();
Pavel Labath605b51b2016-02-23 13:56:30 +000098
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 void SetStopped();
Pavel Labath605b51b2016-02-23 13:56:30 +0000100
Kate Stoneb9c1b512016-09-06 20:57:50 +0000101 // ---------------------------------------------------------------------
102 // Member Variables
103 // ---------------------------------------------------------------------
104 lldb::StateType m_state;
105 ThreadStopInfo m_stop_info;
106 NativeRegisterContextSP m_reg_context_sp;
107 std::string m_stop_description;
108 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
109 WatchpointIndexMap m_watchpoint_index_map;
Omair Javaidd5ffbad2017-02-24 13:27:31 +0000110 WatchpointIndexMap m_hw_break_index_map;
Pavel Labath72784962017-02-16 18:12:04 +0000111 std::unique_ptr<SingleStepWorkaround> m_step_workaround;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000112};
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000113} // namespace process_linux
114} // namespace lldb_private
Todd Fialaaf245d12014-06-30 21:05:18 +0000115
116#endif // #ifndef liblldb_NativeThreadLinux_H_