blob: 66104c7332e7105357777aaca2fdc1f615903fe1 [file] [log] [blame]
Johnny Chen9ed5b492012-01-05 21:48:15 +00001//===-- POSIXThread.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_POSIXThread_H_
11#define liblldb_POSIXThread_H_
12
13// C Includes
14// C++ Includes
15#include <memory>
Matt Kopecfb6ab542013-07-10 20:53:11 +000016#include <string>
Johnny Chen9ed5b492012-01-05 21:48:15 +000017
18// Other libraries and framework includes
19#include "lldb/Target/Thread.h"
20#include "RegisterContextPOSIX.h"
21
22class ProcessMessage;
23class ProcessMonitor;
Michael Sartain2225ac72013-09-14 18:44:01 +000024class POSIXBreakpointProtocol;
Johnny Chen9ed5b492012-01-05 21:48:15 +000025
26//------------------------------------------------------------------------------
27// @class POSIXThread
Ed Masted66d3ec2013-06-25 14:29:15 +000028// @brief Abstraction of a POSIX thread.
Johnny Chen9ed5b492012-01-05 21:48:15 +000029class POSIXThread
30 : public lldb_private::Thread
31{
32public:
Greg Claytondf3df252012-10-12 16:23:23 +000033 POSIXThread(lldb_private::Process &process, lldb::tid_t tid);
Johnny Chen9ed5b492012-01-05 21:48:15 +000034
35 virtual ~POSIXThread();
36
37 void
38 RefreshStateAfterStop();
39
Greg Clayton160c9d82013-05-01 21:54:04 +000040 virtual void
Johnny Chen9ed5b492012-01-05 21:48:15 +000041 WillResume(lldb::StateType resume_state);
42
Andrew Kaylor93132f52013-05-28 23:04:25 +000043 // This notifies the thread when a private stop occurs.
44 virtual void
45 DidStop ();
46
Johnny Chen9ed5b492012-01-05 21:48:15 +000047 const char *
48 GetInfo();
49
Matt Kopecfb6ab542013-07-10 20:53:11 +000050 void
51 SetName (const char *name);
52
53 const char *
54 GetName ();
55
Johnny Chen9ed5b492012-01-05 21:48:15 +000056 virtual lldb::RegisterContextSP
57 GetRegisterContext();
58
59 virtual lldb::RegisterContextSP
60 CreateRegisterContextForFrame (lldb_private::StackFrame *frame);
61
62 //--------------------------------------------------------------------------
Ashok Thirumurthiacbb1a52013-05-09 19:59:47 +000063 // These functions provide a mapping from the register offset
Johnny Chen9ed5b492012-01-05 21:48:15 +000064 // back to the register index or name for use in debugging or log
65 // output.
66
Ashok Thirumurthiacbb1a52013-05-09 19:59:47 +000067 unsigned
Johnny Chen9ed5b492012-01-05 21:48:15 +000068 GetRegisterIndexFromOffset(unsigned offset);
69
Ashok Thirumurthiacbb1a52013-05-09 19:59:47 +000070 const char *
Johnny Chen9ed5b492012-01-05 21:48:15 +000071 GetRegisterName(unsigned reg);
72
Ashok Thirumurthiacbb1a52013-05-09 19:59:47 +000073 const char *
Johnny Chen9ed5b492012-01-05 21:48:15 +000074 GetRegisterNameFromOffset(unsigned offset);
75
76 //--------------------------------------------------------------------------
Ed Masted66d3ec2013-06-25 14:29:15 +000077 // These methods form a specialized interface to POSIX threads.
Johnny Chen9ed5b492012-01-05 21:48:15 +000078 //
79 bool Resume();
80
81 void Notify(const ProcessMessage &message);
82
Matt Kopece9ea0da2013-05-07 19:29:28 +000083 //--------------------------------------------------------------------------
84 // These methods provide an interface to watchpoints
85 //
86 bool EnableHardwareWatchpoint(lldb_private::Watchpoint *wp);
87
88 bool DisableHardwareWatchpoint(lldb_private::Watchpoint *wp);
89
90 uint32_t NumSupportedHardwareWatchpoints();
91
Matt Kopec6f961232013-06-03 17:40:20 +000092 uint32_t FindVacantWatchpointIndex();
93
Michael Sartain9f822cd2013-07-31 23:27:46 +000094protected:
Michael Sartain2225ac72013-09-14 18:44:01 +000095 POSIXBreakpointProtocol *
96 GetPOSIXBreakpointProtocol ()
Johnny Chen9ed5b492012-01-05 21:48:15 +000097 {
98 if (!m_reg_context_sp)
99 m_reg_context_sp = GetRegisterContext();
Michael Sartain2225ac72013-09-14 18:44:01 +0000100 return m_posix_thread;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000101 }
102
Greg Clayton7b0992d2013-04-18 22:45:39 +0000103 std::unique_ptr<lldb_private::StackFrame> m_frame_ap;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000104
105 lldb::BreakpointSiteSP m_breakpoint;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000106
Michael Sartain9f822cd2013-07-31 23:27:46 +0000107 bool m_thread_name_valid;
Matt Kopecfb6ab542013-07-10 20:53:11 +0000108 std::string m_thread_name;
Michael Sartain2225ac72013-09-14 18:44:01 +0000109 POSIXBreakpointProtocol *m_posix_thread;
Matt Kopecfb6ab542013-07-10 20:53:11 +0000110
Johnny Chen9ed5b492012-01-05 21:48:15 +0000111 ProcessMonitor &
112 GetMonitor();
113
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000114 virtual bool
115 CalculateStopInfo();
Johnny Chen9ed5b492012-01-05 21:48:15 +0000116
117 void BreakNotify(const ProcessMessage &message);
Matt Kopece9ea0da2013-05-07 19:29:28 +0000118 void WatchNotify(const ProcessMessage &message);
Michael Sartain9f822cd2013-07-31 23:27:46 +0000119 virtual void TraceNotify(const ProcessMessage &message);
Johnny Chen9ed5b492012-01-05 21:48:15 +0000120 void LimboNotify(const ProcessMessage &message);
121 void SignalNotify(const ProcessMessage &message);
122 void SignalDeliveredNotify(const ProcessMessage &message);
123 void CrashNotify(const ProcessMessage &message);
Matt Kopec650648f2013-01-08 16:30:18 +0000124 void ThreadNotify(const ProcessMessage &message);
Andrew Kaylor93132f52013-05-28 23:04:25 +0000125 void ExitNotify(const ProcessMessage &message);
Johnny Chen9ed5b492012-01-05 21:48:15 +0000126
127 lldb_private::Unwind *
128 GetUnwinder();
129};
130
131#endif // #ifndef liblldb_POSIXThread_H_