From af67cecd47690d70be488673a02de533e044a521 Mon Sep 17 00:00:00 2001 From: Greg Clayton Date: Mon, 20 Dec 2010 20:49:23 +0000 Subject: [PATCH] The LLDB API (lldb::SB*) is now thread safe! llvm-svn: 122262 --- lldb/include/lldb/API/SBDebugger.h | 7 +- lldb/include/lldb/API/SBProcess.h | 11 - lldb/include/lldb/API/SBTarget.h | 16 -- lldb/include/lldb/API/SBValue.h | 3 - lldb/include/lldb/Breakpoint/BreakpointList.h | 6 +- lldb/include/lldb/Core/ValueObject.h | 2 +- lldb/include/lldb/Target/Target.h | 7 + lldb/source/API/SBAddress.cpp | 19 +- lldb/source/API/SBBreakpoint.cpp | 110 +++++++-- lldb/source/API/SBBreakpointLocation.cpp | 85 +++++-- lldb/source/API/SBCommandInterpreter.cpp | 22 +- lldb/source/API/SBDebugger.cpp | 171 +++++-------- lldb/source/API/SBFrame.cpp | 60 ++++- lldb/source/API/SBFunction.cpp | 2 + lldb/source/API/SBProcess.cpp | 104 ++++---- lldb/source/API/SBSymbol.cpp | 4 + lldb/source/API/SBTarget.cpp | 226 ++++-------------- lldb/source/API/SBThread.cpp | 32 ++- lldb/source/API/SBValue.cpp | 113 ++++++--- lldb/source/API/SBValueList.cpp | 29 +-- lldb/source/Core/ValueObject.cpp | 2 +- lldb/source/Target/StackFrame.cpp | 2 +- lldb/source/Target/Target.cpp | 1 + 23 files changed, 537 insertions(+), 497 deletions(-) diff --git a/lldb/include/lldb/API/SBDebugger.h b/lldb/include/lldb/API/SBDebugger.h index b1f99cde20ea..9e02581e3bb7 100644 --- a/lldb/include/lldb/API/SBDebugger.h +++ b/lldb/include/lldb/API/SBDebugger.h @@ -111,9 +111,6 @@ public: lldb::SBTarget GetSelectedTarget (); - void - UpdateSelectedThread (lldb::SBProcess &process); - lldb::SBSourceManager & GetSourceManager (); @@ -125,10 +122,10 @@ public: bool GetUseExternalEditor (); - bool + static bool GetDefaultArchitecture (char *arch_name, size_t arch_name_len); - bool + static bool SetDefaultArchitecture (const char *arch_name); lldb::ScriptLanguage diff --git a/lldb/include/lldb/API/SBProcess.h b/lldb/include/lldb/API/SBProcess.h index 7ef4b428b581..e08a806cb0e1 100644 --- a/lldb/include/lldb/API/SBProcess.h +++ b/lldb/include/lldb/API/SBProcess.h @@ -111,17 +111,6 @@ public: lldb::SBError Destroy (); - lldb::pid_t - AttachByPID (lldb::pid_t pid); // DEPRECATED - - // DEPRECATED: relocated to "SBProcess SBTarget::AttachToProcess (lldb::pid_t pid, lldb::SBError& error)" - lldb::SBError - Attach (lldb::pid_t pid); - - // DEPRECATED: relocated to "SBProcess SBTarget::AttachToProcess (const char *name, bool wait_for_launch, lldb::SBError& error)" - lldb::SBError - AttachByName (const char *name, bool wait_for_launch); - lldb::SBError Continue (); diff --git a/lldb/include/lldb/API/SBTarget.h b/lldb/include/lldb/API/SBTarget.h index 0926c4a84560..bf9d80073519 100644 --- a/lldb/include/lldb/API/SBTarget.h +++ b/lldb/include/lldb/API/SBTarget.h @@ -51,14 +51,9 @@ public: bool IsValid() const; - lldb::SBProcess - CreateProcess (); // DEPRECATED - lldb::SBProcess GetProcess (); - // DEPRECATED in favor of the function below that contains an SBError as the - // last parameter. lldb::SBProcess LaunchProcess (char const **argv, char const **envp, @@ -147,17 +142,6 @@ public: lldb::SBBroadcaster GetBroadcaster () const; - //void - //Disassemble (); - - void - Disassemble (lldb::addr_t start_address, - lldb::addr_t end_address = LLDB_INVALID_ADDRESS, - const char *module_name = NULL); - - void - Disassemble (const char *function_name, const char *module_name = NULL); - #ifndef SWIG bool operator == (const lldb::SBTarget &rhs) const; diff --git a/lldb/include/lldb/API/SBValue.h b/lldb/include/lldb/API/SBValue.h index 0cbba42d3746..76a4dbfa4221 100644 --- a/lldb/include/lldb/API/SBValue.h +++ b/lldb/include/lldb/API/SBValue.h @@ -85,9 +85,6 @@ public: uint32_t GetNumChildren (); - bool - ValueIsStale (); - void * GetOpaqueType(); diff --git a/lldb/include/lldb/Breakpoint/BreakpointList.h b/lldb/include/lldb/Breakpoint/BreakpointList.h index 49db361fb9ae..bf3ce14d91a8 100644 --- a/lldb/include/lldb/Breakpoint/BreakpointList.h +++ b/lldb/include/lldb/Breakpoint/BreakpointList.h @@ -114,7 +114,11 @@ public: /// The number of elements. //------------------------------------------------------------------ size_t - GetSize() const { return m_breakpoints.size(); } + GetSize() const + { + Mutex::Locker locker(m_mutex); + return m_breakpoints.size(); + } //------------------------------------------------------------------ /// Removes the breakpoint given by \b breakID from this list. diff --git a/lldb/include/lldb/Core/ValueObject.h b/lldb/include/lldb/Core/ValueObject.h index a3a91dcb9046..dad51a51b7cc 100644 --- a/lldb/include/lldb/Core/ValueObject.h +++ b/lldb/include/lldb/Core/ValueObject.h @@ -207,7 +207,7 @@ public: CreateConstantValue (ExecutionContextScope *exe_scope, const ConstString &name); virtual lldb::ValueObjectSP - Dereference (ExecutionContextScope *exe_scope, Error &error); + Dereference (Error &error); virtual lldb::ValueObjectSP AddressOf (Error &error); diff --git a/lldb/include/lldb/Target/Target.h b/lldb/include/lldb/Target/Target.h index bb6962ec8864..4bb3e3f02d65 100644 --- a/lldb/include/lldb/Target/Target.h +++ b/lldb/include/lldb/Target/Target.h @@ -173,6 +173,12 @@ private: public: ~Target(); + Mutex & + GetAPIMutex () + { + return m_mutex; + } + void DeleteCurrentProcess (); @@ -472,6 +478,7 @@ protected: // Member variables. //------------------------------------------------------------------ Debugger & m_debugger; + Mutex m_mutex; ///< An API mutex that is used by the lldb::SB* classes make the SB interface thread safe ArchSpec m_arch_spec; ModuleList m_images; ///< The list of images for this process (shared libraries and anything dynamically loaded). SectionLoadList m_section_load_list; diff --git a/lldb/source/API/SBAddress.cpp b/lldb/source/API/SBAddress.cpp index 7a7702a04300..61ad71b633cc 100644 --- a/lldb/source/API/SBAddress.cpp +++ b/lldb/source/API/SBAddress.cpp @@ -12,6 +12,8 @@ #include "lldb/API/SBStream.h" #include "lldb/Core/Address.h" #include "lldb/Core/Log.h" +#include "lldb/Host/Mutex.h" +#include "lldb/Target/Target.h" using namespace lldb; using namespace lldb_private; @@ -89,19 +91,22 @@ SBAddress::GetLoadAddress (const SBTarget &target) const { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + lldb::addr_t addr = LLDB_INVALID_ADDRESS; if (m_opaque_ap.get()) { - lldb::addr_t addr = m_opaque_ap->GetLoadAddress (target.get()); - if (log) - log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%llx", target.get(), addr); - return addr; + Mutex::Locker api_locker (target->GetAPIMutex()); + addr = m_opaque_ap->GetLoadAddress (target.get()); } - else + + if (log) { - if (log) + if (addr == LLDB_INVALID_ADDRESS) log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", target.get()); - return LLDB_INVALID_ADDRESS; + else + log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%llx", target.get(), addr); } + + return addr; } bool diff --git a/lldb/source/API/SBBreakpoint.cpp b/lldb/source/API/SBBreakpoint.cpp index 8954683ebbab..9f2e3a1810cf 100644 --- a/lldb/source/API/SBBreakpoint.cpp +++ b/lldb/source/API/SBBreakpoint.cpp @@ -105,18 +105,19 @@ SBBreakpoint::GetID () const { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + break_id_t break_id = LLDB_INVALID_BREAK_ID; if (m_opaque_sp) - { - break_id_t break_id = m_opaque_sp->GetID(); - if (log) - log->Printf ("SBBreakpoint(%p)::GetID () => %u", m_opaque_sp.get(), break_id); - return break_id; - } + break_id = m_opaque_sp->GetID(); if (log) - log->Printf ("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID", m_opaque_sp.get()); + { + if (break_id == LLDB_INVALID_BREAK_ID) + log->Printf ("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID", m_opaque_sp.get()); + else + log->Printf ("SBBreakpoint(%p)::GetID () => %u", m_opaque_sp.get(), break_id); + } - return LLDB_INVALID_BREAK_ID; + return break_id; } @@ -130,7 +131,10 @@ void SBBreakpoint::ClearAllBreakpointSites () { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); m_opaque_sp->ClearAllBreakpointSites (); + } } SBBreakpointLocation @@ -142,6 +146,7 @@ SBBreakpoint::FindLocationByAddress (addr_t vm_addr) { if (vm_addr != LLDB_INVALID_ADDRESS) { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); Address address; Target &target = m_opaque_sp->GetTarget(); if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false) @@ -158,24 +163,22 @@ SBBreakpoint::FindLocationByAddress (addr_t vm_addr) break_id_t SBBreakpoint::FindLocationIDByAddress (addr_t vm_addr) { - break_id_t lldb_id = (break_id_t) 0; + break_id_t break_id = LLDB_INVALID_BREAK_ID; - if (m_opaque_sp) + if (m_opaque_sp && vm_addr != LLDB_INVALID_ADDRESS) { - if (vm_addr != LLDB_INVALID_ADDRESS) + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + Address address; + Target &target = m_opaque_sp->GetTarget(); + if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false) { - Address address; - Target &target = m_opaque_sp->GetTarget(); - if (target.GetSectionLoadList().ResolveLoadAddress (vm_addr, address) == false) - { - address.SetSection (NULL); - address.SetOffset (vm_addr); - } - lldb_id = m_opaque_sp->FindLocationIDByAddress (address); + address.SetSection (NULL); + address.SetOffset (vm_addr); } + break_id = m_opaque_sp->FindLocationIDByAddress (address); } - return lldb_id; + return break_id; } SBBreakpointLocation @@ -184,7 +187,10 @@ SBBreakpoint::FindLocationByID (break_id_t bp_loc_id) SBBreakpointLocation sb_bp_location; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); sb_bp_location.SetLocation (m_opaque_sp->FindLocationByID (bp_loc_id)); + } return sb_bp_location; } @@ -195,7 +201,10 @@ SBBreakpoint::GetLocationAtIndex (uint32_t index) SBBreakpointLocation sb_bp_location; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); sb_bp_location.SetLocation (m_opaque_sp->GetLocationAtIndex (index)); + } return sb_bp_location; } @@ -209,14 +218,20 @@ SBBreakpoint::SetEnabled (bool enable) log->Printf ("SBBreakpoint(%p)::SetEnabled (enabled=%i)", m_opaque_sp.get(), enable); if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); m_opaque_sp->SetEnabled (enable); + } } bool SBBreakpoint::IsEnabled () { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); return m_opaque_sp->IsEnabled(); + } else return false; } @@ -230,19 +245,31 @@ SBBreakpoint::SetIgnoreCount (uint32_t count) log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)", m_opaque_sp.get(), count); if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); m_opaque_sp->SetIgnoreCount (count); + } } void SBBreakpoint::SetCondition (const char *condition) { - m_opaque_sp->SetCondition (condition); + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetCondition (condition); + } } const char * SBBreakpoint::GetCondition () { - return m_opaque_sp->GetConditionText (); + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->GetConditionText (); + } + return NULL; } uint32_t @@ -250,7 +277,10 @@ SBBreakpoint::GetHitCount () const { uint32_t count = 0; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); count = m_opaque_sp->GetHitCount(); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -264,7 +294,10 @@ SBBreakpoint::GetIgnoreCount () const { uint32_t count = 0; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); count = m_opaque_sp->GetIgnoreCount(); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -277,7 +310,10 @@ void SBBreakpoint::SetThreadID (tid_t tid) { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); m_opaque_sp->SetThreadID (tid); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4x)", m_opaque_sp.get(), tid); @@ -289,7 +325,10 @@ SBBreakpoint::GetThreadID () { tid_t tid = LLDB_INVALID_THREAD_ID; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); tid = m_opaque_sp->GetThreadID(); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -304,7 +343,10 @@ SBBreakpoint::SetThreadIndex (uint32_t index) if (log) log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)", m_opaque_sp.get(), index); if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index); + } } uint32_t @@ -313,7 +355,8 @@ SBBreakpoint::GetThreadIndex() const uint32_t thread_idx = UINT32_MAX; if (m_opaque_sp) { - const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpec(); + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate(); if (thread_spec != NULL) thread_idx = thread_spec->GetIndex(); } @@ -333,7 +376,10 @@ SBBreakpoint::SetThreadName (const char *thread_name) log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)", m_opaque_sp.get(), thread_name); if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name); + } } const char * @@ -342,7 +388,8 @@ SBBreakpoint::GetThreadName () const const char *name = NULL; if (m_opaque_sp) { - const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpec(); + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate(); if (thread_spec != NULL) name = thread_spec->GetName(); } @@ -360,7 +407,10 @@ SBBreakpoint::SetQueueName (const char *queue_name) if (log) log->Printf ("SBBreakpoint(%p)::SetQueueName (%s)", m_opaque_sp.get(), queue_name); if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name); + } } const char * @@ -369,7 +419,9 @@ SBBreakpoint::GetQueueName () const const char *name = NULL; if (m_opaque_sp) { - const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpec(); + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate(); + if (thread_spec) name = thread_spec->GetQueueName(); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -384,7 +436,10 @@ SBBreakpoint::GetNumResolvedLocations() const { size_t num_resolved = 0; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); num_resolved = m_opaque_sp->GetNumResolvedLocations(); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %zu", m_opaque_sp.get(), num_resolved); @@ -396,7 +451,10 @@ SBBreakpoint::GetNumLocations() const { size_t num_locs = 0; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); num_locs = m_opaque_sp->GetNumLocations(); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %zu", m_opaque_sp.get(), num_locs); @@ -408,6 +466,7 @@ SBBreakpoint::GetDescription (SBStream &s) { if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID()); m_opaque_sp->GetResolverDescription (s.get()); m_opaque_sp->GetFilterDescription (s.get()); @@ -465,6 +524,7 @@ SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton) if (m_opaque_sp.get()) { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton)); m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false); } diff --git a/lldb/source/API/SBBreakpointLocation.cpp b/lldb/source/API/SBBreakpointLocation.cpp index af6894266cdb..1e7738ced7b8 100644 --- a/lldb/source/API/SBBreakpointLocation.cpp +++ b/lldb/source/API/SBBreakpointLocation.cpp @@ -20,6 +20,7 @@ #include "lldb/Core/Log.h" #include "lldb/Core/Stream.h" #include "lldb/Core/StreamFile.h" +#include "lldb/Target/Target.h" #include "lldb/Target/ThreadSpec.h" using namespace lldb; @@ -76,6 +77,7 @@ SBBreakpointLocation::GetLoadAddress () if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); ret_addr = m_opaque_sp->GetLoadAddress(); } @@ -87,6 +89,7 @@ SBBreakpointLocation::SetEnabled (bool enabled) { if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); m_opaque_sp->SetEnabled (enabled); } } @@ -95,7 +98,10 @@ bool SBBreakpointLocation::IsEnabled () { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); return m_opaque_sp->IsEnabled(); + } else return false; } @@ -104,7 +110,10 @@ uint32_t SBBreakpointLocation::GetIgnoreCount () { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); return m_opaque_sp->GetIgnoreCount(); + } else return 0; } @@ -113,56 +122,79 @@ void SBBreakpointLocation::SetIgnoreCount (uint32_t n) { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); m_opaque_sp->SetIgnoreCount (n); + } } void SBBreakpointLocation::SetCondition (const char *condition) { - m_opaque_sp->SetCondition (condition); + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); + m_opaque_sp->SetCondition (condition); + } } const char * SBBreakpointLocation::GetCondition () { - return m_opaque_sp->GetConditionText (); + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); + return m_opaque_sp->GetConditionText (); + } + return NULL; } void SBBreakpointLocation::SetThreadID (tid_t thread_id) { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); m_opaque_sp->SetThreadID (thread_id); + } } tid_t SBBreakpointLocation::GetThreadID () { - tid_t sb_thread_id = (lldb::tid_t) LLDB_INVALID_THREAD_ID; + tid_t tid = LLDB_INVALID_THREAD_ID; if (m_opaque_sp) - sb_thread_id = m_opaque_sp->GetLocationOptions()->GetThreadSpecNoCreate()->GetTID(); - return sb_thread_id; + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); + const ThreadSpec *thread_spec = m_opaque_sp->GetLocationOptions()->GetThreadSpecNoCreate(); + if (thread_spec) + tid = thread_spec->GetTID(); + } + return tid; } void SBBreakpointLocation::SetThreadIndex (uint32_t index) { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetIndex (index); + } } uint32_t SBBreakpointLocation::GetThreadIndex() const { + uint32_t thread_idx = UINT32_MAX; if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate(); - if (thread_spec == NULL) - return 0; - else - return thread_spec->GetIndex(); + if (thread_spec) + thread_idx = thread_spec->GetIndex(); } - return 0; + return thread_idx; } @@ -170,7 +202,10 @@ void SBBreakpointLocation::SetThreadName (const char *thread_name) { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetName (thread_name); + } } const char * @@ -178,10 +213,9 @@ SBBreakpointLocation::GetThreadName () const { if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate(); - if (thread_spec == NULL) - return NULL; - else + if (thread_spec) return thread_spec->GetName(); } return NULL; @@ -191,7 +225,10 @@ void SBBreakpointLocation::SetQueueName (const char *queue_name) { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); m_opaque_sp->GetLocationOptions()->GetThreadSpec()->SetQueueName (queue_name); + } } const char * @@ -199,10 +236,9 @@ SBBreakpointLocation::GetQueueName () const { if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); const ThreadSpec *thread_spec = m_opaque_sp->GetOptionsNoCreate()->GetThreadSpecNoCreate(); - if (thread_spec == NULL) - return NULL; - else + if (thread_spec) return thread_spec->GetQueueName(); } return NULL; @@ -212,18 +248,17 @@ bool SBBreakpointLocation::IsResolved () { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); return m_opaque_sp->IsResolved(); - else - return false; + } + return false; } void SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp) { - if (m_opaque_sp) - { - // Uninstall the callbacks? - } + // Uninstall the callbacks? m_opaque_sp = break_loc_sp; } @@ -232,6 +267,7 @@ SBBreakpointLocation::GetDescription (DescriptionLevel level, SBStream &descript { if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); description.ref(); m_opaque_sp->GetDescription (description.get(), level); description.get()->EOL(); @@ -252,7 +288,10 @@ SBBreakpointLocation::GetBreakpoint () SBBreakpoint sb_bp; if (m_opaque_sp) - *sb_bp = m_opaque_sp->GetBreakpoint ().GetSP(); + { + Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex()); + *sb_bp = m_opaque_sp->GetBreakpoint ().GetSP(); + } if (log) { diff --git a/lldb/source/API/SBCommandInterpreter.cpp b/lldb/source/API/SBCommandInterpreter.cpp index 8d748570a5d9..ddd26cf84663 100644 --- a/lldb/source/API/SBCommandInterpreter.cpp +++ b/lldb/source/API/SBCommandInterpreter.cpp @@ -91,6 +91,10 @@ SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnOb result.Clear(); if (m_opaque_ptr) { + TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); + Mutex::Locker api_locker; + if (target_sp) + api_locker.Reset(target_sp->GetAPIMutex().GetMutex()); m_opaque_ptr->HandleCommand (command_line, add_to_history, result.ref()); } else @@ -163,10 +167,12 @@ SBCommandInterpreter::GetProcess () SBProcess process; if (m_opaque_ptr) { - Debugger &debugger = m_opaque_ptr->GetDebugger(); - Target *target = debugger.GetSelectedTarget().get(); - if (target) - process.SetProcess(target->GetProcessSP()); + TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); + if (target_sp) + { + Mutex::Locker api_locker(target_sp->GetAPIMutex()); + process.SetProcess(target_sp->GetProcessSP()); + } } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -229,6 +235,10 @@ SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &resu result.Clear(); if (m_opaque_ptr) { + TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); + Mutex::Locker api_locker; + if (target_sp) + api_locker.Reset(target_sp->GetAPIMutex().GetMutex()); m_opaque_ptr->SourceInitFile (false, result.ref()); } else @@ -250,6 +260,10 @@ SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnOb result.Clear(); if (m_opaque_ptr) { + TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); + Mutex::Locker api_locker; + if (target_sp) + api_locker.Reset(target_sp->GetAPIMutex().GetMutex()); m_opaque_ptr->SourceInitFile (true, result.ref()); } else diff --git a/lldb/source/API/SBDebugger.cpp b/lldb/source/API/SBDebugger.cpp index a2d836f99342..eea2ba290511 100644 --- a/lldb/source/API/SBDebugger.cpp +++ b/lldb/source/API/SBDebugger.cpp @@ -216,6 +216,11 @@ SBDebugger::HandleCommand (const char *command) { if (m_opaque_sp) { + TargetSP target_sp (m_opaque_sp->GetSelectedTarget()); + Mutex::Locker api_locker; + if (target_sp) + api_locker.Reset(target_sp->GetAPIMutex().GetMutex()); + SBCommandInterpreter sb_interpreter(GetCommandInterpreter ()); SBCommandReturnObject result; @@ -262,110 +267,41 @@ SBDebugger::GetListener () void SBDebugger::HandleProcessEvent (const SBProcess &process, const SBEvent &event, FILE *out, FILE *err) { - const uint32_t event_type = event.GetType(); - char stdio_buffer[1024]; - size_t len; + if (!process.IsValid()) + return; - if (event_type & Process::eBroadcastBitSTDOUT) - { - while ((len = process.GetSTDOUT (stdio_buffer, sizeof (stdio_buffer))) > 0) - if (out != NULL) - ::fwrite (stdio_buffer, 1, len, out); - } - else if (event_type & Process::eBroadcastBitSTDERR) - { - while ((len = process.GetSTDERR (stdio_buffer, sizeof (stdio_buffer))) > 0) - if (out != NULL) - ::fwrite (stdio_buffer, 1, len, out); - } - else if (event_type & Process::eBroadcastBitStateChanged) - { - // Drain any stdout messages. - while ((len = process.GetSTDOUT (stdio_buffer, sizeof (stdio_buffer))) > 0) - if (out != NULL) - ::fwrite (stdio_buffer, 1, len, out); + const uint32_t event_type = event.GetType(); + char stdio_buffer[1024]; + size_t len; - // Drain any stderr messages. - while ((len = process.GetSTDERR (stdio_buffer, sizeof (stdio_buffer))) > 0) - if (out != NULL) - ::fwrite (stdio_buffer, 1, len, out); - - StateType event_state = SBProcess::GetStateFromEvent (event); - - if (event_state == eStateInvalid) - return; - - bool is_stopped = StateIsStoppedState (event_state); - if (!is_stopped) - process.ReportEventState (event, out); - } -} - -void -SBDebugger::UpdateSelectedThread (SBProcess &process) -{ - if (process.IsValid()) + Mutex::Locker api_locker (process.GetTarget()->GetAPIMutex()); + + if (event_type & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged)) { - SBThread curr_thread = process.GetSelectedThread (); - SBThread thread; - StopReason curr_thread_stop_reason = eStopReasonInvalid; - if (curr_thread.IsValid()) - { - if (curr_thread.GetStopReason() != eStopReasonInvalid) - curr_thread_stop_reason = curr_thread.GetStopReason (); - } - - if (! curr_thread.IsValid() - || curr_thread_stop_reason == eStopReasonInvalid - || curr_thread_stop_reason == eStopReasonNone) - { - // Prefer a thread that has just completed its plan over another thread as current thread. - SBThread plan_thread; - SBThread other_thread; - const size_t num_threads = process.GetNumThreads (); - size_t i; - for (i = 0; i < num_threads; ++i) - { - thread = process.GetThreadAtIndex(i); - if (thread.GetStopReason () != eStopReasonInvalid) - { - switch (thread.GetStopReason ()) - { - default: - case eStopReasonInvalid: - case eStopReasonNone: - break; - - case eStopReasonTrace: - case eStopReasonBreakpoint: - case eStopReasonWatchpoint: - case eStopReasonSignal: - case eStopReasonException: - if (! other_thread.IsValid()) - other_thread = thread; - break; - case eStopReasonPlanComplete: - if (! plan_thread.IsValid()) - plan_thread = thread; - break; - } - } - } - if (plan_thread.IsValid()) - process.SetSelectedThreadByID (plan_thread.GetThreadID()); - else if (other_thread.IsValid()) - process.SetSelectedThreadByID (other_thread.GetThreadID()); - else - { - if (curr_thread.IsValid()) - thread = curr_thread; - else - thread = process.GetThreadAtIndex(0); - - if (thread.IsValid()) - process.SetSelectedThreadByID (thread.GetThreadID()); - } - } + // Drain stdout when we stop just in case we have any bytes + while ((len = process.GetSTDOUT (stdio_buffer, sizeof (stdio_buffer))) > 0) + if (out != NULL) + ::fwrite (stdio_buffer, 1, len, out); + } + + if (event_type & (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged)) + { + // Drain stderr when we stop just in case we have any bytes + while ((len = process.GetSTDERR (stdio_buffer, sizeof (stdio_buffer))) > 0) + if (err != NULL) + ::fwrite (stdio_buffer, 1, len, err); + } + + if (event_type & Process::eBroadcastBitStateChanged) + { + StateType event_state = SBProcess::GetStateFromEvent (event); + + if (event_state == eStateInvalid) + return; + + bool is_stopped = StateIsStoppedState (event_state); + if (!is_stopped) + process.ReportEventState (event, out); } } @@ -415,6 +351,7 @@ SBDebugger::SetDefaultArchitecture (const char *arch_name) ScriptLanguage SBDebugger::GetScriptingLanguage (const char *script_language_name) { + return Args::StringToScriptLanguage (script_language_name, eScriptLanguageDefault, NULL); @@ -582,7 +519,10 @@ SBDebugger::GetTargetAtIndex (uint32_t idx) { SBTarget sb_target; if (m_opaque_sp) + { + // No need to lock, the target list is thread safe sb_target.reset(m_opaque_sp->GetTargetList().GetTargetAtIndex (idx)); + } return sb_target; } @@ -591,7 +531,10 @@ SBDebugger::FindTargetWithProcessID (pid_t pid) { SBTarget sb_target; if (m_opaque_sp) + { + // No need to lock, the target list is thread safe sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid)); + } return sb_target; } @@ -601,6 +544,7 @@ SBDebugger::FindTargetWithFileAndArch (const char *filename, const char *arch_na SBTarget sb_target; if (m_opaque_sp && filename && filename[0]) { + // No need to lock, the target list is thread safe ArchSpec arch; if (arch_name) arch.SetArch(arch_name); @@ -615,7 +559,10 @@ SBDebugger::FindTargetWithLLDBProcess (const lldb::ProcessSP &process_sp) { SBTarget sb_target; if (m_opaque_sp) + { + // No need to lock, the target list is thread safe sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get())); + } return sb_target; } @@ -624,7 +571,10 @@ uint32_t SBDebugger::GetNumTargets () { if (m_opaque_sp) + { + // No need to lock, the target list is thread safe return m_opaque_sp->GetTargetList().GetNumTargets (); + } return 0; } @@ -635,7 +585,10 @@ SBDebugger::GetSelectedTarget () SBTarget sb_target; if (m_opaque_sp) + { + // No need to lock, the target list is thread safe sb_target.reset(m_opaque_sp->GetTargetList().GetSelectedTarget ()); + } if (log) { @@ -685,6 +638,10 @@ SBDebugger::PushInputReader (SBInputReader &reader) if (m_opaque_sp && reader.IsValid()) { + TargetSP target_sp (m_opaque_sp->GetSelectedTarget()); + Mutex::Locker api_locker; + if (target_sp) + api_locker.Reset(target_sp->GetAPIMutex().GetMutex()); InputReaderSP reader_sp(*reader); m_opaque_sp->PushInputReader (reader_sp); } @@ -713,6 +670,7 @@ SBDebugger::ref () const SBDebugger SBDebugger::FindDebuggerWithID (int id) { + // No need to lock, the debugger list is thread safe SBDebugger sb_debugger; lldb::DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id); if (debugger_sp) @@ -816,19 +774,17 @@ void SBDebugger::SetScriptLanguage (lldb::ScriptLanguage script_lang) { if (m_opaque_sp) + { m_opaque_sp->SetScriptLanguage (script_lang); + } } - - - bool SBDebugger::SetUseExternalEditor (bool value) { if (m_opaque_sp) return m_opaque_sp->SetUseExternalEditor (value); - else - return false; + return false; } bool @@ -836,8 +792,7 @@ SBDebugger::GetUseExternalEditor () { if (m_opaque_sp) return m_opaque_sp->GetUseExternalEditor (); - else - return false; + return false; } bool diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp index 8bd623b3b853..6c1cf09a6931 100644 --- a/lldb/source/API/SBFrame.cpp +++ b/lldb/source/API/SBFrame.cpp @@ -109,7 +109,10 @@ SBFrame::GetSymbolContext (uint32_t resolve_scope) const SBSymbolContext sb_sym_ctx; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); sb_sym_ctx.SetSymbolContext(&m_opaque_sp->GetSymbolContext (resolve_scope)); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -124,7 +127,10 @@ SBFrame::GetModule () const { SBModule sb_module; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); *sb_module = m_opaque_sp->GetSymbolContext (eSymbolContextModule).module_sp; + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -139,7 +145,10 @@ SBFrame::GetCompileUnit () const { SBCompileUnit sb_comp_unit; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); sb_comp_unit.reset (m_opaque_sp->GetSymbolContext (eSymbolContextCompUnit).comp_unit); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetModule () => SBCompileUnit(%p)", @@ -153,7 +162,10 @@ SBFrame::GetFunction () const { SBFunction sb_function; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); sb_function.reset(m_opaque_sp->GetSymbolContext (eSymbolContextFunction).function); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFunction () => SBFunction(%p)", @@ -167,7 +179,10 @@ SBFrame::GetSymbol () const { SBSymbol sb_symbol; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); sb_symbol.reset(m_opaque_sp->GetSymbolContext (eSymbolContextSymbol).symbol); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetSymbol () => SBSymbol(%p)", @@ -180,7 +195,10 @@ SBFrame::GetBlock () const { SBBlock sb_block; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); sb_block.reset (m_opaque_sp->GetSymbolContext (eSymbolContextBlock).block); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetBlock () => SBBlock(%p)", @@ -193,7 +211,10 @@ SBFrame::GetFrameBlock () const { SBBlock sb_block; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); sb_block.reset(m_opaque_sp->GetFrameBlock ()); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetFrameBlock () => SBBlock(%p)", @@ -206,7 +227,10 @@ SBFrame::GetLineEntry () const { SBLineEntry sb_line_entry; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); sb_line_entry.SetLineEntry (m_opaque_sp->GetSymbolContext (eSymbolContextLineEntry).line_entry); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetLineEntry () => SBLineEntry(%p)", @@ -231,7 +255,10 @@ SBFrame::GetPC () const { addr_t addr = LLDB_INVALID_ADDRESS; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); addr = m_opaque_sp->GetFrameCodeAddress().GetLoadAddress (&m_opaque_sp->GetThread().GetProcess().GetTarget()); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -245,7 +272,10 @@ SBFrame::SetPC (addr_t new_pc) { bool ret_val = false; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); ret_val = m_opaque_sp->GetRegisterContext()->SetPC (new_pc); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -260,7 +290,10 @@ SBFrame::GetSP () const { addr_t addr = LLDB_INVALID_ADDRESS; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); addr = m_opaque_sp->GetRegisterContext()->GetSP(); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetSP () => 0x%llx", m_opaque_sp.get(), addr); @@ -274,7 +307,10 @@ SBFrame::GetFP () const { addr_t addr = LLDB_INVALID_ADDRESS; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); addr = m_opaque_sp->GetRegisterContext()->GetFP(); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -288,7 +324,10 @@ SBFrame::GetPCAddress () const { SBAddress sb_addr; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); sb_addr.SetAddress (&m_opaque_sp->GetFrameCodeAddress()); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBFrame(%p)::GetPCAddress () => SBAddress(%p)", m_opaque_sp.get(), sb_addr.get()); @@ -308,7 +347,7 @@ SBFrame::FindVariable (const char *name) if (m_opaque_sp && name && name[0]) { VariableList variable_list; - + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); SymbolContext sc (m_opaque_sp->GetSymbolContext (eSymbolContextBlock)); if (sc.block) @@ -346,6 +385,7 @@ SBFrame::FindValue (const char *name, ValueType value_type) SBValue sb_value; if (m_opaque_sp && name && name[0]) { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); switch (value_type) { @@ -479,7 +519,10 @@ SBFrame::GetThread () const SBThread sb_thread; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); sb_thread.SetThread (m_opaque_sp->GetThread().GetSP()); + } if (log) { @@ -497,7 +540,10 @@ SBFrame::Disassemble () const { const char *disassembly = NULL; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); disassembly = m_opaque_sp->Disassemble(); + } LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -526,8 +572,14 @@ SBFrame::GetVariables (bool arguments, SBValueList value_list; if (m_opaque_sp) { + size_t i; - VariableList *variable_list = m_opaque_sp->GetVariableList(true); + VariableList *variable_list = NULL; + // Scope for locker + { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + variable_list = m_opaque_sp->GetVariableList(true); + } if (variable_list) { const size_t num_variables = variable_list->GetSize(); @@ -587,6 +639,7 @@ SBFrame::GetRegisters () SBValueList value_list; if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); RegisterContext *reg_ctx = m_opaque_sp->GetRegisterContext(); if (reg_ctx) { @@ -609,6 +662,7 @@ SBFrame::GetDescription (SBStream &description) { if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); Stream &s = description.ref(); m_opaque_sp->DumpUsingSettingsFormat (&s); } @@ -621,6 +675,8 @@ SBFrame::GetDescription (SBStream &description) SBValue SBFrame::EvaluateExpression (const char *expr) { + Mutex::Locker api_locker (m_opaque_sp->GetThread().GetProcess().GetTarget().GetAPIMutex()); + LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); LogSP expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); diff --git a/lldb/source/API/SBFunction.cpp b/lldb/source/API/SBFunction.cpp index 54081b55ac3b..853a6ffd4f2c 100644 --- a/lldb/source/API/SBFunction.cpp +++ b/lldb/source/API/SBFunction.cpp @@ -125,9 +125,11 @@ SBFunction::GetInstructions (SBTarget target) SBInstructionList sb_instructions; if (m_opaque_ptr) { + Mutex::Locker api_locker; ExecutionContext exe_ctx; if (target.IsValid()) { + api_locker.Reset (target->GetAPIMutex().GetMutex()); target->CalculateExecutionContext (exe_ctx); exe_ctx.process = target->GetProcessSP().get(); } diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp index 0c2eac500c71..bfdf8578b1c6 100644 --- a/lldb/source/API/SBProcess.cpp +++ b/lldb/source/API/SBProcess.cpp @@ -104,6 +104,7 @@ SBProcess::GetNumThreads () uint32_t num_threads = 0; if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); const bool can_update = true; num_threads = m_opaque_sp->GetThreadList().GetSize(can_update); } @@ -121,7 +122,10 @@ SBProcess::GetSelectedThread () const SBThread sb_thread; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); sb_thread.SetThread (m_opaque_sp->GetThreadList().GetSelectedThread()); + } if (log) { @@ -153,7 +157,7 @@ SBProcess::PutSTDIN (const char *src, size_t src_len) LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); size_t ret_val = 0; - if (m_opaque_sp != NULL) + if (m_opaque_sp) { Error error; ret_val = m_opaque_sp->PutSTDIN (src, src_len, error); @@ -173,7 +177,7 @@ size_t SBProcess::GetSTDOUT (char *dst, size_t dst_len) const { size_t bytes_read = 0; - if (m_opaque_sp != NULL) + if (m_opaque_sp) { Error error; bytes_read = m_opaque_sp->GetSTDOUT (dst, dst_len, error); @@ -191,7 +195,7 @@ size_t SBProcess::GetSTDERR (char *dst, size_t dst_len) const { size_t bytes_read = 0; - if (m_opaque_sp != NULL) + if (m_opaque_sp) { Error error; bytes_read = m_opaque_sp->GetSTDERR (dst, dst_len, error); @@ -211,7 +215,7 @@ SBProcess::ReportEventState (const SBEvent &event, FILE *out) const if (out == NULL) return; - if (m_opaque_sp != NULL) + if (m_opaque_sp) { const StateType event_state = SBProcess::GetStateFromEvent (event); char message[1024]; @@ -229,7 +233,7 @@ SBProcess::ReportEventState (const SBEvent &event, FILE *out) const void SBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject &result) { - if (m_opaque_sp != NULL) + if (m_opaque_sp) { const StateType event_state = SBProcess::GetStateFromEvent (event); char message[1024]; @@ -246,8 +250,11 @@ SBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject & bool SBProcess::SetSelectedThread (const SBThread &thread) { - if (m_opaque_sp != NULL) + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); return m_opaque_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID()); + } return false; } @@ -257,8 +264,11 @@ SBProcess::SetSelectedThreadByID (uint32_t tid) LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); bool ret_val = false; - if (m_opaque_sp != NULL) + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); ret_val = m_opaque_sp->GetThreadList().SetSelectedThreadByID (tid); + } if (log) log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%4.4x) => %s", @@ -274,7 +284,10 @@ SBProcess::GetThreadAtIndex (size_t index) SBThread thread; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); thread.SetThread (m_opaque_sp->GetThreadList().GetThreadAtIndex(index)); + } if (log) { @@ -290,8 +303,11 @@ SBProcess::GetState () { StateType ret_val = eStateInvalid; - if (m_opaque_sp != NULL) + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); ret_val = m_opaque_sp->GetState(); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -308,7 +324,10 @@ SBProcess::GetExitStatus () { int exit_status = 0; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); exit_status = m_opaque_sp->GetExitStatus (); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)", @@ -321,8 +340,11 @@ const char * SBProcess::GetExitDescription () { const char *exit_desc = NULL; - if (m_opaque_sp != NULL) + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); exit_desc = m_opaque_sp->GetExitDescription (); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBProcess(%p)::GetExitDescription () => %s", @@ -361,6 +383,8 @@ SBProcess::GetAddressByteSize () const SBError SBProcess::Continue () { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) log->Printf ("SBProcess(%p)::Continue ()...", m_opaque_sp.get()); @@ -397,6 +421,8 @@ SBProcess::Continue () SBError SBProcess::Destroy () { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + SBError sb_error; if (m_opaque_sp) sb_error.SetError(m_opaque_sp->Destroy()); @@ -418,10 +444,12 @@ SBProcess::Destroy () SBError SBProcess::Stop () { - SBError sb_error; if (IsValid()) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); sb_error.SetError (m_opaque_sp->Halt()); + } else sb_error.SetErrorString ("SBProcess is invalid"); @@ -442,10 +470,12 @@ SBProcess::Stop () SBError SBProcess::Kill () { - SBError sb_error; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); sb_error.SetError (m_opaque_sp->Destroy()); + } else sb_error.SetErrorString ("SBProcess is invalid"); @@ -463,43 +493,15 @@ SBProcess::Kill () return sb_error; } - -SBError -SBProcess::AttachByName (const char *name, bool wait_for_launch) // DEPRECATED -{ - SBError sb_error; - if (m_opaque_sp) - sb_error.SetError (m_opaque_sp->Attach (name, wait_for_launch)); - else - sb_error.SetErrorString ("SBProcess is invalid"); - return sb_error; -} - -lldb::pid_t -SBProcess::AttachByPID (lldb::pid_t attach_pid) // DEPRECATED -{ - Attach (attach_pid); - return GetProcessID(); -} - - -SBError -SBProcess::Attach (lldb::pid_t attach_pid) // DEPRECATED -{ - SBError sb_error; - if (m_opaque_sp) - sb_error.SetError (m_opaque_sp->Attach (attach_pid)); - else - sb_error.SetErrorString ("SBProcess is invalid"); - return sb_error; -} - SBError SBProcess::Detach () { SBError sb_error; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); sb_error.SetError (m_opaque_sp->Detach()); + } else sb_error.SetErrorString ("SBProcess is invalid"); @@ -511,7 +513,10 @@ SBProcess::Signal (int signo) { SBError sb_error; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); sb_error.SetError (m_opaque_sp->Signal (signo)); + } else sb_error.SetErrorString ("SBProcess is invalid"); LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -533,7 +538,10 @@ SBProcess::GetThreadByID (tid_t tid) { SBThread sb_thread; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); sb_thread.SetThread (m_opaque_sp->GetThreadList().FindThreadByID ((tid_t) tid)); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -612,9 +620,10 @@ SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error sb_error.get()); } - if (IsValid()) + if (m_opaque_sp) { Error error; + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); bytes_read = m_opaque_sp->ReadMemory (addr, dst, dst_len, error); sb_error.SetError (error); } @@ -656,9 +665,10 @@ SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &s sb_error.get()); } - if (IsValid()) + if (m_opaque_sp) { Error error; + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); bytes_written = m_opaque_sp->WriteMemory (addr, src, src_len, error); sb_error.SetError (error); } @@ -716,7 +726,10 @@ uint32_t SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error) { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); return m_opaque_sp->LoadImage (*sb_image_spec, sb_error.ref()); + } return LLDB_INVALID_IMAGE_TOKEN; } @@ -725,7 +738,10 @@ SBProcess::UnloadImage (uint32_t image_token) { lldb::SBError sb_error; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); sb_error.SetError (m_opaque_sp->UnloadImage (image_token)); + } else sb_error.SetErrorString("invalid process"); return sb_error; diff --git a/lldb/source/API/SBSymbol.cpp b/lldb/source/API/SBSymbol.cpp index 4c8e02caef17..8f6593c3bc78 100644 --- a/lldb/source/API/SBSymbol.cpp +++ b/lldb/source/API/SBSymbol.cpp @@ -120,9 +120,13 @@ SBSymbol::GetInstructions (SBTarget target) SBInstructionList sb_instructions; if (m_opaque_ptr) { + Mutex::Locker api_locker; ExecutionContext exe_ctx; if (target.IsValid()) + { + api_locker.Reset (target->GetAPIMutex().GetMutex()); target->CalculateExecutionContext (exe_ctx); + } const AddressRange *symbol_range = m_opaque_ptr->GetAddressRangePtr(); if (symbol_range) { diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp index 039c0ecdd511..b23262b00051 100644 --- a/lldb/source/API/SBTarget.cpp +++ b/lldb/source/API/SBTarget.cpp @@ -92,7 +92,10 @@ SBTarget::GetProcess () SBProcess sb_process; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); sb_process.SetProcess (m_opaque_sp->GetProcessSP()); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -113,28 +116,6 @@ SBTarget::GetDebugger () const return debugger; } - -// DEPRECATED -SBProcess -SBTarget::CreateProcess () -{ - - SBProcess sb_process; - - if (m_opaque_sp) - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); - - LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - { - log->Printf ("SBTarget(%p)::CreateProcess () => SBProcess(%p)", - m_opaque_sp.get(), sb_process.get()); - } - - return sb_process; -} - - SBProcess SBTarget::LaunchProcess ( @@ -185,17 +166,8 @@ SBTarget::Launch SBProcess sb_process; if (m_opaque_sp) { - // DEPRECATED, this will change when CreateProcess is removed... - if (m_opaque_sp->GetProcessSP()) - { - sb_process.SetProcess(m_opaque_sp->GetProcessSP()); - } - else - { - // When launching, we always want to create a new process When - // SBTarget::CreateProcess is removed, this will always happen. - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); - } + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); if (sb_process.IsValid()) { @@ -253,17 +225,8 @@ SBTarget::AttachToProcessWithID SBProcess sb_process; if (m_opaque_sp) { - // DEPRECATED, this will change when CreateProcess is removed... - if (m_opaque_sp->GetProcessSP()) - { - sb_process.SetProcess(m_opaque_sp->GetProcessSP()); - } - else - { - // When launching, we always want to create a new process When - // SBTarget::CreateProcess is removed, this will always happen. - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); - } + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); if (sb_process.IsValid()) { @@ -293,17 +256,9 @@ SBTarget::AttachToProcessWithName SBProcess sb_process; if (m_opaque_sp) { - // DEPRECATED, this will change when CreateProcess is removed... - if (m_opaque_sp->GetProcessSP()) - { - sb_process.SetProcess(m_opaque_sp->GetProcessSP()); - } - else - { - // When launching, we always want to create a new process When - // SBTarget::CreateProcess is removed, this will always happen. - sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); - } + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); + + sb_process.SetProcess (m_opaque_sp->CreateProcess (m_opaque_sp->GetDebugger().GetListener())); if (sb_process.IsValid()) { @@ -389,7 +344,10 @@ SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr, lldb::SBAddress& addr) { if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); return m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (vm_addr, *addr); + } addr->Clear(); return false; @@ -408,7 +366,10 @@ SBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, uint32_t l SBBreakpoint sb_bp; if (m_opaque_sp.get() && line != 0) + { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); *sb_bp = m_opaque_sp->CreateBreakpoint (NULL, *sb_file_spec, line, true, false); + } if (log) { @@ -435,6 +396,7 @@ SBTarget::BreakpointCreateByName (const char *symbol_name, const char *module_na SBBreakpoint sb_bp; if (m_opaque_sp.get() && symbol_name && symbol_name[0]) { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); if (module_name && module_name[0]) { FileSpec module_file_spec(module_name, false); @@ -463,6 +425,7 @@ SBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, const char *mo SBBreakpoint sb_bp; if (m_opaque_sp.get() && symbol_name_regex && symbol_name_regex[0]) { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); RegularExpression regexp(symbol_name_regex); if (module_name && module_name[0]) @@ -495,7 +458,10 @@ SBTarget::BreakpointCreateByAddress (addr_t address) SBBreakpoint sb_bp; if (m_opaque_sp.get()) + { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); *sb_bp = m_opaque_sp->CreateBreakpoint (address, false); + } if (log) { @@ -512,7 +478,10 @@ SBTarget::FindBreakpointByID (break_id_t bp_id) SBBreakpoint sb_breakpoint; if (m_opaque_sp && bp_id != LLDB_INVALID_BREAK_ID) + { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); *sb_breakpoint = m_opaque_sp->GetBreakpointByID (bp_id); + } if (log) { @@ -527,7 +496,10 @@ uint32_t SBTarget::GetNumBreakpoints () const { if (m_opaque_sp) + { + // The breakpoint list is thread safe, no need to lock return m_opaque_sp->GetBreakpointList().GetSize(); + } return 0; } @@ -536,7 +508,10 @@ SBTarget::GetBreakpointAtIndex (uint32_t idx) const { SBBreakpoint sb_breakpoint; if (m_opaque_sp) + { + // The breakpoint list is thread safe, no need to lock *sb_breakpoint = m_opaque_sp->GetBreakpointList().GetBreakpointAtIndex(idx); + } return sb_breakpoint; } @@ -547,7 +522,10 @@ SBTarget::BreakpointDelete (break_id_t bp_id) bool result = false; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); result = m_opaque_sp->RemoveBreakpointByID (bp_id); + } if (log) { @@ -562,6 +540,7 @@ SBTarget::EnableAllBreakpoints () { if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); m_opaque_sp->EnableAllBreakpoints (); return true; } @@ -573,6 +552,7 @@ SBTarget::DisableAllBreakpoints () { if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); m_opaque_sp->DisableAllBreakpoints (); return true; } @@ -584,6 +564,7 @@ SBTarget::DeleteAllBreakpoints () { if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetAPIMutex()); m_opaque_sp->RemoveAllBreakpoints (); return true; } @@ -598,7 +579,10 @@ SBTarget::GetNumModules () const uint32_t num = 0; if (m_opaque_sp) - num = m_opaque_sp->GetImages().GetSize(); + { + // The module list is thread safe, no need to lock + num = m_opaque_sp->GetImages().GetSize(); + } if (log) log->Printf ("SBTarget(%p)::GetNumModules () => %d", m_opaque_sp.get(), num); @@ -623,7 +607,10 @@ SBTarget::FindModule (const SBFileSpec &sb_file_spec) { SBModule sb_module; if (m_opaque_sp && sb_file_spec.IsValid()) + { + // The module list is thread safe, no need to lock sb_module.SetModule (m_opaque_sp->GetImages().FindFirstModuleForFileSpec (*sb_file_spec, NULL)); + } return sb_module; } @@ -634,7 +621,10 @@ SBTarget::GetModuleAtIndex (uint32_t idx) SBModule sb_module; if (m_opaque_sp) + { + // The module list is thread safe, no need to lock sb_module.SetModule(m_opaque_sp->GetImages().GetModuleAtIndex(idx)); + } if (log) { @@ -660,130 +650,6 @@ SBTarget::GetBroadcaster () const return broadcaster; } -void -SBTarget::Disassemble (lldb::addr_t start_addr, lldb::addr_t end_addr, const char *module_name) -{ - if (start_addr == LLDB_INVALID_ADDRESS) - return; - - FILE *out = m_opaque_sp->GetDebugger().GetOutputFileHandle(); - if (out == NULL) - return; - - if (m_opaque_sp) - { - ModuleSP module_sp; - if (module_name != NULL) - { - FileSpec module_file_spec (module_name, false); - module_sp = m_opaque_sp->GetImages().FindFirstModuleForFileSpec (module_file_spec, NULL); - } - - AddressRange range; - - // Make sure the process object is alive if we have one (it might be - // created but we might not be launched yet). - - Process *sb_process = m_opaque_sp->GetProcessSP().get(); - if (sb_process && !sb_process->IsAlive()) - sb_process = NULL; - - // If we are given a module, then "start_addr" is a file address in - // that module. - if (module_sp) - { - if (!module_sp->ResolveFileAddress (start_addr, range.GetBaseAddress())) - range.GetBaseAddress().SetOffset(start_addr); - } - else if (m_opaque_sp->GetSectionLoadList().IsEmpty() == false) - { - // We don't have a module, se we need to figure out if "start_addr" - // resolves to anything in a running process. - if (!m_opaque_sp->GetSectionLoadList().ResolveLoadAddress (start_addr, range.GetBaseAddress())) - range.GetBaseAddress().SetOffset(start_addr); - } - else - { - if (m_opaque_sp->GetImages().ResolveFileAddress (start_addr, range.GetBaseAddress())) - range.GetBaseAddress().SetOffset(start_addr); - } - - // For now, we need a process; the disassembly functions insist. If we don't have one already, - // make one. - - ExecutionContext exe_ctx; - - if (sb_process) - sb_process->CalculateExecutionContext(exe_ctx); - else - m_opaque_sp->CalculateExecutionContext(exe_ctx); - - if (end_addr == LLDB_INVALID_ADDRESS || end_addr < start_addr) - range.SetByteSize( DEFAULT_DISASM_BYTE_SIZE); - else - range.SetByteSize(end_addr - start_addr); - - StreamFile out_stream (out); - - Disassembler::Disassemble (m_opaque_sp->GetDebugger(), - m_opaque_sp->GetArchitecture(), - exe_ctx, - range, - 3, - false, - out_stream); - } -} - -void -SBTarget::Disassemble (const char *function_name, const char *module_name) -{ - if (function_name == NULL) - return; - - FILE *out = m_opaque_sp->GetDebugger().GetOutputFileHandle(); - if (out == NULL) - return; - - if (m_opaque_sp) - { - Disassembler *disassembler = Disassembler::FindPlugin (m_opaque_sp->GetArchitecture()); - if (disassembler == NULL) - return; - - ModuleSP module_sp; - if (module_name != NULL) - { - FileSpec module_file_spec (module_name, false); - module_sp = m_opaque_sp->GetImages().FindFirstModuleForFileSpec (module_file_spec, NULL); - } - - ExecutionContext exe_ctx; - - // Make sure the process object is alive if we have one (it might be - // created but we might not be launched yet). - Process *sb_process = m_opaque_sp->GetProcessSP().get(); - if (sb_process && !sb_process->IsAlive()) - sb_process = NULL; - - if (sb_process) - sb_process->CalculateExecutionContext(exe_ctx); - else - m_opaque_sp->CalculateExecutionContext(exe_ctx); - - - StreamFile out_stream (out); - - Disassembler::Disassemble (m_opaque_sp->GetDebugger(), - m_opaque_sp->GetArchitecture(), - exe_ctx, - ConstString (function_name), - module_sp.get(), - 3, - false, - out_stream); - } -} bool SBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) diff --git a/lldb/source/API/SBThread.cpp b/lldb/source/API/SBThread.cpp index cb7cfc5d76eb..772444de85d4 100644 --- a/lldb/source/API/SBThread.cpp +++ b/lldb/source/API/SBThread.cpp @@ -97,6 +97,7 @@ SBThread::GetStopReason() StopReason reason = eStopReasonInvalid; if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo (); if (stop_info_sp) reason = stop_info_sp->GetStopReason(); @@ -114,6 +115,7 @@ SBThread::GetStopReasonDataCount () { if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo (); if (stop_info_sp) { @@ -158,6 +160,7 @@ SBThread::GetStopReasonDataAtIndex (uint32_t idx) { if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo (); if (stop_info_sp) { @@ -219,6 +222,7 @@ SBThread::GetStopDescription (char *dst, size_t dst_len) if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); StopInfoSP stop_info_sp = m_opaque_sp->GetStopInfo (); if (stop_info_sp) { @@ -324,14 +328,14 @@ SBThread::GetThreadID () const { LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - lldb::tid_t id = LLDB_INVALID_THREAD_ID; + lldb::tid_t tid = LLDB_INVALID_THREAD_ID; if (m_opaque_sp) - id = m_opaque_sp->GetID(); + tid = m_opaque_sp->GetID(); if (log) - log->Printf ("SBThread(%p)::GetThreadID () => 0x%4.4x", m_opaque_sp.get(), id); + log->Printf ("SBThread(%p)::GetThreadID () => 0x%4.4x", m_opaque_sp.get(), tid); - return id; + return tid; } uint32_t @@ -346,7 +350,10 @@ SBThread::GetName () const { const char *name = NULL; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); name = m_opaque_sp->GetName(); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -360,7 +367,10 @@ SBThread::GetQueueName () const { const char *name = NULL; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); name = m_opaque_sp->GetQueueName(); + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -381,6 +391,7 @@ SBThread::StepOver (lldb::RunMode stop_other_threads) if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); bool abort_other_plans = true; StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0)); @@ -430,6 +441,7 @@ SBThread::StepInto (lldb::RunMode stop_other_threads) if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); bool abort_other_plans = true; StackFrameSP frame_sp(m_opaque_sp->GetStackFrameAtIndex (0)); @@ -476,6 +488,7 @@ SBThread::StepOut () if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); bool abort_other_plans = true; bool stop_other_threads = true; @@ -504,6 +517,7 @@ SBThread::StepInstruction (bool step_over) if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); m_opaque_sp->QueueThreadPlanForStepSingleInstruction (step_over, true, true); Process &process = m_opaque_sp->GetProcess(); process.GetThreadList().SetSelectedThreadByID (m_opaque_sp->GetID()); @@ -578,7 +592,10 @@ SBThread::GetNumFrames () uint32_t num_frames = 0; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); num_frames = m_opaque_sp->GetStackFrameCount(); + } if (log) log->Printf ("SBThread(%p)::GetNumFrames () => %u", m_opaque_sp.get(), num_frames); @@ -593,7 +610,10 @@ SBThread::GetFrameAtIndex (uint32_t idx) SBFrame sb_frame; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); sb_frame.SetFrame (m_opaque_sp->GetStackFrameAtIndex (idx)); + } if (log) { @@ -613,7 +633,10 @@ SBThread::GetSelectedFrame () SBFrame sb_frame; if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); sb_frame.SetFrame (m_opaque_sp->GetSelectedFrame ()); + } if (log) { @@ -634,6 +657,7 @@ SBThread::SetSelectedFrame (uint32_t idx) SBFrame sb_frame; if (m_opaque_sp) { + Mutex::Locker api_locker (m_opaque_sp->GetProcess().GetTarget().GetAPIMutex()); lldb::StackFrameSP frame_sp (m_opaque_sp->GetStackFrameAtIndex (idx)); if (frame_sp) { diff --git a/lldb/source/API/SBValue.cpp b/lldb/source/API/SBValue.cpp index 538324cb25ab..8161c95ee58a 100644 --- a/lldb/source/API/SBValue.cpp +++ b/lldb/source/API/SBValue.cpp @@ -23,6 +23,7 @@ #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/Process.h" #include "lldb/Target/StackFrame.h" +#include "lldb/Target/Target.h" #include "lldb/Target/Thread.h" #include "lldb/API/SBProcess.h" @@ -135,12 +136,19 @@ SBValue::GetByteSize () } bool -SBValue::IsInScope (const SBFrame &frame) +SBValue::IsInScope (const SBFrame &sb_frame) { bool result = false; if (m_opaque_sp) - result = m_opaque_sp->IsInScope (frame.get()); + { + StackFrame *frame = sb_frame.get(); + if (frame) + { + Mutex::Locker api_locker (frame->GetThread().GetProcess().GetTarget().GetAPIMutex()); + result = m_opaque_sp->IsInScope (frame); + } + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -150,18 +158,25 @@ SBValue::IsInScope (const SBFrame &frame) } const char * -SBValue::GetValue (const SBFrame &frame) +SBValue::GetValue (const SBFrame &sb_frame) { const char *cstr = NULL; - if ( m_opaque_sp) - cstr = m_opaque_sp->GetValueAsCString (frame.get()); + if (m_opaque_sp) + { + StackFrame *frame = sb_frame.get(); + if (frame) + { + Mutex::Locker api_locker (frame->GetThread().GetProcess().GetTarget().GetAPIMutex()); + cstr = m_opaque_sp->GetValueAsCString (frame); + } + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (cstr) - log->Printf ("SBValue(%p)::GetValue (SBFrame(%p)) => \"%s\"", m_opaque_sp.get(), frame.get(), cstr); + log->Printf ("SBValue(%p)::GetValue (SBFrame(%p)) => \"%s\"", m_opaque_sp.get(), sb_frame.get(), cstr); else - log->Printf ("SBValue(%p)::GetValue (SBFrame(%p)) => NULL", m_opaque_sp.get(), frame.get()); + log->Printf ("SBValue(%p)::GetValue (SBFrame(%p)) => NULL", m_opaque_sp.get(), sb_frame.get()); } return cstr; @@ -193,75 +208,110 @@ SBValue::GetValueType () } const char * -SBValue::GetObjectDescription (const SBFrame &frame) +SBValue::GetObjectDescription (const SBFrame &sb_frame) { const char *cstr = NULL; if ( m_opaque_sp) - cstr = m_opaque_sp->GetObjectDescription (frame.get()); + { + StackFrame *frame = sb_frame.get(); + if (frame) + { + Mutex::Locker api_locker (frame->GetThread().GetProcess().GetTarget().GetAPIMutex()); + cstr = m_opaque_sp->GetObjectDescription (frame); + } + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (cstr) - log->Printf ("SBValue(%p)::GetObjectDescription (SBFrame(%p)) => \"%s\"", m_opaque_sp.get(), frame.get(), cstr); + log->Printf ("SBValue(%p)::GetObjectDescription (SBFrame(%p)) => \"%s\"", m_opaque_sp.get(), sb_frame.get(), cstr); else - log->Printf ("SBValue(%p)::GetObjectDescription (SBFrame(%p)) => NULL", m_opaque_sp.get(), frame.get()); + log->Printf ("SBValue(%p)::GetObjectDescription (SBFrame(%p)) => NULL", m_opaque_sp.get(), sb_frame.get()); } return cstr; } bool -SBValue::GetValueDidChange (const SBFrame &frame) +SBValue::GetValueDidChange (const SBFrame &sb_frame) { bool result = false; if (m_opaque_sp) - result = m_opaque_sp->GetValueDidChange (frame.get()); + { + StackFrame *frame = sb_frame.get(); + if (frame) + { + Mutex::Locker api_locker (frame->GetThread().GetProcess().GetTarget().GetAPIMutex()); + result = m_opaque_sp->GetValueDidChange (frame); + } + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBValue(%p)::GetValueDidChange (SBFrame(%p)) => %i", m_opaque_sp.get(), frame.get(), result); + log->Printf ("SBValue(%p)::GetValueDidChange (SBFrame(%p)) => %i", m_opaque_sp.get(), sb_frame.get(), result); return result; } const char * -SBValue::GetSummary (const SBFrame &frame) +SBValue::GetSummary (const SBFrame &sb_frame) { const char *cstr = NULL; if (m_opaque_sp) - cstr = m_opaque_sp->GetSummaryAsCString(frame.get()); + { + StackFrame *frame = sb_frame.get(); + if (frame) + { + Mutex::Locker api_locker (frame->GetThread().GetProcess().GetTarget().GetAPIMutex()); + cstr = m_opaque_sp->GetSummaryAsCString(frame); + } + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (cstr) - log->Printf ("SBValue(%p)::GetSummary (SBFrame(%p)) => \"%s\"", m_opaque_sp.get(), frame.get(), cstr); + log->Printf ("SBValue(%p)::GetSummary (SBFrame(%p)) => \"%s\"", m_opaque_sp.get(), sb_frame.get(), cstr); else - log->Printf ("SBValue(%p)::GetSummary (SBFrame(%p)) => NULL", m_opaque_sp.get(), frame.get()); + log->Printf ("SBValue(%p)::GetSummary (SBFrame(%p)) => NULL", m_opaque_sp.get(), sb_frame.get()); } return cstr; } const char * -SBValue::GetLocation (const SBFrame &frame) +SBValue::GetLocation (const SBFrame &sb_frame) { const char *cstr = NULL; if (m_opaque_sp) - cstr = m_opaque_sp->GetLocationAsCString(frame.get()); + { + StackFrame *frame = sb_frame.get(); + if (frame) + { + Mutex::Locker api_locker (frame->GetThread().GetProcess().GetTarget().GetAPIMutex()); + cstr = m_opaque_sp->GetLocationAsCString(frame); + } + } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { if (cstr) - log->Printf ("SBValue(%p)::GetSummary (SBFrame(%p)) => \"%s\"", m_opaque_sp.get(), frame.get(), cstr); + log->Printf ("SBValue(%p)::GetSummary (SBFrame(%p)) => \"%s\"", m_opaque_sp.get(), sb_frame.get(), cstr); else - log->Printf ("SBValue(%p)::GetSummary (SBFrame(%p)) => NULL", m_opaque_sp.get(), frame.get()); + log->Printf ("SBValue(%p)::GetSummary (SBFrame(%p)) => NULL", m_opaque_sp.get(), sb_frame.get()); } return cstr; } bool -SBValue::SetValueFromCString (const SBFrame &frame, const char *value_str) +SBValue::SetValueFromCString (const SBFrame &sb_frame, const char *value_str) { bool success = false; if (m_opaque_sp) - success = m_opaque_sp->SetValueFromCString (frame.get(), value_str); + { + StackFrame *frame = sb_frame.get(); + if (frame) + { + Mutex::Locker api_locker (frame->GetThread().GetProcess().GetTarget().GetAPIMutex()); + success = m_opaque_sp->SetValueFromCString (frame, value_str); + } + } return success; } @@ -336,17 +386,6 @@ SBValue::GetNumChildren () return num_children; } -bool -SBValue::ValueIsStale () -{ - bool result = true; - - if (m_opaque_sp) - result = m_opaque_sp->GetValueIsValid(); - - return result; -} - SBValue SBValue::Dereference () @@ -354,8 +393,8 @@ SBValue::Dereference () SBValue sb_value; if (m_opaque_sp) { - if (m_opaque_sp->IsPointerType()) - sb_value = GetChildAtIndex(0); + Error error; + sb_value = m_opaque_sp->Dereference (error); } LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) diff --git a/lldb/source/API/SBValueList.cpp b/lldb/source/API/SBValueList.cpp index b83d56717230..bcddedfaf83b 100644 --- a/lldb/source/API/SBValueList.cpp +++ b/lldb/source/API/SBValueList.cpp @@ -11,8 +11,6 @@ #include "lldb/API/SBValueList.h" #include "lldb/API/SBValue.h" #include "lldb/API/SBStream.h" - - #include "lldb/Core/Log.h" #include "lldb/Core/ValueObjectList.h" @@ -35,16 +33,8 @@ SBValueList::SBValueList (const SBValueList &rhs) : if (log) { log->Printf ("SBValueList::SBValueList (rhs.ap=%p) => this.ap = %p", - (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL), m_opaque_ap.get()); - - uint32_t num_vars = GetSize(); - for (uint32_t i = 0; i < num_vars; ++i) - { - SBValue value = GetValueAtIndex (i); - SBStream sstr; - value.GetDescription (sstr); - log->Printf (" %s", sstr.GetData()); - } + (rhs.IsValid() ? rhs.m_opaque_ap.get() : NULL), + m_opaque_ap.get()); } } @@ -58,18 +48,9 @@ SBValueList::SBValueList (const lldb_private::ValueObjectList *lldb_object_ptr) if (log) { - log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p", lldb_object_ptr, + log->Printf ("SBValueList::SBValueList (lldb_object_ptr=%p) => this.ap = %p", + lldb_object_ptr, m_opaque_ap.get()); - - - uint32_t num_vars = GetSize(); - for (uint32_t i = 0; i < num_vars; ++i) - { - SBValue value = GetValueAtIndex (i); - SBStream sstr; - value.GetDescription (sstr); - log->Printf (" %s", sstr.GetData()); - } } } @@ -194,7 +175,7 @@ SBValue SBValueList::FindValueObjectByUID (lldb::user_id_t uid) { SBValue sb_value; - if ( m_opaque_ap.get()) + if (m_opaque_ap.get()) *sb_value = m_opaque_ap->FindValueObjectByUID (uid); return sb_value; } diff --git a/lldb/source/Core/ValueObject.cpp b/lldb/source/Core/ValueObject.cpp index 2f82d49bd0be..47b0c76359d0 100644 --- a/lldb/source/Core/ValueObject.cpp +++ b/lldb/source/Core/ValueObject.cpp @@ -1203,7 +1203,7 @@ ValueObject::CreateConstantValue (ExecutionContextScope *exe_scope, const ConstS } lldb::ValueObjectSP -ValueObject::Dereference (ExecutionContextScope *exe_scope, Error &error) +ValueObject::Dereference (Error &error) { lldb::ValueObjectSP valobj_sp; const bool is_pointer_type = IsPointerType(); diff --git a/lldb/source/Target/StackFrame.cpp b/lldb/source/Target/StackFrame.cpp index 341954f2a113..812846f81432 100644 --- a/lldb/source/Target/StackFrame.cpp +++ b/lldb/source/Target/StackFrame.cpp @@ -688,7 +688,7 @@ StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, bool c { if (deref) { - ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(this, error)); + ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error)); valobj_sp = deref_valobj_sp; } else if (address_of) diff --git a/lldb/source/Target/Target.cpp b/lldb/source/Target/Target.cpp index 7990111aa436..36058e9cc5f0 100644 --- a/lldb/source/Target/Target.cpp +++ b/lldb/source/Target/Target.cpp @@ -40,6 +40,7 @@ Target::Target(Debugger &debugger) : Broadcaster("lldb.target"), TargetInstanceSettings (*GetSettingsController()), m_debugger (debugger), + m_mutex (Mutex::eMutexTypeRecursive), m_images(), m_section_load_list (), m_breakpoint_list (false),