[Lldb-commits] [lldb] r157345 - in /lldb/trunk: include/lldb/Target/ source/Commands/ source/Plugins/Process/gdb-remote/ test/functionalities/watchpoint/watchpoint_commands/ tools/debugserver/source/ tools/debugserver/source/MacOSX/

Johnny Chen johnny.chen at apple.com
Wed May 23 14:09:53 PDT 2012


Author: johnny
Date: Wed May 23 16:09:52 2012
New Revision: 157345

URL: http://llvm.org/viewvc/llvm-project?rev=157345&view=rev
Log:
Add the capability to display the number of supported hardware watchpoints to the "watchpoint list" command.

Add default Process::GetWatchpointSupportInfo() impl which returns an error of "not supported".
Add "qWatchpointSupportInfo" packet to the gdb communication layer to support this, and modify TestWatchpointCommands.py to test it.

Modified:
    lldb/trunk/include/lldb/Target/Process.h
    lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
    lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py
    lldb/trunk/tools/debugserver/source/DNB.cpp
    lldb/trunk/tools/debugserver/source/DNB.h
    lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
    lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h
    lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.h
    lldb/trunk/tools/debugserver/source/RNBRemote.cpp
    lldb/trunk/tools/debugserver/source/RNBRemote.h

Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Wed May 23 16:09:52 2012
@@ -2722,6 +2722,14 @@
         return error;
     }
 
+    virtual Error
+    GetWatchpointSupportInfo (uint32_t &num)
+    {
+        Error error;
+        error.SetErrorString ("Process::GetWatchpointSupportInfo() not supported");
+        return error;
+    }
+
     lldb::ModuleSP
     ReadModuleFromMemory (const FileSpec& file_spec, 
                           lldb::addr_t header_addr,

Modified: lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectWatchpoint.cpp Wed May 23 16:09:52 2012
@@ -290,6 +290,15 @@
         return true;
     }
 
+    if (target->GetProcessSP() && target->GetProcessSP()->IsAlive())
+    {
+        uint32_t num_supported_hardware_watchpoints;
+        Error error = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints);
+        if (error.Success())
+            result.AppendMessageWithFormat("Number of supported hardware watchpoints: %u\n",
+                                           num_supported_hardware_watchpoints);
+    }
+
     const WatchpointList &watchpoints = target->GetWatchpointList();
     Mutex::Locker locker;
     target->GetWatchpointList().GetListMutex(locker);

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Wed May 23 16:09:52 2012
@@ -48,6 +48,7 @@
     m_qHostInfo_is_valid (eLazyBoolCalculate),
     m_supports_alloc_dealloc_memory (eLazyBoolCalculate),
     m_supports_memory_region_info  (eLazyBoolCalculate),
+    m_supports_watchpoint_support_info  (eLazyBoolCalculate),
     m_supports_qProcessInfoPID (true),
     m_supports_qfProcessInfo (true),
     m_supports_qUserName (true),
@@ -60,6 +61,7 @@
     m_supports_z4 (true),
     m_curr_tid (LLDB_INVALID_THREAD_ID),
     m_curr_tid_run (LLDB_INVALID_THREAD_ID),
+    m_num_supported_hardware_watchpoints (0),
     m_async_mutex (Mutex::eMutexTypeRecursive),
     m_async_packet_predicate (false),
     m_async_packet (),
@@ -1286,6 +1288,52 @@
 
 }
 
