1254721Semaste//===-- SBTarget.cpp --------------------------------------------*- C++ -*-===// 2254721Semaste// 3254721Semaste// The LLVM Compiler Infrastructure 4254721Semaste// 5254721Semaste// This file is distributed under the University of Illinois Open Source 6254721Semaste// License. See LICENSE.TXT for details. 7254721Semaste// 8254721Semaste//===----------------------------------------------------------------------===// 9254721Semaste 10254721Semaste#include "lldb/API/SBTarget.h" 11254721Semaste 12254721Semaste#include "lldb/lldb-public.h" 13254721Semaste 14288943Sdim#include "lldb/API/SBBreakpoint.h" 15254721Semaste#include "lldb/API/SBDebugger.h" 16288943Sdim#include "lldb/API/SBEvent.h" 17254721Semaste#include "lldb/API/SBExpressionOptions.h" 18254721Semaste#include "lldb/API/SBFileSpec.h" 19254721Semaste#include "lldb/API/SBListener.h" 20254721Semaste#include "lldb/API/SBModule.h" 21254721Semaste#include "lldb/API/SBModuleSpec.h" 22254721Semaste#include "lldb/API/SBSourceManager.h" 23254721Semaste#include "lldb/API/SBProcess.h" 24254721Semaste#include "lldb/API/SBStream.h" 25254721Semaste#include "lldb/API/SBSymbolContextList.h" 26254721Semaste#include "lldb/Breakpoint/BreakpointID.h" 27254721Semaste#include "lldb/Breakpoint/BreakpointIDList.h" 28254721Semaste#include "lldb/Breakpoint/BreakpointList.h" 29254721Semaste#include "lldb/Breakpoint/BreakpointLocation.h" 30254721Semaste#include "lldb/Core/Address.h" 31254721Semaste#include "lldb/Core/AddressResolver.h" 32254721Semaste#include "lldb/Core/AddressResolverName.h" 33254721Semaste#include "lldb/Core/ArchSpec.h" 34254721Semaste#include "lldb/Core/Debugger.h" 35254721Semaste#include "lldb/Core/Disassembler.h" 36254721Semaste#include "lldb/Core/Log.h" 37254721Semaste#include "lldb/Core/Module.h" 38254721Semaste#include "lldb/Core/ModuleSpec.h" 39254721Semaste#include "lldb/Core/RegularExpression.h" 40254721Semaste#include "lldb/Core/SearchFilter.h" 41254721Semaste#include "lldb/Core/Section.h" 42254721Semaste#include "lldb/Core/STLUtils.h" 43258054Semaste#include "lldb/Core/ValueObjectConstResult.h" 44254721Semaste#include "lldb/Core/ValueObjectList.h" 45254721Semaste#include "lldb/Core/ValueObjectVariable.h" 46254721Semaste#include "lldb/Host/FileSpec.h" 47254721Semaste#include "lldb/Host/Host.h" 48254721Semaste#include "lldb/Interpreter/Args.h" 49288943Sdim#include "lldb/Symbol/ClangASTContext.h" 50288943Sdim#include "lldb/Symbol/DeclVendor.h" 51254721Semaste#include "lldb/Symbol/ObjectFile.h" 52254721Semaste#include "lldb/Symbol/SymbolVendor.h" 53254721Semaste#include "lldb/Symbol/VariableList.h" 54288943Sdim#include "lldb/Target/ABI.h" 55296417Sdim#include "lldb/Target/Language.h" 56254721Semaste#include "lldb/Target/LanguageRuntime.h" 57288943Sdim#include "lldb/Target/ObjCLanguageRuntime.h" 58254721Semaste#include "lldb/Target/Process.h" 59288943Sdim#include "lldb/Target/StackFrame.h" 60254721Semaste#include "lldb/Target/Target.h" 61254721Semaste#include "lldb/Target/TargetList.h" 62254721Semaste 63254721Semaste#include "lldb/Interpreter/CommandReturnObject.h" 64254721Semaste#include "../source/Commands/CommandObjectBreakpoint.h" 65280031Sdim#include "llvm/Support/Regex.h" 66254721Semaste 67254721Semaste 68254721Semasteusing namespace lldb; 69254721Semasteusing namespace lldb_private; 70254721Semaste 71254721Semaste#define DEFAULT_DISASM_BYTE_SIZE 32 72254721Semaste 73288943Sdimnamespace { 74254721Semaste 75288943SdimError 76288943SdimAttachToProcess (ProcessAttachInfo &attach_info, Target &target) 77254721Semaste{ 78288943Sdim Mutex::Locker api_locker (target.GetAPIMutex ()); 79254721Semaste 80288943Sdim auto process_sp = target.GetProcessSP (); 81288943Sdim if (process_sp) 82254721Semaste { 83288943Sdim const auto state = process_sp->GetState (); 84288943Sdim if (process_sp->IsAlive () && state == eStateConnected) 85288943Sdim { 86288943Sdim // If we are already connected, then we have already specified the 87288943Sdim // listener, so if a valid listener is supplied, we need to error out 88288943Sdim // to let the client know. 89288943Sdim if (attach_info.GetListener ()) 90288943Sdim return Error ("process is connected and already has a listener, pass empty listener"); 91288943Sdim } 92254721Semaste } 93254721Semaste 94288943Sdim return target.Attach (attach_info, nullptr); 95254721Semaste} 96254721Semaste 97288943Sdim} // namespace 98254721Semaste 99254721Semaste//---------------------------------------------------------------------- 100254721Semaste// SBTarget constructor 101254721Semaste//---------------------------------------------------------------------- 102254721SemasteSBTarget::SBTarget () : 103254721Semaste m_opaque_sp () 104254721Semaste{ 105254721Semaste} 106254721Semaste 107254721SemasteSBTarget::SBTarget (const SBTarget& rhs) : 108254721Semaste m_opaque_sp (rhs.m_opaque_sp) 109254721Semaste{ 110254721Semaste} 111254721Semaste 112254721SemasteSBTarget::SBTarget(const TargetSP& target_sp) : 113254721Semaste m_opaque_sp (target_sp) 114254721Semaste{ 115254721Semaste} 116254721Semaste 117254721Semasteconst SBTarget& 118254721SemasteSBTarget::operator = (const SBTarget& rhs) 119254721Semaste{ 120254721Semaste if (this != &rhs) 121254721Semaste m_opaque_sp = rhs.m_opaque_sp; 122254721Semaste return *this; 123254721Semaste} 124254721Semaste 125254721Semaste//---------------------------------------------------------------------- 126254721Semaste// Destructor 127254721Semaste//---------------------------------------------------------------------- 128254721SemasteSBTarget::~SBTarget() 129254721Semaste{ 130254721Semaste} 131254721Semaste 132288943Sdimbool 133288943SdimSBTarget::EventIsTargetEvent (const SBEvent &event) 134288943Sdim{ 135288943Sdim return Target::TargetEventData::GetEventDataFromEvent(event.get()) != NULL; 136288943Sdim} 137288943Sdim 138288943SdimSBTarget 139288943SdimSBTarget::GetTargetFromEvent (const SBEvent &event) 140288943Sdim{ 141288943Sdim return Target::TargetEventData::GetTargetFromEvent (event.get()); 142288943Sdim} 143288943Sdim 144288943Sdimuint32_t 145288943SdimSBTarget::GetNumModulesFromEvent (const SBEvent &event) 146288943Sdim{ 147288943Sdim const ModuleList module_list = Target::TargetEventData::GetModuleListFromEvent (event.get()); 148288943Sdim return module_list.GetSize(); 149288943Sdim} 150288943Sdim 151288943SdimSBModule 152288943SdimSBTarget::GetModuleAtIndexFromEvent (const uint32_t idx, const SBEvent &event) 153288943Sdim{ 154288943Sdim const ModuleList module_list = Target::TargetEventData::GetModuleListFromEvent (event.get()); 155288943Sdim return SBModule(module_list.GetModuleAtIndex(idx)); 156288943Sdim} 157288943Sdim 158254721Semasteconst char * 159254721SemasteSBTarget::GetBroadcasterClassName () 160254721Semaste{ 161254721Semaste return Target::GetStaticBroadcasterClass().AsCString(); 162254721Semaste} 163254721Semaste 164254721Semastebool 165254721SemasteSBTarget::IsValid () const 166254721Semaste{ 167254721Semaste return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid(); 168254721Semaste} 169254721Semaste 170254721SemasteSBProcess 171254721SemasteSBTarget::GetProcess () 172254721Semaste{ 173254721Semaste SBProcess sb_process; 174254721Semaste ProcessSP process_sp; 175254721Semaste TargetSP target_sp(GetSP()); 176254721Semaste if (target_sp) 177254721Semaste { 178254721Semaste process_sp = target_sp->GetProcessSP(); 179254721Semaste sb_process.SetSP (process_sp); 180254721Semaste } 181254721Semaste 182254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 183254721Semaste if (log) 184276479Sdim log->Printf ("SBTarget(%p)::GetProcess () => SBProcess(%p)", 185276479Sdim static_cast<void*>(target_sp.get()), 186276479Sdim static_cast<void*>(process_sp.get())); 187254721Semaste 188254721Semaste return sb_process; 189254721Semaste} 190254721Semaste 191280031SdimSBPlatform 192280031SdimSBTarget::GetPlatform () 193280031Sdim{ 194280031Sdim TargetSP target_sp(GetSP()); 195280031Sdim if (!target_sp) 196280031Sdim return SBPlatform(); 197280031Sdim 198280031Sdim SBPlatform platform; 199280031Sdim platform.m_opaque_sp = target_sp->GetPlatform(); 200280031Sdim 201280031Sdim return platform; 202280031Sdim} 203280031Sdim 204254721SemasteSBDebugger 205254721SemasteSBTarget::GetDebugger () const 206254721Semaste{ 207254721Semaste SBDebugger debugger; 208254721Semaste TargetSP target_sp(GetSP()); 209254721Semaste if (target_sp) 210254721Semaste debugger.reset (target_sp->GetDebugger().shared_from_this()); 211254721Semaste return debugger; 212254721Semaste} 213254721Semaste 214254721SemasteSBProcess 215254721SemasteSBTarget::LoadCore (const char *core_file) 216254721Semaste{ 217254721Semaste SBProcess sb_process; 218254721Semaste TargetSP target_sp(GetSP()); 219254721Semaste if (target_sp) 220254721Semaste { 221254721Semaste FileSpec filespec(core_file, true); 222254721Semaste ProcessSP process_sp (target_sp->CreateProcess(target_sp->GetDebugger().GetListener(), 223254721Semaste NULL, 224254721Semaste &filespec)); 225254721Semaste if (process_sp) 226254721Semaste { 227254721Semaste process_sp->LoadCore(); 228254721Semaste sb_process.SetSP (process_sp); 229254721Semaste } 230254721Semaste } 231254721Semaste return sb_process; 232254721Semaste} 233254721Semaste 234254721SemasteSBProcess 235254721SemasteSBTarget::LaunchSimple 236254721Semaste( 237254721Semaste char const **argv, 238254721Semaste char const **envp, 239254721Semaste const char *working_directory 240254721Semaste) 241254721Semaste{ 242254721Semaste char *stdin_path = NULL; 243254721Semaste char *stdout_path = NULL; 244254721Semaste char *stderr_path = NULL; 245254721Semaste uint32_t launch_flags = 0; 246254721Semaste bool stop_at_entry = false; 247254721Semaste SBError error; 248254721Semaste SBListener listener = GetDebugger().GetListener(); 249254721Semaste return Launch (listener, 250254721Semaste argv, 251254721Semaste envp, 252254721Semaste stdin_path, 253254721Semaste stdout_path, 254254721Semaste stderr_path, 255254721Semaste working_directory, 256254721Semaste launch_flags, 257254721Semaste stop_at_entry, 258254721Semaste error); 259254721Semaste} 260254721Semaste 261258884SemasteSBError 262258884SemasteSBTarget::Install() 263258884Semaste{ 264258884Semaste SBError sb_error; 265258884Semaste TargetSP target_sp(GetSP()); 266258884Semaste if (target_sp) 267258884Semaste { 268258884Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 269258884Semaste sb_error.ref() = target_sp->Install(NULL); 270258884Semaste } 271258884Semaste return sb_error; 272258884Semaste} 273258884Semaste 274254721SemasteSBProcess 275254721SemasteSBTarget::Launch 276254721Semaste( 277254721Semaste SBListener &listener, 278254721Semaste char const **argv, 279254721Semaste char const **envp, 280254721Semaste const char *stdin_path, 281254721Semaste const char *stdout_path, 282254721Semaste const char *stderr_path, 283254721Semaste const char *working_directory, 284254721Semaste uint32_t launch_flags, // See LaunchFlags 285254721Semaste bool stop_at_entry, 286254721Semaste lldb::SBError& error 287254721Semaste) 288254721Semaste{ 289254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 290254721Semaste 291254721Semaste SBProcess sb_process; 292254721Semaste ProcessSP process_sp; 293254721Semaste TargetSP target_sp(GetSP()); 294254721Semaste 295254721Semaste if (log) 296254721Semaste log->Printf ("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...", 297276479Sdim static_cast<void*>(target_sp.get()), 298276479Sdim static_cast<void*>(argv), static_cast<void*>(envp), 299276479Sdim stdin_path ? stdin_path : "NULL", 300276479Sdim stdout_path ? stdout_path : "NULL", 301276479Sdim stderr_path ? stderr_path : "NULL", 302254721Semaste working_directory ? working_directory : "NULL", 303276479Sdim launch_flags, stop_at_entry, 304276479Sdim static_cast<void*>(error.get())); 305254721Semaste 306254721Semaste if (target_sp) 307254721Semaste { 308254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 309254721Semaste 310288943Sdim if (stop_at_entry) 311288943Sdim launch_flags |= eLaunchFlagStopAtEntry; 312288943Sdim 313254721Semaste if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR")) 314254721Semaste launch_flags |= eLaunchFlagDisableASLR; 315254721Semaste 316254721Semaste StateType state = eStateInvalid; 317254721Semaste process_sp = target_sp->GetProcessSP(); 318254721Semaste if (process_sp) 319254721Semaste { 320254721Semaste state = process_sp->GetState(); 321276479Sdim 322254721Semaste if (process_sp->IsAlive() && state != eStateConnected) 323276479Sdim { 324254721Semaste if (state == eStateAttaching) 325254721Semaste error.SetErrorString ("process attach is in progress"); 326254721Semaste else 327254721Semaste error.SetErrorString ("a process is already being debugged"); 328254721Semaste return sb_process; 329276479Sdim } 330254721Semaste } 331276479Sdim 332254721Semaste if (state == eStateConnected) 333254721Semaste { 334254721Semaste // If we are already connected, then we have already specified the 335254721Semaste // listener, so if a valid listener is supplied, we need to error out 336254721Semaste // to let the client know. 337254721Semaste if (listener.IsValid()) 338254721Semaste { 339254721Semaste error.SetErrorString ("process is connected and already has a listener, pass empty listener"); 340254721Semaste return sb_process; 341254721Semaste } 342254721Semaste } 343254721Semaste 344262528Semaste if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) 345262528Semaste launch_flags |= eLaunchFlagDisableSTDIO; 346254721Semaste 347288943Sdim ProcessLaunchInfo launch_info(FileSpec{stdin_path, false}, 348288943Sdim FileSpec{stdout_path, false}, 349288943Sdim FileSpec{stderr_path, false}, 350288943Sdim FileSpec{working_directory, false}, 351288943Sdim launch_flags); 352276479Sdim 353262528Semaste Module *exe_module = target_sp->GetExecutableModulePointer(); 354262528Semaste if (exe_module) 355262528Semaste launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); 356262528Semaste if (argv) 357262528Semaste launch_info.GetArguments().AppendArguments (argv); 358262528Semaste if (envp) 359262528Semaste launch_info.GetEnvironmentEntries ().SetArguments (envp); 360254721Semaste 361262528Semaste if (listener.IsValid()) 362280031Sdim launch_info.SetListener(listener.GetSP()); 363262528Semaste 364280031Sdim error.SetError (target_sp->Launch(launch_info, NULL)); 365280031Sdim 366262528Semaste sb_process.SetSP(target_sp->GetProcessSP()); 367254721Semaste } 368254721Semaste else 369254721Semaste { 370254721Semaste error.SetErrorString ("SBTarget is invalid"); 371254721Semaste } 372254721Semaste 373254721Semaste log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); 374254721Semaste if (log) 375276479Sdim log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)", 376276479Sdim static_cast<void*>(target_sp.get()), 377276479Sdim static_cast<void*>(sb_process.GetSP().get())); 378254721Semaste 379254721Semaste return sb_process; 380254721Semaste} 381254721Semaste 382254721SemasteSBProcess 383254721SemasteSBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error) 384254721Semaste{ 385254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 386276479Sdim 387254721Semaste SBProcess sb_process; 388254721Semaste TargetSP target_sp(GetSP()); 389276479Sdim 390254721Semaste if (log) 391276479Sdim log->Printf ("SBTarget(%p)::Launch (launch_info, error)...", 392276479Sdim static_cast<void*>(target_sp.get())); 393276479Sdim 394254721Semaste if (target_sp) 395254721Semaste { 396254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 397254721Semaste StateType state = eStateInvalid; 398262528Semaste { 399276479Sdim ProcessSP process_sp = target_sp->GetProcessSP(); 400276479Sdim if (process_sp) 401276479Sdim { 402276479Sdim state = process_sp->GetState(); 403276479Sdim 404276479Sdim if (process_sp->IsAlive() && state != eStateConnected) 405276479Sdim { 406276479Sdim if (state == eStateAttaching) 407276479Sdim error.SetErrorString ("process attach is in progress"); 408276479Sdim else 409276479Sdim error.SetErrorString ("a process is already being debugged"); 410276479Sdim return sb_process; 411276479Sdim } 412276479Sdim } 413254721Semaste } 414254721Semaste 415262528Semaste lldb_private::ProcessLaunchInfo &launch_info = sb_launch_info.ref(); 416254721Semaste 417276479Sdim if (!launch_info.GetExecutableFile()) 418276479Sdim { 419276479Sdim Module *exe_module = target_sp->GetExecutableModulePointer(); 420276479Sdim if (exe_module) 421276479Sdim launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); 422276479Sdim } 423262528Semaste 424262528Semaste const ArchSpec &arch_spec = target_sp->GetArchitecture(); 425262528Semaste if (arch_spec.IsValid()) 426262528Semaste launch_info.GetArchitecture () = arch_spec; 427276479Sdim 428280031Sdim error.SetError (target_sp->Launch (launch_info, NULL)); 429262528Semaste sb_process.SetSP(target_sp->GetProcessSP()); 430254721Semaste } 431254721Semaste else 432254721Semaste { 433254721Semaste error.SetErrorString ("SBTarget is invalid"); 434254721Semaste } 435276479Sdim 436254721Semaste log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); 437254721Semaste if (log) 438262528Semaste log->Printf ("SBTarget(%p)::Launch (...) => SBProcess(%p)", 439276479Sdim static_cast<void*>(target_sp.get()), 440276479Sdim static_cast<void*>(sb_process.GetSP().get())); 441276479Sdim 442254721Semaste return sb_process; 443254721Semaste} 444254721Semaste 445254721Semastelldb::SBProcess 446254721SemasteSBTarget::Attach (SBAttachInfo &sb_attach_info, SBError& error) 447254721Semaste{ 448254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 449276479Sdim 450254721Semaste SBProcess sb_process; 451254721Semaste TargetSP target_sp(GetSP()); 452276479Sdim 453254721Semaste if (log) 454276479Sdim log->Printf ("SBTarget(%p)::Attach (sb_attach_info, error)...", 455276479Sdim static_cast<void*>(target_sp.get())); 456276479Sdim 457254721Semaste if (target_sp) 458254721Semaste { 459288943Sdim ProcessAttachInfo &attach_info = sb_attach_info.ref(); 460288943Sdim if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) 461254721Semaste { 462288943Sdim PlatformSP platform_sp = target_sp->GetPlatform(); 463288943Sdim // See if we can pre-verify if a process exists or not 464288943Sdim if (platform_sp && platform_sp->IsConnected()) 465276479Sdim { 466288943Sdim lldb::pid_t attach_pid = attach_info.GetProcessID(); 467288943Sdim ProcessInstanceInfo instance_info; 468288943Sdim if (platform_sp->GetProcessInfo(attach_pid, instance_info)) 469288943Sdim { 470288943Sdim attach_info.SetUserID(instance_info.GetEffectiveUserID()); 471288943Sdim } 472254721Semaste else 473254721Semaste { 474288943Sdim error.ref().SetErrorStringWithFormat("no process found with process ID %" PRIu64, attach_pid); 475288943Sdim if (log) 476254721Semaste { 477288943Sdim log->Printf ("SBTarget(%p)::Attach (...) => error %s", 478288943Sdim static_cast<void*>(target_sp.get()), error.GetCString()); 479254721Semaste } 480288943Sdim return sb_process; 481254721Semaste } 482254721Semaste } 483254721Semaste } 484288943Sdim error.SetError(AttachToProcess(attach_info, *target_sp)); 485288943Sdim if (error.Success()) 486288943Sdim sb_process.SetSP(target_sp->GetProcessSP()); 487254721Semaste } 488254721Semaste else 489254721Semaste { 490254721Semaste error.SetErrorString ("SBTarget is invalid"); 491254721Semaste } 492276479Sdim 493254721Semaste if (log) 494254721Semaste log->Printf ("SBTarget(%p)::Attach (...) => SBProcess(%p)", 495276479Sdim static_cast<void*>(target_sp.get()), 496288943Sdim static_cast<void*>(sb_process.GetSP().get())); 497276479Sdim 498254721Semaste return sb_process; 499254721Semaste} 500254721Semaste 501254721Semaste 502254721Semaste#if defined(__APPLE__) 503254721Semaste 504254721Semastelldb::SBProcess 505254721SemasteSBTarget::AttachToProcessWithID (SBListener &listener, 506254721Semaste ::pid_t pid, 507254721Semaste lldb::SBError& error) 508254721Semaste{ 509254721Semaste return AttachToProcessWithID (listener, (lldb::pid_t)pid, error); 510254721Semaste} 511254721Semaste 512254721Semaste#endif // #if defined(__APPLE__) 513254721Semaste 514254721Semastelldb::SBProcess 515254721SemasteSBTarget::AttachToProcessWithID 516254721Semaste( 517254721Semaste SBListener &listener, 518254721Semaste lldb::pid_t pid,// The process ID to attach to 519254721Semaste SBError& error // An error explaining what went wrong if attach fails 520254721Semaste) 521254721Semaste{ 522254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 523254721Semaste 524254721Semaste SBProcess sb_process; 525254721Semaste TargetSP target_sp(GetSP()); 526254721Semaste 527254721Semaste if (log) 528288943Sdim log->Printf ("SBTarget(%p)::%s (listener, pid=%" PRId64 ", error)...", 529288943Sdim static_cast<void*>(target_sp.get()), 530288943Sdim __FUNCTION__, 531288943Sdim pid); 532276479Sdim 533254721Semaste if (target_sp) 534254721Semaste { 535288943Sdim ProcessAttachInfo attach_info; 536288943Sdim attach_info.SetProcessID (pid); 537288943Sdim if (listener.IsValid()) 538288943Sdim attach_info.SetListener(listener.GetSP()); 539254721Semaste 540288943Sdim ProcessInstanceInfo instance_info; 541288943Sdim if (target_sp->GetPlatform ()->GetProcessInfo (pid, instance_info)) 542288943Sdim attach_info.SetUserID (instance_info.GetEffectiveUserID ()); 543276479Sdim 544288943Sdim error.SetError (AttachToProcess (attach_info, *target_sp)); 545288943Sdim if (error.Success ()) 546288943Sdim sb_process.SetSP (target_sp->GetProcessSP ()); 547254721Semaste } 548254721Semaste else 549254721Semaste error.SetErrorString ("SBTarget is invalid"); 550276479Sdim 551254721Semaste if (log) 552288943Sdim log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)", 553288943Sdim static_cast<void*>(target_sp.get ()), 554288943Sdim __FUNCTION__, 555288943Sdim static_cast<void*>(sb_process.GetSP().get ())); 556254721Semaste return sb_process; 557254721Semaste} 558254721Semaste 559254721Semastelldb::SBProcess 560254721SemasteSBTarget::AttachToProcessWithName 561254721Semaste( 562254721Semaste SBListener &listener, 563254721Semaste const char *name, // basename of process to attach to 564254721Semaste bool wait_for, // if true wait for a new instance of "name" to be launched 565254721Semaste SBError& error // An error explaining what went wrong if attach fails 566254721Semaste) 567254721Semaste{ 568254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 569276479Sdim 570254721Semaste SBProcess sb_process; 571254721Semaste TargetSP target_sp(GetSP()); 572276479Sdim 573254721Semaste if (log) 574288943Sdim log->Printf ("SBTarget(%p)::%s (listener, name=%s, wait_for=%s, error)...", 575288943Sdim static_cast<void*>(target_sp.get()), 576288943Sdim __FUNCTION__, 577288943Sdim name, 578276479Sdim wait_for ? "true" : "false"); 579276479Sdim 580254721Semaste if (name && target_sp) 581254721Semaste { 582288943Sdim ProcessAttachInfo attach_info; 583288943Sdim attach_info.GetExecutableFile().SetFile(name, false); 584288943Sdim attach_info.SetWaitForLaunch(wait_for); 585288943Sdim if (listener.IsValid()) 586288943Sdim attach_info.SetListener(listener.GetSP()); 587254721Semaste 588288943Sdim error.SetError (AttachToProcess (attach_info, *target_sp)); 589288943Sdim if (error.Success ()) 590288943Sdim sb_process.SetSP (target_sp->GetProcessSP ()); 591254721Semaste } 592254721Semaste else 593254721Semaste error.SetErrorString ("SBTarget is invalid"); 594276479Sdim 595254721Semaste if (log) 596288943Sdim log->Printf ("SBTarget(%p)::%s (...) => SBProcess(%p)", 597276479Sdim static_cast<void*>(target_sp.get()), 598288943Sdim __FUNCTION__, 599288943Sdim static_cast<void*>(sb_process.GetSP().get())); 600254721Semaste return sb_process; 601254721Semaste} 602254721Semaste 603254721Semastelldb::SBProcess 604254721SemasteSBTarget::ConnectRemote 605254721Semaste( 606254721Semaste SBListener &listener, 607254721Semaste const char *url, 608254721Semaste const char *plugin_name, 609254721Semaste SBError& error 610254721Semaste) 611254721Semaste{ 612254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 613254721Semaste 614254721Semaste SBProcess sb_process; 615254721Semaste ProcessSP process_sp; 616254721Semaste TargetSP target_sp(GetSP()); 617276479Sdim 618254721Semaste if (log) 619276479Sdim log->Printf ("SBTarget(%p)::ConnectRemote (listener, url=%s, plugin_name=%s, error)...", 620276479Sdim static_cast<void*>(target_sp.get()), url, plugin_name); 621276479Sdim 622254721Semaste if (target_sp) 623254721Semaste { 624254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 625254721Semaste if (listener.IsValid()) 626254721Semaste process_sp = target_sp->CreateProcess (listener.ref(), plugin_name, NULL); 627254721Semaste else 628254721Semaste process_sp = target_sp->CreateProcess (target_sp->GetDebugger().GetListener(), plugin_name, NULL); 629276479Sdim 630254721Semaste if (process_sp) 631254721Semaste { 632254721Semaste sb_process.SetSP (process_sp); 633254721Semaste error.SetError (process_sp->ConnectRemote (NULL, url)); 634254721Semaste } 635254721Semaste else 636254721Semaste { 637254721Semaste error.SetErrorString ("unable to create lldb_private::Process"); 638254721Semaste } 639254721Semaste } 640254721Semaste else 641254721Semaste { 642254721Semaste error.SetErrorString ("SBTarget is invalid"); 643254721Semaste } 644276479Sdim 645254721Semaste if (log) 646254721Semaste log->Printf ("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)", 647276479Sdim static_cast<void*>(target_sp.get()), 648276479Sdim static_cast<void*>(process_sp.get())); 649254721Semaste return sb_process; 650254721Semaste} 651254721Semaste 652254721SemasteSBFileSpec 653254721SemasteSBTarget::GetExecutable () 654254721Semaste{ 655254721Semaste 656254721Semaste SBFileSpec exe_file_spec; 657254721Semaste TargetSP target_sp(GetSP()); 658254721Semaste if (target_sp) 659254721Semaste { 660254721Semaste Module *exe_module = target_sp->GetExecutableModulePointer(); 661254721Semaste if (exe_module) 662254721Semaste exe_file_spec.SetFileSpec (exe_module->GetFileSpec()); 663254721Semaste } 664254721Semaste 665254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 666254721Semaste if (log) 667254721Semaste { 668276479Sdim log->Printf ("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)", 669276479Sdim static_cast<void*>(target_sp.get()), 670276479Sdim static_cast<const void*>(exe_file_spec.get())); 671254721Semaste } 672254721Semaste 673254721Semaste return exe_file_spec; 674254721Semaste} 675254721Semaste 676254721Semastebool 677254721SemasteSBTarget::operator == (const SBTarget &rhs) const 678254721Semaste{ 679254721Semaste return m_opaque_sp.get() == rhs.m_opaque_sp.get(); 680254721Semaste} 681254721Semaste 682254721Semastebool 683254721SemasteSBTarget::operator != (const SBTarget &rhs) const 684254721Semaste{ 685254721Semaste return m_opaque_sp.get() != rhs.m_opaque_sp.get(); 686254721Semaste} 687254721Semaste 688254721Semastelldb::TargetSP 689254721SemasteSBTarget::GetSP () const 690254721Semaste{ 691254721Semaste return m_opaque_sp; 692254721Semaste} 693254721Semaste 694254721Semastevoid 695254721SemasteSBTarget::SetSP (const lldb::TargetSP& target_sp) 696254721Semaste{ 697254721Semaste m_opaque_sp = target_sp; 698254721Semaste} 699254721Semaste 700254721Semastelldb::SBAddress 701254721SemasteSBTarget::ResolveLoadAddress (lldb::addr_t vm_addr) 702254721Semaste{ 703254721Semaste lldb::SBAddress sb_addr; 704254721Semaste Address &addr = sb_addr.ref(); 705254721Semaste TargetSP target_sp(GetSP()); 706254721Semaste if (target_sp) 707254721Semaste { 708254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 709262528Semaste if (target_sp->ResolveLoadAddress (vm_addr, addr)) 710254721Semaste return sb_addr; 711254721Semaste } 712254721Semaste 713254721Semaste // We have a load address that isn't in a section, just return an address 714254721Semaste // with the offset filled in (the address) and the section set to NULL 715254721Semaste addr.SetRawAddress(vm_addr); 716254721Semaste return sb_addr; 717254721Semaste} 718254721Semaste 719280031Sdimlldb::SBAddress 720280031SdimSBTarget::ResolveFileAddress (lldb::addr_t file_addr) 721280031Sdim{ 722280031Sdim lldb::SBAddress sb_addr; 723280031Sdim Address &addr = sb_addr.ref(); 724280031Sdim TargetSP target_sp(GetSP()); 725280031Sdim if (target_sp) 726280031Sdim { 727280031Sdim Mutex::Locker api_locker (target_sp->GetAPIMutex()); 728280031Sdim if (target_sp->ResolveFileAddress (file_addr, addr)) 729280031Sdim return sb_addr; 730280031Sdim } 731262528Semaste 732280031Sdim addr.SetRawAddress(file_addr); 733280031Sdim return sb_addr; 734280031Sdim} 735280031Sdim 736262528Semastelldb::SBAddress 737262528SemasteSBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr) 738262528Semaste{ 739262528Semaste lldb::SBAddress sb_addr; 740262528Semaste Address &addr = sb_addr.ref(); 741262528Semaste TargetSP target_sp(GetSP()); 742262528Semaste if (target_sp) 743262528Semaste { 744262528Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 745262528Semaste if (target_sp->ResolveLoadAddress (vm_addr, addr)) 746262528Semaste return sb_addr; 747262528Semaste } 748262528Semaste 749262528Semaste // We have a load address that isn't in a section, just return an address 750262528Semaste // with the offset filled in (the address) and the section set to NULL 751262528Semaste addr.SetRawAddress(vm_addr); 752262528Semaste return sb_addr; 753262528Semaste} 754262528Semaste 755254721SemasteSBSymbolContext 756258054SemasteSBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, 757258054Semaste uint32_t resolve_scope) 758254721Semaste{ 759254721Semaste SBSymbolContext sc; 760254721Semaste if (addr.IsValid()) 761254721Semaste { 762254721Semaste TargetSP target_sp(GetSP()); 763254721Semaste if (target_sp) 764254721Semaste target_sp->GetImages().ResolveSymbolContextForAddress (addr.ref(), resolve_scope, sc.ref()); 765254721Semaste } 766254721Semaste return sc; 767254721Semaste} 768254721Semaste 769280031Sdimsize_t 770280031SdimSBTarget::ReadMemory (const SBAddress addr, 771280031Sdim void *buf, 772280031Sdim size_t size, 773280031Sdim lldb::SBError &error) 774280031Sdim{ 775280031Sdim SBError sb_error; 776280031Sdim size_t bytes_read = 0; 777280031Sdim TargetSP target_sp(GetSP()); 778280031Sdim if (target_sp) 779280031Sdim { 780280031Sdim Mutex::Locker api_locker (target_sp->GetAPIMutex()); 781280031Sdim bytes_read = target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref()); 782280031Sdim } 783280031Sdim else 784280031Sdim { 785280031Sdim sb_error.SetErrorString("invalid target"); 786280031Sdim } 787254721Semaste 788280031Sdim return bytes_read; 789280031Sdim} 790280031Sdim 791254721SemasteSBBreakpoint 792258054SemasteSBTarget::BreakpointCreateByLocation (const char *file, 793258054Semaste uint32_t line) 794254721Semaste{ 795254721Semaste return SBBreakpoint(BreakpointCreateByLocation (SBFileSpec (file, false), line)); 796254721Semaste} 797254721Semaste 798254721SemasteSBBreakpoint 799258054SemasteSBTarget::BreakpointCreateByLocation (const SBFileSpec &sb_file_spec, 800258054Semaste uint32_t line) 801254721Semaste{ 802254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 803254721Semaste 804254721Semaste SBBreakpoint sb_bp; 805254721Semaste TargetSP target_sp(GetSP()); 806254721Semaste if (target_sp && line != 0) 807254721Semaste { 808254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 809276479Sdim 810254721Semaste const LazyBool check_inlines = eLazyBoolCalculate; 811254721Semaste const LazyBool skip_prologue = eLazyBoolCalculate; 812254721Semaste const bool internal = false; 813258054Semaste const bool hardware = false; 814288943Sdim const LazyBool move_to_nearest_code = eLazyBoolCalculate; 815288943Sdim *sb_bp = target_sp->CreateBreakpoint (NULL, *sb_file_spec, line, check_inlines, skip_prologue, internal, hardware, move_to_nearest_code); 816254721Semaste } 817254721Semaste 818254721Semaste if (log) 819254721Semaste { 820254721Semaste SBStream sstr; 821254721Semaste sb_bp.GetDescription (sstr); 822254721Semaste char path[PATH_MAX]; 823254721Semaste sb_file_spec->GetPath (path, sizeof(path)); 824276479Sdim log->Printf ("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => SBBreakpoint(%p): %s", 825276479Sdim static_cast<void*>(target_sp.get()), path, line, 826276479Sdim static_cast<void*>(sb_bp.get()), sstr.GetData()); 827254721Semaste } 828254721Semaste 829254721Semaste return sb_bp; 830254721Semaste} 831254721Semaste 832254721SemasteSBBreakpoint 833258054SemasteSBTarget::BreakpointCreateByName (const char *symbol_name, 834258054Semaste const char *module_name) 835254721Semaste{ 836254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 837254721Semaste 838254721Semaste SBBreakpoint sb_bp; 839254721Semaste TargetSP target_sp(GetSP()); 840254721Semaste if (target_sp.get()) 841254721Semaste { 842254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 843276479Sdim 844254721Semaste const bool internal = false; 845258054Semaste const bool hardware = false; 846254721Semaste const LazyBool skip_prologue = eLazyBoolCalculate; 847254721Semaste if (module_name && module_name[0]) 848254721Semaste { 849254721Semaste FileSpecList module_spec_list; 850254721Semaste module_spec_list.Append (FileSpec (module_name, false)); 851296417Sdim *sb_bp = target_sp->CreateBreakpoint (&module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown, skip_prologue, internal, hardware); 852254721Semaste } 853254721Semaste else 854254721Semaste { 855296417Sdim *sb_bp = target_sp->CreateBreakpoint (NULL, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown, skip_prologue, internal, hardware); 856254721Semaste } 857254721Semaste } 858276479Sdim 859254721Semaste if (log) 860276479Sdim log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", module=\"%s\") => SBBreakpoint(%p)", 861276479Sdim static_cast<void*>(target_sp.get()), symbol_name, 862276479Sdim module_name, static_cast<void*>(sb_bp.get())); 863254721Semaste 864254721Semaste return sb_bp; 865254721Semaste} 866254721Semaste 867254721Semastelldb::SBBreakpoint 868254721SemasteSBTarget::BreakpointCreateByName (const char *symbol_name, 869258054Semaste const SBFileSpecList &module_list, 870258054Semaste const SBFileSpecList &comp_unit_list) 871254721Semaste{ 872254721Semaste uint32_t name_type_mask = eFunctionNameTypeAuto; 873296417Sdim return BreakpointCreateByName (symbol_name, name_type_mask, eLanguageTypeUnknown, module_list, comp_unit_list); 874254721Semaste} 875254721Semaste 876254721Semastelldb::SBBreakpoint 877254721SemasteSBTarget::BreakpointCreateByName (const char *symbol_name, 878258054Semaste uint32_t name_type_mask, 879258054Semaste const SBFileSpecList &module_list, 880258054Semaste const SBFileSpecList &comp_unit_list) 881254721Semaste{ 882296417Sdim return BreakpointCreateByName (symbol_name, name_type_mask, eLanguageTypeUnknown, module_list, comp_unit_list); 883296417Sdim} 884296417Sdim 885296417Sdimlldb::SBBreakpoint 886296417SdimSBTarget::BreakpointCreateByName (const char *symbol_name, 887296417Sdim uint32_t name_type_mask, 888296417Sdim LanguageType symbol_language, 889296417Sdim const SBFileSpecList &module_list, 890296417Sdim const SBFileSpecList &comp_unit_list) 891296417Sdim{ 892254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 893254721Semaste 894254721Semaste SBBreakpoint sb_bp; 895254721Semaste TargetSP target_sp(GetSP()); 896254721Semaste if (target_sp && symbol_name && symbol_name[0]) 897254721Semaste { 898254721Semaste const bool internal = false; 899258054Semaste const bool hardware = false; 900254721Semaste const LazyBool skip_prologue = eLazyBoolCalculate; 901254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 902254721Semaste *sb_bp = target_sp->CreateBreakpoint (module_list.get(), 903258054Semaste comp_unit_list.get(), 904258054Semaste symbol_name, 905258054Semaste name_type_mask, 906296417Sdim symbol_language, 907258054Semaste skip_prologue, 908258054Semaste internal, 909258054Semaste hardware); 910254721Semaste } 911276479Sdim 912254721Semaste if (log) 913276479Sdim log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", name_type: %d) => SBBreakpoint(%p)", 914276479Sdim static_cast<void*>(target_sp.get()), symbol_name, 915276479Sdim name_type_mask, static_cast<void*>(sb_bp.get())); 916254721Semaste 917254721Semaste return sb_bp; 918254721Semaste} 919254721Semaste 920254721Semastelldb::SBBreakpoint 921254721SemasteSBTarget::BreakpointCreateByNames (const char *symbol_names[], 922254721Semaste uint32_t num_names, 923254721Semaste uint32_t name_type_mask, 924254721Semaste const SBFileSpecList &module_list, 925254721Semaste const SBFileSpecList &comp_unit_list) 926254721Semaste{ 927296417Sdim return BreakpointCreateByNames(symbol_names, num_names, name_type_mask, eLanguageTypeUnknown, module_list, comp_unit_list); 928296417Sdim} 929296417Sdim 930296417Sdimlldb::SBBreakpoint 931296417SdimSBTarget::BreakpointCreateByNames (const char *symbol_names[], 932296417Sdim uint32_t num_names, 933296417Sdim uint32_t name_type_mask, 934296417Sdim LanguageType symbol_language, 935296417Sdim const SBFileSpecList &module_list, 936296417Sdim const SBFileSpecList &comp_unit_list) 937296417Sdim{ 938254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 939254721Semaste 940254721Semaste SBBreakpoint sb_bp; 941254721Semaste TargetSP target_sp(GetSP()); 942254721Semaste if (target_sp && num_names > 0) 943254721Semaste { 944254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 945254721Semaste const bool internal = false; 946258054Semaste const bool hardware = false; 947254721Semaste const LazyBool skip_prologue = eLazyBoolCalculate; 948254721Semaste *sb_bp = target_sp->CreateBreakpoint (module_list.get(), 949296417Sdim comp_unit_list.get(), 950296417Sdim symbol_names, 951296417Sdim num_names, 952296417Sdim name_type_mask, 953296417Sdim symbol_language, 954296417Sdim skip_prologue, 955296417Sdim internal, 956296417Sdim hardware); 957254721Semaste } 958276479Sdim 959254721Semaste if (log) 960254721Semaste { 961276479Sdim log->Printf ("SBTarget(%p)::BreakpointCreateByName (symbols={", 962276479Sdim static_cast<void*>(target_sp.get())); 963254721Semaste for (uint32_t i = 0 ; i < num_names; i++) 964254721Semaste { 965254721Semaste char sep; 966254721Semaste if (i < num_names - 1) 967254721Semaste sep = ','; 968254721Semaste else 969254721Semaste sep = '}'; 970254721Semaste if (symbol_names[i] != NULL) 971254721Semaste log->Printf ("\"%s\"%c ", symbol_names[i], sep); 972254721Semaste else 973254721Semaste log->Printf ("\"<NULL>\"%c ", sep); 974254721Semaste } 975276479Sdim log->Printf ("name_type: %d) => SBBreakpoint(%p)", name_type_mask, 976276479Sdim static_cast<void*>(sb_bp.get())); 977254721Semaste } 978254721Semaste 979254721Semaste return sb_bp; 980254721Semaste} 981254721Semaste 982254721SemasteSBBreakpoint 983258054SemasteSBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, 984258054Semaste const char *module_name) 985254721Semaste{ 986296417Sdim SBFileSpecList module_spec_list; 987296417Sdim SBFileSpecList comp_unit_list; 988296417Sdim if (module_name && module_name[0]) 989296417Sdim { 990296417Sdim module_spec_list.Append (FileSpec (module_name, false)); 991296417Sdim 992296417Sdim } 993296417Sdim return BreakpointCreateByRegex (symbol_name_regex, eLanguageTypeUnknown, module_spec_list, comp_unit_list); 994296417Sdim} 995296417Sdim 996296417Sdimlldb::SBBreakpoint 997296417SdimSBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, 998296417Sdim const SBFileSpecList &module_list, 999296417Sdim const SBFileSpecList &comp_unit_list) 1000296417Sdim{ 1001296417Sdim return BreakpointCreateByRegex (symbol_name_regex, eLanguageTypeUnknown, module_list, comp_unit_list); 1002296417Sdim} 1003296417Sdim 1004296417Sdimlldb::SBBreakpoint 1005296417SdimSBTarget::BreakpointCreateByRegex (const char *symbol_name_regex, 1006296417Sdim LanguageType symbol_language, 1007296417Sdim const SBFileSpecList &module_list, 1008296417Sdim const SBFileSpecList &comp_unit_list) 1009296417Sdim{ 1010254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1011254721Semaste 1012254721Semaste SBBreakpoint sb_bp; 1013254721Semaste TargetSP target_sp(GetSP()); 1014254721Semaste if (target_sp && symbol_name_regex && symbol_name_regex[0]) 1015254721Semaste { 1016254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1017254721Semaste RegularExpression regexp(symbol_name_regex); 1018254721Semaste const bool internal = false; 1019258054Semaste const bool hardware = false; 1020254721Semaste const LazyBool skip_prologue = eLazyBoolCalculate; 1021296417Sdim 1022296417Sdim *sb_bp = target_sp->CreateFuncRegexBreakpoint (module_list.get(), comp_unit_list.get(), regexp, symbol_language, skip_prologue, internal, hardware); 1023254721Semaste } 1024254721Semaste 1025254721Semaste if (log) 1026296417Sdim log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") => SBBreakpoint(%p)", 1027276479Sdim static_cast<void*>(target_sp.get()), symbol_name_regex, 1028296417Sdim static_cast<void*>(sb_bp.get())); 1029254721Semaste 1030254721Semaste return sb_bp; 1031254721Semaste} 1032254721Semaste 1033296417SdimSBBreakpoint 1034296417SdimSBTarget::BreakpointCreateByAddress (addr_t address) 1035254721Semaste{ 1036254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1037254721Semaste 1038254721Semaste SBBreakpoint sb_bp; 1039254721Semaste TargetSP target_sp(GetSP()); 1040296417Sdim if (target_sp) 1041254721Semaste { 1042254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1043258054Semaste const bool hardware = false; 1044296417Sdim *sb_bp = target_sp->CreateBreakpoint (address, false, hardware); 1045254721Semaste } 1046254721Semaste 1047254721Semaste if (log) 1048296417Sdim log->Printf ("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 ") => SBBreakpoint(%p)", 1049296417Sdim static_cast<void*>(target_sp.get()), 1050296417Sdim static_cast<uint64_t>(address), 1051276479Sdim static_cast<void*>(sb_bp.get())); 1052254721Semaste 1053254721Semaste return sb_bp; 1054254721Semaste} 1055254721Semaste 1056254721SemasteSBBreakpoint 1057296417SdimSBTarget::BreakpointCreateBySBAddress (SBAddress &sb_address) 1058254721Semaste{ 1059254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1060254721Semaste 1061254721Semaste SBBreakpoint sb_bp; 1062254721Semaste TargetSP target_sp(GetSP()); 1063296417Sdim if (!sb_address.IsValid()) 1064296417Sdim { 1065296417Sdim if (log) 1066296417Sdim log->Printf ("SBTarget(%p)::BreakpointCreateBySBAddress called with invalid address", 1067296417Sdim static_cast<void*>(target_sp.get())); 1068296417Sdim return sb_bp; 1069296417Sdim } 1070296417Sdim 1071254721Semaste if (target_sp) 1072254721Semaste { 1073254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1074258054Semaste const bool hardware = false; 1075296417Sdim *sb_bp = target_sp->CreateBreakpoint (sb_address.ref(), false, hardware); 1076254721Semaste } 1077276479Sdim 1078254721Semaste if (log) 1079296417Sdim { 1080296417Sdim SBStream s; 1081296417Sdim sb_address.GetDescription(s); 1082296417Sdim log->Printf ("SBTarget(%p)::BreakpointCreateBySBAddress (address=%s) => SBBreakpoint(%p)", 1083276479Sdim static_cast<void*>(target_sp.get()), 1084296417Sdim s.GetData(), 1085276479Sdim static_cast<void*>(sb_bp.get())); 1086296417Sdim } 1087254721Semaste 1088254721Semaste return sb_bp; 1089254721Semaste} 1090254721Semaste 1091254721Semastelldb::SBBreakpoint 1092258054SemasteSBTarget::BreakpointCreateBySourceRegex (const char *source_regex, 1093258054Semaste const lldb::SBFileSpec &source_file, 1094258054Semaste const char *module_name) 1095254721Semaste{ 1096254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1097254721Semaste 1098254721Semaste SBBreakpoint sb_bp; 1099254721Semaste TargetSP target_sp(GetSP()); 1100254721Semaste if (target_sp && source_regex && source_regex[0]) 1101254721Semaste { 1102254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1103254721Semaste RegularExpression regexp(source_regex); 1104254721Semaste FileSpecList source_file_spec_list; 1105258054Semaste const bool hardware = false; 1106288943Sdim const LazyBool move_to_nearest_code = eLazyBoolCalculate; 1107254721Semaste source_file_spec_list.Append (source_file.ref()); 1108276479Sdim 1109254721Semaste if (module_name && module_name[0]) 1110254721Semaste { 1111254721Semaste FileSpecList module_spec_list; 1112254721Semaste module_spec_list.Append (FileSpec (module_name, false)); 1113276479Sdim 1114288943Sdim *sb_bp = target_sp->CreateSourceRegexBreakpoint (&module_spec_list, &source_file_spec_list, regexp, false, hardware, move_to_nearest_code); 1115254721Semaste } 1116254721Semaste else 1117254721Semaste { 1118288943Sdim *sb_bp = target_sp->CreateSourceRegexBreakpoint (NULL, &source_file_spec_list, regexp, false, hardware, move_to_nearest_code); 1119254721Semaste } 1120254721Semaste } 1121254721Semaste 1122254721Semaste if (log) 1123254721Semaste { 1124254721Semaste char path[PATH_MAX]; 1125254721Semaste source_file->GetPath (path, sizeof(path)); 1126276479Sdim log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\", file=\"%s\", module_name=\"%s\") => SBBreakpoint(%p)", 1127276479Sdim static_cast<void*>(target_sp.get()), source_regex, path, 1128276479Sdim module_name, static_cast<void*>(sb_bp.get())); 1129254721Semaste } 1130254721Semaste 1131254721Semaste return sb_bp; 1132254721Semaste} 1133254721Semaste 1134254721Semastelldb::SBBreakpoint 1135288943SdimSBTarget::BreakpointCreateBySourceRegex (const char *source_regex, 1136288943Sdim const SBFileSpecList &module_list, 1137288943Sdim const lldb::SBFileSpecList &source_file_list) 1138254721Semaste{ 1139254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1140254721Semaste 1141254721Semaste SBBreakpoint sb_bp; 1142254721Semaste TargetSP target_sp(GetSP()); 1143254721Semaste if (target_sp && source_regex && source_regex[0]) 1144254721Semaste { 1145254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1146258054Semaste const bool hardware = false; 1147288943Sdim const LazyBool move_to_nearest_code = eLazyBoolCalculate; 1148254721Semaste RegularExpression regexp(source_regex); 1149288943Sdim *sb_bp = target_sp->CreateSourceRegexBreakpoint (module_list.get(), source_file_list.get(), regexp, false, hardware, move_to_nearest_code); 1150254721Semaste } 1151254721Semaste 1152254721Semaste if (log) 1153276479Sdim log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") => SBBreakpoint(%p)", 1154276479Sdim static_cast<void*>(target_sp.get()), source_regex, 1155276479Sdim static_cast<void*>(sb_bp.get())); 1156254721Semaste 1157254721Semaste return sb_bp; 1158254721Semaste} 1159254721Semaste 1160254721Semastelldb::SBBreakpoint 1161254721SemasteSBTarget::BreakpointCreateForException (lldb::LanguageType language, 1162258054Semaste bool catch_bp, 1163258054Semaste bool throw_bp) 1164254721Semaste{ 1165254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1166254721Semaste 1167254721Semaste SBBreakpoint sb_bp; 1168254721Semaste TargetSP target_sp(GetSP()); 1169254721Semaste if (target_sp) 1170254721Semaste { 1171254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1172258054Semaste const bool hardware = false; 1173258054Semaste *sb_bp = target_sp->CreateExceptionBreakpoint (language, catch_bp, throw_bp, hardware); 1174254721Semaste } 1175254721Semaste 1176254721Semaste if (log) 1177276479Sdim log->Printf ("SBTarget(%p)::BreakpointCreateByRegex (Language: %s, catch: %s throw: %s) => SBBreakpoint(%p)", 1178276479Sdim static_cast<void*>(target_sp.get()), 1179296417Sdim Language::GetNameForLanguageType(language), 1180276479Sdim catch_bp ? "on" : "off", throw_bp ? "on" : "off", 1181276479Sdim static_cast<void*>(sb_bp.get())); 1182254721Semaste 1183254721Semaste return sb_bp; 1184254721Semaste} 1185254721Semaste 1186254721Semasteuint32_t 1187254721SemasteSBTarget::GetNumBreakpoints () const 1188254721Semaste{ 1189254721Semaste TargetSP target_sp(GetSP()); 1190254721Semaste if (target_sp) 1191254721Semaste { 1192254721Semaste // The breakpoint list is thread safe, no need to lock 1193254721Semaste return target_sp->GetBreakpointList().GetSize(); 1194254721Semaste } 1195254721Semaste return 0; 1196254721Semaste} 1197254721Semaste 1198254721SemasteSBBreakpoint 1199254721SemasteSBTarget::GetBreakpointAtIndex (uint32_t idx) const 1200254721Semaste{ 1201254721Semaste SBBreakpoint sb_breakpoint; 1202254721Semaste TargetSP target_sp(GetSP()); 1203254721Semaste if (target_sp) 1204254721Semaste { 1205254721Semaste // The breakpoint list is thread safe, no need to lock 1206254721Semaste *sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx); 1207254721Semaste } 1208254721Semaste return sb_breakpoint; 1209254721Semaste} 1210254721Semaste 1211254721Semastebool 1212254721SemasteSBTarget::BreakpointDelete (break_id_t bp_id) 1213254721Semaste{ 1214254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1215254721Semaste 1216254721Semaste bool result = false; 1217254721Semaste TargetSP target_sp(GetSP()); 1218254721Semaste if (target_sp) 1219254721Semaste { 1220254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1221254721Semaste result = target_sp->RemoveBreakpointByID (bp_id); 1222254721Semaste } 1223254721Semaste 1224254721Semaste if (log) 1225276479Sdim log->Printf ("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", 1226276479Sdim static_cast<void*>(target_sp.get()), 1227276479Sdim static_cast<uint32_t>(bp_id), result); 1228254721Semaste 1229254721Semaste return result; 1230254721Semaste} 1231254721Semaste 1232254721SemasteSBBreakpoint 1233254721SemasteSBTarget::FindBreakpointByID (break_id_t bp_id) 1234254721Semaste{ 1235254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1236254721Semaste 1237254721Semaste SBBreakpoint sb_breakpoint; 1238254721Semaste TargetSP target_sp(GetSP()); 1239254721Semaste if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) 1240254721Semaste { 1241254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1242254721Semaste *sb_breakpoint = target_sp->GetBreakpointByID (bp_id); 1243254721Semaste } 1244254721Semaste 1245254721Semaste if (log) 1246276479Sdim log->Printf ("SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)", 1247276479Sdim static_cast<void*>(target_sp.get()), 1248276479Sdim static_cast<uint32_t>(bp_id), 1249276479Sdim static_cast<void*>(sb_breakpoint.get())); 1250254721Semaste 1251254721Semaste return sb_breakpoint; 1252254721Semaste} 1253254721Semaste 1254254721Semastebool 1255254721SemasteSBTarget::EnableAllBreakpoints () 1256254721Semaste{ 1257254721Semaste TargetSP target_sp(GetSP()); 1258254721Semaste if (target_sp) 1259254721Semaste { 1260254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1261254721Semaste target_sp->EnableAllBreakpoints (); 1262254721Semaste return true; 1263254721Semaste } 1264254721Semaste return false; 1265254721Semaste} 1266254721Semaste 1267254721Semastebool 1268254721SemasteSBTarget::DisableAllBreakpoints () 1269254721Semaste{ 1270254721Semaste TargetSP target_sp(GetSP()); 1271254721Semaste if (target_sp) 1272254721Semaste { 1273254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1274254721Semaste target_sp->DisableAllBreakpoints (); 1275254721Semaste return true; 1276254721Semaste } 1277254721Semaste return false; 1278254721Semaste} 1279254721Semaste 1280254721Semastebool 1281254721SemasteSBTarget::DeleteAllBreakpoints () 1282254721Semaste{ 1283254721Semaste TargetSP target_sp(GetSP()); 1284254721Semaste if (target_sp) 1285254721Semaste { 1286254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1287254721Semaste target_sp->RemoveAllBreakpoints (); 1288254721Semaste return true; 1289254721Semaste } 1290254721Semaste return false; 1291254721Semaste} 1292254721Semaste 1293254721Semasteuint32_t 1294254721SemasteSBTarget::GetNumWatchpoints () const 1295254721Semaste{ 1296254721Semaste TargetSP target_sp(GetSP()); 1297254721Semaste if (target_sp) 1298254721Semaste { 1299254721Semaste // The watchpoint list is thread safe, no need to lock 1300254721Semaste return target_sp->GetWatchpointList().GetSize(); 1301254721Semaste } 1302254721Semaste return 0; 1303254721Semaste} 1304254721Semaste 1305254721SemasteSBWatchpoint 1306254721SemasteSBTarget::GetWatchpointAtIndex (uint32_t idx) const 1307254721Semaste{ 1308254721Semaste SBWatchpoint sb_watchpoint; 1309254721Semaste TargetSP target_sp(GetSP()); 1310254721Semaste if (target_sp) 1311254721Semaste { 1312254721Semaste // The watchpoint list is thread safe, no need to lock 1313254721Semaste sb_watchpoint.SetSP (target_sp->GetWatchpointList().GetByIndex(idx)); 1314254721Semaste } 1315254721Semaste return sb_watchpoint; 1316254721Semaste} 1317254721Semaste 1318254721Semastebool 1319254721SemasteSBTarget::DeleteWatchpoint (watch_id_t wp_id) 1320254721Semaste{ 1321254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1322254721Semaste 1323254721Semaste bool result = false; 1324254721Semaste TargetSP target_sp(GetSP()); 1325254721Semaste if (target_sp) 1326254721Semaste { 1327254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1328254721Semaste Mutex::Locker locker; 1329254721Semaste target_sp->GetWatchpointList().GetListMutex(locker); 1330254721Semaste result = target_sp->RemoveWatchpointByID (wp_id); 1331254721Semaste } 1332254721Semaste 1333254721Semaste if (log) 1334276479Sdim log->Printf ("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", 1335276479Sdim static_cast<void*>(target_sp.get()), 1336276479Sdim static_cast<uint32_t>(wp_id), result); 1337254721Semaste 1338254721Semaste return result; 1339254721Semaste} 1340254721Semaste 1341254721SemasteSBWatchpoint 1342254721SemasteSBTarget::FindWatchpointByID (lldb::watch_id_t wp_id) 1343254721Semaste{ 1344254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1345254721Semaste 1346254721Semaste SBWatchpoint sb_watchpoint; 1347254721Semaste lldb::WatchpointSP watchpoint_sp; 1348254721Semaste TargetSP target_sp(GetSP()); 1349254721Semaste if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) 1350254721Semaste { 1351254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1352254721Semaste Mutex::Locker locker; 1353254721Semaste target_sp->GetWatchpointList().GetListMutex(locker); 1354254721Semaste watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id); 1355254721Semaste sb_watchpoint.SetSP (watchpoint_sp); 1356254721Semaste } 1357254721Semaste 1358254721Semaste if (log) 1359276479Sdim log->Printf ("SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)", 1360276479Sdim static_cast<void*>(target_sp.get()), 1361276479Sdim static_cast<uint32_t>(wp_id), 1362276479Sdim static_cast<void*>(watchpoint_sp.get())); 1363254721Semaste 1364254721Semaste return sb_watchpoint; 1365254721Semaste} 1366254721Semaste 1367254721Semastelldb::SBWatchpoint 1368254721SemasteSBTarget::WatchAddress (lldb::addr_t addr, size_t size, bool read, bool write, SBError &error) 1369254721Semaste{ 1370254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1371276479Sdim 1372254721Semaste SBWatchpoint sb_watchpoint; 1373254721Semaste lldb::WatchpointSP watchpoint_sp; 1374254721Semaste TargetSP target_sp(GetSP()); 1375254721Semaste if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && size > 0) 1376254721Semaste { 1377254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1378254721Semaste uint32_t watch_type = 0; 1379254721Semaste if (read) 1380254721Semaste watch_type |= LLDB_WATCH_TYPE_READ; 1381254721Semaste if (write) 1382254721Semaste watch_type |= LLDB_WATCH_TYPE_WRITE; 1383254721Semaste if (watch_type == 0) 1384254721Semaste { 1385254721Semaste error.SetErrorString("Can't create a watchpoint that is neither read nor write."); 1386254721Semaste return sb_watchpoint; 1387254721Semaste } 1388276479Sdim 1389254721Semaste // Target::CreateWatchpoint() is thread safe. 1390254721Semaste Error cw_error; 1391254721Semaste // This API doesn't take in a type, so we can't figure out what it is. 1392296417Sdim CompilerType *type = NULL; 1393254721Semaste watchpoint_sp = target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error); 1394254721Semaste error.SetError(cw_error); 1395254721Semaste sb_watchpoint.SetSP (watchpoint_sp); 1396254721Semaste } 1397276479Sdim 1398254721Semaste if (log) 1399254721Semaste log->Printf ("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 ", 0x%u) => SBWatchpoint(%p)", 1400276479Sdim static_cast<void*>(target_sp.get()), addr, 1401276479Sdim static_cast<uint32_t>(size), 1402276479Sdim static_cast<void*>(watchpoint_sp.get())); 1403276479Sdim 1404254721Semaste return sb_watchpoint; 1405254721Semaste} 1406254721Semaste 1407254721Semastebool 1408254721SemasteSBTarget::EnableAllWatchpoints () 1409254721Semaste{ 1410254721Semaste TargetSP target_sp(GetSP()); 1411254721Semaste if (target_sp) 1412254721Semaste { 1413254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1414254721Semaste Mutex::Locker locker; 1415254721Semaste target_sp->GetWatchpointList().GetListMutex(locker); 1416254721Semaste target_sp->EnableAllWatchpoints (); 1417254721Semaste return true; 1418254721Semaste } 1419254721Semaste return false; 1420254721Semaste} 1421254721Semaste 1422254721Semastebool 1423254721SemasteSBTarget::DisableAllWatchpoints () 1424254721Semaste{ 1425254721Semaste TargetSP target_sp(GetSP()); 1426254721Semaste if (target_sp) 1427254721Semaste { 1428254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1429254721Semaste Mutex::Locker locker; 1430254721Semaste target_sp->GetWatchpointList().GetListMutex(locker); 1431254721Semaste target_sp->DisableAllWatchpoints (); 1432254721Semaste return true; 1433254721Semaste } 1434254721Semaste return false; 1435254721Semaste} 1436254721Semaste 1437258054SemasteSBValue 1438258054SemasteSBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type) 1439258054Semaste{ 1440258054Semaste SBValue sb_value; 1441258054Semaste lldb::ValueObjectSP new_value_sp; 1442258054Semaste if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) 1443258054Semaste { 1444280031Sdim lldb::addr_t load_addr(addr.GetLoadAddress(*this)); 1445280031Sdim ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false))); 1446296417Sdim CompilerType ast_type(type.GetSP()->GetCompilerType(true)); 1447280031Sdim new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, exe_ctx, ast_type); 1448258054Semaste } 1449258054Semaste sb_value.SetSP(new_value_sp); 1450258054Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1451258054Semaste if (log) 1452258054Semaste { 1453258054Semaste if (new_value_sp) 1454276479Sdim log->Printf ("SBTarget(%p)::CreateValueFromAddress => \"%s\"", 1455276479Sdim static_cast<void*>(m_opaque_sp.get()), 1456276479Sdim new_value_sp->GetName().AsCString()); 1457258054Semaste else 1458276479Sdim log->Printf ("SBTarget(%p)::CreateValueFromAddress => NULL", 1459276479Sdim static_cast<void*>(m_opaque_sp.get())); 1460258054Semaste } 1461258054Semaste return sb_value; 1462258054Semaste} 1463258054Semaste 1464280031Sdimlldb::SBValue 1465280031SdimSBTarget::CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type) 1466280031Sdim{ 1467280031Sdim SBValue sb_value; 1468280031Sdim lldb::ValueObjectSP new_value_sp; 1469280031Sdim if (IsValid() && name && *name && data.IsValid() && type.IsValid()) 1470280031Sdim { 1471280031Sdim DataExtractorSP extractor(*data); 1472280031Sdim ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false))); 1473296417Sdim CompilerType ast_type(type.GetSP()->GetCompilerType(true)); 1474280031Sdim new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, exe_ctx, ast_type); 1475280031Sdim } 1476280031Sdim sb_value.SetSP(new_value_sp); 1477280031Sdim Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1478280031Sdim if (log) 1479280031Sdim { 1480280031Sdim if (new_value_sp) 1481280031Sdim log->Printf ("SBTarget(%p)::CreateValueFromData => \"%s\"", 1482280031Sdim static_cast<void*>(m_opaque_sp.get()), 1483280031Sdim new_value_sp->GetName().AsCString()); 1484280031Sdim else 1485280031Sdim log->Printf ("SBTarget(%p)::CreateValueFromData => NULL", 1486280031Sdim static_cast<void*>(m_opaque_sp.get())); 1487280031Sdim } 1488280031Sdim return sb_value; 1489280031Sdim} 1490280031Sdim 1491280031Sdimlldb::SBValue 1492280031SdimSBTarget::CreateValueFromExpression (const char *name, const char* expr) 1493280031Sdim{ 1494280031Sdim SBValue sb_value; 1495280031Sdim lldb::ValueObjectSP new_value_sp; 1496280031Sdim if (IsValid() && name && *name && expr && *expr) 1497280031Sdim { 1498280031Sdim ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false))); 1499280031Sdim new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx); 1500280031Sdim } 1501280031Sdim sb_value.SetSP(new_value_sp); 1502280031Sdim Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1503280031Sdim if (log) 1504280031Sdim { 1505280031Sdim if (new_value_sp) 1506280031Sdim log->Printf ("SBTarget(%p)::CreateValueFromExpression => \"%s\"", 1507280031Sdim static_cast<void*>(m_opaque_sp.get()), 1508280031Sdim new_value_sp->GetName().AsCString()); 1509280031Sdim else 1510280031Sdim log->Printf ("SBTarget(%p)::CreateValueFromExpression => NULL", 1511280031Sdim static_cast<void*>(m_opaque_sp.get())); 1512280031Sdim } 1513280031Sdim return sb_value; 1514280031Sdim} 1515280031Sdim 1516254721Semastebool 1517254721SemasteSBTarget::DeleteAllWatchpoints () 1518254721Semaste{ 1519254721Semaste TargetSP target_sp(GetSP()); 1520254721Semaste if (target_sp) 1521254721Semaste { 1522254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 1523254721Semaste Mutex::Locker locker; 1524254721Semaste target_sp->GetWatchpointList().GetListMutex(locker); 1525254721Semaste target_sp->RemoveAllWatchpoints (); 1526254721Semaste return true; 1527254721Semaste } 1528254721Semaste return false; 1529254721Semaste} 1530254721Semaste 1531254721Semaste 1532254721Semastelldb::SBModule 1533254721SemasteSBTarget::AddModule (const char *path, 1534254721Semaste const char *triple, 1535254721Semaste const char *uuid_cstr) 1536254721Semaste{ 1537254721Semaste return AddModule (path, triple, uuid_cstr, NULL); 1538254721Semaste} 1539254721Semaste 1540254721Semastelldb::SBModule 1541254721SemasteSBTarget::AddModule (const char *path, 1542254721Semaste const char *triple, 1543254721Semaste const char *uuid_cstr, 1544254721Semaste const char *symfile) 1545254721Semaste{ 1546254721Semaste lldb::SBModule sb_module; 1547254721Semaste TargetSP target_sp(GetSP()); 1548254721Semaste if (target_sp) 1549254721Semaste { 1550254721Semaste ModuleSpec module_spec; 1551254721Semaste if (path) 1552254721Semaste module_spec.GetFileSpec().SetFile(path, false); 1553254721Semaste 1554254721Semaste if (uuid_cstr) 1555254721Semaste module_spec.GetUUID().SetFromCString(uuid_cstr); 1556254721Semaste 1557254721Semaste if (triple) 1558254721Semaste module_spec.GetArchitecture().SetTriple (triple, target_sp->GetPlatform ().get()); 1559258054Semaste else 1560258054Semaste module_spec.GetArchitecture() = target_sp->GetArchitecture(); 1561254721Semaste 1562254721Semaste if (symfile) 1563254721Semaste module_spec.GetSymbolFileSpec ().SetFile(symfile, false); 1564254721Semaste 1565254721Semaste sb_module.SetSP(target_sp->GetSharedModule (module_spec)); 1566254721Semaste } 1567254721Semaste return sb_module; 1568254721Semaste} 1569254721Semaste 1570254721Semastelldb::SBModule 1571254721SemasteSBTarget::AddModule (const SBModuleSpec &module_spec) 1572254721Semaste{ 1573254721Semaste lldb::SBModule sb_module; 1574254721Semaste TargetSP target_sp(GetSP()); 1575254721Semaste if (target_sp) 1576254721Semaste sb_module.SetSP(target_sp->GetSharedModule (*module_spec.m_opaque_ap)); 1577254721Semaste return sb_module; 1578254721Semaste} 1579254721Semaste 1580254721Semastebool 1581254721SemasteSBTarget::AddModule (lldb::SBModule &module) 1582254721Semaste{ 1583254721Semaste TargetSP target_sp(GetSP()); 1584254721Semaste if (target_sp) 1585254721Semaste { 1586254721Semaste target_sp->GetImages().AppendIfNeeded (module.GetSP()); 1587254721Semaste return true; 1588254721Semaste } 1589254721Semaste return false; 1590254721Semaste} 1591254721Semaste 1592254721Semasteuint32_t 1593254721SemasteSBTarget::GetNumModules () const 1594254721Semaste{ 1595254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1596254721Semaste 1597254721Semaste uint32_t num = 0; 1598254721Semaste TargetSP target_sp(GetSP()); 1599254721Semaste if (target_sp) 1600254721Semaste { 1601254721Semaste // The module list is thread safe, no need to lock 1602254721Semaste num = target_sp->GetImages().GetSize(); 1603254721Semaste } 1604254721Semaste 1605254721Semaste if (log) 1606276479Sdim log->Printf ("SBTarget(%p)::GetNumModules () => %d", 1607276479Sdim static_cast<void*>(target_sp.get()), num); 1608254721Semaste 1609254721Semaste return num; 1610254721Semaste} 1611254721Semaste 1612254721Semastevoid 1613254721SemasteSBTarget::Clear () 1614254721Semaste{ 1615254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1616254721Semaste 1617254721Semaste if (log) 1618276479Sdim log->Printf ("SBTarget(%p)::Clear ()", 1619276479Sdim static_cast<void*>(m_opaque_sp.get())); 1620254721Semaste 1621254721Semaste m_opaque_sp.reset(); 1622254721Semaste} 1623254721Semaste 1624254721Semaste 1625254721SemasteSBModule 1626254721SemasteSBTarget::FindModule (const SBFileSpec &sb_file_spec) 1627254721Semaste{ 1628254721Semaste SBModule sb_module; 1629254721Semaste TargetSP target_sp(GetSP()); 1630254721Semaste if (target_sp && sb_file_spec.IsValid()) 1631254721Semaste { 1632254721Semaste ModuleSpec module_spec(*sb_file_spec); 1633254721Semaste // The module list is thread safe, no need to lock 1634254721Semaste sb_module.SetSP (target_sp->GetImages().FindFirstModule (module_spec)); 1635254721Semaste } 1636254721Semaste return sb_module; 1637254721Semaste} 1638254721Semaste 1639254721Semastelldb::ByteOrder 1640254721SemasteSBTarget::GetByteOrder () 1641254721Semaste{ 1642254721Semaste TargetSP target_sp(GetSP()); 1643254721Semaste if (target_sp) 1644254721Semaste return target_sp->GetArchitecture().GetByteOrder(); 1645254721Semaste return eByteOrderInvalid; 1646254721Semaste} 1647254721Semaste 1648254721Semasteconst char * 1649254721SemasteSBTarget::GetTriple () 1650254721Semaste{ 1651254721Semaste TargetSP target_sp(GetSP()); 1652254721Semaste if (target_sp) 1653254721Semaste { 1654254721Semaste std::string triple (target_sp->GetArchitecture().GetTriple().str()); 1655254721Semaste // Unique the string so we don't run into ownership issues since 1656254721Semaste // the const strings put the string into the string pool once and 1657254721Semaste // the strings never comes out 1658254721Semaste ConstString const_triple (triple.c_str()); 1659254721Semaste return const_triple.GetCString(); 1660254721Semaste } 1661254721Semaste return NULL; 1662254721Semaste} 1663254721Semaste 1664254721Semasteuint32_t 1665280031SdimSBTarget::GetDataByteSize () 1666280031Sdim{ 1667280031Sdim TargetSP target_sp(GetSP()); 1668280031Sdim if (target_sp) 1669280031Sdim { 1670280031Sdim return target_sp->GetArchitecture().GetDataByteSize() ; 1671280031Sdim } 1672280031Sdim return 0; 1673280031Sdim} 1674280031Sdim 1675280031Sdimuint32_t 1676280031SdimSBTarget::GetCodeByteSize () 1677280031Sdim{ 1678280031Sdim TargetSP target_sp(GetSP()); 1679280031Sdim if (target_sp) 1680280031Sdim { 1681280031Sdim return target_sp->GetArchitecture().GetCodeByteSize() ; 1682280031Sdim } 1683280031Sdim return 0; 1684280031Sdim} 1685280031Sdim 1686280031Sdimuint32_t 1687254721SemasteSBTarget::GetAddressByteSize() 1688254721Semaste{ 1689254721Semaste TargetSP target_sp(GetSP()); 1690254721Semaste if (target_sp) 1691254721Semaste return target_sp->GetArchitecture().GetAddressByteSize(); 1692254721Semaste return sizeof(void*); 1693254721Semaste} 1694254721Semaste 1695254721Semaste 1696254721SemasteSBModule 1697254721SemasteSBTarget::GetModuleAtIndex (uint32_t idx) 1698254721Semaste{ 1699254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1700254721Semaste 1701254721Semaste SBModule sb_module; 1702254721Semaste ModuleSP module_sp; 1703254721Semaste TargetSP target_sp(GetSP()); 1704254721Semaste if (target_sp) 1705254721Semaste { 1706254721Semaste // The module list is thread safe, no need to lock 1707254721Semaste module_sp = target_sp->GetImages().GetModuleAtIndex(idx); 1708254721Semaste sb_module.SetSP (module_sp); 1709254721Semaste } 1710254721Semaste 1711254721Semaste if (log) 1712276479Sdim log->Printf ("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)", 1713276479Sdim static_cast<void*>(target_sp.get()), idx, 1714276479Sdim static_cast<void*>(module_sp.get())); 1715254721Semaste 1716254721Semaste return sb_module; 1717254721Semaste} 1718254721Semaste 1719254721Semastebool 1720254721SemasteSBTarget::RemoveModule (lldb::SBModule module) 1721254721Semaste{ 1722254721Semaste TargetSP target_sp(GetSP()); 1723254721Semaste if (target_sp) 1724254721Semaste return target_sp->GetImages().Remove(module.GetSP()); 1725254721Semaste return false; 1726254721Semaste} 1727254721Semaste 1728254721Semaste 1729254721SemasteSBBroadcaster 1730254721SemasteSBTarget::GetBroadcaster () const 1731254721Semaste{ 1732254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 1733254721Semaste 1734254721Semaste TargetSP target_sp(GetSP()); 1735254721Semaste SBBroadcaster broadcaster(target_sp.get(), false); 1736276479Sdim 1737254721Semaste if (log) 1738276479Sdim log->Printf ("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)", 1739276479Sdim static_cast<void*>(target_sp.get()), 1740276479Sdim static_cast<void*>(broadcaster.get())); 1741254721Semaste 1742254721Semaste return broadcaster; 1743254721Semaste} 1744254721Semaste 1745254721Semastebool 1746254721SemasteSBTarget::GetDescription (SBStream &description, lldb::DescriptionLevel description_level) 1747254721Semaste{ 1748254721Semaste Stream &strm = description.ref(); 1749254721Semaste 1750254721Semaste TargetSP target_sp(GetSP()); 1751254721Semaste if (target_sp) 1752254721Semaste { 1753254721Semaste target_sp->Dump (&strm, description_level); 1754254721Semaste } 1755254721Semaste else 1756254721Semaste strm.PutCString ("No value"); 1757254721Semaste 1758254721Semaste return true; 1759254721Semaste} 1760254721Semaste 1761254721Semastelldb::SBSymbolContextList 1762254721SemasteSBTarget::FindFunctions (const char *name, uint32_t name_type_mask) 1763254721Semaste{ 1764254721Semaste lldb::SBSymbolContextList sb_sc_list; 1765254721Semaste if (name && name[0]) 1766254721Semaste { 1767254721Semaste TargetSP target_sp(GetSP()); 1768254721Semaste if (target_sp) 1769254721Semaste { 1770254721Semaste const bool symbols_ok = true; 1771254721Semaste const bool inlines_ok = true; 1772254721Semaste const bool append = true; 1773254721Semaste target_sp->GetImages().FindFunctions (ConstString(name), 1774254721Semaste name_type_mask, 1775254721Semaste symbols_ok, 1776254721Semaste inlines_ok, 1777254721Semaste append, 1778254721Semaste *sb_sc_list); 1779254721Semaste } 1780254721Semaste } 1781254721Semaste return sb_sc_list; 1782254721Semaste} 1783254721Semaste 1784280031Sdimlldb::SBSymbolContextList 1785280031SdimSBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype) 1786280031Sdim{ 1787280031Sdim lldb::SBSymbolContextList sb_sc_list; 1788280031Sdim if (name && name[0]) 1789280031Sdim { 1790280031Sdim TargetSP target_sp(GetSP()); 1791280031Sdim if (target_sp) 1792280031Sdim { 1793280031Sdim std::string regexstr; 1794280031Sdim switch (matchtype) 1795280031Sdim { 1796280031Sdim case eMatchTypeRegex: 1797280031Sdim target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list); 1798280031Sdim break; 1799280031Sdim case eMatchTypeStartsWith: 1800280031Sdim regexstr = llvm::Regex::escape(name) + ".*"; 1801280031Sdim target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list); 1802280031Sdim break; 1803280031Sdim default: 1804280031Sdim target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list); 1805280031Sdim break; 1806280031Sdim } 1807280031Sdim } 1808280031Sdim } 1809280031Sdim return sb_sc_list; 1810280031Sdim} 1811280031Sdim 1812254721Semastelldb::SBType 1813254721SemasteSBTarget::FindFirstType (const char* typename_cstr) 1814254721Semaste{ 1815254721Semaste TargetSP target_sp(GetSP()); 1816254721Semaste if (typename_cstr && typename_cstr[0] && target_sp) 1817254721Semaste { 1818254721Semaste ConstString const_typename(typename_cstr); 1819254721Semaste SymbolContext sc; 1820254721Semaste const bool exact_match = false; 1821254721Semaste 1822254721Semaste const ModuleList &module_list = target_sp->GetImages(); 1823254721Semaste size_t count = module_list.GetSize(); 1824254721Semaste for (size_t idx = 0; idx < count; idx++) 1825254721Semaste { 1826254721Semaste ModuleSP module_sp (module_list.GetModuleAtIndex(idx)); 1827254721Semaste if (module_sp) 1828254721Semaste { 1829254721Semaste TypeSP type_sp (module_sp->FindFirstType(sc, const_typename, exact_match)); 1830254721Semaste if (type_sp) 1831254721Semaste return SBType(type_sp); 1832254721Semaste } 1833254721Semaste } 1834254721Semaste 1835254721Semaste // Didn't find the type in the symbols; try the Objective-C runtime 1836254721Semaste // if one is installed 1837254721Semaste 1838254721Semaste ProcessSP process_sp(target_sp->GetProcessSP()); 1839254721Semaste 1840254721Semaste if (process_sp) 1841254721Semaste { 1842254721Semaste ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime(); 1843254721Semaste 1844254721Semaste if (objc_language_runtime) 1845254721Semaste { 1846280031Sdim DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor(); 1847254721Semaste 1848280031Sdim if (objc_decl_vendor) 1849254721Semaste { 1850280031Sdim std::vector <clang::NamedDecl *> decls; 1851254721Semaste 1852280031Sdim if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) 1853280031Sdim { 1854296417Sdim if (CompilerType type = ClangASTContext::GetTypeForDecl(decls[0])) 1855280031Sdim { 1856280031Sdim return SBType(type); 1857280031Sdim } 1858280031Sdim } 1859254721Semaste } 1860254721Semaste } 1861254721Semaste } 1862254721Semaste 1863254721Semaste // No matches, search for basic typename matches 1864254721Semaste ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); 1865254721Semaste if (clang_ast) 1866254721Semaste return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename)); 1867254721Semaste } 1868254721Semaste return SBType(); 1869254721Semaste} 1870254721Semaste 1871254721SemasteSBType 1872254721SemasteSBTarget::GetBasicType(lldb::BasicType type) 1873254721Semaste{ 1874254721Semaste TargetSP target_sp(GetSP()); 1875254721Semaste if (target_sp) 1876254721Semaste { 1877254721Semaste ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); 1878254721Semaste if (clang_ast) 1879254721Semaste return SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), type)); 1880254721Semaste } 1881254721Semaste return SBType(); 1882254721Semaste} 1883254721Semaste 1884254721Semaste 1885254721Semastelldb::SBTypeList 1886254721SemasteSBTarget::FindTypes (const char* typename_cstr) 1887254721Semaste{ 1888254721Semaste SBTypeList sb_type_list; 1889254721Semaste TargetSP target_sp(GetSP()); 1890254721Semaste if (typename_cstr && typename_cstr[0] && target_sp) 1891254721Semaste { 1892254721Semaste ModuleList& images = target_sp->GetImages(); 1893254721Semaste ConstString const_typename(typename_cstr); 1894254721Semaste bool exact_match = false; 1895254721Semaste SymbolContext sc; 1896254721Semaste TypeList type_list; 1897254721Semaste 1898254721Semaste uint32_t num_matches = images.FindTypes (sc, 1899254721Semaste const_typename, 1900254721Semaste exact_match, 1901254721Semaste UINT32_MAX, 1902254721Semaste type_list); 1903254721Semaste 1904254721Semaste if (num_matches > 0) 1905254721Semaste { 1906254721Semaste for (size_t idx = 0; idx < num_matches; idx++) 1907254721Semaste { 1908254721Semaste TypeSP type_sp (type_list.GetTypeAtIndex(idx)); 1909254721Semaste if (type_sp) 1910254721Semaste sb_type_list.Append(SBType(type_sp)); 1911254721Semaste } 1912254721Semaste } 1913254721Semaste 1914254721Semaste // Try the Objective-C runtime if one is installed 1915254721Semaste 1916254721Semaste ProcessSP process_sp(target_sp->GetProcessSP()); 1917254721Semaste 1918254721Semaste if (process_sp) 1919254721Semaste { 1920254721Semaste ObjCLanguageRuntime *objc_language_runtime = process_sp->GetObjCLanguageRuntime(); 1921254721Semaste 1922254721Semaste if (objc_language_runtime) 1923254721Semaste { 1924280031Sdim DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor(); 1925254721Semaste 1926280031Sdim if (objc_decl_vendor) 1927254721Semaste { 1928280031Sdim std::vector <clang::NamedDecl *> decls; 1929254721Semaste 1930280031Sdim if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) 1931254721Semaste { 1932280031Sdim for (clang::NamedDecl *decl : decls) 1933254721Semaste { 1934296417Sdim if (CompilerType type = ClangASTContext::GetTypeForDecl(decl)) 1935280031Sdim { 1936280031Sdim sb_type_list.Append(SBType(type)); 1937280031Sdim } 1938254721Semaste } 1939254721Semaste } 1940254721Semaste } 1941254721Semaste } 1942254721Semaste } 1943254721Semaste 1944254721Semaste if (sb_type_list.GetSize() == 0) 1945254721Semaste { 1946254721Semaste // No matches, search for basic typename matches 1947254721Semaste ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); 1948254721Semaste if (clang_ast) 1949254721Semaste sb_type_list.Append (SBType (ClangASTContext::GetBasicType (clang_ast->getASTContext(), const_typename))); 1950254721Semaste } 1951254721Semaste } 1952254721Semaste return sb_type_list; 1953254721Semaste} 1954254721Semaste 1955254721SemasteSBValueList 1956254721SemasteSBTarget::FindGlobalVariables (const char *name, uint32_t max_matches) 1957254721Semaste{ 1958254721Semaste SBValueList sb_value_list; 1959254721Semaste 1960254721Semaste TargetSP target_sp(GetSP()); 1961254721Semaste if (name && target_sp) 1962254721Semaste { 1963254721Semaste VariableList variable_list; 1964254721Semaste const bool append = true; 1965254721Semaste const uint32_t match_count = target_sp->GetImages().FindGlobalVariables (ConstString (name), 1966254721Semaste append, 1967254721Semaste max_matches, 1968254721Semaste variable_list); 1969254721Semaste 1970254721Semaste if (match_count > 0) 1971254721Semaste { 1972254721Semaste ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); 1973254721Semaste if (exe_scope == NULL) 1974254721Semaste exe_scope = target_sp.get(); 1975254721Semaste for (uint32_t i=0; i<match_count; ++i) 1976254721Semaste { 1977254721Semaste lldb::ValueObjectSP valobj_sp (ValueObjectVariable::Create (exe_scope, variable_list.GetVariableAtIndex(i))); 1978254721Semaste if (valobj_sp) 1979254721Semaste sb_value_list.Append(SBValue(valobj_sp)); 1980254721Semaste } 1981254721Semaste } 1982254721Semaste } 1983254721Semaste 1984254721Semaste return sb_value_list; 1985254721Semaste} 1986254721Semaste 1987280031SdimSBValueList 1988280031SdimSBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype) 1989280031Sdim{ 1990280031Sdim SBValueList sb_value_list; 1991280031Sdim 1992280031Sdim TargetSP target_sp(GetSP()); 1993280031Sdim if (name && target_sp) 1994280031Sdim { 1995280031Sdim VariableList variable_list; 1996280031Sdim const bool append = true; 1997280031Sdim 1998280031Sdim std::string regexstr; 1999280031Sdim uint32_t match_count; 2000280031Sdim switch (matchtype) 2001280031Sdim { 2002280031Sdim case eMatchTypeNormal: 2003280031Sdim match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name), 2004280031Sdim append, 2005280031Sdim max_matches, 2006280031Sdim variable_list); 2007280031Sdim break; 2008280031Sdim case eMatchTypeRegex: 2009280031Sdim match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name), 2010280031Sdim append, 2011280031Sdim max_matches, 2012280031Sdim variable_list); 2013280031Sdim break; 2014280031Sdim case eMatchTypeStartsWith: 2015280031Sdim regexstr = llvm::Regex::escape(name) + ".*"; 2016280031Sdim match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()), 2017280031Sdim append, 2018280031Sdim max_matches, 2019280031Sdim variable_list); 2020280031Sdim break; 2021280031Sdim } 2022280031Sdim 2023280031Sdim 2024280031Sdim if (match_count > 0) 2025280031Sdim { 2026280031Sdim ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); 2027280031Sdim if (exe_scope == NULL) 2028280031Sdim exe_scope = target_sp.get(); 2029280031Sdim for (uint32_t i = 0; i<match_count; ++i) 2030280031Sdim { 2031280031Sdim lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i))); 2032280031Sdim if (valobj_sp) 2033280031Sdim sb_value_list.Append(SBValue(valobj_sp)); 2034280031Sdim } 2035280031Sdim } 2036280031Sdim } 2037280031Sdim 2038280031Sdim return sb_value_list; 2039280031Sdim} 2040280031Sdim 2041280031Sdim 2042254721Semastelldb::SBValue 2043254721SemasteSBTarget::FindFirstGlobalVariable (const char* name) 2044254721Semaste{ 2045254721Semaste SBValueList sb_value_list(FindGlobalVariables(name, 1)); 2046254721Semaste if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) 2047254721Semaste return sb_value_list.GetValueAtIndex(0); 2048254721Semaste return SBValue(); 2049254721Semaste} 2050254721Semaste 2051254721SemasteSBSourceManager 2052254721SemasteSBTarget::GetSourceManager() 2053254721Semaste{ 2054254721Semaste SBSourceManager source_manager (*this); 2055254721Semaste return source_manager; 2056254721Semaste} 2057254721Semaste 2058254721Semastelldb::SBInstructionList 2059254721SemasteSBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count) 2060254721Semaste{ 2061254721Semaste return ReadInstructions (base_addr, count, NULL); 2062254721Semaste} 2063254721Semaste 2064254721Semastelldb::SBInstructionList 2065254721SemasteSBTarget::ReadInstructions (lldb::SBAddress base_addr, uint32_t count, const char *flavor_string) 2066254721Semaste{ 2067254721Semaste SBInstructionList sb_instructions; 2068254721Semaste 2069254721Semaste TargetSP target_sp(GetSP()); 2070254721Semaste if (target_sp) 2071254721Semaste { 2072254721Semaste Address *addr_ptr = base_addr.get(); 2073254721Semaste 2074254721Semaste if (addr_ptr) 2075254721Semaste { 2076254721Semaste DataBufferHeap data (target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0); 2077254721Semaste bool prefer_file_cache = false; 2078254721Semaste lldb_private::Error error; 2079254721Semaste lldb::addr_t load_addr = LLDB_INVALID_ADDRESS; 2080254721Semaste const size_t bytes_read = target_sp->ReadMemory(*addr_ptr, 2081254721Semaste prefer_file_cache, 2082254721Semaste data.GetBytes(), 2083254721Semaste data.GetByteSize(), 2084254721Semaste error, 2085254721Semaste &load_addr); 2086254721Semaste const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS; 2087254721Semaste sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(), 2088254721Semaste NULL, 2089254721Semaste flavor_string, 2090254721Semaste *addr_ptr, 2091254721Semaste data.GetBytes(), 2092254721Semaste bytes_read, 2093254721Semaste count, 2094254721Semaste data_from_file)); 2095254721Semaste } 2096254721Semaste } 2097254721Semaste 2098254721Semaste return sb_instructions; 2099254721Semaste 2100254721Semaste} 2101254721Semaste 2102254721Semastelldb::SBInstructionList 2103254721SemasteSBTarget::GetInstructions (lldb::SBAddress base_addr, const void *buf, size_t size) 2104254721Semaste{ 2105254721Semaste return GetInstructionsWithFlavor (base_addr, NULL, buf, size); 2106254721Semaste} 2107254721Semaste 2108254721Semastelldb::SBInstructionList 2109254721SemasteSBTarget::GetInstructionsWithFlavor (lldb::SBAddress base_addr, const char *flavor_string, const void *buf, size_t size) 2110254721Semaste{ 2111254721Semaste SBInstructionList sb_instructions; 2112254721Semaste 2113254721Semaste TargetSP target_sp(GetSP()); 2114254721Semaste if (target_sp) 2115254721Semaste { 2116254721Semaste Address addr; 2117254721Semaste 2118254721Semaste if (base_addr.get()) 2119254721Semaste addr = *base_addr.get(); 2120254721Semaste 2121254721Semaste const bool data_from_file = true; 2122254721Semaste 2123254721Semaste sb_instructions.SetDisassembler (Disassembler::DisassembleBytes (target_sp->GetArchitecture(), 2124254721Semaste NULL, 2125254721Semaste flavor_string, 2126254721Semaste addr, 2127254721Semaste buf, 2128254721Semaste size, 2129254721Semaste UINT32_MAX, 2130254721Semaste data_from_file)); 2131254721Semaste } 2132254721Semaste 2133254721Semaste return sb_instructions; 2134254721Semaste} 2135254721Semaste 2136254721Semastelldb::SBInstructionList 2137254721SemasteSBTarget::GetInstructions (lldb::addr_t base_addr, const void *buf, size_t size) 2138254721Semaste{ 2139254721Semaste return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), NULL, buf, size); 2140254721Semaste} 2141254721Semaste 2142254721Semastelldb::SBInstructionList 2143254721SemasteSBTarget::GetInstructionsWithFlavor (lldb::addr_t base_addr, const char *flavor_string, const void *buf, size_t size) 2144254721Semaste{ 2145254721Semaste return GetInstructionsWithFlavor (ResolveLoadAddress(base_addr), flavor_string, buf, size); 2146254721Semaste} 2147254721Semaste 2148254721SemasteSBError 2149254721SemasteSBTarget::SetSectionLoadAddress (lldb::SBSection section, 2150254721Semaste lldb::addr_t section_base_addr) 2151254721Semaste{ 2152254721Semaste SBError sb_error; 2153254721Semaste TargetSP target_sp(GetSP()); 2154254721Semaste if (target_sp) 2155254721Semaste { 2156254721Semaste if (!section.IsValid()) 2157254721Semaste { 2158254721Semaste sb_error.SetErrorStringWithFormat ("invalid section"); 2159254721Semaste } 2160254721Semaste else 2161254721Semaste { 2162254721Semaste SectionSP section_sp (section.GetSP()); 2163254721Semaste if (section_sp) 2164254721Semaste { 2165254721Semaste if (section_sp->IsThreadSpecific()) 2166254721Semaste { 2167254721Semaste sb_error.SetErrorString ("thread specific sections are not yet supported"); 2168254721Semaste } 2169254721Semaste else 2170254721Semaste { 2171262528Semaste ProcessSP process_sp (target_sp->GetProcessSP()); 2172262528Semaste if (target_sp->SetSectionLoadAddress (section_sp, section_base_addr)) 2173254721Semaste { 2174254721Semaste // Flush info in the process (stack frames, etc) 2175254721Semaste if (process_sp) 2176254721Semaste process_sp->Flush(); 2177254721Semaste } 2178254721Semaste } 2179254721Semaste } 2180254721Semaste } 2181254721Semaste } 2182254721Semaste else 2183254721Semaste { 2184254721Semaste sb_error.SetErrorString ("invalid target"); 2185254721Semaste } 2186254721Semaste return sb_error; 2187254721Semaste} 2188254721Semaste 2189254721SemasteSBError 2190254721SemasteSBTarget::ClearSectionLoadAddress (lldb::SBSection section) 2191254721Semaste{ 2192254721Semaste SBError sb_error; 2193254721Semaste 2194254721Semaste TargetSP target_sp(GetSP()); 2195254721Semaste if (target_sp) 2196254721Semaste { 2197254721Semaste if (!section.IsValid()) 2198254721Semaste { 2199254721Semaste sb_error.SetErrorStringWithFormat ("invalid section"); 2200254721Semaste } 2201254721Semaste else 2202254721Semaste { 2203262528Semaste ProcessSP process_sp (target_sp->GetProcessSP()); 2204262528Semaste if (target_sp->SetSectionUnloaded (section.GetSP())) 2205254721Semaste { 2206254721Semaste // Flush info in the process (stack frames, etc) 2207254721Semaste if (process_sp) 2208254721Semaste process_sp->Flush(); 2209254721Semaste } 2210254721Semaste } 2211254721Semaste } 2212254721Semaste else 2213254721Semaste { 2214254721Semaste sb_error.SetErrorStringWithFormat ("invalid target"); 2215254721Semaste } 2216254721Semaste return sb_error; 2217254721Semaste} 2218254721Semaste 2219254721SemasteSBError 2220254721SemasteSBTarget::SetModuleLoadAddress (lldb::SBModule module, int64_t slide_offset) 2221254721Semaste{ 2222254721Semaste SBError sb_error; 2223254721Semaste 2224254721Semaste TargetSP target_sp(GetSP()); 2225254721Semaste if (target_sp) 2226254721Semaste { 2227254721Semaste ModuleSP module_sp (module.GetSP()); 2228254721Semaste if (module_sp) 2229254721Semaste { 2230254721Semaste bool changed = false; 2231262528Semaste if (module_sp->SetLoadAddress (*target_sp, slide_offset, true, changed)) 2232254721Semaste { 2233254721Semaste // The load was successful, make sure that at least some sections 2234254721Semaste // changed before we notify that our module was loaded. 2235254721Semaste if (changed) 2236254721Semaste { 2237254721Semaste ModuleList module_list; 2238254721Semaste module_list.Append(module_sp); 2239254721Semaste target_sp->ModulesDidLoad (module_list); 2240254721Semaste // Flush info in the process (stack frames, etc) 2241254721Semaste ProcessSP process_sp (target_sp->GetProcessSP()); 2242254721Semaste if (process_sp) 2243254721Semaste process_sp->Flush(); 2244254721Semaste } 2245254721Semaste } 2246254721Semaste } 2247254721Semaste else 2248254721Semaste { 2249254721Semaste sb_error.SetErrorStringWithFormat ("invalid module"); 2250254721Semaste } 2251254721Semaste 2252254721Semaste } 2253254721Semaste else 2254254721Semaste { 2255254721Semaste sb_error.SetErrorStringWithFormat ("invalid target"); 2256254721Semaste } 2257254721Semaste return sb_error; 2258254721Semaste} 2259254721Semaste 2260254721SemasteSBError 2261254721SemasteSBTarget::ClearModuleLoadAddress (lldb::SBModule module) 2262254721Semaste{ 2263254721Semaste SBError sb_error; 2264254721Semaste 2265254721Semaste char path[PATH_MAX]; 2266254721Semaste TargetSP target_sp(GetSP()); 2267254721Semaste if (target_sp) 2268254721Semaste { 2269254721Semaste ModuleSP module_sp (module.GetSP()); 2270254721Semaste if (module_sp) 2271254721Semaste { 2272254721Semaste ObjectFile *objfile = module_sp->GetObjectFile(); 2273254721Semaste if (objfile) 2274254721Semaste { 2275254721Semaste SectionList *section_list = objfile->GetSectionList(); 2276254721Semaste if (section_list) 2277254721Semaste { 2278262528Semaste ProcessSP process_sp (target_sp->GetProcessSP()); 2279262528Semaste 2280254721Semaste bool changed = false; 2281254721Semaste const size_t num_sections = section_list->GetSize(); 2282254721Semaste for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) 2283254721Semaste { 2284254721Semaste SectionSP section_sp (section_list->GetSectionAtIndex(sect_idx)); 2285254721Semaste if (section_sp) 2286276479Sdim changed |= target_sp->SetSectionUnloaded (section_sp); 2287254721Semaste } 2288254721Semaste if (changed) 2289254721Semaste { 2290254721Semaste // Flush info in the process (stack frames, etc) 2291254721Semaste ProcessSP process_sp (target_sp->GetProcessSP()); 2292254721Semaste if (process_sp) 2293254721Semaste process_sp->Flush(); 2294254721Semaste } 2295254721Semaste } 2296254721Semaste else 2297254721Semaste { 2298254721Semaste module_sp->GetFileSpec().GetPath (path, sizeof(path)); 2299254721Semaste sb_error.SetErrorStringWithFormat ("no sections in object file '%s'", path); 2300254721Semaste } 2301254721Semaste } 2302254721Semaste else 2303254721Semaste { 2304254721Semaste module_sp->GetFileSpec().GetPath (path, sizeof(path)); 2305254721Semaste sb_error.SetErrorStringWithFormat ("no object file for module '%s'", path); 2306254721Semaste } 2307254721Semaste } 2308254721Semaste else 2309254721Semaste { 2310254721Semaste sb_error.SetErrorStringWithFormat ("invalid module"); 2311254721Semaste } 2312254721Semaste } 2313254721Semaste else 2314254721Semaste { 2315254721Semaste sb_error.SetErrorStringWithFormat ("invalid target"); 2316254721Semaste } 2317254721Semaste return sb_error; 2318254721Semaste} 2319254721Semaste 2320254721Semaste 2321254721Semastelldb::SBSymbolContextList 2322254721SemasteSBTarget::FindSymbols (const char *name, lldb::SymbolType symbol_type) 2323254721Semaste{ 2324254721Semaste SBSymbolContextList sb_sc_list; 2325254721Semaste if (name && name[0]) 2326254721Semaste { 2327254721Semaste TargetSP target_sp(GetSP()); 2328254721Semaste if (target_sp) 2329254721Semaste { 2330254721Semaste bool append = true; 2331254721Semaste target_sp->GetImages().FindSymbolsWithNameAndType (ConstString(name), 2332254721Semaste symbol_type, 2333254721Semaste *sb_sc_list, 2334254721Semaste append); 2335254721Semaste } 2336254721Semaste } 2337254721Semaste return sb_sc_list; 2338254721Semaste 2339254721Semaste} 2340254721Semaste 2341288943Sdimlldb::SBValue 2342288943SdimSBTarget::EvaluateExpression (const char *expr) 2343288943Sdim{ 2344288943Sdim TargetSP target_sp(GetSP()); 2345288943Sdim if (!target_sp) 2346288943Sdim return SBValue(); 2347254721Semaste 2348288943Sdim SBExpressionOptions options; 2349288943Sdim lldb::DynamicValueType fetch_dynamic_value = target_sp->GetPreferDynamicValue(); 2350288943Sdim options.SetFetchDynamicValue (fetch_dynamic_value); 2351288943Sdim options.SetUnwindOnError (true); 2352288943Sdim return EvaluateExpression(expr, options); 2353288943Sdim} 2354288943Sdim 2355254721Semastelldb::SBValue 2356254721SemasteSBTarget::EvaluateExpression (const char *expr, const SBExpressionOptions &options) 2357254721Semaste{ 2358254721Semaste Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); 2359254721Semaste Log * expr_log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_EXPRESSIONS)); 2360254721Semaste SBValue expr_result; 2361276479Sdim ExpressionResults exe_results = eExpressionSetupError; 2362254721Semaste ValueObjectSP expr_value_sp; 2363254721Semaste TargetSP target_sp(GetSP()); 2364254721Semaste StackFrame *frame = NULL; 2365254721Semaste if (target_sp) 2366254721Semaste { 2367254721Semaste if (expr == NULL || expr[0] == '\0') 2368254721Semaste { 2369254721Semaste if (log) 2370254721Semaste log->Printf ("SBTarget::EvaluateExpression called with an empty expression"); 2371254721Semaste return expr_result; 2372254721Semaste } 2373276479Sdim 2374254721Semaste Mutex::Locker api_locker (target_sp->GetAPIMutex()); 2375254721Semaste ExecutionContext exe_ctx (m_opaque_sp.get()); 2376276479Sdim 2377254721Semaste if (log) 2378254721Semaste log->Printf ("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr); 2379276479Sdim 2380254721Semaste frame = exe_ctx.GetFramePtr(); 2381254721Semaste Target *target = exe_ctx.GetTargetPtr(); 2382276479Sdim 2383254721Semaste if (target) 2384254721Semaste { 2385254721Semaste#ifdef LLDB_CONFIGURATION_DEBUG 2386254721Semaste StreamString frame_description; 2387254721Semaste if (frame) 2388254721Semaste frame->DumpUsingSettingsFormat (&frame_description); 2389254721Semaste Host::SetCrashDescriptionWithFormat ("SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = %u) %s", 2390254721Semaste expr, options.GetFetchDynamicValue(), frame_description.GetString().c_str()); 2391254721Semaste#endif 2392254721Semaste exe_results = target->EvaluateExpression (expr, 2393254721Semaste frame, 2394254721Semaste expr_value_sp, 2395254721Semaste options.ref()); 2396254721Semaste 2397254721Semaste expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue()); 2398254721Semaste#ifdef LLDB_CONFIGURATION_DEBUG 2399254721Semaste Host::SetCrashDescription (NULL); 2400254721Semaste#endif 2401254721Semaste } 2402254721Semaste else 2403254721Semaste { 2404254721Semaste if (log) 2405254721Semaste log->Printf ("SBTarget::EvaluateExpression () => error: could not reconstruct frame object for this SBTarget."); 2406254721Semaste } 2407254721Semaste } 2408254721Semaste#ifndef LLDB_DISABLE_PYTHON 2409254721Semaste if (expr_log) 2410254721Semaste expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is %s, summary %s **", 2411276479Sdim expr_result.GetValue(), expr_result.GetSummary()); 2412276479Sdim 2413254721Semaste if (log) 2414254721Semaste log->Printf ("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) (execution result=%d)", 2415276479Sdim static_cast<void*>(frame), expr, 2416276479Sdim static_cast<void*>(expr_value_sp.get()), exe_results); 2417254721Semaste#endif 2418276479Sdim 2419254721Semaste return expr_result; 2420254721Semaste} 2421254721Semaste 2422254721Semaste 2423254721Semastelldb::addr_t 2424254721SemasteSBTarget::GetStackRedZoneSize() 2425254721Semaste{ 2426254721Semaste TargetSP target_sp(GetSP()); 2427254721Semaste if (target_sp) 2428254721Semaste { 2429254721Semaste ABISP abi_sp; 2430254721Semaste ProcessSP process_sp (target_sp->GetProcessSP()); 2431254721Semaste if (process_sp) 2432254721Semaste abi_sp = process_sp->GetABI(); 2433254721Semaste else 2434254721Semaste abi_sp = ABI::FindPlugin(target_sp->GetArchitecture()); 2435254721Semaste if (abi_sp) 2436254721Semaste return abi_sp->GetRedZoneSize(); 2437254721Semaste } 2438254721Semaste return 0; 2439254721Semaste} 2440254721Semaste 2441288943Sdimlldb::SBLaunchInfo 2442288943SdimSBTarget::GetLaunchInfo () const 2443288943Sdim{ 2444288943Sdim lldb::SBLaunchInfo launch_info(NULL); 2445288943Sdim TargetSP target_sp(GetSP()); 2446288943Sdim if (target_sp) 2447288943Sdim launch_info.ref() = m_opaque_sp->GetProcessLaunchInfo(); 2448288943Sdim return launch_info; 2449288943Sdim} 2450288943Sdim 2451288943Sdimvoid 2452288943SdimSBTarget::SetLaunchInfo (const lldb::SBLaunchInfo &launch_info) 2453288943Sdim{ 2454288943Sdim TargetSP target_sp(GetSP()); 2455288943Sdim if (target_sp) 2456288943Sdim m_opaque_sp->SetProcessLaunchInfo(launch_info.ref()); 2457288943Sdim} 2458