Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 1 | //===-- LinuxThread.cpp -----------------------------------------*- 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 | #include <errno.h> |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | #include "lldb/Target/Process.h" |
Stephen Wilson | c8c74e0 | 2011-01-04 21:43:19 +0000 | [diff] [blame] | 16 | #include "lldb/Target/StopInfo.h" |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 17 | #include "lldb/Target/Target.h" |
| 18 | |
| 19 | #include "LinuxThread.h" |
| 20 | #include "ProcessLinux.h" |
| 21 | #include "ProcessMonitor.h" |
| 22 | #include "RegisterContextLinux_x86_64.h" |
| 23 | |
| 24 | using namespace lldb_private; |
| 25 | |
| 26 | LinuxThread::LinuxThread(Process &process, lldb::tid_t tid) |
| 27 | : Thread(process, tid), |
| 28 | m_frame_ap(0), |
Stephen Wilson | 140f69a | 2011-01-15 00:07:36 +0000 | [diff] [blame] | 29 | m_stop_info_id(0), |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 30 | m_note(eNone) |
| 31 | { |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | ProcessMonitor & |
| 35 | LinuxThread::GetMonitor() |
| 36 | { |
Stephen Wilson | bc1418b | 2011-01-07 00:10:43 +0000 | [diff] [blame] | 37 | ProcessLinux &process = static_cast<ProcessLinux&>(GetProcess()); |
| 38 | return process.GetMonitor(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void |
| 42 | LinuxThread::RefreshStateAfterStop() |
| 43 | { |
Stephen Wilson | 140f69a | 2011-01-15 00:07:36 +0000 | [diff] [blame] | 44 | RefreshPrivateStopReason(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | const char * |
| 48 | LinuxThread::GetInfo() |
| 49 | { |
| 50 | return NULL; |
| 51 | } |
| 52 | |
Greg Clayton | 90ccf88 | 2011-01-06 22:35:55 +0000 | [diff] [blame] | 53 | lldb::RegisterContextSP |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 54 | LinuxThread::GetRegisterContext() |
| 55 | { |
Stephen Wilson | bc1418b | 2011-01-07 00:10:43 +0000 | [diff] [blame] | 56 | ProcessLinux &process = static_cast<ProcessLinux&>(GetProcess()); |
| 57 | |
Greg Clayton | 90ccf88 | 2011-01-06 22:35:55 +0000 | [diff] [blame] | 58 | if (!m_reg_context_sp) |
| 59 | { |
| 60 | ArchSpec arch = process.GetTarget().GetArchitecture(); |
| 61 | |
| 62 | switch (arch.GetGenericCPUType()) |
| 63 | { |
| 64 | default: |
| 65 | assert(false && "CPU type not supported!"); |
| 66 | break; |
| 67 | |
| 68 | case ArchSpec::eCPU_x86_64: |
| 69 | m_reg_context_sp.reset(new RegisterContextLinux_x86_64(*this, 0)); |
| 70 | break; |
| 71 | } |
| 72 | } |
Stephen Wilson | bc1418b | 2011-01-07 00:10:43 +0000 | [diff] [blame] | 73 | return m_reg_context_sp; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | bool |
| 77 | LinuxThread::SaveFrameZeroState(RegisterCheckpoint &checkpoint) |
| 78 | { |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | bool |
| 83 | LinuxThread::RestoreSaveFrameZero(const RegisterCheckpoint &checkpoint) |
| 84 | { |
| 85 | return false; |
| 86 | } |
| 87 | |
Greg Clayton | 90ccf88 | 2011-01-06 22:35:55 +0000 | [diff] [blame] | 88 | lldb::RegisterContextSP |
| 89 | LinuxThread::CreateRegisterContextForFrame (lldb_private::StackFrame *frame) |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 90 | { |
Greg Clayton | 90ccf88 | 2011-01-06 22:35:55 +0000 | [diff] [blame] | 91 | lldb::RegisterContextSP reg_ctx_sp; |
| 92 | uint32_t concrete_frame_idx = 0; |
| 93 | if (frame) |
| 94 | concrete_frame_idx = frame->GetConcreteFrameIndex(); |
| 95 | |
| 96 | if (concrete_frame_idx == 0) |
| 97 | reg_ctx_sp = GetRegisterContext(); |
| 98 | else |
| 99 | reg_ctx_sp.reset (new RegisterContextLinux_x86_64(*this, frame->GetConcreteFrameIndex())); |
| 100 | return reg_ctx_sp; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Stephen Wilson | ed56002 | 2011-01-04 21:45:02 +0000 | [diff] [blame] | 103 | lldb::StopInfoSP |
| 104 | LinuxThread::GetPrivateStopReason() |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 105 | { |
Stephen Wilson | 140f69a | 2011-01-15 00:07:36 +0000 | [diff] [blame] | 106 | const uint32_t process_stop_id = GetProcess().GetStopID(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 107 | |
Stephen Wilson | 140f69a | 2011-01-15 00:07:36 +0000 | [diff] [blame] | 108 | if (m_stop_info_id != process_stop_id || !m_stop_info || !m_stop_info->IsValid()) |
| 109 | RefreshPrivateStopReason(); |
| 110 | return m_stop_info; |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Stephen Wilson | d61182d | 2011-01-04 21:45:57 +0000 | [diff] [blame] | 113 | Unwind * |
| 114 | LinuxThread::GetUnwinder() |
| 115 | { |
| 116 | return m_unwinder_ap.get(); |
| 117 | } |
| 118 | |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 119 | bool |
| 120 | LinuxThread::WillResume(lldb::StateType resume_state) |
| 121 | { |
| 122 | SetResumeState(resume_state); |
| 123 | return Thread::WillResume(resume_state); |
| 124 | } |
| 125 | |
| 126 | bool |
| 127 | LinuxThread::Resume() |
| 128 | { |
| 129 | lldb::StateType resume_state = GetResumeState(); |
| 130 | ProcessMonitor &monitor = GetMonitor(); |
| 131 | bool status; |
| 132 | |
| 133 | switch (GetResumeState()) |
| 134 | { |
| 135 | default: |
| 136 | assert(false && "Unexpected state for resume!"); |
| 137 | status = false; |
| 138 | break; |
| 139 | |
| 140 | case lldb::eStateSuspended: |
| 141 | // FIXME: Implement process suspension. |
| 142 | status = false; |
| 143 | |
| 144 | case lldb::eStateRunning: |
| 145 | SetState(resume_state); |
| 146 | status = monitor.Resume(GetID()); |
| 147 | break; |
| 148 | |
| 149 | case lldb::eStateStepping: |
| 150 | SetState(resume_state); |
| 151 | status = GetRegisterContext()->HardwareSingleStep(true); |
| 152 | break; |
| 153 | } |
| 154 | |
| 155 | m_note = eNone; |
| 156 | return status; |
| 157 | } |
| 158 | |
| 159 | void |
| 160 | LinuxThread::BreakNotify() |
| 161 | { |
| 162 | bool status; |
| 163 | |
Greg Clayton | 90ccf88 | 2011-01-06 22:35:55 +0000 | [diff] [blame] | 164 | status = GetRegisterContextLinux()->UpdateAfterBreakpoint(); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 165 | assert(status && "Breakpoint update failed!"); |
| 166 | |
| 167 | // With our register state restored, resolve the breakpoint object |
| 168 | // corresponding to our current PC. |
| 169 | lldb::addr_t pc = GetRegisterContext()->GetPC(); |
Greg Clayton | 90ccf88 | 2011-01-06 22:35:55 +0000 | [diff] [blame] | 170 | lldb::BreakpointSiteSP bp_site(GetProcess().GetBreakpointSiteList().FindByAddress(pc)); |
Stephen Wilson | f6f4033 | 2010-07-24 02:19:04 +0000 | [diff] [blame] | 171 | assert(bp_site && bp_site->ValidForThisThread(this)); |
| 172 | |
| 173 | m_note = eBreak; |
| 174 | m_breakpoint = bp_site; |
| 175 | } |
| 176 | |
| 177 | void |
| 178 | LinuxThread::TraceNotify() |
| 179 | { |
| 180 | m_note = eTrace; |
| 181 | } |
| 182 | |
| 183 | void |
| 184 | LinuxThread::ExitNotify() |
| 185 | { |
| 186 | m_note = eExit; |
| 187 | } |
Stephen Wilson | 140f69a | 2011-01-15 00:07:36 +0000 | [diff] [blame] | 188 | |
| 189 | void |
| 190 | LinuxThread::RefreshPrivateStopReason() |
| 191 | { |
| 192 | m_stop_info_id = GetProcess().GetStopID(); |
| 193 | |
| 194 | switch (m_note) { |
| 195 | |
| 196 | default: |
| 197 | case eNone: |
| 198 | m_stop_info.reset(); |
| 199 | break; |
| 200 | |
| 201 | case eBreak: |
| 202 | m_stop_info = StopInfo::CreateStopReasonWithBreakpointSiteID( |
| 203 | *this, m_breakpoint->GetID()); |
| 204 | break; |
| 205 | |
| 206 | case eTrace: |
| 207 | m_stop_info = StopInfo::CreateStopReasonToTrace(*this); |
| 208 | break; |
| 209 | |
| 210 | case eExit: |
| 211 | m_stop_info = StopInfo::CreateStopReasonWithSignal(*this, SIGCHLD); |
| 212 | break; |
| 213 | } |
| 214 | } |