<div dir="ltr">Hi all,<div><br></div><div>This is a patch which allows ProcessGDBServer to obtain the auxv from a remote gdbserver via GDBServerProcessRemote, returning the data as a DataBufferSP.</div><div><br></div><div>
The patch includes a small fix to GDBRemoteCommunicationClient::SendPacketsAndConcatenateResponses() to support binary file format packet returns (by not assuming each binary packet is a null-terminated string when concatenating them).</div>
<div><br></div><div>I've also added a base-class Process::GetAuxvData which delegates to the Host.</div><div><br></div><div>No code currently calls this method.</div><div><br></div><div> - Steve</div><div><br></div><div>
<div>Index: include/lldb/Target/Process.h</div><div>===================================================================</div><div>--- include/lldb/Target/Process.h<span class="" style="white-space:pre">      </span>(revision 202766)</div>
<div>+++ include/lldb/Target/Process.h<span class="" style="white-space:pre">   </span>(working copy)</div><div>@@ -2063,6 +2063,9 @@</div><div>         return m_unix_signals;</div><div>     }</div><div> </div><div>+    virtual const lldb::DataBufferSP</div>
<div>+    GetAuxvData();</div><div>+</div><div>     //==================================================================</div><div>     // Plug-in Process Control Overrides</div><div>     //==================================================================</div>
<div>Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp</div><div>===================================================================</div><div>--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp<span class="" style="white-space:pre">    </span>(revision 202766)</div>
<div>+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp<span class="" style="white-space:pre">      </span>(working copy)</div><div>@@ -66,6 +66,7 @@</div><div>     m_prepare_for_reg_writing_reply (eLazyBoolCalculate),</div>
<div>     m_supports_p (eLazyBoolCalculate),</div><div>     m_supports_QSaveRegisterState (eLazyBoolCalculate),</div><div>+    m_supports_qXfer_auxv_read (eLazyBoolCalculate),</div><div>     m_supports_qXfer_libraries_read (eLazyBoolCalculate),</div>
<div>     m_supports_qXfer_libraries_svr4_read (eLazyBoolCalculate),</div><div>     m_supports_augmented_libraries_svr4_read (eLazyBoolCalculate),</div><div>@@ -187,6 +188,16 @@</div><div>     return (m_supports_qXfer_libraries_read == eLazyBoolYes);</div>
<div> }</div><div> </div><div>+bool</div><div>+GDBRemoteCommunicationClient::GetQXferAuxvReadSupported ()</div><div>+{</div><div>+    if (m_supports_qXfer_auxv_read == eLazyBoolCalculate)</div><div>+    {</div><div>+        GetRemoteQSupported();</div>
<div>+    }</div><div>+    return (m_supports_qXfer_auxv_read == eLazyBoolYes);</div><div>+}</div><div>+</div><div> uint64_t</div><div> GDBRemoteCommunicationClient::GetRemoteMaxPacketSize()</div><div> {</div><div>@@ -294,6 +305,7 @@</div>
<div>     m_supports_memory_region_info = eLazyBoolCalculate;</div><div>     m_prepare_for_reg_writing_reply = eLazyBoolCalculate;</div><div>     m_attach_or_wait_reply = eLazyBoolCalculate;</div><div>+    m_supports_qXfer_auxv_read = eLazyBoolCalculate;</div>
<div>     m_supports_qXfer_libraries_read = eLazyBoolCalculate;</div><div>     m_supports_qXfer_libraries_svr4_read = eLazyBoolCalculate;</div><div>     m_supports_augmented_libraries_svr4_read = eLazyBoolCalculate;</div>
<div>@@ -320,8 +332,9 @@</div><div> GDBRemoteCommunicationClient::GetRemoteQSupported ()</div><div> {</div><div>     // Clear out any capabilities we expect to see in the qSupported response</div><div>+    m_supports_qXfer_auxv_read = eLazyBoolNo;</div>
<div>+    m_supports_qXfer_libraries_read = eLazyBoolNo;</div><div>     m_supports_qXfer_libraries_svr4_read = eLazyBoolNo;</div><div>-    m_supports_qXfer_libraries_read = eLazyBoolNo;</div><div>     m_supports_augmented_libraries_svr4_read = eLazyBoolNo;</div>
<div>     m_max_packet_size = UINT64_MAX;  // It's supposed to always be there, but if not, we assume no limit</div><div> </div><div>@@ -331,6 +344,8 @@</div><div>                                      /*send_async=*/false) == PacketResult::Success)</div>
<div>     {</div><div>         const char *response_cstr = response.GetStringRef().c_str();</div><div>+        if (::strstr (response_cstr, "qXfer:auxv:read+"))</div><div>+            m_supports_qXfer_auxv_read = eLazyBoolYes;</div>
<div>         if (::strstr (response_cstr, "qXfer:libraries-svr4:read+"))</div><div>             m_supports_qXfer_libraries_svr4_read = eLazyBoolYes;</div><div>         if (::strstr (response_cstr, "augmented-libraries-svr4-read"))</div>
<div>@@ -502,11 +517,8 @@</div><div>         {</div><div>             return PacketResult::ErrorReplyInvalid;</div><div>         }</div><div>-        // Skip past m or l</div><div>-        const char *s = this_string.c_str() + 1;</div>
<div>-</div><div>-        // Concatenate the result so far</div><div>-        response_string += s;</div><div>+        // Concatenate the result so far (skipping 'm' or 'l')</div><div>+        response_string.append(this_string, 1, std::string::npos);</div>
<div>         if (first_char == 'l')</div><div>             // We're done</div><div>             return PacketResult::Success;</div><div>Index: source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h</div>
<div>===================================================================</div><div>--- source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h<span class="" style="white-space:pre">      </span>(revision 202766)</div>
<div>+++ source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h<span class="" style="white-space:pre">        </span>(working copy)</div><div>@@ -384,6 +384,9 @@</div><div>     SetCurrentThreadForRun (uint64_t tid);</div>
<div> </div><div>     bool</div><div>+    GetQXferAuxvReadSupported ();</div><div>+</div><div>+    bool</div><div>     GetQXferLibrariesReadSupported ();</div><div> </div><div>     bool</div><div>@@ -525,6 +528,7 @@</div>
<div>     lldb_private::LazyBool m_prepare_for_reg_writing_reply;</div><div>     lldb_private::LazyBool m_supports_p;</div><div>     lldb_private::LazyBool m_supports_QSaveRegisterState;</div><div>+    lldb_private::LazyBool m_supports_qXfer_auxv_read;</div>
<div>     lldb_private::LazyBool m_supports_qXfer_libraries_read;</div><div>     lldb_private::LazyBool m_supports_qXfer_libraries_svr4_read;</div><div>     lldb_private::LazyBool m_supports_augmented_libraries_svr4_read;</div>
<div>Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp</div><div>===================================================================</div><div>--- source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp<span class="" style="white-space:pre">    </span>(revision 202766)</div>
<div>+++ source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp<span class="" style="white-space:pre">  </span>(working copy)</div><div>@@ -281,7 +281,8 @@</div><div>     m_waiting_for_attach (false),</div><div>     m_destroy_tried_resuming (false),</div>
<div>     m_command_sp (),</div><div>-    m_breakpoint_pc_offset (0)</div><div>+    m_breakpoint_pc_offset (0),</div><div>+    m_breakpoint_trap_opcode_size (0)</div><div> {</div><div>     m_async_broadcaster.SetEventName (eBroadcastBitAsyncThreadShouldExit,   "async thread should exit");</div>
<div>     m_async_broadcaster.SetEventName (eBroadcastBitAsyncContinue,           "async thread continue");</div><div>@@ -3060,7 +3061,22 @@</div><div>     return m_dyld_ap.get();</div><div> }</div><div> </div><div>
+const DataBufferSP</div><div>+ProcessGDBRemote::GetAuxvData()</div><div>+{</div><div>+    DataBufferSP buf;</div><div>+    if (m_gdb_comm.GetQXferAuxvReadSupported())</div><div>+    {</div><div>+        std::string response_string;</div>
<div>+        if (m_gdb_comm.SendPacketsAndConcatenateResponses("qXfer:auxv:read::", response_string) == GDBRemoteCommunication::PacketResult::Success)</div><div>+            buf.reset(new DataBufferHeap(response_string.c_str(), response_string.length()));</div>
<div>+    }</div><div>+    if (buf.get() != NULL)</div><div>+        return buf;</div><div>+    return Process::GetAuxvData();</div><div>+}</div><div> </div><div>+</div><div> class CommandObjectProcessGDBRemotePacketHistory : public CommandObjectParsed</div>
<div> {</div><div> private:</div><div>Index: source/Plugins/Process/gdb-remote/ProcessGDBRemote.h</div><div>===================================================================</div><div>--- source/Plugins/Process/gdb-remote/ProcessGDBRemote.h<span class="" style="white-space:pre">     </span>(revision 202766)</div>
<div>+++ source/Plugins/Process/gdb-remote/ProcessGDBRemote.h<span class="" style="white-space:pre">    </span>(working copy)</div><div>@@ -299,6 +299,9 @@</div><div>     bool</div><div>     ParseRegisters(lldb_private::ScriptInterpreterObject *registers_array);</div>
<div> </div><div>+    virtual const lldb::DataBufferSP</div><div>+    GetAuxvData();</div><div>+</div><div>     //------------------------------------------------------------------</div><div>     /// Broadcaster event bits definitions.</div>
<div>     //------------------------------------------------------------------</div><div>@@ -341,7 +344,8 @@</div><div>     bool m_destroy_tried_resuming;</div><div>     lldb::CommandObjectSP m_command_sp;</div><div>     int64_t m_breakpoint_pc_offset;</div>
<div>-    </div><div>+    size_t m_breakpoint_trap_opcode_size;  // If set by Python</div><div>+</div><div>     bool</div><div>     StartAsyncThread ();</div><div> </div><div>Index: source/Target/Process.cpp</div><div>===================================================================</div>
<div>--- source/Target/Process.cpp<span class="" style="white-space:pre">       </span>(revision 202766)</div><div>+++ source/Target/Process.cpp<span class="" style="white-space:pre">     </span>(working copy)</div><div>@@ -5973,6 +5973,12 @@</div>
<div>     target.DidExec();</div><div> }</div><div> </div><div>+const DataBufferSP</div><div>+Process::GetAuxvData()</div><div>+{</div><div>+    return lldb_private::Host::GetAuxvData(this);</div><div>+}</div><div>+</div>
<div> addr_t</div><div> Process::ResolveIndirectFunction(const Address *address, Error &error)</div><div> {</div></div><div><br></div></div>