]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Host/common/NativeThreadProtocol.cpp
MFV r316124: Fix build when WITHOUT_INET6.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Host / common / NativeThreadProtocol.cpp
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,
20                                            lldb::tid_t tid)
21     : m_process_wp(process->shared_from_this()), m_tid(tid) {}
22
23 Error NativeThreadProtocol::ReadRegister(uint32_t reg,
24                                          RegisterValue &reg_value) {
25   NativeRegisterContextSP register_context_sp = GetRegisterContext();
26   if (!register_context_sp)
27     return Error("no register context");
28
29   const RegisterInfo *const reg_info =
30       register_context_sp->GetRegisterInfoAtIndex(reg);
31   if (!reg_info)
32     return Error("no register info for reg num %" PRIu32, reg);
33
34   return register_context_sp->ReadRegister(reg_info, reg_value);
35   ;
36 }
37
38 Error NativeThreadProtocol::WriteRegister(uint32_t reg,
39                                           const RegisterValue &reg_value) {
40   NativeRegisterContextSP register_context_sp = GetRegisterContext();
41   if (!register_context_sp)
42     return Error("no register context");
43
44   const RegisterInfo *const reg_info =
45       register_context_sp->GetRegisterInfoAtIndex(reg);
46   if (!reg_info)
47     return Error("no register info for reg num %" PRIu32, reg);
48
49   return register_context_sp->WriteRegister(reg_info, reg_value);
50 }
51
52 Error NativeThreadProtocol::SaveAllRegisters(lldb::DataBufferSP &data_sp) {
53   NativeRegisterContextSP register_context_sp = GetRegisterContext();
54   if (!register_context_sp)
55     return Error("no register context");
56   return register_context_sp->WriteAllRegisterValues(data_sp);
57 }
58
59 Error NativeThreadProtocol::RestoreAllRegisters(lldb::DataBufferSP &data_sp) {
60   NativeRegisterContextSP register_context_sp = GetRegisterContext();
61   if (!register_context_sp)
62     return Error("no register context");
63   return register_context_sp->ReadAllRegisterValues(data_sp);
64 }
65
66 NativeProcessProtocolSP NativeThreadProtocol::GetProcess() {
67   return m_process_wp.lock();
68 }