1 //===-- SBBreakpointLocation.cpp --------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBBreakpointLocation.h"
11 #include "lldb/API/SBDefines.h"
12 #include "lldb/API/SBAddress.h"
13 #include "lldb/API/SBDebugger.h"
14 #include "lldb/API/SBStream.h"
16 #include "lldb/lldb-types.h"
17 #include "lldb/lldb-defines.h"
18 #include "lldb/Breakpoint/Breakpoint.h"
19 #include "lldb/Breakpoint/BreakpointLocation.h"
20 #include "lldb/Core/Debugger.h"
21 #include "lldb/Core/Log.h"
22 #include "lldb/Core/Stream.h"
23 #include "lldb/Core/StreamFile.h"
24 #include "lldb/Interpreter/CommandInterpreter.h"
25 #include "lldb/Interpreter/ScriptInterpreter.h"
26 #include "lldb/Target/ThreadSpec.h"
27 #include "lldb/Target/Target.h"
28 #include "lldb/Target/ThreadSpec.h"
31 using namespace lldb_private;
34 SBBreakpointLocation::SBBreakpointLocation () :
39 SBBreakpointLocation::SBBreakpointLocation (const lldb::BreakpointLocationSP &break_loc_sp) :
40 m_opaque_sp (break_loc_sp)
42 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
47 GetDescription (sstr, lldb::eDescriptionLevelBrief);
48 log->Printf ("SBBreakpointLocation::SBBreakpointLocaiton (const lldb::BreakpointLocationsSP &break_loc_sp"
49 "=%p) => this.sp = %p (%s)",
50 static_cast<void*>(break_loc_sp.get()),
51 static_cast<void*>(m_opaque_sp.get()), sstr.GetData());
55 SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) :
56 m_opaque_sp (rhs.m_opaque_sp)
60 const SBBreakpointLocation &
61 SBBreakpointLocation::operator = (const SBBreakpointLocation &rhs)
64 m_opaque_sp = rhs.m_opaque_sp;
69 SBBreakpointLocation::~SBBreakpointLocation ()
74 SBBreakpointLocation::IsValid() const
76 return m_opaque_sp.get() != NULL;
80 SBBreakpointLocation::GetAddress ()
83 return SBAddress(&m_opaque_sp->GetAddress());
89 SBBreakpointLocation::GetLoadAddress ()
91 addr_t ret_addr = LLDB_INVALID_ADDRESS;
95 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
96 ret_addr = m_opaque_sp->GetLoadAddress();
103 SBBreakpointLocation::SetEnabled (bool enabled)
107 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
108 m_opaque_sp->SetEnabled (enabled);
113 SBBreakpointLocation::IsEnabled ()
117 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
118 return m_opaque_sp->IsEnabled();
125 SBBreakpointLocation::GetIgnoreCount ()
129 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
130 return m_opaque_sp->GetIgnoreCount();
137 SBBreakpointLocation::SetIgnoreCount (uint32_t n)
141 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
142 m_opaque_sp->SetIgnoreCount (n);
147 SBBreakpointLocation::SetCondition (const char *condition)
151 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
152 m_opaque_sp->SetCondition (condition);
157 SBBreakpointLocation::GetCondition ()
161 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
162 return m_opaque_sp->GetConditionText ();
168 SBBreakpointLocation::SetScriptCallbackFunction (const char *callback_function_name)
170 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
173 log->Printf ("SBBreakpointLocation(%p)::SetScriptCallbackFunction (callback=%s)",
174 static_cast<void*>(m_opaque_sp.get()),
175 callback_function_name);
179 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
180 BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions();
181 m_opaque_sp->GetBreakpoint().GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallbackFunction (bp_options,
182 callback_function_name);
187 SBBreakpointLocation::SetScriptCallbackBody (const char *callback_body_text)
189 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
192 log->Printf ("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)",
193 static_cast<void*>(m_opaque_sp.get()), callback_body_text);
198 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
199 BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions();
200 Error error = m_opaque_sp->GetBreakpoint().GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options,
202 sb_error.SetError(error);
205 sb_error.SetErrorString("invalid breakpoint");
211 SBBreakpointLocation::SetThreadID (tid_t thread_id)
215 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
216 m_opaque_sp->SetThreadID (thread_id);
221 SBBreakpointLocation::GetThreadID ()
223 tid_t tid = LLDB_INVALID_THREAD_ID;
226 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
227 return m_opaque_sp->GetThreadID();
233 SBBreakpointLocation::SetThreadIndex (uint32_t index)
237 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
238 m_opaque_sp->SetThreadIndex (index);
243 SBBreakpointLocation::GetThreadIndex() const
245 uint32_t thread_idx = UINT32_MAX;
248 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
249 return m_opaque_sp->GetThreadIndex();
256 SBBreakpointLocation::SetThreadName (const char *thread_name)
260 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
261 m_opaque_sp->SetThreadName (thread_name);
266 SBBreakpointLocation::GetThreadName () const
270 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
271 return m_opaque_sp->GetThreadName();
277 SBBreakpointLocation::SetQueueName (const char *queue_name)
281 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
282 m_opaque_sp->SetQueueName (queue_name);
287 SBBreakpointLocation::GetQueueName () const
291 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
292 m_opaque_sp->GetQueueName ();
298 SBBreakpointLocation::IsResolved ()
302 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
303 return m_opaque_sp->IsResolved();
309 SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp)
311 // Uninstall the callbacks?
312 m_opaque_sp = break_loc_sp;
316 SBBreakpointLocation::GetDescription (SBStream &description, DescriptionLevel level)
318 Stream &strm = description.ref();
322 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
323 m_opaque_sp->GetDescription (&strm, level);
327 strm.PutCString ("No value");
333 SBBreakpointLocation::GetID ()
337 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
338 return m_opaque_sp->GetID ();
341 return LLDB_INVALID_BREAK_ID;
345 SBBreakpointLocation::GetBreakpoint ()
347 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
350 // log->Printf ("SBBreakpointLocation::GetBreakpoint ()");
355 Mutex::Locker api_locker (m_opaque_sp->GetBreakpoint().GetTarget().GetAPIMutex());
356 *sb_bp = m_opaque_sp->GetBreakpoint ().shared_from_this();
362 sb_bp.GetDescription (sstr);
363 log->Printf ("SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s",
364 static_cast<void*>(m_opaque_sp.get()),
365 static_cast<void*>(sb_bp.get()), sstr.GetData());