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