[Lldb-commits] [lldb] r311002 - Make i386-*-freebsd expression work on JIT path

Ed Maste via lldb-commits lldb-commits at lists.llvm.org
Wed Aug 16 05:55:02 PDT 2017


Author: emaste
Date: Wed Aug 16 05:55:02 2017
New Revision: 311002

URL: http://llvm.org/viewvc/llvm-project?rev=311002&view=rev
Log:
Make i386-*-freebsd expression work on JIT path

* Enable i386 ABI creation for freebsd
* Added an extra argument in ABISysV_i386::PrepareTrivialCall for mmap
  syscall
* Unlike linux, the last argument of mmap is actually 64-bit(off_t).
  This requires us to push an additional word for the higher order bits.
* Prior to this change, ktrace dump will show mmap failures due to
  invalid argument coming from the 6th mmap argument.

Patch by Karnajit Wangkhem

Differential Revision:	https://reviews.llvm.org/D34776

Modified:
    lldb/trunk/include/lldb/Target/Platform.h
    lldb/trunk/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp
    lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
    lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
    lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp
    lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h
    lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp
    lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.h
    lldb/trunk/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
    lldb/trunk/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
    lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
    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=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Platform.h (original)
+++ lldb/trunk/include/lldb/Target/Platform.h Wed Aug 16 05:55:02 2017
@@ -53,6 +53,7 @@ public:
 };
 
 typedef std::shared_ptr<PlatformProperties> PlatformPropertiesSP;
+typedef llvm::SmallVector<lldb::addr_t, 6> MmapArgList;
 
 //----------------------------------------------------------------------
 /// @class Platform Platform.h "lldb/Target/Platform.h"
@@ -628,8 +629,11 @@ public:
 
   virtual Status Unlink(const FileSpec &file_spec);
 
-  virtual uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch,
-                                              unsigned flags);
+  virtual MmapArgList GetMmapArgumentList(const ArchSpec &arch,
+                                          lldb::addr_t addr,
+                                          lldb::addr_t length,
+                                          unsigned prot, unsigned flags,
+                                          lldb::addr_t fd, lldb::addr_t offset);
 
   virtual bool GetSupportsRSync() { return m_supports_rsync; }
 

Modified: lldb/trunk/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp?rev=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp (original)
+++ lldb/trunk/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp Wed Aug 16 05:55:02 2017
@@ -206,7 +206,7 @@ ABISP
 ABISysV_i386::CreateInstance(lldb::ProcessSP process_sp, const ArchSpec &arch) {
   static ABISP g_abi_sp;
   if ((arch.GetTriple().getArch() == llvm::Triple::x86) &&
-      arch.GetTriple().isOSLinux()) {
+      (arch.GetTriple().isOSLinux() || arch.GetTriple().isOSFreeBSD())) {
     if (!g_abi_sp)
       g_abi_sp.reset(new ABISysV_i386(process_sp));
     return g_abi_sp;

Modified: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp?rev=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp Wed Aug 16 05:55:02 2017
@@ -314,13 +314,19 @@ void PlatformFreeBSD::CalculateTrapHandl
   m_trap_handlers.push_back(ConstString("_sigtramp"));
 }
 
-uint64_t PlatformFreeBSD::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
-                                                     unsigned flags) {
+MmapArgList PlatformFreeBSD::GetMmapArgumentList(const ArchSpec &arch,
+                                                 addr_t addr, addr_t length,
+                                                 unsigned prot, unsigned flags,
+                                                 addr_t fd, addr_t offset) {
   uint64_t flags_platform = 0;
 
   if (flags & eMmapFlagsPrivate)
     flags_platform |= MAP_PRIVATE;
   if (flags & eMmapFlagsAnon)
     flags_platform |= MAP_ANON;
-  return flags_platform;
+
+  MmapArgList args({addr, length, prot, flags_platform, fd, offset});
+  if (arch.GetTriple().getArch() == llvm::Triple::x86)
+    args.push_back(0);
+  return args;
 }

Modified: lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h?rev=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h (original)
+++ lldb/trunk/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h Wed Aug 16 05:55:02 2017
@@ -61,8 +61,10 @@ public:
 
   void CalculateTrapHandlerSymbolNames() override;
 
-  uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch,
-                                      unsigned flags) override;
+  MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr,
+                                  lldb::addr_t length, unsigned prot,
+                                  unsigned flags, lldb::addr_t fd,
+                                  lldb::addr_t offset) override;
 
 private:
   DISALLOW_COPY_AND_ASSIGN(PlatformFreeBSD);

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=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.cpp Wed Aug 16 05:55:02 2017
@@ -390,8 +390,10 @@ void PlatformLinux::CalculateTrapHandler
   m_trap_handlers.push_back(ConstString("_sigtramp"));
 }
 
