diff options
author | Pavel Labath <labath@google.com> | 2018-05-18 11:35:46 +0000 |
---|---|---|
committer | Pavel Labath <labath@google.com> | 2018-05-18 11:35:46 +0000 |
commit | 981a34c4282de3ac3863b305df2ded130bed8242 (patch) | |
tree | edf1c4a80b86f461539c769d6abebd3890fc60b9 | |
parent | 90d308ef4b3a8af58a9bb2a828d3243b664637cd (diff) | |
download | bcm5719-llvm-981a34c4282de3ac3863b305df2ded130bed8242.tar.gz bcm5719-llvm-981a34c4282de3ac3863b305df2ded130bed8242.zip |
Make ObjectFileMachO work on non-darwin platforms
Summary:
Before this patch we were unable to write cross-platform MachO tests
because the parsing code did not compile on other platforms. The reason
for that was that ObjectFileMachO depended on
RegisterContextDarwin_arm(64)? (presumably for core file parsing) and
the two Register Context classes uses constants from the system headers
(KERN_SUCCESS, KERN_INVALID_ARGUMENT).
As far as I can tell, these two files don't actually interact with the
darwin kernel -- they are used only in ObjectFileMachO and MacOSX-Kernel
process plugin (even though it has "kernel" in the name, this one
communicates with it via network packets and not syscalls). For the time
being I have created OS-independent definitions of these constants and
made the register context classes use those. Long term, the error
handling in these classes should be probably changed to use more
standard mechanisms such as Status or Error classes.
This is the only change necessary (apart from build system glue) to make
ObjectFileMachO work on other platforms. To demonstrate that, I remove
REQUIRES:darwin from our (only) cross-platform mach-o test.
Reviewers: jasonmolenda, aprantl, clayborg, javed.absar
Subscribers: mgorny, lldb-commits, kristof.beyls
Differential Revision: https://reviews.llvm.org/D46934
llvm-svn: 332702
6 files changed, 32 insertions, 31 deletions
diff --git a/lldb/lit/Modules/lc_version_min.yaml b/lldb/lit/Modules/lc_version_min.yaml index afeddc8b40d..5294ecfcb4d 100644 --- a/lldb/lit/Modules/lc_version_min.yaml +++ b/lldb/lit/Modules/lc_version_min.yaml @@ -1,6 +1,6 @@ # RUN: yaml2obj %s > %t.out # RUN: lldb-test symbols %t.out | FileCheck %s -# REQUIRES: darwin + # Test that the deployment target is parsed from the load commands. # CHECK: x86_64-apple-macosx10.9.0 --- !mach-o diff --git a/lldb/source/Initialization/CMakeLists.txt b/lldb/source/Initialization/CMakeLists.txt index 7a100588e00..22a5ce969c3 100644 --- a/lldb/source/Initialization/CMakeLists.txt +++ b/lldb/source/Initialization/CMakeLists.txt @@ -1,7 +1,3 @@ -if ( CMAKE_SYSTEM_NAME MATCHES "Darwin" ) - list(APPEND EXTRA_PLUGINS lldbPluginObjectFileMachO) -endif() - if ( CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|NetBSD" ) list(APPEND EXTRA_PLUGINS lldbPluginProcessPOSIX) endif() @@ -24,6 +20,7 @@ add_lldb_library(lldbInitialization lldbPluginObjectContainerBSDArchive lldbPluginObjectContainerMachOArchive lldbPluginObjectFileELF + lldbPluginObjectFileMachO lldbPluginObjectFilePECOFF lldbPluginProcessGDBRemote ${EXTRA_PLUGINS} diff --git a/lldb/source/Initialization/SystemInitializerCommon.cpp b/lldb/source/Initialization/SystemInitializerCommon.cpp index a8fc46c119d..74a53e4ff1d 100644 --- a/lldb/source/Initialization/SystemInitializerCommon.cpp +++ b/lldb/source/Initialization/SystemInitializerCommon.cpp @@ -21,10 +21,7 @@ #include "lldb/Host/HostInfo.h" #include "lldb/Utility/Log.h" #include "lldb/Utility/Timer.h" - -#if defined(__APPLE__) #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" -#endif #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) #include "Plugins/Process/POSIX/ProcessPOSIXLog.h" @@ -82,6 +79,7 @@ void SystemInitializerCommon::Initialize() { // Initialize plug-ins ObjectContainerBSDArchive::Initialize(); ObjectFileELF::Initialize(); + ObjectFileMachO::Initialize(); ObjectFilePECOFF::Initialize(); EmulateInstructionARM::Initialize(); @@ -93,9 +91,6 @@ void SystemInitializerCommon::Initialize() { //---------------------------------------------------------------------- ObjectContainerUniversalMachO::Initialize(); -#if defined(__APPLE__) - ObjectFileMachO::Initialize(); -#endif #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) ProcessPOSIXLog::Initialize(); #endif @@ -109,6 +104,7 @@ void SystemInitializerCommon::Terminate() { Timer scoped_timer(func_cat, LLVM_PRETTY_FUNCTION); ObjectContainerBSDArchive::Terminate(); ObjectFileELF::Terminate(); + ObjectFileMachO::Terminate(); ObjectFilePECOFF::Terminate(); EmulateInstructionARM::Terminate(); @@ -116,9 +112,6 @@ void SystemInitializerCommon::Terminate() { EmulateInstructionMIPS64::Terminate(); ObjectContainerUniversalMachO::Terminate(); -#if defined(__APPLE__) - ObjectFileMachO::Terminate(); -#endif #if defined(_MSC_VER) ProcessWindowsLog::Terminate(); diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextDarwinConstants.h b/lldb/source/Plugins/Process/Utility/RegisterContextDarwinConstants.h new file mode 100644 index 00000000000..ff57464be2d --- /dev/null +++ b/lldb/source/Plugins/Process/Utility/RegisterContextDarwinConstants.h @@ -0,0 +1,26 @@ +//===-- RegisterContextDarwinConstants.h ------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLDB_REGISTERCONTEXTDARWINCONSTANTS_H +#define LLDB_REGISTERCONTEXTDARWINCONSTANTS_H + +namespace lldb_private { + +/// Constants returned by various RegisterContextDarwin_*** functions. +#ifndef KERN_SUCCESS +#define KERN_SUCCESS 0 +#endif + +#ifndef KERN_INVALID_ARGUMENT +#define KERN_INVALID_ARGUMENT 4 +#endif + +} // namespace lldb_private + +#endif // LLDB_REGISTERCONTEXTDARWINCONSTANTS_H diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp index b07ad7fdaba..f26a64ad957 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm.cpp @@ -7,13 +7,8 @@ // //===----------------------------------------------------------------------===// -#if defined(__APPLE__) - #include "RegisterContextDarwin_arm.h" - -// C Includes -#include <mach/mach_types.h> -#include <mach/thread_act.h> +#include "RegisterContextDarwinConstants.h" // C++ Includes // Other libraries and framework includes @@ -1766,5 +1761,3 @@ bool RegisterContextDarwin_arm::ClearHardwareWatchpoint(uint32_t hw_index) { } return false; } - -#endif diff --git a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp index f11cd7f5cb1..2a2bd8d67da 100644 --- a/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp +++ b/lldb/source/Plugins/Process/Utility/RegisterContextDarwin_arm64.cpp @@ -8,14 +8,8 @@ // //===----------------------------------------------------------------------===// -#if defined(__APPLE__) - #include "RegisterContextDarwin_arm64.h" - -// C Includes -#include <mach/mach_types.h> -#include <mach/thread_act.h> -#include <sys/sysctl.h> +#include "RegisterContextDarwinConstants.h" // C++ Includes // Other libraries and framework includes @@ -1043,5 +1037,3 @@ bool RegisterContextDarwin_arm64::ClearHardwareWatchpoint(uint32_t hw_index) { } return false; } - -#endif |