blob: dfcc2b04f24f83368493b72e6250ac4ee909a3f9 [file] [log] [blame]
Greg Clayton56d9a1b2011-08-22 02:49:39 +00001//===-- ThreadMemory.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 "Plugins/Process/Utility/ThreadMemory.h"
11#include "lldb/Target/OperatingSystem.h"
12#include "lldb/Target/RegisterContext.h"
13#include "lldb/Target/Process.h"
14#include "lldb/Target/StopInfo.h"
15#include "lldb/Target/Unwind.h"
16
17using namespace lldb;
18using namespace lldb_private;
19
Greg Clayton1ac04c32012-02-21 00:09:25 +000020ThreadMemory::ThreadMemory (const ProcessSP &process_sp,
Greg Clayton56d9a1b2011-08-22 02:49:39 +000021 tid_t tid,
22 const ValueObjectSP &thread_info_valobj_sp) :
Greg Clayton1ac04c32012-02-21 00:09:25 +000023 Thread (process_sp, tid),
Greg Clayton56d9a1b2011-08-22 02:49:39 +000024 m_thread_info_valobj_sp (thread_info_valobj_sp)
25{
26}
27
28
29ThreadMemory::~ThreadMemory()
30{
31 DestroyThread();
32}
33
34bool
35ThreadMemory::WillResume (StateType resume_state)
36{
37 ClearStackFrames();
38 // Call the Thread::WillResume first. If we stop at a signal, the stop info
39 // class for signal will set the resume signal that we need below. The signal
40 // stuff obeys the Process::UnixSignal defaults.
41 Thread::WillResume(resume_state);
42 return true;
43}
44
45RegisterContextSP
46ThreadMemory::GetRegisterContext ()
47{
48 if (!m_reg_context_sp)
49 {
Greg Clayton1ac04c32012-02-21 00:09:25 +000050 ProcessSP process_sp (GetProcess());
51 if (process_sp)
52 {
53 OperatingSystem *os = process_sp->GetOperatingSystem ();
54 if (os)
55 m_reg_context_sp = os->CreateRegisterContextForThread (this);
56 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +000057 }
58 return m_reg_context_sp;
59}
60
61RegisterContextSP
62ThreadMemory::CreateRegisterContextForFrame (StackFrame *frame)
63{
64 RegisterContextSP reg_ctx_sp;
65 uint32_t concrete_frame_idx = 0;
66
67 if (frame)
68 concrete_frame_idx = frame->GetConcreteFrameIndex ();
69
70 if (concrete_frame_idx == 0)
71 {
72 reg_ctx_sp = GetRegisterContext ();
73 }
74 else if (m_unwinder_ap.get())
75 {
76 reg_ctx_sp = m_unwinder_ap->CreateRegisterContextForFrame (frame);
77 }
78 return reg_ctx_sp;
79}
80
81lldb::StopInfoSP
82ThreadMemory::GetPrivateStopReason ()
83{
Greg Clayton1ac04c32012-02-21 00:09:25 +000084 ProcessSP process_sp (GetProcess());
85
86 if (process_sp)
Greg Clayton56d9a1b2011-08-22 02:49:39 +000087 {
Greg Clayton1ac04c32012-02-21 00:09:25 +000088 const uint32_t process_stop_id = process_sp->GetStopID();
89 if (m_thread_stop_reason_stop_id != process_stop_id ||
90 (m_actual_stop_info_sp && !m_actual_stop_info_sp->IsValid()))
91 {
92 // If GetGDBProcess().SetThreadStopInfo() doesn't find a stop reason
93 // for this thread, then m_actual_stop_info_sp will not ever contain
94 // a valid stop reason and the "m_actual_stop_info_sp->IsValid() == false"
95 // check will never be able to tell us if we have the correct stop info
96 // for this thread and we will continually send qThreadStopInfo packets
97 // down to the remote GDB server, so we need to keep our own notion
98 // of the stop ID that m_actual_stop_info_sp is valid for (even if it
99 // contains nothing). We use m_thread_stop_reason_stop_id for this below.
100 m_thread_stop_reason_stop_id = process_stop_id;
101 m_actual_stop_info_sp.reset();
102
103 OperatingSystem *os = process_sp->GetOperatingSystem ();
104 if (os)
105 m_actual_stop_info_sp = os->CreateThreadStopReason (this);
106 }
Greg Clayton56d9a1b2011-08-22 02:49:39 +0000107 }
108 return m_actual_stop_info_sp;
109
110}
111
112void
113ThreadMemory::RefreshStateAfterStop()
114{
115 RegisterContextSP reg_ctx_sp(GetRegisterContext());
116 if (reg_ctx_sp)
117 {
118 const bool force = true;
119 reg_ctx_sp->InvalidateIfNeeded (force);
120 }
121}