blob: 6cef5b1fa2d2730a5287f0050e8beecfb2f4a58a [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
10#include "NativeThreadProtocol.h"
11
12#include "NativeProcessProtocol.h"
13#include "lldb/Target/NativeRegisterContext.h"
14#include "SoftwareBreakpoint.h"
15
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}
76
77uint32_t
78NativeThreadProtocol::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}