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 "NativeThreadProtocol.h"
11 
12 #include "NativeProcessProtocol.h"
13 #include "lldb/Target/NativeRegisterContext.h"
14 #include "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 &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 
39 Error
40 NativeThreadProtocol::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 
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 
77 uint32_t
78 NativeThreadProtocol::TranslateStopInfoToGdbSignal (const ThreadStopInfo &stop_info) const
79 {
80     // Default: no translation.  Do the real translation where there
81     // is access to the host signal numbers.
82     switch (stop_info.reason)
83     {
84         case eStopReasonSignal:
85             return stop_info.details.signal.signo;
86             break;
87 
88         case eStopReasonException:
89             // FIXME verify the way to specify pass-thru here.
90             return static_cast<uint32_t> (stop_info.details.exception.type);
91             break;
92 
93         default:
94             assert (0 && "unexpected stop_info.reason found");
95             return 0;
96     }
97 }
98