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