[Lldb-commits] [PATCH] 32-bit linux Remove WriteRegOperation's explicit GetAsUInt32() call

Matthew Gardiner mg11 at csr.com
Tue Mar 4 01:34:40 PST 2014


Hi folks

Even with the register map fixed (see UserArea in RegisterContextLinux_i386.cpp)
an assertion failure occurs:

$ lldb hello
Current executable set to 'hello' (i386).
(lldb) log enable linux ptrace
(lldb) run
operation ptrace(PTRACE_SETOPTIONS, 2667, (nil), 0x58, 0)=0 called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 1456
Process 2667 launching
operation ptrace(PTRACE_TRACEME, 0, (nil), (nil), 0)=0 called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 1196
operation ptrace(PTRACE_PEEKDATA, 2667, 0x8048340, (nil), 0)=895EED31 called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 245
operation ptrace(PTRACE_PEEKDATA, 2667, 0x8048340, (nil), 0)=895EED31 called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 245
operation ptrace(PTRACE_POKEDATA, 2667, 0x8048340, 0x895eedcc, 0)=0 called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 319
operation ptrace(PTRACE_PEEKDATA, 2667, 0x8048340, (nil), 0)=895EEDCC called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 245
operation ptrace(PTRACE_POKEUSER, 2667, 0x114, 0xffffffff, 0)=0 called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 543
operation ptrace(PTRACE_POKEUSER, 2667, 0x118, 0xffffffff, 0)=0 called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 543
operation ptrace(PTRACE_PEEKUSER, 2667, 0x114, (nil), 0)=FFFFFFFF called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 494
operation ptrace(PTRACE_PEEKUSER, 2667, 0x114, (nil), 0)=FFFFFFFF called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 494
operation ptrace(PTRACE_POKEUSER, 2667, 0x114, 0xffffffff, 0)=0 called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 543
operation ptrace(PTRACE_PEEKUSER, 2667, 0x118, (nil), 0)=FFFFFFFF called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 494
operation ptrace(PTRACE_PEEKUSER, 2667, 0xfc, (nil), 0)=0 called from file /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/Linux/ProcessMonitor.cpp line 494
lldb: /home/mg11/src/heracles/llvm/tools/lldb/source/Plugins/Process/POSIX/POSIXThread.cpp:530: void POSIXThread::WatchNotify(const ProcessMessage&): Assertion `wp_sp.get() && "No watchpoint found"' 
failed.
Aborted (core dumped)

The root cause of this is that 0xffffffff is written to dr6/7 originally from
RegisterContextPOSIXProcessMonitor_x86.cpp, whereas the programmer intended
0 to be written:

RegisterContextPOSIXProcessMonitor_x86_64::IsWatchpointHit(uint32_t hw_index)
{
<snip>
         RegisterValue zero_bits = RegisterValue(uint64_t(0));
         if (!WriteRegister(m_reg_info.first_dr + 6, zero_bits) || !WriteRegister(m_reg_info.first_dr + 7, zero_bits))

Construction of the RegisterValue as uint64_t and the subsequent conditional
compilation of 32-bit code within ProcessMonitor.cpp

void
WriteRegOperation::Execute(ProcessMonitor *monitor)
{
<snip>
#if __WORDSIZE == 32
     buf = (void*) m_value.GetAsUInt32();
#else

combined with RegisterValue's implementation returning "fail_value" for
wrapped 64-bit data accessed as 32-bits.

Removal of the preprocessing step, relies on the compiler forcing truncation
to 32-bit, when compiled on 32-bit platform, more faithfully than the
explicit GetAsUInt32().

Please could someone apply the attached patch which fixes the fail_value
return. I tested this on 32-bit by launching a program, stopping, setting
a break, then resuming it. It was fine. I can't test 64-bit yet, but clearly
my proposed patch results in the 64-bit code being unchanged.

Index: source/Plugins/Process/Linux/ProcessMonitor.cpp
===================================================================
--- source/Plugins/Process/Linux/ProcessMonitor.cpp	(revision 202675)
+++ source/Plugins/Process/Linux/ProcessMonitor.cpp	(working copy)
@@ -532,11 +532,7 @@
      void* buf;
      Log *log (ProcessPOSIXLog::GetLogIfAllCategoriesSet (POSIX_LOG_REGISTERS));

-#if __WORDSIZE == 32
-    buf = (void*) m_value.GetAsUInt32();
-#else
      buf = (void*) m_value.GetAsUInt64();
-#endif

      if (log)
          log->Printf ("ProcessMonitor::%s() reg %s: %p", __FUNCTION__, m_reg_name, buf);

thanks
Matt

PS

(If this patch is applied *and* the debug register offset problem fixed -
I'm uploading separate patch - then 32-bit linux debug experience is
sane).





Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Keep up to date with CSR on our technical blog, www.csr.com/blog, CSR people blog, www.csr.com/people, YouTube, www.youtube.com/user/CSRplc, Facebook, www.facebook.com/pages/CSR/191038434253534, or follow us on Twitter at www.twitter.com/CSR_plc.
New for 2014, you can now access the wide range of products powered by aptX at www.aptx.com.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ProcessMonitor.cpp.diff
Type: text/x-patch
Size: 606 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140304/77475c26/attachment.bin>


More information about the lldb-commits mailing list