blob: b9126b3752a06a3f8fc6b78fd4144dbe615c6574 [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
Chaoren Lin18fe6402015-02-03 01:51:47 +000017#include <map>
Pavel Labath0e1d7292015-08-20 09:06:12 +000018#include <memory>
Richard Smith7572caf2015-03-22 23:18:46 +000019#include <string>
Chaoren Lin18fe6402015-02-03 01:51:47 +000020
Tamas Berghammerdb264a62015-03-31 09:52:22 +000021namespace lldb_private {
22namespace process_linux {
23
Kate Stoneb9c1b512016-09-06 20:57:50 +000024class NativeProcessLinux;
Todd Fialaaf245d12014-06-30 21:05:18 +000025
Kate Stoneb9c1b512016-09-06 20:57:50 +000026class NativeThreadLinux : public NativeThreadProtocol {
27 friend class NativeProcessLinux;
Todd Fialaaf245d12014-06-30 21:05:18 +000028
Kate Stoneb9c1b512016-09-06 20:57:50 +000029public:
30 NativeThreadLinux(NativeProcessLinux *process, lldb::tid_t tid);
Todd Fialaaf245d12014-06-30 21:05:18 +000031
Kate Stoneb9c1b512016-09-06 20:57:50 +000032 // ---------------------------------------------------------------------
33 // NativeThreadProtocol Interface
34 // ---------------------------------------------------------------------
35 std::string GetName() override;
Todd Fialaaf245d12014-06-30 21:05:18 +000036
Kate Stoneb9c1b512016-09-06 20:57:50 +000037 lldb::StateType GetState() override;
Todd Fialaaf245d12014-06-30 21:05:18 +000038
Kate Stoneb9c1b512016-09-06 20:57:50 +000039 bool GetStopReason(ThreadStopInfo &stop_info,
40 std::string &description) override;
Todd Fialaaf245d12014-06-30 21:05:18 +000041
Kate Stoneb9c1b512016-09-06 20:57:50 +000042 NativeRegisterContextSP GetRegisterContext() override;
Todd Fialaaf245d12014-06-30 21:05:18 +000043
Zachary Turner97206d52017-05-12 04:51:55 +000044 Status SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags,
45 bool hardware) override;
Todd Fialaaf245d12014-06-30 21:05:18 +000046
Zachary Turner97206d52017-05-12 04:51:55 +000047 Status RemoveWatchpoint(lldb::addr_t addr) override;
Todd Fialaaf245d12014-06-30 21:05:18 +000048
Zachary Turner97206d52017-05-12 04:51:55 +000049 Status SetHardwareBreakpoint(lldb::addr_t addr, size_t size) override;
Omair Javaidd5ffbad2017-02-24 13:27:31 +000050
Zachary Turner97206d52017-05-12 04:51:55 +000051 Status RemoveHardwareBreakpoint(lldb::addr_t addr) override;
Omair Javaidd5ffbad2017-02-24 13:27:31 +000052
Kate Stoneb9c1b512016-09-06 20:57:50 +000053private:
54 // ---------------------------------------------------------------------
55 // Interface for friend classes
56 // ---------------------------------------------------------------------
Todd Fialaaf245d12014-06-30 21:05:18 +000057
Kate Stoneb9c1b512016-09-06 20:57:50 +000058 /// Resumes the thread. If @p signo is anything but
59 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
Zachary Turner97206d52017-05-12 04:51:55 +000060 Status Resume(uint32_t signo);
Pavel Labath605b51b2016-02-23 13:56:30 +000061
Kate Stoneb9c1b512016-09-06 20:57:50 +000062 /// Single steps the thread. If @p signo is anything but
63 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
Zachary Turner97206d52017-05-12 04:51:55 +000064 Status SingleStep(uint32_t signo);
Todd Fialaaf245d12014-06-30 21:05:18 +000065
Kate Stoneb9c1b512016-09-06 20:57:50 +000066 void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
Todd Fialaaf245d12014-06-30 21:05:18 +000067
Kate Stoneb9c1b512016-09-06 20:57:50 +000068 /// Return true if the thread is stopped.
69 /// If stopped by a signal, indicate the signo in the signo argument.
70 /// Otherwise, return LLDB_INVALID_SIGNAL_NUMBER.
71 bool IsStopped(int *signo);
Todd Fiala511e5cd2014-09-11 23:29:14 +000072
Kate Stoneb9c1b512016-09-06 20:57:50 +000073 void SetStoppedByExec();
Todd Fialaa9882ce2014-08-28 15:46:54 +000074
Kate Stoneb9c1b512016-09-06 20:57:50 +000075 void SetStoppedByBreakpoint();
Todd Fialaaf245d12014-06-30 21:05:18 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 void SetStoppedByWatchpoint(uint32_t wp_index);
Chaoren Lin18fe6402015-02-03 01:51:47 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 bool IsStoppedAtBreakpoint();
Todd Fialaaf245d12014-06-30 21:05:18 +000080
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 bool IsStoppedAtWatchpoint();
Chaoren Lin18fe6402015-02-03 01:51:47 +000082
Kate Stoneb9c1b512016-09-06 20:57:50 +000083 void SetStoppedByTrace();
Chaoren Lin28e57422015-02-03 01:51:25 +000084
Kate Stoneb9c1b512016-09-06 20:57:50 +000085 void SetStoppedWithNoReason();
Todd Fialaaf245d12014-06-30 21:05:18 +000086
Kate Stoneb9c1b512016-09-06 20:57:50 +000087 void SetExited();
Todd Fialaaf245d12014-06-30 21:05:18 +000088
Zachary Turner97206d52017-05-12 04:51:55 +000089 Status RequestStop();
Pavel Labath8c8ff7a2015-05-11 10:03:10 +000090
Kate Stoneb9c1b512016-09-06 20:57:50 +000091 // ---------------------------------------------------------------------
92 // Private interface
93 // ---------------------------------------------------------------------
94 void MaybeLogStateChange(lldb::StateType new_state);
Todd Fialaaf245d12014-06-30 21:05:18 +000095
Kate Stoneb9c1b512016-09-06 20:57:50 +000096 NativeProcessLinux &GetProcess();
Pavel Labath605b51b2016-02-23 13:56:30 +000097
Kate Stoneb9c1b512016-09-06 20:57:50 +000098 void SetStopped();
Pavel Labath605b51b2016-02-23 13:56:30 +000099
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 // ---------------------------------------------------------------------
101 // Member Variables
102 // ---------------------------------------------------------------------
103 lldb::StateType m_state;
104 ThreadStopInfo m_stop_info;
105 NativeRegisterContextSP m_reg_context_sp;
106 std::string m_stop_description;
107 using WatchpointIndexMap = std::map<lldb::addr_t, uint32_t>;
108 WatchpointIndexMap m_watchpoint_index_map;
Omair Javaidd5ffbad2017-02-24 13:27:31 +0000109 WatchpointIndexMap m_hw_break_index_map;
Pavel Labath72784962017-02-16 18:12:04 +0000110 std::unique_ptr<SingleStepWorkaround> m_step_workaround;
Kate Stoneb9c1b512016-09-06 20:57:50 +0000111};
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000112
Kate Stoneb9c1b512016-09-06 20:57:50 +0000113typedef std::shared_ptr<NativeThreadLinux> NativeThreadLinuxSP;
Tamas Berghammerdb264a62015-03-31 09:52:22 +0000114} // namespace process_linux
115} // namespace lldb_private
Todd Fialaaf245d12014-06-30 21:05:18 +0000116
117#endif // #ifndef liblldb_NativeThreadLinux_H_