10b57cec5SDimitry Andric //===-- Target.h ------------------------------------------------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 95ffd83dbSDimitry Andric #ifndef LLDB_TARGET_TARGET_H 105ffd83dbSDimitry Andric #define LLDB_TARGET_TARGET_H 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include <list> 130b57cec5SDimitry Andric #include <map> 140b57cec5SDimitry Andric #include <memory> 150b57cec5SDimitry Andric #include <string> 160b57cec5SDimitry Andric #include <vector> 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointList.h" 190b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointName.h" 200b57cec5SDimitry Andric #include "lldb/Breakpoint/WatchpointList.h" 210b57cec5SDimitry Andric #include "lldb/Core/Architecture.h" 220b57cec5SDimitry Andric #include "lldb/Core/Disassembler.h" 230b57cec5SDimitry Andric #include "lldb/Core/ModuleList.h" 240eae32dcSDimitry Andric #include "lldb/Core/StructuredDataImpl.h" 250b57cec5SDimitry Andric #include "lldb/Core/UserSettingsController.h" 260b57cec5SDimitry Andric #include "lldb/Expression/Expression.h" 270b57cec5SDimitry Andric #include "lldb/Host/ProcessLaunchInfo.h" 280b57cec5SDimitry Andric #include "lldb/Symbol/TypeSystem.h" 290b57cec5SDimitry Andric #include "lldb/Target/ExecutionContextScope.h" 300b57cec5SDimitry Andric #include "lldb/Target/PathMappingList.h" 310b57cec5SDimitry Andric #include "lldb/Target/SectionLoadHistory.h" 32349cc55cSDimitry Andric #include "lldb/Target/Statistics.h" 33e8d8bef9SDimitry Andric #include "lldb/Target/ThreadSpec.h" 340b57cec5SDimitry Andric #include "lldb/Utility/ArchSpec.h" 350b57cec5SDimitry Andric #include "lldb/Utility/Broadcaster.h" 360b57cec5SDimitry Andric #include "lldb/Utility/LLDBAssert.h" 370b57cec5SDimitry Andric #include "lldb/Utility/Timeout.h" 380b57cec5SDimitry Andric #include "lldb/lldb-public.h" 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric namespace lldb_private { 410b57cec5SDimitry Andric 420b57cec5SDimitry Andric OptionEnumValues GetDynamicValueTypes(); 430b57cec5SDimitry Andric 440b57cec5SDimitry Andric enum InlineStrategy { 450b57cec5SDimitry Andric eInlineBreakpointsNever = 0, 460b57cec5SDimitry Andric eInlineBreakpointsHeaders, 470b57cec5SDimitry Andric eInlineBreakpointsAlways 480b57cec5SDimitry Andric }; 490b57cec5SDimitry Andric 500b57cec5SDimitry Andric enum LoadScriptFromSymFile { 510b57cec5SDimitry Andric eLoadScriptFromSymFileTrue, 520b57cec5SDimitry Andric eLoadScriptFromSymFileFalse, 530b57cec5SDimitry Andric eLoadScriptFromSymFileWarn 540b57cec5SDimitry Andric }; 550b57cec5SDimitry Andric 560b57cec5SDimitry Andric enum LoadCWDlldbinitFile { 570b57cec5SDimitry Andric eLoadCWDlldbinitTrue, 580b57cec5SDimitry Andric eLoadCWDlldbinitFalse, 590b57cec5SDimitry Andric eLoadCWDlldbinitWarn 600b57cec5SDimitry Andric }; 610b57cec5SDimitry Andric 62e8d8bef9SDimitry Andric enum ImportStdModule { 63e8d8bef9SDimitry Andric eImportStdModuleFalse, 64e8d8bef9SDimitry Andric eImportStdModuleFallback, 65e8d8bef9SDimitry Andric eImportStdModuleTrue, 66e8d8bef9SDimitry Andric }; 67e8d8bef9SDimitry Andric 6881ad6265SDimitry Andric enum DynamicClassInfoHelper { 6981ad6265SDimitry Andric eDynamicClassInfoHelperAuto, 7081ad6265SDimitry Andric eDynamicClassInfoHelperRealizedClassesStruct, 7181ad6265SDimitry Andric eDynamicClassInfoHelperCopyRealizedClassList, 7281ad6265SDimitry Andric eDynamicClassInfoHelperGetRealizedClassList, 7381ad6265SDimitry Andric }; 7481ad6265SDimitry Andric 750b57cec5SDimitry Andric class TargetExperimentalProperties : public Properties { 760b57cec5SDimitry Andric public: 770b57cec5SDimitry Andric TargetExperimentalProperties(); 780b57cec5SDimitry Andric }; 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric class TargetProperties : public Properties { 810b57cec5SDimitry Andric public: 820b57cec5SDimitry Andric TargetProperties(Target *target); 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric ~TargetProperties() override; 850b57cec5SDimitry Andric 860b57cec5SDimitry Andric ArchSpec GetDefaultArchitecture() const; 870b57cec5SDimitry Andric 880b57cec5SDimitry Andric void SetDefaultArchitecture(const ArchSpec &arch); 890b57cec5SDimitry Andric 900b57cec5SDimitry Andric bool GetMoveToNearestCode() const; 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric lldb::DynamicValueType GetPreferDynamicValue() const; 930b57cec5SDimitry Andric 940b57cec5SDimitry Andric bool SetPreferDynamicValue(lldb::DynamicValueType d); 950b57cec5SDimitry Andric 960b57cec5SDimitry Andric bool GetPreloadSymbols() const; 970b57cec5SDimitry Andric 980b57cec5SDimitry Andric void SetPreloadSymbols(bool b); 990b57cec5SDimitry Andric 1000b57cec5SDimitry Andric bool GetDisableASLR() const; 1010b57cec5SDimitry Andric 1020b57cec5SDimitry Andric void SetDisableASLR(bool b); 1030b57cec5SDimitry Andric 104e8d8bef9SDimitry Andric bool GetInheritTCC() const; 105e8d8bef9SDimitry Andric 106e8d8bef9SDimitry Andric void SetInheritTCC(bool b); 107e8d8bef9SDimitry Andric 1080b57cec5SDimitry Andric bool GetDetachOnError() const; 1090b57cec5SDimitry Andric 1100b57cec5SDimitry Andric void SetDetachOnError(bool b); 1110b57cec5SDimitry Andric 1120b57cec5SDimitry Andric bool GetDisableSTDIO() const; 1130b57cec5SDimitry Andric 1140b57cec5SDimitry Andric void SetDisableSTDIO(bool b); 1150b57cec5SDimitry Andric 1160b57cec5SDimitry Andric const char *GetDisassemblyFlavor() const; 1170b57cec5SDimitry Andric 1180b57cec5SDimitry Andric InlineStrategy GetInlineStrategy() const; 1190b57cec5SDimitry Andric 1200b57cec5SDimitry Andric llvm::StringRef GetArg0() const; 1210b57cec5SDimitry Andric 1220b57cec5SDimitry Andric void SetArg0(llvm::StringRef arg); 1230b57cec5SDimitry Andric 1240b57cec5SDimitry Andric bool GetRunArguments(Args &args) const; 1250b57cec5SDimitry Andric 1260b57cec5SDimitry Andric void SetRunArguments(const Args &args); 1270b57cec5SDimitry Andric 128349cc55cSDimitry Andric // Get the whole environment including the platform inherited environment and 129349cc55cSDimitry Andric // the target specific environment, excluding the unset environment variables. 1300b57cec5SDimitry Andric Environment GetEnvironment() const; 131349cc55cSDimitry Andric // Get the platform inherited environment, excluding the unset environment 132349cc55cSDimitry Andric // variables. 133349cc55cSDimitry Andric Environment GetInheritedEnvironment() const; 134349cc55cSDimitry Andric // Get the target specific environment only, without the platform inherited 135349cc55cSDimitry Andric // environment. 136349cc55cSDimitry Andric Environment GetTargetEnvironment() const; 137349cc55cSDimitry Andric // Set the target specific environment. 1380b57cec5SDimitry Andric void SetEnvironment(Environment env); 1390b57cec5SDimitry Andric 1400b57cec5SDimitry Andric bool GetSkipPrologue() const; 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andric PathMappingList &GetSourcePathMap() const; 1430b57cec5SDimitry Andric 144bdd1243dSDimitry Andric bool GetAutoSourceMapRelative() const; 145bdd1243dSDimitry Andric 1460b57cec5SDimitry Andric FileSpecList GetExecutableSearchPaths(); 1470b57cec5SDimitry Andric 1480b57cec5SDimitry Andric void AppendExecutableSearchPaths(const FileSpec &); 1490b57cec5SDimitry Andric 1500b57cec5SDimitry Andric FileSpecList GetDebugFileSearchPaths(); 1510b57cec5SDimitry Andric 1520b57cec5SDimitry Andric FileSpecList GetClangModuleSearchPaths(); 1530b57cec5SDimitry Andric 1540b57cec5SDimitry Andric bool GetEnableAutoImportClangModules() const; 1550b57cec5SDimitry Andric 156e8d8bef9SDimitry Andric ImportStdModule GetImportStdModule() const; 1570b57cec5SDimitry Andric 15881ad6265SDimitry Andric DynamicClassInfoHelper GetDynamicClassInfoHelper() const; 15981ad6265SDimitry Andric 1600b57cec5SDimitry Andric bool GetEnableAutoApplyFixIts() const; 1610b57cec5SDimitry Andric 1625ffd83dbSDimitry Andric uint64_t GetNumberOfRetriesWithFixits() const; 1635ffd83dbSDimitry Andric 1640b57cec5SDimitry Andric bool GetEnableNotifyAboutFixIts() const; 1650b57cec5SDimitry Andric 16681ad6265SDimitry Andric FileSpec GetSaveJITObjectsDir() const; 1670b57cec5SDimitry Andric 1680b57cec5SDimitry Andric bool GetEnableSyntheticValue() const; 1690b57cec5SDimitry Andric 1705f757f3fSDimitry Andric bool ShowHexVariableValuesWithLeadingZeroes() const; 1715f757f3fSDimitry Andric 1729dba64beSDimitry Andric uint32_t GetMaxZeroPaddingInFloatFormat() const; 1739dba64beSDimitry Andric 1740b57cec5SDimitry Andric uint32_t GetMaximumNumberOfChildrenToDisplay() const; 1750b57cec5SDimitry Andric 17681ad6265SDimitry Andric /// Get the max depth value, augmented with a bool to indicate whether the 17781ad6265SDimitry Andric /// depth is the default. 17881ad6265SDimitry Andric /// 17981ad6265SDimitry Andric /// When the user has customized the max depth, the bool will be false. 18081ad6265SDimitry Andric /// 18181ad6265SDimitry Andric /// \returns the max depth, and true if the max depth is the system default, 18281ad6265SDimitry Andric /// otherwise false. 18381ad6265SDimitry Andric std::pair<uint32_t, bool> GetMaximumDepthOfChildrenToDisplay() const; 18481ad6265SDimitry Andric 1850b57cec5SDimitry Andric uint32_t GetMaximumSizeOfStringSummary() const; 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric uint32_t GetMaximumMemReadSize() const; 1880b57cec5SDimitry Andric 1890b57cec5SDimitry Andric FileSpec GetStandardInputPath() const; 1900b57cec5SDimitry Andric FileSpec GetStandardErrorPath() const; 1910b57cec5SDimitry Andric FileSpec GetStandardOutputPath() const; 1920b57cec5SDimitry Andric 1930b57cec5SDimitry Andric void SetStandardInputPath(llvm::StringRef path); 1940b57cec5SDimitry Andric void SetStandardOutputPath(llvm::StringRef path); 1950b57cec5SDimitry Andric void SetStandardErrorPath(llvm::StringRef path); 1960b57cec5SDimitry Andric 1970b57cec5SDimitry Andric void SetStandardInputPath(const char *path) = delete; 1980b57cec5SDimitry Andric void SetStandardOutputPath(const char *path) = delete; 1990b57cec5SDimitry Andric void SetStandardErrorPath(const char *path) = delete; 2000b57cec5SDimitry Andric 2010b57cec5SDimitry Andric bool GetBreakpointsConsultPlatformAvoidList(); 2020b57cec5SDimitry Andric 2030b57cec5SDimitry Andric lldb::LanguageType GetLanguage() const; 2040b57cec5SDimitry Andric 2050b57cec5SDimitry Andric llvm::StringRef GetExpressionPrefixContents(); 2060b57cec5SDimitry Andric 207e8d8bef9SDimitry Andric uint64_t GetExprErrorLimit() const; 208e8d8bef9SDimitry Andric 20906c3fb27SDimitry Andric uint64_t GetExprAllocAddress() const; 21006c3fb27SDimitry Andric 21106c3fb27SDimitry Andric uint64_t GetExprAllocSize() const; 21206c3fb27SDimitry Andric 21306c3fb27SDimitry Andric uint64_t GetExprAllocAlign() const; 21406c3fb27SDimitry Andric 2150b57cec5SDimitry Andric bool GetUseHexImmediates() const; 2160b57cec5SDimitry Andric 2170b57cec5SDimitry Andric bool GetUseFastStepping() const; 2180b57cec5SDimitry Andric 2190b57cec5SDimitry Andric bool GetDisplayExpressionsInCrashlogs() const; 2200b57cec5SDimitry Andric 2210b57cec5SDimitry Andric LoadScriptFromSymFile GetLoadScriptFromSymbolFile() const; 2220b57cec5SDimitry Andric 2230b57cec5SDimitry Andric LoadCWDlldbinitFile GetLoadCWDlldbinitFile() const; 2240b57cec5SDimitry Andric 2250b57cec5SDimitry Andric Disassembler::HexImmediateStyle GetHexImmediateStyle() const; 2260b57cec5SDimitry Andric 2270b57cec5SDimitry Andric MemoryModuleLoadLevel GetMemoryModuleLoadLevel() const; 2280b57cec5SDimitry Andric 2290b57cec5SDimitry Andric bool GetUserSpecifiedTrapHandlerNames(Args &args) const; 2300b57cec5SDimitry Andric 2310b57cec5SDimitry Andric void SetUserSpecifiedTrapHandlerNames(const Args &args); 2320b57cec5SDimitry Andric 2330b57cec5SDimitry Andric bool GetDisplayRuntimeSupportValues() const; 2340b57cec5SDimitry Andric 2350b57cec5SDimitry Andric void SetDisplayRuntimeSupportValues(bool b); 2360b57cec5SDimitry Andric 2370b57cec5SDimitry Andric bool GetDisplayRecognizedArguments() const; 2380b57cec5SDimitry Andric 2390b57cec5SDimitry Andric void SetDisplayRecognizedArguments(bool b); 2400b57cec5SDimitry Andric 241fe6060f1SDimitry Andric const ProcessLaunchInfo &GetProcessLaunchInfo() const; 2420b57cec5SDimitry Andric 2430b57cec5SDimitry Andric void SetProcessLaunchInfo(const ProcessLaunchInfo &launch_info); 2440b57cec5SDimitry Andric 2450b57cec5SDimitry Andric bool GetInjectLocalVariables(ExecutionContext *exe_ctx) const; 2460b57cec5SDimitry Andric 2470b57cec5SDimitry Andric void SetInjectLocalVariables(ExecutionContext *exe_ctx, bool b); 2480b57cec5SDimitry Andric 2490b57cec5SDimitry Andric void SetRequireHardwareBreakpoints(bool b); 2500b57cec5SDimitry Andric 2510b57cec5SDimitry Andric bool GetRequireHardwareBreakpoints() const; 2520b57cec5SDimitry Andric 2535ffd83dbSDimitry Andric bool GetAutoInstallMainExecutable() const; 2545ffd83dbSDimitry Andric 2555ffd83dbSDimitry Andric void UpdateLaunchInfoFromProperties(); 2565ffd83dbSDimitry Andric 257fe6060f1SDimitry Andric void SetDebugUtilityExpression(bool debug); 258fe6060f1SDimitry Andric 259fe6060f1SDimitry Andric bool GetDebugUtilityExpression() const; 260fe6060f1SDimitry Andric 2610b57cec5SDimitry Andric private: 2620b57cec5SDimitry Andric // Callbacks for m_launch_info. 263480093f4SDimitry Andric void Arg0ValueChangedCallback(); 264480093f4SDimitry Andric void RunArgsValueChangedCallback(); 265480093f4SDimitry Andric void EnvVarsValueChangedCallback(); 266480093f4SDimitry Andric void InputPathValueChangedCallback(); 267480093f4SDimitry Andric void OutputPathValueChangedCallback(); 268480093f4SDimitry Andric void ErrorPathValueChangedCallback(); 269480093f4SDimitry Andric void DetachOnErrorValueChangedCallback(); 270480093f4SDimitry Andric void DisableASLRValueChangedCallback(); 271e8d8bef9SDimitry Andric void InheritTCCValueChangedCallback(); 272480093f4SDimitry Andric void DisableSTDIOValueChangedCallback(); 2730b57cec5SDimitry Andric 27481ad6265SDimitry Andric // Settings checker for target.jit-save-objects-dir: 27581ad6265SDimitry Andric void CheckJITObjectsDir(); 27681ad6265SDimitry Andric 2775ffd83dbSDimitry Andric Environment ComputeEnvironment() const; 2785ffd83dbSDimitry Andric 2790b57cec5SDimitry Andric // Member variables. 2800b57cec5SDimitry Andric ProcessLaunchInfo m_launch_info; 2810b57cec5SDimitry Andric std::unique_ptr<TargetExperimentalProperties> m_experimental_properties_up; 2825ffd83dbSDimitry Andric Target *m_target; 2830b57cec5SDimitry Andric }; 2840b57cec5SDimitry Andric 2850b57cec5SDimitry Andric class EvaluateExpressionOptions { 2860b57cec5SDimitry Andric public: 2870b57cec5SDimitry Andric // MSVC has a bug here that reports C4268: 'const' static/global data 2880b57cec5SDimitry Andric // initialized with compiler generated default constructor fills the object 2890b57cec5SDimitry Andric // with zeros. Confirmed that MSVC is *not* zero-initializing, it's just a 2900b57cec5SDimitry Andric // bogus warning. 2910b57cec5SDimitry Andric #if defined(_MSC_VER) 2920b57cec5SDimitry Andric #pragma warning(push) 2930b57cec5SDimitry Andric #pragma warning(disable : 4268) 2940b57cec5SDimitry Andric #endif 2950b57cec5SDimitry Andric static constexpr std::chrono::milliseconds default_timeout{500}; 2960b57cec5SDimitry Andric #if defined(_MSC_VER) 2970b57cec5SDimitry Andric #pragma warning(pop) 2980b57cec5SDimitry Andric #endif 2990b57cec5SDimitry Andric 3000b57cec5SDimitry Andric static constexpr ExecutionPolicy default_execution_policy = 3010b57cec5SDimitry Andric eExecutionPolicyOnlyWhenNeeded; 3020b57cec5SDimitry Andric 3030b57cec5SDimitry Andric EvaluateExpressionOptions() = default; 3040b57cec5SDimitry Andric GetExecutionPolicy()3050b57cec5SDimitry Andric ExecutionPolicy GetExecutionPolicy() const { return m_execution_policy; } 3060b57cec5SDimitry Andric 3070b57cec5SDimitry Andric void SetExecutionPolicy(ExecutionPolicy policy = eExecutionPolicyAlways) { 3080b57cec5SDimitry Andric m_execution_policy = policy; 3090b57cec5SDimitry Andric } 3100b57cec5SDimitry Andric GetLanguage()3110b57cec5SDimitry Andric lldb::LanguageType GetLanguage() const { return m_language; } 3120b57cec5SDimitry Andric SetLanguage(lldb::LanguageType language)3130b57cec5SDimitry Andric void SetLanguage(lldb::LanguageType language) { m_language = language; } 3140b57cec5SDimitry Andric DoesCoerceToId()3150b57cec5SDimitry Andric bool DoesCoerceToId() const { return m_coerce_to_id; } 3160b57cec5SDimitry Andric GetPrefix()3170b57cec5SDimitry Andric const char *GetPrefix() const { 3180b57cec5SDimitry Andric return (m_prefix.empty() ? nullptr : m_prefix.c_str()); 3190b57cec5SDimitry Andric } 3200b57cec5SDimitry Andric SetPrefix(const char * prefix)3210b57cec5SDimitry Andric void SetPrefix(const char *prefix) { 3220b57cec5SDimitry Andric if (prefix && prefix[0]) 3230b57cec5SDimitry Andric m_prefix = prefix; 3240b57cec5SDimitry Andric else 3250b57cec5SDimitry Andric m_prefix.clear(); 3260b57cec5SDimitry Andric } 3270b57cec5SDimitry Andric 3280b57cec5SDimitry Andric void SetCoerceToId(bool coerce = true) { m_coerce_to_id = coerce; } 3290b57cec5SDimitry Andric DoesUnwindOnError()3300b57cec5SDimitry Andric bool DoesUnwindOnError() const { return m_unwind_on_error; } 3310b57cec5SDimitry Andric 3320b57cec5SDimitry Andric void SetUnwindOnError(bool unwind = false) { m_unwind_on_error = unwind; } 3330b57cec5SDimitry Andric DoesIgnoreBreakpoints()3340b57cec5SDimitry Andric bool DoesIgnoreBreakpoints() const { return m_ignore_breakpoints; } 3350b57cec5SDimitry Andric 3360b57cec5SDimitry Andric void SetIgnoreBreakpoints(bool ignore = false) { 3370b57cec5SDimitry Andric m_ignore_breakpoints = ignore; 3380b57cec5SDimitry Andric } 3390b57cec5SDimitry Andric DoesKeepInMemory()3400b57cec5SDimitry Andric bool DoesKeepInMemory() const { return m_keep_in_memory; } 3410b57cec5SDimitry Andric 3420b57cec5SDimitry Andric void SetKeepInMemory(bool keep = true) { m_keep_in_memory = keep; } 3430b57cec5SDimitry Andric GetUseDynamic()3440b57cec5SDimitry Andric lldb::DynamicValueType GetUseDynamic() const { return m_use_dynamic; } 3450b57cec5SDimitry Andric 3460b57cec5SDimitry Andric void 3470b57cec5SDimitry Andric SetUseDynamic(lldb::DynamicValueType dynamic = lldb::eDynamicCanRunTarget) { 3480b57cec5SDimitry Andric m_use_dynamic = dynamic; 3490b57cec5SDimitry Andric } 3500b57cec5SDimitry Andric GetTimeout()3510b57cec5SDimitry Andric const Timeout<std::micro> &GetTimeout() const { return m_timeout; } 3520b57cec5SDimitry Andric SetTimeout(const Timeout<std::micro> & timeout)3530b57cec5SDimitry Andric void SetTimeout(const Timeout<std::micro> &timeout) { m_timeout = timeout; } 3540b57cec5SDimitry Andric GetOneThreadTimeout()3550b57cec5SDimitry Andric const Timeout<std::micro> &GetOneThreadTimeout() const { 3560b57cec5SDimitry Andric return m_one_thread_timeout; 3570b57cec5SDimitry Andric } 3580b57cec5SDimitry Andric SetOneThreadTimeout(const Timeout<std::micro> & timeout)3590b57cec5SDimitry Andric void SetOneThreadTimeout(const Timeout<std::micro> &timeout) { 3600b57cec5SDimitry Andric m_one_thread_timeout = timeout; 3610b57cec5SDimitry Andric } 3620b57cec5SDimitry Andric GetTryAllThreads()3630b57cec5SDimitry Andric bool GetTryAllThreads() const { return m_try_others; } 3640b57cec5SDimitry Andric 3650b57cec5SDimitry Andric void SetTryAllThreads(bool try_others = true) { m_try_others = try_others; } 3660b57cec5SDimitry Andric GetStopOthers()3670b57cec5SDimitry Andric bool GetStopOthers() const { return m_stop_others; } 3680b57cec5SDimitry Andric 3690b57cec5SDimitry Andric void SetStopOthers(bool stop_others = true) { m_stop_others = stop_others; } 3700b57cec5SDimitry Andric GetDebug()3710b57cec5SDimitry Andric bool GetDebug() const { return m_debug; } 3720b57cec5SDimitry Andric SetDebug(bool b)3730b57cec5SDimitry Andric void SetDebug(bool b) { 3740b57cec5SDimitry Andric m_debug = b; 3750b57cec5SDimitry Andric if (m_debug) 3760b57cec5SDimitry Andric m_generate_debug_info = true; 3770b57cec5SDimitry Andric } 3780b57cec5SDimitry Andric GetGenerateDebugInfo()3790b57cec5SDimitry Andric bool GetGenerateDebugInfo() const { return m_generate_debug_info; } 3800b57cec5SDimitry Andric SetGenerateDebugInfo(bool b)3810b57cec5SDimitry Andric void SetGenerateDebugInfo(bool b) { m_generate_debug_info = b; } 3820b57cec5SDimitry Andric GetColorizeErrors()3830b57cec5SDimitry Andric bool GetColorizeErrors() const { return m_ansi_color_errors; } 3840b57cec5SDimitry Andric SetColorizeErrors(bool b)3850b57cec5SDimitry Andric void SetColorizeErrors(bool b) { m_ansi_color_errors = b; } 3860b57cec5SDimitry Andric GetTrapExceptions()3870b57cec5SDimitry Andric bool GetTrapExceptions() const { return m_trap_exceptions; } 3880b57cec5SDimitry Andric SetTrapExceptions(bool b)3890b57cec5SDimitry Andric void SetTrapExceptions(bool b) { m_trap_exceptions = b; } 3900b57cec5SDimitry Andric GetREPLEnabled()3910b57cec5SDimitry Andric bool GetREPLEnabled() const { return m_repl; } 3920b57cec5SDimitry Andric SetREPLEnabled(bool b)3930b57cec5SDimitry Andric void SetREPLEnabled(bool b) { m_repl = b; } 3940b57cec5SDimitry Andric SetCancelCallback(lldb::ExpressionCancelCallback callback,void * baton)3950b57cec5SDimitry Andric void SetCancelCallback(lldb::ExpressionCancelCallback callback, void *baton) { 3960b57cec5SDimitry Andric m_cancel_callback_baton = baton; 3970b57cec5SDimitry Andric m_cancel_callback = callback; 3980b57cec5SDimitry Andric } 3990b57cec5SDimitry Andric InvokeCancelCallback(lldb::ExpressionEvaluationPhase phase)4000b57cec5SDimitry Andric bool InvokeCancelCallback(lldb::ExpressionEvaluationPhase phase) const { 4010b57cec5SDimitry Andric return ((m_cancel_callback != nullptr) 4020b57cec5SDimitry Andric ? m_cancel_callback(phase, m_cancel_callback_baton) 4030b57cec5SDimitry Andric : false); 4040b57cec5SDimitry Andric } 4050b57cec5SDimitry Andric 4060b57cec5SDimitry Andric // Allows the expression contents to be remapped to point to the specified 4070b57cec5SDimitry Andric // file and line using #line directives. SetPoundLine(const char * path,uint32_t line)4080b57cec5SDimitry Andric void SetPoundLine(const char *path, uint32_t line) const { 4090b57cec5SDimitry Andric if (path && path[0]) { 4100b57cec5SDimitry Andric m_pound_line_file = path; 4110b57cec5SDimitry Andric m_pound_line_line = line; 4120b57cec5SDimitry Andric } else { 4130b57cec5SDimitry Andric m_pound_line_file.clear(); 4140b57cec5SDimitry Andric m_pound_line_line = 0; 4150b57cec5SDimitry Andric } 4160b57cec5SDimitry Andric } 4170b57cec5SDimitry Andric GetPoundLineFilePath()4180b57cec5SDimitry Andric const char *GetPoundLineFilePath() const { 4190b57cec5SDimitry Andric return (m_pound_line_file.empty() ? nullptr : m_pound_line_file.c_str()); 4200b57cec5SDimitry Andric } 4210b57cec5SDimitry Andric GetPoundLineLine()4220b57cec5SDimitry Andric uint32_t GetPoundLineLine() const { return m_pound_line_line; } 4230b57cec5SDimitry Andric SetSuppressPersistentResult(bool b)42406c3fb27SDimitry Andric void SetSuppressPersistentResult(bool b) { m_suppress_persistent_result = b; } 4250b57cec5SDimitry Andric GetSuppressPersistentResult()42606c3fb27SDimitry Andric bool GetSuppressPersistentResult() const { 42706c3fb27SDimitry Andric return m_suppress_persistent_result; 42806c3fb27SDimitry Andric } 4290b57cec5SDimitry Andric SetAutoApplyFixIts(bool b)4300b57cec5SDimitry Andric void SetAutoApplyFixIts(bool b) { m_auto_apply_fixits = b; } 4310b57cec5SDimitry Andric GetAutoApplyFixIts()4320b57cec5SDimitry Andric bool GetAutoApplyFixIts() const { return m_auto_apply_fixits; } 4330b57cec5SDimitry Andric SetRetriesWithFixIts(uint64_t number_of_retries)4345ffd83dbSDimitry Andric void SetRetriesWithFixIts(uint64_t number_of_retries) { 4355ffd83dbSDimitry Andric m_retries_with_fixits = number_of_retries; 4365ffd83dbSDimitry Andric } 4375ffd83dbSDimitry Andric GetRetriesWithFixIts()4385ffd83dbSDimitry Andric uint64_t GetRetriesWithFixIts() const { return m_retries_with_fixits; } 4395ffd83dbSDimitry Andric IsForUtilityExpr()4400b57cec5SDimitry Andric bool IsForUtilityExpr() const { return m_running_utility_expression; } 4410b57cec5SDimitry Andric SetIsForUtilityExpr(bool b)4420b57cec5SDimitry Andric void SetIsForUtilityExpr(bool b) { m_running_utility_expression = b; } 4430b57cec5SDimitry Andric 4440b57cec5SDimitry Andric private: 4450b57cec5SDimitry Andric ExecutionPolicy m_execution_policy = default_execution_policy; 4460b57cec5SDimitry Andric lldb::LanguageType m_language = lldb::eLanguageTypeUnknown; 4470b57cec5SDimitry Andric std::string m_prefix; 4480b57cec5SDimitry Andric bool m_coerce_to_id = false; 4490b57cec5SDimitry Andric bool m_unwind_on_error = true; 4500b57cec5SDimitry Andric bool m_ignore_breakpoints = false; 4510b57cec5SDimitry Andric bool m_keep_in_memory = false; 4520b57cec5SDimitry Andric bool m_try_others = true; 4530b57cec5SDimitry Andric bool m_stop_others = true; 4540b57cec5SDimitry Andric bool m_debug = false; 4550b57cec5SDimitry Andric bool m_trap_exceptions = true; 4560b57cec5SDimitry Andric bool m_repl = false; 4570b57cec5SDimitry Andric bool m_generate_debug_info = false; 4580b57cec5SDimitry Andric bool m_ansi_color_errors = false; 45906c3fb27SDimitry Andric bool m_suppress_persistent_result = false; 4600b57cec5SDimitry Andric bool m_auto_apply_fixits = true; 4615ffd83dbSDimitry Andric uint64_t m_retries_with_fixits = 1; 4620b57cec5SDimitry Andric /// True if the executed code should be treated as utility code that is only 4630b57cec5SDimitry Andric /// used by LLDB internally. 4640b57cec5SDimitry Andric bool m_running_utility_expression = false; 4650b57cec5SDimitry Andric 4660b57cec5SDimitry Andric lldb::DynamicValueType m_use_dynamic = lldb::eNoDynamicValues; 4670b57cec5SDimitry Andric Timeout<std::micro> m_timeout = default_timeout; 468bdd1243dSDimitry Andric Timeout<std::micro> m_one_thread_timeout = std::nullopt; 4690b57cec5SDimitry Andric lldb::ExpressionCancelCallback m_cancel_callback = nullptr; 4700b57cec5SDimitry Andric void *m_cancel_callback_baton = nullptr; 4710b57cec5SDimitry Andric // If m_pound_line_file is not empty and m_pound_line_line is non-zero, use 4720b57cec5SDimitry Andric // #line %u "%s" before the expression content to remap where the source 4730b57cec5SDimitry Andric // originates 4740b57cec5SDimitry Andric mutable std::string m_pound_line_file; 47581ad6265SDimitry Andric mutable uint32_t m_pound_line_line = 0; 4760b57cec5SDimitry Andric }; 4770b57cec5SDimitry Andric 4780b57cec5SDimitry Andric // Target 4790b57cec5SDimitry Andric class Target : public std::enable_shared_from_this<Target>, 4800b57cec5SDimitry Andric public TargetProperties, 4810b57cec5SDimitry Andric public Broadcaster, 4820b57cec5SDimitry Andric public ExecutionContextScope, 4830b57cec5SDimitry Andric public ModuleList::Notifier { 4840b57cec5SDimitry Andric public: 4850b57cec5SDimitry Andric friend class TargetList; 486e8d8bef9SDimitry Andric friend class Debugger; 4870b57cec5SDimitry Andric 4880b57cec5SDimitry Andric /// Broadcaster event bits definitions. 4890b57cec5SDimitry Andric enum { 4900b57cec5SDimitry Andric eBroadcastBitBreakpointChanged = (1 << 0), 4910b57cec5SDimitry Andric eBroadcastBitModulesLoaded = (1 << 1), 4920b57cec5SDimitry Andric eBroadcastBitModulesUnloaded = (1 << 2), 4930b57cec5SDimitry Andric eBroadcastBitWatchpointChanged = (1 << 3), 494bdd1243dSDimitry Andric eBroadcastBitSymbolsLoaded = (1 << 4), 495bdd1243dSDimitry Andric eBroadcastBitSymbolsChanged = (1 << 5), 4960b57cec5SDimitry Andric }; 4970b57cec5SDimitry Andric 4980b57cec5SDimitry Andric // These two functions fill out the Broadcaster interface: 4990b57cec5SDimitry Andric 5000b57cec5SDimitry Andric static ConstString &GetStaticBroadcasterClass(); 5010b57cec5SDimitry Andric GetBroadcasterClass()5020b57cec5SDimitry Andric ConstString &GetBroadcasterClass() const override { 5030b57cec5SDimitry Andric return GetStaticBroadcasterClass(); 5040b57cec5SDimitry Andric } 5050b57cec5SDimitry Andric 5060b57cec5SDimitry Andric // This event data class is for use by the TargetList to broadcast new target 5070b57cec5SDimitry Andric // notifications. 5080b57cec5SDimitry Andric class TargetEventData : public EventData { 5090b57cec5SDimitry Andric public: 5100b57cec5SDimitry Andric TargetEventData(const lldb::TargetSP &target_sp); 5110b57cec5SDimitry Andric 5120b57cec5SDimitry Andric TargetEventData(const lldb::TargetSP &target_sp, 5130b57cec5SDimitry Andric const ModuleList &module_list); 5140b57cec5SDimitry Andric 5150b57cec5SDimitry Andric ~TargetEventData() override; 5160b57cec5SDimitry Andric 51706c3fb27SDimitry Andric static llvm::StringRef GetFlavorString(); 5180b57cec5SDimitry Andric GetFlavor()51906c3fb27SDimitry Andric llvm::StringRef GetFlavor() const override { 5200b57cec5SDimitry Andric return TargetEventData::GetFlavorString(); 5210b57cec5SDimitry Andric } 5220b57cec5SDimitry Andric 5230b57cec5SDimitry Andric void Dump(Stream *s) const override; 5240b57cec5SDimitry Andric 5250b57cec5SDimitry Andric static const TargetEventData *GetEventDataFromEvent(const Event *event_ptr); 5260b57cec5SDimitry Andric 5270b57cec5SDimitry Andric static lldb::TargetSP GetTargetFromEvent(const Event *event_ptr); 5280b57cec5SDimitry Andric 5290b57cec5SDimitry Andric static ModuleList GetModuleListFromEvent(const Event *event_ptr); 5300b57cec5SDimitry Andric GetTarget()5310b57cec5SDimitry Andric const lldb::TargetSP &GetTarget() const { return m_target_sp; } 5320b57cec5SDimitry Andric GetModuleList()5330b57cec5SDimitry Andric const ModuleList &GetModuleList() const { return m_module_list; } 5340b57cec5SDimitry Andric 5350b57cec5SDimitry Andric private: 5360b57cec5SDimitry Andric lldb::TargetSP m_target_sp; 5370b57cec5SDimitry Andric ModuleList m_module_list; 5380b57cec5SDimitry Andric 5395ffd83dbSDimitry Andric TargetEventData(const TargetEventData &) = delete; 5405ffd83dbSDimitry Andric const TargetEventData &operator=(const TargetEventData &) = delete; 5410b57cec5SDimitry Andric }; 5420b57cec5SDimitry Andric 5430b57cec5SDimitry Andric ~Target() override; 5440b57cec5SDimitry Andric 5450b57cec5SDimitry Andric static void SettingsInitialize(); 5460b57cec5SDimitry Andric 5470b57cec5SDimitry Andric static void SettingsTerminate(); 5480b57cec5SDimitry Andric 5490b57cec5SDimitry Andric static FileSpecList GetDefaultExecutableSearchPaths(); 5500b57cec5SDimitry Andric 5510b57cec5SDimitry Andric static FileSpecList GetDefaultDebugFileSearchPaths(); 5520b57cec5SDimitry Andric 5530b57cec5SDimitry Andric static ArchSpec GetDefaultArchitecture(); 5540b57cec5SDimitry Andric 5550b57cec5SDimitry Andric static void SetDefaultArchitecture(const ArchSpec &arch); 5560b57cec5SDimitry Andric IsDummyTarget()557e8d8bef9SDimitry Andric bool IsDummyTarget() const { return m_is_dummy_target; } 558e8d8bef9SDimitry Andric GetLabel()55906c3fb27SDimitry Andric const std::string &GetLabel() const { return m_label; } 56006c3fb27SDimitry Andric 56106c3fb27SDimitry Andric /// Set a label for a target. 56206c3fb27SDimitry Andric /// 56306c3fb27SDimitry Andric /// The label cannot be used by another target or be only integral. 56406c3fb27SDimitry Andric /// 56506c3fb27SDimitry Andric /// \return 56606c3fb27SDimitry Andric /// The label for this target or an error if the label didn't match the 56706c3fb27SDimitry Andric /// requirements. 56806c3fb27SDimitry Andric llvm::Error SetLabel(llvm::StringRef label); 56906c3fb27SDimitry Andric 5700b57cec5SDimitry Andric /// Find a binary on the system and return its Module, 5710b57cec5SDimitry Andric /// or return an existing Module that is already in the Target. 5720b57cec5SDimitry Andric /// 5730b57cec5SDimitry Andric /// Given a ModuleSpec, find a binary satisifying that specification, 5740b57cec5SDimitry Andric /// or identify a matching Module already present in the Target, 5750b57cec5SDimitry Andric /// and return a shared pointer to it. 5760b57cec5SDimitry Andric /// 5770b57cec5SDimitry Andric /// \param[in] module_spec 5780b57cec5SDimitry Andric /// The criteria that must be matched for the binary being loaded. 5790b57cec5SDimitry Andric /// e.g. UUID, architecture, file path. 5800b57cec5SDimitry Andric /// 5810b57cec5SDimitry Andric /// \param[in] notify 5820b57cec5SDimitry Andric /// If notify is true, and the Module is new to this Target, 5830b57cec5SDimitry Andric /// Target::ModulesDidLoad will be called. 5840b57cec5SDimitry Andric /// If notify is false, it is assumed that the caller is adding 5850b57cec5SDimitry Andric /// multiple Modules and will call ModulesDidLoad with the 5860b57cec5SDimitry Andric /// full list at the end. 5870b57cec5SDimitry Andric /// ModulesDidLoad must be called when a Module/Modules have 5880b57cec5SDimitry Andric /// been added to the target, one way or the other. 5890b57cec5SDimitry Andric /// 5900b57cec5SDimitry Andric /// \param[out] error_ptr 5910b57cec5SDimitry Andric /// Optional argument, pointing to a Status object to fill in 5920b57cec5SDimitry Andric /// with any results / messages while attempting to find/load 5930b57cec5SDimitry Andric /// this binary. Many callers will be internal functions that 5940b57cec5SDimitry Andric /// will handle / summarize the failures in a custom way and 5950b57cec5SDimitry Andric /// don't use these messages. 5960b57cec5SDimitry Andric /// 5970b57cec5SDimitry Andric /// \return 5980b57cec5SDimitry Andric /// An empty ModuleSP will be returned if no matching file 5990b57cec5SDimitry Andric /// was found. If error_ptr was non-nullptr, an error message 6000b57cec5SDimitry Andric /// will likely be provided. 6019dba64beSDimitry Andric lldb::ModuleSP GetOrCreateModule(const ModuleSpec &module_spec, bool notify, 6020b57cec5SDimitry Andric Status *error_ptr = nullptr); 6030b57cec5SDimitry Andric 6040b57cec5SDimitry Andric // Settings accessors 6050b57cec5SDimitry Andric 606349cc55cSDimitry Andric static TargetProperties &GetGlobalProperties(); 6070b57cec5SDimitry Andric 6089dba64beSDimitry Andric std::recursive_mutex &GetAPIMutex(); 6090b57cec5SDimitry Andric 6100b57cec5SDimitry Andric void DeleteCurrentProcess(); 6110b57cec5SDimitry Andric 6120b57cec5SDimitry Andric void CleanupProcess(); 6130b57cec5SDimitry Andric 6140b57cec5SDimitry Andric /// Dump a description of this object to a Stream. 6150b57cec5SDimitry Andric /// 6160b57cec5SDimitry Andric /// Dump a description of the contents of this object to the 6170b57cec5SDimitry Andric /// supplied stream \a s. The dumped content will be only what has 6180b57cec5SDimitry Andric /// been loaded or parsed up to this point at which this function 6190b57cec5SDimitry Andric /// is called, so this is a good way to see what has been parsed 6200b57cec5SDimitry Andric /// in a target. 6210b57cec5SDimitry Andric /// 6220b57cec5SDimitry Andric /// \param[in] s 6230b57cec5SDimitry Andric /// The stream to which to dump the object description. 6240b57cec5SDimitry Andric void Dump(Stream *s, lldb::DescriptionLevel description_level); 6250b57cec5SDimitry Andric 6260b57cec5SDimitry Andric // If listener_sp is null, the listener of the owning Debugger object will be 6270b57cec5SDimitry Andric // used. 6280b57cec5SDimitry Andric const lldb::ProcessSP &CreateProcess(lldb::ListenerSP listener_sp, 6290b57cec5SDimitry Andric llvm::StringRef plugin_name, 630e8d8bef9SDimitry Andric const FileSpec *crash_file, 631e8d8bef9SDimitry Andric bool can_connect); 6320b57cec5SDimitry Andric 6330b57cec5SDimitry Andric const lldb::ProcessSP &GetProcessSP() const; 6340b57cec5SDimitry Andric IsValid()6350b57cec5SDimitry Andric bool IsValid() { return m_valid; } 6360b57cec5SDimitry Andric 6370b57cec5SDimitry Andric void Destroy(); 6380b57cec5SDimitry Andric 6390b57cec5SDimitry Andric Status Launch(ProcessLaunchInfo &launch_info, 6400b57cec5SDimitry Andric Stream *stream); // Optional stream to receive first stop info 6410b57cec5SDimitry Andric 6420b57cec5SDimitry Andric Status Attach(ProcessAttachInfo &attach_info, 6430b57cec5SDimitry Andric Stream *stream); // Optional stream to receive first stop info 6440b57cec5SDimitry Andric 6450b57cec5SDimitry Andric // This part handles the breakpoints. 6460b57cec5SDimitry Andric 6470b57cec5SDimitry Andric BreakpointList &GetBreakpointList(bool internal = false); 6480b57cec5SDimitry Andric 6490b57cec5SDimitry Andric const BreakpointList &GetBreakpointList(bool internal = false) const; 6500b57cec5SDimitry Andric GetLastCreatedBreakpoint()6510b57cec5SDimitry Andric lldb::BreakpointSP GetLastCreatedBreakpoint() { 6520b57cec5SDimitry Andric return m_last_created_breakpoint; 6530b57cec5SDimitry Andric } 6540b57cec5SDimitry Andric 6550b57cec5SDimitry Andric lldb::BreakpointSP GetBreakpointByID(lldb::break_id_t break_id); 6560b57cec5SDimitry Andric 6575f757f3fSDimitry Andric lldb::BreakpointSP CreateBreakpointAtUserEntry(Status &error); 6585f757f3fSDimitry Andric 6590b57cec5SDimitry Andric // Use this to create a file and line breakpoint to a given module or all 6600b57cec5SDimitry Andric // module it is nullptr 6610b57cec5SDimitry Andric lldb::BreakpointSP CreateBreakpoint(const FileSpecList *containingModules, 6620b57cec5SDimitry Andric const FileSpec &file, uint32_t line_no, 6630b57cec5SDimitry Andric uint32_t column, lldb::addr_t offset, 6640b57cec5SDimitry Andric LazyBool check_inlines, 6650b57cec5SDimitry Andric LazyBool skip_prologue, bool internal, 6660b57cec5SDimitry Andric bool request_hardware, 6670b57cec5SDimitry Andric LazyBool move_to_nearest_code); 6680b57cec5SDimitry Andric 6690b57cec5SDimitry Andric // Use this to create breakpoint that matches regex against the source lines 6700b57cec5SDimitry Andric // in files given in source_file_list: If function_names is non-empty, also 6710b57cec5SDimitry Andric // filter by function after the matches are made. 6720b57cec5SDimitry Andric lldb::BreakpointSP CreateSourceRegexBreakpoint( 6730b57cec5SDimitry Andric const FileSpecList *containingModules, 6740b57cec5SDimitry Andric const FileSpecList *source_file_list, 6750b57cec5SDimitry Andric const std::unordered_set<std::string> &function_names, 6769dba64beSDimitry Andric RegularExpression source_regex, bool internal, bool request_hardware, 6770b57cec5SDimitry Andric LazyBool move_to_nearest_code); 6780b57cec5SDimitry Andric 6790b57cec5SDimitry Andric // Use this to create a breakpoint from a load address 6800b57cec5SDimitry Andric lldb::BreakpointSP CreateBreakpoint(lldb::addr_t load_addr, bool internal, 6810b57cec5SDimitry Andric bool request_hardware); 6820b57cec5SDimitry Andric 6830b57cec5SDimitry Andric // Use this to create a breakpoint from a load address and a module file spec 6840b57cec5SDimitry Andric lldb::BreakpointSP CreateAddressInModuleBreakpoint(lldb::addr_t file_addr, 6850b57cec5SDimitry Andric bool internal, 6865f757f3fSDimitry Andric const FileSpec &file_spec, 6870b57cec5SDimitry Andric bool request_hardware); 6880b57cec5SDimitry Andric 6890b57cec5SDimitry Andric // Use this to create Address breakpoints: 6900b57cec5SDimitry Andric lldb::BreakpointSP CreateBreakpoint(const Address &addr, bool internal, 6910b57cec5SDimitry Andric bool request_hardware); 6920b57cec5SDimitry Andric 6930b57cec5SDimitry Andric // Use this to create a function breakpoint by regexp in 6940b57cec5SDimitry Andric // containingModule/containingSourceFiles, or all modules if it is nullptr 6950b57cec5SDimitry Andric // When "skip_prologue is set to eLazyBoolCalculate, we use the current 6960b57cec5SDimitry Andric // target setting, else we use the values passed in 6970b57cec5SDimitry Andric lldb::BreakpointSP CreateFuncRegexBreakpoint( 6980b57cec5SDimitry Andric const FileSpecList *containingModules, 6999dba64beSDimitry Andric const FileSpecList *containingSourceFiles, RegularExpression func_regexp, 7000b57cec5SDimitry Andric lldb::LanguageType requested_language, LazyBool skip_prologue, 7010b57cec5SDimitry Andric bool internal, bool request_hardware); 7020b57cec5SDimitry Andric 7030b57cec5SDimitry Andric // Use this to create a function breakpoint by name in containingModule, or 7040b57cec5SDimitry Andric // all modules if it is nullptr When "skip_prologue is set to 7050b57cec5SDimitry Andric // eLazyBoolCalculate, we use the current target setting, else we use the 7060b57cec5SDimitry Andric // values passed in. func_name_type_mask is or'ed values from the 7070b57cec5SDimitry Andric // FunctionNameType enum. 7080b57cec5SDimitry Andric lldb::BreakpointSP CreateBreakpoint( 7090b57cec5SDimitry Andric const FileSpecList *containingModules, 7100b57cec5SDimitry Andric const FileSpecList *containingSourceFiles, const char *func_name, 7110b57cec5SDimitry Andric lldb::FunctionNameType func_name_type_mask, lldb::LanguageType language, 7120b57cec5SDimitry Andric lldb::addr_t offset, LazyBool skip_prologue, bool internal, 7130b57cec5SDimitry Andric bool request_hardware); 7140b57cec5SDimitry Andric 7150b57cec5SDimitry Andric lldb::BreakpointSP 7160b57cec5SDimitry Andric CreateExceptionBreakpoint(enum lldb::LanguageType language, bool catch_bp, 7170b57cec5SDimitry Andric bool throw_bp, bool internal, 7180b57cec5SDimitry Andric Args *additional_args = nullptr, 7190b57cec5SDimitry Andric Status *additional_args_error = nullptr); 7200b57cec5SDimitry Andric 7219dba64beSDimitry Andric lldb::BreakpointSP CreateScriptedBreakpoint( 7229dba64beSDimitry Andric const llvm::StringRef class_name, const FileSpecList *containingModules, 7239dba64beSDimitry Andric const FileSpecList *containingSourceFiles, bool internal, 7249dba64beSDimitry Andric bool request_hardware, StructuredData::ObjectSP extra_args_sp, 7250b57cec5SDimitry Andric Status *creation_error = nullptr); 7260b57cec5SDimitry Andric 7270b57cec5SDimitry Andric // This is the same as the func_name breakpoint except that you can specify a 7280b57cec5SDimitry Andric // vector of names. This is cheaper than a regular expression breakpoint in 7290b57cec5SDimitry Andric // the case where you just want to set a breakpoint on a set of names you 7300b57cec5SDimitry Andric // already know. func_name_type_mask is or'ed values from the 7310b57cec5SDimitry Andric // FunctionNameType enum. 7320b57cec5SDimitry Andric lldb::BreakpointSP CreateBreakpoint( 7330b57cec5SDimitry Andric const FileSpecList *containingModules, 7340b57cec5SDimitry Andric const FileSpecList *containingSourceFiles, const char *func_names[], 7350b57cec5SDimitry Andric size_t num_names, lldb::FunctionNameType func_name_type_mask, 7360b57cec5SDimitry Andric lldb::LanguageType language, lldb::addr_t offset, LazyBool skip_prologue, 7370b57cec5SDimitry Andric bool internal, bool request_hardware); 7380b57cec5SDimitry Andric 7390b57cec5SDimitry Andric lldb::BreakpointSP 7400b57cec5SDimitry Andric CreateBreakpoint(const FileSpecList *containingModules, 7410b57cec5SDimitry Andric const FileSpecList *containingSourceFiles, 7420b57cec5SDimitry Andric const std::vector<std::string> &func_names, 7430b57cec5SDimitry Andric lldb::FunctionNameType func_name_type_mask, 7440b57cec5SDimitry Andric lldb::LanguageType language, lldb::addr_t m_offset, 7450b57cec5SDimitry Andric LazyBool skip_prologue, bool internal, 7460b57cec5SDimitry Andric bool request_hardware); 7470b57cec5SDimitry Andric 7480b57cec5SDimitry Andric // Use this to create a general breakpoint: 7490b57cec5SDimitry Andric lldb::BreakpointSP CreateBreakpoint(lldb::SearchFilterSP &filter_sp, 7500b57cec5SDimitry Andric lldb::BreakpointResolverSP &resolver_sp, 7510b57cec5SDimitry Andric bool internal, bool request_hardware, 7520b57cec5SDimitry Andric bool resolve_indirect_symbols); 7530b57cec5SDimitry Andric 7540b57cec5SDimitry Andric // Use this to create a watchpoint: 7550b57cec5SDimitry Andric lldb::WatchpointSP CreateWatchpoint(lldb::addr_t addr, size_t size, 7560b57cec5SDimitry Andric const CompilerType *type, uint32_t kind, 7570b57cec5SDimitry Andric Status &error); 7580b57cec5SDimitry Andric GetLastCreatedWatchpoint()7590b57cec5SDimitry Andric lldb::WatchpointSP GetLastCreatedWatchpoint() { 7600b57cec5SDimitry Andric return m_last_created_watchpoint; 7610b57cec5SDimitry Andric } 7620b57cec5SDimitry Andric GetWatchpointList()7630b57cec5SDimitry Andric WatchpointList &GetWatchpointList() { return m_watchpoint_list; } 7640b57cec5SDimitry Andric 7650b57cec5SDimitry Andric // Manages breakpoint names: 7665f757f3fSDimitry Andric void AddNameToBreakpoint(BreakpointID &id, llvm::StringRef name, 7675f757f3fSDimitry Andric Status &error); 7680b57cec5SDimitry Andric 7695f757f3fSDimitry Andric void AddNameToBreakpoint(lldb::BreakpointSP &bp_sp, llvm::StringRef name, 7700b57cec5SDimitry Andric Status &error); 7710b57cec5SDimitry Andric 7729dba64beSDimitry Andric void RemoveNameFromBreakpoint(lldb::BreakpointSP &bp_sp, ConstString name); 7730b57cec5SDimitry Andric 7740b57cec5SDimitry Andric BreakpointName *FindBreakpointName(ConstString name, bool can_create, 7750b57cec5SDimitry Andric Status &error); 7760b57cec5SDimitry Andric 7770b57cec5SDimitry Andric void DeleteBreakpointName(ConstString name); 7780b57cec5SDimitry Andric 7790b57cec5SDimitry Andric void ConfigureBreakpointName(BreakpointName &bp_name, 7800b57cec5SDimitry Andric const BreakpointOptions &options, 7810b57cec5SDimitry Andric const BreakpointName::Permissions &permissions); 7820b57cec5SDimitry Andric void ApplyNameToBreakpoints(BreakpointName &bp_name); 7830b57cec5SDimitry Andric 784bdd1243dSDimitry Andric void AddBreakpointName(std::unique_ptr<BreakpointName> bp_name); 7850b57cec5SDimitry Andric 7860b57cec5SDimitry Andric void GetBreakpointNames(std::vector<std::string> &names); 7870b57cec5SDimitry Andric 7880b57cec5SDimitry Andric // This call removes ALL breakpoints regardless of permission. 7890b57cec5SDimitry Andric void RemoveAllBreakpoints(bool internal_also = false); 7900b57cec5SDimitry Andric 7910b57cec5SDimitry Andric // This removes all the breakpoints, but obeys the ePermDelete on them. 7920b57cec5SDimitry Andric void RemoveAllowedBreakpoints(); 7930b57cec5SDimitry Andric 7940b57cec5SDimitry Andric void DisableAllBreakpoints(bool internal_also = false); 7950b57cec5SDimitry Andric 7960b57cec5SDimitry Andric void DisableAllowedBreakpoints(); 7970b57cec5SDimitry Andric 7980b57cec5SDimitry Andric void EnableAllBreakpoints(bool internal_also = false); 7990b57cec5SDimitry Andric 8000b57cec5SDimitry Andric void EnableAllowedBreakpoints(); 8010b57cec5SDimitry Andric 8020b57cec5SDimitry Andric bool DisableBreakpointByID(lldb::break_id_t break_id); 8030b57cec5SDimitry Andric 8040b57cec5SDimitry Andric bool EnableBreakpointByID(lldb::break_id_t break_id); 8050b57cec5SDimitry Andric 8060b57cec5SDimitry Andric bool RemoveBreakpointByID(lldb::break_id_t break_id); 8070b57cec5SDimitry Andric 808bdd1243dSDimitry Andric /// Resets the hit count of all breakpoints. 809bdd1243dSDimitry Andric void ResetBreakpointHitCounts(); 810bdd1243dSDimitry Andric 8110b57cec5SDimitry Andric // The flag 'end_to_end', default to true, signifies that the operation is 8120b57cec5SDimitry Andric // performed end to end, for both the debugger and the debuggee. 8130b57cec5SDimitry Andric 8140b57cec5SDimitry Andric bool RemoveAllWatchpoints(bool end_to_end = true); 8150b57cec5SDimitry Andric 8160b57cec5SDimitry Andric bool DisableAllWatchpoints(bool end_to_end = true); 8170b57cec5SDimitry Andric 8180b57cec5SDimitry Andric bool EnableAllWatchpoints(bool end_to_end = true); 8190b57cec5SDimitry Andric 8200b57cec5SDimitry Andric bool ClearAllWatchpointHitCounts(); 8210b57cec5SDimitry Andric 8220b57cec5SDimitry Andric bool ClearAllWatchpointHistoricValues(); 8230b57cec5SDimitry Andric 8240b57cec5SDimitry Andric bool IgnoreAllWatchpoints(uint32_t ignore_count); 8250b57cec5SDimitry Andric 8260b57cec5SDimitry Andric bool DisableWatchpointByID(lldb::watch_id_t watch_id); 8270b57cec5SDimitry Andric 8280b57cec5SDimitry Andric bool EnableWatchpointByID(lldb::watch_id_t watch_id); 8290b57cec5SDimitry Andric 8300b57cec5SDimitry Andric bool RemoveWatchpointByID(lldb::watch_id_t watch_id); 8310b57cec5SDimitry Andric 8320b57cec5SDimitry Andric bool IgnoreWatchpointByID(lldb::watch_id_t watch_id, uint32_t ignore_count); 8330b57cec5SDimitry Andric 8340b57cec5SDimitry Andric Status SerializeBreakpointsToFile(const FileSpec &file, 8350b57cec5SDimitry Andric const BreakpointIDList &bp_ids, 8360b57cec5SDimitry Andric bool append); 8370b57cec5SDimitry Andric 8380b57cec5SDimitry Andric Status CreateBreakpointsFromFile(const FileSpec &file, 8390b57cec5SDimitry Andric BreakpointIDList &new_bps); 8400b57cec5SDimitry Andric 8410b57cec5SDimitry Andric Status CreateBreakpointsFromFile(const FileSpec &file, 8420b57cec5SDimitry Andric std::vector<std::string> &names, 8430b57cec5SDimitry Andric BreakpointIDList &new_bps); 8440b57cec5SDimitry Andric 8450b57cec5SDimitry Andric /// Get \a load_addr as a callable code load address for this target 8460b57cec5SDimitry Andric /// 8470b57cec5SDimitry Andric /// Take \a load_addr and potentially add any address bits that are 8480b57cec5SDimitry Andric /// needed to make the address callable. For ARM this can set bit 8490b57cec5SDimitry Andric /// zero (if it already isn't) if \a load_addr is a thumb function. 8500b57cec5SDimitry Andric /// If \a addr_class is set to AddressClass::eInvalid, then the address 8510b57cec5SDimitry Andric /// adjustment will always happen. If it is set to an address class 8520b57cec5SDimitry Andric /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 8530b57cec5SDimitry Andric /// returned. 8540b57cec5SDimitry Andric lldb::addr_t GetCallableLoadAddress( 8550b57cec5SDimitry Andric lldb::addr_t load_addr, 8560b57cec5SDimitry Andric AddressClass addr_class = AddressClass::eInvalid) const; 8570b57cec5SDimitry Andric 8580b57cec5SDimitry Andric /// Get \a load_addr as an opcode for this target. 8590b57cec5SDimitry Andric /// 8600b57cec5SDimitry Andric /// Take \a load_addr and potentially strip any address bits that are 8610b57cec5SDimitry Andric /// needed to make the address point to an opcode. For ARM this can 8620b57cec5SDimitry Andric /// clear bit zero (if it already isn't) if \a load_addr is a 8630b57cec5SDimitry Andric /// thumb function and load_addr is in code. 8640b57cec5SDimitry Andric /// If \a addr_class is set to AddressClass::eInvalid, then the address 8650b57cec5SDimitry Andric /// adjustment will always happen. If it is set to an address class 8660b57cec5SDimitry Andric /// that doesn't have code in it, LLDB_INVALID_ADDRESS will be 8670b57cec5SDimitry Andric /// returned. 8680b57cec5SDimitry Andric lldb::addr_t 8690b57cec5SDimitry Andric GetOpcodeLoadAddress(lldb::addr_t load_addr, 8700b57cec5SDimitry Andric AddressClass addr_class = AddressClass::eInvalid) const; 8710b57cec5SDimitry Andric 8720b57cec5SDimitry Andric // Get load_addr as breakable load address for this target. Take a addr and 8730b57cec5SDimitry Andric // check if for any reason there is a better address than this to put a 8740b57cec5SDimitry Andric // breakpoint on. If there is then return that address. For MIPS, if 8750b57cec5SDimitry Andric // instruction at addr is a delay slot instruction then this method will find 8760b57cec5SDimitry Andric // the address of its previous instruction and return that address. 8770b57cec5SDimitry Andric lldb::addr_t GetBreakableLoadAddress(lldb::addr_t addr); 8780b57cec5SDimitry Andric 8790b57cec5SDimitry Andric void ModulesDidLoad(ModuleList &module_list); 8800b57cec5SDimitry Andric 8810b57cec5SDimitry Andric void ModulesDidUnload(ModuleList &module_list, bool delete_locations); 8820b57cec5SDimitry Andric 8830b57cec5SDimitry Andric void SymbolsDidLoad(ModuleList &module_list); 8840b57cec5SDimitry Andric 8850b57cec5SDimitry Andric void ClearModules(bool delete_locations); 8860b57cec5SDimitry Andric 8870b57cec5SDimitry Andric /// Called as the last function in Process::DidExec(). 8880b57cec5SDimitry Andric /// 8890b57cec5SDimitry Andric /// Process::DidExec() will clear a lot of state in the process, 8900b57cec5SDimitry Andric /// then try to reload a dynamic loader plugin to discover what 8910b57cec5SDimitry Andric /// binaries are currently available and then this function should 8920b57cec5SDimitry Andric /// be called to allow the target to do any cleanup after everything 8930b57cec5SDimitry Andric /// has been figured out. It can remove breakpoints that no longer 8940b57cec5SDimitry Andric /// make sense as the exec might have changed the target 8950b57cec5SDimitry Andric /// architecture, and unloaded some modules that might get deleted. 8960b57cec5SDimitry Andric void DidExec(); 8970b57cec5SDimitry Andric 8980b57cec5SDimitry Andric /// Gets the module for the main executable. 8990b57cec5SDimitry Andric /// 9000b57cec5SDimitry Andric /// Each process has a notion of a main executable that is the file 9010b57cec5SDimitry Andric /// that will be executed or attached to. Executable files can have 9020b57cec5SDimitry Andric /// dependent modules that are discovered from the object files, or 9030b57cec5SDimitry Andric /// discovered at runtime as things are dynamically loaded. 9040b57cec5SDimitry Andric /// 9050b57cec5SDimitry Andric /// \return 9060b57cec5SDimitry Andric /// The shared pointer to the executable module which can 9070b57cec5SDimitry Andric /// contains a nullptr Module object if no executable has been 9080b57cec5SDimitry Andric /// set. 9090b57cec5SDimitry Andric /// 9100b57cec5SDimitry Andric /// \see DynamicLoader 9110b57cec5SDimitry Andric /// \see ObjectFile::GetDependentModules (FileSpecList&) 9120b57cec5SDimitry Andric /// \see Process::SetExecutableModule(lldb::ModuleSP&) 9130b57cec5SDimitry Andric lldb::ModuleSP GetExecutableModule(); 9140b57cec5SDimitry Andric 9150b57cec5SDimitry Andric Module *GetExecutableModulePointer(); 9160b57cec5SDimitry Andric 9170b57cec5SDimitry Andric /// Set the main executable module. 9180b57cec5SDimitry Andric /// 9190b57cec5SDimitry Andric /// Each process has a notion of a main executable that is the file 9200b57cec5SDimitry Andric /// that will be executed or attached to. Executable files can have 9210b57cec5SDimitry Andric /// dependent modules that are discovered from the object files, or 9220b57cec5SDimitry Andric /// discovered at runtime as things are dynamically loaded. 9230b57cec5SDimitry Andric /// 9240b57cec5SDimitry Andric /// Setting the executable causes any of the current dependent 9250b57cec5SDimitry Andric /// image information to be cleared and replaced with the static 9260b57cec5SDimitry Andric /// dependent image information found by calling 9270b57cec5SDimitry Andric /// ObjectFile::GetDependentModules (FileSpecList&) on the main 9280b57cec5SDimitry Andric /// executable and any modules on which it depends. Calling 9290b57cec5SDimitry Andric /// Process::GetImages() will return the newly found images that 9300b57cec5SDimitry Andric /// were obtained from all of the object files. 9310b57cec5SDimitry Andric /// 9320b57cec5SDimitry Andric /// \param[in] module_sp 9330b57cec5SDimitry Andric /// A shared pointer reference to the module that will become 9340b57cec5SDimitry Andric /// the main executable for this process. 9350b57cec5SDimitry Andric /// 9360b57cec5SDimitry Andric /// \param[in] load_dependent_files 9370b57cec5SDimitry Andric /// If \b true then ask the object files to track down any 9380b57cec5SDimitry Andric /// known dependent files. 9390b57cec5SDimitry Andric /// 9400b57cec5SDimitry Andric /// \see ObjectFile::GetDependentModules (FileSpecList&) 9410b57cec5SDimitry Andric /// \see Process::GetImages() 9420b57cec5SDimitry Andric void SetExecutableModule( 9430b57cec5SDimitry Andric lldb::ModuleSP &module_sp, 9440b57cec5SDimitry Andric LoadDependentFiles load_dependent_files = eLoadDependentsDefault); 9450b57cec5SDimitry Andric 9460b57cec5SDimitry Andric bool LoadScriptingResources(std::list<Status> &errors, 94706c3fb27SDimitry Andric Stream &feedback_stream, 9480b57cec5SDimitry Andric bool continue_on_error = true) { 9490b57cec5SDimitry Andric return m_images.LoadScriptingResourcesInTarget( 9500b57cec5SDimitry Andric this, errors, feedback_stream, continue_on_error); 9510b57cec5SDimitry Andric } 9520b57cec5SDimitry Andric 9530b57cec5SDimitry Andric /// Get accessor for the images for this process. 9540b57cec5SDimitry Andric /// 9550b57cec5SDimitry Andric /// Each process has a notion of a main executable that is the file 9560b57cec5SDimitry Andric /// that will be executed or attached to. Executable files can have 9570b57cec5SDimitry Andric /// dependent modules that are discovered from the object files, or 9580b57cec5SDimitry Andric /// discovered at runtime as things are dynamically loaded. After 9590b57cec5SDimitry Andric /// a main executable has been set, the images will contain a list 9600b57cec5SDimitry Andric /// of all the files that the executable depends upon as far as the 9610b57cec5SDimitry Andric /// object files know. These images will usually contain valid file 9620b57cec5SDimitry Andric /// virtual addresses only. When the process is launched or attached 9630b57cec5SDimitry Andric /// to, the DynamicLoader plug-in will discover where these images 9640b57cec5SDimitry Andric /// were loaded in memory and will resolve the load virtual 9650b57cec5SDimitry Andric /// addresses is each image, and also in images that are loaded by 9660b57cec5SDimitry Andric /// code. 9670b57cec5SDimitry Andric /// 9680b57cec5SDimitry Andric /// \return 9690b57cec5SDimitry Andric /// A list of Module objects in a module list. GetImages()9700b57cec5SDimitry Andric const ModuleList &GetImages() const { return m_images; } 9710b57cec5SDimitry Andric GetImages()9720b57cec5SDimitry Andric ModuleList &GetImages() { return m_images; } 9730b57cec5SDimitry Andric 9740b57cec5SDimitry Andric /// Return whether this FileSpec corresponds to a module that should be 9750b57cec5SDimitry Andric /// considered for general searches. 9760b57cec5SDimitry Andric /// 9770b57cec5SDimitry Andric /// This API will be consulted by the SearchFilterForUnconstrainedSearches 9780b57cec5SDimitry Andric /// and any module that returns \b true will not be searched. Note the 9790b57cec5SDimitry Andric /// SearchFilterForUnconstrainedSearches is the search filter that 9800b57cec5SDimitry Andric /// gets used in the CreateBreakpoint calls when no modules is provided. 9810b57cec5SDimitry Andric /// 9820b57cec5SDimitry Andric /// The target call at present just consults the Platform's call of the 9830b57cec5SDimitry Andric /// same name. 9840b57cec5SDimitry Andric /// 985480093f4SDimitry Andric /// \param[in] module_spec 986480093f4SDimitry Andric /// Path to the module. 9870b57cec5SDimitry Andric /// 9880b57cec5SDimitry Andric /// \return \b true if the module should be excluded, \b false otherwise. 9890b57cec5SDimitry Andric bool ModuleIsExcludedForUnconstrainedSearches(const FileSpec &module_spec); 9900b57cec5SDimitry Andric 9910b57cec5SDimitry Andric /// Return whether this module should be considered for general searches. 9920b57cec5SDimitry Andric /// 9930b57cec5SDimitry Andric /// This API will be consulted by the SearchFilterForUnconstrainedSearches 9940b57cec5SDimitry Andric /// and any module that returns \b true will not be searched. Note the 9950b57cec5SDimitry Andric /// SearchFilterForUnconstrainedSearches is the search filter that 9960b57cec5SDimitry Andric /// gets used in the CreateBreakpoint calls when no modules is provided. 9970b57cec5SDimitry Andric /// 9980b57cec5SDimitry Andric /// The target call at present just consults the Platform's call of the 9990b57cec5SDimitry Andric /// same name. 10000b57cec5SDimitry Andric /// 10010b57cec5SDimitry Andric /// FIXME: When we get time we should add a way for the user to set modules 10020b57cec5SDimitry Andric /// that they 10030b57cec5SDimitry Andric /// don't want searched, in addition to or instead of the platform ones. 10040b57cec5SDimitry Andric /// 10050b57cec5SDimitry Andric /// \param[in] module_sp 10060b57cec5SDimitry Andric /// A shared pointer reference to the module that checked. 10070b57cec5SDimitry Andric /// 10080b57cec5SDimitry Andric /// \return \b true if the module should be excluded, \b false otherwise. 10090b57cec5SDimitry Andric bool 10100b57cec5SDimitry Andric ModuleIsExcludedForUnconstrainedSearches(const lldb::ModuleSP &module_sp); 10110b57cec5SDimitry Andric GetArchitecture()10120b57cec5SDimitry Andric const ArchSpec &GetArchitecture() const { return m_arch.GetSpec(); } 10130b57cec5SDimitry Andric 101481ad6265SDimitry Andric /// Returns the name of the target's ABI plugin. 101581ad6265SDimitry Andric llvm::StringRef GetABIName() const; 101681ad6265SDimitry Andric 10170b57cec5SDimitry Andric /// Set the architecture for this target. 10180b57cec5SDimitry Andric /// 10190b57cec5SDimitry Andric /// If the current target has no Images read in, then this just sets the 10200b57cec5SDimitry Andric /// architecture, which will be used to select the architecture of the 10210b57cec5SDimitry Andric /// ExecutableModule when that is set. If the current target has an 10220b57cec5SDimitry Andric /// ExecutableModule, then calling SetArchitecture with a different 10230b57cec5SDimitry Andric /// architecture from the currently selected one will reset the 10240b57cec5SDimitry Andric /// ExecutableModule to that slice of the file backing the ExecutableModule. 10250b57cec5SDimitry Andric /// If the file backing the ExecutableModule does not contain a fork of this 10260b57cec5SDimitry Andric /// architecture, then this code will return false, and the architecture 10270b57cec5SDimitry Andric /// won't be changed. If the input arch_spec is the same as the already set 10280b57cec5SDimitry Andric /// architecture, this is a no-op. 10290b57cec5SDimitry Andric /// 10300b57cec5SDimitry Andric /// \param[in] arch_spec 10310b57cec5SDimitry Andric /// The new architecture. 10320b57cec5SDimitry Andric /// 10330b57cec5SDimitry Andric /// \param[in] set_platform 10340b57cec5SDimitry Andric /// If \b true, then the platform will be adjusted if the currently 10355ffd83dbSDimitry Andric /// selected platform is not compatible with the architecture being set. 10360b57cec5SDimitry Andric /// If \b false, then just the architecture will be set even if the 10370b57cec5SDimitry Andric /// currently selected platform isn't compatible (in case it might be 10380b57cec5SDimitry Andric /// manually set following this function call). 10390b57cec5SDimitry Andric /// 1040bdd1243dSDimitry Andric /// \param[in] merged 1041bdd1243dSDimitry Andric /// If true, arch_spec is merged with the current 1042bdd1243dSDimitry Andric /// architecture. Otherwise it's replaced. 1043bdd1243dSDimitry Andric /// 10440b57cec5SDimitry Andric /// \return 10450b57cec5SDimitry Andric /// \b true if the architecture was successfully set, \b false otherwise. 1046bdd1243dSDimitry Andric bool SetArchitecture(const ArchSpec &arch_spec, bool set_platform = false, 1047bdd1243dSDimitry Andric bool merge = true); 10480b57cec5SDimitry Andric 10490b57cec5SDimitry Andric bool MergeArchitecture(const ArchSpec &arch_spec); 10500b57cec5SDimitry Andric GetArchitecturePlugin()10510b57cec5SDimitry Andric Architecture *GetArchitecturePlugin() const { return m_arch.GetPlugin(); } 10520b57cec5SDimitry Andric GetDebugger()10530b57cec5SDimitry Andric Debugger &GetDebugger() { return m_debugger; } 10540b57cec5SDimitry Andric 10550b57cec5SDimitry Andric size_t ReadMemoryFromFileCache(const Address &addr, void *dst, size_t dst_len, 10560b57cec5SDimitry Andric Status &error); 10570b57cec5SDimitry Andric 10580b57cec5SDimitry Andric // Reading memory through the target allows us to skip going to the process 10590b57cec5SDimitry Andric // for reading memory if possible and it allows us to try and read from any 10600b57cec5SDimitry Andric // constant sections in our object files on disk. If you always want live 10610b57cec5SDimitry Andric // program memory, read straight from the process. If you possibly want to 10620b57cec5SDimitry Andric // read from const sections in object files, read from the target. This 10630b57cec5SDimitry Andric // version of ReadMemory will try and read memory from the process if the 10640b57cec5SDimitry Andric // process is alive. The order is: 1065fe6060f1SDimitry Andric // 1 - if (force_live_memory == false) and the address falls in a read-only 1066fe6060f1SDimitry Andric // section, then read from the file cache 1067fe6060f1SDimitry Andric // 2 - if there is a process, then read from memory 1068fe6060f1SDimitry Andric // 3 - if there is no process, then read from the file cache 1069fe6060f1SDimitry Andric size_t ReadMemory(const Address &addr, void *dst, size_t dst_len, 1070fe6060f1SDimitry Andric Status &error, bool force_live_memory = false, 10710b57cec5SDimitry Andric lldb::addr_t *load_addr_ptr = nullptr); 10720b57cec5SDimitry Andric 10730b57cec5SDimitry Andric size_t ReadCStringFromMemory(const Address &addr, std::string &out_str, 10741fd87a68SDimitry Andric Status &error, bool force_live_memory = false); 10750b57cec5SDimitry Andric 10760b57cec5SDimitry Andric size_t ReadCStringFromMemory(const Address &addr, char *dst, 10771fd87a68SDimitry Andric size_t dst_max_len, Status &result_error, 10781fd87a68SDimitry Andric bool force_live_memory = false); 10790b57cec5SDimitry Andric 1080349cc55cSDimitry Andric /// Read a NULL terminated string from memory 1081349cc55cSDimitry Andric /// 1082349cc55cSDimitry Andric /// This function will read a cache page at a time until a NULL string 1083349cc55cSDimitry Andric /// terminator is found. It will stop reading if an aligned sequence of NULL 1084349cc55cSDimitry Andric /// termination \a type_width bytes is not found before reading \a 1085349cc55cSDimitry Andric /// cstr_max_len bytes. The results are always guaranteed to be NULL 1086349cc55cSDimitry Andric /// terminated, and that no more than (max_bytes - type_width) bytes will be 1087349cc55cSDimitry Andric /// read. 1088349cc55cSDimitry Andric /// 1089349cc55cSDimitry Andric /// \param[in] addr 1090349cc55cSDimitry Andric /// The address to start the memory read. 1091349cc55cSDimitry Andric /// 1092349cc55cSDimitry Andric /// \param[in] dst 1093349cc55cSDimitry Andric /// A character buffer containing at least max_bytes. 1094349cc55cSDimitry Andric /// 1095349cc55cSDimitry Andric /// \param[in] max_bytes 1096349cc55cSDimitry Andric /// The maximum number of bytes to read. 1097349cc55cSDimitry Andric /// 1098349cc55cSDimitry Andric /// \param[in] error 1099349cc55cSDimitry Andric /// The error status of the read operation. 1100349cc55cSDimitry Andric /// 1101349cc55cSDimitry Andric /// \param[in] type_width 1102349cc55cSDimitry Andric /// The size of the null terminator (1 to 4 bytes per 1103349cc55cSDimitry Andric /// character). Defaults to 1. 1104349cc55cSDimitry Andric /// 1105349cc55cSDimitry Andric /// \return 1106349cc55cSDimitry Andric /// The error status or the number of bytes prior to the null terminator. 1107349cc55cSDimitry Andric size_t ReadStringFromMemory(const Address &addr, char *dst, size_t max_bytes, 1108349cc55cSDimitry Andric Status &error, size_t type_width, 1109349cc55cSDimitry Andric bool force_live_memory = true); 1110349cc55cSDimitry Andric 1111fe6060f1SDimitry Andric size_t ReadScalarIntegerFromMemory(const Address &addr, uint32_t byte_size, 11120b57cec5SDimitry Andric bool is_signed, Scalar &scalar, 1113fe6060f1SDimitry Andric Status &error, 1114fe6060f1SDimitry Andric bool force_live_memory = false); 11150b57cec5SDimitry Andric 11160b57cec5SDimitry Andric uint64_t ReadUnsignedIntegerFromMemory(const Address &addr, 11170b57cec5SDimitry Andric size_t integer_byte_size, 1118fe6060f1SDimitry Andric uint64_t fail_value, Status &error, 1119fe6060f1SDimitry Andric bool force_live_memory = false); 11200b57cec5SDimitry Andric 1121fe6060f1SDimitry Andric bool ReadPointerFromMemory(const Address &addr, Status &error, 1122fe6060f1SDimitry Andric Address &pointer_addr, 1123fe6060f1SDimitry Andric bool force_live_memory = false); 11240b57cec5SDimitry Andric GetSectionLoadList()11250b57cec5SDimitry Andric SectionLoadList &GetSectionLoadList() { 11260b57cec5SDimitry Andric return m_section_load_history.GetCurrentSectionLoadList(); 11270b57cec5SDimitry Andric } 11280b57cec5SDimitry Andric 11290b57cec5SDimitry Andric static Target *GetTargetFromContexts(const ExecutionContext *exe_ctx_ptr, 11300b57cec5SDimitry Andric const SymbolContext *sc_ptr); 11310b57cec5SDimitry Andric 11320b57cec5SDimitry Andric // lldb::ExecutionContextScope pure virtual functions 11330b57cec5SDimitry Andric lldb::TargetSP CalculateTarget() override; 11340b57cec5SDimitry Andric 11350b57cec5SDimitry Andric lldb::ProcessSP CalculateProcess() override; 11360b57cec5SDimitry Andric 11370b57cec5SDimitry Andric lldb::ThreadSP CalculateThread() override; 11380b57cec5SDimitry Andric 11390b57cec5SDimitry Andric lldb::StackFrameSP CalculateStackFrame() override; 11400b57cec5SDimitry Andric 11410b57cec5SDimitry Andric void CalculateExecutionContext(ExecutionContext &exe_ctx) override; 11420b57cec5SDimitry Andric 11430b57cec5SDimitry Andric PathMappingList &GetImageSearchPathList(); 11440b57cec5SDimitry Andric 1145bdd1243dSDimitry Andric llvm::Expected<lldb::TypeSystemSP> 11469dba64beSDimitry Andric GetScratchTypeSystemForLanguage(lldb::LanguageType language, 11470b57cec5SDimitry Andric bool create_on_demand = true); 11480b57cec5SDimitry Andric 1149bdd1243dSDimitry Andric std::vector<lldb::TypeSystemSP> 1150bdd1243dSDimitry Andric GetScratchTypeSystems(bool create_on_demand = true); 11519dba64beSDimitry Andric 11520b57cec5SDimitry Andric PersistentExpressionState * 11530b57cec5SDimitry Andric GetPersistentExpressionStateForLanguage(lldb::LanguageType language); 11540b57cec5SDimitry Andric 11550b57cec5SDimitry Andric // Creates a UserExpression for the given language, the rest of the 11560b57cec5SDimitry Andric // parameters have the same meaning as for the UserExpression constructor. 11570b57cec5SDimitry Andric // Returns a new-ed object which the caller owns. 11580b57cec5SDimitry Andric 11599dba64beSDimitry Andric UserExpression * 11609dba64beSDimitry Andric GetUserExpressionForLanguage(llvm::StringRef expr, llvm::StringRef prefix, 11619dba64beSDimitry Andric lldb::LanguageType language, 11620b57cec5SDimitry Andric Expression::ResultType desired_type, 11630b57cec5SDimitry Andric const EvaluateExpressionOptions &options, 11640b57cec5SDimitry Andric ValueObject *ctx_obj, Status &error); 11650b57cec5SDimitry Andric 11660b57cec5SDimitry Andric // Creates a FunctionCaller for the given language, the rest of the 11670b57cec5SDimitry Andric // parameters have the same meaning as for the FunctionCaller constructor. 11680b57cec5SDimitry Andric // Since a FunctionCaller can't be 11690b57cec5SDimitry Andric // IR Interpreted, it makes no sense to call this with an 11700b57cec5SDimitry Andric // ExecutionContextScope that lacks 11710b57cec5SDimitry Andric // a Process. 11720b57cec5SDimitry Andric // Returns a new-ed object which the caller owns. 11730b57cec5SDimitry Andric 11740b57cec5SDimitry Andric FunctionCaller *GetFunctionCallerForLanguage(lldb::LanguageType language, 11750b57cec5SDimitry Andric const CompilerType &return_type, 11760b57cec5SDimitry Andric const Address &function_address, 11770b57cec5SDimitry Andric const ValueList &arg_value_list, 11780b57cec5SDimitry Andric const char *name, Status &error); 11790b57cec5SDimitry Andric 1180e8d8bef9SDimitry Andric /// Creates and installs a UtilityFunction for the given language. 1181e8d8bef9SDimitry Andric llvm::Expected<std::unique_ptr<UtilityFunction>> 1182e8d8bef9SDimitry Andric CreateUtilityFunction(std::string expression, std::string name, 1183e8d8bef9SDimitry Andric lldb::LanguageType language, ExecutionContext &exe_ctx); 11840b57cec5SDimitry Andric 11850b57cec5SDimitry Andric // Install any files through the platform that need be to installed prior to 11860b57cec5SDimitry Andric // launching or attaching. 11870b57cec5SDimitry Andric Status Install(ProcessLaunchInfo *launch_info); 11880b57cec5SDimitry Andric 11890b57cec5SDimitry Andric bool ResolveFileAddress(lldb::addr_t load_addr, Address &so_addr); 11900b57cec5SDimitry Andric 11910b57cec5SDimitry Andric bool ResolveLoadAddress(lldb::addr_t load_addr, Address &so_addr, 11920b57cec5SDimitry Andric uint32_t stop_id = SectionLoadHistory::eStopIDNow); 11930b57cec5SDimitry Andric 11940b57cec5SDimitry Andric bool SetSectionLoadAddress(const lldb::SectionSP §ion, 11950b57cec5SDimitry Andric lldb::addr_t load_addr, 11960b57cec5SDimitry Andric bool warn_multiple = false); 11970b57cec5SDimitry Andric 11980b57cec5SDimitry Andric size_t UnloadModuleSections(const lldb::ModuleSP &module_sp); 11990b57cec5SDimitry Andric 12000b57cec5SDimitry Andric size_t UnloadModuleSections(const ModuleList &module_list); 12010b57cec5SDimitry Andric 12020b57cec5SDimitry Andric bool SetSectionUnloaded(const lldb::SectionSP §ion_sp); 12030b57cec5SDimitry Andric 12040b57cec5SDimitry Andric bool SetSectionUnloaded(const lldb::SectionSP §ion_sp, 12050b57cec5SDimitry Andric lldb::addr_t load_addr); 12060b57cec5SDimitry Andric 12070b57cec5SDimitry Andric void ClearAllLoadedSections(); 12080b57cec5SDimitry Andric 1209e8d8bef9SDimitry Andric /// Set the \a Trace object containing processor trace information of this 1210e8d8bef9SDimitry Andric /// target. 1211e8d8bef9SDimitry Andric /// 1212e8d8bef9SDimitry Andric /// \param[in] trace_sp 1213e8d8bef9SDimitry Andric /// The trace object. 1214e8d8bef9SDimitry Andric void SetTrace(const lldb::TraceSP &trace_sp); 1215e8d8bef9SDimitry Andric 1216e8d8bef9SDimitry Andric /// Get the \a Trace object containing processor trace information of this 1217e8d8bef9SDimitry Andric /// target. 1218e8d8bef9SDimitry Andric /// 1219e8d8bef9SDimitry Andric /// \return 1220e8d8bef9SDimitry Andric /// The trace object. It might be undefined. 1221fe6060f1SDimitry Andric lldb::TraceSP GetTrace(); 1222fe6060f1SDimitry Andric 1223fe6060f1SDimitry Andric /// Create a \a Trace object for the current target using the using the 1224fe6060f1SDimitry Andric /// default supported tracing technology for this process. 1225fe6060f1SDimitry Andric /// 1226fe6060f1SDimitry Andric /// \return 1227fe6060f1SDimitry Andric /// The new \a Trace or an \a llvm::Error if a \a Trace already exists or 1228fe6060f1SDimitry Andric /// the trace couldn't be created. 1229fe6060f1SDimitry Andric llvm::Expected<lldb::TraceSP> CreateTrace(); 1230fe6060f1SDimitry Andric 1231fe6060f1SDimitry Andric /// If a \a Trace object is present, this returns it, otherwise a new Trace is 1232fe6060f1SDimitry Andric /// created with \a Trace::CreateTrace. 1233fe6060f1SDimitry Andric llvm::Expected<lldb::TraceSP> GetTraceOrCreate(); 1234e8d8bef9SDimitry Andric 12350b57cec5SDimitry Andric // Since expressions results can persist beyond the lifetime of a process, 12360b57cec5SDimitry Andric // and the const expression results are available after a process is gone, we 12370b57cec5SDimitry Andric // provide a way for expressions to be evaluated from the Target itself. If 12380b57cec5SDimitry Andric // an expression is going to be run, then it should have a frame filled in in 12390b57cec5SDimitry Andric // the execution context. 12400b57cec5SDimitry Andric lldb::ExpressionResults EvaluateExpression( 12410b57cec5SDimitry Andric llvm::StringRef expression, ExecutionContextScope *exe_scope, 12420b57cec5SDimitry Andric lldb::ValueObjectSP &result_valobj_sp, 12430b57cec5SDimitry Andric const EvaluateExpressionOptions &options = EvaluateExpressionOptions(), 12449dba64beSDimitry Andric std::string *fixed_expression = nullptr, ValueObject *ctx_obj = nullptr); 12450b57cec5SDimitry Andric 12460b57cec5SDimitry Andric lldb::ExpressionVariableSP GetPersistentVariable(ConstString name); 12470b57cec5SDimitry Andric 12480b57cec5SDimitry Andric lldb::addr_t GetPersistentSymbol(ConstString name); 12490b57cec5SDimitry Andric 12509dba64beSDimitry Andric /// This method will return the address of the starting function for 12519dba64beSDimitry Andric /// this binary, e.g. main() or its equivalent. This can be used as 12529dba64beSDimitry Andric /// an address of a function that is not called once a binary has 12539dba64beSDimitry Andric /// started running - e.g. as a return address for inferior function 12549dba64beSDimitry Andric /// calls that are unambiguous completion of the function call, not 12559dba64beSDimitry Andric /// called during the course of the inferior function code running. 12569dba64beSDimitry Andric /// 12579dba64beSDimitry Andric /// If no entry point can be found, an invalid address is returned. 12589dba64beSDimitry Andric /// 12599dba64beSDimitry Andric /// \param [out] err 12609dba64beSDimitry Andric /// This object will be set to failure if no entry address could 12619dba64beSDimitry Andric /// be found, and may contain a helpful error message. 12629dba64beSDimitry Andric // 12639dba64beSDimitry Andric /// \return 12649dba64beSDimitry Andric /// Returns the entry address for this program, or an error 12659dba64beSDimitry Andric /// if none can be found. 12669dba64beSDimitry Andric llvm::Expected<lldb_private::Address> GetEntryPointAddress(); 12679dba64beSDimitry Andric 126806c3fb27SDimitry Andric CompilerType GetRegisterType(const std::string &name, 126906c3fb27SDimitry Andric const lldb_private::RegisterFlags &flags, 127006c3fb27SDimitry Andric uint32_t byte_size); 127106c3fb27SDimitry Andric 12720b57cec5SDimitry Andric // Target Stop Hooks 12730b57cec5SDimitry Andric class StopHook : public UserID { 12740b57cec5SDimitry Andric public: 12750b57cec5SDimitry Andric StopHook(const StopHook &rhs); 1276e8d8bef9SDimitry Andric virtual ~StopHook() = default; 12770b57cec5SDimitry Andric 1278e8d8bef9SDimitry Andric enum class StopHookKind : uint32_t { CommandBased = 0, ScriptBased }; 1279e8d8bef9SDimitry Andric enum class StopHookResult : uint32_t { 1280e8d8bef9SDimitry Andric KeepStopped = 0, 1281e8d8bef9SDimitry Andric RequestContinue, 1282e8d8bef9SDimitry Andric AlreadyContinued 1283e8d8bef9SDimitry Andric }; 12840b57cec5SDimitry Andric GetTarget()12850b57cec5SDimitry Andric lldb::TargetSP &GetTarget() { return m_target_sp; } 12860b57cec5SDimitry Andric 12870b57cec5SDimitry Andric // Set the specifier. The stop hook will own the specifier, and is 12880b57cec5SDimitry Andric // responsible for deleting it when we're done. 12890b57cec5SDimitry Andric void SetSpecifier(SymbolContextSpecifier *specifier); 12900b57cec5SDimitry Andric GetSpecifier()12910b57cec5SDimitry Andric SymbolContextSpecifier *GetSpecifier() { return m_specifier_sp.get(); } 12920b57cec5SDimitry Andric 1293e8d8bef9SDimitry Andric bool ExecutionContextPasses(const ExecutionContext &exe_ctx); 1294e8d8bef9SDimitry Andric 1295e8d8bef9SDimitry Andric // Called on stop, this gets passed the ExecutionContext for each "stop 1296e8d8bef9SDimitry Andric // with a reason" thread. It should add to the stream whatever text it 1297e8d8bef9SDimitry Andric // wants to show the user, and return False to indicate it wants the target 1298e8d8bef9SDimitry Andric // not to stop. 1299e8d8bef9SDimitry Andric virtual StopHookResult HandleStop(ExecutionContext &exe_ctx, 1300e8d8bef9SDimitry Andric lldb::StreamSP output) = 0; 1301e8d8bef9SDimitry Andric 13020b57cec5SDimitry Andric // Set the Thread Specifier. The stop hook will own the thread specifier, 13030b57cec5SDimitry Andric // and is responsible for deleting it when we're done. 13040b57cec5SDimitry Andric void SetThreadSpecifier(ThreadSpec *specifier); 13050b57cec5SDimitry Andric GetThreadSpecifier()13060b57cec5SDimitry Andric ThreadSpec *GetThreadSpecifier() { return m_thread_spec_up.get(); } 13070b57cec5SDimitry Andric IsActive()13080b57cec5SDimitry Andric bool IsActive() { return m_active; } 13090b57cec5SDimitry Andric SetIsActive(bool is_active)13100b57cec5SDimitry Andric void SetIsActive(bool is_active) { m_active = is_active; } 13110b57cec5SDimitry Andric SetAutoContinue(bool auto_continue)13129dba64beSDimitry Andric void SetAutoContinue(bool auto_continue) { 13139dba64beSDimitry Andric m_auto_continue = auto_continue; 13149dba64beSDimitry Andric } 13150b57cec5SDimitry Andric GetAutoContinue()13160b57cec5SDimitry Andric bool GetAutoContinue() const { return m_auto_continue; } 13170b57cec5SDimitry Andric 131806c3fb27SDimitry Andric void GetDescription(Stream &s, lldb::DescriptionLevel level) const; 131906c3fb27SDimitry Andric virtual void GetSubclassDescription(Stream &s, 1320e8d8bef9SDimitry Andric lldb::DescriptionLevel level) const = 0; 13210b57cec5SDimitry Andric 1322e8d8bef9SDimitry Andric protected: 13230b57cec5SDimitry Andric lldb::TargetSP m_target_sp; 13240b57cec5SDimitry Andric lldb::SymbolContextSpecifierSP m_specifier_sp; 13250b57cec5SDimitry Andric std::unique_ptr<ThreadSpec> m_thread_spec_up; 13260b57cec5SDimitry Andric bool m_active = true; 13270b57cec5SDimitry Andric bool m_auto_continue = false; 13280b57cec5SDimitry Andric 1329e8d8bef9SDimitry Andric StopHook(lldb::TargetSP target_sp, lldb::user_id_t uid); 1330e8d8bef9SDimitry Andric }; 1331e8d8bef9SDimitry Andric 1332e8d8bef9SDimitry Andric class StopHookCommandLine : public StopHook { 1333e8d8bef9SDimitry Andric public: 133481ad6265SDimitry Andric ~StopHookCommandLine() override = default; 1335e8d8bef9SDimitry Andric GetCommands()1336e8d8bef9SDimitry Andric StringList &GetCommands() { return m_commands; } 1337e8d8bef9SDimitry Andric void SetActionFromString(const std::string &strings); 1338e8d8bef9SDimitry Andric void SetActionFromStrings(const std::vector<std::string> &strings); 1339e8d8bef9SDimitry Andric 1340e8d8bef9SDimitry Andric StopHookResult HandleStop(ExecutionContext &exc_ctx, 1341e8d8bef9SDimitry Andric lldb::StreamSP output_sp) override; 134206c3fb27SDimitry Andric void GetSubclassDescription(Stream &s, 1343e8d8bef9SDimitry Andric lldb::DescriptionLevel level) const override; 1344e8d8bef9SDimitry Andric 1345e8d8bef9SDimitry Andric private: 1346e8d8bef9SDimitry Andric StringList m_commands; 13470b57cec5SDimitry Andric // Use CreateStopHook to make a new empty stop hook. The GetCommandPointer 13480b57cec5SDimitry Andric // and fill it with commands, and SetSpecifier to set the specifier shared 13490b57cec5SDimitry Andric // pointer (can be null, that will match anything.) StopHookCommandLine(lldb::TargetSP target_sp,lldb::user_id_t uid)1350e8d8bef9SDimitry Andric StopHookCommandLine(lldb::TargetSP target_sp, lldb::user_id_t uid) 1351e8d8bef9SDimitry Andric : StopHook(target_sp, uid) {} 13520b57cec5SDimitry Andric friend class Target; 13530b57cec5SDimitry Andric }; 1354e8d8bef9SDimitry Andric 1355e8d8bef9SDimitry Andric class StopHookScripted : public StopHook { 1356e8d8bef9SDimitry Andric public: 135781ad6265SDimitry Andric ~StopHookScripted() override = default; 1358e8d8bef9SDimitry Andric StopHookResult HandleStop(ExecutionContext &exc_ctx, 1359e8d8bef9SDimitry Andric lldb::StreamSP output) override; 1360e8d8bef9SDimitry Andric 1361e8d8bef9SDimitry Andric Status SetScriptCallback(std::string class_name, 1362e8d8bef9SDimitry Andric StructuredData::ObjectSP extra_args_sp); 1363e8d8bef9SDimitry Andric 136406c3fb27SDimitry Andric void GetSubclassDescription(Stream &s, 1365e8d8bef9SDimitry Andric lldb::DescriptionLevel level) const override; 1366e8d8bef9SDimitry Andric 1367e8d8bef9SDimitry Andric private: 1368e8d8bef9SDimitry Andric std::string m_class_name; 1369e8d8bef9SDimitry Andric /// This holds the dictionary of keys & values that can be used to 1370e8d8bef9SDimitry Andric /// parametrize any given callback's behavior. 13710eae32dcSDimitry Andric StructuredDataImpl m_extra_args; 1372e8d8bef9SDimitry Andric /// This holds the python callback object. 1373e8d8bef9SDimitry Andric StructuredData::GenericSP m_implementation_sp; 1374e8d8bef9SDimitry Andric 1375e8d8bef9SDimitry Andric /// Use CreateStopHook to make a new empty stop hook. The GetCommandPointer 1376e8d8bef9SDimitry Andric /// and fill it with commands, and SetSpecifier to set the specifier shared 1377e8d8bef9SDimitry Andric /// pointer (can be null, that will match anything.) StopHookScripted(lldb::TargetSP target_sp,lldb::user_id_t uid)1378e8d8bef9SDimitry Andric StopHookScripted(lldb::TargetSP target_sp, lldb::user_id_t uid) 1379e8d8bef9SDimitry Andric : StopHook(target_sp, uid) {} 1380e8d8bef9SDimitry Andric friend class Target; 1381e8d8bef9SDimitry Andric }; 1382e8d8bef9SDimitry Andric 13830b57cec5SDimitry Andric typedef std::shared_ptr<StopHook> StopHookSP; 13840b57cec5SDimitry Andric 1385e8d8bef9SDimitry Andric /// Add an empty stop hook to the Target's stop hook list, and returns a 1386e8d8bef9SDimitry Andric /// shared pointer to it in new_hook. Returns the id of the new hook. 1387e8d8bef9SDimitry Andric StopHookSP CreateStopHook(StopHook::StopHookKind kind); 13880b57cec5SDimitry Andric 1389e8d8bef9SDimitry Andric /// If you tried to create a stop hook, and that failed, call this to 1390e8d8bef9SDimitry Andric /// remove the stop hook, as it will also reset the stop hook counter. 1391e8d8bef9SDimitry Andric void UndoCreateStopHook(lldb::user_id_t uid); 1392e8d8bef9SDimitry Andric 1393e8d8bef9SDimitry Andric // Runs the stop hooks that have been registered for this target. 1394e8d8bef9SDimitry Andric // Returns true if the stop hooks cause the target to resume. 1395e8d8bef9SDimitry Andric bool RunStopHooks(); 13960b57cec5SDimitry Andric 13970b57cec5SDimitry Andric size_t GetStopHookSize(); 13980b57cec5SDimitry Andric SetSuppresStopHooks(bool suppress)13990b57cec5SDimitry Andric bool SetSuppresStopHooks(bool suppress) { 14000b57cec5SDimitry Andric bool old_value = m_suppress_stop_hooks; 14010b57cec5SDimitry Andric m_suppress_stop_hooks = suppress; 14020b57cec5SDimitry Andric return old_value; 14030b57cec5SDimitry Andric } 14040b57cec5SDimitry Andric GetSuppressStopHooks()14050b57cec5SDimitry Andric bool GetSuppressStopHooks() { return m_suppress_stop_hooks; } 14060b57cec5SDimitry Andric 14070b57cec5SDimitry Andric bool RemoveStopHookByID(lldb::user_id_t uid); 14080b57cec5SDimitry Andric 14090b57cec5SDimitry Andric void RemoveAllStopHooks(); 14100b57cec5SDimitry Andric 14110b57cec5SDimitry Andric StopHookSP GetStopHookByID(lldb::user_id_t uid); 14120b57cec5SDimitry Andric 14130b57cec5SDimitry Andric bool SetStopHookActiveStateByID(lldb::user_id_t uid, bool active_state); 14140b57cec5SDimitry Andric 14150b57cec5SDimitry Andric void SetAllStopHooksActiveState(bool active_state); 14160b57cec5SDimitry Andric GetNumStopHooks()14170b57cec5SDimitry Andric size_t GetNumStopHooks() const { return m_stop_hooks.size(); } 14180b57cec5SDimitry Andric GetStopHookAtIndex(size_t index)14190b57cec5SDimitry Andric StopHookSP GetStopHookAtIndex(size_t index) { 14200b57cec5SDimitry Andric if (index >= GetNumStopHooks()) 14210b57cec5SDimitry Andric return StopHookSP(); 14220b57cec5SDimitry Andric StopHookCollection::iterator pos = m_stop_hooks.begin(); 14230b57cec5SDimitry Andric 14240b57cec5SDimitry Andric while (index > 0) { 14250b57cec5SDimitry Andric pos++; 14260b57cec5SDimitry Andric index--; 14270b57cec5SDimitry Andric } 14280b57cec5SDimitry Andric return (*pos).second; 14290b57cec5SDimitry Andric } 14300b57cec5SDimitry Andric GetPlatform()14310b57cec5SDimitry Andric lldb::PlatformSP GetPlatform() { return m_platform_sp; } 14320b57cec5SDimitry Andric SetPlatform(const lldb::PlatformSP & platform_sp)14330b57cec5SDimitry Andric void SetPlatform(const lldb::PlatformSP &platform_sp) { 14340b57cec5SDimitry Andric m_platform_sp = platform_sp; 14350b57cec5SDimitry Andric } 14360b57cec5SDimitry Andric 14370b57cec5SDimitry Andric SourceManager &GetSourceManager(); 14380b57cec5SDimitry Andric 14390b57cec5SDimitry Andric // Methods. 14400b57cec5SDimitry Andric lldb::SearchFilterSP 14410b57cec5SDimitry Andric GetSearchFilterForModule(const FileSpec *containingModule); 14420b57cec5SDimitry Andric 14430b57cec5SDimitry Andric lldb::SearchFilterSP 14440b57cec5SDimitry Andric GetSearchFilterForModuleList(const FileSpecList *containingModuleList); 14450b57cec5SDimitry Andric 14460b57cec5SDimitry Andric lldb::SearchFilterSP 14470b57cec5SDimitry Andric GetSearchFilterForModuleAndCUList(const FileSpecList *containingModules, 14480b57cec5SDimitry Andric const FileSpecList *containingSourceFiles); 14490b57cec5SDimitry Andric 14500b57cec5SDimitry Andric lldb::REPLSP GetREPL(Status &err, lldb::LanguageType language, 14510b57cec5SDimitry Andric const char *repl_options, bool can_create); 14520b57cec5SDimitry Andric 14530b57cec5SDimitry Andric void SetREPL(lldb::LanguageType language, lldb::REPLSP repl_sp); 14540b57cec5SDimitry Andric GetFrameRecognizerManager()1455e8d8bef9SDimitry Andric StackFrameRecognizerManager &GetFrameRecognizerManager() { 1456e8d8bef9SDimitry Andric return *m_frame_recognizer_manager_up; 1457e8d8bef9SDimitry Andric } 1458e8d8bef9SDimitry Andric 145906c3fb27SDimitry Andric void SaveScriptedLaunchInfo(lldb_private::ProcessInfo &process_info); 146006c3fb27SDimitry Andric 146181ad6265SDimitry Andric /// Add a signal for the target. This will get copied over to the process 146281ad6265SDimitry Andric /// if the signal exists on that target. Only the values with Yes and No are 146381ad6265SDimitry Andric /// set, Calculate values will be ignored. 146481ad6265SDimitry Andric protected: 146581ad6265SDimitry Andric struct DummySignalValues { 146681ad6265SDimitry Andric LazyBool pass = eLazyBoolCalculate; 146781ad6265SDimitry Andric LazyBool notify = eLazyBoolCalculate; 146881ad6265SDimitry Andric LazyBool stop = eLazyBoolCalculate; DummySignalValuesDummySignalValues1469bdd1243dSDimitry Andric DummySignalValues(LazyBool pass, LazyBool notify, LazyBool stop) 1470bdd1243dSDimitry Andric : pass(pass), notify(notify), stop(stop) {} 147181ad6265SDimitry Andric DummySignalValues() = default; 147281ad6265SDimitry Andric }; 147381ad6265SDimitry Andric using DummySignalElement = llvm::StringMapEntry<DummySignalValues>; 147481ad6265SDimitry Andric static bool UpdateSignalFromDummy(lldb::UnixSignalsSP signals_sp, 147581ad6265SDimitry Andric const DummySignalElement &element); 147681ad6265SDimitry Andric static bool ResetSignalFromDummy(lldb::UnixSignalsSP signals_sp, 147781ad6265SDimitry Andric const DummySignalElement &element); 147881ad6265SDimitry Andric 147981ad6265SDimitry Andric public: 148081ad6265SDimitry Andric /// Add a signal to the Target's list of stored signals/actions. These 148181ad6265SDimitry Andric /// values will get copied into any processes launched from 148281ad6265SDimitry Andric /// this target. 148381ad6265SDimitry Andric void AddDummySignal(llvm::StringRef name, LazyBool pass, LazyBool print, 148481ad6265SDimitry Andric LazyBool stop); 148581ad6265SDimitry Andric /// Updates the signals in signals_sp using the stored dummy signals. 148681ad6265SDimitry Andric /// If warning_stream_sp is not null, if any stored signals are not found in 148781ad6265SDimitry Andric /// the current process, a warning will be emitted here. 148881ad6265SDimitry Andric void UpdateSignalsFromDummy(lldb::UnixSignalsSP signals_sp, 148981ad6265SDimitry Andric lldb::StreamSP warning_stream_sp); 149081ad6265SDimitry Andric /// Clear the dummy signals in signal_names from the target, or all signals 149181ad6265SDimitry Andric /// if signal_names is empty. Also remove the behaviors they set from the 149281ad6265SDimitry Andric /// process's signals if it exists. 149381ad6265SDimitry Andric void ClearDummySignals(Args &signal_names); 149481ad6265SDimitry Andric /// Print all the signals set in this target. 149581ad6265SDimitry Andric void PrintDummySignals(Stream &strm, Args &signals); 149681ad6265SDimitry Andric 14970b57cec5SDimitry Andric protected: 14980b57cec5SDimitry Andric /// Implementing of ModuleList::Notifier. 14990b57cec5SDimitry Andric 15000b57cec5SDimitry Andric void NotifyModuleAdded(const ModuleList &module_list, 15010b57cec5SDimitry Andric const lldb::ModuleSP &module_sp) override; 15020b57cec5SDimitry Andric 15030b57cec5SDimitry Andric void NotifyModuleRemoved(const ModuleList &module_list, 15040b57cec5SDimitry Andric const lldb::ModuleSP &module_sp) override; 15050b57cec5SDimitry Andric 15060b57cec5SDimitry Andric void NotifyModuleUpdated(const ModuleList &module_list, 15070b57cec5SDimitry Andric const lldb::ModuleSP &old_module_sp, 15080b57cec5SDimitry Andric const lldb::ModuleSP &new_module_sp) override; 15090b57cec5SDimitry Andric 15100b57cec5SDimitry Andric void NotifyWillClearList(const ModuleList &module_list) override; 15110b57cec5SDimitry Andric 15120b57cec5SDimitry Andric void NotifyModulesRemoved(lldb_private::ModuleList &module_list) override; 15130b57cec5SDimitry Andric 15140b57cec5SDimitry Andric class Arch { 15150b57cec5SDimitry Andric public: 15160b57cec5SDimitry Andric explicit Arch(const ArchSpec &spec); 15170b57cec5SDimitry Andric const Arch &operator=(const ArchSpec &spec); 15180b57cec5SDimitry Andric GetSpec()15190b57cec5SDimitry Andric const ArchSpec &GetSpec() const { return m_spec; } GetPlugin()15200b57cec5SDimitry Andric Architecture *GetPlugin() const { return m_plugin_up.get(); } 15210b57cec5SDimitry Andric 15220b57cec5SDimitry Andric private: 15230b57cec5SDimitry Andric ArchSpec m_spec; 15240b57cec5SDimitry Andric std::unique_ptr<Architecture> m_plugin_up; 15250b57cec5SDimitry Andric }; 152681ad6265SDimitry Andric 15270b57cec5SDimitry Andric // Member variables. 15280b57cec5SDimitry Andric Debugger &m_debugger; 15290b57cec5SDimitry Andric lldb::PlatformSP m_platform_sp; ///< The platform for this target. 15300b57cec5SDimitry Andric std::recursive_mutex m_mutex; ///< An API mutex that is used by the lldb::SB* 15310b57cec5SDimitry Andric /// classes make the SB interface thread safe 15329dba64beSDimitry Andric /// When the private state thread calls SB API's - usually because it is 15339dba64beSDimitry Andric /// running OS plugin or Python ThreadPlan code - it should not block on the 15349dba64beSDimitry Andric /// API mutex that is held by the code that kicked off the sequence of events 15359dba64beSDimitry Andric /// that led us to run the code. We hand out this mutex instead when we 15369dba64beSDimitry Andric /// detect that code is running on the private state thread. 15379dba64beSDimitry Andric std::recursive_mutex m_private_mutex; 15380b57cec5SDimitry Andric Arch m_arch; 153906c3fb27SDimitry Andric std::string m_label; 15400b57cec5SDimitry Andric ModuleList m_images; ///< The list of images for this process (shared 15410b57cec5SDimitry Andric /// libraries and anything dynamically loaded). 15420b57cec5SDimitry Andric SectionLoadHistory m_section_load_history; 15430b57cec5SDimitry Andric BreakpointList m_breakpoint_list; 15440b57cec5SDimitry Andric BreakpointList m_internal_breakpoint_list; 1545bdd1243dSDimitry Andric using BreakpointNameList = 1546bdd1243dSDimitry Andric std::map<ConstString, std::unique_ptr<BreakpointName>>; 15470b57cec5SDimitry Andric BreakpointNameList m_breakpoint_names; 15480b57cec5SDimitry Andric 15490b57cec5SDimitry Andric lldb::BreakpointSP m_last_created_breakpoint; 15500b57cec5SDimitry Andric WatchpointList m_watchpoint_list; 15510b57cec5SDimitry Andric lldb::WatchpointSP m_last_created_watchpoint; 15520b57cec5SDimitry Andric // We want to tightly control the process destruction process so we can 15530b57cec5SDimitry Andric // correctly tear down everything that we need to, so the only class that 15540b57cec5SDimitry Andric // knows about the process lifespan is this target class. 15550b57cec5SDimitry Andric lldb::ProcessSP m_process_sp; 15560b57cec5SDimitry Andric lldb::SearchFilterSP m_search_filter_sp; 15570b57cec5SDimitry Andric PathMappingList m_image_search_paths; 15580b57cec5SDimitry Andric TypeSystemMap m_scratch_type_system_map; 15590b57cec5SDimitry Andric 15600b57cec5SDimitry Andric typedef std::map<lldb::LanguageType, lldb::REPLSP> REPLMap; 15610b57cec5SDimitry Andric REPLMap m_repl_map; 15620b57cec5SDimitry Andric 15630b57cec5SDimitry Andric lldb::SourceManagerUP m_source_manager_up; 15640b57cec5SDimitry Andric 15650b57cec5SDimitry Andric typedef std::map<lldb::user_id_t, StopHookSP> StopHookCollection; 15660b57cec5SDimitry Andric StopHookCollection m_stop_hooks; 15670b57cec5SDimitry Andric lldb::user_id_t m_stop_hook_next_id; 1568fe6060f1SDimitry Andric uint32_t m_latest_stop_hook_id; /// This records the last natural stop at 1569fe6060f1SDimitry Andric /// which we ran a stop-hook. 15700b57cec5SDimitry Andric bool m_valid; 1571fe6060f1SDimitry Andric bool m_suppress_stop_hooks; /// Used to not run stop hooks for expressions 15720b57cec5SDimitry Andric bool m_is_dummy_target; 15730b57cec5SDimitry Andric unsigned m_next_persistent_variable_index = 0; 1574e8d8bef9SDimitry Andric /// An optional \a lldb_private::Trace object containing processor trace 1575e8d8bef9SDimitry Andric /// information of this target. 1576e8d8bef9SDimitry Andric lldb::TraceSP m_trace_sp; 1577e8d8bef9SDimitry Andric /// Stores the frame recognizers of this target. 1578e8d8bef9SDimitry Andric lldb::StackFrameRecognizerManagerUP m_frame_recognizer_manager_up; 157981ad6265SDimitry Andric /// These are used to set the signal state when you don't have a process and 158081ad6265SDimitry Andric /// more usefully in the Dummy target where you can't know exactly what 158181ad6265SDimitry Andric /// signals you will have. 158281ad6265SDimitry Andric llvm::StringMap<DummySignalValues> m_dummy_signals; 15830b57cec5SDimitry Andric 15840b57cec5SDimitry Andric static void ImageSearchPathsChanged(const PathMappingList &path_list, 15850b57cec5SDimitry Andric void *baton); 15860b57cec5SDimitry Andric 15870b57cec5SDimitry Andric // Utilities for `statistics` command. 15880b57cec5SDimitry Andric private: 1589349cc55cSDimitry Andric // Target metrics storage. 1590349cc55cSDimitry Andric TargetStats m_stats; 15910b57cec5SDimitry Andric 15920b57cec5SDimitry Andric public: 1593349cc55cSDimitry Andric /// Get metrics associated with this target in JSON format. 1594349cc55cSDimitry Andric /// 1595349cc55cSDimitry Andric /// Target metrics help measure timings and information that is contained in 1596349cc55cSDimitry Andric /// a target. These are designed to help measure performance of a debug 1597349cc55cSDimitry Andric /// session as well as represent the current state of the target, like 1598349cc55cSDimitry Andric /// information on the currently modules, currently set breakpoints and more. 1599349cc55cSDimitry Andric /// 1600349cc55cSDimitry Andric /// \return 1601349cc55cSDimitry Andric /// Returns a JSON value that contains all target metrics. 1602349cc55cSDimitry Andric llvm::json::Value ReportStatistics(); 16030b57cec5SDimitry Andric GetStatistics()1604349cc55cSDimitry Andric TargetStats &GetStatistics() { return m_stats; } 16050b57cec5SDimitry Andric 16060b57cec5SDimitry Andric private: 16070b57cec5SDimitry Andric /// Construct with optional file and arch. 16080b57cec5SDimitry Andric /// 16090b57cec5SDimitry Andric /// This member is private. Clients must use 16100b57cec5SDimitry Andric /// TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 16110b57cec5SDimitry Andric /// so all targets can be tracked from the central target list. 16120b57cec5SDimitry Andric /// 16130b57cec5SDimitry Andric /// \see TargetList::CreateTarget(const FileSpec*, const ArchSpec*) 16140b57cec5SDimitry Andric Target(Debugger &debugger, const ArchSpec &target_arch, 16150b57cec5SDimitry Andric const lldb::PlatformSP &platform_sp, bool is_dummy_target); 16160b57cec5SDimitry Andric 16170b57cec5SDimitry Andric // Helper function. 16180b57cec5SDimitry Andric bool ProcessIsValid(); 16190b57cec5SDimitry Andric 16200b57cec5SDimitry Andric // Copy breakpoints, stop hooks and so forth from the dummy target: 1621e8d8bef9SDimitry Andric void PrimeFromDummyTarget(Target &target); 16220b57cec5SDimitry Andric 16230b57cec5SDimitry Andric void AddBreakpoint(lldb::BreakpointSP breakpoint_sp, bool internal); 16240b57cec5SDimitry Andric 16250b57cec5SDimitry Andric void FinalizeFileActions(ProcessLaunchInfo &info); 16260b57cec5SDimitry Andric 1627349cc55cSDimitry Andric /// Return a recommended size for memory reads at \a addr, optimizing for 1628349cc55cSDimitry Andric /// cache usage. 1629349cc55cSDimitry Andric lldb::addr_t GetReasonableReadSize(const Address &addr); 1630349cc55cSDimitry Andric 16315ffd83dbSDimitry Andric Target(const Target &) = delete; 16325ffd83dbSDimitry Andric const Target &operator=(const Target &) = delete; 16330b57cec5SDimitry Andric }; 16340b57cec5SDimitry Andric 16350b57cec5SDimitry Andric } // namespace lldb_private 16360b57cec5SDimitry Andric 16375ffd83dbSDimitry Andric #endif // LLDB_TARGET_TARGET_H 1638