[Lldb-commits] [lldb] r236933 - Convert mmap options for target in InferiorCallMmap.

Robert Flack flackr at gmail.com
Sat May 9 08:53:32 PDT 2015


Author: flackr
Date: Sat May  9 10:53:31 2015
New Revision: 236933

URL: http://llvm.org/viewvc/llvm-project?rev=236933&view=rev
Log:
Convert mmap options for target in InferiorCallMmap.

Converts the MAP_PRIVATE and MAP_ANON options to the target platform constants
(on which the call runs) rather than using those of the compiled host.

Test Plan:
Run test suite, the following tests requiring memory allocation / JIT support
begin passing when running mac -> linux:
Test11588.py
TestAnonymous.py
TestBreakpointConditions.py
TestCPPStaticMethods.py
TestCStrings.py
TestCallStdStringFunction.py
TestDataFormatterCpp.py
TestDataFormatterStdList.py
TestExprDoesntBlock.py
TestExprHelpExamples.py
TestFunctionTypes.py
TestPrintfAfterUp.py
TestSBValuePersist.py
TestSetValues.py

Differential Revision: http://reviews.llvm.org/D9511

Modified:
    lldb/trunk/include/lldb/Target/Platform.h
    lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
    lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h
    lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
    lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.h
    lldb/trunk/source/Target/Platform.cpp

Modified: lldb/trunk/include/lldb/Target/Platform.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Platform.h?rev=236933&r1=236932&r2=236933&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Platform.h (original)
+++ lldb/trunk/include/lldb/Target/Platform.h Sat May  9 10:53:31 2015
@@ -37,6 +37,11 @@ namespace lldb_private {
 
 class ModuleCache;
 
+    enum MmapFlags {
+      eMmapFlagsPrivate = 1,
+      eMmapFlagsAnon = 2
+    };
+
     class PlatformProperties : public Properties
     {
     public:
@@ -745,6 +750,9 @@ class ModuleCache;
         virtual Error
         Unlink (const char *path);
 
+        virtual uint64_t
+        ConvertMmapFlagsToPlatform(unsigned flags);
+
         virtual bool
         GetSupportsRSync ()
         {

Modified: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp?rev=236933&r1=236932&r2=236933&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp Sat May  9 10:53:31 2015
@@ -14,6 +14,7 @@
 
 // C Includes
 #include <stdio.h>
+#include <vector>
 #ifndef LLDB_DISABLE_POSIX
 #include <sys/utsname.h>
 #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 @@ PlatformLinux::FindProcesses (const Proc
 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<ArchSpec> 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 @@ PlatformLinux::AttachNativeProcess (lldb
     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;
+}

Modified: lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h?rev=236933&r1=236932&r2=236933&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h (original)
+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h Sat May  9 10:53:31 2015
@@ -119,6 +119,9 @@ namespace platform_linux {
                              NativeProcessProtocol::NativeDelegate &native_delegate,
                              NativeProcessProtocolSP &process_sp) override;
 
+        uint64_t
+        ConvertMmapFlagsToPlatform(unsigned flags) override;
+
         static bool
         UseLlgsForLocalDebugging ();
 

Modified: lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp?rev=236933&r1=236932&r2=236933&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp Sat May  9 10:53:31 2015
@@ -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 @@ lldb_private::InferiorCallMmap (Process
                 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))

Modified: lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.h?rev=236933&r1=236932&r2=236933&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.h (original)
+++ lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.h Sat May  9 10:53:31 2015
@@ -25,11 +25,6 @@ enum MmapProt {
   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);

Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=236933&r1=236932&r2=236933&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Sat May  9 10:53:31 2015
@@ -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 @@ Platform::Unlink (const char *path)
     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





More information about the lldb-commits mailing list