1af245d11STodd Fiala //===-- NativeThreadProtocol.cpp --------------------------------*- C++ -*-===//
2af245d11STodd Fiala //
3af245d11STodd Fiala //                     The LLVM Compiler Infrastructure
4af245d11STodd Fiala //
5af245d11STodd Fiala // This file is distributed under the University of Illinois Open Source
6af245d11STodd Fiala // License. See LICENSE.TXT for details.
7af245d11STodd Fiala //
8af245d11STodd Fiala //===----------------------------------------------------------------------===//
9af245d11STodd Fiala 
102fe1d0abSChaoren Lin #include "lldb/Host/common/NativeThreadProtocol.h"
11af245d11STodd Fiala 
122fe1d0abSChaoren Lin #include "lldb/Host/common/NativeProcessProtocol.h"
132fe1d0abSChaoren Lin #include "lldb/Host/common/NativeRegisterContext.h"
142fe1d0abSChaoren Lin #include "lldb/Host/common/SoftwareBreakpoint.h"
15af245d11STodd Fiala 
16af245d11STodd Fiala using namespace lldb;
17af245d11STodd Fiala using namespace lldb_private;
18af245d11STodd Fiala 
19*b9c1b51eSKate Stone NativeThreadProtocol::NativeThreadProtocol(NativeProcessProtocol *process,
20*b9c1b51eSKate Stone                                            lldb::tid_t tid)
21*b9c1b51eSKate Stone     : m_process_wp(process->shared_from_this()), m_tid(tid) {}
22af245d11STodd Fiala 
23*b9c1b51eSKate Stone Error NativeThreadProtocol::ReadRegister(uint32_t reg,
24*b9c1b51eSKate Stone                                          RegisterValue &reg_value) {
25af245d11STodd Fiala   NativeRegisterContextSP register_context_sp = GetRegisterContext();
26af245d11STodd Fiala   if (!register_context_sp)
27af245d11STodd Fiala     return Error("no register context");
28af245d11STodd Fiala 
29*b9c1b51eSKate Stone   const RegisterInfo *const reg_info =
30*b9c1b51eSKate Stone       register_context_sp->GetRegisterInfoAtIndex(reg);
31af245d11STodd Fiala   if (!reg_info)
32af245d11STodd Fiala     return Error("no register info for reg num %" PRIu32, reg);
33af245d11STodd Fiala 
34*b9c1b51eSKate Stone   return register_context_sp->ReadRegister(reg_info, reg_value);
35*b9c1b51eSKate Stone   ;
36af245d11STodd Fiala }
37af245d11STodd Fiala 
38*b9c1b51eSKate Stone Error NativeThreadProtocol::WriteRegister(uint32_t reg,
39*b9c1b51eSKate Stone                                           const RegisterValue &reg_value) {
40af245d11STodd Fiala   NativeRegisterContextSP register_context_sp = GetRegisterContext();
41af245d11STodd Fiala   if (!register_context_sp)
42af245d11STodd Fiala     return Error("no register context");
43af245d11STodd Fiala 
44*b9c1b51eSKate Stone   const RegisterInfo *const reg_info =
45*b9c1b51eSKate Stone       register_context_sp->GetRegisterInfoAtIndex(reg);
46af245d11STodd Fiala   if (!reg_info)
47af245d11STodd Fiala     return Error("no register info for reg num %" PRIu32, reg);
48af245d11STodd Fiala 
49af245d11STodd Fiala   return register_context_sp->WriteRegister(reg_info, reg_value);
50af245d11STodd Fiala }
51af245d11STodd Fiala 
52*b9c1b51eSKate Stone Error NativeThreadProtocol::SaveAllRegisters(lldb::DataBufferSP &data_sp) {
53af245d11STodd Fiala   NativeRegisterContextSP register_context_sp = GetRegisterContext();
54af245d11STodd Fiala   if (!register_context_sp)
55af245d11STodd Fiala     return Error("no register context");
56af245d11STodd Fiala   return register_context_sp->WriteAllRegisterValues(data_sp);
57af245d11STodd Fiala }
58af245d11STodd Fiala 
59*b9c1b51eSKate Stone Error NativeThreadProtocol::RestoreAllRegisters(lldb::DataBufferSP &data_sp) {
60af245d11STodd Fiala   NativeRegisterContextSP register_context_sp = GetRegisterContext();
61af245d11STodd Fiala   if (!register_context_sp)
62af245d11STodd Fiala     return Error("no register context");
63af245d11STodd Fiala   return register_context_sp->ReadAllRegisterValues(data_sp);
64af245d11STodd Fiala }
65af245d11STodd Fiala 
66*b9c1b51eSKate Stone NativeProcessProtocolSP NativeThreadProtocol::GetProcess() {
67af245d11STodd Fiala   return m_process_wp.lock();
68af245d11STodd Fiala }
69