1254721Semaste//===-- Target.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/lldb-python.h" 11254721Semaste 12254721Semaste#include "lldb/Target/Target.h" 13254721Semaste 14254721Semaste// C Includes 15254721Semaste// C++ Includes 16254721Semaste// Other libraries and framework includes 17254721Semaste// Project includes 18254721Semaste#include "lldb/Breakpoint/BreakpointResolver.h" 19254721Semaste#include "lldb/Breakpoint/BreakpointResolverAddress.h" 20254721Semaste#include "lldb/Breakpoint/BreakpointResolverFileLine.h" 21254721Semaste#include "lldb/Breakpoint/BreakpointResolverFileRegex.h" 22254721Semaste#include "lldb/Breakpoint/BreakpointResolverName.h" 23254721Semaste#include "lldb/Breakpoint/Watchpoint.h" 24254721Semaste#include "lldb/Core/Debugger.h" 25254721Semaste#include "lldb/Core/Event.h" 26254721Semaste#include "lldb/Core/Log.h" 27254721Semaste#include "lldb/Core/Module.h" 28254721Semaste#include "lldb/Core/ModuleSpec.h" 29254721Semaste#include "lldb/Core/Section.h" 30254721Semaste#include "lldb/Core/SourceManager.h" 31269024Semaste#include "lldb/Core/State.h" 32269024Semaste#include "lldb/Core/StreamFile.h" 33254721Semaste#include "lldb/Core/StreamString.h" 34254721Semaste#include "lldb/Core/Timer.h" 35254721Semaste#include "lldb/Core/ValueObject.h" 36254721Semaste#include "lldb/Expression/ClangASTSource.h" 37254721Semaste#include "lldb/Expression/ClangUserExpression.h" 38254721Semaste#include "lldb/Host/Host.h" 39254721Semaste#include "lldb/Interpreter/CommandInterpreter.h" 40254721Semaste#include "lldb/Interpreter/CommandReturnObject.h" 41254721Semaste#include "lldb/Interpreter/OptionGroupWatchpoint.h" 42254721Semaste#include "lldb/Interpreter/OptionValues.h" 43254721Semaste#include "lldb/Interpreter/Property.h" 44254721Semaste#include "lldb/lldb-private-log.h" 45254721Semaste#include "lldb/Symbol/ObjectFile.h" 46254721Semaste#include "lldb/Target/Process.h" 47269024Semaste#include "lldb/Target/SectionLoadList.h" 48254721Semaste#include "lldb/Target/StackFrame.h" 49263363Semaste#include "lldb/Target/SystemRuntime.h" 50254721Semaste#include "lldb/Target/Thread.h" 51254721Semaste#include "lldb/Target/ThreadSpec.h" 52254721Semaste 53254721Semasteusing namespace lldb; 54254721Semasteusing namespace lldb_private; 55254721Semaste 56254721SemasteConstString & 57254721SemasteTarget::GetStaticBroadcasterClass () 58254721Semaste{ 59254721Semaste static ConstString class_name ("lldb.target"); 60254721Semaste return class_name; 61254721Semaste} 62254721Semaste 63254721Semaste//---------------------------------------------------------------------- 64254721Semaste// Target constructor 65254721Semaste//---------------------------------------------------------------------- 66254721SemasteTarget::Target(Debugger &debugger, const ArchSpec &target_arch, const lldb::PlatformSP &platform_sp) : 67254721Semaste TargetProperties (this), 68254721Semaste Broadcaster (&debugger, Target::GetStaticBroadcasterClass().AsCString()), 69254721Semaste ExecutionContextScope (), 70254721Semaste m_debugger (debugger), 71254721Semaste m_platform_sp (platform_sp), 72254721Semaste m_mutex (Mutex::eMutexTypeRecursive), 73254721Semaste m_arch (target_arch), 74254721Semaste m_images (this), 75269024Semaste m_section_load_history (), 76254721Semaste m_breakpoint_list (false), 77254721Semaste m_internal_breakpoint_list (true), 78254721Semaste m_watchpoint_list (), 79254721Semaste m_process_sp (), 80254721Semaste m_search_filter_sp (), 81254721Semaste m_image_search_paths (ImageSearchPathsChanged, this), 82254721Semaste m_scratch_ast_context_ap (), 83254721Semaste m_scratch_ast_source_ap (), 84254721Semaste m_ast_importer_ap (), 85254721Semaste m_persistent_variables (), 86254721Semaste m_source_manager_ap(), 87254721Semaste m_stop_hooks (), 88254721Semaste m_stop_hook_next_id (0), 89269024Semaste m_valid (true), 90263363Semaste m_suppress_stop_hooks (false) 91254721Semaste{ 92254721Semaste SetEventName (eBroadcastBitBreakpointChanged, "breakpoint-changed"); 93254721Semaste SetEventName (eBroadcastBitModulesLoaded, "modules-loaded"); 94254721Semaste SetEventName (eBroadcastBitModulesUnloaded, "modules-unloaded"); 95254721Semaste SetEventName (eBroadcastBitWatchpointChanged, "watchpoint-changed"); 96254721Semaste SetEventName (eBroadcastBitSymbolsLoaded, "symbols-loaded"); 97254721Semaste 98254721Semaste CheckInWithManager(); 99254721Semaste 100254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 101254721Semaste if (log) 102254721Semaste log->Printf ("%p Target::Target()", this); 103254721Semaste if (m_arch.IsValid()) 104254721Semaste { 105254721Semaste LogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET, "Target::Target created with architecture %s (%s)", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str()); 106254721Semaste } 107254721Semaste} 108254721Semaste 109254721Semaste//---------------------------------------------------------------------- 110254721Semaste// Destructor 111254721Semaste//---------------------------------------------------------------------- 112254721SemasteTarget::~Target() 113254721Semaste{ 114254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_OBJECT)); 115254721Semaste if (log) 116254721Semaste log->Printf ("%p Target::~Target()", this); 117254721Semaste DeleteCurrentProcess (); 118254721Semaste} 119254721Semaste 120254721Semastevoid 121254721SemasteTarget::Dump (Stream *s, lldb::DescriptionLevel description_level) 122254721Semaste{ 123254721Semaste// s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); 124254721Semaste if (description_level != lldb::eDescriptionLevelBrief) 125254721Semaste { 126254721Semaste s->Indent(); 127254721Semaste s->PutCString("Target\n"); 128254721Semaste s->IndentMore(); 129254721Semaste m_images.Dump(s); 130254721Semaste m_breakpoint_list.Dump(s); 131254721Semaste m_internal_breakpoint_list.Dump(s); 132254721Semaste s->IndentLess(); 133254721Semaste } 134254721Semaste else 135254721Semaste { 136254721Semaste Module *exe_module = GetExecutableModulePointer(); 137254721Semaste if (exe_module) 138254721Semaste s->PutCString (exe_module->GetFileSpec().GetFilename().GetCString()); 139254721Semaste else 140254721Semaste s->PutCString ("No executable module."); 141254721Semaste } 142254721Semaste} 143254721Semaste 144254721Semastevoid 145254721SemasteTarget::CleanupProcess () 146254721Semaste{ 147254721Semaste // Do any cleanup of the target we need to do between process instances. 148254721Semaste // NB It is better to do this before destroying the process in case the 149254721Semaste // clean up needs some help from the process. 150254721Semaste m_breakpoint_list.ClearAllBreakpointSites(); 151254721Semaste m_internal_breakpoint_list.ClearAllBreakpointSites(); 152254721Semaste // Disable watchpoints just on the debugger side. 153254721Semaste Mutex::Locker locker; 154254721Semaste this->GetWatchpointList().GetListMutex(locker); 155254721Semaste DisableAllWatchpoints(false); 156254721Semaste ClearAllWatchpointHitCounts(); 157254721Semaste} 158254721Semaste 159254721Semastevoid 160254721SemasteTarget::DeleteCurrentProcess () 161254721Semaste{ 162254721Semaste if (m_process_sp.get()) 163254721Semaste { 164269024Semaste m_section_load_history.Clear(); 165254721Semaste if (m_process_sp->IsAlive()) 166254721Semaste m_process_sp->Destroy(); 167254721Semaste 168254721Semaste m_process_sp->Finalize(); 169254721Semaste 170254721Semaste CleanupProcess (); 171254721Semaste 172254721Semaste m_process_sp.reset(); 173254721Semaste } 174254721Semaste} 175254721Semaste 176254721Semasteconst lldb::ProcessSP & 177254721SemasteTarget::CreateProcess (Listener &listener, const char *plugin_name, const FileSpec *crash_file) 178254721Semaste{ 179254721Semaste DeleteCurrentProcess (); 180254721Semaste m_process_sp = Process::FindPlugin(*this, plugin_name, listener, crash_file); 181254721Semaste return m_process_sp; 182254721Semaste} 183254721Semaste 184254721Semasteconst lldb::ProcessSP & 185254721SemasteTarget::GetProcessSP () const 186254721Semaste{ 187254721Semaste return m_process_sp; 188254721Semaste} 189254721Semaste 190254721Semastevoid 191254721SemasteTarget::Destroy() 192254721Semaste{ 193254721Semaste Mutex::Locker locker (m_mutex); 194254721Semaste m_valid = false; 195254721Semaste DeleteCurrentProcess (); 196254721Semaste m_platform_sp.reset(); 197254721Semaste m_arch.Clear(); 198263367Semaste ClearModules(true); 199269024Semaste m_section_load_history.Clear(); 200254721Semaste const bool notify = false; 201254721Semaste m_breakpoint_list.RemoveAll(notify); 202254721Semaste m_internal_breakpoint_list.RemoveAll(notify); 203254721Semaste m_last_created_breakpoint.reset(); 204254721Semaste m_last_created_watchpoint.reset(); 205254721Semaste m_search_filter_sp.reset(); 206254721Semaste m_image_search_paths.Clear(notify); 207254721Semaste m_persistent_variables.Clear(); 208254721Semaste m_stop_hooks.clear(); 209254721Semaste m_stop_hook_next_id = 0; 210254721Semaste m_suppress_stop_hooks = false; 211254721Semaste} 212254721Semaste 213254721Semaste 214254721SemasteBreakpointList & 215254721SemasteTarget::GetBreakpointList(bool internal) 216254721Semaste{ 217254721Semaste if (internal) 218254721Semaste return m_internal_breakpoint_list; 219254721Semaste else 220254721Semaste return m_breakpoint_list; 221254721Semaste} 222254721Semaste 223254721Semasteconst BreakpointList & 224254721SemasteTarget::GetBreakpointList(bool internal) const 225254721Semaste{ 226254721Semaste if (internal) 227254721Semaste return m_internal_breakpoint_list; 228254721Semaste else 229254721Semaste return m_breakpoint_list; 230254721Semaste} 231254721Semaste 232254721SemasteBreakpointSP 233254721SemasteTarget::GetBreakpointByID (break_id_t break_id) 234254721Semaste{ 235254721Semaste BreakpointSP bp_sp; 236254721Semaste 237254721Semaste if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) 238254721Semaste bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); 239254721Semaste else 240254721Semaste bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); 241254721Semaste 242254721Semaste return bp_sp; 243254721Semaste} 244254721Semaste 245254721SemasteBreakpointSP 246254721SemasteTarget::CreateSourceRegexBreakpoint (const FileSpecList *containingModules, 247254721Semaste const FileSpecList *source_file_spec_list, 248254721Semaste RegularExpression &source_regex, 249263363Semaste bool internal, 250263363Semaste bool hardware) 251254721Semaste{ 252254721Semaste SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, source_file_spec_list)); 253254721Semaste BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex (NULL, source_regex)); 254269024Semaste return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true); 255254721Semaste} 256254721Semaste 257254721Semaste 258254721SemasteBreakpointSP 259254721SemasteTarget::CreateBreakpoint (const FileSpecList *containingModules, 260254721Semaste const FileSpec &file, 261254721Semaste uint32_t line_no, 262254721Semaste LazyBool check_inlines, 263254721Semaste LazyBool skip_prologue, 264263363Semaste bool internal, 265263363Semaste bool hardware) 266254721Semaste{ 267254721Semaste if (check_inlines == eLazyBoolCalculate) 268254721Semaste { 269254721Semaste const InlineStrategy inline_strategy = GetInlineStrategy(); 270254721Semaste switch (inline_strategy) 271254721Semaste { 272254721Semaste case eInlineBreakpointsNever: 273254721Semaste check_inlines = eLazyBoolNo; 274254721Semaste break; 275254721Semaste 276254721Semaste case eInlineBreakpointsHeaders: 277254721Semaste if (file.IsSourceImplementationFile()) 278254721Semaste check_inlines = eLazyBoolNo; 279254721Semaste else 280254721Semaste check_inlines = eLazyBoolYes; 281254721Semaste break; 282254721Semaste 283254721Semaste case eInlineBreakpointsAlways: 284254721Semaste check_inlines = eLazyBoolYes; 285254721Semaste break; 286254721Semaste } 287254721Semaste } 288254721Semaste SearchFilterSP filter_sp; 289254721Semaste if (check_inlines == eLazyBoolNo) 290254721Semaste { 291254721Semaste // Not checking for inlines, we are looking only for matching compile units 292254721Semaste FileSpecList compile_unit_list; 293254721Semaste compile_unit_list.Append (file); 294254721Semaste filter_sp = GetSearchFilterForModuleAndCUList (containingModules, &compile_unit_list); 295254721Semaste } 296254721Semaste else 297254721Semaste { 298254721Semaste filter_sp = GetSearchFilterForModuleList (containingModules); 299254721Semaste } 300254721Semaste if (skip_prologue == eLazyBoolCalculate) 301254721Semaste skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo; 302254721Semaste 303254721Semaste BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine (NULL, 304254721Semaste file, 305254721Semaste line_no, 306254721Semaste check_inlines, 307254721Semaste skip_prologue)); 308269024Semaste return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true); 309254721Semaste} 310254721Semaste 311254721Semaste 312254721SemasteBreakpointSP 313263363SemasteTarget::CreateBreakpoint (lldb::addr_t addr, bool internal, bool hardware) 314254721Semaste{ 315254721Semaste Address so_addr; 316254721Semaste // Attempt to resolve our load address if possible, though it is ok if 317254721Semaste // it doesn't resolve to section/offset. 318254721Semaste 319254721Semaste // Try and resolve as a load address if possible 320269024Semaste GetSectionLoadList().ResolveLoadAddress(addr, so_addr); 321254721Semaste if (!so_addr.IsValid()) 322254721Semaste { 323254721Semaste // The address didn't resolve, so just set this as an absolute address 324254721Semaste so_addr.SetOffset (addr); 325254721Semaste } 326263363Semaste BreakpointSP bp_sp (CreateBreakpoint(so_addr, internal, hardware)); 327254721Semaste return bp_sp; 328254721Semaste} 329254721Semaste 330254721SemasteBreakpointSP 331263363SemasteTarget::CreateBreakpoint (Address &addr, bool internal, bool hardware) 332254721Semaste{ 333254721Semaste SearchFilterSP filter_sp(new SearchFilterForNonModuleSpecificSearches (shared_from_this())); 334254721Semaste BreakpointResolverSP resolver_sp (new BreakpointResolverAddress (NULL, addr)); 335269024Semaste return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, false); 336254721Semaste} 337254721Semaste 338254721SemasteBreakpointSP 339254721SemasteTarget::CreateBreakpoint (const FileSpecList *containingModules, 340254721Semaste const FileSpecList *containingSourceFiles, 341254721Semaste const char *func_name, 342254721Semaste uint32_t func_name_type_mask, 343254721Semaste LazyBool skip_prologue, 344263363Semaste bool internal, 345263363Semaste bool hardware) 346254721Semaste{ 347254721Semaste BreakpointSP bp_sp; 348254721Semaste if (func_name) 349254721Semaste { 350254721Semaste SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); 351254721Semaste 352254721Semaste if (skip_prologue == eLazyBoolCalculate) 353254721Semaste skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo; 354254721Semaste 355254721Semaste BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, 356254721Semaste func_name, 357254721Semaste func_name_type_mask, 358254721Semaste Breakpoint::Exact, 359254721Semaste skip_prologue)); 360269024Semaste bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true); 361254721Semaste } 362254721Semaste return bp_sp; 363254721Semaste} 364254721Semaste 365254721Semastelldb::BreakpointSP 366254721SemasteTarget::CreateBreakpoint (const FileSpecList *containingModules, 367254721Semaste const FileSpecList *containingSourceFiles, 368254721Semaste const std::vector<std::string> &func_names, 369254721Semaste uint32_t func_name_type_mask, 370254721Semaste LazyBool skip_prologue, 371263363Semaste bool internal, 372263363Semaste bool hardware) 373254721Semaste{ 374254721Semaste BreakpointSP bp_sp; 375254721Semaste size_t num_names = func_names.size(); 376254721Semaste if (num_names > 0) 377254721Semaste { 378254721Semaste SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); 379254721Semaste 380254721Semaste if (skip_prologue == eLazyBoolCalculate) 381254721Semaste skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo; 382254721Semaste 383254721Semaste BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, 384254721Semaste func_names, 385254721Semaste func_name_type_mask, 386254721Semaste skip_prologue)); 387269024Semaste bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true); 388254721Semaste } 389254721Semaste return bp_sp; 390254721Semaste} 391254721Semaste 392254721SemasteBreakpointSP 393254721SemasteTarget::CreateBreakpoint (const FileSpecList *containingModules, 394254721Semaste const FileSpecList *containingSourceFiles, 395254721Semaste const char *func_names[], 396254721Semaste size_t num_names, 397254721Semaste uint32_t func_name_type_mask, 398254721Semaste LazyBool skip_prologue, 399263363Semaste bool internal, 400263363Semaste bool hardware) 401254721Semaste{ 402254721Semaste BreakpointSP bp_sp; 403254721Semaste if (num_names > 0) 404254721Semaste { 405254721Semaste SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); 406254721Semaste 407254721Semaste if (skip_prologue == eLazyBoolCalculate) 408254721Semaste skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo; 409254721Semaste 410254721Semaste BreakpointResolverSP resolver_sp (new BreakpointResolverName (NULL, 411254721Semaste func_names, 412254721Semaste num_names, 413254721Semaste func_name_type_mask, 414254721Semaste skip_prologue)); 415269024Semaste bp_sp = CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true); 416254721Semaste } 417254721Semaste return bp_sp; 418254721Semaste} 419254721Semaste 420254721SemasteSearchFilterSP 421254721SemasteTarget::GetSearchFilterForModule (const FileSpec *containingModule) 422254721Semaste{ 423254721Semaste SearchFilterSP filter_sp; 424254721Semaste if (containingModule != NULL) 425254721Semaste { 426254721Semaste // TODO: We should look into sharing module based search filters 427254721Semaste // across many breakpoints like we do for the simple target based one 428254721Semaste filter_sp.reset (new SearchFilterByModule (shared_from_this(), *containingModule)); 429254721Semaste } 430254721Semaste else 431254721Semaste { 432254721Semaste if (m_search_filter_sp.get() == NULL) 433254721Semaste m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this())); 434254721Semaste filter_sp = m_search_filter_sp; 435254721Semaste } 436254721Semaste return filter_sp; 437254721Semaste} 438254721Semaste 439254721SemasteSearchFilterSP 440254721SemasteTarget::GetSearchFilterForModuleList (const FileSpecList *containingModules) 441254721Semaste{ 442254721Semaste SearchFilterSP filter_sp; 443254721Semaste if (containingModules && containingModules->GetSize() != 0) 444254721Semaste { 445254721Semaste // TODO: We should look into sharing module based search filters 446254721Semaste // across many breakpoints like we do for the simple target based one 447254721Semaste filter_sp.reset (new SearchFilterByModuleList (shared_from_this(), *containingModules)); 448254721Semaste } 449254721Semaste else 450254721Semaste { 451254721Semaste if (m_search_filter_sp.get() == NULL) 452254721Semaste m_search_filter_sp.reset (new SearchFilterForNonModuleSpecificSearches (shared_from_this())); 453254721Semaste filter_sp = m_search_filter_sp; 454254721Semaste } 455254721Semaste return filter_sp; 456254721Semaste} 457254721Semaste 458254721SemasteSearchFilterSP 459254721SemasteTarget::GetSearchFilterForModuleAndCUList (const FileSpecList *containingModules, 460254721Semaste const FileSpecList *containingSourceFiles) 461254721Semaste{ 462254721Semaste if (containingSourceFiles == NULL || containingSourceFiles->GetSize() == 0) 463254721Semaste return GetSearchFilterForModuleList(containingModules); 464254721Semaste 465254721Semaste SearchFilterSP filter_sp; 466254721Semaste if (containingModules == NULL) 467254721Semaste { 468254721Semaste // We could make a special "CU List only SearchFilter". Better yet was if these could be composable, 469254721Semaste // but that will take a little reworking. 470254721Semaste 471254721Semaste filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), FileSpecList(), *containingSourceFiles)); 472254721Semaste } 473254721Semaste else 474254721Semaste { 475254721Semaste filter_sp.reset (new SearchFilterByModuleListAndCU (shared_from_this(), *containingModules, *containingSourceFiles)); 476254721Semaste } 477254721Semaste return filter_sp; 478254721Semaste} 479254721Semaste 480254721SemasteBreakpointSP 481254721SemasteTarget::CreateFuncRegexBreakpoint (const FileSpecList *containingModules, 482254721Semaste const FileSpecList *containingSourceFiles, 483254721Semaste RegularExpression &func_regex, 484254721Semaste LazyBool skip_prologue, 485263363Semaste bool internal, 486263363Semaste bool hardware) 487254721Semaste{ 488254721Semaste SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList (containingModules, containingSourceFiles)); 489254721Semaste BreakpointResolverSP resolver_sp(new BreakpointResolverName (NULL, 490254721Semaste func_regex, 491254721Semaste skip_prologue == eLazyBoolCalculate ? GetSkipPrologue() : skip_prologue)); 492254721Semaste 493269024Semaste return CreateBreakpoint (filter_sp, resolver_sp, internal, hardware, true); 494254721Semaste} 495254721Semaste 496254721Semastelldb::BreakpointSP 497254721SemasteTarget::CreateExceptionBreakpoint (enum lldb::LanguageType language, bool catch_bp, bool throw_bp, bool internal) 498254721Semaste{ 499254721Semaste return LanguageRuntime::CreateExceptionBreakpoint (*this, language, catch_bp, throw_bp, internal); 500254721Semaste} 501254721Semaste 502254721SemasteBreakpointSP 503269024SemasteTarget::CreateBreakpoint (SearchFilterSP &filter_sp, BreakpointResolverSP &resolver_sp, bool internal, bool request_hardware, bool resolve_indirect_symbols) 504254721Semaste{ 505254721Semaste BreakpointSP bp_sp; 506254721Semaste if (filter_sp && resolver_sp) 507254721Semaste { 508269024Semaste bp_sp.reset(new Breakpoint (*this, filter_sp, resolver_sp, request_hardware, resolve_indirect_symbols)); 509254721Semaste resolver_sp->SetBreakpoint (bp_sp.get()); 510254721Semaste 511254721Semaste if (internal) 512254721Semaste m_internal_breakpoint_list.Add (bp_sp, false); 513254721Semaste else 514254721Semaste m_breakpoint_list.Add (bp_sp, true); 515254721Semaste 516254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); 517254721Semaste if (log) 518254721Semaste { 519254721Semaste StreamString s; 520254721Semaste bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); 521254721Semaste log->Printf ("Target::%s (internal = %s) => break_id = %s\n", __FUNCTION__, internal ? "yes" : "no", s.GetData()); 522254721Semaste } 523254721Semaste 524254721Semaste bp_sp->ResolveBreakpoint(); 525254721Semaste } 526254721Semaste 527254721Semaste if (!internal && bp_sp) 528254721Semaste { 529254721Semaste m_last_created_breakpoint = bp_sp; 530254721Semaste } 531254721Semaste 532254721Semaste return bp_sp; 533254721Semaste} 534254721Semaste 535254721Semastebool 536254721SemasteTarget::ProcessIsValid() 537254721Semaste{ 538254721Semaste return (m_process_sp && m_process_sp->IsAlive()); 539254721Semaste} 540254721Semaste 541254721Semastestatic bool 542254721SemasteCheckIfWatchpointsExhausted(Target *target, Error &error) 543254721Semaste{ 544254721Semaste uint32_t num_supported_hardware_watchpoints; 545254721Semaste Error rc = target->GetProcessSP()->GetWatchpointSupportInfo(num_supported_hardware_watchpoints); 546254721Semaste if (rc.Success()) 547254721Semaste { 548254721Semaste uint32_t num_current_watchpoints = target->GetWatchpointList().GetSize(); 549254721Semaste if (num_current_watchpoints >= num_supported_hardware_watchpoints) 550254721Semaste error.SetErrorStringWithFormat("number of supported hardware watchpoints (%u) has been reached", 551254721Semaste num_supported_hardware_watchpoints); 552254721Semaste } 553254721Semaste return false; 554254721Semaste} 555254721Semaste 556254721Semaste// See also Watchpoint::SetWatchpointType(uint32_t type) and 557254721Semaste// the OptionGroupWatchpoint::WatchType enum type. 558254721SemasteWatchpointSP 559254721SemasteTarget::CreateWatchpoint(lldb::addr_t addr, size_t size, const ClangASTType *type, uint32_t kind, Error &error) 560254721Semaste{ 561254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); 562254721Semaste if (log) 563254721Semaste log->Printf("Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64 " type = %u)\n", 564254721Semaste __FUNCTION__, addr, (uint64_t)size, kind); 565254721Semaste 566254721Semaste WatchpointSP wp_sp; 567254721Semaste if (!ProcessIsValid()) 568254721Semaste { 569254721Semaste error.SetErrorString("process is not alive"); 570254721Semaste return wp_sp; 571254721Semaste } 572254721Semaste 573254721Semaste if (addr == LLDB_INVALID_ADDRESS || size == 0) 574254721Semaste { 575254721Semaste if (size == 0) 576254721Semaste error.SetErrorString("cannot set a watchpoint with watch_size of 0"); 577254721Semaste else 578254721Semaste error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr); 579254721Semaste return wp_sp; 580254721Semaste } 581254721Semaste 582254721Semaste if (!LLDB_WATCH_TYPE_IS_VALID(kind)) 583254721Semaste { 584254721Semaste error.SetErrorStringWithFormat ("invalid watchpoint type: %d", kind); 585254721Semaste } 586254721Semaste 587254721Semaste // Currently we only support one watchpoint per address, with total number 588254721Semaste // of watchpoints limited by the hardware which the inferior is running on. 589254721Semaste 590254721Semaste // Grab the list mutex while doing operations. 591254721Semaste const bool notify = false; // Don't notify about all the state changes we do on creating the watchpoint. 592254721Semaste Mutex::Locker locker; 593254721Semaste this->GetWatchpointList().GetListMutex(locker); 594254721Semaste WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr); 595254721Semaste if (matched_sp) 596254721Semaste { 597254721Semaste size_t old_size = matched_sp->GetByteSize(); 598254721Semaste uint32_t old_type = 599254721Semaste (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) | 600254721Semaste (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0); 601254721Semaste // Return the existing watchpoint if both size and type match. 602254721Semaste if (size == old_size && kind == old_type) 603254721Semaste { 604254721Semaste wp_sp = matched_sp; 605254721Semaste wp_sp->SetEnabled(false, notify); 606254721Semaste } 607254721Semaste else 608254721Semaste { 609254721Semaste // Nil the matched watchpoint; we will be creating a new one. 610254721Semaste m_process_sp->DisableWatchpoint(matched_sp.get(), notify); 611254721Semaste m_watchpoint_list.Remove(matched_sp->GetID(), true); 612254721Semaste } 613254721Semaste } 614254721Semaste 615254721Semaste if (!wp_sp) 616254721Semaste { 617254721Semaste wp_sp.reset(new Watchpoint(*this, addr, size, type)); 618254721Semaste wp_sp->SetWatchpointType(kind, notify); 619254721Semaste m_watchpoint_list.Add (wp_sp, true); 620254721Semaste } 621254721Semaste 622254721Semaste error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify); 623254721Semaste if (log) 624254721Semaste log->Printf("Target::%s (creation of watchpoint %s with id = %u)\n", 625254721Semaste __FUNCTION__, 626254721Semaste error.Success() ? "succeeded" : "failed", 627254721Semaste wp_sp->GetID()); 628254721Semaste 629254721Semaste if (error.Fail()) 630254721Semaste { 631254721Semaste // Enabling the watchpoint on the device side failed. 632254721Semaste // Remove the said watchpoint from the list maintained by the target instance. 633254721Semaste m_watchpoint_list.Remove (wp_sp->GetID(), true); 634254721Semaste // See if we could provide more helpful error message. 635254721Semaste if (!CheckIfWatchpointsExhausted(this, error)) 636254721Semaste { 637254721Semaste if (!OptionGroupWatchpoint::IsWatchSizeSupported(size)) 638263363Semaste error.SetErrorStringWithFormat("watch size of %zu is not supported", size); 639254721Semaste } 640254721Semaste wp_sp.reset(); 641254721Semaste } 642254721Semaste else 643254721Semaste m_last_created_watchpoint = wp_sp; 644254721Semaste return wp_sp; 645254721Semaste} 646254721Semaste 647254721Semastevoid 648254721SemasteTarget::RemoveAllBreakpoints (bool internal_also) 649254721Semaste{ 650254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); 651254721Semaste if (log) 652254721Semaste log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); 653254721Semaste 654254721Semaste m_breakpoint_list.RemoveAll (true); 655254721Semaste if (internal_also) 656254721Semaste m_internal_breakpoint_list.RemoveAll (false); 657254721Semaste 658254721Semaste m_last_created_breakpoint.reset(); 659254721Semaste} 660254721Semaste 661254721Semastevoid 662254721SemasteTarget::DisableAllBreakpoints (bool internal_also) 663254721Semaste{ 664254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); 665254721Semaste if (log) 666254721Semaste log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); 667254721Semaste 668254721Semaste m_breakpoint_list.SetEnabledAll (false); 669254721Semaste if (internal_also) 670254721Semaste m_internal_breakpoint_list.SetEnabledAll (false); 671254721Semaste} 672254721Semaste 673254721Semastevoid 674254721SemasteTarget::EnableAllBreakpoints (bool internal_also) 675254721Semaste{ 676254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); 677254721Semaste if (log) 678254721Semaste log->Printf ("Target::%s (internal_also = %s)\n", __FUNCTION__, internal_also ? "yes" : "no"); 679254721Semaste 680254721Semaste m_breakpoint_list.SetEnabledAll (true); 681254721Semaste if (internal_also) 682254721Semaste m_internal_breakpoint_list.SetEnabledAll (true); 683254721Semaste} 684254721Semaste 685254721Semastebool 686254721SemasteTarget::RemoveBreakpointByID (break_id_t break_id) 687254721Semaste{ 688254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); 689254721Semaste if (log) 690254721Semaste log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); 691254721Semaste 692254721Semaste if (DisableBreakpointByID (break_id)) 693254721Semaste { 694254721Semaste if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) 695254721Semaste m_internal_breakpoint_list.Remove(break_id, false); 696254721Semaste else 697254721Semaste { 698254721Semaste if (m_last_created_breakpoint) 699254721Semaste { 700254721Semaste if (m_last_created_breakpoint->GetID() == break_id) 701254721Semaste m_last_created_breakpoint.reset(); 702254721Semaste } 703254721Semaste m_breakpoint_list.Remove(break_id, true); 704254721Semaste } 705254721Semaste return true; 706254721Semaste } 707254721Semaste return false; 708254721Semaste} 709254721Semaste 710254721Semastebool 711254721SemasteTarget::DisableBreakpointByID (break_id_t break_id) 712254721Semaste{ 713254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); 714254721Semaste if (log) 715254721Semaste log->Printf ("Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, break_id, LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); 716254721Semaste 717254721Semaste BreakpointSP bp_sp; 718254721Semaste 719254721Semaste if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) 720254721Semaste bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); 721254721Semaste else 722254721Semaste bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); 723254721Semaste if (bp_sp) 724254721Semaste { 725254721Semaste bp_sp->SetEnabled (false); 726254721Semaste return true; 727254721Semaste } 728254721Semaste return false; 729254721Semaste} 730254721Semaste 731254721Semastebool 732254721SemasteTarget::EnableBreakpointByID (break_id_t break_id) 733254721Semaste{ 734254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_BREAKPOINTS)); 735254721Semaste if (log) 736254721Semaste log->Printf ("Target::%s (break_id = %i, internal = %s)\n", 737254721Semaste __FUNCTION__, 738254721Semaste break_id, 739254721Semaste LLDB_BREAK_ID_IS_INTERNAL (break_id) ? "yes" : "no"); 740254721Semaste 741254721Semaste BreakpointSP bp_sp; 742254721Semaste 743254721Semaste if (LLDB_BREAK_ID_IS_INTERNAL (break_id)) 744254721Semaste bp_sp = m_internal_breakpoint_list.FindBreakpointByID (break_id); 745254721Semaste else 746254721Semaste bp_sp = m_breakpoint_list.FindBreakpointByID (break_id); 747254721Semaste 748254721Semaste if (bp_sp) 749254721Semaste { 750254721Semaste bp_sp->SetEnabled (true); 751254721Semaste return true; 752254721Semaste } 753254721Semaste return false; 754254721Semaste} 755254721Semaste 756254721Semaste// The flag 'end_to_end', default to true, signifies that the operation is 757254721Semaste// performed end to end, for both the debugger and the debuggee. 758254721Semaste 759254721Semaste// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end 760254721Semaste// to end operations. 761254721Semastebool 762254721SemasteTarget::RemoveAllWatchpoints (bool end_to_end) 763254721Semaste{ 764254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); 765254721Semaste if (log) 766254721Semaste log->Printf ("Target::%s\n", __FUNCTION__); 767254721Semaste 768254721Semaste if (!end_to_end) { 769254721Semaste m_watchpoint_list.RemoveAll(true); 770254721Semaste return true; 771254721Semaste } 772254721Semaste 773254721Semaste // Otherwise, it's an end to end operation. 774254721Semaste 775254721Semaste if (!ProcessIsValid()) 776254721Semaste return false; 777254721Semaste 778254721Semaste size_t num_watchpoints = m_watchpoint_list.GetSize(); 779254721Semaste for (size_t i = 0; i < num_watchpoints; ++i) 780254721Semaste { 781254721Semaste WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); 782254721Semaste if (!wp_sp) 783254721Semaste return false; 784254721Semaste 785254721Semaste Error rc = m_process_sp->DisableWatchpoint(wp_sp.get()); 786254721Semaste if (rc.Fail()) 787254721Semaste return false; 788254721Semaste } 789254721Semaste m_watchpoint_list.RemoveAll (true); 790254721Semaste m_last_created_watchpoint.reset(); 791254721Semaste return true; // Success! 792254721Semaste} 793254721Semaste 794254721Semaste// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to 795254721Semaste// end operations. 796254721Semastebool 797254721SemasteTarget::DisableAllWatchpoints (bool end_to_end) 798254721Semaste{ 799254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); 800254721Semaste if (log) 801254721Semaste log->Printf ("Target::%s\n", __FUNCTION__); 802254721Semaste 803254721Semaste if (!end_to_end) { 804254721Semaste m_watchpoint_list.SetEnabledAll(false); 805254721Semaste return true; 806254721Semaste } 807254721Semaste 808254721Semaste // Otherwise, it's an end to end operation. 809254721Semaste 810254721Semaste if (!ProcessIsValid()) 811254721Semaste return false; 812254721Semaste 813254721Semaste size_t num_watchpoints = m_watchpoint_list.GetSize(); 814254721Semaste for (size_t i = 0; i < num_watchpoints; ++i) 815254721Semaste { 816254721Semaste WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); 817254721Semaste if (!wp_sp) 818254721Semaste return false; 819254721Semaste 820254721Semaste Error rc = m_process_sp->DisableWatchpoint(wp_sp.get()); 821254721Semaste if (rc.Fail()) 822254721Semaste return false; 823254721Semaste } 824254721Semaste return true; // Success! 825254721Semaste} 826254721Semaste 827254721Semaste// Assumption: Caller holds the list mutex lock for m_watchpoint_list for end to 828254721Semaste// end operations. 829254721Semastebool 830254721SemasteTarget::EnableAllWatchpoints (bool end_to_end) 831254721Semaste{ 832254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); 833254721Semaste if (log) 834254721Semaste log->Printf ("Target::%s\n", __FUNCTION__); 835254721Semaste 836254721Semaste if (!end_to_end) { 837254721Semaste m_watchpoint_list.SetEnabledAll(true); 838254721Semaste return true; 839254721Semaste } 840254721Semaste 841254721Semaste // Otherwise, it's an end to end operation. 842254721Semaste 843254721Semaste if (!ProcessIsValid()) 844254721Semaste return false; 845254721Semaste 846254721Semaste size_t num_watchpoints = m_watchpoint_list.GetSize(); 847254721Semaste for (size_t i = 0; i < num_watchpoints; ++i) 848254721Semaste { 849254721Semaste WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); 850254721Semaste if (!wp_sp) 851254721Semaste return false; 852254721Semaste 853254721Semaste Error rc = m_process_sp->EnableWatchpoint(wp_sp.get()); 854254721Semaste if (rc.Fail()) 855254721Semaste return false; 856254721Semaste } 857254721Semaste return true; // Success! 858254721Semaste} 859254721Semaste 860254721Semaste// Assumption: Caller holds the list mutex lock for m_watchpoint_list. 861254721Semastebool 862254721SemasteTarget::ClearAllWatchpointHitCounts () 863254721Semaste{ 864254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); 865254721Semaste if (log) 866254721Semaste log->Printf ("Target::%s\n", __FUNCTION__); 867254721Semaste 868254721Semaste size_t num_watchpoints = m_watchpoint_list.GetSize(); 869254721Semaste for (size_t i = 0; i < num_watchpoints; ++i) 870254721Semaste { 871254721Semaste WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); 872254721Semaste if (!wp_sp) 873254721Semaste return false; 874254721Semaste 875254721Semaste wp_sp->ResetHitCount(); 876254721Semaste } 877254721Semaste return true; // Success! 878254721Semaste} 879254721Semaste 880254721Semaste// Assumption: Caller holds the list mutex lock for m_watchpoint_list 881254721Semaste// during these operations. 882254721Semastebool 883254721SemasteTarget::IgnoreAllWatchpoints (uint32_t ignore_count) 884254721Semaste{ 885254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); 886254721Semaste if (log) 887254721Semaste log->Printf ("Target::%s\n", __FUNCTION__); 888254721Semaste 889254721Semaste if (!ProcessIsValid()) 890254721Semaste return false; 891254721Semaste 892254721Semaste size_t num_watchpoints = m_watchpoint_list.GetSize(); 893254721Semaste for (size_t i = 0; i < num_watchpoints; ++i) 894254721Semaste { 895254721Semaste WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); 896254721Semaste if (!wp_sp) 897254721Semaste return false; 898254721Semaste 899254721Semaste wp_sp->SetIgnoreCount(ignore_count); 900254721Semaste } 901254721Semaste return true; // Success! 902254721Semaste} 903254721Semaste 904254721Semaste// Assumption: Caller holds the list mutex lock for m_watchpoint_list. 905254721Semastebool 906254721SemasteTarget::DisableWatchpointByID (lldb::watch_id_t watch_id) 907254721Semaste{ 908254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); 909254721Semaste if (log) 910254721Semaste log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); 911254721Semaste 912254721Semaste if (!ProcessIsValid()) 913254721Semaste return false; 914254721Semaste 915254721Semaste WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id); 916254721Semaste if (wp_sp) 917254721Semaste { 918254721Semaste Error rc = m_process_sp->DisableWatchpoint(wp_sp.get()); 919254721Semaste if (rc.Success()) 920254721Semaste return true; 921254721Semaste 922254721Semaste // Else, fallthrough. 923254721Semaste } 924254721Semaste return false; 925254721Semaste} 926254721Semaste 927254721Semaste// Assumption: Caller holds the list mutex lock for m_watchpoint_list. 928254721Semastebool 929254721SemasteTarget::EnableWatchpointByID (lldb::watch_id_t watch_id) 930254721Semaste{ 931254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); 932254721Semaste if (log) 933254721Semaste log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); 934254721Semaste 935254721Semaste if (!ProcessIsValid()) 936254721Semaste return false; 937254721Semaste 938254721Semaste WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id); 939254721Semaste if (wp_sp) 940254721Semaste { 941254721Semaste Error rc = m_process_sp->EnableWatchpoint(wp_sp.get()); 942254721Semaste if (rc.Success()) 943254721Semaste return true; 944254721Semaste 945254721Semaste // Else, fallthrough. 946254721Semaste } 947254721Semaste return false; 948254721Semaste} 949254721Semaste 950254721Semaste// Assumption: Caller holds the list mutex lock for m_watchpoint_list. 951254721Semastebool 952254721SemasteTarget::RemoveWatchpointByID (lldb::watch_id_t watch_id) 953254721Semaste{ 954254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); 955254721Semaste if (log) 956254721Semaste log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); 957254721Semaste 958254721Semaste WatchpointSP watch_to_remove_sp = m_watchpoint_list.FindByID(watch_id); 959254721Semaste if (watch_to_remove_sp == m_last_created_watchpoint) 960254721Semaste m_last_created_watchpoint.reset(); 961254721Semaste 962254721Semaste if (DisableWatchpointByID (watch_id)) 963254721Semaste { 964254721Semaste m_watchpoint_list.Remove(watch_id, true); 965254721Semaste return true; 966254721Semaste } 967254721Semaste return false; 968254721Semaste} 969254721Semaste 970254721Semaste// Assumption: Caller holds the list mutex lock for m_watchpoint_list. 971254721Semastebool 972254721SemasteTarget::IgnoreWatchpointByID (lldb::watch_id_t watch_id, uint32_t ignore_count) 973254721Semaste{ 974254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_WATCHPOINTS)); 975254721Semaste if (log) 976254721Semaste log->Printf ("Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); 977254721Semaste 978254721Semaste if (!ProcessIsValid()) 979254721Semaste return false; 980254721Semaste 981254721Semaste WatchpointSP wp_sp = m_watchpoint_list.FindByID (watch_id); 982254721Semaste if (wp_sp) 983254721Semaste { 984254721Semaste wp_sp->SetIgnoreCount(ignore_count); 985254721Semaste return true; 986254721Semaste } 987254721Semaste return false; 988254721Semaste} 989254721Semaste 990254721SemasteModuleSP 991254721SemasteTarget::GetExecutableModule () 992254721Semaste{ 993254721Semaste return m_images.GetModuleAtIndex(0); 994254721Semaste} 995254721Semaste 996254721SemasteModule* 997254721SemasteTarget::GetExecutableModulePointer () 998254721Semaste{ 999254721Semaste return m_images.GetModulePointerAtIndex(0); 1000254721Semaste} 1001254721Semaste 1002254721Semastestatic void 1003254721SemasteLoadScriptingResourceForModule (const ModuleSP &module_sp, Target *target) 1004254721Semaste{ 1005254721Semaste Error error; 1006254721Semaste StreamString feedback_stream; 1007254721Semaste if (module_sp && !module_sp->LoadScriptingResourceInTarget(target, error, &feedback_stream)) 1008254721Semaste { 1009254721Semaste if (error.AsCString()) 1010269024Semaste target->GetDebugger().GetErrorFile()->Printf("unable to load scripting data for module %s - error reported was %s\n", 1011254721Semaste module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(), 1012254721Semaste error.AsCString()); 1013254721Semaste if (feedback_stream.GetSize()) 1014269024Semaste target->GetDebugger().GetErrorFile()->Printf("%s\n", 1015254721Semaste feedback_stream.GetData()); 1016254721Semaste } 1017254721Semaste} 1018254721Semaste 1019254721Semastevoid 1020263367SemasteTarget::ClearModules(bool delete_locations) 1021254721Semaste{ 1022263367Semaste ModulesDidUnload (m_images, delete_locations); 1023269024Semaste m_section_load_history.Clear(); 1024254721Semaste m_images.Clear(); 1025254721Semaste m_scratch_ast_context_ap.reset(); 1026254721Semaste m_scratch_ast_source_ap.reset(); 1027254721Semaste m_ast_importer_ap.reset(); 1028263363Semaste} 1029263363Semaste 1030263363Semastevoid 1031263367SemasteTarget::DidExec () 1032263367Semaste{ 1033263367Semaste // When a process exec's we need to know about it so we can do some cleanup. 1034263367Semaste m_breakpoint_list.RemoveInvalidLocations(m_arch); 1035263367Semaste m_internal_breakpoint_list.RemoveInvalidLocations(m_arch); 1036263367Semaste} 1037263367Semaste 1038263367Semastevoid 1039263363SemasteTarget::SetExecutableModule (ModuleSP& executable_sp, bool get_dependent_files) 1040263363Semaste{ 1041263363Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET)); 1042263367Semaste ClearModules(false); 1043254721Semaste 1044254721Semaste if (executable_sp.get()) 1045254721Semaste { 1046254721Semaste Timer scoped_timer (__PRETTY_FUNCTION__, 1047254721Semaste "Target::SetExecutableModule (executable = '%s')", 1048254721Semaste executable_sp->GetFileSpec().GetPath().c_str()); 1049254721Semaste 1050254721Semaste m_images.Append(executable_sp); // The first image is our exectuable file 1051254721Semaste 1052254721Semaste // If we haven't set an architecture yet, reset our architecture based on what we found in the executable module. 1053254721Semaste if (!m_arch.IsValid()) 1054254721Semaste { 1055254721Semaste m_arch = executable_sp->GetArchitecture(); 1056254721Semaste if (log) 1057254721Semaste log->Printf ("Target::SetExecutableModule setting architecture to %s (%s) based on executable file", m_arch.GetArchitectureName(), m_arch.GetTriple().getTriple().c_str()); 1058254721Semaste } 1059254721Semaste 1060254721Semaste FileSpecList dependent_files; 1061254721Semaste ObjectFile *executable_objfile = executable_sp->GetObjectFile(); 1062254721Semaste 1063254721Semaste if (executable_objfile && get_dependent_files) 1064254721Semaste { 1065254721Semaste executable_objfile->GetDependentModules(dependent_files); 1066254721Semaste for (uint32_t i=0; i<dependent_files.GetSize(); i++) 1067254721Semaste { 1068254721Semaste FileSpec dependent_file_spec (dependent_files.GetFileSpecPointerAtIndex(i)); 1069254721Semaste FileSpec platform_dependent_file_spec; 1070254721Semaste if (m_platform_sp) 1071269024Semaste m_platform_sp->GetFileWithUUID (dependent_file_spec, NULL, platform_dependent_file_spec); 1072254721Semaste else 1073254721Semaste platform_dependent_file_spec = dependent_file_spec; 1074254721Semaste 1075254721Semaste ModuleSpec module_spec (platform_dependent_file_spec, m_arch); 1076254721Semaste ModuleSP image_module_sp(GetSharedModule (module_spec)); 1077254721Semaste if (image_module_sp.get()) 1078254721Semaste { 1079254721Semaste ObjectFile *objfile = image_module_sp->GetObjectFile(); 1080254721Semaste if (objfile) 1081254721Semaste objfile->GetDependentModules(dependent_files); 1082254721Semaste } 1083254721Semaste } 1084254721Semaste } 1085254721Semaste } 1086254721Semaste} 1087254721Semaste 1088254721Semaste 1089254721Semastebool 1090254721SemasteTarget::SetArchitecture (const ArchSpec &arch_spec) 1091254721Semaste{ 1092254721Semaste Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TARGET)); 1093254721Semaste if (m_arch.IsCompatibleMatch(arch_spec) || !m_arch.IsValid()) 1094254721Semaste { 1095254721Semaste // If we haven't got a valid arch spec, or the architectures are 1096254721Semaste // compatible, so just update the architecture. Architectures can be 1097254721Semaste // equal, yet the triple OS and vendor might change, so we need to do 1098254721Semaste // the assignment here just in case. 1099254721Semaste m_arch = arch_spec; 1100254721Semaste if (log) 1101254721Semaste log->Printf ("Target::SetArchitecture setting architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str()); 1102254721Semaste return true; 1103254721Semaste } 1104254721Semaste else 1105254721Semaste { 1106254721Semaste // If we have an executable file, try to reset the executable to the desired architecture 1107254721Semaste if (log) 1108254721Semaste log->Printf ("Target::SetArchitecture changing architecture to %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str()); 1109254721Semaste m_arch = arch_spec; 1110254721Semaste ModuleSP executable_sp = GetExecutableModule (); 1111263363Semaste 1112263367Semaste ClearModules(true); 1113254721Semaste // Need to do something about unsetting breakpoints. 1114254721Semaste 1115254721Semaste if (executable_sp) 1116254721Semaste { 1117254721Semaste if (log) 1118254721Semaste log->Printf("Target::SetArchitecture Trying to select executable file architecture %s (%s)", arch_spec.GetArchitectureName(), arch_spec.GetTriple().getTriple().c_str()); 1119254721Semaste ModuleSpec module_spec (executable_sp->GetFileSpec(), arch_spec); 1120254721Semaste Error error = ModuleList::GetSharedModule (module_spec, 1121254721Semaste executable_sp, 1122254721Semaste &GetExecutableSearchPaths(), 1123254721Semaste NULL, 1124254721Semaste NULL); 1125254721Semaste 1126254721Semaste if (!error.Fail() && executable_sp) 1127254721Semaste { 1128254721Semaste SetExecutableModule (executable_sp, true); 1129254721Semaste return true; 1130254721Semaste } 1131254721Semaste } 1132254721Semaste } 1133254721Semaste return false; 1134254721Semaste} 1135254721Semaste 1136254721Semastevoid 1137254721SemasteTarget::WillClearList (const ModuleList& module_list) 1138254721Semaste{ 1139254721Semaste} 1140254721Semaste 1141254721Semastevoid 1142254721SemasteTarget::ModuleAdded (const ModuleList& module_list, const ModuleSP &module_sp) 1143254721Semaste{ 1144254721Semaste // A module is being added to this target for the first time 1145254721Semaste ModuleList my_module_list; 1146254721Semaste my_module_list.Append(module_sp); 1147254721Semaste LoadScriptingResourceForModule(module_sp, this); 1148254721Semaste ModulesDidLoad (my_module_list); 1149254721Semaste} 1150254721Semaste 1151254721Semastevoid 1152254721SemasteTarget::ModuleRemoved (const ModuleList& module_list, const ModuleSP &module_sp) 1153254721Semaste{ 1154254721Semaste // A module is being added to this target for the first time 1155254721Semaste ModuleList my_module_list; 1156254721Semaste my_module_list.Append(module_sp); 1157263363Semaste ModulesDidUnload (my_module_list, false); 1158254721Semaste} 1159254721Semaste 1160254721Semastevoid 1161254721SemasteTarget::ModuleUpdated (const ModuleList& module_list, const ModuleSP &old_module_sp, const ModuleSP &new_module_sp) 1162254721Semaste{ 1163254721Semaste // A module is replacing an already added module 1164254721Semaste m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, new_module_sp); 1165254721Semaste} 1166254721Semaste 1167254721Semastevoid 1168254721SemasteTarget::ModulesDidLoad (ModuleList &module_list) 1169254721Semaste{ 1170254721Semaste if (module_list.GetSize()) 1171254721Semaste { 1172263363Semaste m_breakpoint_list.UpdateBreakpoints (module_list, true, false); 1173263363Semaste if (m_process_sp) 1174263363Semaste { 1175263363Semaste SystemRuntime *sys_runtime = m_process_sp->GetSystemRuntime(); 1176263363Semaste if (sys_runtime) 1177263363Semaste { 1178263363Semaste sys_runtime->ModulesDidLoad (module_list); 1179263363Semaste } 1180263363Semaste } 1181254721Semaste // TODO: make event data that packages up the module_list 1182254721Semaste BroadcastEvent (eBroadcastBitModulesLoaded, NULL); 1183254721Semaste } 1184254721Semaste} 1185254721Semaste 1186254721Semastevoid 1187254721SemasteTarget::SymbolsDidLoad (ModuleList &module_list) 1188254721Semaste{ 1189254721Semaste if (module_list.GetSize()) 1190254721Semaste { 1191254721Semaste if (m_process_sp) 1192254721Semaste { 1193254721Semaste LanguageRuntime* runtime = m_process_sp->GetLanguageRuntime(lldb::eLanguageTypeObjC); 1194254721Semaste if (runtime) 1195254721Semaste { 1196254721Semaste ObjCLanguageRuntime *objc_runtime = (ObjCLanguageRuntime*)runtime; 1197254721Semaste objc_runtime->SymbolsDidLoad(module_list); 1198254721Semaste } 1199254721Semaste } 1200254721Semaste 1201263363Semaste m_breakpoint_list.UpdateBreakpoints (module_list, true, false); 1202254721Semaste BroadcastEvent(eBroadcastBitSymbolsLoaded, NULL); 1203254721Semaste } 1204254721Semaste} 1205254721Semaste 1206254721Semastevoid 1207263363SemasteTarget::ModulesDidUnload (ModuleList &module_list, bool delete_locations) 1208254721Semaste{ 1209254721Semaste if (module_list.GetSize()) 1210254721Semaste { 1211263363Semaste m_breakpoint_list.UpdateBreakpoints (module_list, false, delete_locations); 1212254721Semaste // TODO: make event data that packages up the module_list 1213254721Semaste BroadcastEvent (eBroadcastBitModulesUnloaded, NULL); 1214254721Semaste } 1215254721Semaste} 1216254721Semaste 1217254721Semastebool 1218254721SemasteTarget::ModuleIsExcludedForNonModuleSpecificSearches (const FileSpec &module_file_spec) 1219254721Semaste{ 1220254721Semaste if (GetBreakpointsConsultPlatformAvoidList()) 1221254721Semaste { 1222254721Semaste ModuleList matchingModules; 1223254721Semaste ModuleSpec module_spec (module_file_spec); 1224254721Semaste size_t num_modules = GetImages().FindModules(module_spec, matchingModules); 1225254721Semaste 1226254721Semaste // If there is more than one module for this file spec, only return true if ALL the modules are on the 1227254721Semaste // black list. 1228254721Semaste if (num_modules > 0) 1229254721Semaste { 1230254721Semaste for (size_t i = 0; i < num_modules; i++) 1231254721Semaste { 1232254721Semaste if (!ModuleIsExcludedForNonModuleSpecificSearches (matchingModules.GetModuleAtIndex(i))) 1233254721Semaste return false; 1234254721Semaste } 1235254721Semaste return true; 1236254721Semaste } 1237254721Semaste } 1238254721Semaste return false; 1239254721Semaste} 1240254721Semaste 1241254721Semastebool 1242254721SemasteTarget::ModuleIsExcludedForNonModuleSpecificSearches (const lldb::ModuleSP &module_sp) 1243254721Semaste{ 1244254721Semaste if (GetBreakpointsConsultPlatformAvoidList()) 1245254721Semaste { 1246254721Semaste if (m_platform_sp) 1247254721Semaste return m_platform_sp->ModuleIsExcludedForNonModuleSpecificSearches (*this, module_sp); 1248254721Semaste } 1249254721Semaste return false; 1250254721Semaste} 1251254721Semaste 1252254721Semastesize_t 1253254721SemasteTarget::ReadMemoryFromFileCache (const Address& addr, void *dst, size_t dst_len, Error &error) 1254254721Semaste{ 1255254721Semaste SectionSP section_sp (addr.GetSection()); 1256254721Semaste if (section_sp) 1257254721Semaste { 1258254721Semaste // If the contents of this section are encrypted, the on-disk file is unusuable. Read only from live memory. 1259254721Semaste if (section_sp->IsEncrypted()) 1260254721Semaste { 1261254721Semaste error.SetErrorString("section is encrypted"); 1262254721Semaste return 0; 1263254721Semaste } 1264254721Semaste ModuleSP module_sp (section_sp->GetModule()); 1265254721Semaste if (module_sp) 1266254721Semaste { 1267254721Semaste ObjectFile *objfile = section_sp->GetModule()->GetObjectFile(); 1268254721Semaste if (objfile) 1269254721Semaste { 1270254721Semaste size_t bytes_read = objfile->ReadSectionData (section_sp.get(), 1271254721Semaste addr.GetOffset(), 1272254721Semaste dst, 1273254721Semaste dst_len); 1274254721Semaste if (bytes_read > 0) 1275254721Semaste return bytes_read; 1276254721Semaste else 1277254721Semaste error.SetErrorStringWithFormat("error reading data from section %s", section_sp->GetName().GetCString()); 1278254721Semaste } 1279254721Semaste else 1280254721Semaste error.SetErrorString("address isn't from a object file"); 1281254721Semaste } 1282254721Semaste else 1283254721Semaste error.SetErrorString("address isn't in a module"); 1284254721Semaste } 1285254721Semaste else 1286254721Semaste error.SetErrorString("address doesn't contain a section that points to a section in a object file"); 1287254721Semaste 1288254721Semaste return 0; 1289254721Semaste} 1290254721Semaste 1291254721Semastesize_t 1292254721SemasteTarget::ReadMemory (const Address& addr, 1293254721Semaste bool prefer_file_cache, 1294254721Semaste void *dst, 1295254721Semaste size_t dst_len, 1296254721Semaste Error &error, 1297254721Semaste lldb::addr_t *load_addr_ptr) 1298254721Semaste{ 1299254721Semaste error.Clear(); 1300254721Semaste 1301254721Semaste // if we end up reading this from process memory, we will fill this 1302254721Semaste // with the actual load address 1303254721Semaste if (load_addr_ptr) 1304254721Semaste *load_addr_ptr = LLDB_INVALID_ADDRESS; 1305254721Semaste 1306254721Semaste size_t bytes_read = 0; 1307254721Semaste 1308254721Semaste addr_t load_addr = LLDB_INVALID_ADDRESS; 1309254721Semaste addr_t file_addr = LLDB_INVALID_ADDRESS; 1310254721Semaste Address resolved_addr; 1311254721Semaste if (!addr.IsSectionOffset()) 1312254721Semaste { 1313269024Semaste SectionLoadList §ion_load_list = GetSectionLoadList(); 1314269024Semaste if (section_load_list.IsEmpty()) 1315254721Semaste { 1316254721Semaste // No sections are loaded, so we must assume we are not running 1317254721Semaste // yet and anything we are given is a file address. 1318254721Semaste file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the file address 1319254721Semaste m_images.ResolveFileAddress (file_addr, resolved_addr); 1320254721Semaste } 1321254721Semaste else 1322254721Semaste { 1323254721Semaste // We have at least one section loaded. This can be becuase 1324254721Semaste // we have manually loaded some sections with "target modules load ..." 1325254721Semaste // or because we have have a live process that has sections loaded 1326254721Semaste // through the dynamic loader 1327254721Semaste load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its offset is the load address 1328269024Semaste section_load_list.ResolveLoadAddress (load_addr, resolved_addr); 1329254721Semaste } 1330254721Semaste } 1331254721Semaste if (!resolved_addr.IsValid()) 1332254721Semaste resolved_addr = addr; 1333254721Semaste 1334254721Semaste 1335254721Semaste if (prefer_file_cache) 1336254721Semaste { 1337254721Semaste bytes_read = ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); 1338254721Semaste if (bytes_read > 0) 1339254721Semaste return bytes_read; 1340254721Semaste } 1341254721Semaste 1342254721Semaste if (ProcessIsValid()) 1343254721Semaste { 1344254721Semaste if (load_addr == LLDB_INVALID_ADDRESS) 1345254721Semaste load_addr = resolved_addr.GetLoadAddress (this); 1346254721Semaste 1347254721Semaste if (load_addr == LLDB_INVALID_ADDRESS) 1348254721Semaste { 1349254721Semaste ModuleSP addr_module_sp (resolved_addr.GetModule()); 1350254721Semaste if (addr_module_sp && addr_module_sp->GetFileSpec()) 1351254721Semaste error.SetErrorStringWithFormat("%s[0x%" PRIx64 "] can't be resolved, %s in not currently loaded", 1352254721Semaste addr_module_sp->GetFileSpec().GetFilename().AsCString(), 1353254721Semaste resolved_addr.GetFileAddress(), 1354254721Semaste addr_module_sp->GetFileSpec().GetFilename().AsCString()); 1355254721Semaste else 1356254721Semaste error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", resolved_addr.GetFileAddress()); 1357254721Semaste } 1358254721Semaste else 1359254721Semaste { 1360254721Semaste bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); 1361254721Semaste if (bytes_read != dst_len) 1362254721Semaste { 1363254721Semaste if (error.Success()) 1364254721Semaste { 1365254721Semaste if (bytes_read == 0) 1366254721Semaste error.SetErrorStringWithFormat("read memory from 0x%" PRIx64 " failed", load_addr); 1367254721Semaste else 1368254721Semaste error.SetErrorStringWithFormat("only %" PRIu64 " of %" PRIu64 " bytes were read from memory at 0x%" PRIx64, (uint64_t)bytes_read, (uint64_t)dst_len, load_addr); 1369254721Semaste } 1370254721Semaste } 1371254721Semaste if (bytes_read) 1372254721Semaste { 1373254721Semaste if (load_addr_ptr) 1374254721Semaste *load_addr_ptr = load_addr; 1375254721Semaste return bytes_read; 1376254721Semaste } 1377254721Semaste // If the address is not section offset we have an address that 1378254721Semaste // doesn't resolve to any address in any currently loaded shared 1379254721Semaste // libaries and we failed to read memory so there isn't anything 1380254721Semaste // more we can do. If it is section offset, we might be able to 1381254721Semaste // read cached memory from the object file. 1382254721Semaste if (!resolved_addr.IsSectionOffset()) 1383254721Semaste return 0; 1384254721Semaste } 1385254721Semaste } 1386254721Semaste 1387254721Semaste if (!prefer_file_cache && resolved_addr.IsSectionOffset()) 1388254721Semaste { 1389254721Semaste // If we didn't already try and read from the object file cache, then 1390254721Semaste // try it after failing to read from the process. 1391254721Semaste return ReadMemoryFromFileCache (resolved_addr, dst, dst_len, error); 1392254721Semaste } 1393254721Semaste return 0; 1394254721Semaste} 1395254721Semaste 1396254721Semastesize_t 1397254721SemasteTarget::ReadCStringFromMemory (const Address& addr, std::string &out_str, Error &error) 1398254721Semaste{ 1399254721Semaste char buf[256]; 1400254721Semaste out_str.clear(); 1401254721Semaste addr_t curr_addr = addr.GetLoadAddress(this); 1402254721Semaste Address address(addr); 1403254721Semaste while (1) 1404254721Semaste { 1405254721Semaste size_t length = ReadCStringFromMemory (address, buf, sizeof(buf), error); 1406254721Semaste if (length == 0) 1407254721Semaste break; 1408254721Semaste out_str.append(buf, length); 1409254721Semaste // If we got "length - 1" bytes, we didn't get the whole C string, we 1410254721Semaste // need to read some more characters 1411254721Semaste if (length == sizeof(buf) - 1) 1412254721Semaste curr_addr += length; 1413254721Semaste else 1414254721Semaste break; 1415254721Semaste address = Address(curr_addr); 1416254721Semaste } 1417254721Semaste return out_str.size(); 1418254721Semaste} 1419254721Semaste 1420254721Semaste 1421254721Semastesize_t 1422254721SemasteTarget::ReadCStringFromMemory (const Address& addr, char *dst, size_t dst_max_len, Error &result_error) 1423254721Semaste{ 1424254721Semaste size_t total_cstr_len = 0; 1425254721Semaste if (dst && dst_max_len) 1426254721Semaste { 1427254721Semaste result_error.Clear(); 1428254721Semaste // NULL out everything just to be safe 1429254721Semaste memset (dst, 0, dst_max_len); 1430254721Semaste Error error; 1431254721Semaste addr_t curr_addr = addr.GetLoadAddress(this); 1432254721Semaste Address address(addr); 1433254721Semaste const size_t cache_line_size = 512; 1434254721Semaste size_t bytes_left = dst_max_len - 1; 1435254721Semaste char *curr_dst = dst; 1436254721Semaste 1437254721Semaste while (bytes_left > 0) 1438254721Semaste { 1439254721Semaste addr_t cache_line_bytes_left = cache_line_size - (curr_addr % cache_line_size); 1440254721Semaste addr_t bytes_to_read = std::min<addr_t>(bytes_left, cache_line_bytes_left); 1441254721Semaste size_t bytes_read = ReadMemory (address, false, curr_dst, bytes_to_read, error); 1442254721Semaste 1443254721Semaste if (bytes_read == 0) 1444254721Semaste { 1445254721Semaste result_error = error; 1446254721Semaste dst[total_cstr_len] = '\0'; 1447254721Semaste break; 1448254721Semaste } 1449254721Semaste const size_t len = strlen(curr_dst); 1450254721Semaste 1451254721Semaste total_cstr_len += len; 1452254721Semaste 1453254721Semaste if (len < bytes_to_read) 1454254721Semaste break; 1455254721Semaste 1456254721Semaste curr_dst += bytes_read; 1457254721Semaste curr_addr += bytes_read; 1458254721Semaste bytes_left -= bytes_read; 1459254721Semaste address = Address(curr_addr); 1460254721Semaste } 1461254721Semaste } 1462254721Semaste else 1463254721Semaste { 1464254721Semaste if (dst == NULL) 1465254721Semaste result_error.SetErrorString("invalid arguments"); 1466254721Semaste else 1467254721Semaste result_error.Clear(); 1468254721Semaste } 1469254721Semaste return total_cstr_len; 1470254721Semaste} 1471254721Semaste 1472254721Semastesize_t 1473254721SemasteTarget::ReadScalarIntegerFromMemory (const Address& addr, 1474254721Semaste bool prefer_file_cache, 1475254721Semaste uint32_t byte_size, 1476254721Semaste bool is_signed, 1477254721Semaste Scalar &scalar, 1478254721Semaste Error &error) 1479254721Semaste{ 1480254721Semaste uint64_t uval; 1481254721Semaste 1482254721Semaste if (byte_size <= sizeof(uval)) 1483254721Semaste { 1484254721Semaste size_t bytes_read = ReadMemory (addr, prefer_file_cache, &uval, byte_size, error); 1485254721Semaste if (bytes_read == byte_size) 1486254721Semaste { 1487254721Semaste DataExtractor data (&uval, sizeof(uval), m_arch.GetByteOrder(), m_arch.GetAddressByteSize()); 1488254721Semaste lldb::offset_t offset = 0; 1489254721Semaste if (byte_size <= 4) 1490254721Semaste scalar = data.GetMaxU32 (&offset, byte_size); 1491254721Semaste else 1492254721Semaste scalar = data.GetMaxU64 (&offset, byte_size); 1493254721Semaste 1494254721Semaste if (is_signed) 1495254721Semaste scalar.SignExtend(byte_size * 8); 1496254721Semaste return bytes_read; 1497254721Semaste } 1498254721Semaste } 1499254721Semaste else 1500254721Semaste { 1501254721Semaste error.SetErrorStringWithFormat ("byte size of %u is too large for integer scalar type", byte_size); 1502254721Semaste } 1503254721Semaste return 0; 1504254721Semaste} 1505254721Semaste 1506254721Semasteuint64_t 1507254721SemasteTarget::ReadUnsignedIntegerFromMemory (const Address& addr, 1508254721Semaste bool prefer_file_cache, 1509254721Semaste size_t integer_byte_size, 1510254721Semaste uint64_t fail_value, 1511254721Semaste Error &error) 1512254721Semaste{ 1513254721Semaste Scalar scalar; 1514254721Semaste if (ReadScalarIntegerFromMemory (addr, 1515254721Semaste prefer_file_cache, 1516254721Semaste integer_byte_size, 1517254721Semaste false, 1518254721Semaste scalar, 1519254721Semaste error)) 1520254721Semaste return scalar.ULongLong(fail_value); 1521254721Semaste return fail_value; 1522254721Semaste} 1523254721Semaste 1524254721Semastebool 1525254721SemasteTarget::ReadPointerFromMemory (const Address& addr, 1526254721Semaste bool prefer_file_cache, 1527254721Semaste Error &error, 1528254721Semaste Address &pointer_addr) 1529254721Semaste{ 1530254721Semaste Scalar scalar; 1531254721Semaste if (ReadScalarIntegerFromMemory (addr, 1532254721Semaste prefer_file_cache, 1533254721Semaste m_arch.GetAddressByteSize(), 1534254721Semaste false, 1535254721Semaste scalar, 1536254721Semaste error)) 1537254721Semaste { 1538254721Semaste addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS); 1539254721Semaste if (pointer_vm_addr != LLDB_INVALID_ADDRESS) 1540254721Semaste { 1541269024Semaste SectionLoadList §ion_load_list = GetSectionLoadList(); 1542269024Semaste if (section_load_list.IsEmpty()) 1543254721Semaste { 1544254721Semaste // No sections are loaded, so we must assume we are not running 1545254721Semaste // yet and anything we are given is a file address. 1546254721Semaste m_images.ResolveFileAddress (pointer_vm_addr, pointer_addr); 1547254721Semaste } 1548254721Semaste else 1549254721Semaste { 1550254721Semaste // We have at least one section loaded. This can be becuase 1551254721Semaste // we have manually loaded some sections with "target modules load ..." 1552254721Semaste // or because we have have a live process that has sections loaded 1553254721Semaste // through the dynamic loader 1554269024Semaste section_load_list.ResolveLoadAddress (pointer_vm_addr, pointer_addr); 1555254721Semaste } 1556254721Semaste // We weren't able to resolve the pointer value, so just return 1557254721Semaste // an address with no section 1558254721Semaste if (!pointer_addr.IsValid()) 1559254721Semaste pointer_addr.SetOffset (pointer_vm_addr); 1560254721Semaste return true; 1561254721Semaste 1562254721Semaste } 1563254721Semaste } 1564254721Semaste return false; 1565254721Semaste} 1566254721Semaste 1567254721SemasteModuleSP 1568254721SemasteTarget::GetSharedModule (const ModuleSpec &module_spec, Error *error_ptr) 1569254721Semaste{ 1570254721Semaste ModuleSP module_sp; 1571254721Semaste 1572254721Semaste Error error; 1573254721Semaste 1574254721Semaste // First see if we already have this module in our module list. If we do, then we're done, we don't need 1575254721Semaste // to consult the shared modules list. But only do this if we are passed a UUID. 1576254721Semaste 1577254721Semaste if (module_spec.GetUUID().IsValid()) 1578254721Semaste module_sp = m_images.FindFirstModule(module_spec); 1579254721Semaste 1580254721Semaste if (!module_sp) 1581254721Semaste { 1582254721Semaste ModuleSP old_module_sp; // This will get filled in if we have a new version of the library 1583254721Semaste bool did_create_module = false; 1584254721Semaste 1585254721Semaste // If there are image search path entries, try to use them first to acquire a suitable image. 1586254721Semaste if (m_image_search_paths.GetSize()) 1587254721Semaste { 1588254721Semaste ModuleSpec transformed_spec (module_spec); 1589254721Semaste if (m_image_search_paths.RemapPath (module_spec.GetFileSpec().GetDirectory(), transformed_spec.GetFileSpec().GetDirectory())) 1590254721Semaste { 1591254721Semaste transformed_spec.GetFileSpec().GetFilename() = module_spec.GetFileSpec().GetFilename(); 1592254721Semaste error = ModuleList::GetSharedModule (transformed_spec, 1593254721Semaste module_sp, 1594254721Semaste &GetExecutableSearchPaths(), 1595254721Semaste &old_module_sp, 1596254721Semaste &did_create_module); 1597254721Semaste } 1598254721Semaste } 1599254721Semaste 1600254721Semaste if (!module_sp) 1601254721Semaste { 1602254721Semaste // If we have a UUID, we can check our global shared module list in case 1603254721Semaste // we already have it. If we don't have a valid UUID, then we can't since 1604254721Semaste // the path in "module_spec" will be a platform path, and we will need to 1605254721Semaste // let the platform find that file. For example, we could be asking for 1606254721Semaste // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick 1607254721Semaste // the local copy of "/usr/lib/dyld" since our platform could be a remote 1608254721Semaste // platform that has its own "/usr/lib/dyld" in an SDK or in a local file 1609254721Semaste // cache. 1610254721Semaste if (module_spec.GetUUID().IsValid()) 1611254721Semaste { 1612254721Semaste // We have a UUID, it is OK to check the global module list... 1613254721Semaste error = ModuleList::GetSharedModule (module_spec, 1614254721Semaste module_sp, 1615254721Semaste &GetExecutableSearchPaths(), 1616254721Semaste &old_module_sp, 1617254721Semaste &did_create_module); 1618254721Semaste } 1619254721Semaste 1620254721Semaste if (!module_sp) 1621254721Semaste { 1622254721Semaste // The platform is responsible for finding and caching an appropriate 1623254721Semaste // module in the shared module cache. 1624254721Semaste if (m_platform_sp) 1625254721Semaste { 1626254721Semaste FileSpec platform_file_spec; 1627254721Semaste error = m_platform_sp->GetSharedModule (module_spec, 1628254721Semaste module_sp, 1629254721Semaste &GetExecutableSearchPaths(), 1630254721Semaste &old_module_sp, 1631254721Semaste &did_create_module); 1632254721Semaste } 1633254721Semaste else 1634254721Semaste { 1635254721Semaste error.SetErrorString("no platform is currently set"); 1636254721Semaste } 1637254721Semaste } 1638254721Semaste } 1639254721Semaste 1640254721Semaste // We found a module that wasn't in our target list. Let's make sure that there wasn't an equivalent 1641254721Semaste // module in the list already, and if there was, let's remove it. 1642254721Semaste if (module_sp) 1643254721Semaste { 1644254721Semaste ObjectFile *objfile = module_sp->GetObjectFile(); 1645254721Semaste if (objfile) 1646254721Semaste { 1647254721Semaste switch (objfile->GetType()) 1648254721Semaste { 1649254721Semaste case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of a program's execution state 1650254721Semaste case ObjectFile::eTypeExecutable: /// A normal executable 1651254721Semaste case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker executable 1652254721Semaste case ObjectFile::eTypeObjectFile: /// An intermediate object file 1653254721Semaste case ObjectFile::eTypeSharedLibrary: /// A shared library that can be used during execution 1654254721Semaste break; 1655254721Semaste case ObjectFile::eTypeDebugInfo: /// An object file that contains only debug information 1656254721Semaste if (error_ptr) 1657254721Semaste error_ptr->SetErrorString("debug info files aren't valid target modules, please specify an executable"); 1658254721Semaste return ModuleSP(); 1659254721Semaste case ObjectFile::eTypeStubLibrary: /// A library that can be linked against but not used for execution 1660254721Semaste if (error_ptr) 1661254721Semaste error_ptr->SetErrorString("stub libraries aren't valid target modules, please specify an executable"); 1662254721Semaste return ModuleSP(); 1663254721Semaste default: 1664254721Semaste if (error_ptr) 1665254721Semaste error_ptr->SetErrorString("unsupported file type, please specify an executable"); 1666254721Semaste return ModuleSP(); 1667254721Semaste } 1668254721Semaste // GetSharedModule is not guaranteed to find the old shared module, for instance 1669254721Semaste // in the common case where you pass in the UUID, it is only going to find the one 1670254721Semaste // module matching the UUID. In fact, it has no good way to know what the "old module" 1671254721Semaste // relevant to this target is, since there might be many copies of a module with this file spec 1672254721Semaste // in various running debug sessions, but only one of them will belong to this target. 1673254721Semaste // So let's remove the UUID from the module list, and look in the target's module list. 1674254721Semaste // Only do this if there is SOMETHING else in the module spec... 1675254721Semaste if (!old_module_sp) 1676254721Semaste { 1677254721Semaste if (module_spec.GetUUID().IsValid() && !module_spec.GetFileSpec().GetFilename().IsEmpty() && !module_spec.GetFileSpec().GetDirectory().IsEmpty()) 1678254721Semaste { 1679254721Semaste ModuleSpec module_spec_copy(module_spec.GetFileSpec()); 1680254721Semaste module_spec_copy.GetUUID().Clear(); 1681254721Semaste 1682254721Semaste ModuleList found_modules; 1683254721Semaste size_t num_found = m_images.FindModules (module_spec_copy, found_modules); 1684254721Semaste if (num_found == 1) 1685254721Semaste { 1686254721Semaste old_module_sp = found_modules.GetModuleAtIndex(0); 1687254721Semaste } 1688254721Semaste } 1689254721Semaste } 1690254721Semaste 1691254721Semaste if (old_module_sp && m_images.GetIndexForModule (old_module_sp.get()) != LLDB_INVALID_INDEX32) 1692254721Semaste { 1693254721Semaste m_images.ReplaceModule(old_module_sp, module_sp); 1694254721Semaste Module *old_module_ptr = old_module_sp.get(); 1695254721Semaste old_module_sp.reset(); 1696254721Semaste ModuleList::RemoveSharedModuleIfOrphaned (old_module_ptr); 1697254721Semaste } 1698254721Semaste else 1699254721Semaste m_images.Append(module_sp); 1700254721Semaste } 1701254721Semaste } 1702254721Semaste } 1703254721Semaste if (error_ptr) 1704254721Semaste *error_ptr = error; 1705254721Semaste return module_sp; 1706254721Semaste} 1707254721Semaste 1708254721Semaste 1709254721SemasteTargetSP 1710254721SemasteTarget::CalculateTarget () 1711254721Semaste{ 1712254721Semaste return shared_from_this(); 1713254721Semaste} 1714254721Semaste 1715254721SemasteProcessSP 1716254721SemasteTarget::CalculateProcess () 1717254721Semaste{ 1718254721Semaste return ProcessSP(); 1719254721Semaste} 1720254721Semaste 1721254721SemasteThreadSP 1722254721SemasteTarget::CalculateThread () 1723254721Semaste{ 1724254721Semaste return ThreadSP(); 1725254721Semaste} 1726254721Semaste 1727254721SemasteStackFrameSP 1728254721SemasteTarget::CalculateStackFrame () 1729254721Semaste{ 1730254721Semaste return StackFrameSP(); 1731254721Semaste} 1732254721Semaste 1733254721Semastevoid 1734254721SemasteTarget::CalculateExecutionContext (ExecutionContext &exe_ctx) 1735254721Semaste{ 1736254721Semaste exe_ctx.Clear(); 1737254721Semaste exe_ctx.SetTargetPtr(this); 1738254721Semaste} 1739254721Semaste 1740254721SemastePathMappingList & 1741254721SemasteTarget::GetImageSearchPathList () 1742254721Semaste{ 1743254721Semaste return m_image_search_paths; 1744254721Semaste} 1745254721Semaste 1746254721Semastevoid 1747254721SemasteTarget::ImageSearchPathsChanged 1748254721Semaste( 1749254721Semaste const PathMappingList &path_list, 1750254721Semaste void *baton 1751254721Semaste) 1752254721Semaste{ 1753254721Semaste Target *target = (Target *)baton; 1754254721Semaste ModuleSP exe_module_sp (target->GetExecutableModule()); 1755254721Semaste if (exe_module_sp) 1756254721Semaste target->SetExecutableModule (exe_module_sp, true); 1757254721Semaste} 1758254721Semaste 1759254721SemasteClangASTContext * 1760254721SemasteTarget::GetScratchClangASTContext(bool create_on_demand) 1761254721Semaste{ 1762254721Semaste // Now see if we know the target triple, and if so, create our scratch AST context: 1763254721Semaste if (m_scratch_ast_context_ap.get() == NULL && m_arch.IsValid() && create_on_demand) 1764254721Semaste { 1765254721Semaste m_scratch_ast_context_ap.reset (new ClangASTContext(m_arch.GetTriple().str().c_str())); 1766254721Semaste m_scratch_ast_source_ap.reset (new ClangASTSource(shared_from_this())); 1767254721Semaste m_scratch_ast_source_ap->InstallASTContext(m_scratch_ast_context_ap->getASTContext()); 1768254721Semaste llvm::OwningPtr<clang::ExternalASTSource> proxy_ast_source(m_scratch_ast_source_ap->CreateProxy()); 1769254721Semaste m_scratch_ast_context_ap->SetExternalSource(proxy_ast_source); 1770254721Semaste } 1771254721Semaste return m_scratch_ast_context_ap.get(); 1772254721Semaste} 1773254721Semaste 1774254721SemasteClangASTImporter * 1775254721SemasteTarget::GetClangASTImporter() 1776254721Semaste{ 1777254721Semaste ClangASTImporter *ast_importer = m_ast_importer_ap.get(); 1778254721Semaste 1779254721Semaste if (!ast_importer) 1780254721Semaste { 1781254721Semaste ast_importer = new ClangASTImporter(); 1782254721Semaste m_ast_importer_ap.reset(ast_importer); 1783254721Semaste } 1784254721Semaste 1785254721Semaste return ast_importer; 1786254721Semaste} 1787254721Semaste 1788254721Semastevoid 1789254721SemasteTarget::SettingsInitialize () 1790254721Semaste{ 1791254721Semaste Process::SettingsInitialize (); 1792254721Semaste} 1793254721Semaste 1794254721Semastevoid 1795254721SemasteTarget::SettingsTerminate () 1796254721Semaste{ 1797254721Semaste Process::SettingsTerminate (); 1798254721Semaste} 1799254721Semaste 1800254721SemasteFileSpecList 1801254721SemasteTarget::GetDefaultExecutableSearchPaths () 1802254721Semaste{ 1803254721Semaste TargetPropertiesSP properties_sp(Target::GetGlobalProperties()); 1804254721Semaste if (properties_sp) 1805254721Semaste return properties_sp->GetExecutableSearchPaths(); 1806254721Semaste return FileSpecList(); 1807254721Semaste} 1808254721Semaste 1809254721SemasteFileSpecList 1810254721SemasteTarget::GetDefaultDebugFileSearchPaths () 1811254721Semaste{ 1812254721Semaste TargetPropertiesSP properties_sp(Target::GetGlobalProperties()); 1813254721Semaste if (properties_sp) 1814254721Semaste return properties_sp->GetDebugFileSearchPaths(); 1815254721Semaste return FileSpecList(); 1816254721Semaste} 1817254721Semaste 1818254721SemasteArchSpec 1819254721SemasteTarget::GetDefaultArchitecture () 1820254721Semaste{ 1821254721Semaste TargetPropertiesSP properties_sp(Target::GetGlobalProperties()); 1822254721Semaste if (properties_sp) 1823254721Semaste return properties_sp->GetDefaultArchitecture(); 1824254721Semaste return ArchSpec(); 1825254721Semaste} 1826254721Semaste 1827254721Semastevoid 1828254721SemasteTarget::SetDefaultArchitecture (const ArchSpec &arch) 1829254721Semaste{ 1830254721Semaste TargetPropertiesSP properties_sp(Target::GetGlobalProperties()); 1831254721Semaste if (properties_sp) 1832254721Semaste { 1833254721Semaste LogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET, "Target::SetDefaultArchitecture setting target's default architecture to %s (%s)", arch.GetArchitectureName(), arch.GetTriple().getTriple().c_str()); 1834254721Semaste return properties_sp->SetDefaultArchitecture(arch); 1835254721Semaste } 1836254721Semaste} 1837254721Semaste 1838254721SemasteTarget * 1839254721SemasteTarget::GetTargetFromContexts (const ExecutionContext *exe_ctx_ptr, const SymbolContext *sc_ptr) 1840254721Semaste{ 1841254721Semaste // The target can either exist in the "process" of ExecutionContext, or in 1842254721Semaste // the "target_sp" member of SymbolContext. This accessor helper function 1843254721Semaste // will get the target from one of these locations. 1844254721Semaste 1845254721Semaste Target *target = NULL; 1846254721Semaste if (sc_ptr != NULL) 1847254721Semaste target = sc_ptr->target_sp.get(); 1848254721Semaste if (target == NULL && exe_ctx_ptr) 1849254721Semaste target = exe_ctx_ptr->GetTargetPtr(); 1850254721Semaste return target; 1851254721Semaste} 1852254721Semaste 1853254721SemasteExecutionResults 1854254721SemasteTarget::EvaluateExpression 1855254721Semaste( 1856254721Semaste const char *expr_cstr, 1857254721Semaste StackFrame *frame, 1858254721Semaste lldb::ValueObjectSP &result_valobj_sp, 1859254721Semaste const EvaluateExpressionOptions& options 1860254721Semaste) 1861254721Semaste{ 1862254721Semaste result_valobj_sp.reset(); 1863254721Semaste 1864254721Semaste ExecutionResults execution_results = eExecutionSetupError; 1865254721Semaste 1866254721Semaste if (expr_cstr == NULL || expr_cstr[0] == '\0') 1867254721Semaste return execution_results; 1868254721Semaste 1869254721Semaste // We shouldn't run stop hooks in expressions. 1870254721Semaste // Be sure to reset this if you return anywhere within this function. 1871254721Semaste bool old_suppress_value = m_suppress_stop_hooks; 1872254721Semaste m_suppress_stop_hooks = true; 1873254721Semaste 1874254721Semaste ExecutionContext exe_ctx; 1875254721Semaste 1876254721Semaste if (frame) 1877254721Semaste { 1878254721Semaste frame->CalculateExecutionContext(exe_ctx); 1879254721Semaste } 1880254721Semaste else if (m_process_sp) 1881254721Semaste { 1882254721Semaste m_process_sp->CalculateExecutionContext(exe_ctx); 1883254721Semaste } 1884254721Semaste else 1885254721Semaste { 1886254721Semaste CalculateExecutionContext(exe_ctx); 1887254721Semaste } 1888254721Semaste 1889254721Semaste // Make sure we aren't just trying to see the value of a persistent 1890254721Semaste // variable (something like "$0") 1891254721Semaste lldb::ClangExpressionVariableSP persistent_var_sp; 1892254721Semaste // Only check for persistent variables the expression starts with a '$' 1893254721Semaste if (expr_cstr[0] == '$') 1894254721Semaste persistent_var_sp = m_persistent_variables.GetVariable (expr_cstr); 1895254721Semaste 1896254721Semaste if (persistent_var_sp) 1897254721Semaste { 1898254721Semaste result_valobj_sp = persistent_var_sp->GetValueObject (); 1899254721Semaste execution_results = eExecutionCompleted; 1900254721Semaste } 1901254721Semaste else 1902254721Semaste { 1903254721Semaste const char *prefix = GetExpressionPrefixContentsAsCString(); 1904263363Semaste Error error; 1905254721Semaste execution_results = ClangUserExpression::Evaluate (exe_ctx, 1906263363Semaste options, 1907263363Semaste expr_cstr, 1908254721Semaste prefix, 1909254721Semaste result_valobj_sp, 1910263363Semaste error); 1911254721Semaste } 1912254721Semaste 1913254721Semaste m_suppress_stop_hooks = old_suppress_value; 1914254721Semaste 1915254721Semaste return execution_results; 1916254721Semaste} 1917254721Semaste 1918254721Semastelldb::addr_t 1919254721SemasteTarget::GetCallableLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const 1920254721Semaste{ 1921254721Semaste addr_t code_addr = load_addr; 1922254721Semaste switch (m_arch.GetMachine()) 1923254721Semaste { 1924254721Semaste case llvm::Triple::arm: 1925254721Semaste case llvm::Triple::thumb: 1926254721Semaste switch (addr_class) 1927254721Semaste { 1928254721Semaste case eAddressClassData: 1929254721Semaste case eAddressClassDebug: 1930254721Semaste return LLDB_INVALID_ADDRESS; 1931254721Semaste 1932254721Semaste case eAddressClassUnknown: 1933254721Semaste case eAddressClassInvalid: 1934254721Semaste case eAddressClassCode: 1935254721Semaste case eAddressClassCodeAlternateISA: 1936254721Semaste case eAddressClassRuntime: 1937254721Semaste // Check if bit zero it no set? 1938254721Semaste if ((code_addr & 1ull) == 0) 1939254721Semaste { 1940254721Semaste // Bit zero isn't set, check if the address is a multiple of 2? 1941254721Semaste if (code_addr & 2ull) 1942254721Semaste { 1943254721Semaste // The address is a multiple of 2 so it must be thumb, set bit zero 1944254721Semaste code_addr |= 1ull; 1945254721Semaste } 1946254721Semaste else if (addr_class == eAddressClassCodeAlternateISA) 1947254721Semaste { 1948254721Semaste // We checked the address and the address claims to be the alternate ISA 1949254721Semaste // which means thumb, so set bit zero. 1950254721Semaste code_addr |= 1ull; 1951254721Semaste } 1952254721Semaste } 1953254721Semaste break; 1954254721Semaste } 1955254721Semaste break; 1956254721Semaste 1957254721Semaste default: 1958254721Semaste break; 1959254721Semaste } 1960254721Semaste return code_addr; 1961254721Semaste} 1962254721Semaste 1963254721Semastelldb::addr_t 1964254721SemasteTarget::GetOpcodeLoadAddress (lldb::addr_t load_addr, AddressClass addr_class) const 1965254721Semaste{ 1966254721Semaste addr_t opcode_addr = load_addr; 1967254721Semaste switch (m_arch.GetMachine()) 1968254721Semaste { 1969254721Semaste case llvm::Triple::arm: 1970254721Semaste case llvm::Triple::thumb: 1971254721Semaste switch (addr_class) 1972254721Semaste { 1973254721Semaste case eAddressClassData: 1974254721Semaste case eAddressClassDebug: 1975254721Semaste return LLDB_INVALID_ADDRESS; 1976254721Semaste 1977254721Semaste case eAddressClassInvalid: 1978254721Semaste case eAddressClassUnknown: 1979254721Semaste case eAddressClassCode: 1980254721Semaste case eAddressClassCodeAlternateISA: 1981254721Semaste case eAddressClassRuntime: 1982254721Semaste opcode_addr &= ~(1ull); 1983254721Semaste break; 1984254721Semaste } 1985254721Semaste break; 1986254721Semaste 1987254721Semaste default: 1988254721Semaste break; 1989254721Semaste } 1990254721Semaste return opcode_addr; 1991254721Semaste} 1992254721Semaste 1993254721SemasteSourceManager & 1994254721SemasteTarget::GetSourceManager () 1995254721Semaste{ 1996254721Semaste if (m_source_manager_ap.get() == NULL) 1997254721Semaste m_source_manager_ap.reset (new SourceManager(shared_from_this())); 1998254721Semaste return *m_source_manager_ap; 1999254721Semaste} 2000254721Semaste 2001254721Semaste 2002269024SemasteTarget::StopHookSP 2003269024SemasteTarget::CreateStopHook () 2004254721Semaste{ 2005254721Semaste lldb::user_id_t new_uid = ++m_stop_hook_next_id; 2006269024Semaste Target::StopHookSP stop_hook_sp (new StopHook(shared_from_this(), new_uid)); 2007269024Semaste m_stop_hooks[new_uid] = stop_hook_sp; 2008269024Semaste return stop_hook_sp; 2009254721Semaste} 2010254721Semaste 2011254721Semastebool 2012254721SemasteTarget::RemoveStopHookByID (lldb::user_id_t user_id) 2013254721Semaste{ 2014254721Semaste size_t num_removed; 2015254721Semaste num_removed = m_stop_hooks.erase (user_id); 2016254721Semaste if (num_removed == 0) 2017254721Semaste return false; 2018254721Semaste else 2019254721Semaste return true; 2020254721Semaste} 2021254721Semaste 2022254721Semastevoid 2023254721SemasteTarget::RemoveAllStopHooks () 2024254721Semaste{ 2025254721Semaste m_stop_hooks.clear(); 2026254721Semaste} 2027254721Semaste 2028254721SemasteTarget::StopHookSP 2029254721SemasteTarget::GetStopHookByID (lldb::user_id_t user_id) 2030254721Semaste{ 2031254721Semaste StopHookSP found_hook; 2032254721Semaste 2033254721Semaste StopHookCollection::iterator specified_hook_iter; 2034254721Semaste specified_hook_iter = m_stop_hooks.find (user_id); 2035254721Semaste if (specified_hook_iter != m_stop_hooks.end()) 2036254721Semaste found_hook = (*specified_hook_iter).second; 2037254721Semaste return found_hook; 2038254721Semaste} 2039254721Semaste 2040254721Semastebool 2041254721SemasteTarget::SetStopHookActiveStateByID (lldb::user_id_t user_id, bool active_state) 2042254721Semaste{ 2043254721Semaste StopHookCollection::iterator specified_hook_iter; 2044254721Semaste specified_hook_iter = m_stop_hooks.find (user_id); 2045254721Semaste if (specified_hook_iter == m_stop_hooks.end()) 2046254721Semaste return false; 2047254721Semaste 2048254721Semaste (*specified_hook_iter).second->SetIsActive (active_state); 2049254721Semaste return true; 2050254721Semaste} 2051254721Semaste 2052254721Semastevoid 2053254721SemasteTarget::SetAllStopHooksActiveState (bool active_state) 2054254721Semaste{ 2055254721Semaste StopHookCollection::iterator pos, end = m_stop_hooks.end(); 2056254721Semaste for (pos = m_stop_hooks.begin(); pos != end; pos++) 2057254721Semaste { 2058254721Semaste (*pos).second->SetIsActive (active_state); 2059254721Semaste } 2060254721Semaste} 2061254721Semaste 2062254721Semastevoid 2063254721SemasteTarget::RunStopHooks () 2064254721Semaste{ 2065254721Semaste if (m_suppress_stop_hooks) 2066254721Semaste return; 2067254721Semaste 2068254721Semaste if (!m_process_sp) 2069254721Semaste return; 2070254721Semaste 2071254721Semaste // <rdar://problem/12027563> make sure we check that we are not stopped because of us running a user expression 2072254721Semaste // since in that case we do not want to run the stop-hooks 2073254721Semaste if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression()) 2074254721Semaste return; 2075254721Semaste 2076254721Semaste if (m_stop_hooks.empty()) 2077254721Semaste return; 2078254721Semaste 2079254721Semaste StopHookCollection::iterator pos, end = m_stop_hooks.end(); 2080254721Semaste 2081254721Semaste // If there aren't any active stop hooks, don't bother either: 2082254721Semaste bool any_active_hooks = false; 2083254721Semaste for (pos = m_stop_hooks.begin(); pos != end; pos++) 2084254721Semaste { 2085254721Semaste if ((*pos).second->IsActive()) 2086254721Semaste { 2087254721Semaste any_active_hooks = true; 2088254721Semaste break; 2089254721Semaste } 2090254721Semaste } 2091254721Semaste if (!any_active_hooks) 2092254721Semaste return; 2093254721Semaste 2094254721Semaste CommandReturnObject result; 2095254721Semaste 2096254721Semaste std::vector<ExecutionContext> exc_ctx_with_reasons; 2097254721Semaste std::vector<SymbolContext> sym_ctx_with_reasons; 2098254721Semaste 2099254721Semaste ThreadList &cur_threadlist = m_process_sp->GetThreadList(); 2100254721Semaste size_t num_threads = cur_threadlist.GetSize(); 2101254721Semaste for (size_t i = 0; i < num_threads; i++) 2102254721Semaste { 2103254721Semaste lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex (i); 2104254721Semaste if (cur_thread_sp->ThreadStoppedForAReason()) 2105254721Semaste { 2106254721Semaste lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0); 2107254721Semaste exc_ctx_with_reasons.push_back(ExecutionContext(m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get())); 2108254721Semaste sym_ctx_with_reasons.push_back(cur_frame_sp->GetSymbolContext(eSymbolContextEverything)); 2109254721Semaste } 2110254721Semaste } 2111254721Semaste 2112254721Semaste // If no threads stopped for a reason, don't run the stop-hooks. 2113254721Semaste size_t num_exe_ctx = exc_ctx_with_reasons.size(); 2114254721Semaste if (num_exe_ctx == 0) 2115254721Semaste return; 2116254721Semaste 2117254721Semaste result.SetImmediateOutputStream (m_debugger.GetAsyncOutputStream()); 2118254721Semaste result.SetImmediateErrorStream (m_debugger.GetAsyncErrorStream()); 2119254721Semaste 2120254721Semaste bool keep_going = true; 2121254721Semaste bool hooks_ran = false; 2122254721Semaste bool print_hook_header; 2123254721Semaste bool print_thread_header; 2124254721Semaste 2125254721Semaste if (num_exe_ctx == 1) 2126254721Semaste print_thread_header = false; 2127254721Semaste else 2128254721Semaste print_thread_header = true; 2129254721Semaste 2130254721Semaste if (m_stop_hooks.size() == 1) 2131254721Semaste print_hook_header = false; 2132254721Semaste else 2133254721Semaste print_hook_header = true; 2134254721Semaste 2135254721Semaste for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++) 2136254721Semaste { 2137254721Semaste // result.Clear(); 2138254721Semaste StopHookSP cur_hook_sp = (*pos).second; 2139254721Semaste if (!cur_hook_sp->IsActive()) 2140254721Semaste continue; 2141254721Semaste 2142254721Semaste bool any_thread_matched = false; 2143254721Semaste for (size_t i = 0; keep_going && i < num_exe_ctx; i++) 2144254721Semaste { 2145254721Semaste if ((cur_hook_sp->GetSpecifier () == NULL 2146254721Semaste || cur_hook_sp->GetSpecifier()->SymbolContextMatches(sym_ctx_with_reasons[i])) 2147254721Semaste && (cur_hook_sp->GetThreadSpecifier() == NULL 2148254721Semaste || cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx_with_reasons[i].GetThreadRef()))) 2149254721Semaste { 2150254721Semaste if (!hooks_ran) 2151254721Semaste { 2152254721Semaste hooks_ran = true; 2153254721Semaste } 2154254721Semaste if (print_hook_header && !any_thread_matched) 2155254721Semaste { 2156254721Semaste const char *cmd = (cur_hook_sp->GetCommands().GetSize() == 1 ? 2157254721Semaste cur_hook_sp->GetCommands().GetStringAtIndex(0) : 2158254721Semaste NULL); 2159254721Semaste if (cmd) 2160254721Semaste result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(), cmd); 2161254721Semaste else 2162254721Semaste result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID()); 2163254721Semaste any_thread_matched = true; 2164254721Semaste } 2165254721Semaste 2166254721Semaste if (print_thread_header) 2167254721Semaste result.AppendMessageWithFormat("-- Thread %d\n", exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID()); 2168254721Semaste 2169254721Semaste bool stop_on_continue = true; 2170254721Semaste bool stop_on_error = true; 2171254721Semaste bool echo_commands = false; 2172254721Semaste bool print_results = true; 2173254721Semaste GetDebugger().GetCommandInterpreter().HandleCommands (cur_hook_sp->GetCommands(), 2174254721Semaste &exc_ctx_with_reasons[i], 2175254721Semaste stop_on_continue, 2176254721Semaste stop_on_error, 2177254721Semaste echo_commands, 2178254721Semaste print_results, 2179254721Semaste eLazyBoolNo, 2180254721Semaste result); 2181254721Semaste 2182254721Semaste // If the command started the target going again, we should bag out of 2183254721Semaste // running the stop hooks. 2184254721Semaste if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) || 2185254721Semaste (result.GetStatus() == eReturnStatusSuccessContinuingResult)) 2186254721Semaste { 2187254721Semaste result.AppendMessageWithFormat ("Aborting stop hooks, hook %" PRIu64 " set the program running.", cur_hook_sp->GetID()); 2188254721Semaste keep_going = false; 2189254721Semaste } 2190254721Semaste } 2191254721Semaste } 2192254721Semaste } 2193254721Semaste 2194254721Semaste result.GetImmediateOutputStream()->Flush(); 2195254721Semaste result.GetImmediateErrorStream()->Flush(); 2196254721Semaste} 2197254721Semaste 2198263367Semasteconst TargetPropertiesSP & 2199263367SemasteTarget::GetGlobalProperties() 2200263367Semaste{ 2201263367Semaste static TargetPropertiesSP g_settings_sp; 2202263367Semaste if (!g_settings_sp) 2203263367Semaste { 2204263367Semaste g_settings_sp.reset (new TargetProperties (NULL)); 2205263367Semaste } 2206263367Semaste return g_settings_sp; 2207263367Semaste} 2208254721Semaste 2209263367SemasteError 2210263367SemasteTarget::Install (ProcessLaunchInfo *launch_info) 2211263367Semaste{ 2212263367Semaste Error error; 2213263367Semaste PlatformSP platform_sp (GetPlatform()); 2214263367Semaste if (platform_sp) 2215263367Semaste { 2216263367Semaste if (platform_sp->IsRemote()) 2217263367Semaste { 2218263367Semaste if (platform_sp->IsConnected()) 2219263367Semaste { 2220263367Semaste // Install all files that have an install path, and always install the 2221263367Semaste // main executable when connected to a remote platform 2222263367Semaste const ModuleList& modules = GetImages(); 2223263367Semaste const size_t num_images = modules.GetSize(); 2224263367Semaste for (size_t idx = 0; idx < num_images; ++idx) 2225263367Semaste { 2226263367Semaste const bool is_main_executable = idx == 0; 2227263367Semaste ModuleSP module_sp(modules.GetModuleAtIndex(idx)); 2228263367Semaste if (module_sp) 2229263367Semaste { 2230263367Semaste FileSpec local_file (module_sp->GetFileSpec()); 2231263367Semaste if (local_file) 2232263367Semaste { 2233263367Semaste FileSpec remote_file (module_sp->GetRemoteInstallFileSpec()); 2234263367Semaste if (!remote_file) 2235263367Semaste { 2236263367Semaste if (is_main_executable) // TODO: add setting for always installing main executable??? 2237263367Semaste { 2238263367Semaste // Always install the main executable 2239263367Semaste remote_file.GetDirectory() = platform_sp->GetWorkingDirectory(); 2240263367Semaste remote_file.GetFilename() = module_sp->GetFileSpec().GetFilename(); 2241263367Semaste } 2242263367Semaste } 2243263367Semaste if (remote_file) 2244263367Semaste { 2245263367Semaste error = platform_sp->Install(local_file, remote_file); 2246263367Semaste if (error.Success()) 2247263367Semaste { 2248263367Semaste module_sp->SetPlatformFileSpec(remote_file); 2249263367Semaste if (is_main_executable) 2250263367Semaste { 2251263367Semaste if (launch_info) 2252263367Semaste launch_info->SetExecutableFile(remote_file, false); 2253263367Semaste } 2254263367Semaste } 2255263367Semaste else 2256263367Semaste break; 2257263367Semaste } 2258263367Semaste } 2259263367Semaste } 2260263367Semaste } 2261263367Semaste } 2262263367Semaste } 2263263367Semaste } 2264263367Semaste return error; 2265263367Semaste} 2266263367Semaste 2267269024Semastebool 2268269024SemasteTarget::ResolveLoadAddress (addr_t load_addr, Address &so_addr, uint32_t stop_id) 2269269024Semaste{ 2270269024Semaste return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr); 2271269024Semaste} 2272269024Semaste 2273269024Semastebool 2274269024SemasteTarget::SetSectionLoadAddress (const SectionSP §ion_sp, addr_t new_section_load_addr, bool warn_multiple) 2275269024Semaste{ 2276269024Semaste const addr_t old_section_load_addr = m_section_load_history.GetSectionLoadAddress (SectionLoadHistory::eStopIDNow, section_sp); 2277269024Semaste if (old_section_load_addr != new_section_load_addr) 2278269024Semaste { 2279269024Semaste uint32_t stop_id = 0; 2280269024Semaste ProcessSP process_sp(GetProcessSP()); 2281269024Semaste if (process_sp) 2282269024Semaste stop_id = process_sp->GetStopID(); 2283269024Semaste else 2284269024Semaste stop_id = m_section_load_history.GetLastStopID(); 2285269024Semaste if (m_section_load_history.SetSectionLoadAddress (stop_id, section_sp, new_section_load_addr, warn_multiple)) 2286269024Semaste return true; // Return true if the section load address was changed... 2287269024Semaste } 2288269024Semaste return false; // Return false to indicate nothing changed 2289269024Semaste 2290269024Semaste} 2291269024Semaste 2292269024Semastebool 2293269024SemasteTarget::SetSectionUnloaded (const lldb::SectionSP §ion_sp) 2294269024Semaste{ 2295269024Semaste uint32_t stop_id = 0; 2296269024Semaste ProcessSP process_sp(GetProcessSP()); 2297269024Semaste if (process_sp) 2298269024Semaste stop_id = process_sp->GetStopID(); 2299269024Semaste else 2300269024Semaste stop_id = m_section_load_history.GetLastStopID(); 2301269024Semaste return m_section_load_history.SetSectionUnloaded (stop_id, section_sp); 2302269024Semaste} 2303269024Semaste 2304269024Semastebool 2305269024SemasteTarget::SetSectionUnloaded (const lldb::SectionSP §ion_sp, addr_t load_addr) 2306269024Semaste{ 2307269024Semaste uint32_t stop_id = 0; 2308269024Semaste ProcessSP process_sp(GetProcessSP()); 2309269024Semaste if (process_sp) 2310269024Semaste stop_id = process_sp->GetStopID(); 2311269024Semaste else 2312269024Semaste stop_id = m_section_load_history.GetLastStopID(); 2313269024Semaste return m_section_load_history.SetSectionUnloaded (stop_id, section_sp, load_addr); 2314269024Semaste} 2315269024Semaste 2316269024Semastevoid 2317269024SemasteTarget::ClearAllLoadedSections () 2318269024Semaste{ 2319269024Semaste m_section_load_history.Clear(); 2320269024Semaste} 2321269024Semaste 2322269024Semaste 2323269024SemasteError 2324269024SemasteTarget::Launch (Listener &listener, ProcessLaunchInfo &launch_info) 2325269024Semaste{ 2326269024Semaste Error error; 2327269024Semaste 2328269024Semaste StateType state = eStateInvalid; 2329269024Semaste 2330269024Semaste // Scope to temporarily get the process state in case someone has manually 2331269024Semaste // remotely connected already to a process and we can skip the platform 2332269024Semaste // launching. 2333269024Semaste { 2334269024Semaste ProcessSP process_sp (GetProcessSP()); 2335269024Semaste 2336269024Semaste if (process_sp) 2337269024Semaste state = process_sp->GetState(); 2338269024Semaste } 2339269024Semaste 2340269024Semaste launch_info.GetFlags().Set (eLaunchFlagDebug); 2341269024Semaste 2342269024Semaste // Get the value of synchronous execution here. If you wait till after you have started to 2343269024Semaste // run, then you could have hit a breakpoint, whose command might switch the value, and 2344269024Semaste // then you'll pick up that incorrect value. 2345269024Semaste Debugger &debugger = GetDebugger(); 2346269024Semaste const bool synchronous_execution = debugger.GetCommandInterpreter().GetSynchronous (); 2347269024Semaste 2348269024Semaste PlatformSP platform_sp (GetPlatform()); 2349269024Semaste 2350269024Semaste // Finalize the file actions, and if none were given, default to opening 2351269024Semaste // up a pseudo terminal 2352269024Semaste const bool default_to_use_pty = platform_sp ? platform_sp->IsHost() : false; 2353269024Semaste launch_info.FinalizeFileActions (this, default_to_use_pty); 2354269024Semaste 2355269024Semaste if (state == eStateConnected) 2356269024Semaste { 2357269024Semaste if (launch_info.GetFlags().Test (eLaunchFlagLaunchInTTY)) 2358269024Semaste { 2359269024Semaste error.SetErrorString("can't launch in tty when launching through a remote connection"); 2360269024Semaste return error; 2361269024Semaste } 2362269024Semaste } 2363269024Semaste 2364269024Semaste if (!launch_info.GetArchitecture().IsValid()) 2365269024Semaste launch_info.GetArchitecture() = GetArchitecture(); 2366269024Semaste 2367269024Semaste if (state != eStateConnected && platform_sp && platform_sp->CanDebugProcess ()) 2368269024Semaste { 2369269024Semaste m_process_sp = GetPlatform()->DebugProcess (launch_info, 2370269024Semaste debugger, 2371269024Semaste this, 2372269024Semaste listener, 2373269024Semaste error); 2374269024Semaste } 2375269024Semaste else 2376269024Semaste { 2377269024Semaste if (state == eStateConnected) 2378269024Semaste { 2379269024Semaste assert(m_process_sp); 2380269024Semaste } 2381269024Semaste else 2382269024Semaste { 2383269024Semaste const char *plugin_name = launch_info.GetProcessPluginName(); 2384269024Semaste CreateProcess (listener, plugin_name, NULL); 2385269024Semaste } 2386269024Semaste 2387269024Semaste if (m_process_sp) 2388269024Semaste error = m_process_sp->Launch (launch_info); 2389269024Semaste } 2390269024Semaste 2391269024Semaste if (!m_process_sp) 2392269024Semaste { 2393269024Semaste if (error.Success()) 2394269024Semaste error.SetErrorString("failed to launch or debug process"); 2395269024Semaste return error; 2396269024Semaste } 2397269024Semaste 2398269024Semaste if (error.Success()) 2399269024Semaste { 2400269024Semaste if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry) == false) 2401269024Semaste { 2402269024Semaste ListenerSP hijack_listener_sp (launch_info.GetHijackListener()); 2403269024Semaste 2404269024Semaste StateType state = m_process_sp->WaitForProcessToStop (NULL, NULL, false, hijack_listener_sp.get()); 2405269024Semaste 2406269024Semaste if (state == eStateStopped) 2407269024Semaste { 2408269024Semaste if (!synchronous_execution) 2409269024Semaste m_process_sp->RestoreProcessEvents (); 2410269024Semaste 2411269024Semaste error = m_process_sp->PrivateResume(); 2412269024Semaste 2413269024Semaste if (error.Success()) 2414269024Semaste { 2415269024Semaste if (synchronous_execution) 2416269024Semaste { 2417269024Semaste state = m_process_sp->WaitForProcessToStop (NULL, NULL, true, hijack_listener_sp.get()); 2418269024Semaste const bool must_be_alive = false; // eStateExited is ok, so this must be false 2419269024Semaste if (!StateIsStoppedState(state, must_be_alive)) 2420269024Semaste { 2421269024Semaste error.SetErrorStringWithFormat("process isn't stopped: %s", StateAsCString(state)); 2422269024Semaste } 2423269024Semaste } 2424269024Semaste } 2425269024Semaste else 2426269024Semaste { 2427269024Semaste Error error2; 2428269024Semaste error2.SetErrorStringWithFormat("process resume at entry point failed: %s", error.AsCString()); 2429269024Semaste error = error2; 2430269024Semaste } 2431269024Semaste } 2432269024Semaste else 2433269024Semaste { 2434269024Semaste error.SetErrorStringWithFormat ("initial process state wasn't stopped: %s", StateAsCString(state)); 2435269024Semaste } 2436269024Semaste } 2437269024Semaste m_process_sp->RestoreProcessEvents (); 2438269024Semaste } 2439269024Semaste else 2440269024Semaste { 2441269024Semaste Error error2; 2442269024Semaste error2.SetErrorStringWithFormat ("process launch failed: %s", error.AsCString()); 2443269024Semaste error = error2; 2444269024Semaste } 2445269024Semaste return error; 2446269024Semaste} 2447254721Semaste//-------------------------------------------------------------- 2448263367Semaste// Target::StopHook 2449254721Semaste//-------------------------------------------------------------- 2450254721SemasteTarget::StopHook::StopHook (lldb::TargetSP target_sp, lldb::user_id_t uid) : 2451254721Semaste UserID (uid), 2452254721Semaste m_target_sp (target_sp), 2453254721Semaste m_commands (), 2454254721Semaste m_specifier_sp (), 2455254721Semaste m_thread_spec_ap(), 2456254721Semaste m_active (true) 2457254721Semaste{ 2458254721Semaste} 2459254721Semaste 2460254721SemasteTarget::StopHook::StopHook (const StopHook &rhs) : 2461254721Semaste UserID (rhs.GetID()), 2462254721Semaste m_target_sp (rhs.m_target_sp), 2463254721Semaste m_commands (rhs.m_commands), 2464254721Semaste m_specifier_sp (rhs.m_specifier_sp), 2465254721Semaste m_thread_spec_ap (), 2466254721Semaste m_active (rhs.m_active) 2467254721Semaste{ 2468254721Semaste if (rhs.m_thread_spec_ap.get() != NULL) 2469254721Semaste m_thread_spec_ap.reset (new ThreadSpec(*rhs.m_thread_spec_ap.get())); 2470254721Semaste} 2471254721Semaste 2472254721Semaste 2473254721SemasteTarget::StopHook::~StopHook () 2474254721Semaste{ 2475254721Semaste} 2476254721Semaste 2477254721Semastevoid 2478254721SemasteTarget::StopHook::SetThreadSpecifier (ThreadSpec *specifier) 2479254721Semaste{ 2480254721Semaste m_thread_spec_ap.reset (specifier); 2481254721Semaste} 2482254721Semaste 2483254721Semaste 2484254721Semastevoid 2485254721SemasteTarget::StopHook::GetDescription (Stream *s, lldb::DescriptionLevel level) const 2486254721Semaste{ 2487254721Semaste int indent_level = s->GetIndentLevel(); 2488254721Semaste 2489254721Semaste s->SetIndentLevel(indent_level + 2); 2490254721Semaste 2491254721Semaste s->Printf ("Hook: %" PRIu64 "\n", GetID()); 2492254721Semaste if (m_active) 2493254721Semaste s->Indent ("State: enabled\n"); 2494254721Semaste else 2495254721Semaste s->Indent ("State: disabled\n"); 2496254721Semaste 2497254721Semaste if (m_specifier_sp) 2498254721Semaste { 2499254721Semaste s->Indent(); 2500254721Semaste s->PutCString ("Specifier:\n"); 2501254721Semaste s->SetIndentLevel (indent_level + 4); 2502254721Semaste m_specifier_sp->GetDescription (s, level); 2503254721Semaste s->SetIndentLevel (indent_level + 2); 2504254721Semaste } 2505254721Semaste 2506254721Semaste if (m_thread_spec_ap.get() != NULL) 2507254721Semaste { 2508254721Semaste StreamString tmp; 2509254721Semaste s->Indent("Thread:\n"); 2510254721Semaste m_thread_spec_ap->GetDescription (&tmp, level); 2511254721Semaste s->SetIndentLevel (indent_level + 4); 2512254721Semaste s->Indent (tmp.GetData()); 2513254721Semaste s->PutCString ("\n"); 2514254721Semaste s->SetIndentLevel (indent_level + 2); 2515254721Semaste } 2516254721Semaste 2517254721Semaste s->Indent ("Commands: \n"); 2518254721Semaste s->SetIndentLevel (indent_level + 4); 2519254721Semaste uint32_t num_commands = m_commands.GetSize(); 2520254721Semaste for (uint32_t i = 0; i < num_commands; i++) 2521254721Semaste { 2522254721Semaste s->Indent(m_commands.GetStringAtIndex(i)); 2523254721Semaste s->PutCString ("\n"); 2524254721Semaste } 2525254721Semaste s->SetIndentLevel (indent_level); 2526254721Semaste} 2527254721Semaste 2528254721Semaste//-------------------------------------------------------------- 2529254721Semaste// class TargetProperties 2530254721Semaste//-------------------------------------------------------------- 2531254721Semaste 2532254721SemasteOptionEnumValueElement 2533254721Semastelldb_private::g_dynamic_value_types[] = 2534254721Semaste{ 2535254721Semaste { eNoDynamicValues, "no-dynamic-values", "Don't calculate the dynamic type of values"}, 2536254721Semaste { eDynamicCanRunTarget, "run-target", "Calculate the dynamic type of values even if you have to run the target."}, 2537254721Semaste { eDynamicDontRunTarget, "no-run-target", "Calculate the dynamic type of values, but don't run the target."}, 2538254721Semaste { 0, NULL, NULL } 2539254721Semaste}; 2540254721Semaste 2541254721Semastestatic OptionEnumValueElement 2542254721Semasteg_inline_breakpoint_enums[] = 2543254721Semaste{ 2544254721Semaste { eInlineBreakpointsNever, "never", "Never look for inline breakpoint locations (fastest). This setting should only be used if you know that no inlining occurs in your programs."}, 2545254721Semaste { eInlineBreakpointsHeaders, "headers", "Only check for inline breakpoint locations when setting breakpoints in header files, but not when setting breakpoint in implementation source files (default)."}, 2546254721Semaste { eInlineBreakpointsAlways, "always", "Always look for inline breakpoint locations when setting file and line breakpoints (slower but most accurate)."}, 2547254721Semaste { 0, NULL, NULL } 2548254721Semaste}; 2549254721Semaste 2550254721Semastetypedef enum x86DisassemblyFlavor 2551254721Semaste{ 2552254721Semaste eX86DisFlavorDefault, 2553254721Semaste eX86DisFlavorIntel, 2554254721Semaste eX86DisFlavorATT 2555254721Semaste} x86DisassemblyFlavor; 2556254721Semaste 2557254721Semastestatic OptionEnumValueElement 2558254721Semasteg_x86_dis_flavor_value_types[] = 2559254721Semaste{ 2560254721Semaste { eX86DisFlavorDefault, "default", "Disassembler default (currently att)."}, 2561254721Semaste { eX86DisFlavorIntel, "intel", "Intel disassembler flavor."}, 2562254721Semaste { eX86DisFlavorATT, "att", "AT&T disassembler flavor."}, 2563254721Semaste { 0, NULL, NULL } 2564254721Semaste}; 2565254721Semaste 2566254721Semastestatic OptionEnumValueElement 2567254721Semasteg_hex_immediate_style_values[] = 2568254721Semaste{ 2569254721Semaste { Disassembler::eHexStyleC, "c", "C-style (0xffff)."}, 2570254721Semaste { Disassembler::eHexStyleAsm, "asm", "Asm-style (0ffffh)."}, 2571254721Semaste { 0, NULL, NULL } 2572254721Semaste}; 2573254721Semaste 2574254721Semastestatic OptionEnumValueElement 2575254721Semasteg_load_script_from_sym_file_values[] = 2576254721Semaste{ 2577254721Semaste { eLoadScriptFromSymFileTrue, "true", "Load debug scripts inside symbol files"}, 2578254721Semaste { eLoadScriptFromSymFileFalse, "false", "Do not load debug scripts inside symbol files."}, 2579254721Semaste { eLoadScriptFromSymFileWarn, "warn", "Warn about debug scripts inside symbol files but do not load them."}, 2580254721Semaste { 0, NULL, NULL } 2581254721Semaste}; 2582254721Semaste 2583254721Semaste 2584254721Semastestatic OptionEnumValueElement 2585254721Semasteg_memory_module_load_level_values[] = 2586254721Semaste{ 2587254721Semaste { eMemoryModuleLoadLevelMinimal, "minimal" , "Load minimal information when loading modules from memory. Currently this setting loads sections only."}, 2588254721Semaste { eMemoryModuleLoadLevelPartial, "partial" , "Load partial information when loading modules from memory. Currently this setting loads sections and function bounds."}, 2589254721Semaste { eMemoryModuleLoadLevelComplete, "complete", "Load complete information when loading modules from memory. Currently this setting loads sections and all symbols."}, 2590254721Semaste { 0, NULL, NULL } 2591254721Semaste}; 2592254721Semaste 2593254721Semastestatic PropertyDefinition 2594254721Semasteg_properties[] = 2595254721Semaste{ 2596254721Semaste { "default-arch" , OptionValue::eTypeArch , true , 0 , NULL, NULL, "Default architecture to choose, when there's a choice." }, 2597254721Semaste { "expr-prefix" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "Path to a file containing expressions to be prepended to all expressions." }, 2598254721Semaste { "prefer-dynamic-value" , OptionValue::eTypeEnum , false, eNoDynamicValues , NULL, g_dynamic_value_types, "Should printed values be shown as their dynamic value." }, 2599254721Semaste { "enable-synthetic-value" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Should synthetic values be used by default whenever available." }, 2600254721Semaste { "skip-prologue" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Skip function prologues when setting breakpoints by name." }, 2601254721Semaste { "source-map" , OptionValue::eTypePathMap , false, 0 , NULL, NULL, "Source path remappings used to track the change of location between a source file when built, and " 2602254721Semaste "where it exists on the current system. It consists of an array of duples, the first element of each duple is " 2603254721Semaste "some part (starting at the root) of the path to the file when it was built, " 2604254721Semaste "and the second is where the remainder of the original build hierarchy is rooted on the local system. " 2605254721Semaste "Each element of the array is checked in order and the first one that results in a match wins." }, 2606254721Semaste { "exec-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "Executable search paths to use when locating executable files whose paths don't match the local file system." }, 2607254721Semaste { "debug-file-search-paths" , OptionValue::eTypeFileSpecList, false, 0 , NULL, NULL, "List of directories to be searched when locating debug symbol files." }, 2608254721Semaste { "max-children-count" , OptionValue::eTypeSInt64 , false, 256 , NULL, NULL, "Maximum number of children to expand in any level of depth." }, 2609254721Semaste { "max-string-summary-length" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of characters to show when using %s in summary strings." }, 2610254721Semaste { "max-memory-read-size" , OptionValue::eTypeSInt64 , false, 1024 , NULL, NULL, "Maximum number of bytes that 'memory read' will fetch before --force must be specified." }, 2611254721Semaste { "breakpoints-use-platform-avoid-list", OptionValue::eTypeBoolean , false, true , NULL, NULL, "Consult the platform module avoid list when setting non-module specific breakpoints." }, 2612254721Semaste { "arg0" , OptionValue::eTypeString , false, 0 , NULL, NULL, "The first argument passed to the program in the argument array which can be different from the executable itself." }, 2613254721Semaste { "run-args" , OptionValue::eTypeArgs , false, 0 , NULL, NULL, "A list containing all the arguments to be passed to the executable when it is run. Note that this does NOT include the argv[0] which is in target.arg0." }, 2614254721Semaste { "env-vars" , OptionValue::eTypeDictionary, false, OptionValue::eTypeString , NULL, NULL, "A list of all the environment variables to be passed to the executable's environment, and their values." }, 2615254721Semaste { "inherit-env" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Inherit the environment from the process that is running LLDB." }, 2616254721Semaste { "input-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for reading its standard input." }, 2617254721Semaste { "output-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard output." }, 2618254721Semaste { "error-path" , OptionValue::eTypeFileSpec , false, 0 , NULL, NULL, "The file/path to be used by the executable program for writing its standard error." }, 2619254721Semaste { "disable-aslr" , OptionValue::eTypeBoolean , false, true , NULL, NULL, "Disable Address Space Layout Randomization (ASLR)" }, 2620254721Semaste { "disable-stdio" , OptionValue::eTypeBoolean , false, false , NULL, NULL, "Disable stdin/stdout for process (e.g. for a GUI application)" }, 2621254721Semaste { "inline-breakpoint-strategy" , OptionValue::eTypeEnum , false, eInlineBreakpointsHeaders , NULL, g_inline_breakpoint_enums, "The strategy to use when settings breakpoints by file and line. " 2622254721Semaste "Breakpoint locations can end up being inlined by the compiler, so that a compile unit 'a.c' might contain an inlined function from another source file. " 2623254721Semaste "Usually this is limitted to breakpoint locations from inlined functions from header or other include files, or more accurately non-implementation source files. " 2624254721Semaste "Sometimes code might #include implementation files and cause inlined breakpoint locations in inlined implementation files. " 2625254721Semaste "Always checking for inlined breakpoint locations can be expensive (memory and time), so we try to minimize the " 2626254721Semaste "times we look for inlined locations. This setting allows you to control exactly which strategy is used when settings " 2627254721Semaste "file and line breakpoints." }, 2628254721Semaste // FIXME: This is the wrong way to do per-architecture settings, but we don't have a general per architecture settings system in place yet. 2629254721Semaste { "x86-disassembly-flavor" , OptionValue::eTypeEnum , false, eX86DisFlavorDefault, NULL, g_x86_dis_flavor_value_types, "The default disassembly flavor to use for x86 or x86-64 targets." }, 2630254721Semaste { "use-hex-immediates" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Show immediates in disassembly as hexadecimal." }, 2631254721Semaste { "hex-immediate-style" , OptionValue::eTypeEnum , false, Disassembler::eHexStyleC, NULL, g_hex_immediate_style_values, "Which style to use for printing hexadecimal disassembly values." }, 2632254721Semaste { "use-fast-stepping" , OptionValue::eTypeBoolean , false, true, NULL, NULL, "Use a fast stepping algorithm based on running from branch to branch rather than instruction single-stepping." }, 2633254721Semaste { "load-script-from-symbol-file" , OptionValue::eTypeEnum , false, eLoadScriptFromSymFileWarn, NULL, g_load_script_from_sym_file_values, "Allow LLDB to load scripting resources embedded in symbol files when available." }, 2634254721Semaste { "memory-module-load-level" , OptionValue::eTypeEnum , false, eMemoryModuleLoadLevelComplete, NULL, g_memory_module_load_level_values, 2635254721Semaste "Loading modules from memory can be slow as reading the symbol tables and other data can take a long time depending on your connection to the debug target. " 2636254721Semaste "This setting helps users control how much information gets loaded when loading modules from memory." 2637254721Semaste "'complete' is the default value for this setting which will load all sections and symbols by reading them from memory (slowest, most accurate). " 2638254721Semaste "'partial' will load sections and attempt to find function bounds without downloading the symbol table (faster, still accurate, missing symbol names). " 2639254721Semaste "'minimal' is the fastest setting and will load section data with no symbols, but should rarely be used as stack frames in these memory regions will be inaccurate and not provide any context (fastest). " }, 2640269024Semaste { "display-expression-in-crashlogs" , OptionValue::eTypeBoolean , false, false, NULL, NULL, "Expressions that crash will show up in crash logs if the host system supports executable specific crash log strings and this setting is set to true." }, 2641269024Semaste { "trap-handler-names" , OptionValue::eTypeArray , true, OptionValue::eTypeString, NULL, NULL, "A list of trap handler function names, e.g. a common Unix user process one is _sigtramp." }, 2642254721Semaste { NULL , OptionValue::eTypeInvalid , false, 0 , NULL, NULL, NULL } 2643254721Semaste}; 2644254721Semasteenum 2645254721Semaste{ 2646254721Semaste ePropertyDefaultArch, 2647254721Semaste ePropertyExprPrefix, 2648254721Semaste ePropertyPreferDynamic, 2649254721Semaste ePropertyEnableSynthetic, 2650254721Semaste ePropertySkipPrologue, 2651254721Semaste ePropertySourceMap, 2652254721Semaste ePropertyExecutableSearchPaths, 2653254721Semaste ePropertyDebugFileSearchPaths, 2654254721Semaste ePropertyMaxChildrenCount, 2655254721Semaste ePropertyMaxSummaryLength, 2656254721Semaste ePropertyMaxMemReadSize, 2657254721Semaste ePropertyBreakpointUseAvoidList, 2658254721Semaste ePropertyArg0, 2659254721Semaste ePropertyRunArgs, 2660254721Semaste ePropertyEnvVars, 2661254721Semaste ePropertyInheritEnv, 2662254721Semaste ePropertyInputPath, 2663254721Semaste ePropertyOutputPath, 2664254721Semaste ePropertyErrorPath, 2665254721Semaste ePropertyDisableASLR, 2666254721Semaste ePropertyDisableSTDIO, 2667254721Semaste ePropertyInlineStrategy, 2668254721Semaste ePropertyDisassemblyFlavor, 2669254721Semaste ePropertyUseHexImmediates, 2670254721Semaste ePropertyHexImmediateStyle, 2671254721Semaste ePropertyUseFastStepping, 2672254721Semaste ePropertyLoadScriptFromSymbolFile, 2673269024Semaste ePropertyMemoryModuleLoadLevel, 2674269024Semaste ePropertyDisplayExpressionsInCrashlogs, 2675269024Semaste ePropertyTrapHandlerNames 2676254721Semaste}; 2677254721Semaste 2678254721Semaste 2679254721Semasteclass TargetOptionValueProperties : public OptionValueProperties 2680254721Semaste{ 2681254721Semastepublic: 2682254721Semaste TargetOptionValueProperties (const ConstString &name) : 2683254721Semaste OptionValueProperties (name), 2684254721Semaste m_target (NULL), 2685254721Semaste m_got_host_env (false) 2686254721Semaste { 2687254721Semaste } 2688254721Semaste 2689254721Semaste // This constructor is used when creating TargetOptionValueProperties when it 2690254721Semaste // is part of a new lldb_private::Target instance. It will copy all current 2691254721Semaste // global property values as needed 2692254721Semaste TargetOptionValueProperties (Target *target, const TargetPropertiesSP &target_properties_sp) : 2693254721Semaste OptionValueProperties(*target_properties_sp->GetValueProperties()), 2694254721Semaste m_target (target), 2695254721Semaste m_got_host_env (false) 2696254721Semaste { 2697254721Semaste } 2698254721Semaste 2699254721Semaste virtual const Property * 2700254721Semaste GetPropertyAtIndex (const ExecutionContext *exe_ctx, bool will_modify, uint32_t idx) const 2701254721Semaste { 2702254721Semaste // When gettings the value for a key from the target options, we will always 2703254721Semaste // try and grab the setting from the current target if there is one. Else we just 2704254721Semaste // use the one from this instance. 2705254721Semaste if (idx == ePropertyEnvVars) 2706254721Semaste GetHostEnvironmentIfNeeded (); 2707254721Semaste 2708254721Semaste if (exe_ctx) 2709254721Semaste { 2710254721Semaste Target *target = exe_ctx->GetTargetPtr(); 2711254721Semaste if (target) 2712254721Semaste { 2713254721Semaste TargetOptionValueProperties *target_properties = static_cast<TargetOptionValueProperties *>(target->GetValueProperties().get()); 2714254721Semaste if (this != target_properties) 2715254721Semaste return target_properties->ProtectedGetPropertyAtIndex (idx); 2716254721Semaste } 2717254721Semaste } 2718254721Semaste return ProtectedGetPropertyAtIndex (idx); 2719254721Semaste } 2720254721Semaste 2721254721Semaste lldb::TargetSP 2722254721Semaste GetTargetSP () 2723254721Semaste { 2724254721Semaste return m_target->shared_from_this(); 2725254721Semaste } 2726254721Semaste 2727254721Semasteprotected: 2728254721Semaste 2729254721Semaste void 2730254721Semaste GetHostEnvironmentIfNeeded () const 2731254721Semaste { 2732254721Semaste if (!m_got_host_env) 2733254721Semaste { 2734254721Semaste if (m_target) 2735254721Semaste { 2736254721Semaste m_got_host_env = true; 2737254721Semaste const uint32_t idx = ePropertyInheritEnv; 2738254721Semaste if (GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0)) 2739254721Semaste { 2740254721Semaste PlatformSP platform_sp (m_target->GetPlatform()); 2741254721Semaste if (platform_sp) 2742254721Semaste { 2743254721Semaste StringList env; 2744254721Semaste if (platform_sp->GetEnvironment(env)) 2745254721Semaste { 2746254721Semaste OptionValueDictionary *env_dict = GetPropertyAtIndexAsOptionValueDictionary (NULL, ePropertyEnvVars); 2747254721Semaste if (env_dict) 2748254721Semaste { 2749254721Semaste const bool can_replace = false; 2750254721Semaste const size_t envc = env.GetSize(); 2751254721Semaste for (size_t idx=0; idx<envc; idx++) 2752254721Semaste { 2753254721Semaste const char *env_entry = env.GetStringAtIndex (idx); 2754254721Semaste if (env_entry) 2755254721Semaste { 2756254721Semaste const char *equal_pos = ::strchr(env_entry, '='); 2757254721Semaste ConstString key; 2758254721Semaste // It is ok to have environment variables with no values 2759254721Semaste const char *value = NULL; 2760254721Semaste if (equal_pos) 2761254721Semaste { 2762254721Semaste key.SetCStringWithLength(env_entry, equal_pos - env_entry); 2763254721Semaste if (equal_pos[1]) 2764254721Semaste value = equal_pos + 1; 2765254721Semaste } 2766254721Semaste else 2767254721Semaste { 2768254721Semaste key.SetCString(env_entry); 2769254721Semaste } 2770254721Semaste // Don't allow existing keys to be replaced with ones we get from the platform environment 2771254721Semaste env_dict->SetValueForKey(key, OptionValueSP(new OptionValueString(value)), can_replace); 2772254721Semaste } 2773254721Semaste } 2774254721Semaste } 2775254721Semaste } 2776254721Semaste } 2777254721Semaste } 2778254721Semaste } 2779254721Semaste } 2780254721Semaste } 2781254721Semaste Target *m_target; 2782254721Semaste mutable bool m_got_host_env; 2783254721Semaste}; 2784254721Semaste 2785263367Semaste//---------------------------------------------------------------------- 2786263367Semaste// TargetProperties 2787263367Semaste//---------------------------------------------------------------------- 2788254721SemasteTargetProperties::TargetProperties (Target *target) : 2789254721Semaste Properties () 2790254721Semaste{ 2791254721Semaste if (target) 2792254721Semaste { 2793254721Semaste m_collection_sp.reset (new TargetOptionValueProperties(target, Target::GetGlobalProperties())); 2794254721Semaste } 2795254721Semaste else 2796254721Semaste { 2797254721Semaste m_collection_sp.reset (new TargetOptionValueProperties(ConstString("target"))); 2798254721Semaste m_collection_sp->Initialize(g_properties); 2799254721Semaste m_collection_sp->AppendProperty(ConstString("process"), 2800254721Semaste ConstString("Settings specify to processes."), 2801254721Semaste true, 2802254721Semaste Process::GetGlobalProperties()->GetValueProperties()); 2803254721Semaste } 2804254721Semaste} 2805254721Semaste 2806254721SemasteTargetProperties::~TargetProperties () 2807254721Semaste{ 2808254721Semaste} 2809254721SemasteArchSpec 2810254721SemasteTargetProperties::GetDefaultArchitecture () const 2811254721Semaste{ 2812254721Semaste OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch); 2813254721Semaste if (value) 2814254721Semaste return value->GetCurrentValue(); 2815254721Semaste return ArchSpec(); 2816254721Semaste} 2817254721Semaste 2818254721Semastevoid 2819254721SemasteTargetProperties::SetDefaultArchitecture (const ArchSpec& arch) 2820254721Semaste{ 2821254721Semaste OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch (NULL, ePropertyDefaultArch); 2822254721Semaste if (value) 2823254721Semaste return value->SetCurrentValue(arch, true); 2824254721Semaste} 2825254721Semaste 2826254721Semastelldb::DynamicValueType 2827254721SemasteTargetProperties::GetPreferDynamicValue() const 2828254721Semaste{ 2829254721Semaste const uint32_t idx = ePropertyPreferDynamic; 2830254721Semaste return (lldb::DynamicValueType)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value); 2831254721Semaste} 2832254721Semaste 2833254721Semastebool 2834254721SemasteTargetProperties::GetDisableASLR () const 2835254721Semaste{ 2836254721Semaste const uint32_t idx = ePropertyDisableASLR; 2837254721Semaste return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); 2838254721Semaste} 2839254721Semaste 2840254721Semastevoid 2841254721SemasteTargetProperties::SetDisableASLR (bool b) 2842254721Semaste{ 2843254721Semaste const uint32_t idx = ePropertyDisableASLR; 2844254721Semaste m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b); 2845254721Semaste} 2846254721Semaste 2847254721Semastebool 2848254721SemasteTargetProperties::GetDisableSTDIO () const 2849254721Semaste{ 2850254721Semaste const uint32_t idx = ePropertyDisableSTDIO; 2851254721Semaste return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); 2852254721Semaste} 2853254721Semaste 2854254721Semastevoid 2855254721SemasteTargetProperties::SetDisableSTDIO (bool b) 2856254721Semaste{ 2857254721Semaste const uint32_t idx = ePropertyDisableSTDIO; 2858254721Semaste m_collection_sp->SetPropertyAtIndexAsBoolean (NULL, idx, b); 2859254721Semaste} 2860254721Semaste 2861254721Semasteconst char * 2862254721SemasteTargetProperties::GetDisassemblyFlavor () const 2863254721Semaste{ 2864254721Semaste const uint32_t idx = ePropertyDisassemblyFlavor; 2865254721Semaste const char *return_value; 2866254721Semaste 2867254721Semaste x86DisassemblyFlavor flavor_value = (x86DisassemblyFlavor) m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value); 2868254721Semaste return_value = g_x86_dis_flavor_value_types[flavor_value].string_value; 2869254721Semaste return return_value; 2870254721Semaste} 2871254721Semaste 2872254721SemasteInlineStrategy 2873254721SemasteTargetProperties::GetInlineStrategy () const 2874254721Semaste{ 2875254721Semaste const uint32_t idx = ePropertyInlineStrategy; 2876254721Semaste return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration (NULL, idx, g_properties[idx].default_uint_value); 2877254721Semaste} 2878254721Semaste 2879254721Semasteconst char * 2880254721SemasteTargetProperties::GetArg0 () const 2881254721Semaste{ 2882254721Semaste const uint32_t idx = ePropertyArg0; 2883254721Semaste return m_collection_sp->GetPropertyAtIndexAsString (NULL, idx, NULL); 2884254721Semaste} 2885254721Semaste 2886254721Semastevoid 2887254721SemasteTargetProperties::SetArg0 (const char *arg) 2888254721Semaste{ 2889254721Semaste const uint32_t idx = ePropertyArg0; 2890254721Semaste m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, arg); 2891254721Semaste} 2892254721Semaste 2893254721Semastebool 2894254721SemasteTargetProperties::GetRunArguments (Args &args) const 2895254721Semaste{ 2896254721Semaste const uint32_t idx = ePropertyRunArgs; 2897254721Semaste return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args); 2898254721Semaste} 2899254721Semaste 2900254721Semastevoid 2901254721SemasteTargetProperties::SetRunArguments (const Args &args) 2902254721Semaste{ 2903254721Semaste const uint32_t idx = ePropertyRunArgs; 2904254721Semaste m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args); 2905254721Semaste} 2906254721Semaste 2907254721Semastesize_t 2908254721SemasteTargetProperties::GetEnvironmentAsArgs (Args &env) const 2909254721Semaste{ 2910254721Semaste const uint32_t idx = ePropertyEnvVars; 2911254721Semaste return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, env); 2912254721Semaste} 2913254721Semaste 2914254721Semastebool 2915254721SemasteTargetProperties::GetSkipPrologue() const 2916254721Semaste{ 2917254721Semaste const uint32_t idx = ePropertySkipPrologue; 2918254721Semaste return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); 2919254721Semaste} 2920254721Semaste 2921254721SemastePathMappingList & 2922254721SemasteTargetProperties::GetSourcePathMap () const 2923254721Semaste{ 2924254721Semaste const uint32_t idx = ePropertySourceMap; 2925254721Semaste OptionValuePathMappings *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings (NULL, false, idx); 2926254721Semaste assert(option_value); 2927254721Semaste return option_value->GetCurrentValue(); 2928254721Semaste} 2929254721Semaste 2930254721SemasteFileSpecList & 2931254721SemasteTargetProperties::GetExecutableSearchPaths () 2932254721Semaste{ 2933254721Semaste const uint32_t idx = ePropertyExecutableSearchPaths; 2934254721Semaste OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx); 2935254721Semaste assert(option_value); 2936254721Semaste return option_value->GetCurrentValue(); 2937254721Semaste} 2938254721Semaste 2939254721SemasteFileSpecList & 2940254721SemasteTargetProperties::GetDebugFileSearchPaths () 2941254721Semaste{ 2942254721Semaste const uint32_t idx = ePropertyDebugFileSearchPaths; 2943254721Semaste OptionValueFileSpecList *option_value = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList (NULL, false, idx); 2944254721Semaste assert(option_value); 2945254721Semaste return option_value->GetCurrentValue(); 2946254721Semaste} 2947254721Semaste 2948254721Semastebool 2949254721SemasteTargetProperties::GetEnableSyntheticValue () const 2950254721Semaste{ 2951254721Semaste const uint32_t idx = ePropertyEnableSynthetic; 2952254721Semaste return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); 2953254721Semaste} 2954254721Semaste 2955254721Semasteuint32_t 2956254721SemasteTargetProperties::GetMaximumNumberOfChildrenToDisplay() const 2957254721Semaste{ 2958254721Semaste const uint32_t idx = ePropertyMaxChildrenCount; 2959254721Semaste return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value); 2960254721Semaste} 2961254721Semaste 2962254721Semasteuint32_t 2963254721SemasteTargetProperties::GetMaximumSizeOfStringSummary() const 2964254721Semaste{ 2965254721Semaste const uint32_t idx = ePropertyMaxSummaryLength; 2966254721Semaste return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value); 2967254721Semaste} 2968254721Semaste 2969254721Semasteuint32_t 2970254721SemasteTargetProperties::GetMaximumMemReadSize () const 2971254721Semaste{ 2972254721Semaste const uint32_t idx = ePropertyMaxMemReadSize; 2973254721Semaste return m_collection_sp->GetPropertyAtIndexAsSInt64 (NULL, idx, g_properties[idx].default_uint_value); 2974254721Semaste} 2975254721Semaste 2976254721SemasteFileSpec 2977254721SemasteTargetProperties::GetStandardInputPath () const 2978254721Semaste{ 2979254721Semaste const uint32_t idx = ePropertyInputPath; 2980254721Semaste return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx); 2981254721Semaste} 2982254721Semaste 2983254721Semastevoid 2984254721SemasteTargetProperties::SetStandardInputPath (const char *p) 2985254721Semaste{ 2986254721Semaste const uint32_t idx = ePropertyInputPath; 2987254721Semaste m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p); 2988254721Semaste} 2989254721Semaste 2990254721SemasteFileSpec 2991254721SemasteTargetProperties::GetStandardOutputPath () const 2992254721Semaste{ 2993254721Semaste const uint32_t idx = ePropertyOutputPath; 2994254721Semaste return m_collection_sp->GetPropertyAtIndexAsFileSpec (NULL, idx); 2995254721Semaste} 2996254721Semaste 2997254721Semastevoid 2998254721SemasteTargetProperties::SetStandardOutputPath (const char *p) 2999254721Semaste{ 3000254721Semaste const uint32_t idx = ePropertyOutputPath; 3001254721Semaste m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p); 3002254721Semaste} 3003254721Semaste 3004254721SemasteFileSpec 3005254721SemasteTargetProperties::GetStandardErrorPath () const 3006254721Semaste{ 3007254721Semaste const uint32_t idx = ePropertyErrorPath; 3008254721Semaste return m_collection_sp->GetPropertyAtIndexAsFileSpec(NULL, idx); 3009254721Semaste} 3010254721Semaste 3011254721Semasteconst char * 3012254721SemasteTargetProperties::GetExpressionPrefixContentsAsCString () 3013254721Semaste{ 3014254721Semaste const uint32_t idx = ePropertyExprPrefix; 3015254721Semaste OptionValueFileSpec *file = m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec (NULL, false, idx); 3016254721Semaste if (file) 3017254721Semaste { 3018254721Semaste const bool null_terminate = true; 3019254721Semaste DataBufferSP data_sp(file->GetFileContents(null_terminate)); 3020254721Semaste if (data_sp) 3021254721Semaste return (const char *) data_sp->GetBytes(); 3022254721Semaste } 3023254721Semaste return NULL; 3024254721Semaste} 3025254721Semaste 3026254721Semastevoid 3027254721SemasteTargetProperties::SetStandardErrorPath (const char *p) 3028254721Semaste{ 3029254721Semaste const uint32_t idx = ePropertyErrorPath; 3030254721Semaste m_collection_sp->SetPropertyAtIndexAsString (NULL, idx, p); 3031254721Semaste} 3032254721Semaste 3033254721Semastebool 3034254721SemasteTargetProperties::GetBreakpointsConsultPlatformAvoidList () 3035254721Semaste{ 3036254721Semaste const uint32_t idx = ePropertyBreakpointUseAvoidList; 3037254721Semaste return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); 3038254721Semaste} 3039254721Semaste 3040254721Semastebool 3041254721SemasteTargetProperties::GetUseHexImmediates () const 3042254721Semaste{ 3043254721Semaste const uint32_t idx = ePropertyUseHexImmediates; 3044254721Semaste return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); 3045254721Semaste} 3046254721Semaste 3047254721Semastebool 3048254721SemasteTargetProperties::GetUseFastStepping () const 3049254721Semaste{ 3050254721Semaste const uint32_t idx = ePropertyUseFastStepping; 3051254721Semaste return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); 3052254721Semaste} 3053254721Semaste 3054269024Semastebool 3055269024SemasteTargetProperties::GetDisplayExpressionsInCrashlogs () const 3056269024Semaste{ 3057269024Semaste const uint32_t idx = ePropertyDisplayExpressionsInCrashlogs; 3058269024Semaste return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0); 3059269024Semaste} 3060269024Semaste 3061254721SemasteLoadScriptFromSymFile 3062254721SemasteTargetProperties::GetLoadScriptFromSymbolFile () const 3063254721Semaste{ 3064254721Semaste const uint32_t idx = ePropertyLoadScriptFromSymbolFile; 3065254721Semaste return (LoadScriptFromSymFile)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value); 3066254721Semaste} 3067254721Semaste 3068254721SemasteDisassembler::HexImmediateStyle 3069254721SemasteTargetProperties::GetHexImmediateStyle () const 3070254721Semaste{ 3071254721Semaste const uint32_t idx = ePropertyHexImmediateStyle; 3072254721Semaste return (Disassembler::HexImmediateStyle)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value); 3073254721Semaste} 3074254721Semaste 3075254721SemasteMemoryModuleLoadLevel 3076254721SemasteTargetProperties::GetMemoryModuleLoadLevel() const 3077254721Semaste{ 3078254721Semaste const uint32_t idx = ePropertyMemoryModuleLoadLevel; 3079254721Semaste return (MemoryModuleLoadLevel)m_collection_sp->GetPropertyAtIndexAsEnumeration(NULL, idx, g_properties[idx].default_uint_value); 3080254721Semaste} 3081254721Semaste 3082269024Semastebool 3083269024SemasteTargetProperties::GetUserSpecifiedTrapHandlerNames (Args &args) const 3084269024Semaste{ 3085269024Semaste const uint32_t idx = ePropertyTrapHandlerNames; 3086269024Semaste return m_collection_sp->GetPropertyAtIndexAsArgs (NULL, idx, args); 3087269024Semaste} 3088254721Semaste 3089269024Semastevoid 3090269024SemasteTargetProperties::SetUserSpecifiedTrapHandlerNames (const Args &args) 3091269024Semaste{ 3092269024Semaste const uint32_t idx = ePropertyTrapHandlerNames; 3093269024Semaste m_collection_sp->SetPropertyAtIndexFromArgs (NULL, idx, args); 3094269024Semaste} 3095254721Semaste 3096263367Semaste//---------------------------------------------------------------------- 3097263367Semaste// Target::TargetEventData 3098263367Semaste//---------------------------------------------------------------------- 3099254721Semasteconst ConstString & 3100254721SemasteTarget::TargetEventData::GetFlavorString () 3101254721Semaste{ 3102254721Semaste static ConstString g_flavor ("Target::TargetEventData"); 3103254721Semaste return g_flavor; 3104254721Semaste} 3105254721Semaste 3106254721Semasteconst ConstString & 3107254721SemasteTarget::TargetEventData::GetFlavor () const 3108254721Semaste{ 3109254721Semaste return TargetEventData::GetFlavorString (); 3110254721Semaste} 3111254721Semaste 3112254721SemasteTarget::TargetEventData::TargetEventData (const lldb::TargetSP &new_target_sp) : 3113254721Semaste EventData(), 3114254721Semaste m_target_sp (new_target_sp) 3115254721Semaste{ 3116254721Semaste} 3117254721Semaste 3118254721SemasteTarget::TargetEventData::~TargetEventData() 3119254721Semaste{ 3120254721Semaste 3121254721Semaste} 3122254721Semaste 3123254721Semastevoid 3124254721SemasteTarget::TargetEventData::Dump (Stream *s) const 3125254721Semaste{ 3126254721Semaste 3127254721Semaste} 3128254721Semaste 3129254721Semasteconst TargetSP 3130254721SemasteTarget::TargetEventData::GetTargetFromEvent (const lldb::EventSP &event_sp) 3131254721Semaste{ 3132254721Semaste TargetSP target_sp; 3133254721Semaste 3134254721Semaste const TargetEventData *data = GetEventDataFromEvent (event_sp.get()); 3135254721Semaste if (data) 3136254721Semaste target_sp = data->m_target_sp; 3137254721Semaste 3138254721Semaste return target_sp; 3139254721Semaste} 3140254721Semaste 3141254721Semasteconst Target::TargetEventData * 3142254721SemasteTarget::TargetEventData::GetEventDataFromEvent (const Event *event_ptr) 3143254721Semaste{ 3144254721Semaste if (event_ptr) 3145254721Semaste { 3146254721Semaste const EventData *event_data = event_ptr->GetData(); 3147254721Semaste if (event_data && event_data->GetFlavor() == TargetEventData::GetFlavorString()) 3148254721Semaste return static_cast <const TargetEventData *> (event_ptr->GetData()); 3149254721Semaste } 3150254721Semaste return NULL; 3151254721Semaste} 3152254721Semaste 3153