1 //===-- Target.h ------------------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef liblldb_Target_h_ 10 #define liblldb_Target_h_ 11 12 #include <list> 13 #include <map> 14 #include <memory> 15 #include <string> 16 #include <vector> 17 18 #include "lldb/Breakpoint/BreakpointList.h" 19 #include "lldb/Breakpoint/BreakpointName.h" 20 #include "lldb/Breakpoint/WatchpointList.h" 21 #include "lldb/Core/Architecture.h" 22 #include "lldb/Core/Disassembler.h" 23 #include "lldb/Core/ModuleList.h" 24 #include "lldb/Core/UserSettingsController.h" 25 #include "lldb/Expression/Expression.h" 26 #include "lldb/Host/ProcessLaunchInfo.h" 27 #include "lldb/Symbol/TypeSystem.h" 28 #include "lldb/Target/ExecutionContextScope.h" 29 #include "lldb/Target/PathMappingList.h" 30 #include "lldb/Target/SectionLoadHistory.h" 31 #include "lldb/Utility/ArchSpec.h" 32 #include "lldb/Utility/Broadcaster.h" 33 #include "lldb/Utility/LLDBAssert.h" 34 #include "lldb/Utility/Timeout.h" 35 #include "lldb/lldb-public.h" 36 37 namespace lldb_private { 38 39 OptionEnumValues GetDynamicValueTypes(); 40 41 enum InlineStrategy { 42 eInlineBreakpointsNever = 0, 43 eInlineBreakpointsHeaders, 44 eInlineBreakpointsAlways 45 }; 46 47 enum LoadScriptFromSymFile { 48 eLoadScriptFromSymFileTrue, 49 eLoadScriptFromSymFileFalse, 50 eLoadScriptFromSymFileWarn 51 }; 52 53 enum LoadCWDlldbinitFile { 54 eLoadCWDlldbinitTrue, 55 eLoadCWDlldbinitFalse, 56 eLoadCWDlldbinitWarn 57 }; 58 59 enum LoadDependentFiles { 60 eLoadDependentsDefault, 61 eLoadDependentsYes, 62 eLoadDependentsNo, 63 }; 64 65 // TargetProperties 66 class TargetExperimentalProperties : public Properties { 67 public: 68 TargetExperimentalProperties(); 69 }; 70 71 class TargetProperties : public Properties { 72 public: 73 TargetProperties(Target *target); 74 75 ~TargetProperties() override; 76 77 ArchSpec GetDefaultArchitecture() const; 78 79 void SetDefaultArchitecture(const ArchSpec &arch); 80 81 bool GetMoveToNearestCode() const; 82 83 lldb::DynamicValueType GetPreferDynamicValue() const; 84 85 bool SetPreferDynamicValue(lldb::DynamicValueType d); 86 87 bool GetPreloadSymbols() const; 88 89 void SetPreloadSymbols(bool b); 90 91 bool GetDisableASLR() const; 92 93 void SetDisableASLR(bool b); 94 95 bool GetDetachOnError() const; 96 97 void SetDetachOnError(bool b); 98 99 bool GetDisableSTDIO() const; 100 101 void SetDisableSTDIO(bool b); 102 103 const char *GetDisassemblyFlavor() const; 104 105 InlineStrategy GetInlineStrategy() const; 106 107 llvm::StringRef GetArg0() const; 108 109 void SetArg0(llvm::StringRef arg); 110 111 bool GetRunArguments(Args &args) const; 112 113 void SetRunArguments(const Args &args); 114 115 Environment GetEnvironment() const; 116 void SetEnvironment(Environment env); 117 118 bool GetSkipPrologue() const; 119 120 PathMappingList &GetSourcePathMap() const; 121 122 FileSpecList GetExecutableSearchPaths(); 123 124 void AppendExecutableSearchPaths(const FileSpec &); 125 126 FileSpecList GetDebugFileSearchPaths(); 127 128 FileSpecList GetClangModuleSearchPaths(); 129 130 bool GetEnableAutoImportClangModules() const; 131 132 bool GetEnableImportStdModule() const; 133 134 bool GetEnableAutoApplyFixIts() const; 135 136 bool GetEnableNotifyAboutFixIts() const; 137 138 bool GetEnableSaveObjects() const; 139 140 bool GetEnableSyntheticValue() const; 141 142 uint32_t GetMaxZeroPaddingInFloatFormat() const; 143 144 uint32_t GetMaximumNumberOfChildrenToDisplay() const; 145 146 uint32_t GetMaximumSizeOfStringSummary() const; 147 148 uint32_t GetMaximumMemReadSize() const; 149 150 FileSpec GetStandardInputPath() const; 151 FileSpec GetStandardErrorPath() const; 152 FileSpec GetStandardOutputPath() const; 153 154 void SetStandardInputPath(llvm::StringRef path); 155 void SetStandardOutputPath(llvm::StringRef path); 156 void SetStandardErrorPath(llvm::StringRef path); 157 158 void SetStandardInputPath(const char *path) = delete; 159 void SetStandardOutputPath(const char *path) = delete; 160 void SetStandardErrorPath(const char *path) = delete; 161 162 bool GetBreakpointsConsultPlatformAvoidList(); 163 164 lldb::LanguageType GetLanguage() const; 165 166 llvm::StringRef GetExpressionPrefixContents(); 167 168 bool GetUseHexImmediates() const; 169 170 bool GetUseFastStepping() const; 171 172 bool GetDisplayExpressionsInCrashlogs() const; 173 174 LoadScriptFromSymFile GetLoadScriptFromSymbolFile() const; 175 176 LoadCWDlldbinitFile GetLoadCWDlldbinitFile() const; 177 178 Disassembler::HexImmediateStyle GetHexImmediateStyle() const; 179 180 MemoryModuleLoadLevel GetMemoryModuleLoadLevel() const; 181 182 bool GetUserSpecifiedTrapHandlerNames(Args &args) const; 183 184 void SetUserSpecifiedTrapHandlerNames(const Args &args); 185 186 bool GetNonStopModeEnabled() const; 187 188 void SetNonStopModeEnabled(bool b); 189 190 bool GetDisplayRuntimeSupportValues() const; 191 192 void SetDisplayRuntimeSupportValues(bool b); 193 194 bool GetDisplayRecognizedArguments() const; 195 196 void SetDisplayRecognizedArguments(bool b); 197 198 const ProcessLaunchInfo &GetProcessLaunchInfo(); 199 200 void SetProcessLaunchInfo(const ProcessLaunchInfo &launch_info); 201 202 bool GetInjectLocalVariables(ExecutionContext *exe_ctx) const; 203 204 void SetInjectLocalVariables(ExecutionContext *exe_ctx, bool b); 205 206 void SetRequireHardwareBreakpoints(bool b); 207 208 bool GetRequireHardwareBreakpoints() const; 209 210 private: 211 // Callbacks for m_launch_info. 212 void Arg0ValueChangedCallback(); 213 void RunArgsValueChangedCallback(); 214 void EnvVarsValueChangedCallback(); 215 void InputPathValueChangedCallback(); 216 void OutputPathValueChangedCallback(); 217 void ErrorPathValueChangedCallback(); 218 void DetachOnErrorValueChangedCallback(); 219 void DisableASLRValueChangedCallback(); 220 void DisableSTDIOValueChangedCallback(); 221 222 // Member variables. 223 ProcessLaunchInfo m_launch_info; 224 std::unique_ptr<TargetExperimentalProperties> m_experimental_properties_up; 225 }; 226 227 class EvaluateExpressionOptions { 228 public: 229 // MSVC has a bug here that reports C4268: 'const' static/global data 230 // initialized with compiler generated default constructor fills the object 231 // with zeros. Confirmed that MSVC is *not* zero-initializing, it's just a 232 // bogus warning. 233 #if defined(_MSC_VER) 234 #pragma warning(push) 235 #pragma warning(disable : 4268) 236 #endif 237 static constexpr std::chrono::milliseconds default_timeout{500}; 238 #if defined(_MSC_VER) 239 #pragma warning(pop) 240 #endif 241 242 static constexpr ExecutionPolicy default_execution_policy = 243 eExecutionPolicyOnlyWhenNeeded; 244 245 EvaluateExpressionOptions() = default; 246 247 ExecutionPolicy GetExecutionPolicy() const { return m_execution_policy; } 248 249 void SetExecutionPolicy(ExecutionPolicy policy = eExecutionPolicyAlways) { 250 m_execution_policy = policy; 251 } 252 253 lldb::LanguageType GetLanguage() const { return m_language; } 254 255 void SetLanguage(lldb::LanguageType language) { m_language = language; } 256 257 bool DoesCoerceToId() const { return m_coerce_to_id; } 258 259 const char *GetPrefix() const { 260 return (m_prefix.empty() ? nullptr : m_prefix.c_str()); 261 } 262 263 void SetPrefix(const char *prefix) { 264 if (prefix && prefix[0]) 265 m_prefix = prefix; 266 else 267 m_prefix.clear(); 268 } 269 270 void SetCoerceToId(bool coerce = true) { m_coerce_to_id = coerce; } 271 272 bool DoesUnwindOnError() const { return m_unwind_on_error; } 273 274 void SetUnwindOnError(bool unwind = false) { m_unwind_on_error = unwind; } 275 276 bool DoesIgnoreBreakpoints() const { return m_ignore_breakpoints; } 277 278 void SetIgnoreBreakpoints(bool ignore = false) { 279 m_ignore_breakpoints = ignore; 280 } 281 282 bool DoesKeepInMemory() const { return m_keep_in_memory; } 283 284 void SetKeepInMemory(bool keep = true) { m_keep_in_memory = keep; } 285 286 lldb::DynamicValueType GetUseDynamic() const { return m_use_dynamic; } 287 288 void 289 SetUseDynamic(lldb::DynamicValueType dynamic = lldb::eDynamicCanRunTarget) { 290 m_use_dynamic = dynamic; 291 } 292 293 const Timeout<std::micro> &GetTimeout() const { return m_timeout; } 294 295 void SetTimeout(const Timeout<std::micro> &timeout) { m_timeout = timeout; } 296 297 const Timeout<std::micro> &GetOneThreadTimeout() const { 298 return m_one_thread_timeout; 299 } 300 301 void SetOneThreadTimeout(const Timeout<std::micro> &timeout) { 302 m_one_thread_timeout = timeout; 303 } 304 305 bool GetTryAllThreads() const { return m_try_others; } 306 307 void SetTryAllThreads(bool try_others = true) { m_try_others = try_others; } 308 309 bool GetStopOthers() const { return m_stop_others; } 310 311 void SetStopOthers(bool stop_others = true) { m_stop_others = stop_others; } 312 313 bool GetDebug() const { return m_debug; } 314 315 void SetDebug(bool b) { 316 m_debug = b; 317 if (m_debug) 318 m_generate_debug_info = true; 319 } 320 321 bool GetGenerateDebugInfo() const { return m_generate_debug_info; } 322 323 void SetGenerateDebugInfo(bool b) { m_generate_debug_info = b; } 324 325 bool GetColorizeErrors() const { return m_ansi_color_errors; } 326 327 void SetColorizeErrors(bool b) { m_ansi_color_errors = b; } 328 329 bool GetTrapExceptions() const { return m_trap_exceptions; } 330 331 void SetTrapExceptions(bool b) { m_trap_exceptions = b; } 332 333 bool GetREPLEnabled() const { return m_repl; } 334 335 void SetREPLEnabled(bool b) { m_repl = b; } 336 337 void SetCancelCallback(lldb::ExpressionCancelCallback callback, void *baton) { 338 m_cancel_callback_baton = baton; 339 m_cancel_callback = callback; 340 } 341 342 bool InvokeCancelCallback(lldb::ExpressionEvaluationPhase phase) const { 343 return ((m_cancel_callback != nullptr) 344 ? m_cancel_callback(phase, m_cancel_callback_baton) 345 : false); 346 } 347 348 // Allows the expression contents to be remapped to point to the specified 349 // file and line using #line directives. 350 void SetPoundLine(const char *path, uint32_t line) const { 351 if (path && path[0]) { 352 m_pound_line_file = path; 353 m_pound_line_line = line; 354 } else { 355 m_pound_line_file.clear(); 356 m_pound_line_line = 0; 357 } 358 } 359 360 const char *GetPoundLineFilePath() const { 361 return (m_pound_line_file.empty() ? nullptr : m_pound_line_file.c_str()); 362 } 363 364 uint32_t GetPoundLineLine() const { return m_pound_line_line; } 365 366 void SetResultIsInternal(bool b) { m_result_is_internal = b; } 367 368 bool GetResultIsInternal() const { return m_result_is_internal; } 369 370 void SetAutoApplyFixIts(bool b) { m_auto_apply_fixits = b; } 371 372 bool GetAutoApplyFixIts() const { return m_auto_apply_fixits; } 373 374 bool IsForUtilityExpr() const { return m_running_utility_expression; } 375 376 void SetIsForUtilityExpr(bool b) { m_running_utility_expression = b; } 377 378 private: 379 ExecutionPolicy m_execution_policy = default_execution_policy; 380 lldb::LanguageType m_language = lldb::eLanguageTypeUnknown; 381 std::string m_prefix; 382 bool m_coerce_to_id = false; 383 bool m_unwind_on_error = true; 384 bool m_ignore_breakpoints = false; 385 bool m_keep_in_memory = false; 386 bool m_try_others = true; 387 bool m_stop_others = true; 388 bool m_debug = false; 389 bool m_trap_exceptions = true; 390 bool m_repl = false; 391 bool m_generate_debug_info = false; 392 bool m_ansi_color_errors = false; 393 bool m_result_is_internal = false; 394 bool m_auto_apply_fixits = true; 395 /// True if the executed code should be treated as utility code that is only 396 /// used by LLDB internally. 397 bool m_running_utility_expression = false; 398 399 lldb::DynamicValueType m_use_dynamic = lldb::eNoDynamicValues; 400 Timeout<std::micro> m_timeout = default_timeout; 401 Timeout<std::micro> m_one_thread_timeout = llvm::None; 402 lldb::ExpressionCancelCallback m_cancel_callback = nullptr; 403 void *m_cancel_callback_baton = nullptr; 404 // If m_pound_line_file is not empty and m_pound_line_line is non-zero, use 405 // #line %u "%s" before the expression content to remap where the source 406 // originates 407 mutable std::string m_pound_line_file; 408 mutable uint32_t m_pound_line_line; 409 }; 410 411 // Target 412 class Target : public std::enable_shared_from_this<Target>, 413 public TargetProperties, 414 public Broadcaster, 415 public ExecutionContextScope, 416 public ModuleList::Notifier { 417 public: 418 friend class TargetList; 419 420 /// Broadcaster event bits definitions. 421 enum { 422 eBroadcastBitBreakpointChanged = (1 << 0), 423 eBroadcastBitModulesLoaded = (1 << 1), 424 eBroadcastBitModulesUnloaded = (1 << 2), 425 eBroadcastBitWatchpointChanged = (1 << 3), 426 eBroadcastBitSymbolsLoaded = (1 << 4) 427 }; 428 429 // These two functions fill out the Broadcaster interface: 430 431 static ConstString &GetStaticBroadcasterClass(); 432 433 ConstString &GetBroadcasterClass() const override { 434 return GetStaticBroadcasterClass(); 435 } 436 437 // This event data class is for use by the TargetList to broadcast new target 438 // notifications. 439 class TargetEventData : public EventData { 440 public: 441 TargetEventData(const lldb::TargetSP &target_sp); 442 443 TargetEventData(const lldb::TargetSP &target_sp, 444 const ModuleList &module_list); 445 446 ~TargetEventData() override; 447 448 static ConstString GetFlavorString(); 449 450 ConstString GetFlavor() const override { 451 return TargetEventData::GetFlavorString(); 452 } 453 454 void Dump(Stream *s) const override; 455 456 static const TargetEventData *GetEventDataFromEvent(const Event *event_ptr); 457 458 static lldb::TargetSP GetTargetFromEvent(const Event *event_ptr); 459 460 static ModuleList GetModuleListFromEvent(const Event *event_ptr); 461 462 const lldb::TargetSP &GetTarget() const { return m_target_sp; } 463 464 const ModuleList &GetModuleList() const { return m_module_list; } 465 466 private: 467 lldb::TargetSP m_target_sp; 468 ModuleList m_module_list; 469 470 DISALLOW_COPY_AND_ASSIGN(TargetEventData); 471 }; 472 473 ~Target() override; 474 475 static void SettingsInitialize(); 476 477 static void SettingsTerminate(); 478 479 static FileSpecList GetDefaultExecutableSearchPaths(); 480 481 static FileSpecList GetDefaultDebugFileSearchPaths(); 482 483 static ArchSpec GetDefaultArchitecture(); 484 485 static void SetDefaultArchitecture(const ArchSpec &arch); 486 487 /// Find a binary on the system and return its Module, 488 /// or return an existing Module that is already in the Target. 489 /// 490 /// Given a ModuleSpec, find a binary satisifying that specification, 491 /// or identify a matching Module already present in the Target, 492 /// and return a shared pointer to it. 493 /// 494 /// \param[in] module_spec 495 /// The criteria that must be matched for the binary being loaded. 496 /// e.g. UUID, architecture, file path. 497 /// 498 /// \param[in] notify 499 /// If notify is true, and the Module is new to this Target, 500 /// Target::ModulesDidLoad will be called. 501 /// If notify is false, it is assumed that the caller is adding 502 /// multiple Modules and will call ModulesDidLoad with the 503 /// full list at the end. 504 /// ModulesDidLoad must be called when a Module/Modules have 505 /// been added to the target, one way or the other. 506 /// 507 /// \param[out] error_ptr 508 /// Optional argument, pointing to a Status object to fill in 509 /// with any results / messages while attempting to find/load 510 /// this binary. Many callers will be internal functions that 511 /// will handle / summarize the failures in a custom way and 512 /// don't use these messages. 513 /// 514 /// \return 515 /// An empty ModuleSP will be returned if no matching file 516 /// was found. If error_ptr was non-nullptr, an error message 517 /// will likely be provided. 518 lldb::ModuleSP GetOrCreateModule(const ModuleSpec &module_spec, bool notify, 519 Status *error_ptr = nullptr); 520 521 // Settings accessors 522 523 static const lldb::TargetPropertiesSP &GetGlobalProperties(); 524 525 std::recursive_mutex &GetAPIMutex(); 526 527 void DeleteCurrentProcess(); 528 529 void CleanupProcess(); 530 531 /// Dump a description of this object to a Stream. 532 /// 533 /// Dump a description of the contents of this object to the 534 /// supplied stream \a s. The dumped content will be only what has 535 /// been loaded or parsed up to this point at which this function 536 /// is called, so this is a good way to see what has been parsed 537 /// in a target. 538 /// 539 /// \param[in] s 540 /// The stream to which to dump the object description. 541 void Dump(Stream *s, lldb::DescriptionLevel description_level); 542 543 // If listener_sp is null, the listener of the owning Debugger object will be 544 // used. 545 const lldb::ProcessSP &CreateProcess(lldb::ListenerSP listener_sp, 546 llvm::StringRef plugin_name, 547 const FileSpec *crash_file); 548 549 const lldb::ProcessSP &GetProcessSP() const; 550 551 bool IsValid() { return m_valid; } 552 553 void Destroy(); 554 555 Status Launch(ProcessLaunchInfo &launch_info, 556 Stream *stream); // Optional stream to receive first stop info 557 558 Status Attach(ProcessAttachInfo &attach_info, 559 Stream *stream); // Optional stream to receive first stop info 560 561 // This part handles the breakpoints. 562 563 BreakpointList &GetBreakpointList(bool internal = false); 564 565 const BreakpointList &GetBreakpointList(bool internal = false) const; 566 567 lldb::BreakpointSP GetLastCreatedBreakpoint() { 568 return m_last_created_breakpoint; 569 } 570 571 lldb::BreakpointSP GetBreakpointByID(lldb::break_id_t break_id); 572 573 // Use this to create a file and line breakpoint to a given module or all 574 // module it is nullptr 575 lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules, 576 const FileSpec &file, uint32_t line_no, 577 uint32_t column, lldb::addr_t offset, 578 LazyBool check_inlines, 579 LazyBool skip_prologue, bool internal, 580 bool request_hardware, 581 LazyBool move_to_nearest_code); 582 583 // Use this to create breakpoint that matches regex against the source lines 584 // in files given in source_file_list: If function_names is non-empty, also 585 // filter by function after the matches are made. 586 lldb::BreakpointSP CreateSourceRegexBreakpoint( 587 const FileSpecList *containingModules, 588 const FileSpecList *source_file_list, 589 const std::unordered_set<std::string> &function_names, 590 RegularExpression source_regex, bool internal, bool request_hardware, 591 LazyBool move_to_nearest_code); 592 593 // Use this to create a breakpoint from a load address 594 lldb::BreakpointSP CreateBreakpoint(lldb::addr_t load_addr, bool internal, 595 bool request_hardware); 596 597 // Use this to create a breakpoint from a load address and a module file spec 598 lldb::BreakpointSP CreateAddressInModuleBreakpoint(lldb::addr_t file_addr, 599 bool internal, 600 const FileSpec *file_spec, 601 bool request_hardware); 602 603 // Use this to create Address breakpoints: 604 lldb::BreakpointSP CreateBreakpoint(const Address &addr, bool internal, 605 bool request_hardware); 606 607 // Use this to create a function breakpoint by regexp in 608 // containingModule/containingSourceFiles, or all modules if it is nullptr 609 // When "skip_prologue is set to eLazyBoolCalculate, we use the current 610 // target setting, else we use the values passed in 611 lldb::BreakpointSP CreateFuncRegexBreakpoint( 612 const FileSpecList *containingModules, 613 const FileSpecList *containingSourceFiles, RegularExpression func_regexp, 614 lldb::LanguageType requested_language, LazyBool skip_prologue, 615 bool internal, bool request_hardware); 616 617 // Use this to create a function breakpoint by name in containingModule, or 618 // all modules if it is nullptr When "skip_prologue is set to 619 // eLazyBoolCalculate, we use the current target setting, else we use the 620 // values passed in. func_name_type_mask is or'ed values from the 621 // FunctionNameType enum. 622 lldb::BreakpointSP CreateBreakpoint( 623 const FileSpecList *containingModules, 624 const FileSpecList *containingSourceFiles, const char *func_name, 625 lldb::FunctionNameType func_name_type_mask, lldb::LanguageType language, 626 lldb::addr_t offset, LazyBool skip_prologue, bool internal, 627 bool request_hardware); 628 629 lldb::BreakpointSP 630 CreateExceptionBreakpoint(enum lldb::LanguageType language, bool catch_bp, 631 bool throw_bp, bool internal, 632 Args *additional_args = nullptr, 633 Status *additional_args_error = nullptr); 634 635 lldb::BreakpointSP CreateScriptedBreakpoint( 636 const llvm::StringRef class_name, const FileSpecList *containingModules, 637 const FileSpecList *containingSourceFiles, bool internal, 638 bool request_hardware, StructuredData::ObjectSP extra_args_sp, 639 Status *creation_error = nullptr); 640 641 // This is the same as the func_name breakpoint except that you can specify a 642 // vector of names. This is cheaper than a regular expression breakpoint in 643 // the case where you just want to set a breakpoint on a set of names you 644 // already know. func_name_type_mask is or'ed values from the 645 // FunctionNameType enum. 646 lldb::BreakpointSP CreateBreakpoint( 647 const FileSpecList *containingModules, 648 const FileSpecList *containingSourceFiles, const char *func_names[], 649 size_t num_names, lldb::FunctionNameType func_name_type_mask, 650 lldb::LanguageType language, lldb::addr_t offset, LazyBool skip_prologue, 651 bool internal, bool request_hardware); 652 653 lldb::BreakpointSP 654 CreateBreakpoint(const FileSpecList *containingModules, 655 const FileSpecList *containingSourceFiles, 656 const std::vector<std::string> &func_names, 657 lldb::FunctionNameType func_name_type_mask, 658 lldb::LanguageType language, lldb::addr_t m_offset, 659 LazyBool skip_prologue, bool internal, 660 bool request_hardware); 661 662 // Use this to create a general breakpoint: 663 lldb::BreakpointSP CreateBreakpoint(lldb::SearchFilterSP &filter_sp, 664 lldb::BreakpointResolverSP &resolver_sp, 665 bool internal, bool request_hardware, 666 bool resolve_indirect_symbols); 667 668 // Use this to create a watchpoint: 669 lldb::WatchpointSP CreateWatchpoint(lldb::addr_t addr, size_t size, 670 const CompilerType *type, uint32_t kind, 671 Status &error); 672 673 lldb::WatchpointSP GetLastCreatedWatchpoint() { 674 return m_last_created_watchpoint; 675 } 676 677 WatchpointList &GetWatchpointList() { return m_watchpoint_list; } 678 679 // Manages breakpoint names: 680 void AddNameToBreakpoint(BreakpointID &id, const char *name, Status &error); 681 682 void AddNameToBreakpoint(lldb::BreakpointSP &bp_sp, const char *name, 683 Status &error); 684 685 void RemoveNameFromBreakpoint(lldb::BreakpointSP &bp_sp, ConstString name); 686 687 BreakpointName *FindBreakpointName(ConstString name, bool can_create, 688 Status &error); 689 690 void DeleteBreakpointName(ConstString name); 691 692 void ConfigureBreakpointName(BreakpointName &bp_name, 693 const BreakpointOptions &options, 694 const BreakpointName::Permissions &permissions); 695 void ApplyNameToBreakpoints(BreakpointName &bp_name); 696 697 // This takes ownership of the name obj passed in. 698 void AddBreakpointName(BreakpointName *bp_name); 699 700 void GetBreakpointNames(std::vector<std::string> &names); 701 702 // This call removes ALL breakpoints regardless of permission. 703 void RemoveAllBreakpoints(bool internal_also = false); 704 705 // This removes all the breakpoints, but obeys the ePermDelete on them. 706 void RemoveAllowedBreakpoints(); 707 708 void DisableAllBreakpoints(bool internal_also = false); 709 710 void DisableAllowedBreakpoints(); 711 712 void EnableAllBreakpoints(bool internal_also = false); 713 714 void EnableAllowedBreakpoints(); 715 716 bool DisableBreakpointByID(lldb::break_id_t break_id); 717 718 bool EnableBreakpointByID(lldb::break_id_t break_id); 719 720 bool RemoveBreakpointByID(lldb::break_id_t break_id); 721 722 // The flag 'end_to_end', default to true, signifies that the operation is 723 // performed end to end, for both the debugger and the debuggee. 724 725 bool RemoveAllWatchpoints(bool end_to_end = true); 726 727 bool DisableAllWatchpoints(bool end_to_end = true); 728 729 bool EnableAllWatchpoints(bool end_to_end = true); 730 731 bool ClearAllWatchpointHitCounts(); 732 733 bool ClearAllWatchpointHistoricValues(); 734 735 bool IgnoreAllWatchpoints(uint32_t ignore_count); 736 737 bool DisableWatchpointByID(lldb::watch_id_t watch_id); 738 739 bool EnableWatchpointByID(lldb::watch_id_t watch_id); 740 741 bool RemoveWatchpointByID(lldb::watch_id_t watch_id); 742 743 bool IgnoreWatchpointByID(lldb::watch_id_t watch_id, uint32_t ignore_count); 744 745 Status SerializeBreakpointsToFile(const FileSpec &file, 746 const BreakpointIDList &bp_ids, 747 bool append); 748 749 Status CreateBreakpointsFromFile(const FileSpec &file, 750 BreakpointIDList &new_bps); 751 752 Status CreateBreakpointsFromFile(const FileSpec &file, 753 std::vector<std::string> &names, 754 BreakpointIDList &new_bps); 755 756 /// Get \a load_addr as a callable code load address for this target 757 /// 758 /// Take \a load_addr and potentially add any address bits that are 759 /// needed to make the address callable. For ARM this can set bit 760 /// zero (if it already isn't) if \a load_addr is a thumb function. 761 /// If \a addr_class is set to AddressClass::eInvalid, then the address 762 /// adjustment will always happen. If it is set to an address class 763 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 764 /// returned. 765 lldb::addr_t GetCallableLoadAddress( 766 lldb::addr_t load_addr, 767 AddressClass addr_class = AddressClass::eInvalid) const; 768 769 /// Get \a load_addr as an opcode for this target. 770 /// 771 /// Take \a load_addr and potentially strip any address bits that are 772 /// needed to make the address point to an opcode. For ARM this can 773 /// clear bit zero (if it already isn't) if \a load_addr is a 774 /// thumb function and load_addr is in code. 775 /// If \a addr_class is set to AddressClass::eInvalid, then the address 776 /// adjustment will always happen. If it is set to an address class 777 /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 778 /// returned. 779 lldb::addr_t 780 GetOpcodeLoadAddress(lldb::addr_t load_addr, 781 AddressClass addr_class = AddressClass::eInvalid) const; 782 783 // Get load_addr as breakable load address for this target. Take a addr and 784 // check if for any reason there is a better address than this to put a 785 // breakpoint on. If there is then return that address. For MIPS, if 786 // instruction at addr is a delay slot instruction then this method will find 787 // the address of its previous instruction and return that address. 788 lldb::addr_t GetBreakableLoadAddress(lldb::addr_t addr); 789 790 void ModulesDidLoad(ModuleList &module_list); 791 792 void ModulesDidUnload(ModuleList &module_list, bool delete_locations); 793 794 void SymbolsDidLoad(ModuleList &module_list); 795 796 void ClearModules(bool delete_locations); 797 798 /// Called as the last function in Process::DidExec(). 799 /// 800 /// Process::DidExec() will clear a lot of state in the process, 801 /// then try to reload a dynamic loader plugin to discover what 802 /// binaries are currently available and then this function should 803 /// be called to allow the target to do any cleanup after everything 804 /// has been figured out. It can remove breakpoints that no longer 805 /// make sense as the exec might have changed the target 806 /// architecture, and unloaded some modules that might get deleted. 807 void DidExec(); 808 809 /// Gets the module for the main executable. 810 /// 811 /// Each process has a notion of a main executable that is the file 812 /// that will be executed or attached to. Executable files can have 813 /// dependent modules that are discovered from the object files, or 814 /// discovered at runtime as things are dynamically loaded. 815 /// 816 /// \return 817 /// The shared pointer to the executable module which can 818 /// contains a nullptr Module object if no executable has been 819 /// set. 820 /// 821 /// \see DynamicLoader 822 /// \see ObjectFile::GetDependentModules (FileSpecList&) 823 /// \see Process::SetExecutableModule(lldb::ModuleSP&) 824 lldb::ModuleSP GetExecutableModule(); 825 826 Module *GetExecutableModulePointer(); 827 828 /// Set the main executable module. 829 /// 830 /// Each process has a notion of a main executable that is the file 831 /// that will be executed or attached to. Executable files can have 832 /// dependent modules that are discovered from the object files, or 833 /// discovered at runtime as things are dynamically loaded. 834 /// 835 /// Setting the executable causes any of the current dependent 836 /// image information to be cleared and replaced with the static 837 /// dependent image information found by calling 838 /// ObjectFile::GetDependentModules (FileSpecList&) on the main 839 /// executable and any modules on which it depends. Calling 840 /// Process::GetImages() will return the newly found images that 841 /// were obtained from all of the object files. 842 /// 843 /// \param[in] module_sp 844 /// A shared pointer reference to the module that will become 845 /// the main executable for this process. 846 /// 847 /// \param[in] load_dependent_files 848 /// If \b true then ask the object files to track down any 849 /// known dependent files. 850 /// 851 /// \see ObjectFile::GetDependentModules (FileSpecList&) 852 /// \see Process::GetImages() 853 void SetExecutableModule( 854 lldb::ModuleSP &module_sp, 855 LoadDependentFiles load_dependent_files = eLoadDependentsDefault); 856 857 bool LoadScriptingResources(std::list<Status> &errors, 858 Stream *feedback_stream = nullptr, 859 bool continue_on_error = true) { 860 return m_images.LoadScriptingResourcesInTarget( 861 this, errors, feedback_stream, continue_on_error); 862 } 863 864 /// Get accessor for the images for this process. 865 /// 866 /// Each process has a notion of a main executable that is the file 867 /// that will be executed or attached to. Executable files can have 868 /// dependent modules that are discovered from the object files, or 869 /// discovered at runtime as things are dynamically loaded. After 870 /// a main executable has been set, the images will contain a list 871 /// of all the files that the executable depends upon as far as the 872 /// object files know. These images will usually contain valid file 873 /// virtual addresses only. When the process is launched or attached 874 /// to, the DynamicLoader plug-in will discover where these images 875 /// were loaded in memory and will resolve the load virtual 876 /// addresses is each image, and also in images that are loaded by 877 /// code. 878 /// 879 /// \return 880 /// A list of Module objects in a module list. 881 const ModuleList &GetImages() const { return m_images; } 882 883 ModuleList &GetImages() { return m_images; } 884 885 /// Return whether this FileSpec corresponds to a module that should be 886 /// considered for general searches. 887 /// 888 /// This API will be consulted by the SearchFilterForUnconstrainedSearches 889 /// and any module that returns \b true will not be searched. Note the 890 /// SearchFilterForUnconstrainedSearches is the search filter that 891 /// gets used in the CreateBreakpoint calls when no modules is provided. 892 /// 893 /// The target call at present just consults the Platform's call of the 894 /// same name. 895 /// 896 /// \param[in] module_spec 897 /// Path to the module. 898 /// 899 /// \return \b true if the module should be excluded, \b false otherwise. 900 bool ModuleIsExcludedForUnconstrainedSearches(const FileSpec &module_spec); 901 902 /// Return whether this module should be considered for general searches. 903 /// 904 /// This API will be consulted by the SearchFilterForUnconstrainedSearches 905 /// and any module that returns \b true will not be searched. Note the 906 /// SearchFilterForUnconstrainedSearches is the search filter that 907 /// gets used in the CreateBreakpoint calls when no modules is provided. 908 /// 909 /// The target call at present just consults the Platform's call of the 910 /// same name. 911 /// 912 /// FIXME: When we get time we should add a way for the user to set modules 913 /// that they 914 /// don't want searched, in addition to or instead of the platform ones. 915 /// 916 /// \param[in] module_sp 917 /// A shared pointer reference to the module that checked. 918 /// 919 /// \return \b true if the module should be excluded, \b false otherwise. 920 bool 921 ModuleIsExcludedForUnconstrainedSearches(const lldb::ModuleSP &module_sp); 922 923 const ArchSpec &GetArchitecture() const { return m_arch.GetSpec(); } 924 925 /// Set the architecture for this target. 926 /// 927 /// If the current target has no Images read in, then this just sets the 928 /// architecture, which will be used to select the architecture of the 929 /// ExecutableModule when that is set. If the current target has an 930 /// ExecutableModule, then calling SetArchitecture with a different 931 /// architecture from the currently selected one will reset the 932 /// ExecutableModule to that slice of the file backing the ExecutableModule. 933 /// If the file backing the ExecutableModule does not contain a fork of this 934 /// architecture, then this code will return false, and the architecture 935 /// won't be changed. If the input arch_spec is the same as the already set 936 /// architecture, this is a no-op. 937 /// 938 /// \param[in] arch_spec 939 /// The new architecture. 940 /// 941 /// \param[in] set_platform 942 /// If \b true, then the platform will be adjusted if the currently 943 /// selected platform is not compatible with the archicture being set. 944 /// If \b false, then just the architecture will be set even if the 945 /// currently selected platform isn't compatible (in case it might be 946 /// manually set following this function call). 947 /// 948 /// \return 949 /// \b true if the architecture was successfully set, \bfalse otherwise. 950 bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform = false); 951 952 bool MergeArchitecture(const ArchSpec &arch_spec); 953 954 Architecture *GetArchitecturePlugin() const { return m_arch.GetPlugin(); } 955 956 Debugger &GetDebugger() { return m_debugger; } 957 958 size_t ReadMemoryFromFileCache(const Address &addr, void *dst, size_t dst_len, 959 Status &error); 960 961 // Reading memory through the target allows us to skip going to the process 962 // for reading memory if possible and it allows us to try and read from any 963 // constant sections in our object files on disk. If you always want live 964 // program memory, read straight from the process. If you possibly want to 965 // read from const sections in object files, read from the target. This 966 // version of ReadMemory will try and read memory from the process if the 967 // process is alive. The order is: 968 // 1 - if (prefer_file_cache == true) then read from object file cache 969 // 2 - if there is a valid process, try and read from its memory 970 // 3 - if (prefer_file_cache == false) then read from object file cache 971 size_t ReadMemory(const Address &addr, bool prefer_file_cache, void *dst, 972 size_t dst_len, Status &error, 973 lldb::addr_t *load_addr_ptr = nullptr); 974 975 size_t ReadCStringFromMemory(const Address &addr, std::string &out_str, 976 Status &error); 977 978 size_t ReadCStringFromMemory(const Address &addr, char *dst, 979 size_t dst_max_len, Status &result_error); 980 981 size_t ReadScalarIntegerFromMemory(const Address &addr, 982 bool prefer_file_cache, uint32_t byte_size, 983 bool is_signed, Scalar &scalar, 984 Status &error); 985 986 uint64_t ReadUnsignedIntegerFromMemory(const Address &addr, 987 bool prefer_file_cache, 988 size_t integer_byte_size, 989 uint64_t fail_value, Status &error); 990 991 bool ReadPointerFromMemory(const Address &addr, bool prefer_file_cache, 992 Status &error, Address &pointer_addr); 993 994 SectionLoadList &GetSectionLoadList() { 995 return m_section_load_history.GetCurrentSectionLoadList(); 996 } 997 998 static Target *GetTargetFromContexts(const ExecutionContext *exe_ctx_ptr, 999 const SymbolContext *sc_ptr); 1000 1001 // lldb::ExecutionContextScope pure virtual functions 1002 lldb::TargetSP CalculateTarget() override; 1003 1004 lldb::ProcessSP CalculateProcess() override; 1005 1006 lldb::ThreadSP CalculateThread() override; 1007 1008 lldb::StackFrameSP CalculateStackFrame() override; 1009 1010 void CalculateExecutionContext(ExecutionContext &exe_ctx) override; 1011 1012 PathMappingList &GetImageSearchPathList(); 1013 1014 llvm::Expected<TypeSystem &> 1015 GetScratchTypeSystemForLanguage(lldb::LanguageType language, 1016 bool create_on_demand = true); 1017 1018 std::vector<TypeSystem *> GetScratchTypeSystems(bool create_on_demand = true); 1019 1020 PersistentExpressionState * 1021 GetPersistentExpressionStateForLanguage(lldb::LanguageType language); 1022 1023 // Creates a UserExpression for the given language, the rest of the 1024 // parameters have the same meaning as for the UserExpression constructor. 1025 // Returns a new-ed object which the caller owns. 1026 1027 UserExpression * 1028 GetUserExpressionForLanguage(llvm::StringRef expr, llvm::StringRef prefix, 1029 lldb::LanguageType language, 1030 Expression::ResultType desired_type, 1031 const EvaluateExpressionOptions &options, 1032 ValueObject *ctx_obj, Status &error); 1033 1034 // Creates a FunctionCaller for the given language, the rest of the 1035 // parameters have the same meaning as for the FunctionCaller constructor. 1036 // Since a FunctionCaller can't be 1037 // IR Interpreted, it makes no sense to call this with an 1038 // ExecutionContextScope that lacks 1039 // a Process. 1040 // Returns a new-ed object which the caller owns. 1041 1042 FunctionCaller *GetFunctionCallerForLanguage(lldb::LanguageType language, 1043 const CompilerType &return_type, 1044 const Address &function_address, 1045 const ValueList &arg_value_list, 1046 const char *name, Status &error); 1047 1048 // Creates a UtilityFunction for the given language, the rest of the 1049 // parameters have the same meaning as for the UtilityFunction constructor. 1050 // Returns a new-ed object which the caller owns. 1051 1052 UtilityFunction *GetUtilityFunctionForLanguage(const char *expr, 1053 lldb::LanguageType language, 1054 const char *name, 1055 Status &error); 1056 1057 lldb::ClangASTImporterSP GetClangASTImporter(); 1058 1059 // Install any files through the platform that need be to installed prior to 1060 // launching or attaching. 1061 Status Install(ProcessLaunchInfo *launch_info); 1062 1063 bool ResolveFileAddress(lldb::addr_t load_addr, Address &so_addr); 1064 1065 bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, 1066 uint32_t stop_id = SectionLoadHistory::eStopIDNow); 1067 1068 bool SetSectionLoadAddress(const lldb::SectionSP §ion, 1069 lldb::addr_t load_addr, 1070 bool warn_multiple = false); 1071 1072 size_t UnloadModuleSections(const lldb::ModuleSP &module_sp); 1073 1074 size_t UnloadModuleSections(const ModuleList &module_list); 1075 1076 bool SetSectionUnloaded(const lldb::SectionSP §ion_sp); 1077 1078 bool SetSectionUnloaded(const lldb::SectionSP §ion_sp, 1079 lldb::addr_t load_addr); 1080 1081 void ClearAllLoadedSections(); 1082 1083 // Since expressions results can persist beyond the lifetime of a process, 1084 // and the const expression results are available after a process is gone, we 1085 // provide a way for expressions to be evaluated from the Target itself. If 1086 // an expression is going to be run, then it should have a frame filled in in 1087 // the execution context. 1088 lldb::ExpressionResults EvaluateExpression( 1089 llvm::StringRef expression, ExecutionContextScope *exe_scope, 1090 lldb::ValueObjectSP &result_valobj_sp, 1091 const EvaluateExpressionOptions &options = EvaluateExpressionOptions(), 1092 std::string *fixed_expression = nullptr, ValueObject *ctx_obj = nullptr); 1093 1094 lldb::ExpressionVariableSP GetPersistentVariable(ConstString name); 1095 1096 /// Return the next available number for numbered persistent variables. 1097 unsigned GetNextPersistentVariableIndex() { 1098 return m_next_persistent_variable_index++; 1099 } 1100 1101 lldb::addr_t GetPersistentSymbol(ConstString name); 1102 1103 /// This method will return the address of the starting function for 1104 /// this binary, e.g. main() or its equivalent. This can be used as 1105 /// an address of a function that is not called once a binary has 1106 /// started running - e.g. as a return address for inferior function 1107 /// calls that are unambiguous completion of the function call, not 1108 /// called during the course of the inferior function code running. 1109 /// 1110 /// If no entry point can be found, an invalid address is returned. 1111 /// 1112 /// \param [out] err 1113 /// This object will be set to failure if no entry address could 1114 /// be found, and may contain a helpful error message. 1115 // 1116 /// \return 1117 /// Returns the entry address for this program, or an error 1118 /// if none can be found. 1119 llvm::Expected<lldb_private::Address> GetEntryPointAddress(); 1120 1121 // Target Stop Hooks 1122 class StopHook : public UserID { 1123 public: 1124 StopHook(const StopHook &rhs); 1125 1126 ~StopHook(); 1127 1128 StringList *GetCommandPointer() { return &m_commands; } 1129 1130 const StringList &GetCommands() { return m_commands; } 1131 1132 lldb::TargetSP &GetTarget() { return m_target_sp; } 1133 1134 void SetCommands(StringList &in_commands) { m_commands = in_commands; } 1135 1136 // Set the specifier. The stop hook will own the specifier, and is 1137 // responsible for deleting it when we're done. 1138 void SetSpecifier(SymbolContextSpecifier *specifier); 1139 1140 SymbolContextSpecifier *GetSpecifier() { return m_specifier_sp.get(); } 1141 1142 // Set the Thread Specifier. The stop hook will own the thread specifier, 1143 // and is responsible for deleting it when we're done. 1144 void SetThreadSpecifier(ThreadSpec *specifier); 1145 1146 ThreadSpec *GetThreadSpecifier() { return m_thread_spec_up.get(); } 1147 1148 bool IsActive() { return m_active; } 1149 1150 void SetIsActive(bool is_active) { m_active = is_active; } 1151 1152 void SetAutoContinue(bool auto_continue) { 1153 m_auto_continue = auto_continue; 1154 } 1155 1156 bool GetAutoContinue() const { return m_auto_continue; } 1157 1158 void GetDescription(Stream *s, lldb::DescriptionLevel level) const; 1159 1160 private: 1161 lldb::TargetSP m_target_sp; 1162 StringList m_commands; 1163 lldb::SymbolContextSpecifierSP m_specifier_sp; 1164 std::unique_ptr<ThreadSpec> m_thread_spec_up; 1165 bool m_active = true; 1166 bool m_auto_continue = false; 1167 1168 // Use CreateStopHook to make a new empty stop hook. The GetCommandPointer 1169 // and fill it with commands, and SetSpecifier to set the specifier shared 1170 // pointer (can be null, that will match anything.) 1171 StopHook(lldb::TargetSP target_sp, lldb::user_id_t uid); 1172 friend class Target; 1173 }; 1174 typedef std::shared_ptr<StopHook> StopHookSP; 1175 1176 // Add an empty stop hook to the Target's stop hook list, and returns a 1177 // shared pointer to it in new_hook. Returns the id of the new hook. 1178 StopHookSP CreateStopHook(); 1179 1180 void RunStopHooks(); 1181 1182 size_t GetStopHookSize(); 1183 1184 bool SetSuppresStopHooks(bool suppress) { 1185 bool old_value = m_suppress_stop_hooks; 1186 m_suppress_stop_hooks = suppress; 1187 return old_value; 1188 } 1189 1190 bool GetSuppressStopHooks() { return m_suppress_stop_hooks; } 1191 1192 bool RemoveStopHookByID(lldb::user_id_t uid); 1193 1194 void RemoveAllStopHooks(); 1195 1196 StopHookSP GetStopHookByID(lldb::user_id_t uid); 1197 1198 bool SetStopHookActiveStateByID(lldb::user_id_t uid, bool active_state); 1199 1200 void SetAllStopHooksActiveState(bool active_state); 1201 1202 size_t GetNumStopHooks() const { return m_stop_hooks.size(); } 1203 1204 StopHookSP GetStopHookAtIndex(size_t index) { 1205 if (index >= GetNumStopHooks()) 1206 return StopHookSP(); 1207 StopHookCollection::iterator pos = m_stop_hooks.begin(); 1208 1209 while (index > 0) { 1210 pos++; 1211 index--; 1212 } 1213 return (*pos).second; 1214 } 1215 1216 lldb::PlatformSP GetPlatform() { return m_platform_sp; } 1217 1218 void SetPlatform(const lldb::PlatformSP &platform_sp) { 1219 m_platform_sp = platform_sp; 1220 } 1221 1222 SourceManager &GetSourceManager(); 1223 1224 ClangModulesDeclVendor *GetClangModulesDeclVendor(); 1225 1226 // Methods. 1227 lldb::SearchFilterSP 1228 GetSearchFilterForModule(const FileSpec *containingModule); 1229 1230 lldb::SearchFilterSP 1231 GetSearchFilterForModuleList(const FileSpecList *containingModuleList); 1232 1233 lldb::SearchFilterSP 1234 GetSearchFilterForModuleAndCUList(const FileSpecList *containingModules, 1235 const FileSpecList *containingSourceFiles); 1236 1237 lldb::REPLSP GetREPL(Status &err, lldb::LanguageType language, 1238 const char *repl_options, bool can_create); 1239 1240 void SetREPL(lldb::LanguageType language, lldb::REPLSP repl_sp); 1241 1242 protected: 1243 /// Implementing of ModuleList::Notifier. 1244 1245 void NotifyModuleAdded(const ModuleList &module_list, 1246 const lldb::ModuleSP &module_sp) override; 1247 1248 void NotifyModuleRemoved(const ModuleList &module_list, 1249 const lldb::ModuleSP &module_sp) override; 1250 1251 void NotifyModuleUpdated(const ModuleList &module_list, 1252 const lldb::ModuleSP &old_module_sp, 1253 const lldb::ModuleSP &new_module_sp) override; 1254 1255 void NotifyWillClearList(const ModuleList &module_list) override; 1256 1257 void NotifyModulesRemoved(lldb_private::ModuleList &module_list) override; 1258 1259 class Arch { 1260 public: 1261 explicit Arch(const ArchSpec &spec); 1262 const Arch &operator=(const ArchSpec &spec); 1263 1264 const ArchSpec &GetSpec() const { return m_spec; } 1265 Architecture *GetPlugin() const { return m_plugin_up.get(); } 1266 1267 private: 1268 ArchSpec m_spec; 1269 std::unique_ptr<Architecture> m_plugin_up; 1270 }; 1271 // Member variables. 1272 Debugger &m_debugger; 1273 lldb::PlatformSP m_platform_sp; ///< The platform for this target. 1274 std::recursive_mutex m_mutex; ///< An API mutex that is used by the lldb::SB* 1275 /// classes make the SB interface thread safe 1276 /// When the private state thread calls SB API's - usually because it is 1277 /// running OS plugin or Python ThreadPlan code - it should not block on the 1278 /// API mutex that is held by the code that kicked off the sequence of events 1279 /// that led us to run the code. We hand out this mutex instead when we 1280 /// detect that code is running on the private state thread. 1281 std::recursive_mutex m_private_mutex; 1282 Arch m_arch; 1283 ModuleList m_images; ///< The list of images for this process (shared 1284 /// libraries and anything dynamically loaded). 1285 SectionLoadHistory m_section_load_history; 1286 BreakpointList m_breakpoint_list; 1287 BreakpointList m_internal_breakpoint_list; 1288 using BreakpointNameList = std::map<ConstString, BreakpointName *>; 1289 BreakpointNameList m_breakpoint_names; 1290 1291 lldb::BreakpointSP m_last_created_breakpoint; 1292 WatchpointList m_watchpoint_list; 1293 lldb::WatchpointSP m_last_created_watchpoint; 1294 // We want to tightly control the process destruction process so we can 1295 // correctly tear down everything that we need to, so the only class that 1296 // knows about the process lifespan is this target class. 1297 lldb::ProcessSP m_process_sp; 1298 lldb::SearchFilterSP m_search_filter_sp; 1299 PathMappingList m_image_search_paths; 1300 TypeSystemMap m_scratch_type_system_map; 1301 1302 typedef std::map<lldb::LanguageType, lldb::REPLSP> REPLMap; 1303 REPLMap m_repl_map; 1304 1305 lldb::ClangASTImporterSP m_ast_importer_sp; 1306 lldb::ClangModulesDeclVendorUP m_clang_modules_decl_vendor_up; 1307 1308 lldb::SourceManagerUP m_source_manager_up; 1309 1310 typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection; 1311 StopHookCollection m_stop_hooks; 1312 lldb::user_id_t m_stop_hook_next_id; 1313 bool m_valid; 1314 bool m_suppress_stop_hooks; 1315 bool m_is_dummy_target; 1316 unsigned m_next_persistent_variable_index = 0; 1317 1318 static void ImageSearchPathsChanged(const PathMappingList &path_list, 1319 void *baton); 1320 1321 // Utilities for `statistics` command. 1322 private: 1323 std::vector<uint32_t> m_stats_storage; 1324 bool m_collecting_stats = false; 1325 1326 public: 1327 void SetCollectingStats(bool v) { m_collecting_stats = v; } 1328 1329 bool GetCollectingStats() { return m_collecting_stats; } 1330 1331 void IncrementStats(lldb_private::StatisticKind key) { 1332 if (!GetCollectingStats()) 1333 return; 1334 lldbassert(key < lldb_private::StatisticKind::StatisticMax && 1335 "invalid statistics!"); 1336 m_stats_storage[key] += 1; 1337 } 1338 1339 std::vector<uint32_t> GetStatistics() { return m_stats_storage; } 1340 1341 private: 1342 /// Construct with optional file and arch. 1343 /// 1344 /// This member is private. Clients must use 1345 /// TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 1346 /// so all targets can be tracked from the central target list. 1347 /// 1348 /// \see TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 1349 Target(Debugger &debugger, const ArchSpec &target_arch, 1350 const lldb::PlatformSP &platform_sp, bool is_dummy_target); 1351 1352 // Helper function. 1353 bool ProcessIsValid(); 1354 1355 // Copy breakpoints, stop hooks and so forth from the dummy target: 1356 void PrimeFromDummyTarget(Target *dummy_target); 1357 1358 void AddBreakpoint(lldb::BreakpointSP breakpoint_sp, bool internal); 1359 1360 void FinalizeFileActions(ProcessLaunchInfo &info); 1361 1362 DISALLOW_COPY_AND_ASSIGN(Target); 1363 }; 1364 1365 } // namespace lldb_private 1366 1367 #endif // liblldb_Target_h_ 1368