[Lldb-commits] [lldb] r154704 - in /lldb/trunk/source/Plugins/Process/gdb-remote: GDBRemoteCommunication.cpp GDBRemoteCommunication.h GDBRemoteRegisterContext.cpp ProcessGDBRemote.cpp

Greg Clayton gclayton at apple.com
Fri Apr 13 14:24:19 PDT 2012


Author: gclayton
Date: Fri Apr 13 16:24:18 2012
New Revision: 154704

URL: http://llvm.org/viewvc/llvm-project?rev=154704&view=rev
Log:
Added the thread ID (tid) to each packet history item and the packet history now always dumps to a lldb_private::Stream.

Enable logging the packet history when registers fail to read due to not getting the sequence mutex if "--verbose" is enabled on the log channel for the "gdb-remote" log category.

This will help us track down some issues.


Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp?rev=154704&r1=154703&r2=154704&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp Fri Apr 13 16:24:18 2012
@@ -46,6 +46,41 @@
 }
 
 void
+GDBRemoteCommunication::History::AddPacket (char packet_char,
+                                            PacketType type,
+                                            uint32_t bytes_transmitted)
+{
+    const size_t size = m_packets.size();
+    if (size > 0)
+    {
+        const uint32_t idx = GetNextIndex();
+        m_packets[idx].packet.assign (1, packet_char);
+        m_packets[idx].type = type;
+        m_packets[idx].bytes_transmitted = bytes_transmitted;
+        m_packets[idx].packet_idx = m_total_packet_count;
+        m_packets[idx].tid = Host::GetCurrentThreadID();
+    }
+}
+
+void
+GDBRemoteCommunication::History::AddPacket (const std::string &src,
+                                            uint32_t src_len,
+                                            PacketType type,
+                                            uint32_t bytes_transmitted)
+{
+    const size_t size = m_packets.size();
+    if (size > 0)
+    {
+        const uint32_t idx = GetNextIndex();
+        m_packets[idx].packet.assign (src, 0, src_len);
+        m_packets[idx].type = type;
+        m_packets[idx].bytes_transmitted = bytes_transmitted;
+        m_packets[idx].packet_idx = m_total_packet_count;
+        m_packets[idx].tid = Host::GetCurrentThreadID();
+    }
+}
+
+void
 GDBRemoteCommunication::History::Dump (lldb_private::Stream &strm) const
 {
     const uint32_t size = GetNumPacketsInHistory ();
@@ -57,8 +92,9 @@
         const Entry &entry = m_packets[idx];
         if (entry.type == ePacketTypeInvalid || entry.packet.empty())
             break;
-        strm.Printf ("history[%u] <%4u> %s packet: %s\n",
+        strm.Printf ("history[%u] tid=0x%4.4llx <%4u> %s packet: %s\n",
                      entry.packet_idx,
+                     entry.tid,
                      entry.bytes_transmitted,
                      (entry.type == ePacketTypeSend) ? "send" : "read",
                      entry.packet.c_str());
@@ -80,8 +116,9 @@
             const Entry &entry = m_packets[idx];
             if (entry.type == ePacketTypeInvalid || entry.packet.empty())
                 break;
-            log->Printf ("history[%u] <%4u> %s packet: %s",
+            log->Printf ("history[%u] tid=0x%4.4llx <%4u> %s packet: %s",
                          entry.packet_idx,
+                         entry.tid,
                          entry.bytes_transmitted,
                          (entry.type == ePacketTypeSend) ? "send" : "read",
                          entry.packet.c_str());
@@ -598,12 +635,7 @@
 }
 
 void
-GDBRemoteCommunication::DumpHistory(const char *path)
+GDBRemoteCommunication::DumpHistory(Stream &strm)
 {
-    StreamFile strm;
-    Error error (strm.GetFile().Open(path, File::eOpenOptionWrite | File::eOpenOptionCanCreate));
-    if (error.Success())
-        m_history.Dump (strm);
-    else
-        fprintf (stderr, "error: unable to open '%s' -- %s\n", path, error.AsCString());
+    m_history.Dump (strm);
 }

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h?rev=154704&r1=154703&r2=154704&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.h Fri Apr 13 16:24:18 2012
@@ -114,7 +114,7 @@
                              lldb_private::ProcessLaunchInfo &launch_info); 
 
     void
-    DumpHistory(const char *path);
+    DumpHistory(lldb_private::Stream &strm);
     
 protected:
 
@@ -134,7 +134,8 @@
                 packet(),
                 type (ePacketTypeInvalid),
                 bytes_transmitted (0),
-                packet_idx (0)
+                packet_idx (0),
+                tid (LLDB_INVALID_THREAD_ID)
             {
             }
             
@@ -145,12 +146,13 @@
                 type = ePacketTypeInvalid;
                 bytes_transmitted = 0;
                 packet_idx = 0;
-                
+                tid = LLDB_INVALID_THREAD_ID;
             }
             std::string packet;
             PacketType type;
             uint32_t bytes_transmitted;
             uint32_t packet_idx;
+            lldb::tid_t tid;
         };
 
         History (uint32_t size);