+Error
+GDBRemoteCommunicationClient::GetWatchpointSupportInfo (uint32_t &num)
+{
+    Error error;
+
+    if (m_supports_watchpoint_support_info == eLazyBoolYes)
+    {
+        num = m_num_supported_hardware_watchpoints;
+        return error;
+    }
+
+    // Set num to 0 first.
+    num = 0;
+    if (m_supports_watchpoint_support_info != eLazyBoolNo)
+    {
+        char packet[64];
+        const int packet_len = ::snprintf(packet, sizeof(packet), "qWatchpointSupportInfo:");
+        assert (packet_len < sizeof(packet));
+        StringExtractorGDBRemote response;
+        if (SendPacketAndWaitForResponse (packet, packet_len, response, false))
+        {
+            m_supports_watchpoint_support_info = eLazyBoolYes;        
+            std::string name;
+            std::string value;
+            while (response.GetNameColonValue(name, value))
+            {
+                if (name.compare ("num") == 0)
+                {
+                    num = Args::StringToUInt32(value.c_str(), 0, 0);
+                    m_num_supported_hardware_watchpoints = num;
+                }
+            }
+        }
+        else
+        {
+            m_supports_watchpoint_support_info = eLazyBoolNo;
+        }
+    }
+
+    if (m_supports_watchpoint_support_info == eLazyBoolNo)
+    {
+        error.SetErrorString("qWatchpointSupportInfo is not supported");
+    }
+    return error;
+
+}
 
 int
 GDBRemoteCommunicationClient::SetSTDIN (char const *path)

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h Wed May 23 16:09:52 2012
@@ -206,6 +206,9 @@
     GetMemoryRegionInfo (lldb::addr_t addr, 
                         lldb_private::MemoryRegionInfo &range_info); 
 
+    lldb_private::Error
+    GetWatchpointSupportInfo (uint32_t &num); 
+
     const lldb_private::ArchSpec &
     GetHostArchitecture ();
     
@@ -354,6 +357,7 @@
     lldb_private::LazyBool m_qHostInfo_is_valid;
     lldb_private::LazyBool m_supports_alloc_dealloc_memory;
     lldb_private::LazyBool m_supports_memory_region_info;
+    lldb_private::LazyBool m_supports_watchpoint_support_info;
 
     bool
         m_supports_qProcessInfoPID:1,
@@ -372,6 +376,8 @@
     lldb::tid_t m_curr_tid_run;     // Current gdb remote protocol thread index for continue, step, etc
 
 
+    uint32_t m_num_supported_hardware_watchpoints;
+
     // If we need to send a packet while the target is running, the m_async_XXX
     // member variables take care of making this happen.
     lldb_private::Mutex m_async_mutex;

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=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Wed May 23 16:09:52 2012
@@ -1858,6 +1858,14 @@
 }
 
 Error
+ProcessGDBRemote::GetWatchpointSupportInfo (uint32_t &num)
+{
+    
+    Error error (m_gdb_comm.GetWatchpointSupportInfo (num));
+    return error;
+}
+
+Error
 ProcessGDBRemote::DoDeallocateMemory (lldb::addr_t addr)
 {
     Error error; 

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h Wed May 23 16:09:52 2012
@@ -204,6 +204,9 @@
     virtual lldb_private::Error
     DisableWatchpoint (lldb_private::Watchpoint *wp);
 
+    virtual lldb_private::Error
+    GetWatchpointSupportInfo (uint32_t &num);
+    
     virtual bool
     StartNoticingNewThreads();    
 

Modified: lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py (original)
+++ lldb/trunk/test/functionalities/watchpoint/watchpoint_commands/TestWatchpointCommands.py Wed May 23 16:09:52 2012
@@ -128,7 +128,8 @@
         # Use the '-v' option to do verbose listing of the watchpoint.
         # The hit count should be 0 initially.
         self.expect("watchpoint list -v",
-            substrs = ['hit_count = 0'])
+            substrs = ['Number of supported hardware watchpoints:',
+                       'hit_count = 0'])
 
         self.runCmd("process continue")
 

Modified: lldb/trunk/tools/debugserver/source/DNB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.cpp?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/DNB.cpp (original)
+++ lldb/trunk/tools/debugserver/source/DNB.cpp Wed May 23 16:09:52 2012
@@ -1081,6 +1081,18 @@
 }
 
 //----------------------------------------------------------------------
