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