<div dir="ltr">Hello Greg,<div><br></div><div>Thank you very much for this explanation. It makes perfect sense to me now the reason for the crash at <span style="color:rgb(0,0,0);font-family:inherit;font-size:13px;white-space:pre-wrap">ABISysV_x86_64.cpp:485, and that supplying the generic register information will solve the problem.</span></div><div><span style="color:rgb(0,0,0);font-family:inherit;font-size:13px;white-space:pre-wrap"><br></span></div><div><span style="color:rgb(0,0,0);font-family:inherit;font-size:13px;white-space:pre-wrap">Testing out the following, the crash no longer occurs:</span></div><div><span style="color:rgb(0,0,0);font-family:inherit;font-size:13px;white-space:pre-wrap"><br></span></div><div><div> <reg name="rax" bitsize="64" type="int64" group="general"/></div><div> <reg name="rbx" bitsize="64" type="int64" group="general"/></div><div> <reg name="rcx" bitsize="64" type="int64" group="general" altname="arg4" generic="arg4"/></div><div> <reg name="rdx" bitsize="64" type="int64" group="general" altname="arg3" generic="arg3"/></div><div> <reg name="rsi" bitsize="64" type="int64" group="general" altname="arg2" generic="arg2"/></div><div> <reg name="rdi" bitsize="64" type="int64" group="general" altname="arg1" generic="arg1"/></div><div> <reg name="rbp" bitsize="64" type="data_ptr" group="general" altname="fp" generic="fp"/></div><div> <reg name="rsp" bitsize="64" type="data_ptr" group="general" altname="sp" generic="sp"/></div><div> <reg name="r8" bitsize="64" type="int64" group="general" altname="arg5" generic="arg5"/></div><div> <reg name="r9" bitsize="64" type="int64" group="general" altname="arg6" generic="arg6"/></div><div> <reg name="r10" bitsize="64" type="int64" group="general"/></div><div> <reg name="r11" bitsize="64" type="int64" group="general"/></div><div> <reg name="r12" bitsize="64" type="int64" group="general"/></div><div> <reg name="r13" bitsize="64" type="int64" group="general"/></div><div> <reg name="r14" bitsize="64" type="int64" group="general"/></div><div> <reg name="r15" bitsize="64" type="int64" group="general"/></div><div><br></div><div> <reg name="rip" bitsize="64" type="code_ptr" altname="pc" generic="pc"/></div><div> <reg name="eflags" bitsize="32" type="i386_eflags" altname="flags" generic="flags"/></div></div><div><br></div><div><br></div><div>Daniel Trebbien</div><div><span style="color:rgb(0,0,0);font-family:inherit;font-size:13px;white-space:pre-wrap"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 4, 2015 at 1:55 PM, Greg Clayton <span dir="ltr"><<a href="mailto:gclayton@apple.com" target="_blank">gclayton@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The issue is LLDB wants to know information in the registers in the register context regarding how they map to "generic" registers. For x86_64 this means:<br>
<br>
LLDB_REGNUM_GENERIC_PC -> rip<br>
LLDB_REGNUM_GENERIC_SP -> rsp<br>
LLDB_REGNUM_GENERIC_FP -> rbp<br>
LLDB_REGNUM_GENERIC_RA -> <none for x86><br>
LLDB_REGNUM_GENERIC_FLAGS -> rflags<br>
LLDB_REGNUM_GENERIC_ARG1 -> rdi<br>
LLDB_REGNUM_GENERIC_ARG2 -> rsi<br>
LLDB_REGNUM_GENERIC_ARG3 -> rdx<br>
LLDB_REGNUM_GENERIC_ARG4 -> rcx<br>
LLDB_REGNUM_GENERIC_ARG5 -> r8<br>
LLDB_REGNUM_GENERIC_ARG6 -> r9<br>
<br>
We also want to know what DWARF register number each register has, what compiler register number (for EH frame) each register is, and more.<br>
<br>
There are two ways to do this:<br>
<br>
1 - if you want to change the LLDB code<br>
2 - if you want to make this work by only modifying valgrind's GDB server<br>
<br>
If you go with option 1, it looks like the bug here is in:<br>
<br>
static void<br>
AugmentRegisterInfoViaABI (RegisterInfo ®_info, ConstString reg_name, ABISP abi_sp)<br>
<br>
It grabs the register info from the ABI and fills it in, but it wasn't filling in the generic register number. I just fixed this with:<br>
<br>
r254743 | gclayton | 2015-12-04 10:37:48 -0800 (Fri, 04 Dec 2015) | 1 line<br>
<br>
Fill in the generic register kind if in AugmentRegisterInfoViaABI if it is available.<br>
<br>
So if you update your sources, it might start working.<br>
<br>
If you don't want the change LLDB, you can make the XML returned for the registers contain extra attributes to specify these things. If you check the code in ProcessGDBRemote.cpp around line 4327:<br>
<br>
bool<br>
ParseRegisters (XMLNode feature_node, GdbServerTargetInfo &target_info, GDBRemoteDynamicRegisterInfo &dyn_reg_info, ABISP abi_sp)<br>
<br>
You can see the extra attributes a "reg" element node can contain.<br>
<br>
We extended the XML to include keys that LLDB can use. The assert that is causing the crash is the fact that we are asking a register context for the "generic" register that is "arg1". If you can modify the XML that is returned to mark up the registers so the generic name is attached to each register, it will help out LLDB. "debugserver" actually used this modified XML, so to see what it would look like with all of the new things we added you can copy what you need from the XML below. But lets look at the definition for "rip" alone:<br>
<br>
<reg name="rip" regnum="16" offset="128" bitsize="64" group="general" altname="pc" group_id="1" gcc_regnum="16" dwarf_regnum="16" generic="pc"/><br>
<br>
Note we specify regnum (the lldb register number), offset (the byte offset for this register in the register context), altname, group_id (the register group this should appear in, see the "groups" at the end of the XML to see the register set names), gcc_regnum which is the compiler register number, dwarf_regnum, and the generic register name ("pc", "sp", "fp", "arg1", "arg2", etc).<br>
<br>
So our full XML which specifies the compiler register numbers, DWARF register numbers and generic register names looks like:<br>
<br>
l<?xml version="1.0"?><br>
<target version="1.0"><br>
<feature name="com.apple.debugserver.x86_64"><br>
<reg name="rax" regnum="0" offset="0" bitsize="64" group="general" group_id="1" gcc_regnum="0" dwarf_regnum="0"/><br>
<reg name="rbx" regnum="1" offset="8" bitsize="64" group="general" group_id="1" gcc_regnum="3" dwarf_regnum="3"/><br>
<reg name="rcx" regnum="2" offset="16" bitsize="64" group="general" altname="arg4" group_id="1" gcc_regnum="2" dwarf_regnum="2" generic="arg4"/><br>
<reg name="rdx" regnum="3" offset="24" bitsize="64" group="general" altname="arg3" group_id="1" gcc_regnum="1" dwarf_regnum="1" generic="arg3"/><br>
<reg name="rdi" regnum="4" offset="32" bitsize="64" group="general" altname="arg1" group_id="1" gcc_regnum="5" dwarf_regnum="5" generic="arg1"/><br>
<reg name="rsi" regnum="5" offset="40" bitsize="64" group="general" altname="arg2" group_id="1" gcc_regnum="4" dwarf_regnum="4" generic="arg2"/><br>
<reg name="rbp" regnum="6" offset="48" bitsize="64" group="general" altname="fp" group_id="1" gcc_regnum="6" dwarf_regnum="6" generic="fp"/><br>
<reg name="rsp" regnum="7" offset="56" bitsize="64" group="general" altname="sp" group_id="1" gcc_regnum="7" dwarf_regnum="7" generic="sp"/><br>
<reg name="r8" regnum="8" offset="64" bitsize="64" group="general" altname="arg5" group_id="1" gcc_regnum="8" dwarf_regnum="8" generic="arg5"/><br>
<reg name="r9" regnum="9" offset="72" bitsize="64" group="general" altname="arg6" group_id="1" gcc_regnum="9" dwarf_regnum="9" generic="arg6"/><br>
<reg name="r10" regnum="10" offset="80" bitsize="64" group="general" group_id="1" gcc_regnum="10" dwarf_regnum="10"/><br>
<reg name="r11" regnum="11" offset="88" bitsize="64" group="general" group_id="1" gcc_regnum="11" dwarf_regnum="11"/><br>
<reg name="r12" regnum="12" offset="96" bitsize="64" group="general" group_id="1" gcc_regnum="12" dwarf_regnum="12"/><br>
<reg name="r13" regnum="13" offset="104" bitsize="64" group="general" group_id="1" gcc_regnum="13" dwarf_regnum="13"/><br>
<reg name="r14" regnum="14" offset="112" bitsize="64" group="general" group_id="1" gcc_regnum="14" dwarf_regnum="14"/><br>
<reg name="r15" regnum="15" offset="120" bitsize="64" group="general" group_id="1" gcc_regnum="15" dwarf_regnum="15"/><br>
<reg name="rip" regnum="16" offset="128" bitsize="64" group="general" altname="pc" group_id="1" gcc_regnum="16" dwarf_regnum="16" generic="pc"/><br>
<reg name="rflags" regnum="17" offset="136" bitsize="64" group="general" altname="flags" group_id="1" generic="flags"/><br>
<reg name="cs" regnum="18" offset="144" bitsize="64" group="general" group_id="1"/><br>
<reg name="fs" regnum="19" offset="152" bitsize="64" group="general" group_id="1"/><br>
<reg name="gs" regnum="20" offset="160" bitsize="64" group="general" group_id="1"/><br>
<reg name="fctrl" regnum="73" offset="168" bitsize="16" group="general" group_id="2"/><br>
<reg name="fstat" regnum="74" offset="170" bitsize="16" group="general" group_id="2"/><br>
<reg name="ftag" regnum="75" offset="172" bitsize="8" group="general" group_id="2"/><br>
<reg name="fop" regnum="76" offset="173" bitsize="16" group="general" group_id="2"/><br>
<reg name="fioff" regnum="77" offset="175" bitsize="32" group="general" group_id="2"/><br>
<reg name="fiseg" regnum="78" offset="179" bitsize="16" group="general" group_id="2"/><br>
<reg name="fooff" regnum="79" offset="181" bitsize="32" group="general" group_id="2"/><br>
<reg name="foseg" regnum="80" offset="185" bitsize="16" group="general" group_id="2"/><br>
<reg name="mxcsr" regnum="81" offset="187" bitsize="32" group="general" group_id="2"/><br>
<reg name="mxcsrmask" regnum="82" offset="191" bitsize="32" group="general" group_id="2"/><br>
<reg name="stmm0" regnum="83" offset="195" bitsize="80" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="33" dwarf_regnum="33"/><br>
<reg name="stmm1" regnum="84" offset="205" bitsize="80" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="34" dwarf_regnum="34"/><br>
<reg name="stmm2" regnum="85" offset="215" bitsize="80" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="35" dwarf_regnum="35"/><br>
<reg name="stmm3" regnum="86" offset="225" bitsize="80" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="36" dwarf_regnum="36"/><br>
<reg name="stmm4" regnum="87" offset="235" bitsize="80" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="37" dwarf_regnum="37"/><br>
<reg name="stmm5" regnum="88" offset="245" bitsize="80" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="38" dwarf_regnum="38"/><br>
<reg name="stmm6" regnum="89" offset="255" bitsize="80" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="39" dwarf_regnum="39"/><br>
<reg name="stmm7" regnum="90" offset="265" bitsize="80" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="40" dwarf_regnum="40"/><br>
<reg name="ymm0" regnum="91" offset="275" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="17" dwarf_regnum="17"/><br>
<reg name="ymm1" regnum="92" offset="307" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="18" dwarf_regnum="18"/><br>
<reg name="ymm2" regnum="93" offset="339" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="19" dwarf_regnum="19"/><br>
<reg name="ymm3" regnum="94" offset="371" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="20" dwarf_regnum="20"/><br>
<reg name="ymm4" regnum="95" offset="403" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="21" dwarf_regnum="21"/><br>
<reg name="ymm5" regnum="96" offset="435" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="22" dwarf_regnum="22"/><br>
<reg name="ymm6" regnum="97" offset="467" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="23" dwarf_regnum="23"/><br>
<reg name="ymm7" regnum="98" offset="499" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="24" dwarf_regnum="24"/><br>
<reg name="ymm8" regnum="99" offset="531" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="25" dwarf_regnum="25"/><br>
<reg name="ymm9" regnum="100" offset="563" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="26" dwarf_regnum="26"/><br>
<reg name="ymm10" regnum="101" offset="595" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="27" dwarf_regnum="27"/><br>
<reg name="ymm11" regnum="102" offset="627" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="28" dwarf_regnum="28"/><br>
<reg name="ymm12" regnum="103" offset="659" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="29" dwarf_regnum="29"/><br>
<reg name="ymm13" regnum="104" offset="691" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="30" dwarf_regnum="30"/><br>
<reg name="ymm14" regnum="105" offset="723" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="31" dwarf_regnum="31"/><br>
<reg name="ymm15" regnum="106" offset="755" bitsize="256" group="vector" type="float" encoding="vector" format="vector-uint8" group_id="2" gcc_regnum="32" dwarf_regnum="32"/><br>
<reg name="trapno" regnum="123" offset="787" bitsize="32" group="general" group_id="3"/><br>
<reg name="err" regnum="124" offset="791" bitsize="32" group="general" group_id="3"/><br>
<reg name="faultvaddr" regnum="125" offset="795" bitsize="64" group="general" group_id="3"/><br>
</feature><br>
<groups><br>
<group id="1" name="General Purpose Registers"/><br>
<group id="2" name="Floating Point Registers"/><br>
<group id="3" name="Exception State Registers"/><br>
</groups><br>
</target><br>
<br>
<br>
<br>
So if you get the generic register numbers fixed, you should probably not be crashing anymore.<br>
<br>
Greg Clayton<br>
<div><div class="h5"><br>
<br>
<br>
<br>
> On Dec 3, 2015, at 4:24 PM, Daniel Trebbien via lldb-dev <<a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hello,<br>
><br>
> 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" rel="noreferrer" target="_blank">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.<br>
><br>
> I am using OS X 10.11.1 (15B42) and lldb-340.4.110.1.<br>
><br>
> The location of the segmentation fault is ABISysV_x86_64::GetArgumentValues(lldb_private::Thread&, lldb_private::ValueList&) const + 147:<br>
><br>
> [ 0] 0x000000010432d7ad LLDB`ABISysV_x86_64::GetArgumentValues(lldb_private::Thread&, lldb_private::ValueList&) const + 147 at ABISysV_x86_64.cpp:485:32<br>
> 481 addr_t current_stack_argument = sp + 8; // jump over return address<br>
> 482<br>
> 483 uint32_t argument_register_ids[6];<br>
> 484<br>
> -> 485 argument_register_ids[0] = reg_ctx->GetRegisterInfo (eRegisterKindGeneric, LLDB_REGNUM_GENERIC_ARG1)->kinds[eRegisterKindLLDB];<br>
><br>
><br>
> 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'.<br>
><br>
> ADR 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/" rel="noreferrer" target="_blank">http://llvm.org/svn/llvm-project/lldb/trunk/examples/python/</a><br>
> I can confirm that using either x86_64_linux_target_definition.py or x86_64_target_definition.py fixes the segfault issue.<br>
><br>
> Valgrind's gdbserver does not support qRegisterInfo, but it does support qXfer:features:read:target.xml.<br>
><br>
> Enabling LLDB's gdb-remote logging, I am seeing that the Valgrind embedded gdbserver is sending:<br>
><br>
> target.xml:<br>
> ```<br>
> <?xml version="1.0"?><br>
> <!-- Copyright (C) 2010 Free Software Foundation, Inc.<br>
><br>
> Copying and distribution of this file, with or without modification,<br>
> are permitted in any medium without royalty provided the copyright<br>
> notice and this notice are preserved. --><br>
><br>
> <!-- AMD64 - core and sse and avx. --><br>
><br>
> <!DOCTYPE target SYSTEM "gdb-target.dtd"><br>
> <target><br>
> <architecture>i386:x86-64</architecture><br>
> <xi:include href="64bit-core.xml"/><br>
> <xi:include href="64bit-sse.xml"/><br>
> <xi:include href="64bit-avx.xml"/><br>
> </target><br>
><br>
> ```<br>
><br>
> 64bit-core.xml:<br>
> ```<br>
> <?xml version="1.0"?><br>
> <!-- Copyright (C) 2010 Free Software Foundation, Inc.<br>
><br>
> Copying and distribution of this file, with or without modification,<br>
> are permitted in any medium without royalty provided the copyright<br>
> notice and this notice are preserved. --><br>
><br>
> <!DOCTYPE feature SYSTEM "gdb-target.dtd"><br>
> <feature name="org.gnu.gdb.i386.core"><br>
> <flags id="i386_eflags" size="4"><br>
> <field name="CF" start="0" end="0"/><br>
> <field name="" start="1" end="1"/><br>
> <field name="PF" start="2" end="2"/><br>
> <field name="AF" start="4" end="4"/><br>
> <field name="ZF" start="6" end="6"/><br>
> <field name="SF" start="7" end="7"/><br>
> <field name="TF" start="8" end="8"/><br>
> <field name="IF" start="9" end="9"/><br>
> <field name="DF" start="10" end="10"/><br>
> <field name="OF" start="11" end="11"/><br>
> <field name="NT" start="14" end="14"/><br>
> <field name="RF" start="16" end="16"/><br>
> <field name="VM" start="17" end="17"/><br>
> <field name="AC" start="18" end="18"/><br>
> <field name="VIF" start="19" end="19"/><br>
> <field name="VIP" start="20" end="20"/><br>
> <field name="ID" start="21" end="21"/><br>
> </flags><br>
><br>
> <reg name="rax" bitsize="64" type="int64"/><br>
> <reg name="rbx" bitsize="64" type="int64"/><br>
> <reg name="rcx" bitsize="64" type="int64"/><br>
> <reg name="rdx" bitsize="64" type="int64"/><br>
> <reg name="rsi" bitsize="64" type="int64"/><br>
> <reg name="rdi" bitsize="64" type="int64"/><br>
> <reg name="rbp" bitsize="64" type="data_ptr"/><br>
> <reg name="rsp" bitsize="64" type="data_ptr"/><br>
> <reg name="r8" bitsize="64" type="int64"/><br>
> <reg name="r9" bitsize="64" type="int64"/><br>
> <reg name="r10" bitsize="64" type="int64"/><br>
> <reg name="r11" bitsize="64" type="int64"/><br>
> <reg name="r12" bitsize="64" type="int64"/><br>
> <reg name="r13" bitsize="64" type="int64"/><br>
> <reg name="r14" bitsize="64" type="int64"/><br>
> <reg name="r15" bitsize="64" type="int64"/><br>
><br>
> <reg name="rip" bitsize="64" type="code_ptr"/><br>
> <reg name="eflags" bitsize="32" type="i386_eflags"/><br>
> <reg name="cs" bitsize="32" type="int32"/><br>
> <reg name="ss" bitsize="32" type="int32"/><br>
> <reg name="ds" bitsize="32" type="int32"/><br>
> <reg name="es" bitsize="32" type="int32"/><br>
> <reg name="fs" bitsize="32" type="int32"/><br>
> <reg name="gs" bitsize="32" type="int32"/><br>
><br>
> <reg name="st0" bitsize="80" type="i387_ext"/><br>
> <reg name="st1" bitsize="80" type="i387_ext"/><br>
> <reg name="st2" bitsize="80" type="i387_ext"/><br>
> <reg name="st3" bitsize="80" type="i387_ext"/><br>
> <reg name="st4" bitsize="80" type="i387_ext"/><br>
> <reg name="st5" bitsize="80" type="i387_ext"/><br>
> <reg name="st6" bitsize="80" type="i387_ext"/><br>
> <reg name="st7" bitsize="80" type="i387_ext"/><br>
><br>
> <reg name="fctrl" bitsize="32" type="int" group="float"/><br>
> <reg name="fstat" bitsize="32" type="int" group="float"/><br>
> <reg name="ftag" bitsize="32" type="int" group="float"/><br>
> <reg name="fiseg" bitsize="32" type="int" group="float"/><br>
> <reg name="fioff" bitsize="32" type="int" group="float"/><br>
> <reg name="foseg" bitsize="32" type="int" group="float"/><br>
> <reg name="fooff" bitsize="32" type="int" group="float"/><br>
> <reg name="fop" bitsize="32" type="int" group="float"/><br>
> </feature><br>
><br>
> ```<br>
><br>
> (64bit-sse.xml and 64bit-avx.xml omitted.)<br>
><br>
> Can anyone see why this XML target definition would be causing the crash?<br>
><br>
> Daniel Trebbien<br>
</div></div>> _______________________________________________<br>
> lldb-dev mailing list<br>
> <a href="mailto:lldb-dev@lists.llvm.org">lldb-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-dev</a><br>
<br>
</blockquote></div><br></div>