Skip to content

Commit af0c828

Browse files
committedAug 7, 2019
[ExecutionContext] Return the target/process byte order.
Currently ExecutionContext::GetByteOrder() always returns the host byte order. This seems like a simple mistake: the return keyword appears to have been omitted by accident. This patch fixes that and adds a unit test. Bugreport: https://llvm.org/PR37950 Differential revision: https://reviews.llvm.org/D48704 llvm-svn: 368181
1 parent 4d4eefd commit af0c828

File tree

3 files changed

+126
-4
lines changed

3 files changed

+126
-4
lines changed
 

‎lldb/source/Target/ExecutionContext.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ uint32_t ExecutionContext::GetAddressByteSize() const {
183183

184184
lldb::ByteOrder ExecutionContext::GetByteOrder() const {
185185
if (m_target_sp && m_target_sp->GetArchitecture().IsValid())
186-
m_target_sp->GetArchitecture().GetByteOrder();
186+
return m_target_sp->GetArchitecture().GetByteOrder();
187187
if (m_process_sp)
188-
m_process_sp->GetByteOrder();
188+
return m_process_sp->GetByteOrder();
189189
return endian::InlHostByteOrder();
190190
}
191191

‎lldb/unittests/Target/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_lldb_unittest(TargetTests
2+
ExecutionContextTest.cpp
23
MemoryRegionInfoTest.cpp
34
ModuleCacheTest.cpp
45
PathMappingListTest.cpp
@@ -7,10 +8,11 @@ add_lldb_unittest(TargetTests
78
LINK_LIBS
89
lldbCore
910
lldbHost
10-
lldbSymbol
11-
lldbUtility
1211
lldbPluginObjectFileELF
12+
lldbPluginPlatformLinux
1313
lldbPluginSymbolFileSymtab
14+
lldbSymbol
15+
lldbUtility
1416
lldbUtilityHelpers
1517
LINK_COMPONENTS
1618
Support
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//===-- ExecutionContextTest.cpp --------------------------------*- C++ -*-===//
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 "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/Utility/Reproducer.h"
20+
#include "lldb/lldb-enumerations.h"
21+
#include "lldb/lldb-forward.h"
22+
#include "lldb/lldb-private-enumerations.h"
23+
#include "lldb/lldb-private.h"
24+
#include "llvm/Support/FormatVariadic.h"
25+
#include "gtest/gtest.h"
26+
27+
using namespace lldb_private;
28+
using namespace lldb_private::repro;
29+
using namespace lldb;
30+
31+
namespace {
32+
class ExecutionContextTest : public ::testing::Test {
33+
public:
34+
void SetUp() override {
35+
llvm::cantFail(Reproducer::Initialize(ReproducerMode::Off, llvm::None));
36+
FileSystem::Initialize();
37+
HostInfo::Initialize();
38+
platform_linux::PlatformLinux::Initialize();
39+
}
40+
void TearDown() override {
41+
platform_linux::PlatformLinux::Terminate();
42+
HostInfo::Terminate();
43+
FileSystem::Terminate();
44+
Reproducer::Terminate();
45+
}
46+
};
47+
48+
class DummyProcess : public Process {
49+
public:
50+
using Process::Process;
51+
52+
virtual bool CanDebug(lldb::TargetSP target, bool plugin_specified_by_name) {
53+
return true;
54+
}
55+
virtual Status DoDestroy() { return {}; }
56+
virtual void RefreshStateAfterStop() {}
57+
virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
58+
Status &error) {
59+
return 0;
60+
}
61+
virtual bool UpdateThreadList(ThreadList &old_thread_list,
62+
ThreadList &new_thread_list) {
63+
return false;
64+
}
65+
virtual ConstString GetPluginName() { return ConstString("Dummy"); }
66+
virtual uint32_t GetPluginVersion() { return 0; }
67+
};
68+
} // namespace
69+
70+
TEST_F(ExecutionContextTest, GetByteOrder) {
71+
ExecutionContext exe_ctx(nullptr, nullptr, nullptr);
72+
EXPECT_EQ(endian::InlHostByteOrder(), exe_ctx.GetByteOrder());
73+
}
74+
75+
TEST_F(ExecutionContextTest, GetByteOrderTarget) {
76+
ArchSpec arch("powerpc64-pc-linux");
77+
78+
Platform::SetHostPlatform(
79+
platform_linux::PlatformLinux::CreateInstance(true, &arch));
80+
81+
DebuggerSP debugger_sp = Debugger::CreateInstance();
82+
ASSERT_TRUE(debugger_sp);
83+
84+
TargetSP target_sp;
85+
PlatformSP platform_sp;
86+
Status error = debugger_sp->GetTargetList().CreateTarget(
87+
*debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
88+
ASSERT_TRUE(target_sp);
89+
ASSERT_TRUE(target_sp->GetArchitecture().IsValid());
90+
ASSERT_TRUE(platform_sp);
91+
92+
ExecutionContext target_ctx(target_sp, false);
93+
EXPECT_EQ(target_sp->GetArchitecture().GetByteOrder(),
94+
target_ctx.GetByteOrder());
95+
}
96+
97+
TEST_F(ExecutionContextTest, GetByteOrderProcess) {
98+
ArchSpec arch("powerpc64-pc-linux");
99+
100+
Platform::SetHostPlatform(
101+
platform_linux::PlatformLinux::CreateInstance(true, &arch));
102+
103+
DebuggerSP debugger_sp = Debugger::CreateInstance();
104+
ASSERT_TRUE(debugger_sp);
105+
106+
TargetSP target_sp;
107+
PlatformSP platform_sp;
108+
Status error = debugger_sp->GetTargetList().CreateTarget(
109+
*debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
110+
ASSERT_TRUE(target_sp);
111+
ASSERT_TRUE(target_sp->GetArchitecture().IsValid());
112+
ASSERT_TRUE(platform_sp);
113+
114+
ListenerSP listener_sp(Listener::MakeListener("dummy"));
115+
ProcessSP process_sp = std::make_shared<DummyProcess>(target_sp, listener_sp);
116+
ASSERT_TRUE(process_sp);
117+
118+
ExecutionContext process_ctx(process_sp);
119+
EXPECT_EQ(process_sp->GetByteOrder(), process_ctx.GetByteOrder());
120+
}

0 commit comments

Comments
 (0)
Please sign in to comment.