blob: f170bb1e8508424069a3a54f94bfe99d83d3860e [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
Chaoren Lin2fe1d0a2015-02-03 01:51:38 +000013#include "lldb/Host/common/NativeThreadProtocol.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000014#include "lldb/lldb-private-forward.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
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:
31 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
Kate Stoneb9c1b512016-09-06 20:57:50 +000045 Error SetWatchpoint(lldb::addr_t addr, size_t size, uint32_t watch_flags,
46 bool hardware) override;
Todd Fialaaf245d12014-06-30 21:05:18 +000047
Kate Stoneb9c1b512016-09-06 20:57:50 +000048 Error RemoveWatchpoint(lldb::addr_t addr) override;
Todd Fialaaf245d12014-06-30 21:05:18 +000049
Kate Stoneb9c1b512016-09-06 20:57:50 +000050private:
51 // ---------------------------------------------------------------------
52 // Interface for friend classes
53 // ---------------------------------------------------------------------
Todd Fialaaf245d12014-06-30 21:05:18 +000054
Kate Stoneb9c1b512016-09-06 20:57:50 +000055 /// Resumes the thread. If @p signo is anything but
56 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
57 Error Resume(uint32_t signo);
Pavel Labath605b51b2016-02-23 13:56:30 +000058
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 /// Single steps the thread. If @p signo is anything but
60 /// LLDB_INVALID_SIGNAL_NUMBER, deliver that signal to the thread.
61 Error SingleStep(uint32_t signo);
Todd Fialaaf245d12014-06-30 21:05:18 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 void SetStoppedBySignal(uint32_t signo, const siginfo_t *info = nullptr);
Todd Fialaaf245d12014-06-30 21:05:18 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +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 IsStopped(int *signo);
Todd Fiala511e5cd2014-09-11 23:29:14 +000069
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 void SetStoppedByExec();
Todd Fialaa9882ce2014-08-28 15:46:54 +000071
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 void SetStoppedByBreakpoint();
Todd Fialaaf245d12014-06-30 21:05:18 +000073
Kate Stoneb9c1b512016-09-06 20:57:50 +000074 void SetStoppedByWatchpoint(uint32_t wp_index);
Chaoren Lin18fe6402015-02-03 01:51:47 +000075
Kate Stoneb9c1b512016-09-06 20:57:50 +000076 bool IsStoppedAtBreakpoint();
Todd Fialaaf245d12014-06-30 21:05:18 +000077
Kate Stoneb9c1b512016-09-06 20:57:50 +000078 bool IsStoppedAtWatchpoint();
Chaoren Lin18fe6402015-02-03 01:51:47 +000079
Kate Stoneb9c1b512016-09-06 20:57:50 +000080 void SetStoppedByTrace();
Chaoren Lin28e57422015-02-03 01:51:25 +000081
Kate Stoneb9c1b512016-09-06 20:57:50 +000082 void SetStoppedWithNoReason();
Todd Fialaaf245d12014-06-30 21:05:18 +000083
Kate Stoneb9c1b512016-09-06 20:57:50 +000084 void SetExited();
Todd Fialaaf245d12014-06-30 21:05:18 +000085
Kate Stoneb9c1b512016-09-06 20:57:50 +000086 Error RequestStop();
Pavel Labath8c8ff7a2015-05-11 10:03:10 +000087
Kate Stoneb9c1b512016-09-06 20:57:50 +000088 // ---------------------------------------------------------------------
89 // Private interface
90 // ---------------------------------------------------------------------
91 void MaybeLogStateChange(lldb::StateType new_state);
Todd Fialaaf245d12014-06-30 21:05:18 +000092
Kate Stoneb9c1b512016-09-06 20:57:50 +000093 NativeProcessLinux &GetProcess();
Pavel Labath605b51b2016-02-23 13:56:30 +000094
Kate Stoneb9c1b512016-09-06 20:57:50 +000095 void SetStopped();
Pavel Labath605b51b2016-02-23 13:56:30 +000096
Kate Stoneb9c1b512016-09-06 20:57:50 +000097 inline void MaybePrepareSingleStepWorkaround();
Pavel Labath605b51b2016-02-23 13:56:30 +000098
Kate Stoneb9c1b512016-09-06 20:57:50 +000099 inline void MaybeCleanupSingleStepWorkaround();
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;
110 cpu_set_t m_original_cpu_set; // For single-step workaround.
111};
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_