1 //===-- ThreadElfCore.cpp --------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Core/DataExtractor.h"
11 #include "lldb/Target/RegisterContext.h"
12 #include "lldb/Target/StopInfo.h"
13 #include "lldb/Target/Target.h"
14 #include "lldb/Target/Unwind.h"
15 #include "ProcessPOSIXLog.h"
17 #include "ThreadElfCore.h"
18 #include "ProcessElfCore.h"
19 #include "RegisterContextLinux_x86_64.h"
20 #include "RegisterContextFreeBSD_i386.h"
21 #include "RegisterContextFreeBSD_mips64.h"
22 #include "RegisterContextFreeBSD_x86_64.h"
23 #include "RegisterContextPOSIXCore_mips64.h"
24 #include "RegisterContextPOSIXCore_x86_64.h"
27 using namespace lldb_private;
29 //----------------------------------------------------------------------
30 // Construct a Thread object with given data
31 //----------------------------------------------------------------------
32 ThreadElfCore::ThreadElfCore (Process &process, tid_t tid,
33 const ThreadData &td) :
35 m_thread_name(td.name),
36 m_thread_reg_ctx_sp (),
38 m_gpregset_data(td.gpregset),
39 m_fpregset_data(td.fpregset)
43 ThreadElfCore::~ThreadElfCore ()
49 ThreadElfCore::RefreshStateAfterStop()
51 GetRegisterContext()->InvalidateIfNeeded (false);
55 ThreadElfCore::ClearStackFrames ()
57 Unwind *unwinder = GetUnwinder ();
60 Thread::ClearStackFrames();
64 ThreadElfCore::GetRegisterContext ()
66 if (m_reg_context_sp.get() == NULL) {
67 m_reg_context_sp = CreateRegisterContextForFrame (NULL);
69 return m_reg_context_sp;
73 ThreadElfCore::CreateRegisterContextForFrame (StackFrame *frame)
75 RegisterContextSP reg_ctx_sp;
76 uint32_t concrete_frame_idx = 0;
77 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
80 concrete_frame_idx = frame->GetConcreteFrameIndex ();
82 if (concrete_frame_idx == 0)
84 if (m_thread_reg_ctx_sp)
85 return m_thread_reg_ctx_sp;
87 ProcessElfCore *process = static_cast<ProcessElfCore *>(GetProcess().get());
88 ArchSpec arch = process->GetArchitecture();
89 RegisterInfoInterface *reg_interface = NULL;
91 switch (arch.GetTriple().getOS())
93 case llvm::Triple::FreeBSD:
95 switch (arch.GetMachine())
97 case llvm::Triple::mips64:
98 reg_interface = new RegisterContextFreeBSD_mips64(arch);
100 case llvm::Triple::x86:
101 reg_interface = new RegisterContextFreeBSD_i386(arch);
103 case llvm::Triple::x86_64:
104 reg_interface = new RegisterContextFreeBSD_x86_64(arch);
112 case llvm::Triple::Linux:
114 switch (arch.GetMachine())
116 case llvm::Triple::x86_64:
117 reg_interface = new RegisterContextLinux_x86_64(arch);
129 if (!reg_interface) {
131 log->Printf ("elf-core::%s:: Architecture(%d) or OS(%d) not supported",
132 __FUNCTION__, arch.GetMachine(), arch.GetTriple().getOS());
133 assert (false && "Architecture or OS not supported");
136 switch (arch.GetMachine())
138 case llvm::Triple::mips64:
139 m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_mips64 (*this, reg_interface, m_gpregset_data, m_fpregset_data));
141 case llvm::Triple::x86:
142 case llvm::Triple::x86_64:
143 m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64 (*this, reg_interface, m_gpregset_data, m_fpregset_data));
149 reg_ctx_sp = m_thread_reg_ctx_sp;
151 else if (m_unwinder_ap.get())
153 reg_ctx_sp = m_unwinder_ap->CreateRegisterContextForFrame (frame);
159 ThreadElfCore::CalculateStopInfo ()
161 ProcessSP process_sp (GetProcess());
164 SetStopInfo(StopInfo::CreateStopReasonWithSignal (*this, m_signo));
170 //----------------------------------------------------------------
171 // Parse PRSTATUS from NOTE entry
172 //----------------------------------------------------------------
173 ELFLinuxPrStatus::ELFLinuxPrStatus()
175 memset(this, 0, sizeof(ELFLinuxPrStatus));
179 ELFLinuxPrStatus::Parse(DataExtractor &data, ArchSpec &arch)
181 ByteOrder byteorder = data.GetByteOrder();
183 switch(arch.GetCore())
185 case ArchSpec::eCore_x86_64_x86_64:
186 len = data.ExtractBytes(0, ELFLINUXPRSTATUS64_SIZE, byteorder, this);
187 return len == ELFLINUXPRSTATUS64_SIZE;
193 //----------------------------------------------------------------
194 // Parse PRPSINFO from NOTE entry
195 //----------------------------------------------------------------
196 ELFLinuxPrPsInfo::ELFLinuxPrPsInfo()
198 memset(this, 0, sizeof(ELFLinuxPrPsInfo));
202 ELFLinuxPrPsInfo::Parse(DataExtractor &data, ArchSpec &arch)
204 ByteOrder byteorder = data.GetByteOrder();
206 switch(arch.GetCore())
208 case ArchSpec::eCore_x86_64_x86_64:
209 len = data.ExtractBytes(0, ELFLINUXPRPSINFO64_SIZE, byteorder, this);
210 return len == ELFLINUXPRPSINFO64_SIZE;