[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / lldb / unittests / Target / ExecutionContextTest.cpp
blobcba32c21423e3e2fcb9eed25d3e68a82644dd122
1 //===-- ExecutionContextTest.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 //===----------------------------------------------------------------------===//
9 #include "lldb/Target/ExecutionContext.h"
10 #include "Plugins/Platform/Linux/PlatformLinux.h"
11 #include "lldb/Core/Debugger.h"
12 #include "lldb/Host/FileSystem.h"
13 #include "lldb/Host/HostInfo.h"
14 #include "lldb/Target/Platform.h"
15 #include "lldb/Target/Process.h"
16 #include "lldb/Target/Target.h"
17 #include "lldb/Utility/ArchSpec.h"
18 #include "lldb/Utility/Endian.h"
19 #include "lldb/lldb-enumerations.h"
20 #include "lldb/lldb-forward.h"
21 #include "lldb/lldb-private-enumerations.h"
22 #include "lldb/lldb-private.h"
23 #include "llvm/Support/FormatVariadic.h"
24 #include "gtest/gtest.h"
26 using namespace lldb_private;
27 using namespace lldb_private::repro;
28 using namespace lldb;
30 namespace {
31 class ExecutionContextTest : public ::testing::Test {
32 public:
33 void SetUp() override {
34 FileSystem::Initialize();
35 HostInfo::Initialize();
36 platform_linux::PlatformLinux::Initialize();
38 void TearDown() override {
39 platform_linux::PlatformLinux::Terminate();
40 HostInfo::Terminate();
41 FileSystem::Terminate();
45 class DummyProcess : public Process {
46 public:
47 DummyProcess(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp)
48 : Process(target_sp, listener_sp) {}
50 bool CanDebug(lldb::TargetSP target, bool plugin_specified_by_name) override {
51 return true;
53 Status DoDestroy() override { return {}; }
54 void RefreshStateAfterStop() override {}
55 size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
56 Status &error) override {
57 return 0;
59 bool DoUpdateThreadList(ThreadList &old_thread_list,
60 ThreadList &new_thread_list) override {
61 return false;
63 llvm::StringRef GetPluginName() override { return "Dummy"; }
65 } // namespace
67 TEST_F(ExecutionContextTest, GetByteOrder) {
68 ExecutionContext exe_ctx(nullptr, nullptr, nullptr);
69 EXPECT_EQ(endian::InlHostByteOrder(), exe_ctx.GetByteOrder());
72 TEST_F(ExecutionContextTest, GetByteOrderTarget) {
73 ArchSpec arch("powerpc64-pc-linux");
75 Platform::SetHostPlatform(
76 platform_linux::PlatformLinux::CreateInstance(true, &arch));
78 DebuggerSP debugger_sp = Debugger::CreateInstance();
79 ASSERT_TRUE(debugger_sp);
81 TargetSP target_sp;
82 PlatformSP platform_sp;
83 Status error = debugger_sp->GetTargetList().CreateTarget(
84 *debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
85 ASSERT_TRUE(target_sp);
86 ASSERT_TRUE(target_sp->GetArchitecture().IsValid());
87 ASSERT_TRUE(platform_sp);
89 ExecutionContext target_ctx(target_sp, false);
90 EXPECT_EQ(target_sp->GetArchitecture().GetByteOrder(),
91 target_ctx.GetByteOrder());
94 TEST_F(ExecutionContextTest, GetByteOrderProcess) {
95 ArchSpec arch("powerpc64-pc-linux");
97 Platform::SetHostPlatform(
98 platform_linux::PlatformLinux::CreateInstance(true, &arch));
100 DebuggerSP debugger_sp = Debugger::CreateInstance();
101 ASSERT_TRUE(debugger_sp);
103 TargetSP target_sp;
104 PlatformSP platform_sp;
105 Status error = debugger_sp->GetTargetList().CreateTarget(
106 *debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
107 ASSERT_TRUE(target_sp);
108 ASSERT_TRUE(target_sp->GetArchitecture().IsValid());
109 ASSERT_TRUE(platform_sp);
111 ListenerSP listener_sp(Listener::MakeListener("dummy"));
112 ProcessSP process_sp = std::make_shared<DummyProcess>(target_sp, listener_sp);
113 ASSERT_TRUE(process_sp);
115 ExecutionContext process_ctx(process_sp);
116 EXPECT_EQ(process_sp->GetByteOrder(), process_ctx.GetByteOrder());