1 //===-- ArchitecturePPC64.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 "Plugins/Architecture/PPC64/ArchitecturePPC64.h" 10 #include "lldb/Core/PluginManager.h" 11 #include "lldb/Symbol/Function.h" 12 #include "lldb/Symbol/Symbol.h" 13 #include "lldb/Target/RegisterContext.h" 14 #include "lldb/Target/Target.h" 15 #include "lldb/Target/Thread.h" 16 #include "lldb/Utility/ArchSpec.h" 17 18 #include "llvm/BinaryFormat/ELF.h" 19 20 using namespace lldb_private; 21 using namespace lldb; 22 LLDB_PLUGIN_DEFINE(ArchitecturePPC64)23LLDB_PLUGIN_DEFINE(ArchitecturePPC64) 24 25 ConstString ArchitecturePPC64::GetPluginNameStatic() { 26 return ConstString("ppc64"); 27 } 28 Initialize()29void ArchitecturePPC64::Initialize() { 30 PluginManager::RegisterPlugin(GetPluginNameStatic(), 31 "PPC64-specific algorithms", 32 &ArchitecturePPC64::Create); 33 } 34 Terminate()35void ArchitecturePPC64::Terminate() { 36 PluginManager::UnregisterPlugin(&ArchitecturePPC64::Create); 37 } 38 Create(const ArchSpec & arch)39std::unique_ptr<Architecture> ArchitecturePPC64::Create(const ArchSpec &arch) { 40 if (arch.GetTriple().isPPC64() && 41 arch.GetTriple().getObjectFormat() == llvm::Triple::ObjectFormatType::ELF) 42 return std::unique_ptr<Architecture>(new ArchitecturePPC64()); 43 return nullptr; 44 } 45 GetPluginName()46ConstString ArchitecturePPC64::GetPluginName() { return GetPluginNameStatic(); } GetPluginVersion()47uint32_t ArchitecturePPC64::GetPluginVersion() { return 1; } 48 GetLocalEntryOffset(const Symbol & sym)49static int32_t GetLocalEntryOffset(const Symbol &sym) { 50 unsigned char other = sym.GetFlags() >> 8 & 0xFF; 51 return llvm::ELF::decodePPC64LocalEntryOffset(other); 52 } 53 GetBytesToSkip(Symbol & func,const Address & curr_addr) const54size_t ArchitecturePPC64::GetBytesToSkip(Symbol &func, 55 const Address &curr_addr) const { 56 if (curr_addr.GetFileAddress() == 57 func.GetFileAddress() + GetLocalEntryOffset(func)) 58 return func.GetPrologueByteSize(); 59 return 0; 60 } 61 AdjustBreakpointAddress(const Symbol & func,Address & addr) const62void ArchitecturePPC64::AdjustBreakpointAddress(const Symbol &func, 63 Address &addr) const { 64 int32_t loffs = GetLocalEntryOffset(func); 65 if (!loffs) 66 return; 67 68 addr.SetOffset(addr.GetOffset() + loffs); 69 } 70