LLDB  mainline
ThreadMinidump.cpp
Go to the documentation of this file.
1 //===-- ThreadMinidump.cpp ------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "ThreadMinidump.h"
10 
11 #include "ProcessMinidump.h"
12 
17 
22 
24 #include "lldb/Target/StopInfo.h"
25 #include "lldb/Target/Target.h"
26 #include "lldb/Target/Unwind.h"
28 #include "lldb/Utility/Log.h"
29 
30 #include <memory>
31 
32 using namespace lldb;
33 using namespace lldb_private;
34 using namespace minidump;
35 
36 ThreadMinidump::ThreadMinidump(Process &process, const minidump::Thread &td,
37  llvm::ArrayRef<uint8_t> gpregset_data)
38  : Thread(process, td.ThreadId), m_thread_reg_ctx_sp(),
39  m_gpregset_data(gpregset_data) {}
40 
42 
44 
46  if (!m_reg_context_sp) {
48  }
49  return m_reg_context_sp;
50 }
51 
52 RegisterContextSP
54  RegisterContextSP reg_ctx_sp;
55  uint32_t concrete_frame_idx = 0;
56 
57  if (frame)
58  concrete_frame_idx = frame->GetConcreteFrameIndex();
59 
60  if (concrete_frame_idx == 0) {
62  return m_thread_reg_ctx_sp;
63 
64  ProcessMinidump *process =
65  static_cast<ProcessMinidump *>(GetProcess().get());
66  ArchSpec arch = process->GetArchitecture();
67  RegisterInfoInterface *reg_interface = nullptr;
68 
69  // TODO write other register contexts and add them here
70  switch (arch.GetMachine()) {
71  case llvm::Triple::x86: {
72  reg_interface = new RegisterContextLinux_i386(arch);
73  lldb::DataBufferSP buf =
75  DataExtractor gpregset(buf, lldb::eByteOrderLittle, 4);
76  m_thread_reg_ctx_sp = std::make_shared<RegisterContextCorePOSIX_x86_64>(
77  *this, reg_interface, gpregset,
78  llvm::ArrayRef<lldb_private::CoreNote>());
79  break;
80  }
81  case llvm::Triple::x86_64: {
82  reg_interface = new RegisterContextLinux_x86_64(arch);
83  lldb::DataBufferSP buf =
85  DataExtractor gpregset(buf, lldb::eByteOrderLittle, 8);
86  m_thread_reg_ctx_sp = std::make_shared<RegisterContextCorePOSIX_x86_64>(
87  *this, reg_interface, gpregset,
88  llvm::ArrayRef<lldb_private::CoreNote>());
89  break;
90  }
91  case llvm::Triple::aarch64: {
92  DataExtractor data(m_gpregset_data.data(), m_gpregset_data.size(),
95  std::make_shared<RegisterContextMinidump_ARM64>(*this, data);
96  break;
97  }
98  case llvm::Triple::arm: {
99  DataExtractor data(m_gpregset_data.data(), m_gpregset_data.size(),
101  const bool apple = arch.GetTriple().getVendor() == llvm::Triple::Apple;
103  std::make_shared<RegisterContextMinidump_ARM>(*this, data, apple);
104  break;
105  }
106  default:
107  break;
108  }
109 
110  reg_ctx_sp = m_thread_reg_ctx_sp;
111  } else if (m_unwinder_up) {
112  reg_ctx_sp = m_unwinder_up->CreateRegisterContextForFrame(frame);
113  }
114 
115  return reg_ctx_sp;
116 }
117 
118 bool ThreadMinidump::CalculateStopInfo() { return false; }
ThreadMinidump.h
lldb_private::ArchSpec
Definition: ArchSpec.h:33
RegisterContextMinidump_x86_32.h
lldb_private::minidump::ConvertMinidumpContext_x86_32
lldb::DataBufferSP ConvertMinidumpContext_x86_32(llvm::ArrayRef< uint8_t > source_data, RegisterInfoInterface *target_reg_interface)
Definition: RegisterContextMinidump_x86_32.cpp:24
RegisterContextMinidump_ARM.h
lldb_private::minidump::ThreadMinidump::CreateRegisterContextForFrame
lldb::RegisterContextSP CreateRegisterContextForFrame(StackFrame *frame) override
Definition: ThreadMinidump.cpp:53
lldb_private::ArchSpec::GetMachine
llvm::Triple::ArchType GetMachine() const
Returns a machine family for the current architecture.
Definition: ArchSpec.cpp:667
RegisterContextLinux_x86_64
Definition: RegisterContextLinux_x86_64.h:14
RegisterContextMinidump_ARM64.h
Unwind.h
RegisterContextLinux_x86_64.h
lldb_private::RegisterInfoInterface
Definition: RegisterInfoInterface.h:21
lldb_private::Process
Definition: Process.h:341
RegisterUtilities.h
lldb_private::ArchSpec::GetTriple
llvm::Triple & GetTriple()
Architecture triple accessor.
Definition: ArchSpec.h:444
lldb_private::minidump::ThreadMinidump::GetRegisterContext
lldb::RegisterContextSP GetRegisterContext() override
Definition: ThreadMinidump.cpp:45
RegisterContextLinux_i386.h
Target.h
lldb_private::StackFrame::GetConcreteFrameIndex
uint32_t GetConcreteFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList, not counting inlined frame...
Definition: StackFrame.h:407
lldb_private::Thread::GetProcess
lldb::ProcessSP GetProcess() const
Definition: Thread.h:152
lldb_private::minidump::ThreadMinidump::RefreshStateAfterStop
void RefreshStateAfterStop() override
Definition: ThreadMinidump.cpp:43
lldb_private::DataExtractor
Definition: DataExtractor.h:48
Log.h
lldb_private::Thread
Definition: Thread.h:60
lldb_private::minidump::ConvertMinidumpContext_x86_64
lldb::DataBufferSP ConvertMinidumpContext_x86_64(llvm::ArrayRef< uint8_t > source_data, RegisterInfoInterface *target_reg_interface)
Definition: RegisterContextMinidump_x86_64.cpp:47
lldb_private::minidump::ProcessMinidump
Definition: ProcessMinidump.h:29
RegisterContextMinidump_x86_64.h
lldb_private::minidump::ThreadMinidump::CalculateStopInfo
bool CalculateStopInfo() override
Definition: ThreadMinidump.cpp:118
RegisterContextLinux_i386
Definition: RegisterContextLinux_i386.h:14
lldb_private::Thread::m_unwinder_up
std::unique_ptr< lldb_private::Unwind > m_unwinder_up
It gets set in Thread::ShouldResume.
Definition: Thread.h:1268
RegisterContextPOSIXCore_x86_64.h
lldb_private::minidump::ThreadMinidump::m_thread_reg_ctx_sp
lldb::RegisterContextSP m_thread_reg_ctx_sp
Definition: ThreadMinidump.h:36
lldb_private::Thread::m_reg_context_sp
lldb::RegisterContextSP m_reg_context_sp
The register context for this thread's current register state.
Definition: Thread.h:1247
uint32_t
lldb_private::minidump::ProcessMinidump::GetArchitecture
ArchSpec GetArchitecture()
Definition: ProcessMinidump.cpp:393
StopInfo.h
DataExtractor.h
lldb_private::minidump::ThreadMinidump::m_gpregset_data
llvm::ArrayRef< uint8_t > m_gpregset_data
Definition: ThreadMinidump.h:37
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::minidump::ThreadMinidump::~ThreadMinidump
~ThreadMinidump() override
ProcessMinidump.h
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb::eByteOrderLittle
@ eByteOrderLittle
Definition: lldb-enumerations.h:142
lldb
Definition: SBAddress.h:15
RegisterContext.h