<div dir="ltr">Hello,<div><br></div><div>I am working on enhancing Valgrind's embedded gdbserver to allow LLDB to use it (<a href="https://bugs.kde.org/show_bug.cgi?id=356174">https://bugs.kde.org/show_bug.cgi?id=356174</a> ).  After adding support for 'qC' packets to the embedded gdbserver, LLDB is able to continue the halted program running under Valgrind; however, a short moment later LLDB crashes.</div><div><br></div><div>I am using OS X 10.11.1 (15B42) and lldb-340.4.110.1.</div><div><br></div><div>The location of the segmentation fault is ABISysV_x86_64::GetArgumentValues(lldb_private::Thread&, lldb_private::ValueList&) const + 147:</div><div><br></div><div><pre class="" style="outline:none;font-family:inherit;font-size:13px;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word;color:rgb(0,0,0)">[  0] 0x000000010432d7ad LLDB`ABISysV_x86_64::GetArgumentValues(lldb_private::Thread&, lldb_private::ValueList&) const + 147 at ABISysV_x86_64.cpp:485:32
       481          addr_t current_stack_argument = sp + 8; // jump over return address
       482          
       483          uint32_t argument_register_ids[6];
       484          
    -> 485       argument_register_ids[0] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1)->kinds[eRegisterKindLLDB];</pre><pre class="" style="outline:none;font-family:inherit;font-size:13px;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word;color:rgb(0,0,0)"><br></pre><pre class="" style="outline:none;font-family:inherit;font-size:13px;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word;color:rgb(0,0,0)">Someone at Apple Developer Relations (ADR) informed me that unlike gdb, lldb does not have an initial target definition set, and relies on the gdbserver to tell it which registers the gdbserver supports.  This can be done either by responding to 'qRegisterInfo XX' packets or to 'qXfer:features:read:target.xml'.</pre><pre class="" style="outline:none;font-family:inherit;font-size:13px;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word;color:rgb(0,0,0)"><br></pre><pre class="" style="outline:none;font-family:inherit;font-size:13px;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word;color:rgb(0,0,0)">ADR<span style="font-family:inherit"> also informed me about the plugin.process.gdb-remote.target-definition-file LLDB setting and the example target definitions at <a href="http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/">http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/</a></span></pre><pre class="" style="outline:none;font-family:inherit;font-size:13px;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word;color:rgb(0,0,0)">I can confirm that using either x86_64_linux_target_definition.py or <span style="font-size:small">x86_64_target_definition.py fixes the segfault issue.</span></pre><pre class="" style="outline:none;font-family:inherit;font-size:13px;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word;color:rgb(0,0,0)"><span style="font-size:small"><br></span></pre><pre class="" style="outline:none;font-family:inherit;font-size:13px;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word;color:rgb(0,0,0)"><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word">Valgrind's gdbserver does not support <span style="font-family:inherit">qRegisterInfo, but it does support </span><span style="font-family:inherit">qXfer:features:read:target.xml.</span></pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word"><span style="font-family:inherit"><br></span></pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word">Enabling LLDB's gdb-remote logging, I am seeing that the Valgrind embedded gdbserver is sending:</pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word"><br></pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word">target.xml:</pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word">```</pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word"><?xml version="1.0"?>
<!-- Copyright (C) 2010 Free Software Foundation, Inc.

     Copying and distribution of this file, with or without modification,
     are permitted in any medium without royalty provided the copyright
     notice and this notice are preserved.  -->

<!-- AMD64 - core and sse and avx.  -->

<!DOCTYPE target SYSTEM "gdb-target.dtd">
<target>
  <architecture>i386:x86-64</architecture>
  <xi:include href="64bit-core.xml"/>
  <xi:include href="64bit-sse.xml"/>
  <xi:include href="64bit-avx.xml"/>
</target><br></pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word">```</pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word"><br></pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word">64bit-core.xml:</pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word">```</pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word"><?xml version="1.0"?>
<!-- Copyright (C) 2010 Free Software Foundation, Inc.

     Copying and distribution of this file, with or without modification,
     are permitted in any medium without royalty provided the copyright
     notice and this notice are preserved.  -->