-uint64_t PlatformLinux::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
-                                                   unsigned flags) {
+MmapArgList PlatformLinux::GetMmapArgumentList(const ArchSpec &arch,
+                                               addr_t addr, addr_t length,
+                                               unsigned prot, unsigned flags,
+                                               addr_t fd, addr_t offset) {
   uint64_t flags_platform = 0;
   uint64_t map_anon = MAP_ANON;
 
@@ -406,6 +408,8 @@ uint64_t PlatformLinux::ConvertMmapFlags
     flags_platform |= MAP_PRIVATE;
   if (flags & eMmapFlagsAnon)
     flags_platform |= map_anon;
-  return flags_platform;
+
+  MmapArgList args({addr, length, prot, flags_platform, fd, offset});
+  return args;
 }
 

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=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h (original)
+++ lldb/trunk/source/Plugins/Platform/Linux/PlatformLinux.h Wed Aug 16 05:55:02 2017
@@ -59,8 +59,10 @@ public:
 
   void CalculateTrapHandlerSymbolNames() override;
 
-  uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch,
-                                      unsigned flags) override;
+  MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr,
+                                  lldb::addr_t length, unsigned prot,
+                                  unsigned flags, lldb::addr_t fd,
+                                  lldb::addr_t offset) override;
 
 private:
   DISALLOW_COPY_AND_ASSIGN(PlatformLinux);

Modified: lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp?rev=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp Wed Aug 16 05:55:02 2017
@@ -420,13 +420,17 @@ void PlatformNetBSD::CalculateTrapHandle
   m_trap_handlers.push_back(ConstString("_sigtramp"));
 }
 
-uint64_t PlatformNetBSD::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
-                                                   unsigned flags) {
+MmapArgList PlatformNetBSD::GetMmapArgumentList(const ArchSpec &arch,
+                                                addr_t addr, addr_t length,
+                                                unsigned prot, unsigned flags,
+                                                addr_t fd, addr_t offset) {
   uint64_t flags_platform = 0;
 
   if (flags & eMmapFlagsPrivate)
     flags_platform |= MAP_PRIVATE;
   if (flags & eMmapFlagsAnon)
     flags_platform |= MAP_ANON;
-  return flags_platform;
+
+  MmapArgList args({addr, length, prot, flags_platform, fd, offset});
+  return args;
 }

Modified: lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.h?rev=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.h (original)
+++ lldb/trunk/source/Plugins/Platform/NetBSD/PlatformNetBSD.h Wed Aug 16 05:55:02 2017
@@ -59,8 +59,10 @@ public:
 
   void CalculateTrapHandlerSymbolNames() override;
 
-  uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch,
-                                      unsigned flags) override;
+  MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr,
+                                  lldb::addr_t length, unsigned prot,
+                                  unsigned flags, lldb::addr_t fd,
+                                  lldb::addr_t offset) override;
 
 private:
   DISALLOW_COPY_AND_ASSIGN(PlatformNetBSD);

Modified: lldb/trunk/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp?rev=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp Wed Aug 16 05:55:02 2017
@@ -211,13 +211,17 @@ void PlatformOpenBSD::CalculateTrapHandl
   m_trap_handlers.push_back(ConstString("_sigtramp"));
 }
 
