<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Thu, Feb 4, 2016 at 11:32 PM Bhushan Attarde via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">bhushan created this revision.<br>
bhushan added a reviewer: clayborg.<br>
bhushan added subscribers: lldb-commits, nitesh.jain, mohit.bhakkad, sagar, jaydeep.<br>
bhushan set the repository for this revision to rL LLVM.<br>
<br>
This test (TestExpressionInSyscall.py) checks if we are able to evaluate expressions when the inferior is blocked in a syscall.<br>
<br>
As a part of expression evaluation LLDB checks for memory allocation on target (by executing mmap).<br>
So we setup call to mmap by setting argument registers and PC.<br>
Now the process is stopped in the syscall and when it continue to allocate memory, the system call is restarted.<br>
<br>
In MIPS, to restart a syscall, kernel decreases the PC by 4 so the resulting PC now points to mmap-4<br>
and also register R7 that provides 'flags' argument to mmap gets clobbered to 0 and hence mmap fails.<br>
<br>
A fix to this issue is to postpone the syscall restart until the expression is evaluated.<br>
In MIPS, register R0 controls syscall restart. This patch writes 0 into register R0 when preparing call to mmap.<br>
This setting avoids a syscall restart and prevents automatic decrement of the PC so that expression can be evaluated correctly.<br>
<br>
Once the expression completes the registers are restored and program resumes the interrupted syscall when the continue command is issued.<br>
<br>
This fixes TestExpressionInSyscall.py and solves bug 23659 for MIPS.<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="http://reviews.llvm.org/D16916" rel="noreferrer" target="_blank">http://reviews.llvm.org/D16916</a><br>
<br>
Files:<br>
  source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp<br>
  source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp<br>
<br>
Index: source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp<br>
===================================================================<br>
--- source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp<br>
+++ source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp<br>
@@ -207,6 +207,17 @@<br>
     const RegisterInfo *sp_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);<br>
     const RegisterInfo *ra_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA);<br>
     const RegisterInfo *r25_info = reg_ctx->GetRegisterInfoByName("r25", 0);<br>
+    const RegisterInfo *r0_info = reg_ctx->GetRegisterInfoByName("zero", 0);<br>
+<br>
+    if (log)<br>
+    log->Printf("Writing R0: 0x%" PRIx64, (uint64_t)0);<br></blockquote><div>Your indentation is wrong here.  Please use clang-format on this patch.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+    /* Write r0 with 0, in case we are stopped in syscall,<br>
+     * such setting prevents automatic decrement of the PC.<br>
+     * This clears the bug 23659 for MIPS.<br>
+    */<br>
+    if (!reg_ctx->WriteRegisterFromUnsigned (r0_info, (uint64_t)0))<br>
+        return false;<br>
<br>
     if (log)<br>
     log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);<br>
Index: source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp<br>
===================================================================<br>
--- source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp<br>
+++ source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp<br>
@@ -242,6 +242,17 @@<br>
     const RegisterInfo *sp_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_SP);<br>
     const RegisterInfo *ra_reg_info = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_RA);<br>
     const RegisterInfo *r25_info = reg_ctx->GetRegisterInfoByName("r25", 0);<br>
+    const RegisterInfo *r0_info = reg_ctx->GetRegisterInfoByName("zero", 0);<br>
+<br>
+    if (log)<br>
+    log->Printf("Writing R0: 0x%" PRIx64, (uint64_t)0);<br></blockquote><div>Also wrong here.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+    /* Write r0 with 0, in case we are stopped in syscall,<br>
+     * such setting prevents automatic decrement of the PC.<br>
+     * This clears the bug 23659 for MIPS.<br>
+    */<br>
+    if (!reg_ctx->WriteRegisterFromUnsigned (r0_info, (uint64_t)0))<br>
+        return false;<br>
<br>
     if (log)<br>
     log->Printf("Writing SP: 0x%" PRIx64, (uint64_t)sp);<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div></div>