ThreadMinidump.cpp revision 341825
1//===-- ThreadMinidump.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// Project includes 11#include "ThreadMinidump.h" 12#include "ProcessMinidump.h" 13 14#include "RegisterContextMinidump_x86_32.h" 15#include "RegisterContextMinidump_x86_64.h" 16 17// Other libraries and framework includes 18#include "Plugins/Process/Utility/RegisterContextLinux_i386.h" 19#include "Plugins/Process/Utility/RegisterContextLinux_x86_64.h" 20#include "Plugins/Process/elf-core/RegisterContextPOSIXCore_x86_64.h" 21#include "Plugins/Process/elf-core/RegisterUtilities.h" 22 23#include "lldb/Target/RegisterContext.h" 24#include "lldb/Target/StopInfo.h" 25#include "lldb/Target/Target.h" 26#include "lldb/Target/Unwind.h" 27#include "lldb/Utility/DataExtractor.h" 28#include "lldb/Utility/Log.h" 29 30// C Includes 31// C++ Includes 32 33using namespace lldb; 34using namespace lldb_private; 35using namespace minidump; 36 37ThreadMinidump::ThreadMinidump(Process &process, const MinidumpThread &td, 38 llvm::ArrayRef<uint8_t> gpregset_data) 39 : Thread(process, td.thread_id), m_thread_reg_ctx_sp(), 40 m_gpregset_data(gpregset_data) {} 41 42ThreadMinidump::~ThreadMinidump() {} 43 44void ThreadMinidump::RefreshStateAfterStop() {} 45 46RegisterContextSP ThreadMinidump::GetRegisterContext() { 47 if (!m_reg_context_sp) { 48 m_reg_context_sp = CreateRegisterContextForFrame(nullptr); 49 } 50 return m_reg_context_sp; 51} 52 53RegisterContextSP 54ThreadMinidump::CreateRegisterContextForFrame(StackFrame *frame) { 55 RegisterContextSP reg_ctx_sp; 56 uint32_t concrete_frame_idx = 0; 57 Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_THREAD)); 58 59 if (frame) 60 concrete_frame_idx = frame->GetConcreteFrameIndex(); 61 62 if (concrete_frame_idx == 0) { 63 if (m_thread_reg_ctx_sp) 64 return m_thread_reg_ctx_sp; 65 66 ProcessMinidump *process = 67 static_cast<ProcessMinidump *>(GetProcess().get()); 68 ArchSpec arch = process->GetArchitecture(); 69 RegisterInfoInterface *reg_interface = nullptr; 70 71 // TODO write other register contexts and add them here 72 switch (arch.GetMachine()) { 73 case llvm::Triple::x86: { 74 reg_interface = new RegisterContextLinux_i386(arch); 75 lldb::DataBufferSP buf = 76 ConvertMinidumpContext_x86_32(m_gpregset_data, reg_interface); 77 DataExtractor gpregset(buf, lldb::eByteOrderLittle, 4); 78 m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64( 79 *this, reg_interface, gpregset, {})); 80 break; 81 } 82 case llvm::Triple::x86_64: { 83 reg_interface = new RegisterContextLinux_x86_64(arch); 84 lldb::DataBufferSP buf = 85 ConvertMinidumpContext_x86_64(m_gpregset_data, reg_interface); 86 DataExtractor gpregset(buf, lldb::eByteOrderLittle, 8); 87 m_thread_reg_ctx_sp.reset(new RegisterContextCorePOSIX_x86_64( 88 *this, reg_interface, gpregset, {})); 89 break; 90 } 91 default: 92 break; 93 } 94 95 if (!reg_interface) { 96 if (log) 97 log->Printf("elf-core::%s:: Architecture(%d) not supported", 98 __FUNCTION__, arch.GetMachine()); 99 assert(false && "Architecture not supported"); 100 } 101 102 reg_ctx_sp = m_thread_reg_ctx_sp; 103 } else if (m_unwinder_ap) { 104 reg_ctx_sp = m_unwinder_ap->CreateRegisterContextForFrame(frame); 105 } 106 107 return reg_ctx_sp; 108} 109 110bool ThreadMinidump::CalculateStopInfo() { return false; } 111