Index: include/lldb/Target/Platform.h =================================================================== --- include/lldb/Target/Platform.h +++ include/lldb/Target/Platform.h @@ -37,6 +37,11 @@ class ModuleCache; + enum MmapFlags { + eMmapFlagsPrivate = 1, + eMmapFlagsAnon = 2 + }; + class PlatformProperties : public Properties { public: @@ -745,6 +750,9 @@ virtual Error Unlink (const char *path); + virtual uint64_t + ConvertMmapFlagsToPlatform(unsigned flags); + virtual bool GetSupportsRSync () { Index: source/Plugins/Platform/Linux/PlatformLinux.h =================================================================== --- source/Plugins/Platform/Linux/PlatformLinux.h +++ source/Plugins/Platform/Linux/PlatformLinux.h @@ -119,6 +119,9 @@ NativeProcessProtocol::NativeDelegate &native_delegate, NativeProcessProtocolSP &process_sp) override; + uint64_t + ConvertMmapFlagsToPlatform(unsigned flags) override; + static bool UseLlgsForLocalDebugging (); Index: source/Plugins/Platform/Linux/PlatformLinux.cpp =================================================================== --- source/Plugins/Platform/Linux/PlatformLinux.cpp +++ source/Plugins/Platform/Linux/PlatformLinux.cpp @@ -14,6 +14,7 @@ // C Includes #include +#include #ifndef LLDB_DISABLE_POSIX #include #endif @@ -42,6 +43,11 @@ #include "../../Process/Linux/NativeProcessLinux.h" #endif +// Define these constants from Linux mman.h for use when targetting +// remote linux systems even when host has different values. +#define MAP_PRIVATE 2 +#define MAP_ANON 0x20 + using namespace lldb; using namespace lldb_private; using namespace lldb_private::platform_linux; @@ -492,22 +498,14 @@ bool PlatformLinux::GetSupportedArchitectureAtIndex (uint32_t idx, ArchSpec &arch) { - if (idx == 0) - { - arch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault); - return arch.IsValid(); - } - else if (idx == 1) - { - // If the default host architecture is 64-bit, look for a 32-bit variant - ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault); - if (hostArch.IsValid() && hostArch.GetTriple().isArch64Bit()) - { - arch = HostInfo::GetArchitecture(HostInfo::eArchKind32); - return arch.IsValid(); - } - } - return false; + static std::vector architectures = { + ArchSpec("x86_64-unknown-linux-gnu"), + ArchSpec("i386-unknown-linux-gnu"), + }; + if (idx >= architectures.size()) + return false; + arch = architectures[idx]; + return true; } void @@ -911,3 +909,14 @@ return process_linux::NativeProcessLinux::AttachToProcess (pid, native_delegate, process_sp); #endif } + +uint64_t +PlatformLinux::ConvertMmapFlagsToPlatform(unsigned flags) +{ + uint64_t flags_platform = 0; + if (flags & eMmapFlagsPrivate) + flags_platform |= MAP_PRIVATE; + if (flags & eMmapFlagsAnon) + flags_platform |= MAP_ANON; + return flags_platform; +} Index: source/Plugins/Process/Utility/InferiorCallPOSIX.h =================================================================== --- source/Plugins/Process/Utility/InferiorCallPOSIX.h +++ source/Plugins/Process/Utility/InferiorCallPOSIX.h @@ -25,11 +25,6 @@ eMmapProtWrite = 4 }; -enum MmapFlags { - eMmapFlagsPrivate = 1, - eMmapFlagsAnon = 2 -}; - bool InferiorCallMmap(Process *proc, lldb::addr_t &allocated_addr, lldb::addr_t addr, lldb::addr_t length, unsigned prot, unsigned flags, lldb::addr_t fd, lldb::addr_t offset); Index: source/Plugins/Process/Utility/InferiorCallPOSIX.cpp =================================================================== --- source/Plugins/Process/Utility/InferiorCallPOSIX.cpp +++ source/Plugins/Process/Utility/InferiorCallPOSIX.cpp @@ -14,6 +14,7 @@ #include "lldb/Symbol/ClangASTContext.h" #include "lldb/Symbol/SymbolContext.h" #include "lldb/Target/ExecutionContext.h" +#include "lldb/Target/Platform.h" #include "lldb/Target/Process.h" #include "lldb/Target/Target.h" #include "lldb/Target/ThreadPlanCallFunction.h" @@ -27,8 +28,6 @@ #define PROT_READ 1 #define PROT_WRITE 2 #define PROT_EXEC 4 -#define MAP_PRIVATE 2 -#define MAP_ANON 0x1000 #endif using namespace lldb; @@ -87,10 +86,7 @@ prot_arg |= PROT_WRITE; } - if (flags & eMmapFlagsPrivate) - flags_arg |= MAP_PRIVATE; - if (flags & eMmapFlagsAnon) - flags_arg |= MAP_ANON; + flags_arg = process->GetTarget().GetPlatform()->ConvertMmapFlagsToPlatform(flags); AddressRange mmap_range; if (sc.GetAddressRange(range_scope, 0, use_inline_block_range, mmap_range)) Index: source/Target/Platform.cpp =================================================================== --- source/Target/Platform.cpp +++ source/Target/Platform.cpp @@ -40,6 +40,11 @@ #include "Utility/ModuleCache.h" +// Define these constants from POSIX mman.h rather than include the file +// so that they will be correct even when compiled on Linux. +#define MAP_PRIVATE 2 +#define MAP_ANON 0x1000 + using namespace lldb; using namespace lldb_private; @@ -1480,7 +1485,16 @@ return error; } - +uint64_t +Platform::ConvertMmapFlagsToPlatform(unsigned flags) +{ + uint64_t flags_platform = 0; + if (flags & eMmapFlagsPrivate) + flags_platform |= MAP_PRIVATE; + if (flags & eMmapFlagsAnon) + flags_platform |= MAP_ANON; + return flags_platform; +} lldb_private::Error Platform::RunShellCommand (const char *command, // Shouldn't be NULL