[Lldb-commits] [lldb] r368181 - [ExecutionContext] Return the target/process byte order.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 7 09:09:35 PDT 2019


Author: jdevlieghere
Date: Wed Aug  7 09:09:35 2019
New Revision: 368181

URL: http://llvm.org/viewvc/llvm-project?rev=368181&view=rev
Log:
[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

Added:
    lldb/trunk/unittests/Target/ExecutionContextTest.cpp
Modified:
    lldb/trunk/source/Target/ExecutionContext.cpp
    lldb/trunk/unittests/Target/CMakeLists.txt

Modified: lldb/trunk/source/Target/ExecutionContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/ExecutionContext.cpp?rev=368181&r1=368180&r2=368181&view=diff
==============================================================================
--- lldb/trunk/source/Target/ExecutionContext.cpp (original)
+++ lldb/trunk/source/Target/ExecutionContext.cpp Wed Aug  7 09:09:35 2019
@@ -183,9 +183,9 @@ uint32_t ExecutionContext::GetAddressByt
 
 lldb::ByteOrder ExecutionContext::GetByteOrder() const {
   if (m_target_sp && m_target_sp->GetArchitecture().IsValid())
-    m_target_sp->GetArchitecture().GetByteOrder();
+    return m_target_sp->GetArchitecture().GetByteOrder();
   if (m_process_sp)
-    m_process_sp->GetByteOrder();
+    return m_process_sp->GetByteOrder();
   return endian::InlHostByteOrder();
 }
 

Modified: lldb/trunk/unittests/Target/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Target/CMakeLists.txt?rev=368181&r1=368180&r2=368181&view=diff
==============================================================================
--- lldb/trunk/unittests/Target/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Target/CMakeLists.txt Wed Aug  7 09:09:35 2019
@@ -1,4 +1,5 @@
 add_lldb_unittest(TargetTests
+  ExecutionContextTest.cpp
   MemoryRegionInfoTest.cpp
   ModuleCacheTest.cpp
   PathMappingListTest.cpp
@@ -7,10 +8,11 @@ add_lldb_unittest(TargetTests
   LINK_LIBS
       lldbCore
       lldbHost
-      lldbSymbol
-      lldbUtility
       lldbPluginObjectFileELF
+      lldbPluginPlatformLinux
       lldbPluginSymbolFileSymtab
+      lldbSymbol
+      lldbUtility
       lldbUtilityHelpers
     LINK_COMPONENTS
       Support

Added: lldb/trunk/unittests/Target/ExecutionContextTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Target/ExecutionContextTest.cpp?rev=368181&view=auto
==============================================================================
--- lldb/trunk/unittests/Target/ExecutionContextTest.cpp (added)
+++ lldb/trunk/unittests/Target/ExecutionContextTest.cpp Wed Aug  7 09:09:35 2019
@@ -0,0 +1,120 @@
+//===-- ExecutionContextTest.cpp --------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "lldb/Target/ExecutionContext.h"
+#include "Plugins/Platform/Linux/PlatformLinux.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Host/FileSystem.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Target/Platform.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/ArchSpec.h"
+#include "lldb/Utility/Endian.h"
+#include "lldb/Utility/Reproducer.h"
+#include "lldb/lldb-enumerations.h"
+#include "lldb/lldb-forward.h"
+#include "lldb/lldb-private-enumerations.h"
+#include "lldb/lldb-private.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "gtest/gtest.h"
+
+using namespace lldb_private;
+using namespace lldb_private::repro;
+using namespace lldb;
+
+namespace {
+class ExecutionContextTest : public ::testing::Test {
+public:
+  void SetUp() override {
+    llvm::cantFail(Reproducer::Initialize(ReproducerMode::Off, llvm::None));
+    FileSystem::Initialize();
+    HostInfo::Initialize();
+    platform_linux::PlatformLinux::Initialize();
+  }
+  void TearDown() override {
+    platform_linux::PlatformLinux::Terminate();
+    HostInfo::Terminate();
+    FileSystem::Terminate();
+    Reproducer::Terminate();
+  }
+};
+
+class DummyProcess : public Process {
+public:
+  using Process::Process;
+
+  virtual bool CanDebug(lldb::TargetSP target, bool plugin_specified_by_name) {
+    return true;
+  }
+  virtual Status DoDestroy() { return {}; }
+  virtual void RefreshStateAfterStop() {}
+  virtual size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
+                              Status &error) {
+    return 0;
+  }
+  virtual bool UpdateThreadList(ThreadList &old_thread_list,
+                                ThreadList &new_thread_list) {
+    return false;
+  }
+  virtual ConstString GetPluginName() { return ConstString("Dummy"); }
+  virtual uint32_t GetPluginVersion() { return 0; }
+};
+} // namespace
+
+TEST_F(ExecutionContextTest, GetByteOrder) {
+  ExecutionContext exe_ctx(nullptr, nullptr, nullptr);
+  EXPECT_EQ(endian::InlHostByteOrder(), exe_ctx.GetByteOrder());
+}
+
+TEST_F(ExecutionContextTest, GetByteOrderTarget) {
+  ArchSpec arch("powerpc64-pc-linux");
+
+  Platform::SetHostPlatform(
+      platform_linux::PlatformLinux::CreateInstance(true, &arch));
+
+  DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+
+  TargetSP target_sp;
+  PlatformSP platform_sp;
+  Status error = debugger_sp->GetTargetList().CreateTarget(
+      *debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
+  ASSERT_TRUE(target_sp);
+  ASSERT_TRUE(target_sp->GetArchitecture().IsValid());
+  ASSERT_TRUE(platform_sp);
+
+  ExecutionContext target_ctx(target_sp, false);
+  EXPECT_EQ(target_sp->GetArchitecture().GetByteOrder(),
+            target_ctx.GetByteOrder());
+}
+
+TEST_F(ExecutionContextTest, GetByteOrderProcess) {
+  ArchSpec arch("powerpc64-pc-linux");
+
+  Platform::SetHostPlatform(
+      platform_linux::PlatformLinux::CreateInstance(true, &arch));
+
+  DebuggerSP debugger_sp = Debugger::CreateInstance();
+  ASSERT_TRUE(debugger_sp);
+
+  TargetSP target_sp;
+  PlatformSP platform_sp;
+  Status error = debugger_sp->GetTargetList().CreateTarget(
+      *debugger_sp, "", arch, eLoadDependentsNo, platform_sp, target_sp);
+  ASSERT_TRUE(target_sp);
+  ASSERT_TRUE(target_sp->GetArchitecture().IsValid());
+  ASSERT_TRUE(platform_sp);
+
+  ListenerSP listener_sp(Listener::MakeListener("dummy"));
+  ProcessSP process_sp = std::make_shared<DummyProcess>(target_sp, listener_sp);
+  ASSERT_TRUE(process_sp);
+
+  ExecutionContext process_ctx(process_sp);
+  EXPECT_EQ(process_sp->GetByteOrder(), process_ctx.GetByteOrder());
+}




More information about the lldb-commits mailing list