svn commit: r322326 - in head/contrib/llvm/tools/lldb: include/lldb/Target source/Plugins/ABI/SysV-i386 source/Plugins/Platform/FreeBSD source/Plugins/Platform/NetBSD source/Plugins/Platform/OpenBS...

Ed Maste emaste at FreeBSD.org
Wed Aug 9 19:09:25 UTC 2017


Author: emaste
Date: Wed Aug  9 19:09:23 2017
New Revision: 322326
URL: https://svnweb.freebsd.org/changeset/base/322326

Log:
  lldb: 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.
  
  Submitted by:	Karnajit Wangkhem
  Differential Revision:	https://reviews.llvm.org/D34776

Modified:
  head/contrib/llvm/tools/lldb/include/lldb/Target/Platform.h
  head/contrib/llvm/tools/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp
  head/contrib/llvm/tools/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
  head/contrib/llvm/tools/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
  head/contrib/llvm/tools/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp
  head/contrib/llvm/tools/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.h
  head/contrib/llvm/tools/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
  head/contrib/llvm/tools/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
  head/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
  head/contrib/llvm/tools/lldb/source/Target/Platform.cpp

Modified: head/contrib/llvm/tools/lldb/include/lldb/Target/Platform.h
==============================================================================
--- head/contrib/llvm/tools/lldb/include/lldb/Target/Platform.h	Wed Aug  9 18:23:46 2017	(r322325)
+++ head/contrib/llvm/tools/lldb/include/lldb/Target/Platform.h	Wed Aug  9 19:09:23 2017	(r322326)
@@ -53,6 +53,7 @@ class PlatformProperties : public Properties { (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 @@ class Platform : public PluginInterface { (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: head/contrib/llvm/tools/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp
==============================================================================
--- head/contrib/llvm/tools/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp	Wed Aug  9 18:23:46 2017	(r322325)
+++ head/contrib/llvm/tools/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp	Wed Aug  9 19:09:23 2017	(r322326)
@@ -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: head/contrib/llvm/tools/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp
==============================================================================
--- head/contrib/llvm/tools/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp	Wed Aug  9 18:23:46 2017	(r322325)
+++ head/contrib/llvm/tools/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.cpp	Wed Aug  9 19:09:23 2017	(r322326)
@@ -314,13 +314,19 @@ void PlatformFreeBSD::CalculateTrapHandlerSymbolNames(
   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: head/contrib/llvm/tools/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h
==============================================================================
--- head/contrib/llvm/tools/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h	Wed Aug  9 18:23:46 2017	(r322325)
+++ head/contrib/llvm/tools/lldb/source/Plugins/Platform/FreeBSD/PlatformFreeBSD.h	Wed Aug  9 19:09:23 2017	(r322326)
@@ -61,8 +61,10 @@ class PlatformFreeBSD : public PlatformPOSIX { (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: head/contrib/llvm/tools/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp
==============================================================================
--- head/contrib/llvm/tools/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp	Wed Aug  9 18:23:46 2017	(r322325)
+++ head/contrib/llvm/tools/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.cpp	Wed Aug  9 19:09:23 2017	(r322326)
@@ -420,13 +420,17 @@ void PlatformNetBSD::CalculateTrapHandlerSymbolNames()
   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: head/contrib/llvm/tools/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.h
==============================================================================
--- head/contrib/llvm/tools/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.h	Wed Aug  9 18:23:46 2017	(r322325)
+++ head/contrib/llvm/tools/lldb/source/Plugins/Platform/NetBSD/PlatformNetBSD.h	Wed Aug  9 19:09:23 2017	(r322326)
@@ -59,8 +59,10 @@ class PlatformNetBSD : public PlatformPOSIX { (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: head/contrib/llvm/tools/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
==============================================================================
--- head/contrib/llvm/tools/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp	Wed Aug  9 18:23:46 2017	(r322325)
+++ head/contrib/llvm/tools/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp	Wed Aug  9 19:09:23 2017	(r322326)
@@ -219,5 +219,7 @@ uint64_t PlatformOpenBSD::ConvertMmapFlagsToPlatform(c
     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: head/contrib/llvm/tools/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h
==============================================================================
--- head/contrib/llvm/tools/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h	Wed Aug  9 18:23:46 2017	(r322325)
+++ head/contrib/llvm/tools/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.h	Wed Aug  9 19:09:23 2017	(r322326)
@@ -53,8 +53,10 @@ class PlatformOpenBSD : public PlatformPOSIX { (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: head/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
==============================================================================
--- head/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp	Wed Aug  9 18:23:46 2017	(r322325)
+++ head/contrib/llvm/tools/lldb/source/Plugins/Process/Utility/InferiorCallPOSIX.cpp	Wed Aug  9 19:09:23 2017	(r322326)
@@ -64,7 +64,7 @@ bool lldb_private::InferiorCallMmap(Process *process, 
       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(Process *process, 
           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(Process *process, 
             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: head/contrib/llvm/tools/lldb/source/Target/Platform.cpp
==============================================================================
--- head/contrib/llvm/tools/lldb/source/Target/Platform.cpp	Wed Aug  9 18:23:46 2017	(r322325)
+++ head/contrib/llvm/tools/lldb/source/Target/Platform.cpp	Wed Aug  9 19:09:23 2017	(r322326)
@@ -1316,14 +1316,18 @@ Status Platform::Unlink(const FileSpec &path) {
   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 svn-src-head mailing list