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 "RegisterContextCoreFreeBSD_x86_64.h"
20 #include "RegisterContextCoreLinux_x86_64.h"
23 using namespace lldb_private;
25 //----------------------------------------------------------------------
26 // Construct a Thread object with given data
27 //----------------------------------------------------------------------
28 ThreadElfCore::ThreadElfCore (Process &process, tid_t tid,
29 const ThreadData &td) :
31 m_thread_name(td.name),
32 m_thread_reg_ctx_sp (),
34 m_gpregset_data(td.gpregset),
35 m_fpregset_data(td.fpregset)
39 ThreadElfCore::~ThreadElfCore ()
45 ThreadElfCore::RefreshStateAfterStop()
47 GetRegisterContext()->InvalidateIfNeeded (false);
51 ThreadElfCore::ClearStackFrames ()
53 Unwind *unwinder = GetUnwinder ();
56 Thread::ClearStackFrames();
60 ThreadElfCore::GetRegisterContext ()
62 if (m_reg_context_sp.get() == NULL) {
63 m_reg_context_sp = CreateRegisterContextForFrame (NULL);
65 return m_reg_context_sp;
69 ThreadElfCore::CreateRegisterContextForFrame (StackFrame *frame)
71 RegisterContextSP reg_ctx_sp;
72 uint32_t concrete_frame_idx = 0;
73 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
76 concrete_frame_idx = frame->GetConcreteFrameIndex ();
78 if (concrete_frame_idx == 0)
80 if (m_thread_reg_ctx_sp)
81 return m_thread_reg_ctx_sp;
83 ProcessElfCore *process = static_cast<ProcessElfCore *>(GetProcess().get());
84 ArchSpec arch = process->GetArchitecture();
85 switch (arch.GetMachine())
87 case llvm::Triple::x86_64:
88 switch (arch.GetTriple().getOS())
90 case llvm::Triple::FreeBSD:
91 m_thread_reg_ctx_sp.reset(new RegisterContextCoreFreeBSD_x86_64 (*this, m_gpregset_data, m_fpregset_data));
93 case llvm::Triple::Linux:
94 m_thread_reg_ctx_sp.reset(new RegisterContextCoreLinux_x86_64 (*this, m_gpregset_data, m_fpregset_data));
98 log->Printf ("elf-core::%s:: OS(%d) not supported",
99 __FUNCTION__, arch.GetTriple().getOS());
100 assert (false && "OS not supported");
106 log->Printf ("elf-core::%s:: Architecture(%d) not supported",
107 __FUNCTION__, arch.GetMachine());
108 assert (false && "Architecture not supported");
110 reg_ctx_sp = m_thread_reg_ctx_sp;
112 else if (m_unwinder_ap.get())
114 reg_ctx_sp = m_unwinder_ap->CreateRegisterContextForFrame (frame);
120 ThreadElfCore::CalculateStopInfo ()
122 ProcessSP process_sp (GetProcess());
125 SetStopInfo(StopInfo::CreateStopReasonWithSignal (*this, m_signo));
131 //----------------------------------------------------------------
132 // Parse PRSTATUS from NOTE entry
133 //----------------------------------------------------------------
134 ELFLinuxPrStatus::ELFLinuxPrStatus()
136 memset(this, 0, sizeof(ELFLinuxPrStatus));
140 ELFLinuxPrStatus::Parse(DataExtractor &data, ArchSpec &arch)
142 ByteOrder byteorder = data.GetByteOrder();
144 switch(arch.GetCore())
146 case ArchSpec::eCore_x86_64_x86_64:
147 len = data.ExtractBytes(0, ELFLINUXPRSTATUS64_SIZE, byteorder, this);
148 return len == ELFLINUXPRSTATUS64_SIZE;
154 //----------------------------------------------------------------
155 // Parse PRPSINFO from NOTE entry
156 //----------------------------------------------------------------
157 ELFLinuxPrPsInfo::ELFLinuxPrPsInfo()
159 memset(this, 0, sizeof(ELFLinuxPrPsInfo));
163 ELFLinuxPrPsInfo::Parse(DataExtractor &data, ArchSpec &arch)
165 ByteOrder byteorder = data.GetByteOrder();
167 switch(arch.GetCore())
169 case ArchSpec::eCore_x86_64_x86_64:
170 len = data.ExtractBytes(0, ELFLINUXPRPSINFO64_SIZE, byteorder, this);
171 return len == ELFLINUXPRPSINFO64_SIZE;