xref: /openbsd-src/gnu/llvm/lldb/source/Plugins/Architecture/PPC64/ArchitecturePPC64.cpp (revision f6aab3d83b51b91c24247ad2c2573574de475a82)
1*dda28197Spatrick //===-- ArchitecturePPC64.cpp ---------------------------------------------===//
2061da546Spatrick //
3061da546Spatrick // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4061da546Spatrick // See https://llvm.org/LICENSE.txt for license information.
5061da546Spatrick // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6061da546Spatrick //
7061da546Spatrick //===----------------------------------------------------------------------===//
8061da546Spatrick 
9061da546Spatrick #include "Plugins/Architecture/PPC64/ArchitecturePPC64.h"
10061da546Spatrick #include "lldb/Core/PluginManager.h"
11061da546Spatrick #include "lldb/Symbol/Function.h"
12061da546Spatrick #include "lldb/Symbol/Symbol.h"
13061da546Spatrick #include "lldb/Target/RegisterContext.h"
14061da546Spatrick #include "lldb/Target/Target.h"
15061da546Spatrick #include "lldb/Target/Thread.h"
16061da546Spatrick #include "lldb/Utility/ArchSpec.h"
17061da546Spatrick 
18061da546Spatrick #include "llvm/BinaryFormat/ELF.h"
19061da546Spatrick 
20061da546Spatrick using namespace lldb_private;
21061da546Spatrick using namespace lldb;
22061da546Spatrick 
LLDB_PLUGIN_DEFINE(ArchitecturePPC64)23*dda28197Spatrick LLDB_PLUGIN_DEFINE(ArchitecturePPC64)
24*dda28197Spatrick 
25061da546Spatrick void ArchitecturePPC64::Initialize() {
26061da546Spatrick   PluginManager::RegisterPlugin(GetPluginNameStatic(),
27061da546Spatrick                                 "PPC64-specific algorithms",
28061da546Spatrick                                 &ArchitecturePPC64::Create);
29061da546Spatrick }
30061da546Spatrick 
Terminate()31061da546Spatrick void ArchitecturePPC64::Terminate() {
32061da546Spatrick   PluginManager::UnregisterPlugin(&ArchitecturePPC64::Create);
33061da546Spatrick }
34061da546Spatrick 
Create(const ArchSpec & arch)35061da546Spatrick std::unique_ptr<Architecture> ArchitecturePPC64::Create(const ArchSpec &arch) {
36061da546Spatrick   if (arch.GetTriple().isPPC64() &&
37061da546Spatrick       arch.GetTriple().getObjectFormat() == llvm::Triple::ObjectFormatType::ELF)
38061da546Spatrick     return std::unique_ptr<Architecture>(new ArchitecturePPC64());
39061da546Spatrick   return nullptr;
40061da546Spatrick }
41061da546Spatrick 
GetLocalEntryOffset(const Symbol & sym)42061da546Spatrick static int32_t GetLocalEntryOffset(const Symbol &sym) {
43061da546Spatrick   unsigned char other = sym.GetFlags() >> 8 & 0xFF;
44061da546Spatrick   return llvm::ELF::decodePPC64LocalEntryOffset(other);
45061da546Spatrick }
46061da546Spatrick 
GetBytesToSkip(Symbol & func,const Address & curr_addr) const47061da546Spatrick size_t ArchitecturePPC64::GetBytesToSkip(Symbol &func,
48061da546Spatrick                                          const Address &curr_addr) const {
49061da546Spatrick   if (curr_addr.GetFileAddress() ==
50061da546Spatrick       func.GetFileAddress() + GetLocalEntryOffset(func))
51061da546Spatrick     return func.GetPrologueByteSize();
52061da546Spatrick   return 0;
53061da546Spatrick }
54061da546Spatrick 
AdjustBreakpointAddress(const Symbol & func,Address & addr) const55061da546Spatrick void ArchitecturePPC64::AdjustBreakpointAddress(const Symbol &func,
56061da546Spatrick                                                 Address &addr) const {
57061da546Spatrick   int32_t loffs = GetLocalEntryOffset(func);
58061da546Spatrick   if (!loffs)
59061da546Spatrick     return;
60061da546Spatrick 
61061da546Spatrick   addr.SetOffset(addr.GetOffset() + loffs);
62061da546Spatrick }
63