+// Return the number of supported hardware watchpoints.
+//----------------------------------------------------------------------
+uint32_t
+DNBWatchpointGetNumSupportedHWP (nub_process_t pid)
+{
+    MachProcessSP procSP;
+    if (GetProcessSP (pid, procSP))
+        return procSP->GetNumSupportedHardwareWatchpoints();
+    return 0;
+}
+
+//----------------------------------------------------------------------
 // Read memory in the address space of process PID. This call will take
 // care of setting and restoring permissions and breaking up the memory
 // read into multiple chunks as required.

Modified: lldb/trunk/tools/debugserver/source/DNB.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.h?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/DNB.h (original)
+++ lldb/trunk/tools/debugserver/source/DNB.h Wed May 23 16:09:52 2012
@@ -138,6 +138,7 @@
 nub_bool_t      DNBWatchpointSetIgnoreCount     (nub_process_t pid, nub_watch_t watchID, nub_size_t ignore_count) DNB_EXPORT;
 nub_bool_t      DNBWatchpointSetCallback        (nub_process_t pid, nub_watch_t watchID, DNBCallbackBreakpointHit callback, void *baton) DNB_EXPORT;
 void            DNBWatchpointPrint              (nub_process_t pid, nub_watch_t watchID) DNB_EXPORT;
+uint32_t        DNBWatchpointGetNumSupportedHWP (nub_process_t pid) DNB_EXPORT; 
 
 const DNBRegisterSetInfo *
                 DNBGetRegisterSetInfo           (nub_size_t *num_reg_sets) DNB_EXPORT;

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.cpp Wed May 23 16:09:52 2012
@@ -944,6 +944,12 @@
     }
 }
 
+uint32_t
+MachProcess::GetNumSupportedHardwareWatchpoints () const
+{
+    return m_thread_list.NumSupportedHardwareWatchpoints();
+}
+
 bool
 MachProcess::EnableBreakpoint(nub_break_t breakID)
 {

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.h Wed May 23 16:09:52 2012
@@ -131,6 +131,7 @@
     nub_size_t              DisableAllWatchpoints (bool remove);
     bool                    EnableWatchpoint (nub_watch_t watchID);
     void                    DumpWatchpoint(nub_watch_t watchID) const;
+    uint32_t                GetNumSupportedHardwareWatchpoints () const;
     DNBBreakpointList&      Watchpoints() { return m_watchpoints; }
     const DNBBreakpointList& Watchpoints() const { return m_watchpoints; }
 

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachThread.cpp Wed May 23 16:09:52 2012
@@ -715,6 +715,12 @@
     return false;
 }
 
