blob: 619de093aaccf4314eeb4126708f5332d0d93fb3 [file] [log] [blame]
Jim Ingham08581262018-03-12 21:17:04 +00001//===-- ArchitecturePPC64.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#include "Plugins/Architecture/PPC64/ArchitecturePPC64.h"
11#include "lldb/Core/PluginManager.h"
12#include "lldb/Symbol/Function.h"
13#include "lldb/Symbol/Symbol.h"
14#include "lldb/Target/RegisterContext.h"
15#include "lldb/Target/Target.h"
16#include "lldb/Target/Thread.h"
17#include "lldb/Utility/ArchSpec.h"
18
19#include "llvm/BinaryFormat/ELF.h"
20
21using namespace lldb_private;
22using namespace lldb;
23
24ConstString ArchitecturePPC64::GetPluginNameStatic() {
25 return ConstString("ppc64");
26}
27
28void ArchitecturePPC64::Initialize() {
29 PluginManager::RegisterPlugin(GetPluginNameStatic(),
30 "PPC64-specific algorithms",
31 &ArchitecturePPC64::Create);
32}
33
34void ArchitecturePPC64::Terminate() {
35 PluginManager::UnregisterPlugin(&ArchitecturePPC64::Create);
36}
37
38std::unique_ptr<Architecture> ArchitecturePPC64::Create(const ArchSpec &arch) {
39 if ((arch.GetMachine() != llvm::Triple::ppc64 &&
40 arch.GetMachine() != llvm::Triple::ppc64le) ||
41 arch.GetTriple().getObjectFormat() != llvm::Triple::ObjectFormatType::ELF)
42 return nullptr;
43 return std::unique_ptr<Architecture>(new ArchitecturePPC64());
44}
45
46ConstString ArchitecturePPC64::GetPluginName() { return GetPluginNameStatic(); }
47uint32_t ArchitecturePPC64::GetPluginVersion() { return 1; }
48
49static int32_t GetLocalEntryOffset(const Symbol &sym) {
50 unsigned char other = sym.GetFlags() >> 8 & 0xFF;
51 return llvm::ELF::decodePPC64LocalEntryOffset(other);
52}
53
54size_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
62void 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}