blob: a8559fe8b2ca9fefd4cb5d65c1f5bdb0e48b653c [file] [log] [blame]
Ed Maste7fd845c2013-12-09 15:51:17 +00001//===-- FreeBSDThread.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_FreeBSDThread_H_
11#define liblldb_FreeBSDThread_H_
12
Ed Mastefe5a6422015-07-28 15:45:57 +000013#include <memory>
14#include <string>
15
Ed Maste1b3f13d2015-09-14 14:20:56 +000016#include "RegisterContextPOSIX.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000017#include "lldb/Target/Thread.h"
Ed Mastefe5a6422015-07-28 15:45:57 +000018
19class ProcessMessage;
20class ProcessMonitor;
21class POSIXBreakpointProtocol;
Ed Maste7fd845c2013-12-09 15:51:17 +000022
23//------------------------------------------------------------------------------
24// @class FreeBSDThread
Adrian Prantld8f460e2018-05-02 16:55:16 +000025// Abstraction of a FreeBSD thread.
Kate Stoneb9c1b512016-09-06 20:57:50 +000026class FreeBSDThread : public lldb_private::Thread {
Ed Maste7fd845c2013-12-09 15:51:17 +000027public:
Kate Stoneb9c1b512016-09-06 20:57:50 +000028 //------------------------------------------------------------------
29 // Constructors and destructors
30 //------------------------------------------------------------------
31 FreeBSDThread(lldb_private::Process &process, lldb::tid_t tid);
Ed Maste7fd845c2013-12-09 15:51:17 +000032
Kate Stoneb9c1b512016-09-06 20:57:50 +000033 virtual ~FreeBSDThread();
Ed Maste7fd845c2013-12-09 15:51:17 +000034
Kate Stoneb9c1b512016-09-06 20:57:50 +000035 // POSIXThread
36 void RefreshStateAfterStop() override;
Ed Maste7fd845c2013-12-09 15:51:17 +000037
Kate Stoneb9c1b512016-09-06 20:57:50 +000038 // This notifies the thread when a private stop occurs.
39 void DidStop() override;
Ed Mastefe5a6422015-07-28 15:45:57 +000040
Kate Stoneb9c1b512016-09-06 20:57:50 +000041 const char *GetInfo() override;
Ed Mastefe5a6422015-07-28 15:45:57 +000042
Kate Stoneb9c1b512016-09-06 20:57:50 +000043 void SetName(const char *name) override;
Ed Mastefe5a6422015-07-28 15:45:57 +000044
Kate Stoneb9c1b512016-09-06 20:57:50 +000045 const char *GetName() override;
Ed Mastefe5a6422015-07-28 15:45:57 +000046
Kate Stoneb9c1b512016-09-06 20:57:50 +000047 lldb::RegisterContextSP GetRegisterContext() override;
Ed Mastefe5a6422015-07-28 15:45:57 +000048
Kate Stoneb9c1b512016-09-06 20:57:50 +000049 lldb::RegisterContextSP
50 CreateRegisterContextForFrame(lldb_private::StackFrame *frame) override;
Ed Mastefe5a6422015-07-28 15:45:57 +000051
Kate Stoneb9c1b512016-09-06 20:57:50 +000052 lldb::addr_t GetThreadPointer() override;
Ed Mastefe5a6422015-07-28 15:45:57 +000053
Kate Stoneb9c1b512016-09-06 20:57:50 +000054 //--------------------------------------------------------------------------
55 // These functions provide a mapping from the register offset
56 // back to the register index or name for use in debugging or log
57 // output.
Ed Mastefe5a6422015-07-28 15:45:57 +000058
Kate Stoneb9c1b512016-09-06 20:57:50 +000059 unsigned GetRegisterIndexFromOffset(unsigned offset);
Ed Mastefe5a6422015-07-28 15:45:57 +000060
Kate Stoneb9c1b512016-09-06 20:57:50 +000061 const char *GetRegisterName(unsigned reg);
Ed Mastefe5a6422015-07-28 15:45:57 +000062
Kate Stoneb9c1b512016-09-06 20:57:50 +000063 const char *GetRegisterNameFromOffset(unsigned offset);
Ed Mastefe5a6422015-07-28 15:45:57 +000064
Kate Stoneb9c1b512016-09-06 20:57:50 +000065 //--------------------------------------------------------------------------
66 // These methods form a specialized interface to POSIX threads.
67 //
68 bool Resume();
Ed Mastefe5a6422015-07-28 15:45:57 +000069
Kate Stoneb9c1b512016-09-06 20:57:50 +000070 void Notify(const ProcessMessage &message);
Ed Mastefe5a6422015-07-28 15:45:57 +000071
Kate Stoneb9c1b512016-09-06 20:57:50 +000072 //--------------------------------------------------------------------------
73 // These methods provide an interface to watchpoints
74 //
75 bool EnableHardwareWatchpoint(lldb_private::Watchpoint *wp);
Ed Mastefe5a6422015-07-28 15:45:57 +000076
Kate Stoneb9c1b512016-09-06 20:57:50 +000077 bool DisableHardwareWatchpoint(lldb_private::Watchpoint *wp);
Ed Mastefe5a6422015-07-28 15:45:57 +000078
Kate Stoneb9c1b512016-09-06 20:57:50 +000079 uint32_t NumSupportedHardwareWatchpoints();
Ed Mastefe5a6422015-07-28 15:45:57 +000080
Kate Stoneb9c1b512016-09-06 20:57:50 +000081 uint32_t FindVacantWatchpointIndex();
Ed Mastefe5a6422015-07-28 15:45:57 +000082
83protected:
Kate Stoneb9c1b512016-09-06 20:57:50 +000084 POSIXBreakpointProtocol *GetPOSIXBreakpointProtocol() {
85 if (!m_reg_context_sp)
86 m_reg_context_sp = GetRegisterContext();
87 return m_posix_thread;
88 }
Ed Mastefe5a6422015-07-28 15:45:57 +000089
Kate Stoneb9c1b512016-09-06 20:57:50 +000090 std::unique_ptr<lldb_private::StackFrame> m_frame_ap;
Ed Mastefe5a6422015-07-28 15:45:57 +000091
Kate Stoneb9c1b512016-09-06 20:57:50 +000092 lldb::BreakpointSiteSP m_breakpoint;
Ed Mastefe5a6422015-07-28 15:45:57 +000093
Kate Stoneb9c1b512016-09-06 20:57:50 +000094 bool m_thread_name_valid;
95 std::string m_thread_name;
96 POSIXBreakpointProtocol *m_posix_thread;
Ed Mastefe5a6422015-07-28 15:45:57 +000097
Kate Stoneb9c1b512016-09-06 20:57:50 +000098 ProcessMonitor &GetMonitor();
Ed Mastefe5a6422015-07-28 15:45:57 +000099
Kate Stoneb9c1b512016-09-06 20:57:50 +0000100 bool CalculateStopInfo() override;
Ed Mastefe5a6422015-07-28 15:45:57 +0000101
Kate Stoneb9c1b512016-09-06 20:57:50 +0000102 void BreakNotify(const ProcessMessage &message);
103 void WatchNotify(const ProcessMessage &message);
104 virtual void TraceNotify(const ProcessMessage &message);
105 void LimboNotify(const ProcessMessage &message);
106 void SignalNotify(const ProcessMessage &message);
107 void SignalDeliveredNotify(const ProcessMessage &message);
108 void CrashNotify(const ProcessMessage &message);
109 void ExitNotify(const ProcessMessage &message);
110 void ExecNotify(const ProcessMessage &message);
Ed Mastefe5a6422015-07-28 15:45:57 +0000111
Kate Stoneb9c1b512016-09-06 20:57:50 +0000112 lldb_private::Unwind *GetUnwinder() override;
Ed Maste7fd845c2013-12-09 15:51:17 +0000113
Kate Stoneb9c1b512016-09-06 20:57:50 +0000114 //--------------------------------------------------------------------------
115 // FreeBSDThread internal API.
116
117 // POSIXThread override
118 virtual void WillResume(lldb::StateType resume_state) override;
Ed Maste7fd845c2013-12-09 15:51:17 +0000119};
120
121#endif // #ifndef liblldb_FreeBSDThread_H_