1 //===-- NativeThreadProtocol.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 "lldb/Host/common/NativeThreadProtocol.h" 11 12 #include "lldb/Host/common/NativeProcessProtocol.h" 13 #include "lldb/Host/common/NativeRegisterContext.h" 14 #include "lldb/Host/common/SoftwareBreakpoint.h" 15 16 using namespace lldb; 17 using namespace lldb_private; 18 19 NativeThreadProtocol::NativeThreadProtocol (NativeProcessProtocol *process, lldb::tid_t tid) : 20 m_process_wp (process->shared_from_this ()), 21 m_tid (tid) 22 { 23 } 24 25 Error 26 NativeThreadProtocol::ReadRegister (uint32_t reg, RegisterValue ®_value) 27 { 28 NativeRegisterContextSP register_context_sp = GetRegisterContext (); 29 if (!register_context_sp) 30 return Error ("no register context"); 31 32 const RegisterInfo *const reg_info = register_context_sp->GetRegisterInfoAtIndex (reg); 33 if (!reg_info) 34 return Error ("no register info for reg num %" PRIu32, reg); 35 36 return register_context_sp->ReadRegister (reg_info, reg_value);; 37 } 38 39 Error 40 NativeThreadProtocol::WriteRegister (uint32_t reg, const RegisterValue ®_value) 41 { 42 NativeRegisterContextSP register_context_sp = GetRegisterContext (); 43 if (!register_context_sp) 44 return Error ("no register context"); 45 46 const RegisterInfo *const reg_info = register_context_sp->GetRegisterInfoAtIndex (reg); 47 if (!reg_info) 48 return Error ("no register info for reg num %" PRIu32, reg); 49 50 return register_context_sp->WriteRegister (reg_info, reg_value); 51 } 52 53 Error 54 NativeThreadProtocol::SaveAllRegisters (lldb::DataBufferSP &data_sp) 55 { 56 NativeRegisterContextSP register_context_sp = GetRegisterContext (); 57 if (!register_context_sp) 58 return Error ("no register context"); 59 return register_context_sp->WriteAllRegisterValues (data_sp); 60 } 61 62 Error 63 NativeThreadProtocol::RestoreAllRegisters (lldb::DataBufferSP &data_sp) 64 { 65 NativeRegisterContextSP register_context_sp = GetRegisterContext (); 66 if (!register_context_sp) 67 return Error ("no register context"); 68 return register_context_sp->ReadAllRegisterValues (data_sp); 69 } 70 71 NativeProcessProtocolSP 72 NativeThreadProtocol::GetProcess () 73 { 74 return m_process_wp.lock (); 75 } 76