+uint32_t
+MachThread::NumSupportedHardwareWatchpoints () const
+{
+    return m_arch_ap->NumSupportedHardwareWatchpoints();
+}
+
 bool
 MachThread::GetIdentifierInfo ()
 {

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachThread.h Wed May 23 16:09:52 2012
@@ -65,6 +65,7 @@
     uint32_t        EnableHardwareWatchpoint (const DNBBreakpoint *watchpoint);
     bool            DisableHardwareBreakpoint (const DNBBreakpoint *breakpoint);
     bool            DisableHardwareWatchpoint (const DNBBreakpoint *watchpoint);
+    uint32_t        NumSupportedHardwareWatchpoints () const;
 
     nub_state_t     GetState();
     void            SetState(nub_state_t state);

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.cpp?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.cpp (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.cpp Wed May 23 16:09:52 2012
@@ -509,6 +509,17 @@
 }
 
 uint32_t
+MachThreadList::NumSupportedHardwareWatchpoints () const
+{
+    PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);
+    const uint32_t num_threads = m_threads.size();
+    // Use an arbitrary thread to retrieve the number of supported hardware watchpoints.
+    if (num_threads)
+        return m_threads[0]->NumSupportedHardwareWatchpoints();
+    return 0;
+}
+
+uint32_t
 MachThreadList::GetThreadIndexForThreadStoppedWithSignal (const int signo) const
 {
     PTHREAD_MUTEX_LOCKER (locker, m_threads_mutex);

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.h?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.h (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachThreadList.h Wed May 23 16:09:52 2012
@@ -50,6 +50,8 @@
     bool            DisableHardwareBreakpoint (const DNBBreakpoint *bp) const;
     uint32_t        EnableHardwareWatchpoint (const DNBBreakpoint *wp) const;
     bool            DisableHardwareWatchpoint (const DNBBreakpoint *wp) const;
+    uint32_t        NumSupportedHardwareWatchpoints () const;
+
     uint32_t        GetThreadIndexForThreadStoppedWithSignal (const int signo) const;
 
     MachThreadSP    GetThreadByID (nub_thread_t tid) const;

Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original)
+++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Wed May 23 16:09:52 2012
@@ -189,6 +189,7 @@
     t.push_back (Packet (allocate_memory,               &RNBRemote::HandlePacket_AllocateMemory, NULL, "_M", "Allocate memory in the inferior process."));
     t.push_back (Packet (deallocate_memory,             &RNBRemote::HandlePacket_DeallocateMemory, NULL, "_m", "Deallocate memory in the inferior process."));
     t.push_back (Packet (memory_region_info,            &RNBRemote::HandlePacket_MemoryRegionInfo, NULL, "qMemoryRegionInfo", "Return size and attributes of a memory region that contains the given address"));
+    t.push_back (Packet (watchpoint_support_info,       &RNBRemote::HandlePacket_WatchpointSupportInfo, NULL, "qWatchpointSupportInfo", "Return the number of supported hardware watchpoints"));
 
 }
 
@@ -3361,6 +3362,33 @@
     return SendPacket (ostrm.str());
 }
 
+rnb_err_t
+RNBRemote::HandlePacket_WatchpointSupportInfo (const char *p)
+{
+    /* This packet simply returns the number of supported hardware watchpoints.
+       
+       Examples of use:
+          qWatchpointSupportInfo:
+          num:4
+
+          qWatchpointSupportInfo
+          OK                   // this packet is implemented by the remote nub
+    */
+
+    p += sizeof ("qWatchpointSupportInfo") - 1;
+    if (*p == '\0')
+       return SendPacket ("OK");
+    if (*p++ != ':')
+       return SendPacket ("E67");
+
+    errno = 0;
+    uint32_t num = DNBWatchpointGetNumSupportedHWP (m_ctx.ProcessID());
+    std::ostringstream ostrm;
+
+    // size:4
+    ostrm << "num:" << std::dec << num << ';';
+    return SendPacket (ostrm.str());
+}
 
 /* 'C sig [;addr]'
  Resume with signal sig, optionally at address addr.  */

Modified: lldb/trunk/tools/debugserver/source/RNBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.h?rev=157345&r1=157344&r2=157345&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBRemote.h (original)
+++ lldb/trunk/tools/debugserver/source/RNBRemote.h Wed May 23 16:09:52 2012
@@ -108,6 +108,7 @@
         set_working_dir,                // 'QSetWorkingDir:'
         set_list_threads_in_stop_reply, // 'QListThreadsInStopReply:'
         memory_region_info,             // 'qMemoryRegionInfo:'
+        watchpoint_support_info,        // 'qWatchpointSupportInfo:'
         allocate_memory,                // '_M'
         deallocate_memory,              // '_m'
 
@@ -202,6 +203,7 @@
     rnb_err_t HandlePacket_AllocateMemory (const char *p);
     rnb_err_t HandlePacket_DeallocateMemory (const char *p);
     rnb_err_t HandlePacket_MemoryRegionInfo (const char *p);
+    rnb_err_t HandlePacket_WatchpointSupportInfo (const char *p);
 
     rnb_err_t HandlePacket_stop_process (const char *p);
 





More information about the lldb-commits mailing list