SBBreakpointLocation.cpp revision 314564
1//===-- SBBreakpointLocation.cpp --------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#include "lldb/API/SBBreakpointLocation.h" 11#include "lldb/API/SBAddress.h" 12#include "lldb/API/SBDebugger.h" 13#include "lldb/API/SBDefines.h" 14#include "lldb/API/SBStream.h" 15 16#include "lldb/Breakpoint/Breakpoint.h" 17#include "lldb/Breakpoint/BreakpointLocation.h" 18#include "lldb/Core/Debugger.h" 19#include "lldb/Core/Log.h" 20#include "lldb/Core/Stream.h" 21#include "lldb/Core/StreamFile.h" 22#include "lldb/Interpreter/CommandInterpreter.h" 23#include "lldb/Interpreter/ScriptInterpreter.h" 24#include "lldb/Target/Target.h" 25#include "lldb/Target/ThreadSpec.h" 26#include "lldb/Target/ThreadSpec.h" 27#include "lldb/lldb-defines.h" 28#include "lldb/lldb-types.h" 29 30using namespace lldb; 31using namespace lldb_private; 32 33SBBreakpointLocation::SBBreakpointLocation() : m_opaque_sp() {} 34 35SBBreakpointLocation::SBBreakpointLocation( 36 const lldb::BreakpointLocationSP &break_loc_sp) 37 : m_opaque_sp(break_loc_sp) { 38 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 39 40 if (log) { 41 SBStream sstr; 42 GetDescription(sstr, lldb::eDescriptionLevelBrief); 43 log->Printf("SBBreakpointLocation::SBBreakpointLocaiton (const " 44 "lldb::BreakpointLocationsSP &break_loc_sp" 45 "=%p) => this.sp = %p (%s)", 46 static_cast<void *>(break_loc_sp.get()), 47 static_cast<void *>(m_opaque_sp.get()), sstr.GetData()); 48 } 49} 50 51SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) 52 : m_opaque_sp(rhs.m_opaque_sp) {} 53 54const SBBreakpointLocation &SBBreakpointLocation:: 55operator=(const SBBreakpointLocation &rhs) { 56 if (this != &rhs) 57 m_opaque_sp = rhs.m_opaque_sp; 58 return *this; 59} 60 61SBBreakpointLocation::~SBBreakpointLocation() {} 62 63bool SBBreakpointLocation::IsValid() const { return m_opaque_sp.get() != NULL; } 64 65SBAddress SBBreakpointLocation::GetAddress() { 66 if (m_opaque_sp) 67 return SBAddress(&m_opaque_sp->GetAddress()); 68 else 69 return SBAddress(); 70} 71 72addr_t SBBreakpointLocation::GetLoadAddress() { 73 addr_t ret_addr = LLDB_INVALID_ADDRESS; 74 75 if (m_opaque_sp) { 76 std::lock_guard<std::recursive_mutex> guard( 77 m_opaque_sp->GetTarget().GetAPIMutex()); 78 ret_addr = m_opaque_sp->GetLoadAddress(); 79 } 80 81 return ret_addr; 82} 83 84void SBBreakpointLocation::SetEnabled(bool enabled) { 85 if (m_opaque_sp) { 86 std::lock_guard<std::recursive_mutex> guard( 87 m_opaque_sp->GetTarget().GetAPIMutex()); 88 m_opaque_sp->SetEnabled(enabled); 89 } 90} 91 92bool SBBreakpointLocation::IsEnabled() { 93 if (m_opaque_sp) { 94 std::lock_guard<std::recursive_mutex> guard( 95 m_opaque_sp->GetTarget().GetAPIMutex()); 96 return m_opaque_sp->IsEnabled(); 97 } else 98 return false; 99} 100 101uint32_t SBBreakpointLocation::GetIgnoreCount() { 102 if (m_opaque_sp) { 103 std::lock_guard<std::recursive_mutex> guard( 104 m_opaque_sp->GetTarget().GetAPIMutex()); 105 return m_opaque_sp->GetIgnoreCount(); 106 } else 107 return 0; 108} 109 110void SBBreakpointLocation::SetIgnoreCount(uint32_t n) { 111 if (m_opaque_sp) { 112 std::lock_guard<std::recursive_mutex> guard( 113 m_opaque_sp->GetTarget().GetAPIMutex()); 114 m_opaque_sp->SetIgnoreCount(n); 115 } 116} 117 118void SBBreakpointLocation::SetCondition(const char *condition) { 119 if (m_opaque_sp) { 120 std::lock_guard<std::recursive_mutex> guard( 121 m_opaque_sp->GetTarget().GetAPIMutex()); 122 m_opaque_sp->SetCondition(condition); 123 } 124} 125 126const char *SBBreakpointLocation::GetCondition() { 127 if (m_opaque_sp) { 128 std::lock_guard<std::recursive_mutex> guard( 129 m_opaque_sp->GetTarget().GetAPIMutex()); 130 return m_opaque_sp->GetConditionText(); 131 } 132 return NULL; 133} 134 135void SBBreakpointLocation::SetScriptCallbackFunction( 136 const char *callback_function_name) { 137 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 138 139 if (log) 140 log->Printf( 141 "SBBreakpointLocation(%p)::SetScriptCallbackFunction (callback=%s)", 142 static_cast<void *>(m_opaque_sp.get()), callback_function_name); 143 144 if (m_opaque_sp) { 145 std::lock_guard<std::recursive_mutex> guard( 146 m_opaque_sp->GetTarget().GetAPIMutex()); 147 BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions(); 148 m_opaque_sp->GetBreakpoint() 149 .GetTarget() 150 .GetDebugger() 151 .GetCommandInterpreter() 152 .GetScriptInterpreter() 153 ->SetBreakpointCommandCallbackFunction(bp_options, 154 callback_function_name); 155 } 156} 157 158SBError 159SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) { 160 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 161 162 if (log) 163 log->Printf("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)", 164 static_cast<void *>(m_opaque_sp.get()), callback_body_text); 165 166 SBError sb_error; 167 if (m_opaque_sp) { 168 std::lock_guard<std::recursive_mutex> guard( 169 m_opaque_sp->GetTarget().GetAPIMutex()); 170 BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions(); 171 Error error = 172 m_opaque_sp->GetBreakpoint() 173 .GetTarget() 174 .GetDebugger() 175 .GetCommandInterpreter() 176 .GetScriptInterpreter() 177 ->SetBreakpointCommandCallback(bp_options, callback_body_text); 178 sb_error.SetError(error); 179 } else 180 sb_error.SetErrorString("invalid breakpoint"); 181 182 return sb_error; 183} 184 185void SBBreakpointLocation::SetThreadID(tid_t thread_id) { 186 if (m_opaque_sp) { 187 std::lock_guard<std::recursive_mutex> guard( 188 m_opaque_sp->GetTarget().GetAPIMutex()); 189 m_opaque_sp->SetThreadID(thread_id); 190 } 191} 192 193tid_t SBBreakpointLocation::GetThreadID() { 194 tid_t tid = LLDB_INVALID_THREAD_ID; 195 if (m_opaque_sp) { 196 std::lock_guard<std::recursive_mutex> guard( 197 m_opaque_sp->GetTarget().GetAPIMutex()); 198 return m_opaque_sp->GetThreadID(); 199 } 200 return tid; 201} 202 203void SBBreakpointLocation::SetThreadIndex(uint32_t index) { 204 if (m_opaque_sp) { 205 std::lock_guard<std::recursive_mutex> guard( 206 m_opaque_sp->GetTarget().GetAPIMutex()); 207 m_opaque_sp->SetThreadIndex(index); 208 } 209} 210 211uint32_t SBBreakpointLocation::GetThreadIndex() const { 212 uint32_t thread_idx = UINT32_MAX; 213 if (m_opaque_sp) { 214 std::lock_guard<std::recursive_mutex> guard( 215 m_opaque_sp->GetTarget().GetAPIMutex()); 216 return m_opaque_sp->GetThreadIndex(); 217 } 218 return thread_idx; 219} 220 221void SBBreakpointLocation::SetThreadName(const char *thread_name) { 222 if (m_opaque_sp) { 223 std::lock_guard<std::recursive_mutex> guard( 224 m_opaque_sp->GetTarget().GetAPIMutex()); 225 m_opaque_sp->SetThreadName(thread_name); 226 } 227} 228 229const char *SBBreakpointLocation::GetThreadName() const { 230 if (m_opaque_sp) { 231 std::lock_guard<std::recursive_mutex> guard( 232 m_opaque_sp->GetTarget().GetAPIMutex()); 233 return m_opaque_sp->GetThreadName(); 234 } 235 return NULL; 236} 237 238void SBBreakpointLocation::SetQueueName(const char *queue_name) { 239 if (m_opaque_sp) { 240 std::lock_guard<std::recursive_mutex> guard( 241 m_opaque_sp->GetTarget().GetAPIMutex()); 242 m_opaque_sp->SetQueueName(queue_name); 243 } 244} 245 246const char *SBBreakpointLocation::GetQueueName() const { 247 if (m_opaque_sp) { 248 std::lock_guard<std::recursive_mutex> guard( 249 m_opaque_sp->GetTarget().GetAPIMutex()); 250 m_opaque_sp->GetQueueName(); 251 } 252 return NULL; 253} 254 255bool SBBreakpointLocation::IsResolved() { 256 if (m_opaque_sp) { 257 std::lock_guard<std::recursive_mutex> guard( 258 m_opaque_sp->GetTarget().GetAPIMutex()); 259 return m_opaque_sp->IsResolved(); 260 } 261 return false; 262} 263 264void SBBreakpointLocation::SetLocation( 265 const lldb::BreakpointLocationSP &break_loc_sp) { 266 // Uninstall the callbacks? 267 m_opaque_sp = break_loc_sp; 268} 269 270bool SBBreakpointLocation::GetDescription(SBStream &description, 271 DescriptionLevel level) { 272 Stream &strm = description.ref(); 273 274 if (m_opaque_sp) { 275 std::lock_guard<std::recursive_mutex> guard( 276 m_opaque_sp->GetTarget().GetAPIMutex()); 277 m_opaque_sp->GetDescription(&strm, level); 278 strm.EOL(); 279 } else 280 strm.PutCString("No value"); 281 282 return true; 283} 284 285break_id_t SBBreakpointLocation::GetID() { 286 if (m_opaque_sp) { 287 std::lock_guard<std::recursive_mutex> guard( 288 m_opaque_sp->GetTarget().GetAPIMutex()); 289 return m_opaque_sp->GetID(); 290 } else 291 return LLDB_INVALID_BREAK_ID; 292} 293 294SBBreakpoint SBBreakpointLocation::GetBreakpoint() { 295 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); 296 297 // if (log) 298 // log->Printf ("SBBreakpointLocation::GetBreakpoint ()"); 299 300 SBBreakpoint sb_bp; 301 if (m_opaque_sp) { 302 std::lock_guard<std::recursive_mutex> guard( 303 m_opaque_sp->GetTarget().GetAPIMutex()); 304 *sb_bp = m_opaque_sp->GetBreakpoint().shared_from_this(); 305 } 306 307 if (log) { 308 SBStream sstr; 309 sb_bp.GetDescription(sstr); 310 log->Printf( 311 "SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s", 312 static_cast<void *>(m_opaque_sp.get()), 313 static_cast<void *>(sb_bp.get()), sstr.GetData()); 314 } 315 return sb_bp; 316} 317