blob: 51d6645f209d8a8157057fa60340343099eed3bb [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
Richard Mitton0a558352013-10-17 21:14:00 +000062 virtual lldb::addr_t
63 GetThreadPointer ();
64
Johnny Chen9ed5b492012-01-05 21:48:15 +000065 //--------------------------------------------------------------------------
Ashok Thirumurthiacbb1a52013-05-09 19:59:47 +000066 // These functions provide a mapping from the register offset
Johnny Chen9ed5b492012-01-05 21:48:15 +000067 // back to the register index or name for use in debugging or log
68 // output.
69
Ashok Thirumurthiacbb1a52013-05-09 19:59:47 +000070 unsigned
Johnny Chen9ed5b492012-01-05 21:48:15 +000071 GetRegisterIndexFromOffset(unsigned offset);
72
Ashok Thirumurthiacbb1a52013-05-09 19:59:47 +000073 const char *
Johnny Chen9ed5b492012-01-05 21:48:15 +000074 GetRegisterName(unsigned reg);
75
Ashok Thirumurthiacbb1a52013-05-09 19:59:47 +000076 const char *
Johnny Chen9ed5b492012-01-05 21:48:15 +000077 GetRegisterNameFromOffset(unsigned offset);
78
79 //--------------------------------------------------------------------------
Ed Masted66d3ec2013-06-25 14:29:15 +000080 // These methods form a specialized interface to POSIX threads.
Johnny Chen9ed5b492012-01-05 21:48:15 +000081 //
Ed Maste30df85e2013-12-11 20:43:27 +000082 bool Resume();
83
Johnny Chen9ed5b492012-01-05 21:48:15 +000084 void Notify(const ProcessMessage &message);
85
Matt Kopece9ea0da2013-05-07 19:29:28 +000086 //--------------------------------------------------------------------------
87 // These methods provide an interface to watchpoints
88 //
89 bool EnableHardwareWatchpoint(lldb_private::Watchpoint *wp);
90
91 bool DisableHardwareWatchpoint(lldb_private::Watchpoint *wp);
92
93 uint32_t NumSupportedHardwareWatchpoints();
94
Matt Kopec6f961232013-06-03 17:40:20 +000095 uint32_t FindVacantWatchpointIndex();
96
Michael Sartain9f822cd2013-07-31 23:27:46 +000097protected:
Michael Sartain2225ac72013-09-14 18:44:01 +000098 POSIXBreakpointProtocol *
99 GetPOSIXBreakpointProtocol ()
Johnny Chen9ed5b492012-01-05 21:48:15 +0000100 {
101 if (!m_reg_context_sp)
102 m_reg_context_sp = GetRegisterContext();
Michael Sartain2225ac72013-09-14 18:44:01 +0000103 return m_posix_thread;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000104 }
105
Greg Clayton7b0992d2013-04-18 22:45:39 +0000106 std::unique_ptr<lldb_private::StackFrame> m_frame_ap;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000107
108 lldb::BreakpointSiteSP m_breakpoint;
Johnny Chen9ed5b492012-01-05 21:48:15 +0000109
Michael Sartain9f822cd2013-07-31 23:27:46 +0000110 bool m_thread_name_valid;
Matt Kopecfb6ab542013-07-10 20:53:11 +0000111 std::string m_thread_name;
Michael Sartain2225ac72013-09-14 18:44:01 +0000112 POSIXBreakpointProtocol *m_posix_thread;
Matt Kopecfb6ab542013-07-10 20:53:11 +0000113
Johnny Chen9ed5b492012-01-05 21:48:15 +0000114 ProcessMonitor &
115 GetMonitor();
116
Greg Clayton6e0ff1a2013-05-09 01:55:29 +0000117 virtual bool
118 CalculateStopInfo();
Johnny Chen9ed5b492012-01-05 21:48:15 +0000119
120 void BreakNotify(const ProcessMessage &message);
Matt Kopece9ea0da2013-05-07 19:29:28 +0000121 void WatchNotify(const ProcessMessage &message);
Michael Sartain9f822cd2013-07-31 23:27:46 +0000122 virtual void TraceNotify(const ProcessMessage &message);
Johnny Chen9ed5b492012-01-05 21:48:15 +0000123 void LimboNotify(const ProcessMessage &message);
124 void SignalNotify(const ProcessMessage &message);
125 void SignalDeliveredNotify(const ProcessMessage &message);
126 void CrashNotify(const ProcessMessage &message);
Matt Kopec650648f2013-01-08 16:30:18 +0000127 void ThreadNotify(const ProcessMessage &message);
Andrew Kaylor93132f52013-05-28 23:04:25 +0000128 void ExitNotify(const ProcessMessage &message);
Matt Kopec718be872013-10-09 19:39:55 +0000129 void ExecNotify(const ProcessMessage &message);
Johnny Chen9ed5b492012-01-05 21:48:15 +0000130
131 lldb_private::Unwind *
132 GetUnwinder();
133};
134
135#endif // #ifndef liblldb_POSIXThread_H_