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