-uint64_t PlatformOpenBSD::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
-						     unsigned flags) {
+MmapArgList PlatformOpenBSD::GetMmapArgumentList(const ArchSpec &arch,
+                                                 addr_t addr, addr_t length,
+                                                 unsigned prot, unsigned flags,
+                                                 addr_t fd, addr_t offset) {
   uint64_t flags_platform = 0;
 
   if (flags & eMmapFlagsPrivate)
     flags_platform |= MAP_PRIVATE;
   if (flags & eMmapFlagsAnon)
     flags_platform |= MAP_ANON;
-  return flags_platform;
+
+  MmapArgList args({addr, length, prot, flags_platform, fd, offset});
+  return args;
 }

Modified: lldb/trunk/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h?rev=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h (original)
+++ lldb/trunk/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h Wed Aug 16 05:55:02 2017
@@ -53,8 +53,10 @@ public:
 
   void CalculateTrapHandlerSymbolNames() override;
 
-  uint64_t ConvertMmapFlagsToPlatform(const ArchSpec &arch,
-                                      unsigned flags) override;
+  MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr,
+                                  lldb::addr_t length, unsigned prot,
+                                  unsigned flags, lldb::addr_t fd,
+                                  lldb::addr_t offset) override;
 
 private:
   DISALLOW_COPY_AND_ASSIGN(PlatformOpenBSD);

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=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp Wed Aug 16 05:55:02 2017
@@ -64,7 +64,7 @@ bool lldb_private::InferiorCallMmap(Proc
       options.SetTimeout(std::chrono::milliseconds(500));
       options.SetTrapExceptions(false);
 
-      addr_t prot_arg, flags_arg = 0;
+      addr_t prot_arg;
       if (prot == eMmapProtNone)
         prot_arg = PROT_NONE;
       else {
@@ -77,11 +77,6 @@ bool lldb_private::InferiorCallMmap(Proc
           prot_arg |= PROT_WRITE;
       }
 
-      const ArchSpec arch = process->GetTarget().GetArchitecture();
-      flags_arg =
-          process->GetTarget().GetPlatform()->ConvertMmapFlagsToPlatform(arch,
-                                                                         flags);
-
       AddressRange mmap_range;
       if (sc.GetAddressRange(range_scope, 0, use_inline_block_range,
                              mmap_range)) {
@@ -89,7 +84,10 @@ bool lldb_private::InferiorCallMmap(Proc
             process->GetTarget().GetScratchClangASTContext();
         CompilerType clang_void_ptr_type =
             clang_ast_context->GetBasicType(eBasicTypeVoid).GetPointerType();
-        lldb::addr_t args[] = {addr, length, prot_arg, flags_arg, fd, offset};
+        const ArchSpec arch = process->GetTarget().GetArchitecture();
+        MmapArgList args =
+            process->GetTarget().GetPlatform()->GetMmapArgumentList(
+                arch, addr, length, prot_arg, flags, fd, offset);
         lldb::ThreadPlanSP call_plan_sp(
             new ThreadPlanCallFunction(*thread, mmap_range.GetBaseAddress(),
                                        clang_void_ptr_type, args, options));

Modified: lldb/trunk/source/Target/Platform.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Platform.cpp?rev=311002&r1=311001&r2=311002&view=diff
==============================================================================
--- lldb/trunk/source/Target/Platform.cpp (original)
+++ lldb/trunk/source/Target/Platform.cpp Wed Aug 16 05:55:02 2017
@@ -1316,14 +1316,18 @@ Status Platform::Unlink(const FileSpec &
   return error;
 }
 
-uint64_t Platform::ConvertMmapFlagsToPlatform(const ArchSpec &arch,
-                                              unsigned flags) {
+MmapArgList Platform::GetMmapArgumentList(const ArchSpec &arch, addr_t addr,
+                                          addr_t length, unsigned prot,
+                                          unsigned flags, addr_t fd,
+                                          addr_t offset) {
   uint64_t flags_platform = 0;
   if (flags & eMmapFlagsPrivate)
     flags_platform |= MAP_PRIVATE;
   if (flags & eMmapFlagsAnon)
     flags_platform |= MAP_ANON;
-  return flags_platform;
+
+  MmapArgList args({addr, length, prot, flags_platform, fd, offset});
+  return args;
 }
 
 lldb_private::Status Platform::RunShellCommand(




More information about the lldb-commits mailing list