[Lldb-commits] [PATCH] D34776: Make i386-*-freebsd expression work on JIT path

Karnajit Wangkhem via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed Jun 28 14:05:09 PDT 2017


karnajitw created this revision.
Herald added a subscriber: emaste.

Expression evaluation which takes the non IRInterpreter::Interpret path fails on i386-*-freebsd. Following changes are done to enable it.

1. Enable i386 ABI creation for freebsd
2. Added an extra argument in ABISysV_i386::PrepareTrivialCall for mmap syscall
3. 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.
4. Prior to this change, ktrace dump will show mmap failures due to invalid argument coming from the 6th mmap argument.

Prior Fix:
(lldb) expression printf("%d", d1)
error: Can't run the expression locally: Interpreter doesn't handle one of the expression's opcodes
(lldb) expression d1 + 5   << IRInterpreter path
(int) $0 = 10
(lldb) expression d1 + 5.0
error: Can't run the expression locally: Interpreter doesn't handle one of the expression's opcodes
(lldb) expression f1 * 5
error: Can't run the expression locally: Interpreter doesn't handle one of the expression's opcodes
(lldb) expression f1 / 5
error: Can't run the expression locally: Interpreter doesn't handle one of the expression's opcodes

With Fix:
(lldb) expression printf("%d", d1)
(int) $0 = 1
(lldb) expression printf("%2.3f", f1)
(int) $2 = 5
(lldb) expression d1 + 5
(int) $3 = 10
(lldb) expression d1 + 5.0
(double) $4 = 10
(lldb) expression f1 * 5
(float) $7 = 25.5
(lldb) expression f1 / 5
(float) $8 = 1.01999998

NOTE: Expression involving floating point arithmetic will result in NaN on i386-*-freebsd11.0. Patch https://svnweb.freebsd.org/base?view=revision&revision=320051 is required to make it work.


Repository:
  rL LLVM

https://reviews.llvm.org/D34776

Files:
  source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp
  source/Plugins/Process/Utility/InferiorCallPOSIX.cpp


Index: source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
===================================================================
--- source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
+++ source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
@@ -89,7 +89,11 @@
             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};
+        llvm::SmallVector<lldb::addr_t, 6> args({ addr, length, prot_arg,
+            flags_arg, fd, offset });
+        if (arch.GetTriple().getOS() == llvm::Triple::FreeBSD
+            && arch.GetTriple().getArch() == llvm::Triple::x86)
+          args.push_back(0);
         lldb::ThreadPlanSP call_plan_sp(
             new ThreadPlanCallFunction(*thread, mmap_range.GetBaseAddress(),
                                        clang_void_ptr_type, args, options));
Index: source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp
===================================================================
--- source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp
+++ source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp
@@ -206,7 +206,7 @@
 ABISysV_i386::CreateInstance(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);
     return g_abi_sp;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34776.104495.patch
Type: text/x-patch
Size: 1575 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20170628/09315f60/attachment.bin>


More information about the lldb-commits mailing list