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_mips64.h"
21 #include "RegisterContextFreeBSD_x86_64.h"
22 #include "RegisterContextPOSIXCore_mips64.h"
23 #include "RegisterContextPOSIXCore_x86_64.h"
26 using namespace lldb_private;
28 //----------------------------------------------------------------------
29 // Construct a Thread object with given data
30 //----------------------------------------------------------------------
31 ThreadElfCore::ThreadElfCore (Process &process, tid_t tid,
32 const ThreadData &td) :
34 m_thread_name(td.name),
35 m_thread_reg_ctx_sp (),
37 m_gpregset_data(td.gpregset),
38 m_fpregset_data(td.fpregset)
42 ThreadElfCore::~ThreadElfCore ()
48 ThreadElfCore::RefreshStateAfterStop()
50 GetRegisterContext()->InvalidateIfNeeded (false);
54 ThreadElfCore::ClearStackFrames ()
56 Unwind *unwinder = GetUnwinder ();
59 Thread::ClearStackFrames();
63 ThreadElfCore::GetRegisterContext ()
65 if (m_reg_context_sp.get() == NULL) {
66 m_reg_context_sp = CreateRegisterContextForFrame (NULL);
68 return m_reg_context_sp;
72 ThreadElfCore::CreateRegisterContextForFrame (StackFrame *frame)
74 RegisterContextSP reg_ctx_sp;
75 uint32_t concrete_frame_idx = 0;
76 Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_THREAD));
79 concrete_frame_idx = frame->GetConcreteFrameIndex ();
81 if (concrete_frame_idx == 0)
83 if (m_thread_reg_ctx_sp)
84 return m_thread_reg_ctx_sp;
86 ProcessElfCore *process = static_cast<ProcessElfCore *>(GetProcess().get());
87 ArchSpec arch = process->GetArchitecture();
88 switch (arch.GetMachine())
90 case llvm::Triple::mips64:
91 switch (arch.GetTriple().getOS())
93 case llvm::Triple::FreeBSD:
94 m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_mips64 (*this, new RegisterContextFreeBSD_mips64(arch), 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");
104 case llvm::Triple::x86_64:
105 switch (arch.GetTriple().getOS())
107 case llvm::Triple::FreeBSD:
108 m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64 (*this, new RegisterContextFreeBSD_x86_64(arch), m_gpregset_data, m_fpregset_data));
110 case llvm::Triple::Linux:
111 m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64 (*this, new RegisterContextLinux_x86_64(arch), m_gpregset_data, m_fpregset_data));
115 log->Printf ("elf-core::%s:: OS(%d) not supported",
116 __FUNCTION__, arch.GetTriple().getOS());
117 assert (false && "OS not supported");
123 log->Printf ("elf-core::%s:: Architecture(%d) not supported",
124 __FUNCTION__, arch.GetMachine());
125 assert (false && "Architecture not supported");
127 reg_ctx_sp = m_thread_reg_ctx_sp;
129 else if (m_unwinder_ap.get())
131 reg_ctx_sp = m_unwinder_ap->CreateRegisterContextForFrame (frame);
137 ThreadElfCore::CalculateStopInfo ()
139 ProcessSP process_sp (GetProcess());
142 SetStopInfo(StopInfo::CreateStopReasonWithSignal (*this, m_signo));
148 //----------------------------------------------------------------
149 // Parse PRSTATUS from NOTE entry
150 //----------------------------------------------------------------
151 ELFLinuxPrStatus::ELFLinuxPrStatus()
153 memset(this, 0, sizeof(ELFLinuxPrStatus));
157 ELFLinuxPrStatus::Parse(DataExtractor &data, ArchSpec &arch)
159 ByteOrder byteorder = data.GetByteOrder();
161 switch(arch.GetCore())
163 case ArchSpec::eCore_x86_64_x86_64:
164 len = data.ExtractBytes(0, ELFLINUXPRSTATUS64_SIZE, byteorder, this);
165 return len == ELFLINUXPRSTATUS64_SIZE;
171 //----------------------------------------------------------------
172 // Parse PRPSINFO from NOTE entry
173 //----------------------------------------------------------------
174 ELFLinuxPrPsInfo::ELFLinuxPrPsInfo()
176 memset(this, 0, sizeof(ELFLinuxPrPsInfo));
180 ELFLinuxPrPsInfo::Parse(DataExtractor &data, ArchSpec &arch)
182 ByteOrder byteorder = data.GetByteOrder();
184 switch(arch.GetCore())
186 case ArchSpec::eCore_x86_64_x86_64:
187 len = data.ExtractBytes(0, ELFLINUXPRPSINFO64_SIZE, byteorder, this);
188 return len == ELFLINUXPRPSINFO64_SIZE;