<!DOCTYPE feature SYSTEM "gdb-target.dtd">
<feature name="org.gnu.gdb.i386.core">
  <flags id="i386_eflags" size="4">
    <field name="CF" start="0" end="0"/>
    <field name="" start="1" end="1"/>
    <field name="PF" start="2" end="2"/>
    <field name="AF" start="4" end="4"/>
    <field name="ZF" start="6" end="6"/>
    <field name="SF" start="7" end="7"/>
    <field name="TF" start="8" end="8"/>
    <field name="IF" start="9" end="9"/>
    <field name="DF" start="10" end="10"/>
    <field name="OF" start="11" end="11"/>
    <field name="NT" start="14" end="14"/>
    <field name="RF" start="16" end="16"/>
    <field name="VM" start="17" end="17"/>
    <field name="AC" start="18" end="18"/>
    <field name="VIF" start="19" end="19"/>
    <field name="VIP" start="20" end="20"/>
    <field name="ID" start="21" end="21"/>
  </flags>

  <reg name="rax" bitsize="64" type="int64"/>
  <reg name="rbx" bitsize="64" type="int64"/>
  <reg name="rcx" bitsize="64" type="int64"/>
  <reg name="rdx" bitsize="64" type="int64"/>
  <reg name="rsi" bitsize="64" type="int64"/>
  <reg name="rdi" bitsize="64" type="int64"/>
  <reg name="rbp" bitsize="64" type="data_ptr"/>
  <reg name="rsp" bitsize="64" type="data_ptr"/>
  <reg name="r8" bitsize="64" type="int64"/>
  <reg name="r9" bitsize="64" type="int64"/>
  <reg name="r10" bitsize="64" type="int64"/>
  <reg name="r11" bitsize="64" type="int64"/>
  <reg name="r12" bitsize="64" type="int64"/>
  <reg name="r13" bitsize="64" type="int64"/>
  <reg name="r14" bitsize="64" type="int64"/>
  <reg name="r15" bitsize="64" type="int64"/>

  <reg name="rip" bitsize="64" type="code_ptr"/>
  <reg name="eflags" bitsize="32" type="i386_eflags"/>
  <reg name="cs" bitsize="32" type="int32"/>
  <reg name="ss" bitsize="32" type="int32"/>
  <reg name="ds" bitsize="32" type="int32"/>
  <reg name="es" bitsize="32" type="int32"/>
  <reg name="fs" bitsize="32" type="int32"/>
  <reg name="gs" bitsize="32" type="int32"/>

  <reg name="st0" bitsize="80" type="i387_ext"/>
  <reg name="st1" bitsize="80" type="i387_ext"/>
  <reg name="st2" bitsize="80" type="i387_ext"/>
  <reg name="st3" bitsize="80" type="i387_ext"/>
  <reg name="st4" bitsize="80" type="i387_ext"/>
  <reg name="st5" bitsize="80" type="i387_ext"/>
  <reg name="st6" bitsize="80" type="i387_ext"/>
  <reg name="st7" bitsize="80" type="i387_ext"/>

  <reg name="fctrl" bitsize="32" type="int" group="float"/>
  <reg name="fstat" bitsize="32" type="int" group="float"/>
  <reg name="ftag" bitsize="32" type="int" group="float"/>
  <reg name="fiseg" bitsize="32" type="int" group="float"/>
  <reg name="fioff" bitsize="32" type="int" group="float"/>
  <reg name="foseg" bitsize="32" type="int" group="float"/>
  <reg name="fooff" bitsize="32" type="int" group="float"/>
  <reg name="fop" bitsize="32" type="int" group="float"/>
</feature><br></pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word">```</pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word"><br></pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word">(<span style="font-family:inherit">64bit-sse.xml and </span><span style="font-family:inherit">64bit-avx.xml omitted.)</span></pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word"><span style="font-family:inherit"><br></span></pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word"><span style="font-family:inherit">Can anyone see why this XML target definition would be causing the crash?</span></pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word"><span style="font-family:inherit"><br></span></pre><pre class="" style="outline:none;font-family:inherit;margin-top:0px;margin-bottom:0px;padding:0px;white-space:pre-wrap;word-wrap:break-word"><span style="font-family:inherit">Daniel Trebbien</span></pre></pre></div></div>