blob: ea406e9ef2c65b155efacded82f1b7b999f51f32 [file] [log] [blame]
Todd Fialaaf245d12014-06-30 21:05:18 +00001//===-- 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
Chaoren Lin2fe1d0a2015-02-03 01:51:38 +000010#include "lldb/Host/common/NativeThreadProtocol.h"
Todd Fialaaf245d12014-06-30 21:05:18 +000011
Chaoren Lin2fe1d0a2015-02-03 01:51:38 +000012#include "lldb/Host/common/NativeProcessProtocol.h"
13#include "lldb/Host/common/NativeRegisterContext.h"
14#include "lldb/Host/common/SoftwareBreakpoint.h"
Todd Fialaaf245d12014-06-30 21:05:18 +000015
16using namespace lldb;
17using namespace lldb_private;
18
19NativeThreadProtocol::NativeThreadProtocol (NativeProcessProtocol *process, lldb::tid_t tid) :
20 m_process_wp (process->shared_from_this ()),
21 m_tid (tid)
22{
23}
24
25Error
26NativeThreadProtocol::ReadRegister (uint32_t reg, RegisterValue &reg_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
39Error
40NativeThreadProtocol::WriteRegister (uint32_t reg, const RegisterValue &reg_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
53Error
54NativeThreadProtocol::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
62Error
63NativeThreadProtocol::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
71NativeProcessProtocolSP
72NativeThreadProtocol::GetProcess ()
73{
74 return m_process_wp.lock ();
75}