@@ -161,35 +163,12 @@
         void
         AddPacket (char packet_char,
                    PacketType type,
-                   uint32_t bytes_transmitted)
-        {
-            const size_t size = m_packets.size();
-            if (size > 0)
-            {
-                const uint32_t idx = GetNextIndex();
-                m_packets[idx].packet.assign (1, packet_char);
-                m_packets[idx].type = type;
-                m_packets[idx].bytes_transmitted = bytes_transmitted;
-                m_packets[idx].packet_idx = m_total_packet_count;
-            }
-        }
-
+                   uint32_t bytes_transmitted);
         void
         AddPacket (const std::string &src,
                    uint32_t src_len,
                    PacketType type,
-                   uint32_t bytes_transmitted)
-        {
-            const size_t size = m_packets.size();
-            if (size > 0)
-            {
-                const uint32_t idx = GetNextIndex();
-                m_packets[idx].packet.assign (src, 0, src_len);
-                m_packets[idx].type = type;
-                m_packets[idx].bytes_transmitted = bytes_transmitted;
-                m_packets[idx].packet_idx = m_total_packet_count;
-            }
-        }
+                   uint32_t bytes_transmitted);
         
         void
         Dump (lldb_private::Stream &strm) const;

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp?rev=154704&r1=154703&r2=154704&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp Fri Apr 13 16:24:18 2012
@@ -246,7 +246,18 @@
         {
             LogSP log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_THREAD | GDBR_LOG_PACKETS));
             if (log)
-                log->Printf("error: failed to get packet sequence mutex, not sending read register for \"%s\"", reg_info->name);
+            {
+                if (log->GetVerbose())
+                {
+                    StreamString strm;
+                    gdb_comm.DumpHistory(strm);
+                    log->Printf("error: failed to get packet sequence mutex, not sending read register for \"%s\":\n%s", reg_info->name, strm.GetData());
+                }
+                else
+                {
+                    log->Printf("error: failed to get packet sequence mutex, not sending read register for \"%s\"", reg_info->name);
+                }
+            }
         }
 
         // Make sure we got a valid register value after reading it
@@ -431,7 +442,16 @@
         {
             LogSP log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_THREAD | GDBR_LOG_PACKETS));
             if (log)
-                log->Printf("error: failed to get packet sequence mutex, not sending write register for \"%s\"", reg_info->name);
+            {
+                if (log->GetVerbose())
+                {
+                    StreamString strm;
+                    gdb_comm.DumpHistory(strm);
+                    log->Printf("error: failed to get packet sequence mutex, not sending write register for \"%s\":\n%s", reg_info->name, strm.GetData());
+                }
+                else
+                    log->Printf("error: failed to get packet sequence mutex, not sending write register for \"%s\"", reg_info->name);
+            }
         }
     }
     return false;
@@ -492,7 +512,16 @@
     {
         LogSP log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_THREAD | GDBR_LOG_PACKETS));
         if (log)
-            log->Printf("error: failed to get packet sequence mutex, not sending read all registers");
+        {
+            if (log->GetVerbose())
+            {
+                StreamString strm;
+                gdb_comm.DumpHistory(strm);
+                log->Printf("error: failed to get packet sequence mutex, not sending read all registers:\n%s", strm.GetData());
+            }
+            else
+                log->Printf("error: failed to get packet sequence mutex, not sending read all registers");
+        }
     }
 
     data_sp.reset();
@@ -616,7 +645,16 @@
     {
         LogSP log (ProcessGDBRemoteLog::GetLogIfAnyCategoryIsSet (GDBR_LOG_THREAD | GDBR_LOG_PACKETS));
         if (log)
-            log->Printf("error: failed to get packet sequence mutex, not sending write all registers");
+        {
+            if (log->GetVerbose())
+            {
+                StreamString strm;
+                gdb_comm.DumpHistory(strm);
+                log->Printf("error: failed to get packet sequence mutex, not sending write all registers:\n%s", strm.GetData());
+            }
+            else
+                log->Printf("error: failed to get packet sequence mutex, not sending write all registers");
+        }
     }
     return false;
 }

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=154704&r1=154703&r2=154704&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Fri Apr 13 16:24:18 2012
@@ -32,6 +32,7 @@
 #include "lldb/Core/Module.h"
 #include "lldb/Core/PluginManager.h"
 #include "lldb/Core/State.h"
+#include "lldb/Core/StreamFile.h"
 #include "lldb/Core/StreamString.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/Core/Value.h"
@@ -64,7 +65,10 @@
     void
     DumpProcessGDBRemotePacketHistory (void *p, const char *path)
     {
-        ((ProcessGDBRemote *)p)->GetGDBRemote().DumpHistory (path);
+        lldb_private::StreamFile strm;
+        lldb_private::Error error (strm.GetFile().Open(path, lldb_private::File::eOpenOptionWrite | lldb_private::File::eOpenOptionCanCreate));
+        if (error.Success())
+            ((ProcessGDBRemote *)p)->GetGDBRemote().DumpHistory (strm);
     }
 };
 





More information about the lldb-commits mailing list