diff options
| author | Jim Ingham <jingham@apple.com> | 2011-01-22 01:33:44 +0000 |
|---|---|---|
| committer | Jim Ingham <jingham@apple.com> | 2011-01-22 01:33:44 +0000 |
| commit | 1c823b43e58310fc508a712c93d7b46344413367 (patch) | |
| tree | 47338785cb2ee77e0276cd82c1e35d27caf23d95 /lldb/source/Plugins/Process/gdb-remote | |
| parent | e22e88b8a88461adfa2ee84f4c57b6a0ad9bc943 (diff) | |
| download | bcm5719-llvm-1c823b43e58310fc508a712c93d7b46344413367.tar.gz bcm5719-llvm-1c823b43e58310fc508a712c93d7b46344413367.zip | |
Added an interface for noticing new thread creation. At this point, I only turn it on when
we are requesting a single thread to run. May seem like a silly thing to do, but the kernel
on MacOS X will inject new threads into a program willy-nilly, and I would like to keep them
from running if I can.
llvm-svn: 124018
Diffstat (limited to 'lldb/source/Plugins/Process/gdb-remote')
| -rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp | 91 | ||||
| -rw-r--r-- | lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h | 13 |
2 files changed, 103 insertions, 1 deletions
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp index 26aa4564281..f0087ec4200 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp @@ -119,7 +119,8 @@ ProcessGDBRemote::ProcessGDBRemote(Target& target, Listener &listener) : m_packet_timeout (1), m_max_memory_size (512), m_waiting_for_attach (false), - m_local_debugserver (true) + m_local_debugserver (true), + m_thread_observation_bps() { } @@ -2279,3 +2280,91 @@ ProcessGDBRemote::ListProcessesMatchingName (const char *name, StringList &match } } + +bool +ProcessGDBRemote::NewThreadNotifyBreakpointHit (void *baton, + lldb_private::StoppointCallbackContext *context, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id) +{ + // I don't think I have to do anything here, just make sure I notice the new thread when it starts to + // run so I can stop it if that's what I want to do. + LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + if (log) + log->Printf("Hit New Thread Notification breakpoint."); + return false; +} + + +bool +ProcessGDBRemote::StartNoticingNewThreads() +{ + static const char *bp_names[] = + { + "start_wqthread", + "_pthread_start", + NULL + }; + + LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + size_t num_bps = m_thread_observation_bps.size(); + if (num_bps != 0) + { + for (int i = 0; i < num_bps; i++) + { + lldb::BreakpointSP break_sp = m_target.GetBreakpointByID(m_thread_observation_bps[i]); + if (break_sp) + { + if (log) + log->Printf("Enabled noticing new thread breakpoint."); + break_sp->SetEnabled(true); + } + } + } + else + { + for (int i = 0; bp_names[i] != NULL; i++) + { + Breakpoint *breakpoint = m_target.CreateBreakpoint (NULL, bp_names[i], eFunctionNameTypeFull, true).get(); + if (breakpoint) + { + if (log) + log->Printf("Successfully created new thread notification breakpoint at \"%s\".", bp_names[i]); + m_thread_observation_bps.push_back(breakpoint->GetID()); + breakpoint->SetCallback (ProcessGDBRemote::NewThreadNotifyBreakpointHit, this, true); + } + else + { + if (log) + log->Printf("Failed to create new thread notification breakpoint."); + return false; + } + } + } + + return true; +} + +bool +ProcessGDBRemote::StopNoticingNewThreads() +{ + size_t num_bps = m_thread_observation_bps.size(); + if (num_bps != 0) + { + for (int i = 0; i < num_bps; i++) + { + LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP)); + + lldb::BreakpointSP break_sp = m_target.GetBreakpointByID(m_thread_observation_bps[i]); + if (break_sp) + { + if (log) + log->Printf ("Disabling new thread notification breakpoint."); + break_sp->SetEnabled(false); + } + } + } + return true; +} + + diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h index 74905d0e646..ebb4cca23d4 100644 --- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h +++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h @@ -216,6 +216,12 @@ public: virtual lldb_private::DynamicLoader * GetDynamicLoader (); + + virtual bool + StartNoticingNewThreads(); + + virtual bool + StopNoticingNewThreads(); protected: friend class ThreadGDBRemote; @@ -336,6 +342,7 @@ protected: size_t m_max_memory_size; // The maximum number of bytes to read/write when reading and writing memory bool m_waiting_for_attach; bool m_local_debugserver; // Is the debugserver process we are talking to local or on another machine. + std::vector<lldb::user_id_t> m_thread_observation_bps; void ResetGDBRemoteState (); @@ -379,6 +386,12 @@ private: //------------------------------------------------------------------ // For ProcessGDBRemote only //------------------------------------------------------------------ + static bool + NewThreadNotifyBreakpointHit (void *baton, + lldb_private::StoppointCallbackContext *context, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id); + DISALLOW_COPY_AND_ASSIGN (ProcessGDBRemote); }; |

