15ffd83dbSDimitry Andric //===-- Target.cpp --------------------------------------------------------===//
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
90b57cec5SDimitry Andric #include "lldb/Target/Target.h"
100b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointIDList.h"
110b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointPrecondition.h"
120b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointResolver.h"
130b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointResolverAddress.h"
140b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointResolverFileLine.h"
150b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointResolverFileRegex.h"
160b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointResolverName.h"
170b57cec5SDimitry Andric #include "lldb/Breakpoint/BreakpointResolverScripted.h"
180b57cec5SDimitry Andric #include "lldb/Breakpoint/Watchpoint.h"
190b57cec5SDimitry Andric #include "lldb/Core/Debugger.h"
200b57cec5SDimitry Andric #include "lldb/Core/Module.h"
210b57cec5SDimitry Andric #include "lldb/Core/ModuleSpec.h"
220b57cec5SDimitry Andric #include "lldb/Core/PluginManager.h"
230b57cec5SDimitry Andric #include "lldb/Core/SearchFilter.h"
240b57cec5SDimitry Andric #include "lldb/Core/Section.h"
250b57cec5SDimitry Andric #include "lldb/Core/SourceManager.h"
260b57cec5SDimitry Andric #include "lldb/Core/StreamFile.h"
270b57cec5SDimitry Andric #include "lldb/Core/StructuredDataImpl.h"
280b57cec5SDimitry Andric #include "lldb/Core/ValueObject.h"
29af732203SDimitry Andric #include "lldb/Expression/DiagnosticManager.h"
305ffd83dbSDimitry Andric #include "lldb/Expression/ExpressionVariable.h"
310b57cec5SDimitry Andric #include "lldb/Expression/REPL.h"
320b57cec5SDimitry Andric #include "lldb/Expression/UserExpression.h"
33af732203SDimitry Andric #include "lldb/Expression/UtilityFunction.h"
340b57cec5SDimitry Andric #include "lldb/Host/Host.h"
350b57cec5SDimitry Andric #include "lldb/Host/PosixApi.h"
360b57cec5SDimitry Andric #include "lldb/Interpreter/CommandInterpreter.h"
370b57cec5SDimitry Andric #include "lldb/Interpreter/CommandReturnObject.h"
380b57cec5SDimitry Andric #include "lldb/Interpreter/OptionGroupWatchpoint.h"
390b57cec5SDimitry Andric #include "lldb/Interpreter/OptionValues.h"
400b57cec5SDimitry Andric #include "lldb/Interpreter/Property.h"
410b57cec5SDimitry Andric #include "lldb/Symbol/Function.h"
420b57cec5SDimitry Andric #include "lldb/Symbol/ObjectFile.h"
430b57cec5SDimitry Andric #include "lldb/Symbol/Symbol.h"
44*5f7ddb14SDimitry Andric #include "lldb/Target/ABI.h"
450b57cec5SDimitry Andric #include "lldb/Target/Language.h"
460b57cec5SDimitry Andric #include "lldb/Target/LanguageRuntime.h"
470b57cec5SDimitry Andric #include "lldb/Target/Process.h"
480b57cec5SDimitry Andric #include "lldb/Target/SectionLoadList.h"
490b57cec5SDimitry Andric #include "lldb/Target/StackFrame.h"
50af732203SDimitry Andric #include "lldb/Target/StackFrameRecognizer.h"
510b57cec5SDimitry Andric #include "lldb/Target/SystemRuntime.h"
520b57cec5SDimitry Andric #include "lldb/Target/Thread.h"
530b57cec5SDimitry Andric #include "lldb/Target/ThreadSpec.h"
540b57cec5SDimitry Andric #include "lldb/Utility/Event.h"
550b57cec5SDimitry Andric #include "lldb/Utility/FileSpec.h"
560b57cec5SDimitry Andric #include "lldb/Utility/LLDBAssert.h"
570b57cec5SDimitry Andric #include "lldb/Utility/Log.h"
580b57cec5SDimitry Andric #include "lldb/Utility/State.h"
590b57cec5SDimitry Andric #include "lldb/Utility/StreamString.h"
600b57cec5SDimitry Andric #include "lldb/Utility/Timer.h"
610b57cec5SDimitry Andric
620b57cec5SDimitry Andric #include "llvm/ADT/ScopeExit.h"
630b57cec5SDimitry Andric
640b57cec5SDimitry Andric #include <memory>
650b57cec5SDimitry Andric #include <mutex>
660b57cec5SDimitry Andric
670b57cec5SDimitry Andric using namespace lldb;
680b57cec5SDimitry Andric using namespace lldb_private;
690b57cec5SDimitry Andric
700b57cec5SDimitry Andric constexpr std::chrono::milliseconds EvaluateExpressionOptions::default_timeout;
710b57cec5SDimitry Andric
Arch(const ArchSpec & spec)720b57cec5SDimitry Andric Target::Arch::Arch(const ArchSpec &spec)
730b57cec5SDimitry Andric : m_spec(spec),
740b57cec5SDimitry Andric m_plugin_up(PluginManager::CreateArchitectureInstance(spec)) {}
750b57cec5SDimitry Andric
operator =(const ArchSpec & spec)760b57cec5SDimitry Andric const Target::Arch &Target::Arch::operator=(const ArchSpec &spec) {
770b57cec5SDimitry Andric m_spec = spec;
780b57cec5SDimitry Andric m_plugin_up = PluginManager::CreateArchitectureInstance(spec);
790b57cec5SDimitry Andric return *this;
800b57cec5SDimitry Andric }
810b57cec5SDimitry Andric
GetStaticBroadcasterClass()820b57cec5SDimitry Andric ConstString &Target::GetStaticBroadcasterClass() {
830b57cec5SDimitry Andric static ConstString class_name("lldb.target");
840b57cec5SDimitry Andric return class_name;
850b57cec5SDimitry Andric }
860b57cec5SDimitry Andric
Target(Debugger & debugger,const ArchSpec & target_arch,const lldb::PlatformSP & platform_sp,bool is_dummy_target)870b57cec5SDimitry Andric Target::Target(Debugger &debugger, const ArchSpec &target_arch,
880b57cec5SDimitry Andric const lldb::PlatformSP &platform_sp, bool is_dummy_target)
890b57cec5SDimitry Andric : TargetProperties(this),
900b57cec5SDimitry Andric Broadcaster(debugger.GetBroadcasterManager(),
910b57cec5SDimitry Andric Target::GetStaticBroadcasterClass().AsCString()),
920b57cec5SDimitry Andric ExecutionContextScope(), m_debugger(debugger), m_platform_sp(platform_sp),
930b57cec5SDimitry Andric m_mutex(), m_arch(target_arch), m_images(this), m_section_load_history(),
940b57cec5SDimitry Andric m_breakpoint_list(false), m_internal_breakpoint_list(true),
950b57cec5SDimitry Andric m_watchpoint_list(), m_process_sp(), m_search_filter_sp(),
965ffd83dbSDimitry Andric m_image_search_paths(ImageSearchPathsChanged, this),
970b57cec5SDimitry Andric m_source_manager_up(), m_stop_hooks(), m_stop_hook_next_id(0),
98*5f7ddb14SDimitry Andric m_latest_stop_hook_id(0),
990b57cec5SDimitry Andric m_valid(true), m_suppress_stop_hooks(false),
1000b57cec5SDimitry Andric m_is_dummy_target(is_dummy_target),
101af732203SDimitry Andric m_frame_recognizer_manager_up(
102af732203SDimitry Andric std::make_unique<StackFrameRecognizerManager>()),
1030b57cec5SDimitry Andric m_stats_storage(static_cast<int>(StatisticKind::StatisticMax))
1040b57cec5SDimitry Andric
1050b57cec5SDimitry Andric {
1060b57cec5SDimitry Andric SetEventName(eBroadcastBitBreakpointChanged, "breakpoint-changed");
1070b57cec5SDimitry Andric SetEventName(eBroadcastBitModulesLoaded, "modules-loaded");
1080b57cec5SDimitry Andric SetEventName(eBroadcastBitModulesUnloaded, "modules-unloaded");
1090b57cec5SDimitry Andric SetEventName(eBroadcastBitWatchpointChanged, "watchpoint-changed");
1100b57cec5SDimitry Andric SetEventName(eBroadcastBitSymbolsLoaded, "symbols-loaded");
1110b57cec5SDimitry Andric
1120b57cec5SDimitry Andric CheckInWithManager();
1130b57cec5SDimitry Andric
1149dba64beSDimitry Andric LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT),
1159dba64beSDimitry Andric "{0} Target::Target()", static_cast<void *>(this));
1160b57cec5SDimitry Andric if (target_arch.IsValid()) {
1179dba64beSDimitry Andric LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET),
1189dba64beSDimitry Andric "Target::Target created with architecture {0} ({1})",
1190b57cec5SDimitry Andric target_arch.GetArchitectureName(),
1200b57cec5SDimitry Andric target_arch.GetTriple().getTriple().c_str());
1210b57cec5SDimitry Andric }
1225ffd83dbSDimitry Andric
1235ffd83dbSDimitry Andric UpdateLaunchInfoFromProperties();
1240b57cec5SDimitry Andric }
1250b57cec5SDimitry Andric
~Target()1260b57cec5SDimitry Andric Target::~Target() {
1270b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT));
1289dba64beSDimitry Andric LLDB_LOG(log, "{0} Target::~Target()", static_cast<void *>(this));
1290b57cec5SDimitry Andric DeleteCurrentProcess();
1300b57cec5SDimitry Andric }
1310b57cec5SDimitry Andric
PrimeFromDummyTarget(Target & target)132af732203SDimitry Andric void Target::PrimeFromDummyTarget(Target &target) {
133af732203SDimitry Andric m_stop_hooks = target.m_stop_hooks;
1340b57cec5SDimitry Andric
135af732203SDimitry Andric for (const auto &breakpoint_sp : target.m_breakpoint_list.Breakpoints()) {
1360b57cec5SDimitry Andric if (breakpoint_sp->IsInternal())
1370b57cec5SDimitry Andric continue;
1380b57cec5SDimitry Andric
1395ffd83dbSDimitry Andric BreakpointSP new_bp(
1405ffd83dbSDimitry Andric Breakpoint::CopyFromBreakpoint(shared_from_this(), *breakpoint_sp));
1415ffd83dbSDimitry Andric AddBreakpoint(std::move(new_bp), false);
1420b57cec5SDimitry Andric }
1430b57cec5SDimitry Andric
144af732203SDimitry Andric for (auto bp_name_entry : target.m_breakpoint_names) {
1450b57cec5SDimitry Andric
1460b57cec5SDimitry Andric BreakpointName *new_bp_name = new BreakpointName(*bp_name_entry.second);
1470b57cec5SDimitry Andric AddBreakpointName(new_bp_name);
1480b57cec5SDimitry Andric }
149af732203SDimitry Andric
150af732203SDimitry Andric m_frame_recognizer_manager_up = std::make_unique<StackFrameRecognizerManager>(
151af732203SDimitry Andric *target.m_frame_recognizer_manager_up);
1520b57cec5SDimitry Andric }
1530b57cec5SDimitry Andric
Dump(Stream * s,lldb::DescriptionLevel description_level)1540b57cec5SDimitry Andric void Target::Dump(Stream *s, lldb::DescriptionLevel description_level) {
1550b57cec5SDimitry Andric // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this);
1560b57cec5SDimitry Andric if (description_level != lldb::eDescriptionLevelBrief) {
1570b57cec5SDimitry Andric s->Indent();
1580b57cec5SDimitry Andric s->PutCString("Target\n");
1590b57cec5SDimitry Andric s->IndentMore();
1600b57cec5SDimitry Andric m_images.Dump(s);
1610b57cec5SDimitry Andric m_breakpoint_list.Dump(s);
1620b57cec5SDimitry Andric m_internal_breakpoint_list.Dump(s);
1630b57cec5SDimitry Andric s->IndentLess();
1640b57cec5SDimitry Andric } else {
1650b57cec5SDimitry Andric Module *exe_module = GetExecutableModulePointer();
1660b57cec5SDimitry Andric if (exe_module)
1670b57cec5SDimitry Andric s->PutCString(exe_module->GetFileSpec().GetFilename().GetCString());
1680b57cec5SDimitry Andric else
1690b57cec5SDimitry Andric s->PutCString("No executable module.");
1700b57cec5SDimitry Andric }
1710b57cec5SDimitry Andric }
1720b57cec5SDimitry Andric
CleanupProcess()1730b57cec5SDimitry Andric void Target::CleanupProcess() {
1740b57cec5SDimitry Andric // Do any cleanup of the target we need to do between process instances.
1750b57cec5SDimitry Andric // NB It is better to do this before destroying the process in case the
1760b57cec5SDimitry Andric // clean up needs some help from the process.
1770b57cec5SDimitry Andric m_breakpoint_list.ClearAllBreakpointSites();
1780b57cec5SDimitry Andric m_internal_breakpoint_list.ClearAllBreakpointSites();
1790b57cec5SDimitry Andric // Disable watchpoints just on the debugger side.
1800b57cec5SDimitry Andric std::unique_lock<std::recursive_mutex> lock;
1810b57cec5SDimitry Andric this->GetWatchpointList().GetListMutex(lock);
1820b57cec5SDimitry Andric DisableAllWatchpoints(false);
1830b57cec5SDimitry Andric ClearAllWatchpointHitCounts();
1840b57cec5SDimitry Andric ClearAllWatchpointHistoricValues();
185*5f7ddb14SDimitry Andric m_latest_stop_hook_id = 0;
1860b57cec5SDimitry Andric }
1870b57cec5SDimitry Andric
DeleteCurrentProcess()1880b57cec5SDimitry Andric void Target::DeleteCurrentProcess() {
1890b57cec5SDimitry Andric if (m_process_sp) {
1900b57cec5SDimitry Andric m_section_load_history.Clear();
1910b57cec5SDimitry Andric if (m_process_sp->IsAlive())
1920b57cec5SDimitry Andric m_process_sp->Destroy(false);
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andric m_process_sp->Finalize();
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andric CleanupProcess();
1970b57cec5SDimitry Andric
1980b57cec5SDimitry Andric m_process_sp.reset();
1990b57cec5SDimitry Andric }
2000b57cec5SDimitry Andric }
2010b57cec5SDimitry Andric
CreateProcess(ListenerSP listener_sp,llvm::StringRef plugin_name,const FileSpec * crash_file,bool can_connect)2020b57cec5SDimitry Andric const lldb::ProcessSP &Target::CreateProcess(ListenerSP listener_sp,
2030b57cec5SDimitry Andric llvm::StringRef plugin_name,
204af732203SDimitry Andric const FileSpec *crash_file,
205af732203SDimitry Andric bool can_connect) {
2060b57cec5SDimitry Andric if (!listener_sp)
2070b57cec5SDimitry Andric listener_sp = GetDebugger().GetListener();
2080b57cec5SDimitry Andric DeleteCurrentProcess();
2090b57cec5SDimitry Andric m_process_sp = Process::FindPlugin(shared_from_this(), plugin_name,
210af732203SDimitry Andric listener_sp, crash_file, can_connect);
2110b57cec5SDimitry Andric return m_process_sp;
2120b57cec5SDimitry Andric }
2130b57cec5SDimitry Andric
GetProcessSP() const2140b57cec5SDimitry Andric const lldb::ProcessSP &Target::GetProcessSP() const { return m_process_sp; }
2150b57cec5SDimitry Andric
GetREPL(Status & err,lldb::LanguageType language,const char * repl_options,bool can_create)2160b57cec5SDimitry Andric lldb::REPLSP Target::GetREPL(Status &err, lldb::LanguageType language,
2170b57cec5SDimitry Andric const char *repl_options, bool can_create) {
2180b57cec5SDimitry Andric if (language == eLanguageTypeUnknown) {
2199dba64beSDimitry Andric LanguageSet repl_languages = Language::GetLanguagesSupportingREPLs();
2200b57cec5SDimitry Andric
2219dba64beSDimitry Andric if (auto single_lang = repl_languages.GetSingularLanguage()) {
2229dba64beSDimitry Andric language = *single_lang;
2239dba64beSDimitry Andric } else if (repl_languages.Empty()) {
2240b57cec5SDimitry Andric err.SetErrorStringWithFormat(
2250b57cec5SDimitry Andric "LLDB isn't configured with REPL support for any languages.");
2260b57cec5SDimitry Andric return REPLSP();
2270b57cec5SDimitry Andric } else {
2280b57cec5SDimitry Andric err.SetErrorStringWithFormat(
2290b57cec5SDimitry Andric "Multiple possible REPL languages. Please specify a language.");
2300b57cec5SDimitry Andric return REPLSP();
2310b57cec5SDimitry Andric }
2320b57cec5SDimitry Andric }
2330b57cec5SDimitry Andric
2340b57cec5SDimitry Andric REPLMap::iterator pos = m_repl_map.find(language);
2350b57cec5SDimitry Andric
2360b57cec5SDimitry Andric if (pos != m_repl_map.end()) {
2370b57cec5SDimitry Andric return pos->second;
2380b57cec5SDimitry Andric }
2390b57cec5SDimitry Andric
2400b57cec5SDimitry Andric if (!can_create) {
2410b57cec5SDimitry Andric err.SetErrorStringWithFormat(
2420b57cec5SDimitry Andric "Couldn't find an existing REPL for %s, and can't create a new one",
2430b57cec5SDimitry Andric Language::GetNameForLanguageType(language));
2440b57cec5SDimitry Andric return lldb::REPLSP();
2450b57cec5SDimitry Andric }
2460b57cec5SDimitry Andric
2470b57cec5SDimitry Andric Debugger *const debugger = nullptr;
2480b57cec5SDimitry Andric lldb::REPLSP ret = REPL::Create(err, language, debugger, this, repl_options);
2490b57cec5SDimitry Andric
2500b57cec5SDimitry Andric if (ret) {
2510b57cec5SDimitry Andric m_repl_map[language] = ret;
2520b57cec5SDimitry Andric return m_repl_map[language];
2530b57cec5SDimitry Andric }
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andric if (err.Success()) {
2560b57cec5SDimitry Andric err.SetErrorStringWithFormat("Couldn't create a REPL for %s",
2570b57cec5SDimitry Andric Language::GetNameForLanguageType(language));
2580b57cec5SDimitry Andric }
2590b57cec5SDimitry Andric
2600b57cec5SDimitry Andric return lldb::REPLSP();
2610b57cec5SDimitry Andric }
2620b57cec5SDimitry Andric
SetREPL(lldb::LanguageType language,lldb::REPLSP repl_sp)2630b57cec5SDimitry Andric void Target::SetREPL(lldb::LanguageType language, lldb::REPLSP repl_sp) {
2640b57cec5SDimitry Andric lldbassert(!m_repl_map.count(language));
2650b57cec5SDimitry Andric
2660b57cec5SDimitry Andric m_repl_map[language] = repl_sp;
2670b57cec5SDimitry Andric }
2680b57cec5SDimitry Andric
Destroy()2690b57cec5SDimitry Andric void Target::Destroy() {
2700b57cec5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(m_mutex);
2710b57cec5SDimitry Andric m_valid = false;
2720b57cec5SDimitry Andric DeleteCurrentProcess();
2730b57cec5SDimitry Andric m_platform_sp.reset();
2740b57cec5SDimitry Andric m_arch = ArchSpec();
2750b57cec5SDimitry Andric ClearModules(true);
2760b57cec5SDimitry Andric m_section_load_history.Clear();
2770b57cec5SDimitry Andric const bool notify = false;
2780b57cec5SDimitry Andric m_breakpoint_list.RemoveAll(notify);
2790b57cec5SDimitry Andric m_internal_breakpoint_list.RemoveAll(notify);
2800b57cec5SDimitry Andric m_last_created_breakpoint.reset();
2810b57cec5SDimitry Andric m_last_created_watchpoint.reset();
2820b57cec5SDimitry Andric m_search_filter_sp.reset();
2830b57cec5SDimitry Andric m_image_search_paths.Clear(notify);
2840b57cec5SDimitry Andric m_stop_hooks.clear();
2850b57cec5SDimitry Andric m_stop_hook_next_id = 0;
2860b57cec5SDimitry Andric m_suppress_stop_hooks = false;
2870b57cec5SDimitry Andric }
2880b57cec5SDimitry Andric
GetBreakpointList(bool internal)2890b57cec5SDimitry Andric BreakpointList &Target::GetBreakpointList(bool internal) {
2900b57cec5SDimitry Andric if (internal)
2910b57cec5SDimitry Andric return m_internal_breakpoint_list;
2920b57cec5SDimitry Andric else
2930b57cec5SDimitry Andric return m_breakpoint_list;
2940b57cec5SDimitry Andric }
2950b57cec5SDimitry Andric
GetBreakpointList(bool internal) const2960b57cec5SDimitry Andric const BreakpointList &Target::GetBreakpointList(bool internal) const {
2970b57cec5SDimitry Andric if (internal)
2980b57cec5SDimitry Andric return m_internal_breakpoint_list;
2990b57cec5SDimitry Andric else
3000b57cec5SDimitry Andric return m_breakpoint_list;
3010b57cec5SDimitry Andric }
3020b57cec5SDimitry Andric
GetBreakpointByID(break_id_t break_id)3030b57cec5SDimitry Andric BreakpointSP Target::GetBreakpointByID(break_id_t break_id) {
3040b57cec5SDimitry Andric BreakpointSP bp_sp;
3050b57cec5SDimitry Andric
3060b57cec5SDimitry Andric if (LLDB_BREAK_ID_IS_INTERNAL(break_id))
3070b57cec5SDimitry Andric bp_sp = m_internal_breakpoint_list.FindBreakpointByID(break_id);
3080b57cec5SDimitry Andric else
3090b57cec5SDimitry Andric bp_sp = m_breakpoint_list.FindBreakpointByID(break_id);
3100b57cec5SDimitry Andric
3110b57cec5SDimitry Andric return bp_sp;
3120b57cec5SDimitry Andric }
3130b57cec5SDimitry Andric
CreateSourceRegexBreakpoint(const FileSpecList * containingModules,const FileSpecList * source_file_spec_list,const std::unordered_set<std::string> & function_names,RegularExpression source_regex,bool internal,bool hardware,LazyBool move_to_nearest_code)3140b57cec5SDimitry Andric BreakpointSP Target::CreateSourceRegexBreakpoint(
3150b57cec5SDimitry Andric const FileSpecList *containingModules,
3160b57cec5SDimitry Andric const FileSpecList *source_file_spec_list,
3170b57cec5SDimitry Andric const std::unordered_set<std::string> &function_names,
3189dba64beSDimitry Andric RegularExpression source_regex, bool internal, bool hardware,
3190b57cec5SDimitry Andric LazyBool move_to_nearest_code) {
3200b57cec5SDimitry Andric SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList(
3210b57cec5SDimitry Andric containingModules, source_file_spec_list));
3220b57cec5SDimitry Andric if (move_to_nearest_code == eLazyBoolCalculate)
3230b57cec5SDimitry Andric move_to_nearest_code = GetMoveToNearestCode() ? eLazyBoolYes : eLazyBoolNo;
3240b57cec5SDimitry Andric BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex(
3259dba64beSDimitry Andric nullptr, std::move(source_regex), function_names,
3260b57cec5SDimitry Andric !static_cast<bool>(move_to_nearest_code)));
3270b57cec5SDimitry Andric
3280b57cec5SDimitry Andric return CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true);
3290b57cec5SDimitry Andric }
3300b57cec5SDimitry Andric
CreateBreakpoint(const FileSpecList * containingModules,const FileSpec & file,uint32_t line_no,uint32_t column,lldb::addr_t offset,LazyBool check_inlines,LazyBool skip_prologue,bool internal,bool hardware,LazyBool move_to_nearest_code)3310b57cec5SDimitry Andric BreakpointSP Target::CreateBreakpoint(const FileSpecList *containingModules,
3320b57cec5SDimitry Andric const FileSpec &file, uint32_t line_no,
3330b57cec5SDimitry Andric uint32_t column, lldb::addr_t offset,
3340b57cec5SDimitry Andric LazyBool check_inlines,
3350b57cec5SDimitry Andric LazyBool skip_prologue, bool internal,
3360b57cec5SDimitry Andric bool hardware,
3370b57cec5SDimitry Andric LazyBool move_to_nearest_code) {
3380b57cec5SDimitry Andric FileSpec remapped_file;
3390b57cec5SDimitry Andric if (!GetSourcePathMap().ReverseRemapPath(file, remapped_file))
3400b57cec5SDimitry Andric remapped_file = file;
3410b57cec5SDimitry Andric
3420b57cec5SDimitry Andric if (check_inlines == eLazyBoolCalculate) {
3430b57cec5SDimitry Andric const InlineStrategy inline_strategy = GetInlineStrategy();
3440b57cec5SDimitry Andric switch (inline_strategy) {
3450b57cec5SDimitry Andric case eInlineBreakpointsNever:
3460b57cec5SDimitry Andric check_inlines = eLazyBoolNo;
3470b57cec5SDimitry Andric break;
3480b57cec5SDimitry Andric
3490b57cec5SDimitry Andric case eInlineBreakpointsHeaders:
3500b57cec5SDimitry Andric if (remapped_file.IsSourceImplementationFile())
3510b57cec5SDimitry Andric check_inlines = eLazyBoolNo;
3520b57cec5SDimitry Andric else
3530b57cec5SDimitry Andric check_inlines = eLazyBoolYes;
3540b57cec5SDimitry Andric break;
3550b57cec5SDimitry Andric
3560b57cec5SDimitry Andric case eInlineBreakpointsAlways:
3570b57cec5SDimitry Andric check_inlines = eLazyBoolYes;
3580b57cec5SDimitry Andric break;
3590b57cec5SDimitry Andric }
3600b57cec5SDimitry Andric }
3610b57cec5SDimitry Andric SearchFilterSP filter_sp;
3620b57cec5SDimitry Andric if (check_inlines == eLazyBoolNo) {
3630b57cec5SDimitry Andric // Not checking for inlines, we are looking only for matching compile units
3640b57cec5SDimitry Andric FileSpecList compile_unit_list;
3650b57cec5SDimitry Andric compile_unit_list.Append(remapped_file);
3660b57cec5SDimitry Andric filter_sp = GetSearchFilterForModuleAndCUList(containingModules,
3670b57cec5SDimitry Andric &compile_unit_list);
3680b57cec5SDimitry Andric } else {
3690b57cec5SDimitry Andric filter_sp = GetSearchFilterForModuleList(containingModules);
3700b57cec5SDimitry Andric }
3710b57cec5SDimitry Andric if (skip_prologue == eLazyBoolCalculate)
3720b57cec5SDimitry Andric skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
3730b57cec5SDimitry Andric if (move_to_nearest_code == eLazyBoolCalculate)
3740b57cec5SDimitry Andric move_to_nearest_code = GetMoveToNearestCode() ? eLazyBoolYes : eLazyBoolNo;
3750b57cec5SDimitry Andric
376*5f7ddb14SDimitry Andric SourceLocationSpec location_spec(remapped_file, line_no, column,
377*5f7ddb14SDimitry Andric check_inlines,
378*5f7ddb14SDimitry Andric !static_cast<bool>(move_to_nearest_code));
379*5f7ddb14SDimitry Andric if (!location_spec)
380*5f7ddb14SDimitry Andric return nullptr;
381*5f7ddb14SDimitry Andric
3820b57cec5SDimitry Andric BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine(
383*5f7ddb14SDimitry Andric nullptr, offset, skip_prologue, location_spec));
3840b57cec5SDimitry Andric return CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true);
3850b57cec5SDimitry Andric }
3860b57cec5SDimitry Andric
CreateBreakpoint(lldb::addr_t addr,bool internal,bool hardware)3870b57cec5SDimitry Andric BreakpointSP Target::CreateBreakpoint(lldb::addr_t addr, bool internal,
3880b57cec5SDimitry Andric bool hardware) {
3890b57cec5SDimitry Andric Address so_addr;
3900b57cec5SDimitry Andric
3910b57cec5SDimitry Andric // Check for any reason we want to move this breakpoint to other address.
3920b57cec5SDimitry Andric addr = GetBreakableLoadAddress(addr);
3930b57cec5SDimitry Andric
3940b57cec5SDimitry Andric // Attempt to resolve our load address if possible, though it is ok if it
3950b57cec5SDimitry Andric // doesn't resolve to section/offset.
3960b57cec5SDimitry Andric
3970b57cec5SDimitry Andric // Try and resolve as a load address if possible
3980b57cec5SDimitry Andric GetSectionLoadList().ResolveLoadAddress(addr, so_addr);
3990b57cec5SDimitry Andric if (!so_addr.IsValid()) {
4000b57cec5SDimitry Andric // The address didn't resolve, so just set this as an absolute address
4010b57cec5SDimitry Andric so_addr.SetOffset(addr);
4020b57cec5SDimitry Andric }
4030b57cec5SDimitry Andric BreakpointSP bp_sp(CreateBreakpoint(so_addr, internal, hardware));
4040b57cec5SDimitry Andric return bp_sp;
4050b57cec5SDimitry Andric }
4060b57cec5SDimitry Andric
CreateBreakpoint(const Address & addr,bool internal,bool hardware)4070b57cec5SDimitry Andric BreakpointSP Target::CreateBreakpoint(const Address &addr, bool internal,
4080b57cec5SDimitry Andric bool hardware) {
4090b57cec5SDimitry Andric SearchFilterSP filter_sp(
4100b57cec5SDimitry Andric new SearchFilterForUnconstrainedSearches(shared_from_this()));
4110b57cec5SDimitry Andric BreakpointResolverSP resolver_sp(
4120b57cec5SDimitry Andric new BreakpointResolverAddress(nullptr, addr));
4130b57cec5SDimitry Andric return CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, false);
4140b57cec5SDimitry Andric }
4150b57cec5SDimitry Andric
4160b57cec5SDimitry Andric lldb::BreakpointSP
CreateAddressInModuleBreakpoint(lldb::addr_t file_addr,bool internal,const FileSpec * file_spec,bool request_hardware)4170b57cec5SDimitry Andric Target::CreateAddressInModuleBreakpoint(lldb::addr_t file_addr, bool internal,
4180b57cec5SDimitry Andric const FileSpec *file_spec,
4190b57cec5SDimitry Andric bool request_hardware) {
4200b57cec5SDimitry Andric SearchFilterSP filter_sp(
4210b57cec5SDimitry Andric new SearchFilterForUnconstrainedSearches(shared_from_this()));
422480093f4SDimitry Andric BreakpointResolverSP resolver_sp(new BreakpointResolverAddress(
423480093f4SDimitry Andric nullptr, file_addr, file_spec ? *file_spec : FileSpec()));
4240b57cec5SDimitry Andric return CreateBreakpoint(filter_sp, resolver_sp, internal, request_hardware,
4250b57cec5SDimitry Andric false);
4260b57cec5SDimitry Andric }
4270b57cec5SDimitry Andric
CreateBreakpoint(const FileSpecList * containingModules,const FileSpecList * containingSourceFiles,const char * func_name,FunctionNameType func_name_type_mask,LanguageType language,lldb::addr_t offset,LazyBool skip_prologue,bool internal,bool hardware)4280b57cec5SDimitry Andric BreakpointSP Target::CreateBreakpoint(
4290b57cec5SDimitry Andric const FileSpecList *containingModules,
4300b57cec5SDimitry Andric const FileSpecList *containingSourceFiles, const char *func_name,
4310b57cec5SDimitry Andric FunctionNameType func_name_type_mask, LanguageType language,
4320b57cec5SDimitry Andric lldb::addr_t offset, LazyBool skip_prologue, bool internal, bool hardware) {
4330b57cec5SDimitry Andric BreakpointSP bp_sp;
4340b57cec5SDimitry Andric if (func_name) {
4350b57cec5SDimitry Andric SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList(
4360b57cec5SDimitry Andric containingModules, containingSourceFiles));
4370b57cec5SDimitry Andric
4380b57cec5SDimitry Andric if (skip_prologue == eLazyBoolCalculate)
4390b57cec5SDimitry Andric skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
4400b57cec5SDimitry Andric if (language == lldb::eLanguageTypeUnknown)
4410b57cec5SDimitry Andric language = GetLanguage();
4420b57cec5SDimitry Andric
4430b57cec5SDimitry Andric BreakpointResolverSP resolver_sp(new BreakpointResolverName(
4440b57cec5SDimitry Andric nullptr, func_name, func_name_type_mask, language, Breakpoint::Exact,
4450b57cec5SDimitry Andric offset, skip_prologue));
4460b57cec5SDimitry Andric bp_sp = CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true);
4470b57cec5SDimitry Andric }
4480b57cec5SDimitry Andric return bp_sp;
4490b57cec5SDimitry Andric }
4500b57cec5SDimitry Andric
4510b57cec5SDimitry Andric lldb::BreakpointSP
CreateBreakpoint(const FileSpecList * containingModules,const FileSpecList * containingSourceFiles,const std::vector<std::string> & func_names,FunctionNameType func_name_type_mask,LanguageType language,lldb::addr_t offset,LazyBool skip_prologue,bool internal,bool hardware)4520b57cec5SDimitry Andric Target::CreateBreakpoint(const FileSpecList *containingModules,
4530b57cec5SDimitry Andric const FileSpecList *containingSourceFiles,
4540b57cec5SDimitry Andric const std::vector<std::string> &func_names,
4550b57cec5SDimitry Andric FunctionNameType func_name_type_mask,
4560b57cec5SDimitry Andric LanguageType language, lldb::addr_t offset,
4570b57cec5SDimitry Andric LazyBool skip_prologue, bool internal, bool hardware) {
4580b57cec5SDimitry Andric BreakpointSP bp_sp;
4590b57cec5SDimitry Andric size_t num_names = func_names.size();
4600b57cec5SDimitry Andric if (num_names > 0) {
4610b57cec5SDimitry Andric SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList(
4620b57cec5SDimitry Andric containingModules, containingSourceFiles));
4630b57cec5SDimitry Andric
4640b57cec5SDimitry Andric if (skip_prologue == eLazyBoolCalculate)
4650b57cec5SDimitry Andric skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
4660b57cec5SDimitry Andric if (language == lldb::eLanguageTypeUnknown)
4670b57cec5SDimitry Andric language = GetLanguage();
4680b57cec5SDimitry Andric
4690b57cec5SDimitry Andric BreakpointResolverSP resolver_sp(
4700b57cec5SDimitry Andric new BreakpointResolverName(nullptr, func_names, func_name_type_mask,
4710b57cec5SDimitry Andric language, offset, skip_prologue));
4720b57cec5SDimitry Andric bp_sp = CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true);
4730b57cec5SDimitry Andric }
4740b57cec5SDimitry Andric return bp_sp;
4750b57cec5SDimitry Andric }
4760b57cec5SDimitry Andric
4770b57cec5SDimitry Andric BreakpointSP
CreateBreakpoint(const FileSpecList * containingModules,const FileSpecList * containingSourceFiles,const char * func_names[],size_t num_names,FunctionNameType func_name_type_mask,LanguageType language,lldb::addr_t offset,LazyBool skip_prologue,bool internal,bool hardware)4780b57cec5SDimitry Andric Target::CreateBreakpoint(const FileSpecList *containingModules,
4790b57cec5SDimitry Andric const FileSpecList *containingSourceFiles,
4800b57cec5SDimitry Andric const char *func_names[], size_t num_names,
4810b57cec5SDimitry Andric FunctionNameType func_name_type_mask,
4820b57cec5SDimitry Andric LanguageType language, lldb::addr_t offset,
4830b57cec5SDimitry Andric LazyBool skip_prologue, bool internal, bool hardware) {
4840b57cec5SDimitry Andric BreakpointSP bp_sp;
4850b57cec5SDimitry Andric if (num_names > 0) {
4860b57cec5SDimitry Andric SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList(
4870b57cec5SDimitry Andric containingModules, containingSourceFiles));
4880b57cec5SDimitry Andric
4890b57cec5SDimitry Andric if (skip_prologue == eLazyBoolCalculate) {
4900b57cec5SDimitry Andric if (offset == 0)
4910b57cec5SDimitry Andric skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo;
4920b57cec5SDimitry Andric else
4930b57cec5SDimitry Andric skip_prologue = eLazyBoolNo;
4940b57cec5SDimitry Andric }
4950b57cec5SDimitry Andric if (language == lldb::eLanguageTypeUnknown)
4960b57cec5SDimitry Andric language = GetLanguage();
4970b57cec5SDimitry Andric
4980b57cec5SDimitry Andric BreakpointResolverSP resolver_sp(new BreakpointResolverName(
4990b57cec5SDimitry Andric nullptr, func_names, num_names, func_name_type_mask, language, offset,
5000b57cec5SDimitry Andric skip_prologue));
5010b57cec5SDimitry Andric resolver_sp->SetOffset(offset);
5020b57cec5SDimitry Andric bp_sp = CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true);
5030b57cec5SDimitry Andric }
5040b57cec5SDimitry Andric return bp_sp;
5050b57cec5SDimitry Andric }
5060b57cec5SDimitry Andric
5070b57cec5SDimitry Andric SearchFilterSP
GetSearchFilterForModule(const FileSpec * containingModule)5080b57cec5SDimitry Andric Target::GetSearchFilterForModule(const FileSpec *containingModule) {
5090b57cec5SDimitry Andric SearchFilterSP filter_sp;
5100b57cec5SDimitry Andric if (containingModule != nullptr) {
5110b57cec5SDimitry Andric // TODO: We should look into sharing module based search filters
5120b57cec5SDimitry Andric // across many breakpoints like we do for the simple target based one
5130b57cec5SDimitry Andric filter_sp = std::make_shared<SearchFilterByModule>(shared_from_this(),
5140b57cec5SDimitry Andric *containingModule);
5150b57cec5SDimitry Andric } else {
5160b57cec5SDimitry Andric if (!m_search_filter_sp)
5170b57cec5SDimitry Andric m_search_filter_sp =
5180b57cec5SDimitry Andric std::make_shared<SearchFilterForUnconstrainedSearches>(
5190b57cec5SDimitry Andric shared_from_this());
5200b57cec5SDimitry Andric filter_sp = m_search_filter_sp;
5210b57cec5SDimitry Andric }
5220b57cec5SDimitry Andric return filter_sp;
5230b57cec5SDimitry Andric }
5240b57cec5SDimitry Andric
5250b57cec5SDimitry Andric SearchFilterSP
GetSearchFilterForModuleList(const FileSpecList * containingModules)5260b57cec5SDimitry Andric Target::GetSearchFilterForModuleList(const FileSpecList *containingModules) {
5270b57cec5SDimitry Andric SearchFilterSP filter_sp;
5280b57cec5SDimitry Andric if (containingModules && containingModules->GetSize() != 0) {
5290b57cec5SDimitry Andric // TODO: We should look into sharing module based search filters
5300b57cec5SDimitry Andric // across many breakpoints like we do for the simple target based one
5310b57cec5SDimitry Andric filter_sp = std::make_shared<SearchFilterByModuleList>(shared_from_this(),
5320b57cec5SDimitry Andric *containingModules);
5330b57cec5SDimitry Andric } else {
5340b57cec5SDimitry Andric if (!m_search_filter_sp)
5350b57cec5SDimitry Andric m_search_filter_sp =
5360b57cec5SDimitry Andric std::make_shared<SearchFilterForUnconstrainedSearches>(
5370b57cec5SDimitry Andric shared_from_this());
5380b57cec5SDimitry Andric filter_sp = m_search_filter_sp;
5390b57cec5SDimitry Andric }
5400b57cec5SDimitry Andric return filter_sp;
5410b57cec5SDimitry Andric }
5420b57cec5SDimitry Andric
GetSearchFilterForModuleAndCUList(const FileSpecList * containingModules,const FileSpecList * containingSourceFiles)5430b57cec5SDimitry Andric SearchFilterSP Target::GetSearchFilterForModuleAndCUList(
5440b57cec5SDimitry Andric const FileSpecList *containingModules,
5450b57cec5SDimitry Andric const FileSpecList *containingSourceFiles) {
5460b57cec5SDimitry Andric if (containingSourceFiles == nullptr || containingSourceFiles->GetSize() == 0)
5470b57cec5SDimitry Andric return GetSearchFilterForModuleList(containingModules);
5480b57cec5SDimitry Andric
5490b57cec5SDimitry Andric SearchFilterSP filter_sp;
5500b57cec5SDimitry Andric if (containingModules == nullptr) {
5510b57cec5SDimitry Andric // We could make a special "CU List only SearchFilter". Better yet was if
5520b57cec5SDimitry Andric // these could be composable, but that will take a little reworking.
5530b57cec5SDimitry Andric
5540b57cec5SDimitry Andric filter_sp = std::make_shared<SearchFilterByModuleListAndCU>(
5550b57cec5SDimitry Andric shared_from_this(), FileSpecList(), *containingSourceFiles);
5560b57cec5SDimitry Andric } else {
5570b57cec5SDimitry Andric filter_sp = std::make_shared<SearchFilterByModuleListAndCU>(
5580b57cec5SDimitry Andric shared_from_this(), *containingModules, *containingSourceFiles);
5590b57cec5SDimitry Andric }
5600b57cec5SDimitry Andric return filter_sp;
5610b57cec5SDimitry Andric }
5620b57cec5SDimitry Andric
CreateFuncRegexBreakpoint(const FileSpecList * containingModules,const FileSpecList * containingSourceFiles,RegularExpression func_regex,lldb::LanguageType requested_language,LazyBool skip_prologue,bool internal,bool hardware)5630b57cec5SDimitry Andric BreakpointSP Target::CreateFuncRegexBreakpoint(
5640b57cec5SDimitry Andric const FileSpecList *containingModules,
5659dba64beSDimitry Andric const FileSpecList *containingSourceFiles, RegularExpression func_regex,
5660b57cec5SDimitry Andric lldb::LanguageType requested_language, LazyBool skip_prologue,
5670b57cec5SDimitry Andric bool internal, bool hardware) {
5680b57cec5SDimitry Andric SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList(
5690b57cec5SDimitry Andric containingModules, containingSourceFiles));
5700b57cec5SDimitry Andric bool skip = (skip_prologue == eLazyBoolCalculate)
5710b57cec5SDimitry Andric ? GetSkipPrologue()
5720b57cec5SDimitry Andric : static_cast<bool>(skip_prologue);
5730b57cec5SDimitry Andric BreakpointResolverSP resolver_sp(new BreakpointResolverName(
5749dba64beSDimitry Andric nullptr, std::move(func_regex), requested_language, 0, skip));
5750b57cec5SDimitry Andric
5760b57cec5SDimitry Andric return CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true);
5770b57cec5SDimitry Andric }
5780b57cec5SDimitry Andric
5790b57cec5SDimitry Andric lldb::BreakpointSP
CreateExceptionBreakpoint(enum lldb::LanguageType language,bool catch_bp,bool throw_bp,bool internal,Args * additional_args,Status * error)5800b57cec5SDimitry Andric Target::CreateExceptionBreakpoint(enum lldb::LanguageType language,
5810b57cec5SDimitry Andric bool catch_bp, bool throw_bp, bool internal,
5820b57cec5SDimitry Andric Args *additional_args, Status *error) {
5830b57cec5SDimitry Andric BreakpointSP exc_bkpt_sp = LanguageRuntime::CreateExceptionBreakpoint(
5840b57cec5SDimitry Andric *this, language, catch_bp, throw_bp, internal);
5850b57cec5SDimitry Andric if (exc_bkpt_sp && additional_args) {
5860b57cec5SDimitry Andric BreakpointPreconditionSP precondition_sp = exc_bkpt_sp->GetPrecondition();
5870b57cec5SDimitry Andric if (precondition_sp && additional_args) {
5880b57cec5SDimitry Andric if (error)
5890b57cec5SDimitry Andric *error = precondition_sp->ConfigurePrecondition(*additional_args);
5900b57cec5SDimitry Andric else
5910b57cec5SDimitry Andric precondition_sp->ConfigurePrecondition(*additional_args);
5920b57cec5SDimitry Andric }
5930b57cec5SDimitry Andric }
5940b57cec5SDimitry Andric return exc_bkpt_sp;
5950b57cec5SDimitry Andric }
5960b57cec5SDimitry Andric
CreateScriptedBreakpoint(const llvm::StringRef class_name,const FileSpecList * containingModules,const FileSpecList * containingSourceFiles,bool internal,bool request_hardware,StructuredData::ObjectSP extra_args_sp,Status * creation_error)5979dba64beSDimitry Andric lldb::BreakpointSP Target::CreateScriptedBreakpoint(
5989dba64beSDimitry Andric const llvm::StringRef class_name, const FileSpecList *containingModules,
5999dba64beSDimitry Andric const FileSpecList *containingSourceFiles, bool internal,
6009dba64beSDimitry Andric bool request_hardware, StructuredData::ObjectSP extra_args_sp,
6019dba64beSDimitry Andric Status *creation_error) {
6020b57cec5SDimitry Andric SearchFilterSP filter_sp;
6030b57cec5SDimitry Andric
6040b57cec5SDimitry Andric lldb::SearchDepth depth = lldb::eSearchDepthTarget;
6059dba64beSDimitry Andric bool has_files =
6069dba64beSDimitry Andric containingSourceFiles && containingSourceFiles->GetSize() > 0;
6070b57cec5SDimitry Andric bool has_modules = containingModules && containingModules->GetSize() > 0;
6080b57cec5SDimitry Andric
6090b57cec5SDimitry Andric if (has_files && has_modules) {
6109dba64beSDimitry Andric filter_sp = GetSearchFilterForModuleAndCUList(containingModules,
6119dba64beSDimitry Andric containingSourceFiles);
6120b57cec5SDimitry Andric } else if (has_files) {
6139dba64beSDimitry Andric filter_sp =
6149dba64beSDimitry Andric GetSearchFilterForModuleAndCUList(nullptr, containingSourceFiles);
6150b57cec5SDimitry Andric } else if (has_modules) {
6160b57cec5SDimitry Andric filter_sp = GetSearchFilterForModuleList(containingModules);
6170b57cec5SDimitry Andric } else {
6180b57cec5SDimitry Andric filter_sp = std::make_shared<SearchFilterForUnconstrainedSearches>(
6190b57cec5SDimitry Andric shared_from_this());
6200b57cec5SDimitry Andric }
6210b57cec5SDimitry Andric
6220b57cec5SDimitry Andric StructuredDataImpl *extra_args_impl = new StructuredDataImpl();
6230b57cec5SDimitry Andric if (extra_args_sp)
6240b57cec5SDimitry Andric extra_args_impl->SetObjectSP(extra_args_sp);
6250b57cec5SDimitry Andric
6260b57cec5SDimitry Andric BreakpointResolverSP resolver_sp(new BreakpointResolverScripted(
6279dba64beSDimitry Andric nullptr, class_name, depth, extra_args_impl));
6280b57cec5SDimitry Andric return CreateBreakpoint(filter_sp, resolver_sp, internal, false, true);
6290b57cec5SDimitry Andric }
6300b57cec5SDimitry Andric
CreateBreakpoint(SearchFilterSP & filter_sp,BreakpointResolverSP & resolver_sp,bool internal,bool request_hardware,bool resolve_indirect_symbols)6310b57cec5SDimitry Andric BreakpointSP Target::CreateBreakpoint(SearchFilterSP &filter_sp,
6320b57cec5SDimitry Andric BreakpointResolverSP &resolver_sp,
6330b57cec5SDimitry Andric bool internal, bool request_hardware,
6340b57cec5SDimitry Andric bool resolve_indirect_symbols) {
6350b57cec5SDimitry Andric BreakpointSP bp_sp;
6360b57cec5SDimitry Andric if (filter_sp && resolver_sp) {
6370b57cec5SDimitry Andric const bool hardware = request_hardware || GetRequireHardwareBreakpoints();
6380b57cec5SDimitry Andric bp_sp.reset(new Breakpoint(*this, filter_sp, resolver_sp, hardware,
6390b57cec5SDimitry Andric resolve_indirect_symbols));
6405ffd83dbSDimitry Andric resolver_sp->SetBreakpoint(bp_sp);
6410b57cec5SDimitry Andric AddBreakpoint(bp_sp, internal);
6420b57cec5SDimitry Andric }
6430b57cec5SDimitry Andric return bp_sp;
6440b57cec5SDimitry Andric }
6450b57cec5SDimitry Andric
AddBreakpoint(lldb::BreakpointSP bp_sp,bool internal)6460b57cec5SDimitry Andric void Target::AddBreakpoint(lldb::BreakpointSP bp_sp, bool internal) {
6470b57cec5SDimitry Andric if (!bp_sp)
6480b57cec5SDimitry Andric return;
6490b57cec5SDimitry Andric if (internal)
6500b57cec5SDimitry Andric m_internal_breakpoint_list.Add(bp_sp, false);
6510b57cec5SDimitry Andric else
6520b57cec5SDimitry Andric m_breakpoint_list.Add(bp_sp, true);
6530b57cec5SDimitry Andric
6540b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
6550b57cec5SDimitry Andric if (log) {
6560b57cec5SDimitry Andric StreamString s;
6570b57cec5SDimitry Andric bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose);
6589dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (internal = %s) => break_id = %s\n",
6599dba64beSDimitry Andric __FUNCTION__, bp_sp->IsInternal() ? "yes" : "no", s.GetData());
6600b57cec5SDimitry Andric }
6610b57cec5SDimitry Andric
6620b57cec5SDimitry Andric bp_sp->ResolveBreakpoint();
6630b57cec5SDimitry Andric
6640b57cec5SDimitry Andric if (!internal) {
6650b57cec5SDimitry Andric m_last_created_breakpoint = bp_sp;
6660b57cec5SDimitry Andric }
6670b57cec5SDimitry Andric }
6680b57cec5SDimitry Andric
AddNameToBreakpoint(BreakpointID & id,const char * name,Status & error)6699dba64beSDimitry Andric void Target::AddNameToBreakpoint(BreakpointID &id, const char *name,
6709dba64beSDimitry Andric Status &error) {
6719dba64beSDimitry Andric BreakpointSP bp_sp =
6729dba64beSDimitry Andric m_breakpoint_list.FindBreakpointByID(id.GetBreakpointID());
6739dba64beSDimitry Andric if (!bp_sp) {
6740b57cec5SDimitry Andric StreamString s;
6750b57cec5SDimitry Andric id.GetDescription(&s, eDescriptionLevelBrief);
6769dba64beSDimitry Andric error.SetErrorStringWithFormat("Could not find breakpoint %s", s.GetData());
6770b57cec5SDimitry Andric return;
6780b57cec5SDimitry Andric }
6790b57cec5SDimitry Andric AddNameToBreakpoint(bp_sp, name, error);
6800b57cec5SDimitry Andric }
6810b57cec5SDimitry Andric
AddNameToBreakpoint(BreakpointSP & bp_sp,const char * name,Status & error)6829dba64beSDimitry Andric void Target::AddNameToBreakpoint(BreakpointSP &bp_sp, const char *name,
6839dba64beSDimitry Andric Status &error) {
6840b57cec5SDimitry Andric if (!bp_sp)
6850b57cec5SDimitry Andric return;
6860b57cec5SDimitry Andric
6870b57cec5SDimitry Andric BreakpointName *bp_name = FindBreakpointName(ConstString(name), true, error);
6880b57cec5SDimitry Andric if (!bp_name)
6890b57cec5SDimitry Andric return;
6900b57cec5SDimitry Andric
6910b57cec5SDimitry Andric bp_name->ConfigureBreakpoint(bp_sp);
6920b57cec5SDimitry Andric bp_sp->AddName(name);
6930b57cec5SDimitry Andric }
6940b57cec5SDimitry Andric
AddBreakpointName(BreakpointName * bp_name)6950b57cec5SDimitry Andric void Target::AddBreakpointName(BreakpointName *bp_name) {
6960b57cec5SDimitry Andric m_breakpoint_names.insert(std::make_pair(bp_name->GetName(), bp_name));
6970b57cec5SDimitry Andric }
6980b57cec5SDimitry Andric
FindBreakpointName(ConstString name,bool can_create,Status & error)6999dba64beSDimitry Andric BreakpointName *Target::FindBreakpointName(ConstString name, bool can_create,
7009dba64beSDimitry Andric Status &error) {
7010b57cec5SDimitry Andric BreakpointID::StringIsBreakpointName(name.GetStringRef(), error);
7020b57cec5SDimitry Andric if (!error.Success())
7030b57cec5SDimitry Andric return nullptr;
7040b57cec5SDimitry Andric
7050b57cec5SDimitry Andric BreakpointNameList::iterator iter = m_breakpoint_names.find(name);
7060b57cec5SDimitry Andric if (iter == m_breakpoint_names.end()) {
7079dba64beSDimitry Andric if (!can_create) {
7080b57cec5SDimitry Andric error.SetErrorStringWithFormat("Breakpoint name \"%s\" doesn't exist and "
7099dba64beSDimitry Andric "can_create is false.",
7109dba64beSDimitry Andric name.AsCString());
7110b57cec5SDimitry Andric return nullptr;
7120b57cec5SDimitry Andric }
7130b57cec5SDimitry Andric
7149dba64beSDimitry Andric iter = m_breakpoint_names
7159dba64beSDimitry Andric .insert(std::make_pair(name, new BreakpointName(name)))
7160b57cec5SDimitry Andric .first;
7170b57cec5SDimitry Andric }
7180b57cec5SDimitry Andric return (iter->second);
7190b57cec5SDimitry Andric }
7200b57cec5SDimitry Andric
DeleteBreakpointName(ConstString name)7219dba64beSDimitry Andric void Target::DeleteBreakpointName(ConstString name) {
7220b57cec5SDimitry Andric BreakpointNameList::iterator iter = m_breakpoint_names.find(name);
7230b57cec5SDimitry Andric
7240b57cec5SDimitry Andric if (iter != m_breakpoint_names.end()) {
7250b57cec5SDimitry Andric const char *name_cstr = name.AsCString();
7260b57cec5SDimitry Andric m_breakpoint_names.erase(iter);
7270b57cec5SDimitry Andric for (auto bp_sp : m_breakpoint_list.Breakpoints())
7280b57cec5SDimitry Andric bp_sp->RemoveName(name_cstr);
7290b57cec5SDimitry Andric }
7300b57cec5SDimitry Andric }
7310b57cec5SDimitry Andric
RemoveNameFromBreakpoint(lldb::BreakpointSP & bp_sp,ConstString name)7320b57cec5SDimitry Andric void Target::RemoveNameFromBreakpoint(lldb::BreakpointSP &bp_sp,
7339dba64beSDimitry Andric ConstString name) {
7340b57cec5SDimitry Andric bp_sp->RemoveName(name.AsCString());
7350b57cec5SDimitry Andric }
7360b57cec5SDimitry Andric
ConfigureBreakpointName(BreakpointName & bp_name,const BreakpointOptions & new_options,const BreakpointName::Permissions & new_permissions)7379dba64beSDimitry Andric void Target::ConfigureBreakpointName(
7389dba64beSDimitry Andric BreakpointName &bp_name, const BreakpointOptions &new_options,
7399dba64beSDimitry Andric const BreakpointName::Permissions &new_permissions) {
7400b57cec5SDimitry Andric bp_name.GetOptions().CopyOverSetOptions(new_options);
7410b57cec5SDimitry Andric bp_name.GetPermissions().MergeInto(new_permissions);
7420b57cec5SDimitry Andric ApplyNameToBreakpoints(bp_name);
7430b57cec5SDimitry Andric }
7440b57cec5SDimitry Andric
ApplyNameToBreakpoints(BreakpointName & bp_name)7450b57cec5SDimitry Andric void Target::ApplyNameToBreakpoints(BreakpointName &bp_name) {
746480093f4SDimitry Andric llvm::Expected<std::vector<BreakpointSP>> expected_vector =
747480093f4SDimitry Andric m_breakpoint_list.FindBreakpointsByName(bp_name.GetName().AsCString());
7480b57cec5SDimitry Andric
749480093f4SDimitry Andric if (!expected_vector) {
750480093f4SDimitry Andric LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS),
751480093f4SDimitry Andric "invalid breakpoint name: {}",
752480093f4SDimitry Andric llvm::toString(expected_vector.takeError()));
753480093f4SDimitry Andric return;
754480093f4SDimitry Andric }
755480093f4SDimitry Andric
756480093f4SDimitry Andric for (auto bp_sp : *expected_vector)
7570b57cec5SDimitry Andric bp_name.ConfigureBreakpoint(bp_sp);
7580b57cec5SDimitry Andric }
7590b57cec5SDimitry Andric
GetBreakpointNames(std::vector<std::string> & names)7609dba64beSDimitry Andric void Target::GetBreakpointNames(std::vector<std::string> &names) {
7610b57cec5SDimitry Andric names.clear();
7620b57cec5SDimitry Andric for (auto bp_name : m_breakpoint_names) {
7630b57cec5SDimitry Andric names.push_back(bp_name.first.AsCString());
7640b57cec5SDimitry Andric }
7650b57cec5SDimitry Andric llvm::sort(names.begin(), names.end());
7660b57cec5SDimitry Andric }
7670b57cec5SDimitry Andric
ProcessIsValid()7680b57cec5SDimitry Andric bool Target::ProcessIsValid() {
7690b57cec5SDimitry Andric return (m_process_sp && m_process_sp->IsAlive());
7700b57cec5SDimitry Andric }
7710b57cec5SDimitry Andric
CheckIfWatchpointsSupported(Target * target,Status & error)7720b57cec5SDimitry Andric static bool CheckIfWatchpointsSupported(Target *target, Status &error) {
7730b57cec5SDimitry Andric uint32_t num_supported_hardware_watchpoints;
7740b57cec5SDimitry Andric Status rc = target->GetProcessSP()->GetWatchpointSupportInfo(
7750b57cec5SDimitry Andric num_supported_hardware_watchpoints);
7760b57cec5SDimitry Andric
7770b57cec5SDimitry Andric // If unable to determine the # of watchpoints available,
7780b57cec5SDimitry Andric // assume they are supported.
7790b57cec5SDimitry Andric if (rc.Fail())
7800b57cec5SDimitry Andric return true;
7810b57cec5SDimitry Andric
7820b57cec5SDimitry Andric if (num_supported_hardware_watchpoints == 0) {
7830b57cec5SDimitry Andric error.SetErrorStringWithFormat(
7840b57cec5SDimitry Andric "Target supports (%u) hardware watchpoint slots.\n",
7850b57cec5SDimitry Andric num_supported_hardware_watchpoints);
7860b57cec5SDimitry Andric return false;
7870b57cec5SDimitry Andric }
7880b57cec5SDimitry Andric return true;
7890b57cec5SDimitry Andric }
7900b57cec5SDimitry Andric
7910b57cec5SDimitry Andric // See also Watchpoint::SetWatchpointType(uint32_t type) and the
7920b57cec5SDimitry Andric // OptionGroupWatchpoint::WatchType enum type.
CreateWatchpoint(lldb::addr_t addr,size_t size,const CompilerType * type,uint32_t kind,Status & error)7930b57cec5SDimitry Andric WatchpointSP Target::CreateWatchpoint(lldb::addr_t addr, size_t size,
7940b57cec5SDimitry Andric const CompilerType *type, uint32_t kind,
7950b57cec5SDimitry Andric Status &error) {
7960b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
7979dba64beSDimitry Andric LLDB_LOGF(log,
7989dba64beSDimitry Andric "Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64
7990b57cec5SDimitry Andric " type = %u)\n",
8000b57cec5SDimitry Andric __FUNCTION__, addr, (uint64_t)size, kind);
8010b57cec5SDimitry Andric
8020b57cec5SDimitry Andric WatchpointSP wp_sp;
8030b57cec5SDimitry Andric if (!ProcessIsValid()) {
8040b57cec5SDimitry Andric error.SetErrorString("process is not alive");
8050b57cec5SDimitry Andric return wp_sp;
8060b57cec5SDimitry Andric }
8070b57cec5SDimitry Andric
8080b57cec5SDimitry Andric if (addr == LLDB_INVALID_ADDRESS || size == 0) {
8090b57cec5SDimitry Andric if (size == 0)
8100b57cec5SDimitry Andric error.SetErrorString("cannot set a watchpoint with watch_size of 0");
8110b57cec5SDimitry Andric else
8120b57cec5SDimitry Andric error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr);
8130b57cec5SDimitry Andric return wp_sp;
8140b57cec5SDimitry Andric }
8150b57cec5SDimitry Andric
8160b57cec5SDimitry Andric if (!LLDB_WATCH_TYPE_IS_VALID(kind)) {
8170b57cec5SDimitry Andric error.SetErrorStringWithFormat("invalid watchpoint type: %d", kind);
8180b57cec5SDimitry Andric }
8190b57cec5SDimitry Andric
8200b57cec5SDimitry Andric if (!CheckIfWatchpointsSupported(this, error))
8210b57cec5SDimitry Andric return wp_sp;
8220b57cec5SDimitry Andric
8230b57cec5SDimitry Andric // Currently we only support one watchpoint per address, with total number of
8240b57cec5SDimitry Andric // watchpoints limited by the hardware which the inferior is running on.
8250b57cec5SDimitry Andric
8260b57cec5SDimitry Andric // Grab the list mutex while doing operations.
8270b57cec5SDimitry Andric const bool notify = false; // Don't notify about all the state changes we do
8280b57cec5SDimitry Andric // on creating the watchpoint.
829*5f7ddb14SDimitry Andric
830*5f7ddb14SDimitry Andric // Mask off ignored bits from watchpoint address.
831*5f7ddb14SDimitry Andric if (ABISP abi = m_process_sp->GetABI())
832*5f7ddb14SDimitry Andric addr = abi->FixDataAddress(addr);
833*5f7ddb14SDimitry Andric
8340b57cec5SDimitry Andric std::unique_lock<std::recursive_mutex> lock;
8350b57cec5SDimitry Andric this->GetWatchpointList().GetListMutex(lock);
8360b57cec5SDimitry Andric WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr);
8370b57cec5SDimitry Andric if (matched_sp) {
8380b57cec5SDimitry Andric size_t old_size = matched_sp->GetByteSize();
8390b57cec5SDimitry Andric uint32_t old_type =
8400b57cec5SDimitry Andric (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) |
8410b57cec5SDimitry Andric (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0);
8420b57cec5SDimitry Andric // Return the existing watchpoint if both size and type match.
8430b57cec5SDimitry Andric if (size == old_size && kind == old_type) {
8440b57cec5SDimitry Andric wp_sp = matched_sp;
8450b57cec5SDimitry Andric wp_sp->SetEnabled(false, notify);
8460b57cec5SDimitry Andric } else {
8470b57cec5SDimitry Andric // Nil the matched watchpoint; we will be creating a new one.
8480b57cec5SDimitry Andric m_process_sp->DisableWatchpoint(matched_sp.get(), notify);
8490b57cec5SDimitry Andric m_watchpoint_list.Remove(matched_sp->GetID(), true);
8500b57cec5SDimitry Andric }
8510b57cec5SDimitry Andric }
8520b57cec5SDimitry Andric
8530b57cec5SDimitry Andric if (!wp_sp) {
8540b57cec5SDimitry Andric wp_sp = std::make_shared<Watchpoint>(*this, addr, size, type);
8550b57cec5SDimitry Andric wp_sp->SetWatchpointType(kind, notify);
8560b57cec5SDimitry Andric m_watchpoint_list.Add(wp_sp, true);
8570b57cec5SDimitry Andric }
8580b57cec5SDimitry Andric
8590b57cec5SDimitry Andric error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify);
8609dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (creation of watchpoint %s with id = %u)\n",
8610b57cec5SDimitry Andric __FUNCTION__, error.Success() ? "succeeded" : "failed",
8620b57cec5SDimitry Andric wp_sp->GetID());
8630b57cec5SDimitry Andric
8640b57cec5SDimitry Andric if (error.Fail()) {
8650b57cec5SDimitry Andric // Enabling the watchpoint on the device side failed. Remove the said
8660b57cec5SDimitry Andric // watchpoint from the list maintained by the target instance.
8670b57cec5SDimitry Andric m_watchpoint_list.Remove(wp_sp->GetID(), true);
8680b57cec5SDimitry Andric // See if we could provide more helpful error message.
8690b57cec5SDimitry Andric if (!OptionGroupWatchpoint::IsWatchSizeSupported(size))
8700b57cec5SDimitry Andric error.SetErrorStringWithFormat(
8710b57cec5SDimitry Andric "watch size of %" PRIu64 " is not supported", (uint64_t)size);
8720b57cec5SDimitry Andric
8730b57cec5SDimitry Andric wp_sp.reset();
8740b57cec5SDimitry Andric } else
8750b57cec5SDimitry Andric m_last_created_watchpoint = wp_sp;
8760b57cec5SDimitry Andric return wp_sp;
8770b57cec5SDimitry Andric }
8780b57cec5SDimitry Andric
RemoveAllowedBreakpoints()8799dba64beSDimitry Andric void Target::RemoveAllowedBreakpoints() {
8800b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
8819dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s \n", __FUNCTION__);
8820b57cec5SDimitry Andric
8830b57cec5SDimitry Andric m_breakpoint_list.RemoveAllowed(true);
8840b57cec5SDimitry Andric
8850b57cec5SDimitry Andric m_last_created_breakpoint.reset();
8860b57cec5SDimitry Andric }
8870b57cec5SDimitry Andric
RemoveAllBreakpoints(bool internal_also)8880b57cec5SDimitry Andric void Target::RemoveAllBreakpoints(bool internal_also) {
8890b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
8909dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (internal_also = %s)\n", __FUNCTION__,
8910b57cec5SDimitry Andric internal_also ? "yes" : "no");
8920b57cec5SDimitry Andric
8930b57cec5SDimitry Andric m_breakpoint_list.RemoveAll(true);
8940b57cec5SDimitry Andric if (internal_also)
8950b57cec5SDimitry Andric m_internal_breakpoint_list.RemoveAll(false);
8960b57cec5SDimitry Andric
8970b57cec5SDimitry Andric m_last_created_breakpoint.reset();
8980b57cec5SDimitry Andric }
8990b57cec5SDimitry Andric
DisableAllBreakpoints(bool internal_also)9000b57cec5SDimitry Andric void Target::DisableAllBreakpoints(bool internal_also) {
9010b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
9029dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (internal_also = %s)\n", __FUNCTION__,
9030b57cec5SDimitry Andric internal_also ? "yes" : "no");
9040b57cec5SDimitry Andric
9050b57cec5SDimitry Andric m_breakpoint_list.SetEnabledAll(false);
9060b57cec5SDimitry Andric if (internal_also)
9070b57cec5SDimitry Andric m_internal_breakpoint_list.SetEnabledAll(false);
9080b57cec5SDimitry Andric }
9090b57cec5SDimitry Andric
DisableAllowedBreakpoints()9100b57cec5SDimitry Andric void Target::DisableAllowedBreakpoints() {
9110b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
9129dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s", __FUNCTION__);
9130b57cec5SDimitry Andric
9140b57cec5SDimitry Andric m_breakpoint_list.SetEnabledAllowed(false);
9150b57cec5SDimitry Andric }
9160b57cec5SDimitry Andric
EnableAllBreakpoints(bool internal_also)9170b57cec5SDimitry Andric void Target::EnableAllBreakpoints(bool internal_also) {
9180b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
9199dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (internal_also = %s)\n", __FUNCTION__,
9200b57cec5SDimitry Andric internal_also ? "yes" : "no");
9210b57cec5SDimitry Andric
9220b57cec5SDimitry Andric m_breakpoint_list.SetEnabledAll(true);
9230b57cec5SDimitry Andric if (internal_also)
9240b57cec5SDimitry Andric m_internal_breakpoint_list.SetEnabledAll(true);
9250b57cec5SDimitry Andric }
9260b57cec5SDimitry Andric
EnableAllowedBreakpoints()9270b57cec5SDimitry Andric void Target::EnableAllowedBreakpoints() {
9280b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
9299dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s", __FUNCTION__);
9300b57cec5SDimitry Andric
9310b57cec5SDimitry Andric m_breakpoint_list.SetEnabledAllowed(true);
9320b57cec5SDimitry Andric }
9330b57cec5SDimitry Andric
RemoveBreakpointByID(break_id_t break_id)9340b57cec5SDimitry Andric bool Target::RemoveBreakpointByID(break_id_t break_id) {
9350b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
9369dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__,
9370b57cec5SDimitry Andric break_id, LLDB_BREAK_ID_IS_INTERNAL(break_id) ? "yes" : "no");
9380b57cec5SDimitry Andric
9390b57cec5SDimitry Andric if (DisableBreakpointByID(break_id)) {
9400b57cec5SDimitry Andric if (LLDB_BREAK_ID_IS_INTERNAL(break_id))
9410b57cec5SDimitry Andric m_internal_breakpoint_list.Remove(break_id, false);
9420b57cec5SDimitry Andric else {
9430b57cec5SDimitry Andric if (m_last_created_breakpoint) {
9440b57cec5SDimitry Andric if (m_last_created_breakpoint->GetID() == break_id)
9450b57cec5SDimitry Andric m_last_created_breakpoint.reset();
9460b57cec5SDimitry Andric }
9470b57cec5SDimitry Andric m_breakpoint_list.Remove(break_id, true);
9480b57cec5SDimitry Andric }
9490b57cec5SDimitry Andric return true;
9500b57cec5SDimitry Andric }
9510b57cec5SDimitry Andric return false;
9520b57cec5SDimitry Andric }
9530b57cec5SDimitry Andric
DisableBreakpointByID(break_id_t break_id)9540b57cec5SDimitry Andric bool Target::DisableBreakpointByID(break_id_t break_id) {
9550b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
9569dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__,
9570b57cec5SDimitry Andric break_id, LLDB_BREAK_ID_IS_INTERNAL(break_id) ? "yes" : "no");
9580b57cec5SDimitry Andric
9590b57cec5SDimitry Andric BreakpointSP bp_sp;
9600b57cec5SDimitry Andric
9610b57cec5SDimitry Andric if (LLDB_BREAK_ID_IS_INTERNAL(break_id))
9620b57cec5SDimitry Andric bp_sp = m_internal_breakpoint_list.FindBreakpointByID(break_id);
9630b57cec5SDimitry Andric else
9640b57cec5SDimitry Andric bp_sp = m_breakpoint_list.FindBreakpointByID(break_id);
9650b57cec5SDimitry Andric if (bp_sp) {
9660b57cec5SDimitry Andric bp_sp->SetEnabled(false);
9670b57cec5SDimitry Andric return true;
9680b57cec5SDimitry Andric }
9690b57cec5SDimitry Andric return false;
9700b57cec5SDimitry Andric }
9710b57cec5SDimitry Andric
EnableBreakpointByID(break_id_t break_id)9720b57cec5SDimitry Andric bool Target::EnableBreakpointByID(break_id_t break_id) {
9730b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS));
9749dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__,
9750b57cec5SDimitry Andric break_id, LLDB_BREAK_ID_IS_INTERNAL(break_id) ? "yes" : "no");
9760b57cec5SDimitry Andric
9770b57cec5SDimitry Andric BreakpointSP bp_sp;
9780b57cec5SDimitry Andric
9790b57cec5SDimitry Andric if (LLDB_BREAK_ID_IS_INTERNAL(break_id))
9800b57cec5SDimitry Andric bp_sp = m_internal_breakpoint_list.FindBreakpointByID(break_id);
9810b57cec5SDimitry Andric else
9820b57cec5SDimitry Andric bp_sp = m_breakpoint_list.FindBreakpointByID(break_id);
9830b57cec5SDimitry Andric
9840b57cec5SDimitry Andric if (bp_sp) {
9850b57cec5SDimitry Andric bp_sp->SetEnabled(true);
9860b57cec5SDimitry Andric return true;
9870b57cec5SDimitry Andric }
9880b57cec5SDimitry Andric return false;
9890b57cec5SDimitry Andric }
9900b57cec5SDimitry Andric
SerializeBreakpointsToFile(const FileSpec & file,const BreakpointIDList & bp_ids,bool append)9910b57cec5SDimitry Andric Status Target::SerializeBreakpointsToFile(const FileSpec &file,
9920b57cec5SDimitry Andric const BreakpointIDList &bp_ids,
9930b57cec5SDimitry Andric bool append) {
9940b57cec5SDimitry Andric Status error;
9950b57cec5SDimitry Andric
9960b57cec5SDimitry Andric if (!file) {
9970b57cec5SDimitry Andric error.SetErrorString("Invalid FileSpec.");
9980b57cec5SDimitry Andric return error;
9990b57cec5SDimitry Andric }
10000b57cec5SDimitry Andric
10010b57cec5SDimitry Andric std::string path(file.GetPath());
10020b57cec5SDimitry Andric StructuredData::ObjectSP input_data_sp;
10030b57cec5SDimitry Andric
10040b57cec5SDimitry Andric StructuredData::ArraySP break_store_sp;
10050b57cec5SDimitry Andric StructuredData::Array *break_store_ptr = nullptr;
10060b57cec5SDimitry Andric
10070b57cec5SDimitry Andric if (append) {
10080b57cec5SDimitry Andric input_data_sp = StructuredData::ParseJSONFromFile(file, error);
10090b57cec5SDimitry Andric if (error.Success()) {
10100b57cec5SDimitry Andric break_store_ptr = input_data_sp->GetAsArray();
10110b57cec5SDimitry Andric if (!break_store_ptr) {
10120b57cec5SDimitry Andric error.SetErrorStringWithFormat(
10130b57cec5SDimitry Andric "Tried to append to invalid input file %s", path.c_str());
10140b57cec5SDimitry Andric return error;
10150b57cec5SDimitry Andric }
10160b57cec5SDimitry Andric }
10170b57cec5SDimitry Andric }
10180b57cec5SDimitry Andric
10190b57cec5SDimitry Andric if (!break_store_ptr) {
10200b57cec5SDimitry Andric break_store_sp = std::make_shared<StructuredData::Array>();
10210b57cec5SDimitry Andric break_store_ptr = break_store_sp.get();
10220b57cec5SDimitry Andric }
10230b57cec5SDimitry Andric
10240b57cec5SDimitry Andric StreamFile out_file(path.c_str(),
10259dba64beSDimitry Andric File::eOpenOptionTruncate | File::eOpenOptionWrite |
10269dba64beSDimitry Andric File::eOpenOptionCanCreate |
10279dba64beSDimitry Andric File::eOpenOptionCloseOnExec,
10280b57cec5SDimitry Andric lldb::eFilePermissionsFileDefault);
10290b57cec5SDimitry Andric if (!out_file.GetFile().IsValid()) {
10300b57cec5SDimitry Andric error.SetErrorStringWithFormat("Unable to open output file: %s.",
10310b57cec5SDimitry Andric path.c_str());
10320b57cec5SDimitry Andric return error;
10330b57cec5SDimitry Andric }
10340b57cec5SDimitry Andric
10350b57cec5SDimitry Andric std::unique_lock<std::recursive_mutex> lock;
10360b57cec5SDimitry Andric GetBreakpointList().GetListMutex(lock);
10370b57cec5SDimitry Andric
10380b57cec5SDimitry Andric if (bp_ids.GetSize() == 0) {
10390b57cec5SDimitry Andric const BreakpointList &breakpoints = GetBreakpointList();
10400b57cec5SDimitry Andric
10410b57cec5SDimitry Andric size_t num_breakpoints = breakpoints.GetSize();
10420b57cec5SDimitry Andric for (size_t i = 0; i < num_breakpoints; i++) {
10430b57cec5SDimitry Andric Breakpoint *bp = breakpoints.GetBreakpointAtIndex(i).get();
10440b57cec5SDimitry Andric StructuredData::ObjectSP bkpt_save_sp = bp->SerializeToStructuredData();
10450b57cec5SDimitry Andric // If a breakpoint can't serialize it, just ignore it for now:
10460b57cec5SDimitry Andric if (bkpt_save_sp)
10470b57cec5SDimitry Andric break_store_ptr->AddItem(bkpt_save_sp);
10480b57cec5SDimitry Andric }
10490b57cec5SDimitry Andric } else {
10500b57cec5SDimitry Andric
10510b57cec5SDimitry Andric std::unordered_set<lldb::break_id_t> processed_bkpts;
10520b57cec5SDimitry Andric const size_t count = bp_ids.GetSize();
10530b57cec5SDimitry Andric for (size_t i = 0; i < count; ++i) {
10540b57cec5SDimitry Andric BreakpointID cur_bp_id = bp_ids.GetBreakpointIDAtIndex(i);
10550b57cec5SDimitry Andric lldb::break_id_t bp_id = cur_bp_id.GetBreakpointID();
10560b57cec5SDimitry Andric
10570b57cec5SDimitry Andric if (bp_id != LLDB_INVALID_BREAK_ID) {
10580b57cec5SDimitry Andric // Only do each breakpoint once:
10590b57cec5SDimitry Andric std::pair<std::unordered_set<lldb::break_id_t>::iterator, bool>
10600b57cec5SDimitry Andric insert_result = processed_bkpts.insert(bp_id);
10610b57cec5SDimitry Andric if (!insert_result.second)
10620b57cec5SDimitry Andric continue;
10630b57cec5SDimitry Andric
10640b57cec5SDimitry Andric Breakpoint *bp = GetBreakpointByID(bp_id).get();
10650b57cec5SDimitry Andric StructuredData::ObjectSP bkpt_save_sp = bp->SerializeToStructuredData();
10660b57cec5SDimitry Andric // If the user explicitly asked to serialize a breakpoint, and we
10670b57cec5SDimitry Andric // can't, then raise an error:
10680b57cec5SDimitry Andric if (!bkpt_save_sp) {
10690b57cec5SDimitry Andric error.SetErrorStringWithFormat("Unable to serialize breakpoint %d",
10700b57cec5SDimitry Andric bp_id);
10710b57cec5SDimitry Andric return error;
10720b57cec5SDimitry Andric }
10730b57cec5SDimitry Andric break_store_ptr->AddItem(bkpt_save_sp);
10740b57cec5SDimitry Andric }
10750b57cec5SDimitry Andric }
10760b57cec5SDimitry Andric }
10770b57cec5SDimitry Andric
10780b57cec5SDimitry Andric break_store_ptr->Dump(out_file, false);
10790b57cec5SDimitry Andric out_file.PutChar('\n');
10800b57cec5SDimitry Andric return error;
10810b57cec5SDimitry Andric }
10820b57cec5SDimitry Andric
CreateBreakpointsFromFile(const FileSpec & file,BreakpointIDList & new_bps)10830b57cec5SDimitry Andric Status Target::CreateBreakpointsFromFile(const FileSpec &file,
10840b57cec5SDimitry Andric BreakpointIDList &new_bps) {
10850b57cec5SDimitry Andric std::vector<std::string> no_names;
10860b57cec5SDimitry Andric return CreateBreakpointsFromFile(file, no_names, new_bps);
10870b57cec5SDimitry Andric }
10880b57cec5SDimitry Andric
CreateBreakpointsFromFile(const FileSpec & file,std::vector<std::string> & names,BreakpointIDList & new_bps)10890b57cec5SDimitry Andric Status Target::CreateBreakpointsFromFile(const FileSpec &file,
10900b57cec5SDimitry Andric std::vector<std::string> &names,
10910b57cec5SDimitry Andric BreakpointIDList &new_bps) {
10920b57cec5SDimitry Andric std::unique_lock<std::recursive_mutex> lock;
10930b57cec5SDimitry Andric GetBreakpointList().GetListMutex(lock);
10940b57cec5SDimitry Andric
10950b57cec5SDimitry Andric Status error;
10960b57cec5SDimitry Andric StructuredData::ObjectSP input_data_sp =
10970b57cec5SDimitry Andric StructuredData::ParseJSONFromFile(file, error);
10980b57cec5SDimitry Andric if (!error.Success()) {
10990b57cec5SDimitry Andric return error;
11000b57cec5SDimitry Andric } else if (!input_data_sp || !input_data_sp->IsValid()) {
11010b57cec5SDimitry Andric error.SetErrorStringWithFormat("Invalid JSON from input file: %s.",
11020b57cec5SDimitry Andric file.GetPath().c_str());
11030b57cec5SDimitry Andric return error;
11040b57cec5SDimitry Andric }
11050b57cec5SDimitry Andric
11060b57cec5SDimitry Andric StructuredData::Array *bkpt_array = input_data_sp->GetAsArray();
11070b57cec5SDimitry Andric if (!bkpt_array) {
11080b57cec5SDimitry Andric error.SetErrorStringWithFormat(
11090b57cec5SDimitry Andric "Invalid breakpoint data from input file: %s.", file.GetPath().c_str());
11100b57cec5SDimitry Andric return error;
11110b57cec5SDimitry Andric }
11120b57cec5SDimitry Andric
11130b57cec5SDimitry Andric size_t num_bkpts = bkpt_array->GetSize();
11140b57cec5SDimitry Andric size_t num_names = names.size();
11150b57cec5SDimitry Andric
11160b57cec5SDimitry Andric for (size_t i = 0; i < num_bkpts; i++) {
11170b57cec5SDimitry Andric StructuredData::ObjectSP bkpt_object_sp = bkpt_array->GetItemAtIndex(i);
11180b57cec5SDimitry Andric // Peel off the breakpoint key, and feed the rest to the Breakpoint:
11190b57cec5SDimitry Andric StructuredData::Dictionary *bkpt_dict = bkpt_object_sp->GetAsDictionary();
11200b57cec5SDimitry Andric if (!bkpt_dict) {
11210b57cec5SDimitry Andric error.SetErrorStringWithFormat(
11220b57cec5SDimitry Andric "Invalid breakpoint data for element %zu from input file: %s.", i,
11230b57cec5SDimitry Andric file.GetPath().c_str());
11240b57cec5SDimitry Andric return error;
11250b57cec5SDimitry Andric }
11260b57cec5SDimitry Andric StructuredData::ObjectSP bkpt_data_sp =
11270b57cec5SDimitry Andric bkpt_dict->GetValueForKey(Breakpoint::GetSerializationKey());
11280b57cec5SDimitry Andric if (num_names &&
11290b57cec5SDimitry Andric !Breakpoint::SerializedBreakpointMatchesNames(bkpt_data_sp, names))
11300b57cec5SDimitry Andric continue;
11310b57cec5SDimitry Andric
11325ffd83dbSDimitry Andric BreakpointSP bkpt_sp = Breakpoint::CreateFromStructuredData(
11335ffd83dbSDimitry Andric shared_from_this(), bkpt_data_sp, error);
11340b57cec5SDimitry Andric if (!error.Success()) {
11350b57cec5SDimitry Andric error.SetErrorStringWithFormat(
11360b57cec5SDimitry Andric "Error restoring breakpoint %zu from %s: %s.", i,
11370b57cec5SDimitry Andric file.GetPath().c_str(), error.AsCString());
11380b57cec5SDimitry Andric return error;
11390b57cec5SDimitry Andric }
11400b57cec5SDimitry Andric new_bps.AddBreakpointID(BreakpointID(bkpt_sp->GetID()));
11410b57cec5SDimitry Andric }
11420b57cec5SDimitry Andric return error;
11430b57cec5SDimitry Andric }
11440b57cec5SDimitry Andric
11450b57cec5SDimitry Andric // The flag 'end_to_end', default to true, signifies that the operation is
11460b57cec5SDimitry Andric // performed end to end, for both the debugger and the debuggee.
11470b57cec5SDimitry Andric
11480b57cec5SDimitry Andric // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
11490b57cec5SDimitry Andric // to end operations.
RemoveAllWatchpoints(bool end_to_end)11500b57cec5SDimitry Andric bool Target::RemoveAllWatchpoints(bool end_to_end) {
11510b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
11529dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s\n", __FUNCTION__);
11530b57cec5SDimitry Andric
11540b57cec5SDimitry Andric if (!end_to_end) {
11550b57cec5SDimitry Andric m_watchpoint_list.RemoveAll(true);
11560b57cec5SDimitry Andric return true;
11570b57cec5SDimitry Andric }
11580b57cec5SDimitry Andric
11590b57cec5SDimitry Andric // Otherwise, it's an end to end operation.
11600b57cec5SDimitry Andric
11610b57cec5SDimitry Andric if (!ProcessIsValid())
11620b57cec5SDimitry Andric return false;
11630b57cec5SDimitry Andric
1164*5f7ddb14SDimitry Andric for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) {
11650b57cec5SDimitry Andric if (!wp_sp)
11660b57cec5SDimitry Andric return false;
11670b57cec5SDimitry Andric
11680b57cec5SDimitry Andric Status rc = m_process_sp->DisableWatchpoint(wp_sp.get());
11690b57cec5SDimitry Andric if (rc.Fail())
11700b57cec5SDimitry Andric return false;
11710b57cec5SDimitry Andric }
11720b57cec5SDimitry Andric m_watchpoint_list.RemoveAll(true);
11730b57cec5SDimitry Andric m_last_created_watchpoint.reset();
11740b57cec5SDimitry Andric return true; // Success!
11750b57cec5SDimitry Andric }
11760b57cec5SDimitry Andric
11770b57cec5SDimitry Andric // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
11780b57cec5SDimitry Andric // to end operations.
DisableAllWatchpoints(bool end_to_end)11790b57cec5SDimitry Andric bool Target::DisableAllWatchpoints(bool end_to_end) {
11800b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
11819dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s\n", __FUNCTION__);
11820b57cec5SDimitry Andric
11830b57cec5SDimitry Andric if (!end_to_end) {
11840b57cec5SDimitry Andric m_watchpoint_list.SetEnabledAll(false);
11850b57cec5SDimitry Andric return true;
11860b57cec5SDimitry Andric }
11870b57cec5SDimitry Andric
11880b57cec5SDimitry Andric // Otherwise, it's an end to end operation.
11890b57cec5SDimitry Andric
11900b57cec5SDimitry Andric if (!ProcessIsValid())
11910b57cec5SDimitry Andric return false;
11920b57cec5SDimitry Andric
1193*5f7ddb14SDimitry Andric for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) {
11940b57cec5SDimitry Andric if (!wp_sp)
11950b57cec5SDimitry Andric return false;
11960b57cec5SDimitry Andric
11970b57cec5SDimitry Andric Status rc = m_process_sp->DisableWatchpoint(wp_sp.get());
11980b57cec5SDimitry Andric if (rc.Fail())
11990b57cec5SDimitry Andric return false;
12000b57cec5SDimitry Andric }
12010b57cec5SDimitry Andric return true; // Success!
12020b57cec5SDimitry Andric }
12030b57cec5SDimitry Andric
12040b57cec5SDimitry Andric // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end
12050b57cec5SDimitry Andric // to end operations.
EnableAllWatchpoints(bool end_to_end)12060b57cec5SDimitry Andric bool Target::EnableAllWatchpoints(bool end_to_end) {
12070b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
12089dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s\n", __FUNCTION__);
12090b57cec5SDimitry Andric
12100b57cec5SDimitry Andric if (!end_to_end) {
12110b57cec5SDimitry Andric m_watchpoint_list.SetEnabledAll(true);
12120b57cec5SDimitry Andric return true;
12130b57cec5SDimitry Andric }
12140b57cec5SDimitry Andric
12150b57cec5SDimitry Andric // Otherwise, it's an end to end operation.
12160b57cec5SDimitry Andric
12170b57cec5SDimitry Andric if (!ProcessIsValid())
12180b57cec5SDimitry Andric return false;
12190b57cec5SDimitry Andric
1220*5f7ddb14SDimitry Andric for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) {
12210b57cec5SDimitry Andric if (!wp_sp)
12220b57cec5SDimitry Andric return false;
12230b57cec5SDimitry Andric
12240b57cec5SDimitry Andric Status rc = m_process_sp->EnableWatchpoint(wp_sp.get());
12250b57cec5SDimitry Andric if (rc.Fail())
12260b57cec5SDimitry Andric return false;
12270b57cec5SDimitry Andric }
12280b57cec5SDimitry Andric return true; // Success!
12290b57cec5SDimitry Andric }
12300b57cec5SDimitry Andric
12310b57cec5SDimitry Andric // Assumption: Caller holds the list mutex lock for m_watchpoint_list.
ClearAllWatchpointHitCounts()12320b57cec5SDimitry Andric bool Target::ClearAllWatchpointHitCounts() {
12330b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
12349dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s\n", __FUNCTION__);
12350b57cec5SDimitry Andric
1236*5f7ddb14SDimitry Andric for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) {
12370b57cec5SDimitry Andric if (!wp_sp)
12380b57cec5SDimitry Andric return false;
12390b57cec5SDimitry Andric
12400b57cec5SDimitry Andric wp_sp->ResetHitCount();
12410b57cec5SDimitry Andric }
12420b57cec5SDimitry Andric return true; // Success!
12430b57cec5SDimitry Andric }
12440b57cec5SDimitry Andric
12450b57cec5SDimitry Andric // Assumption: Caller holds the list mutex lock for m_watchpoint_list.
ClearAllWatchpointHistoricValues()12460b57cec5SDimitry Andric bool Target::ClearAllWatchpointHistoricValues() {
12470b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
12489dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s\n", __FUNCTION__);
12490b57cec5SDimitry Andric
1250*5f7ddb14SDimitry Andric for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) {
12510b57cec5SDimitry Andric if (!wp_sp)
12520b57cec5SDimitry Andric return false;
12530b57cec5SDimitry Andric
12540b57cec5SDimitry Andric wp_sp->ResetHistoricValues();
12550b57cec5SDimitry Andric }
12560b57cec5SDimitry Andric return true; // Success!
12570b57cec5SDimitry Andric }
12580b57cec5SDimitry Andric
12590b57cec5SDimitry Andric // Assumption: Caller holds the list mutex lock for m_watchpoint_list during
12600b57cec5SDimitry Andric // these operations.
IgnoreAllWatchpoints(uint32_t ignore_count)12610b57cec5SDimitry Andric bool Target::IgnoreAllWatchpoints(uint32_t ignore_count) {
12620b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
12639dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s\n", __FUNCTION__);
12640b57cec5SDimitry Andric
12650b57cec5SDimitry Andric if (!ProcessIsValid())
12660b57cec5SDimitry Andric return false;
12670b57cec5SDimitry Andric
1268*5f7ddb14SDimitry Andric for (WatchpointSP wp_sp : m_watchpoint_list.Watchpoints()) {
12690b57cec5SDimitry Andric if (!wp_sp)
12700b57cec5SDimitry Andric return false;
12710b57cec5SDimitry Andric
12720b57cec5SDimitry Andric wp_sp->SetIgnoreCount(ignore_count);
12730b57cec5SDimitry Andric }
12740b57cec5SDimitry Andric return true; // Success!
12750b57cec5SDimitry Andric }
12760b57cec5SDimitry Andric
12770b57cec5SDimitry Andric // Assumption: Caller holds the list mutex lock for m_watchpoint_list.
DisableWatchpointByID(lldb::watch_id_t watch_id)12780b57cec5SDimitry Andric bool Target::DisableWatchpointByID(lldb::watch_id_t watch_id) {
12790b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
12809dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
12810b57cec5SDimitry Andric
12820b57cec5SDimitry Andric if (!ProcessIsValid())
12830b57cec5SDimitry Andric return false;
12840b57cec5SDimitry Andric
12850b57cec5SDimitry Andric WatchpointSP wp_sp = m_watchpoint_list.FindByID(watch_id);
12860b57cec5SDimitry Andric if (wp_sp) {
12870b57cec5SDimitry Andric Status rc = m_process_sp->DisableWatchpoint(wp_sp.get());
12880b57cec5SDimitry Andric if (rc.Success())
12890b57cec5SDimitry Andric return true;
12900b57cec5SDimitry Andric
12910b57cec5SDimitry Andric // Else, fallthrough.
12920b57cec5SDimitry Andric }
12930b57cec5SDimitry Andric return false;
12940b57cec5SDimitry Andric }
12950b57cec5SDimitry Andric
12960b57cec5SDimitry Andric // Assumption: Caller holds the list mutex lock for m_watchpoint_list.
EnableWatchpointByID(lldb::watch_id_t watch_id)12970b57cec5SDimitry Andric bool Target::EnableWatchpointByID(lldb::watch_id_t watch_id) {
12980b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
12999dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
13000b57cec5SDimitry Andric
13010b57cec5SDimitry Andric if (!ProcessIsValid())
13020b57cec5SDimitry Andric return false;
13030b57cec5SDimitry Andric
13040b57cec5SDimitry Andric WatchpointSP wp_sp = m_watchpoint_list.FindByID(watch_id);
13050b57cec5SDimitry Andric if (wp_sp) {
13060b57cec5SDimitry Andric Status rc = m_process_sp->EnableWatchpoint(wp_sp.get());
13070b57cec5SDimitry Andric if (rc.Success())
13080b57cec5SDimitry Andric return true;
13090b57cec5SDimitry Andric
13100b57cec5SDimitry Andric // Else, fallthrough.
13110b57cec5SDimitry Andric }
13120b57cec5SDimitry Andric return false;
13130b57cec5SDimitry Andric }
13140b57cec5SDimitry Andric
13150b57cec5SDimitry Andric // Assumption: Caller holds the list mutex lock for m_watchpoint_list.
RemoveWatchpointByID(lldb::watch_id_t watch_id)13160b57cec5SDimitry Andric bool Target::RemoveWatchpointByID(lldb::watch_id_t watch_id) {
13170b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
13189dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
13190b57cec5SDimitry Andric
13200b57cec5SDimitry Andric WatchpointSP watch_to_remove_sp = m_watchpoint_list.FindByID(watch_id);
13210b57cec5SDimitry Andric if (watch_to_remove_sp == m_last_created_watchpoint)
13220b57cec5SDimitry Andric m_last_created_watchpoint.reset();
13230b57cec5SDimitry Andric
13240b57cec5SDimitry Andric if (DisableWatchpointByID(watch_id)) {
13250b57cec5SDimitry Andric m_watchpoint_list.Remove(watch_id, true);
13260b57cec5SDimitry Andric return true;
13270b57cec5SDimitry Andric }
13280b57cec5SDimitry Andric return false;
13290b57cec5SDimitry Andric }
13300b57cec5SDimitry Andric
13310b57cec5SDimitry Andric // Assumption: Caller holds the list mutex lock for m_watchpoint_list.
IgnoreWatchpointByID(lldb::watch_id_t watch_id,uint32_t ignore_count)13320b57cec5SDimitry Andric bool Target::IgnoreWatchpointByID(lldb::watch_id_t watch_id,
13330b57cec5SDimitry Andric uint32_t ignore_count) {
13340b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS));
13359dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id);
13360b57cec5SDimitry Andric
13370b57cec5SDimitry Andric if (!ProcessIsValid())
13380b57cec5SDimitry Andric return false;
13390b57cec5SDimitry Andric
13400b57cec5SDimitry Andric WatchpointSP wp_sp = m_watchpoint_list.FindByID(watch_id);
13410b57cec5SDimitry Andric if (wp_sp) {
13420b57cec5SDimitry Andric wp_sp->SetIgnoreCount(ignore_count);
13430b57cec5SDimitry Andric return true;
13440b57cec5SDimitry Andric }
13450b57cec5SDimitry Andric return false;
13460b57cec5SDimitry Andric }
13470b57cec5SDimitry Andric
GetExecutableModule()13480b57cec5SDimitry Andric ModuleSP Target::GetExecutableModule() {
13490b57cec5SDimitry Andric // search for the first executable in the module list
13500b57cec5SDimitry Andric for (size_t i = 0; i < m_images.GetSize(); ++i) {
13510b57cec5SDimitry Andric ModuleSP module_sp = m_images.GetModuleAtIndex(i);
13520b57cec5SDimitry Andric lldb_private::ObjectFile *obj = module_sp->GetObjectFile();
13530b57cec5SDimitry Andric if (obj == nullptr)
13540b57cec5SDimitry Andric continue;
13550b57cec5SDimitry Andric if (obj->GetType() == ObjectFile::Type::eTypeExecutable)
13560b57cec5SDimitry Andric return module_sp;
13570b57cec5SDimitry Andric }
13580b57cec5SDimitry Andric // as fall back return the first module loaded
13590b57cec5SDimitry Andric return m_images.GetModuleAtIndex(0);
13600b57cec5SDimitry Andric }
13610b57cec5SDimitry Andric
GetExecutableModulePointer()13620b57cec5SDimitry Andric Module *Target::GetExecutableModulePointer() {
13630b57cec5SDimitry Andric return GetExecutableModule().get();
13640b57cec5SDimitry Andric }
13650b57cec5SDimitry Andric
LoadScriptingResourceForModule(const ModuleSP & module_sp,Target * target)13660b57cec5SDimitry Andric static void LoadScriptingResourceForModule(const ModuleSP &module_sp,
13670b57cec5SDimitry Andric Target *target) {
13680b57cec5SDimitry Andric Status error;
13690b57cec5SDimitry Andric StreamString feedback_stream;
13709dba64beSDimitry Andric if (module_sp && !module_sp->LoadScriptingResourceInTarget(
13719dba64beSDimitry Andric target, error, &feedback_stream)) {
13720b57cec5SDimitry Andric if (error.AsCString())
13739dba64beSDimitry Andric target->GetDebugger().GetErrorStream().Printf(
13740b57cec5SDimitry Andric "unable to load scripting data for module %s - error reported was "
13750b57cec5SDimitry Andric "%s\n",
13760b57cec5SDimitry Andric module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(),
13770b57cec5SDimitry Andric error.AsCString());
13780b57cec5SDimitry Andric }
13790b57cec5SDimitry Andric if (feedback_stream.GetSize())
13809dba64beSDimitry Andric target->GetDebugger().GetErrorStream().Printf("%s\n",
13810b57cec5SDimitry Andric feedback_stream.GetData());
13820b57cec5SDimitry Andric }
13830b57cec5SDimitry Andric
ClearModules(bool delete_locations)13840b57cec5SDimitry Andric void Target::ClearModules(bool delete_locations) {
13850b57cec5SDimitry Andric ModulesDidUnload(m_images, delete_locations);
13860b57cec5SDimitry Andric m_section_load_history.Clear();
13870b57cec5SDimitry Andric m_images.Clear();
13880b57cec5SDimitry Andric m_scratch_type_system_map.Clear();
13890b57cec5SDimitry Andric }
13900b57cec5SDimitry Andric
DidExec()13910b57cec5SDimitry Andric void Target::DidExec() {
13920b57cec5SDimitry Andric // When a process exec's we need to know about it so we can do some cleanup.
13930b57cec5SDimitry Andric m_breakpoint_list.RemoveInvalidLocations(m_arch.GetSpec());
13940b57cec5SDimitry Andric m_internal_breakpoint_list.RemoveInvalidLocations(m_arch.GetSpec());
13950b57cec5SDimitry Andric }
13960b57cec5SDimitry Andric
SetExecutableModule(ModuleSP & executable_sp,LoadDependentFiles load_dependent_files)13970b57cec5SDimitry Andric void Target::SetExecutableModule(ModuleSP &executable_sp,
13980b57cec5SDimitry Andric LoadDependentFiles load_dependent_files) {
13990b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET));
14000b57cec5SDimitry Andric ClearModules(false);
14010b57cec5SDimitry Andric
14020b57cec5SDimitry Andric if (executable_sp) {
1403af732203SDimitry Andric LLDB_SCOPED_TIMERF("Target::SetExecutableModule (executable = '%s')",
14040b57cec5SDimitry Andric executable_sp->GetFileSpec().GetPath().c_str());
14050b57cec5SDimitry Andric
14060b57cec5SDimitry Andric const bool notify = true;
14079dba64beSDimitry Andric m_images.Append(executable_sp,
14089dba64beSDimitry Andric notify); // The first image is our executable file
14090b57cec5SDimitry Andric
14100b57cec5SDimitry Andric // If we haven't set an architecture yet, reset our architecture based on
14110b57cec5SDimitry Andric // what we found in the executable module.
14120b57cec5SDimitry Andric if (!m_arch.GetSpec().IsValid()) {
14130b57cec5SDimitry Andric m_arch = executable_sp->GetArchitecture();
14140b57cec5SDimitry Andric LLDB_LOG(log,
14150b57cec5SDimitry Andric "setting architecture to {0} ({1}) based on executable file",
14160b57cec5SDimitry Andric m_arch.GetSpec().GetArchitectureName(),
14170b57cec5SDimitry Andric m_arch.GetSpec().GetTriple().getTriple());
14180b57cec5SDimitry Andric }
14190b57cec5SDimitry Andric
14200b57cec5SDimitry Andric FileSpecList dependent_files;
14210b57cec5SDimitry Andric ObjectFile *executable_objfile = executable_sp->GetObjectFile();
14220b57cec5SDimitry Andric bool load_dependents = true;
14230b57cec5SDimitry Andric switch (load_dependent_files) {
14240b57cec5SDimitry Andric case eLoadDependentsDefault:
14250b57cec5SDimitry Andric load_dependents = executable_sp->IsExecutable();
14260b57cec5SDimitry Andric break;
14270b57cec5SDimitry Andric case eLoadDependentsYes:
14280b57cec5SDimitry Andric load_dependents = true;
14290b57cec5SDimitry Andric break;
14300b57cec5SDimitry Andric case eLoadDependentsNo:
14310b57cec5SDimitry Andric load_dependents = false;
14320b57cec5SDimitry Andric break;
14330b57cec5SDimitry Andric }
14340b57cec5SDimitry Andric
14350b57cec5SDimitry Andric if (executable_objfile && load_dependents) {
14360b57cec5SDimitry Andric ModuleList added_modules;
14370b57cec5SDimitry Andric executable_objfile->GetDependentModules(dependent_files);
14380b57cec5SDimitry Andric for (uint32_t i = 0; i < dependent_files.GetSize(); i++) {
1439480093f4SDimitry Andric FileSpec dependent_file_spec(dependent_files.GetFileSpecAtIndex(i));
14400b57cec5SDimitry Andric FileSpec platform_dependent_file_spec;
14410b57cec5SDimitry Andric if (m_platform_sp)
14420b57cec5SDimitry Andric m_platform_sp->GetFileWithUUID(dependent_file_spec, nullptr,
14430b57cec5SDimitry Andric platform_dependent_file_spec);
14440b57cec5SDimitry Andric else
14450b57cec5SDimitry Andric platform_dependent_file_spec = dependent_file_spec;
14460b57cec5SDimitry Andric
14470b57cec5SDimitry Andric ModuleSpec module_spec(platform_dependent_file_spec, m_arch.GetSpec());
14489dba64beSDimitry Andric ModuleSP image_module_sp(
14499dba64beSDimitry Andric GetOrCreateModule(module_spec, false /* notify */));
14500b57cec5SDimitry Andric if (image_module_sp) {
14510b57cec5SDimitry Andric added_modules.AppendIfNeeded(image_module_sp, false);
14520b57cec5SDimitry Andric ObjectFile *objfile = image_module_sp->GetObjectFile();
14530b57cec5SDimitry Andric if (objfile)
14540b57cec5SDimitry Andric objfile->GetDependentModules(dependent_files);
14550b57cec5SDimitry Andric }
14560b57cec5SDimitry Andric }
14570b57cec5SDimitry Andric ModulesDidLoad(added_modules);
14580b57cec5SDimitry Andric }
14590b57cec5SDimitry Andric }
14600b57cec5SDimitry Andric }
14610b57cec5SDimitry Andric
SetArchitecture(const ArchSpec & arch_spec,bool set_platform)14620b57cec5SDimitry Andric bool Target::SetArchitecture(const ArchSpec &arch_spec, bool set_platform) {
14630b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET));
14640b57cec5SDimitry Andric bool missing_local_arch = !m_arch.GetSpec().IsValid();
14650b57cec5SDimitry Andric bool replace_local_arch = true;
14660b57cec5SDimitry Andric bool compatible_local_arch = false;
14670b57cec5SDimitry Andric ArchSpec other(arch_spec);
14680b57cec5SDimitry Andric
14690b57cec5SDimitry Andric // Changing the architecture might mean that the currently selected platform
14700b57cec5SDimitry Andric // isn't compatible. Set the platform correctly if we are asked to do so,
14710b57cec5SDimitry Andric // otherwise assume the user will set the platform manually.
14720b57cec5SDimitry Andric if (set_platform) {
14730b57cec5SDimitry Andric if (other.IsValid()) {
14740b57cec5SDimitry Andric auto platform_sp = GetPlatform();
14750b57cec5SDimitry Andric if (!platform_sp ||
14760b57cec5SDimitry Andric !platform_sp->IsCompatibleArchitecture(other, false, nullptr)) {
14770b57cec5SDimitry Andric ArchSpec platform_arch;
14780b57cec5SDimitry Andric auto arch_platform_sp =
14790b57cec5SDimitry Andric Platform::GetPlatformForArchitecture(other, &platform_arch);
14800b57cec5SDimitry Andric if (arch_platform_sp) {
14810b57cec5SDimitry Andric SetPlatform(arch_platform_sp);
14820b57cec5SDimitry Andric if (platform_arch.IsValid())
14830b57cec5SDimitry Andric other = platform_arch;
14840b57cec5SDimitry Andric }
14850b57cec5SDimitry Andric }
14860b57cec5SDimitry Andric }
14870b57cec5SDimitry Andric }
14880b57cec5SDimitry Andric
14890b57cec5SDimitry Andric if (!missing_local_arch) {
14900b57cec5SDimitry Andric if (m_arch.GetSpec().IsCompatibleMatch(arch_spec)) {
14910b57cec5SDimitry Andric other.MergeFrom(m_arch.GetSpec());
14920b57cec5SDimitry Andric
14930b57cec5SDimitry Andric if (m_arch.GetSpec().IsCompatibleMatch(other)) {
14940b57cec5SDimitry Andric compatible_local_arch = true;
14950b57cec5SDimitry Andric bool arch_changed, vendor_changed, os_changed, os_ver_changed,
14960b57cec5SDimitry Andric env_changed;
14970b57cec5SDimitry Andric
14989dba64beSDimitry Andric m_arch.GetSpec().PiecewiseTripleCompare(other, arch_changed,
14999dba64beSDimitry Andric vendor_changed, os_changed,
15009dba64beSDimitry Andric os_ver_changed, env_changed);
15010b57cec5SDimitry Andric
15020b57cec5SDimitry Andric if (!arch_changed && !vendor_changed && !os_changed && !env_changed)
15030b57cec5SDimitry Andric replace_local_arch = false;
15040b57cec5SDimitry Andric }
15050b57cec5SDimitry Andric }
15060b57cec5SDimitry Andric }
15070b57cec5SDimitry Andric
15080b57cec5SDimitry Andric if (compatible_local_arch || missing_local_arch) {
15090b57cec5SDimitry Andric // If we haven't got a valid arch spec, or the architectures are compatible
15100b57cec5SDimitry Andric // update the architecture, unless the one we already have is more
15110b57cec5SDimitry Andric // specified
15120b57cec5SDimitry Andric if (replace_local_arch)
15130b57cec5SDimitry Andric m_arch = other;
15140b57cec5SDimitry Andric LLDB_LOG(log, "set architecture to {0} ({1})",
15150b57cec5SDimitry Andric m_arch.GetSpec().GetArchitectureName(),
15160b57cec5SDimitry Andric m_arch.GetSpec().GetTriple().getTriple());
15170b57cec5SDimitry Andric return true;
15180b57cec5SDimitry Andric }
15190b57cec5SDimitry Andric
15200b57cec5SDimitry Andric // If we have an executable file, try to reset the executable to the desired
15210b57cec5SDimitry Andric // architecture
15229dba64beSDimitry Andric LLDB_LOGF(log, "Target::SetArchitecture changing architecture to %s (%s)",
15230b57cec5SDimitry Andric arch_spec.GetArchitectureName(),
15240b57cec5SDimitry Andric arch_spec.GetTriple().getTriple().c_str());
15250b57cec5SDimitry Andric m_arch = other;
15260b57cec5SDimitry Andric ModuleSP executable_sp = GetExecutableModule();
15270b57cec5SDimitry Andric
15280b57cec5SDimitry Andric ClearModules(true);
15290b57cec5SDimitry Andric // Need to do something about unsetting breakpoints.
15300b57cec5SDimitry Andric
15310b57cec5SDimitry Andric if (executable_sp) {
15329dba64beSDimitry Andric LLDB_LOGF(log,
15339dba64beSDimitry Andric "Target::SetArchitecture Trying to select executable file "
15340b57cec5SDimitry Andric "architecture %s (%s)",
15350b57cec5SDimitry Andric arch_spec.GetArchitectureName(),
15360b57cec5SDimitry Andric arch_spec.GetTriple().getTriple().c_str());
15370b57cec5SDimitry Andric ModuleSpec module_spec(executable_sp->GetFileSpec(), other);
15380b57cec5SDimitry Andric FileSpecList search_paths = GetExecutableSearchPaths();
15390b57cec5SDimitry Andric Status error = ModuleList::GetSharedModule(module_spec, executable_sp,
15409dba64beSDimitry Andric &search_paths, nullptr, nullptr);
15410b57cec5SDimitry Andric
15420b57cec5SDimitry Andric if (!error.Fail() && executable_sp) {
15430b57cec5SDimitry Andric SetExecutableModule(executable_sp, eLoadDependentsYes);
15440b57cec5SDimitry Andric return true;
15450b57cec5SDimitry Andric }
15460b57cec5SDimitry Andric }
15470b57cec5SDimitry Andric return false;
15480b57cec5SDimitry Andric }
15490b57cec5SDimitry Andric
MergeArchitecture(const ArchSpec & arch_spec)15500b57cec5SDimitry Andric bool Target::MergeArchitecture(const ArchSpec &arch_spec) {
15510b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET));
15520b57cec5SDimitry Andric if (arch_spec.IsValid()) {
15530b57cec5SDimitry Andric if (m_arch.GetSpec().IsCompatibleMatch(arch_spec)) {
15540b57cec5SDimitry Andric // The current target arch is compatible with "arch_spec", see if we can
15550b57cec5SDimitry Andric // improve our current architecture using bits from "arch_spec"
15560b57cec5SDimitry Andric
15579dba64beSDimitry Andric LLDB_LOGF(log,
15589dba64beSDimitry Andric "Target::MergeArchitecture target has arch %s, merging with "
15590b57cec5SDimitry Andric "arch %s",
15600b57cec5SDimitry Andric m_arch.GetSpec().GetTriple().getTriple().c_str(),
15610b57cec5SDimitry Andric arch_spec.GetTriple().getTriple().c_str());
15620b57cec5SDimitry Andric
15630b57cec5SDimitry Andric // Merge bits from arch_spec into "merged_arch" and set our architecture
15640b57cec5SDimitry Andric ArchSpec merged_arch(m_arch.GetSpec());
15650b57cec5SDimitry Andric merged_arch.MergeFrom(arch_spec);
15660b57cec5SDimitry Andric return SetArchitecture(merged_arch);
15670b57cec5SDimitry Andric } else {
15680b57cec5SDimitry Andric // The new architecture is different, we just need to replace it
15690b57cec5SDimitry Andric return SetArchitecture(arch_spec);
15700b57cec5SDimitry Andric }
15710b57cec5SDimitry Andric }
15720b57cec5SDimitry Andric return false;
15730b57cec5SDimitry Andric }
15740b57cec5SDimitry Andric
NotifyWillClearList(const ModuleList & module_list)15750b57cec5SDimitry Andric void Target::NotifyWillClearList(const ModuleList &module_list) {}
15760b57cec5SDimitry Andric
NotifyModuleAdded(const ModuleList & module_list,const ModuleSP & module_sp)15770b57cec5SDimitry Andric void Target::NotifyModuleAdded(const ModuleList &module_list,
15780b57cec5SDimitry Andric const ModuleSP &module_sp) {
15790b57cec5SDimitry Andric // A module is being added to this target for the first time
15800b57cec5SDimitry Andric if (m_valid) {
15810b57cec5SDimitry Andric ModuleList my_module_list;
15820b57cec5SDimitry Andric my_module_list.Append(module_sp);
15830b57cec5SDimitry Andric ModulesDidLoad(my_module_list);
15840b57cec5SDimitry Andric }
15850b57cec5SDimitry Andric }
15860b57cec5SDimitry Andric
NotifyModuleRemoved(const ModuleList & module_list,const ModuleSP & module_sp)15870b57cec5SDimitry Andric void Target::NotifyModuleRemoved(const ModuleList &module_list,
15880b57cec5SDimitry Andric const ModuleSP &module_sp) {
15890b57cec5SDimitry Andric // A module is being removed from this target.
15900b57cec5SDimitry Andric if (m_valid) {
15910b57cec5SDimitry Andric ModuleList my_module_list;
15920b57cec5SDimitry Andric my_module_list.Append(module_sp);
15930b57cec5SDimitry Andric ModulesDidUnload(my_module_list, false);
15940b57cec5SDimitry Andric }
15950b57cec5SDimitry Andric }
15960b57cec5SDimitry Andric
NotifyModuleUpdated(const ModuleList & module_list,const ModuleSP & old_module_sp,const ModuleSP & new_module_sp)15970b57cec5SDimitry Andric void Target::NotifyModuleUpdated(const ModuleList &module_list,
15980b57cec5SDimitry Andric const ModuleSP &old_module_sp,
15990b57cec5SDimitry Andric const ModuleSP &new_module_sp) {
16000b57cec5SDimitry Andric // A module is replacing an already added module
16010b57cec5SDimitry Andric if (m_valid) {
16020b57cec5SDimitry Andric m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp,
16030b57cec5SDimitry Andric new_module_sp);
16040b57cec5SDimitry Andric m_internal_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(
16050b57cec5SDimitry Andric old_module_sp, new_module_sp);
16060b57cec5SDimitry Andric }
16070b57cec5SDimitry Andric }
16080b57cec5SDimitry Andric
NotifyModulesRemoved(lldb_private::ModuleList & module_list)16090b57cec5SDimitry Andric void Target::NotifyModulesRemoved(lldb_private::ModuleList &module_list) {
16100b57cec5SDimitry Andric ModulesDidUnload(module_list, false);
16110b57cec5SDimitry Andric }
16120b57cec5SDimitry Andric
ModulesDidLoad(ModuleList & module_list)16130b57cec5SDimitry Andric void Target::ModulesDidLoad(ModuleList &module_list) {
16140b57cec5SDimitry Andric const size_t num_images = module_list.GetSize();
16150b57cec5SDimitry Andric if (m_valid && num_images) {
16160b57cec5SDimitry Andric for (size_t idx = 0; idx < num_images; ++idx) {
16170b57cec5SDimitry Andric ModuleSP module_sp(module_list.GetModuleAtIndex(idx));
16180b57cec5SDimitry Andric LoadScriptingResourceForModule(module_sp, this);
16190b57cec5SDimitry Andric }
16200b57cec5SDimitry Andric m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
16210b57cec5SDimitry Andric m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);
16220b57cec5SDimitry Andric if (m_process_sp) {
16230b57cec5SDimitry Andric m_process_sp->ModulesDidLoad(module_list);
16240b57cec5SDimitry Andric }
16250b57cec5SDimitry Andric BroadcastEvent(eBroadcastBitModulesLoaded,
16260b57cec5SDimitry Andric new TargetEventData(this->shared_from_this(), module_list));
16270b57cec5SDimitry Andric }
16280b57cec5SDimitry Andric }
16290b57cec5SDimitry Andric
SymbolsDidLoad(ModuleList & module_list)16300b57cec5SDimitry Andric void Target::SymbolsDidLoad(ModuleList &module_list) {
16310b57cec5SDimitry Andric if (m_valid && module_list.GetSize()) {
16320b57cec5SDimitry Andric if (m_process_sp) {
16330b57cec5SDimitry Andric for (LanguageRuntime *runtime : m_process_sp->GetLanguageRuntimes()) {
16340b57cec5SDimitry Andric runtime->SymbolsDidLoad(module_list);
16350b57cec5SDimitry Andric }
16360b57cec5SDimitry Andric }
16370b57cec5SDimitry Andric
16380b57cec5SDimitry Andric m_breakpoint_list.UpdateBreakpoints(module_list, true, false);
16390b57cec5SDimitry Andric m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false);
16400b57cec5SDimitry Andric BroadcastEvent(eBroadcastBitSymbolsLoaded,
16410b57cec5SDimitry Andric new TargetEventData(this->shared_from_this(), module_list));
16420b57cec5SDimitry Andric }
16430b57cec5SDimitry Andric }
16440b57cec5SDimitry Andric
ModulesDidUnload(ModuleList & module_list,bool delete_locations)16450b57cec5SDimitry Andric void Target::ModulesDidUnload(ModuleList &module_list, bool delete_locations) {
16460b57cec5SDimitry Andric if (m_valid && module_list.GetSize()) {
16470b57cec5SDimitry Andric UnloadModuleSections(module_list);
16480b57cec5SDimitry Andric m_breakpoint_list.UpdateBreakpoints(module_list, false, delete_locations);
16490b57cec5SDimitry Andric m_internal_breakpoint_list.UpdateBreakpoints(module_list, false,
16500b57cec5SDimitry Andric delete_locations);
16510b57cec5SDimitry Andric BroadcastEvent(eBroadcastBitModulesUnloaded,
16520b57cec5SDimitry Andric new TargetEventData(this->shared_from_this(), module_list));
16530b57cec5SDimitry Andric }
16540b57cec5SDimitry Andric }
16550b57cec5SDimitry Andric
ModuleIsExcludedForUnconstrainedSearches(const FileSpec & module_file_spec)16560b57cec5SDimitry Andric bool Target::ModuleIsExcludedForUnconstrainedSearches(
16570b57cec5SDimitry Andric const FileSpec &module_file_spec) {
16580b57cec5SDimitry Andric if (GetBreakpointsConsultPlatformAvoidList()) {
16590b57cec5SDimitry Andric ModuleList matchingModules;
16600b57cec5SDimitry Andric ModuleSpec module_spec(module_file_spec);
16619dba64beSDimitry Andric GetImages().FindModules(module_spec, matchingModules);
16629dba64beSDimitry Andric size_t num_modules = matchingModules.GetSize();
16630b57cec5SDimitry Andric
16649dba64beSDimitry Andric // If there is more than one module for this file spec, only
16659dba64beSDimitry Andric // return true if ALL the modules are on the black list.
16660b57cec5SDimitry Andric if (num_modules > 0) {
16670b57cec5SDimitry Andric for (size_t i = 0; i < num_modules; i++) {
16680b57cec5SDimitry Andric if (!ModuleIsExcludedForUnconstrainedSearches(
16690b57cec5SDimitry Andric matchingModules.GetModuleAtIndex(i)))
16700b57cec5SDimitry Andric return false;
16710b57cec5SDimitry Andric }
16720b57cec5SDimitry Andric return true;
16730b57cec5SDimitry Andric }
16740b57cec5SDimitry Andric }
16750b57cec5SDimitry Andric return false;
16760b57cec5SDimitry Andric }
16770b57cec5SDimitry Andric
ModuleIsExcludedForUnconstrainedSearches(const lldb::ModuleSP & module_sp)16780b57cec5SDimitry Andric bool Target::ModuleIsExcludedForUnconstrainedSearches(
16790b57cec5SDimitry Andric const lldb::ModuleSP &module_sp) {
16800b57cec5SDimitry Andric if (GetBreakpointsConsultPlatformAvoidList()) {
16810b57cec5SDimitry Andric if (m_platform_sp)
16820b57cec5SDimitry Andric return m_platform_sp->ModuleIsExcludedForUnconstrainedSearches(*this,
16830b57cec5SDimitry Andric module_sp);
16840b57cec5SDimitry Andric }
16850b57cec5SDimitry Andric return false;
16860b57cec5SDimitry Andric }
16870b57cec5SDimitry Andric
ReadMemoryFromFileCache(const Address & addr,void * dst,size_t dst_len,Status & error)16880b57cec5SDimitry Andric size_t Target::ReadMemoryFromFileCache(const Address &addr, void *dst,
16890b57cec5SDimitry Andric size_t dst_len, Status &error) {
1690*5f7ddb14SDimitry Andric LLDB_SCOPED_TIMER();
16910b57cec5SDimitry Andric SectionSP section_sp(addr.GetSection());
16920b57cec5SDimitry Andric if (section_sp) {
16930b57cec5SDimitry Andric // If the contents of this section are encrypted, the on-disk file is
16940b57cec5SDimitry Andric // unusable. Read only from live memory.
16950b57cec5SDimitry Andric if (section_sp->IsEncrypted()) {
16960b57cec5SDimitry Andric error.SetErrorString("section is encrypted");
16970b57cec5SDimitry Andric return 0;
16980b57cec5SDimitry Andric }
16990b57cec5SDimitry Andric ModuleSP module_sp(section_sp->GetModule());
17000b57cec5SDimitry Andric if (module_sp) {
17010b57cec5SDimitry Andric ObjectFile *objfile = section_sp->GetModule()->GetObjectFile();
17020b57cec5SDimitry Andric if (objfile) {
17030b57cec5SDimitry Andric size_t bytes_read = objfile->ReadSectionData(
17040b57cec5SDimitry Andric section_sp.get(), addr.GetOffset(), dst, dst_len);
17050b57cec5SDimitry Andric if (bytes_read > 0)
17060b57cec5SDimitry Andric return bytes_read;
17070b57cec5SDimitry Andric else
17080b57cec5SDimitry Andric error.SetErrorStringWithFormat("error reading data from section %s",
17090b57cec5SDimitry Andric section_sp->GetName().GetCString());
17100b57cec5SDimitry Andric } else
17110b57cec5SDimitry Andric error.SetErrorString("address isn't from a object file");
17120b57cec5SDimitry Andric } else
17130b57cec5SDimitry Andric error.SetErrorString("address isn't in a module");
17140b57cec5SDimitry Andric } else
17150b57cec5SDimitry Andric error.SetErrorString("address doesn't contain a section that points to a "
17160b57cec5SDimitry Andric "section in a object file");
17170b57cec5SDimitry Andric
17180b57cec5SDimitry Andric return 0;
17190b57cec5SDimitry Andric }
17200b57cec5SDimitry Andric
ReadMemory(const Address & addr,void * dst,size_t dst_len,Status & error,bool force_live_memory,lldb::addr_t * load_addr_ptr)1721*5f7ddb14SDimitry Andric size_t Target::ReadMemory(const Address &addr, void *dst, size_t dst_len,
1722*5f7ddb14SDimitry Andric Status &error, bool force_live_memory,
17230b57cec5SDimitry Andric lldb::addr_t *load_addr_ptr) {
17240b57cec5SDimitry Andric error.Clear();
17250b57cec5SDimitry Andric
17260b57cec5SDimitry Andric // if we end up reading this from process memory, we will fill this with the
17270b57cec5SDimitry Andric // actual load address
17280b57cec5SDimitry Andric if (load_addr_ptr)
17290b57cec5SDimitry Andric *load_addr_ptr = LLDB_INVALID_ADDRESS;
17300b57cec5SDimitry Andric
17310b57cec5SDimitry Andric size_t bytes_read = 0;
17320b57cec5SDimitry Andric
17330b57cec5SDimitry Andric addr_t load_addr = LLDB_INVALID_ADDRESS;
17340b57cec5SDimitry Andric addr_t file_addr = LLDB_INVALID_ADDRESS;
17350b57cec5SDimitry Andric Address resolved_addr;
17360b57cec5SDimitry Andric if (!addr.IsSectionOffset()) {
17370b57cec5SDimitry Andric SectionLoadList §ion_load_list = GetSectionLoadList();
17380b57cec5SDimitry Andric if (section_load_list.IsEmpty()) {
17390b57cec5SDimitry Andric // No sections are loaded, so we must assume we are not running yet and
17400b57cec5SDimitry Andric // anything we are given is a file address.
17410b57cec5SDimitry Andric file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its
17420b57cec5SDimitry Andric // offset is the file address
17430b57cec5SDimitry Andric m_images.ResolveFileAddress(file_addr, resolved_addr);
17440b57cec5SDimitry Andric } else {
17450b57cec5SDimitry Andric // We have at least one section loaded. This can be because we have
17460b57cec5SDimitry Andric // manually loaded some sections with "target modules load ..." or
17470b57cec5SDimitry Andric // because we have have a live process that has sections loaded through
17480b57cec5SDimitry Andric // the dynamic loader
17490b57cec5SDimitry Andric load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its
17500b57cec5SDimitry Andric // offset is the load address
17510b57cec5SDimitry Andric section_load_list.ResolveLoadAddress(load_addr, resolved_addr);
17520b57cec5SDimitry Andric }
17530b57cec5SDimitry Andric }
17540b57cec5SDimitry Andric if (!resolved_addr.IsValid())
17550b57cec5SDimitry Andric resolved_addr = addr;
17560b57cec5SDimitry Andric
1757*5f7ddb14SDimitry Andric // If we read from the file cache but can't get as many bytes as requested,
1758*5f7ddb14SDimitry Andric // we keep the result around in this buffer, in case this result is the
1759*5f7ddb14SDimitry Andric // best we can do.
1760*5f7ddb14SDimitry Andric std::unique_ptr<uint8_t[]> file_cache_read_buffer;
1761*5f7ddb14SDimitry Andric size_t file_cache_bytes_read = 0;
1762*5f7ddb14SDimitry Andric
1763*5f7ddb14SDimitry Andric // Read from file cache if read-only section.
1764*5f7ddb14SDimitry Andric if (!force_live_memory && resolved_addr.IsSectionOffset()) {
1765*5f7ddb14SDimitry Andric SectionSP section_sp(resolved_addr.GetSection());
1766*5f7ddb14SDimitry Andric if (section_sp) {
1767*5f7ddb14SDimitry Andric auto permissions = Flags(section_sp->GetPermissions());
1768*5f7ddb14SDimitry Andric bool is_readonly = !permissions.Test(ePermissionsWritable) &&
1769*5f7ddb14SDimitry Andric permissions.Test(ePermissionsReadable);
1770*5f7ddb14SDimitry Andric if (is_readonly) {
1771*5f7ddb14SDimitry Andric file_cache_bytes_read =
1772*5f7ddb14SDimitry Andric ReadMemoryFromFileCache(resolved_addr, dst, dst_len, error);
1773*5f7ddb14SDimitry Andric if (file_cache_bytes_read == dst_len)
1774*5f7ddb14SDimitry Andric return file_cache_bytes_read;
1775*5f7ddb14SDimitry Andric else if (file_cache_bytes_read > 0) {
1776*5f7ddb14SDimitry Andric file_cache_read_buffer =
1777*5f7ddb14SDimitry Andric std::make_unique<uint8_t[]>(file_cache_bytes_read);
1778*5f7ddb14SDimitry Andric std::memcpy(file_cache_read_buffer.get(), dst, file_cache_bytes_read);
1779*5f7ddb14SDimitry Andric }
1780*5f7ddb14SDimitry Andric }
1781*5f7ddb14SDimitry Andric }
17820b57cec5SDimitry Andric }
17830b57cec5SDimitry Andric
17840b57cec5SDimitry Andric if (ProcessIsValid()) {
17850b57cec5SDimitry Andric if (load_addr == LLDB_INVALID_ADDRESS)
17860b57cec5SDimitry Andric load_addr = resolved_addr.GetLoadAddress(this);
17870b57cec5SDimitry Andric
17880b57cec5SDimitry Andric if (load_addr == LLDB_INVALID_ADDRESS) {
17890b57cec5SDimitry Andric ModuleSP addr_module_sp(resolved_addr.GetModule());
17900b57cec5SDimitry Andric if (addr_module_sp && addr_module_sp->GetFileSpec())
17910b57cec5SDimitry Andric error.SetErrorStringWithFormatv(
17920b57cec5SDimitry Andric "{0:F}[{1:x+}] can't be resolved, {0:F} is not currently loaded",
17930b57cec5SDimitry Andric addr_module_sp->GetFileSpec(), resolved_addr.GetFileAddress());
17940b57cec5SDimitry Andric else
17950b57cec5SDimitry Andric error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved",
17960b57cec5SDimitry Andric resolved_addr.GetFileAddress());
17970b57cec5SDimitry Andric } else {
17980b57cec5SDimitry Andric bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
17990b57cec5SDimitry Andric if (bytes_read != dst_len) {
18000b57cec5SDimitry Andric if (error.Success()) {
18010b57cec5SDimitry Andric if (bytes_read == 0)
18020b57cec5SDimitry Andric error.SetErrorStringWithFormat(
18030b57cec5SDimitry Andric "read memory from 0x%" PRIx64 " failed", load_addr);
18040b57cec5SDimitry Andric else
18050b57cec5SDimitry Andric error.SetErrorStringWithFormat(
18060b57cec5SDimitry Andric "only %" PRIu64 " of %" PRIu64
18070b57cec5SDimitry Andric " bytes were read from memory at 0x%" PRIx64,
18080b57cec5SDimitry Andric (uint64_t)bytes_read, (uint64_t)dst_len, load_addr);
18090b57cec5SDimitry Andric }
18100b57cec5SDimitry Andric }
18110b57cec5SDimitry Andric if (bytes_read) {
18120b57cec5SDimitry Andric if (load_addr_ptr)
18130b57cec5SDimitry Andric *load_addr_ptr = load_addr;
18140b57cec5SDimitry Andric return bytes_read;
18150b57cec5SDimitry Andric }
18160b57cec5SDimitry Andric }
18170b57cec5SDimitry Andric }
18180b57cec5SDimitry Andric
1819*5f7ddb14SDimitry Andric if (file_cache_read_buffer && file_cache_bytes_read > 0) {
1820*5f7ddb14SDimitry Andric // Reading from the process failed. If we've previously succeeded in reading
1821*5f7ddb14SDimitry Andric // something from the file cache, then copy that over and return that.
1822*5f7ddb14SDimitry Andric std::memcpy(dst, file_cache_read_buffer.get(), file_cache_bytes_read);
1823*5f7ddb14SDimitry Andric return file_cache_bytes_read;
1824*5f7ddb14SDimitry Andric }
1825*5f7ddb14SDimitry Andric
1826*5f7ddb14SDimitry Andric if (!file_cache_read_buffer && resolved_addr.IsSectionOffset()) {
18270b57cec5SDimitry Andric // If we didn't already try and read from the object file cache, then try
18280b57cec5SDimitry Andric // it after failing to read from the process.
18290b57cec5SDimitry Andric return ReadMemoryFromFileCache(resolved_addr, dst, dst_len, error);
18300b57cec5SDimitry Andric }
18310b57cec5SDimitry Andric return 0;
18320b57cec5SDimitry Andric }
18330b57cec5SDimitry Andric
ReadCStringFromMemory(const Address & addr,std::string & out_str,Status & error)18340b57cec5SDimitry Andric size_t Target::ReadCStringFromMemory(const Address &addr, std::string &out_str,
18350b57cec5SDimitry Andric Status &error) {
18360b57cec5SDimitry Andric char buf[256];
18370b57cec5SDimitry Andric out_str.clear();
18380b57cec5SDimitry Andric addr_t curr_addr = addr.GetLoadAddress(this);
18390b57cec5SDimitry Andric Address address(addr);
18400b57cec5SDimitry Andric while (true) {
18410b57cec5SDimitry Andric size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error);
18420b57cec5SDimitry Andric if (length == 0)
18430b57cec5SDimitry Andric break;
18440b57cec5SDimitry Andric out_str.append(buf, length);
18450b57cec5SDimitry Andric // If we got "length - 1" bytes, we didn't get the whole C string, we need
18460b57cec5SDimitry Andric // to read some more characters
18470b57cec5SDimitry Andric if (length == sizeof(buf) - 1)
18480b57cec5SDimitry Andric curr_addr += length;
18490b57cec5SDimitry Andric else
18500b57cec5SDimitry Andric break;
18510b57cec5SDimitry Andric address = Address(curr_addr);
18520b57cec5SDimitry Andric }
18530b57cec5SDimitry Andric return out_str.size();
18540b57cec5SDimitry Andric }
18550b57cec5SDimitry Andric
ReadCStringFromMemory(const Address & addr,char * dst,size_t dst_max_len,Status & result_error)18560b57cec5SDimitry Andric size_t Target::ReadCStringFromMemory(const Address &addr, char *dst,
18570b57cec5SDimitry Andric size_t dst_max_len, Status &result_error) {
18580b57cec5SDimitry Andric size_t total_cstr_len = 0;
18590b57cec5SDimitry Andric if (dst && dst_max_len) {
18600b57cec5SDimitry Andric result_error.Clear();
18610b57cec5SDimitry Andric // NULL out everything just to be safe
18620b57cec5SDimitry Andric memset(dst, 0, dst_max_len);
18630b57cec5SDimitry Andric Status error;
18640b57cec5SDimitry Andric addr_t curr_addr = addr.GetLoadAddress(this);
18650b57cec5SDimitry Andric Address address(addr);
18660b57cec5SDimitry Andric
18670b57cec5SDimitry Andric // We could call m_process_sp->GetMemoryCacheLineSize() but I don't think
18680b57cec5SDimitry Andric // this really needs to be tied to the memory cache subsystem's cache line
18690b57cec5SDimitry Andric // size, so leave this as a fixed constant.
18700b57cec5SDimitry Andric const size_t cache_line_size = 512;
18710b57cec5SDimitry Andric
18720b57cec5SDimitry Andric size_t bytes_left = dst_max_len - 1;
18730b57cec5SDimitry Andric char *curr_dst = dst;
18740b57cec5SDimitry Andric
18750b57cec5SDimitry Andric while (bytes_left > 0) {
18760b57cec5SDimitry Andric addr_t cache_line_bytes_left =
18770b57cec5SDimitry Andric cache_line_size - (curr_addr % cache_line_size);
18780b57cec5SDimitry Andric addr_t bytes_to_read =
18790b57cec5SDimitry Andric std::min<addr_t>(bytes_left, cache_line_bytes_left);
18800b57cec5SDimitry Andric size_t bytes_read =
1881*5f7ddb14SDimitry Andric ReadMemory(address, curr_dst, bytes_to_read, error, true);
18820b57cec5SDimitry Andric
18830b57cec5SDimitry Andric if (bytes_read == 0) {
18840b57cec5SDimitry Andric result_error = error;
18850b57cec5SDimitry Andric dst[total_cstr_len] = '\0';
18860b57cec5SDimitry Andric break;
18870b57cec5SDimitry Andric }
18880b57cec5SDimitry Andric const size_t len = strlen(curr_dst);
18890b57cec5SDimitry Andric
18900b57cec5SDimitry Andric total_cstr_len += len;
18910b57cec5SDimitry Andric
18920b57cec5SDimitry Andric if (len < bytes_to_read)
18930b57cec5SDimitry Andric break;
18940b57cec5SDimitry Andric
18950b57cec5SDimitry Andric curr_dst += bytes_read;
18960b57cec5SDimitry Andric curr_addr += bytes_read;
18970b57cec5SDimitry Andric bytes_left -= bytes_read;
18980b57cec5SDimitry Andric address = Address(curr_addr);
18990b57cec5SDimitry Andric }
19000b57cec5SDimitry Andric } else {
19010b57cec5SDimitry Andric if (dst == nullptr)
19020b57cec5SDimitry Andric result_error.SetErrorString("invalid arguments");
19030b57cec5SDimitry Andric else
19040b57cec5SDimitry Andric result_error.Clear();
19050b57cec5SDimitry Andric }
19060b57cec5SDimitry Andric return total_cstr_len;
19070b57cec5SDimitry Andric }
19080b57cec5SDimitry Andric
ReadScalarIntegerFromMemory(const Address & addr,uint32_t byte_size,bool is_signed,Scalar & scalar,Status & error,bool force_live_memory)1909*5f7ddb14SDimitry Andric size_t Target::ReadScalarIntegerFromMemory(const Address &addr, uint32_t byte_size,
1910*5f7ddb14SDimitry Andric bool is_signed, Scalar &scalar,
1911*5f7ddb14SDimitry Andric Status &error,
1912*5f7ddb14SDimitry Andric bool force_live_memory) {
19130b57cec5SDimitry Andric uint64_t uval;
19140b57cec5SDimitry Andric
19150b57cec5SDimitry Andric if (byte_size <= sizeof(uval)) {
19160b57cec5SDimitry Andric size_t bytes_read =
1917*5f7ddb14SDimitry Andric ReadMemory(addr, &uval, byte_size, error, force_live_memory);
19180b57cec5SDimitry Andric if (bytes_read == byte_size) {
19190b57cec5SDimitry Andric DataExtractor data(&uval, sizeof(uval), m_arch.GetSpec().GetByteOrder(),
19200b57cec5SDimitry Andric m_arch.GetSpec().GetAddressByteSize());
19210b57cec5SDimitry Andric lldb::offset_t offset = 0;
19220b57cec5SDimitry Andric if (byte_size <= 4)
19230b57cec5SDimitry Andric scalar = data.GetMaxU32(&offset, byte_size);
19240b57cec5SDimitry Andric else
19250b57cec5SDimitry Andric scalar = data.GetMaxU64(&offset, byte_size);
19260b57cec5SDimitry Andric
19270b57cec5SDimitry Andric if (is_signed)
19280b57cec5SDimitry Andric scalar.SignExtend(byte_size * 8);
19290b57cec5SDimitry Andric return bytes_read;
19300b57cec5SDimitry Andric }
19310b57cec5SDimitry Andric } else {
19320b57cec5SDimitry Andric error.SetErrorStringWithFormat(
19330b57cec5SDimitry Andric "byte size of %u is too large for integer scalar type", byte_size);
19340b57cec5SDimitry Andric }
19350b57cec5SDimitry Andric return 0;
19360b57cec5SDimitry Andric }
19370b57cec5SDimitry Andric
ReadUnsignedIntegerFromMemory(const Address & addr,size_t integer_byte_size,uint64_t fail_value,Status & error,bool force_live_memory)19380b57cec5SDimitry Andric uint64_t Target::ReadUnsignedIntegerFromMemory(const Address &addr,
19390b57cec5SDimitry Andric size_t integer_byte_size,
1940*5f7ddb14SDimitry Andric uint64_t fail_value, Status &error,
1941*5f7ddb14SDimitry Andric bool force_live_memory) {
19420b57cec5SDimitry Andric Scalar scalar;
1943*5f7ddb14SDimitry Andric if (ReadScalarIntegerFromMemory(addr, integer_byte_size, false, scalar, error,
1944*5f7ddb14SDimitry Andric force_live_memory))
19450b57cec5SDimitry Andric return scalar.ULongLong(fail_value);
19460b57cec5SDimitry Andric return fail_value;
19470b57cec5SDimitry Andric }
19480b57cec5SDimitry Andric
ReadPointerFromMemory(const Address & addr,Status & error,Address & pointer_addr,bool force_live_memory)1949*5f7ddb14SDimitry Andric bool Target::ReadPointerFromMemory(const Address &addr, Status &error,
1950*5f7ddb14SDimitry Andric Address &pointer_addr,
1951*5f7ddb14SDimitry Andric bool force_live_memory) {
19520b57cec5SDimitry Andric Scalar scalar;
1953*5f7ddb14SDimitry Andric if (ReadScalarIntegerFromMemory(addr, m_arch.GetSpec().GetAddressByteSize(),
1954*5f7ddb14SDimitry Andric false, scalar, error, force_live_memory)) {
19550b57cec5SDimitry Andric addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS);
19560b57cec5SDimitry Andric if (pointer_vm_addr != LLDB_INVALID_ADDRESS) {
19570b57cec5SDimitry Andric SectionLoadList §ion_load_list = GetSectionLoadList();
19580b57cec5SDimitry Andric if (section_load_list.IsEmpty()) {
19590b57cec5SDimitry Andric // No sections are loaded, so we must assume we are not running yet and
19600b57cec5SDimitry Andric // anything we are given is a file address.
19610b57cec5SDimitry Andric m_images.ResolveFileAddress(pointer_vm_addr, pointer_addr);
19620b57cec5SDimitry Andric } else {
19630b57cec5SDimitry Andric // We have at least one section loaded. This can be because we have
19640b57cec5SDimitry Andric // manually loaded some sections with "target modules load ..." or
19650b57cec5SDimitry Andric // because we have have a live process that has sections loaded through
19660b57cec5SDimitry Andric // the dynamic loader
19670b57cec5SDimitry Andric section_load_list.ResolveLoadAddress(pointer_vm_addr, pointer_addr);
19680b57cec5SDimitry Andric }
19690b57cec5SDimitry Andric // We weren't able to resolve the pointer value, so just return an
19700b57cec5SDimitry Andric // address with no section
19710b57cec5SDimitry Andric if (!pointer_addr.IsValid())
19720b57cec5SDimitry Andric pointer_addr.SetOffset(pointer_vm_addr);
19730b57cec5SDimitry Andric return true;
19740b57cec5SDimitry Andric }
19750b57cec5SDimitry Andric }
19760b57cec5SDimitry Andric return false;
19770b57cec5SDimitry Andric }
19780b57cec5SDimitry Andric
GetOrCreateModule(const ModuleSpec & module_spec,bool notify,Status * error_ptr)19790b57cec5SDimitry Andric ModuleSP Target::GetOrCreateModule(const ModuleSpec &module_spec, bool notify,
19800b57cec5SDimitry Andric Status *error_ptr) {
19810b57cec5SDimitry Andric ModuleSP module_sp;
19820b57cec5SDimitry Andric
19830b57cec5SDimitry Andric Status error;
19840b57cec5SDimitry Andric
19850b57cec5SDimitry Andric // First see if we already have this module in our module list. If we do,
19860b57cec5SDimitry Andric // then we're done, we don't need to consult the shared modules list. But
19870b57cec5SDimitry Andric // only do this if we are passed a UUID.
19880b57cec5SDimitry Andric
19890b57cec5SDimitry Andric if (module_spec.GetUUID().IsValid())
19900b57cec5SDimitry Andric module_sp = m_images.FindFirstModule(module_spec);
19910b57cec5SDimitry Andric
19920b57cec5SDimitry Andric if (!module_sp) {
1993eaeb601bSDimitry Andric llvm::SmallVector<ModuleSP, 1>
1994eaeb601bSDimitry Andric old_modules; // This will get filled in if we have a new version
19950b57cec5SDimitry Andric // of the library
19960b57cec5SDimitry Andric bool did_create_module = false;
19970b57cec5SDimitry Andric FileSpecList search_paths = GetExecutableSearchPaths();
19980b57cec5SDimitry Andric // If there are image search path entries, try to use them first to acquire
19990b57cec5SDimitry Andric // a suitable image.
20000b57cec5SDimitry Andric if (m_image_search_paths.GetSize()) {
20010b57cec5SDimitry Andric ModuleSpec transformed_spec(module_spec);
20020b57cec5SDimitry Andric if (m_image_search_paths.RemapPath(
20030b57cec5SDimitry Andric module_spec.GetFileSpec().GetDirectory(),
20040b57cec5SDimitry Andric transformed_spec.GetFileSpec().GetDirectory())) {
20050b57cec5SDimitry Andric transformed_spec.GetFileSpec().GetFilename() =
20060b57cec5SDimitry Andric module_spec.GetFileSpec().GetFilename();
20070b57cec5SDimitry Andric error = ModuleList::GetSharedModule(transformed_spec, module_sp,
2008eaeb601bSDimitry Andric &search_paths, &old_modules,
20099dba64beSDimitry Andric &did_create_module);
20100b57cec5SDimitry Andric }
20110b57cec5SDimitry Andric }
20120b57cec5SDimitry Andric
20130b57cec5SDimitry Andric if (!module_sp) {
20140b57cec5SDimitry Andric // If we have a UUID, we can check our global shared module list in case
20150b57cec5SDimitry Andric // we already have it. If we don't have a valid UUID, then we can't since
20160b57cec5SDimitry Andric // the path in "module_spec" will be a platform path, and we will need to
20170b57cec5SDimitry Andric // let the platform find that file. For example, we could be asking for
20180b57cec5SDimitry Andric // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick
20190b57cec5SDimitry Andric // the local copy of "/usr/lib/dyld" since our platform could be a remote
20200b57cec5SDimitry Andric // platform that has its own "/usr/lib/dyld" in an SDK or in a local file
20210b57cec5SDimitry Andric // cache.
20220b57cec5SDimitry Andric if (module_spec.GetUUID().IsValid()) {
20230b57cec5SDimitry Andric // We have a UUID, it is OK to check the global module list...
20249dba64beSDimitry Andric error =
20259dba64beSDimitry Andric ModuleList::GetSharedModule(module_spec, module_sp, &search_paths,
2026eaeb601bSDimitry Andric &old_modules, &did_create_module);
20270b57cec5SDimitry Andric }
20280b57cec5SDimitry Andric
20290b57cec5SDimitry Andric if (!module_sp) {
20300b57cec5SDimitry Andric // The platform is responsible for finding and caching an appropriate
20310b57cec5SDimitry Andric // module in the shared module cache.
20320b57cec5SDimitry Andric if (m_platform_sp) {
20330b57cec5SDimitry Andric error = m_platform_sp->GetSharedModule(
20349dba64beSDimitry Andric module_spec, m_process_sp.get(), module_sp, &search_paths,
2035eaeb601bSDimitry Andric &old_modules, &did_create_module);
20360b57cec5SDimitry Andric } else {
20370b57cec5SDimitry Andric error.SetErrorString("no platform is currently set");
20380b57cec5SDimitry Andric }
20390b57cec5SDimitry Andric }
20400b57cec5SDimitry Andric }
20410b57cec5SDimitry Andric
20420b57cec5SDimitry Andric // We found a module that wasn't in our target list. Let's make sure that
20430b57cec5SDimitry Andric // there wasn't an equivalent module in the list already, and if there was,
20440b57cec5SDimitry Andric // let's remove it.
20450b57cec5SDimitry Andric if (module_sp) {
20460b57cec5SDimitry Andric ObjectFile *objfile = module_sp->GetObjectFile();
20470b57cec5SDimitry Andric if (objfile) {
20480b57cec5SDimitry Andric switch (objfile->GetType()) {
20490b57cec5SDimitry Andric case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of
20500b57cec5SDimitry Andric /// a program's execution state
20510b57cec5SDimitry Andric case ObjectFile::eTypeExecutable: /// A normal executable
20520b57cec5SDimitry Andric case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker
20530b57cec5SDimitry Andric /// executable
20540b57cec5SDimitry Andric case ObjectFile::eTypeObjectFile: /// An intermediate object file
20550b57cec5SDimitry Andric case ObjectFile::eTypeSharedLibrary: /// A shared library that can be
20560b57cec5SDimitry Andric /// used during execution
20570b57cec5SDimitry Andric break;
20580b57cec5SDimitry Andric case ObjectFile::eTypeDebugInfo: /// An object file that contains only
20590b57cec5SDimitry Andric /// debug information
20600b57cec5SDimitry Andric if (error_ptr)
20610b57cec5SDimitry Andric error_ptr->SetErrorString("debug info files aren't valid target "
20620b57cec5SDimitry Andric "modules, please specify an executable");
20630b57cec5SDimitry Andric return ModuleSP();
20640b57cec5SDimitry Andric case ObjectFile::eTypeStubLibrary: /// A library that can be linked
20650b57cec5SDimitry Andric /// against but not used for
20660b57cec5SDimitry Andric /// execution
20670b57cec5SDimitry Andric if (error_ptr)
20680b57cec5SDimitry Andric error_ptr->SetErrorString("stub libraries aren't valid target "
20690b57cec5SDimitry Andric "modules, please specify an executable");
20700b57cec5SDimitry Andric return ModuleSP();
20710b57cec5SDimitry Andric default:
20720b57cec5SDimitry Andric if (error_ptr)
20730b57cec5SDimitry Andric error_ptr->SetErrorString(
20740b57cec5SDimitry Andric "unsupported file type, please specify an executable");
20750b57cec5SDimitry Andric return ModuleSP();
20760b57cec5SDimitry Andric }
20770b57cec5SDimitry Andric // GetSharedModule is not guaranteed to find the old shared module, for
20780b57cec5SDimitry Andric // instance in the common case where you pass in the UUID, it is only
20790b57cec5SDimitry Andric // going to find the one module matching the UUID. In fact, it has no
20800b57cec5SDimitry Andric // good way to know what the "old module" relevant to this target is,
20810b57cec5SDimitry Andric // since there might be many copies of a module with this file spec in
20820b57cec5SDimitry Andric // various running debug sessions, but only one of them will belong to
20830b57cec5SDimitry Andric // this target. So let's remove the UUID from the module list, and look
20840b57cec5SDimitry Andric // in the target's module list. Only do this if there is SOMETHING else
20850b57cec5SDimitry Andric // in the module spec...
20860b57cec5SDimitry Andric if (module_spec.GetUUID().IsValid() &&
20870b57cec5SDimitry Andric !module_spec.GetFileSpec().GetFilename().IsEmpty() &&
20880b57cec5SDimitry Andric !module_spec.GetFileSpec().GetDirectory().IsEmpty()) {
20890b57cec5SDimitry Andric ModuleSpec module_spec_copy(module_spec.GetFileSpec());
20900b57cec5SDimitry Andric module_spec_copy.GetUUID().Clear();
20910b57cec5SDimitry Andric
20920b57cec5SDimitry Andric ModuleList found_modules;
20930b57cec5SDimitry Andric m_images.FindModules(module_spec_copy, found_modules);
2094eaeb601bSDimitry Andric found_modules.ForEach([&](const ModuleSP &found_module) -> bool {
2095eaeb601bSDimitry Andric old_modules.push_back(found_module);
2096eaeb601bSDimitry Andric return true;
2097eaeb601bSDimitry Andric });
20980b57cec5SDimitry Andric }
20990b57cec5SDimitry Andric
21000b57cec5SDimitry Andric // Preload symbols outside of any lock, so hopefully we can do this for
21010b57cec5SDimitry Andric // each library in parallel.
21020b57cec5SDimitry Andric if (GetPreloadSymbols())
21030b57cec5SDimitry Andric module_sp->PreloadSymbols();
21040b57cec5SDimitry Andric
2105eaeb601bSDimitry Andric llvm::SmallVector<ModuleSP, 1> replaced_modules;
2106eaeb601bSDimitry Andric for (ModuleSP &old_module_sp : old_modules) {
2107eaeb601bSDimitry Andric if (m_images.GetIndexForModule(old_module_sp.get()) !=
21080b57cec5SDimitry Andric LLDB_INVALID_INDEX32) {
2109eaeb601bSDimitry Andric if (replaced_modules.empty())
21100b57cec5SDimitry Andric m_images.ReplaceModule(old_module_sp, module_sp);
2111eaeb601bSDimitry Andric else
2112eaeb601bSDimitry Andric m_images.Remove(old_module_sp);
2113eaeb601bSDimitry Andric
2114eaeb601bSDimitry Andric replaced_modules.push_back(std::move(old_module_sp));
2115eaeb601bSDimitry Andric }
2116eaeb601bSDimitry Andric }
2117eaeb601bSDimitry Andric
2118eaeb601bSDimitry Andric if (replaced_modules.size() > 1) {
2119eaeb601bSDimitry Andric // The same new module replaced multiple old modules
2120eaeb601bSDimitry Andric // simultaneously. It's not clear this should ever
2121eaeb601bSDimitry Andric // happen (if we always replace old modules as we add
2122eaeb601bSDimitry Andric // new ones, presumably we should never have more than
2123eaeb601bSDimitry Andric // one old one). If there are legitimate cases where
2124eaeb601bSDimitry Andric // this happens, then the ModuleList::Notifier interface
2125eaeb601bSDimitry Andric // may need to be adjusted to allow reporting this.
2126eaeb601bSDimitry Andric // In the meantime, just log that this has happened; just
2127eaeb601bSDimitry Andric // above we called ReplaceModule on the first one, and Remove
2128eaeb601bSDimitry Andric // on the rest.
2129eaeb601bSDimitry Andric if (Log *log = GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET |
2130eaeb601bSDimitry Andric LIBLLDB_LOG_MODULES)) {
2131eaeb601bSDimitry Andric StreamString message;
2132eaeb601bSDimitry Andric auto dump = [&message](Module &dump_module) -> void {
2133eaeb601bSDimitry Andric UUID dump_uuid = dump_module.GetUUID();
2134eaeb601bSDimitry Andric
2135eaeb601bSDimitry Andric message << '[';
2136eaeb601bSDimitry Andric dump_module.GetDescription(message.AsRawOstream());
2137eaeb601bSDimitry Andric message << " (uuid ";
2138eaeb601bSDimitry Andric
2139eaeb601bSDimitry Andric if (dump_uuid.IsValid())
2140eaeb601bSDimitry Andric dump_uuid.Dump(&message);
2141eaeb601bSDimitry Andric else
2142eaeb601bSDimitry Andric message << "not specified";
2143eaeb601bSDimitry Andric
2144eaeb601bSDimitry Andric message << ")]";
2145eaeb601bSDimitry Andric };
2146eaeb601bSDimitry Andric
2147eaeb601bSDimitry Andric message << "New module ";
2148eaeb601bSDimitry Andric dump(*module_sp);
2149eaeb601bSDimitry Andric message.AsRawOstream()
2150eaeb601bSDimitry Andric << llvm::formatv(" simultaneously replaced {0} old modules: ",
2151eaeb601bSDimitry Andric replaced_modules.size());
2152eaeb601bSDimitry Andric for (ModuleSP &replaced_module_sp : replaced_modules)
2153eaeb601bSDimitry Andric dump(*replaced_module_sp);
2154eaeb601bSDimitry Andric
2155eaeb601bSDimitry Andric log->PutString(message.GetString());
2156eaeb601bSDimitry Andric }
2157eaeb601bSDimitry Andric }
2158eaeb601bSDimitry Andric
2159eaeb601bSDimitry Andric if (replaced_modules.empty())
2160eaeb601bSDimitry Andric m_images.Append(module_sp, notify);
2161eaeb601bSDimitry Andric
2162eaeb601bSDimitry Andric for (ModuleSP &old_module_sp : replaced_modules) {
21630b57cec5SDimitry Andric Module *old_module_ptr = old_module_sp.get();
21640b57cec5SDimitry Andric old_module_sp.reset();
21650b57cec5SDimitry Andric ModuleList::RemoveSharedModuleIfOrphaned(old_module_ptr);
21660b57cec5SDimitry Andric }
21670b57cec5SDimitry Andric } else
21680b57cec5SDimitry Andric module_sp.reset();
21690b57cec5SDimitry Andric }
21700b57cec5SDimitry Andric }
21710b57cec5SDimitry Andric if (error_ptr)
21720b57cec5SDimitry Andric *error_ptr = error;
21730b57cec5SDimitry Andric return module_sp;
21740b57cec5SDimitry Andric }
21750b57cec5SDimitry Andric
CalculateTarget()21760b57cec5SDimitry Andric TargetSP Target::CalculateTarget() { return shared_from_this(); }
21770b57cec5SDimitry Andric
CalculateProcess()21780b57cec5SDimitry Andric ProcessSP Target::CalculateProcess() { return m_process_sp; }
21790b57cec5SDimitry Andric
CalculateThread()21800b57cec5SDimitry Andric ThreadSP Target::CalculateThread() { return ThreadSP(); }
21810b57cec5SDimitry Andric
CalculateStackFrame()21820b57cec5SDimitry Andric StackFrameSP Target::CalculateStackFrame() { return StackFrameSP(); }
21830b57cec5SDimitry Andric
CalculateExecutionContext(ExecutionContext & exe_ctx)21840b57cec5SDimitry Andric void Target::CalculateExecutionContext(ExecutionContext &exe_ctx) {
21850b57cec5SDimitry Andric exe_ctx.Clear();
21860b57cec5SDimitry Andric exe_ctx.SetTargetPtr(this);
21870b57cec5SDimitry Andric }
21880b57cec5SDimitry Andric
GetImageSearchPathList()21890b57cec5SDimitry Andric PathMappingList &Target::GetImageSearchPathList() {
21900b57cec5SDimitry Andric return m_image_search_paths;
21910b57cec5SDimitry Andric }
21920b57cec5SDimitry Andric
ImageSearchPathsChanged(const PathMappingList & path_list,void * baton)21930b57cec5SDimitry Andric void Target::ImageSearchPathsChanged(const PathMappingList &path_list,
21940b57cec5SDimitry Andric void *baton) {
21950b57cec5SDimitry Andric Target *target = (Target *)baton;
21960b57cec5SDimitry Andric ModuleSP exe_module_sp(target->GetExecutableModule());
21970b57cec5SDimitry Andric if (exe_module_sp)
21980b57cec5SDimitry Andric target->SetExecutableModule(exe_module_sp, eLoadDependentsYes);
21990b57cec5SDimitry Andric }
22000b57cec5SDimitry Andric
22019dba64beSDimitry Andric llvm::Expected<TypeSystem &>
GetScratchTypeSystemForLanguage(lldb::LanguageType language,bool create_on_demand)22029dba64beSDimitry Andric Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language,
22030b57cec5SDimitry Andric bool create_on_demand) {
22040b57cec5SDimitry Andric if (!m_valid)
22059dba64beSDimitry Andric return llvm::make_error<llvm::StringError>("Invalid Target",
22069dba64beSDimitry Andric llvm::inconvertibleErrorCode());
22070b57cec5SDimitry Andric
22080b57cec5SDimitry Andric if (language == eLanguageTypeMipsAssembler // GNU AS and LLVM use it for all
22090b57cec5SDimitry Andric // assembly code
22100b57cec5SDimitry Andric || language == eLanguageTypeUnknown) {
22119dba64beSDimitry Andric LanguageSet languages_for_expressions =
22129dba64beSDimitry Andric Language::GetLanguagesSupportingTypeSystemsForExpressions();
22130b57cec5SDimitry Andric
22149dba64beSDimitry Andric if (languages_for_expressions[eLanguageTypeC]) {
22150b57cec5SDimitry Andric language = eLanguageTypeC; // LLDB's default. Override by setting the
22160b57cec5SDimitry Andric // target language.
22170b57cec5SDimitry Andric } else {
22189dba64beSDimitry Andric if (languages_for_expressions.Empty())
22199dba64beSDimitry Andric return llvm::make_error<llvm::StringError>(
22209dba64beSDimitry Andric "No expression support for any languages",
22219dba64beSDimitry Andric llvm::inconvertibleErrorCode());
22229dba64beSDimitry Andric language = (LanguageType)languages_for_expressions.bitvector.find_first();
22230b57cec5SDimitry Andric }
22240b57cec5SDimitry Andric }
22250b57cec5SDimitry Andric
22260b57cec5SDimitry Andric return m_scratch_type_system_map.GetTypeSystemForLanguage(language, this,
22270b57cec5SDimitry Andric create_on_demand);
22280b57cec5SDimitry Andric }
22290b57cec5SDimitry Andric
GetScratchTypeSystems(bool create_on_demand)22309dba64beSDimitry Andric std::vector<TypeSystem *> Target::GetScratchTypeSystems(bool create_on_demand) {
22319dba64beSDimitry Andric if (!m_valid)
22329dba64beSDimitry Andric return {};
22339dba64beSDimitry Andric
22349dba64beSDimitry Andric std::vector<TypeSystem *> scratch_type_systems;
22359dba64beSDimitry Andric
22369dba64beSDimitry Andric LanguageSet languages_for_expressions =
22379dba64beSDimitry Andric Language::GetLanguagesSupportingTypeSystemsForExpressions();
22389dba64beSDimitry Andric
22399dba64beSDimitry Andric for (auto bit : languages_for_expressions.bitvector.set_bits()) {
22409dba64beSDimitry Andric auto language = (LanguageType)bit;
22419dba64beSDimitry Andric auto type_system_or_err =
22429dba64beSDimitry Andric GetScratchTypeSystemForLanguage(language, create_on_demand);
22439dba64beSDimitry Andric if (!type_system_or_err)
22449dba64beSDimitry Andric LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET),
22459dba64beSDimitry Andric type_system_or_err.takeError(),
22469dba64beSDimitry Andric "Language '{}' has expression support but no scratch type "
22479dba64beSDimitry Andric "system available",
22489dba64beSDimitry Andric Language::GetNameForLanguageType(language));
22499dba64beSDimitry Andric else
22509dba64beSDimitry Andric scratch_type_systems.emplace_back(&type_system_or_err.get());
22519dba64beSDimitry Andric }
22529dba64beSDimitry Andric
22539dba64beSDimitry Andric return scratch_type_systems;
22549dba64beSDimitry Andric }
22559dba64beSDimitry Andric
22560b57cec5SDimitry Andric PersistentExpressionState *
GetPersistentExpressionStateForLanguage(lldb::LanguageType language)22570b57cec5SDimitry Andric Target::GetPersistentExpressionStateForLanguage(lldb::LanguageType language) {
22589dba64beSDimitry Andric auto type_system_or_err = GetScratchTypeSystemForLanguage(language, true);
22590b57cec5SDimitry Andric
22609dba64beSDimitry Andric if (auto err = type_system_or_err.takeError()) {
22619dba64beSDimitry Andric LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET),
22629dba64beSDimitry Andric std::move(err),
22639dba64beSDimitry Andric "Unable to get persistent expression state for language {}",
22649dba64beSDimitry Andric Language::GetNameForLanguageType(language));
22650b57cec5SDimitry Andric return nullptr;
22660b57cec5SDimitry Andric }
22679dba64beSDimitry Andric
22689dba64beSDimitry Andric return type_system_or_err->GetPersistentExpressionState();
22690b57cec5SDimitry Andric }
22700b57cec5SDimitry Andric
GetUserExpressionForLanguage(llvm::StringRef expr,llvm::StringRef prefix,lldb::LanguageType language,Expression::ResultType desired_type,const EvaluateExpressionOptions & options,ValueObject * ctx_obj,Status & error)22710b57cec5SDimitry Andric UserExpression *Target::GetUserExpressionForLanguage(
22720b57cec5SDimitry Andric llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language,
22730b57cec5SDimitry Andric Expression::ResultType desired_type,
22749dba64beSDimitry Andric const EvaluateExpressionOptions &options, ValueObject *ctx_obj,
22759dba64beSDimitry Andric Status &error) {
22769dba64beSDimitry Andric auto type_system_or_err = GetScratchTypeSystemForLanguage(language);
22779dba64beSDimitry Andric if (auto err = type_system_or_err.takeError()) {
22780b57cec5SDimitry Andric error.SetErrorStringWithFormat(
22790b57cec5SDimitry Andric "Could not find type system for language %s: %s",
22800b57cec5SDimitry Andric Language::GetNameForLanguageType(language),
22819dba64beSDimitry Andric llvm::toString(std::move(err)).c_str());
22820b57cec5SDimitry Andric return nullptr;
22830b57cec5SDimitry Andric }
22840b57cec5SDimitry Andric
22859dba64beSDimitry Andric auto *user_expr = type_system_or_err->GetUserExpression(
22869dba64beSDimitry Andric expr, prefix, language, desired_type, options, ctx_obj);
22870b57cec5SDimitry Andric if (!user_expr)
22880b57cec5SDimitry Andric error.SetErrorStringWithFormat(
22890b57cec5SDimitry Andric "Could not create an expression for language %s",
22900b57cec5SDimitry Andric Language::GetNameForLanguageType(language));
22910b57cec5SDimitry Andric
22920b57cec5SDimitry Andric return user_expr;
22930b57cec5SDimitry Andric }
22940b57cec5SDimitry Andric
GetFunctionCallerForLanguage(lldb::LanguageType language,const CompilerType & return_type,const Address & function_address,const ValueList & arg_value_list,const char * name,Status & error)22950b57cec5SDimitry Andric FunctionCaller *Target::GetFunctionCallerForLanguage(
22960b57cec5SDimitry Andric lldb::LanguageType language, const CompilerType &return_type,
22970b57cec5SDimitry Andric const Address &function_address, const ValueList &arg_value_list,
22980b57cec5SDimitry Andric const char *name, Status &error) {
22999dba64beSDimitry Andric auto type_system_or_err = GetScratchTypeSystemForLanguage(language);
23009dba64beSDimitry Andric if (auto err = type_system_or_err.takeError()) {
23010b57cec5SDimitry Andric error.SetErrorStringWithFormat(
23020b57cec5SDimitry Andric "Could not find type system for language %s: %s",
23030b57cec5SDimitry Andric Language::GetNameForLanguageType(language),
23049dba64beSDimitry Andric llvm::toString(std::move(err)).c_str());
23059dba64beSDimitry Andric return nullptr;
23060b57cec5SDimitry Andric }
23070b57cec5SDimitry Andric
23089dba64beSDimitry Andric auto *persistent_fn = type_system_or_err->GetFunctionCaller(
23099dba64beSDimitry Andric return_type, function_address, arg_value_list, name);
23100b57cec5SDimitry Andric if (!persistent_fn)
23110b57cec5SDimitry Andric error.SetErrorStringWithFormat(
23120b57cec5SDimitry Andric "Could not create an expression for language %s",
23130b57cec5SDimitry Andric Language::GetNameForLanguageType(language));
23140b57cec5SDimitry Andric
23150b57cec5SDimitry Andric return persistent_fn;
23160b57cec5SDimitry Andric }
23170b57cec5SDimitry Andric
2318af732203SDimitry Andric llvm::Expected<std::unique_ptr<UtilityFunction>>
CreateUtilityFunction(std::string expression,std::string name,lldb::LanguageType language,ExecutionContext & exe_ctx)2319af732203SDimitry Andric Target::CreateUtilityFunction(std::string expression, std::string name,
23200b57cec5SDimitry Andric lldb::LanguageType language,
2321af732203SDimitry Andric ExecutionContext &exe_ctx) {
23229dba64beSDimitry Andric auto type_system_or_err = GetScratchTypeSystemForLanguage(language);
2323af732203SDimitry Andric if (!type_system_or_err)
2324af732203SDimitry Andric return type_system_or_err.takeError();
23250b57cec5SDimitry Andric
2326af732203SDimitry Andric std::unique_ptr<UtilityFunction> utility_fn =
2327af732203SDimitry Andric type_system_or_err->CreateUtilityFunction(std::move(expression),
2328af732203SDimitry Andric std::move(name));
23290b57cec5SDimitry Andric if (!utility_fn)
2330af732203SDimitry Andric return llvm::make_error<llvm::StringError>(
2331af732203SDimitry Andric llvm::StringRef("Could not create an expression for language") +
2332af732203SDimitry Andric Language::GetNameForLanguageType(language),
2333af732203SDimitry Andric llvm::inconvertibleErrorCode());
23340b57cec5SDimitry Andric
2335af732203SDimitry Andric DiagnosticManager diagnostics;
2336af732203SDimitry Andric if (!utility_fn->Install(diagnostics, exe_ctx))
2337af732203SDimitry Andric return llvm::make_error<llvm::StringError>(diagnostics.GetString(),
2338af732203SDimitry Andric llvm::inconvertibleErrorCode());
2339af732203SDimitry Andric
2340af732203SDimitry Andric return std::move(utility_fn);
23410b57cec5SDimitry Andric }
23420b57cec5SDimitry Andric
SettingsInitialize()23430b57cec5SDimitry Andric void Target::SettingsInitialize() { Process::SettingsInitialize(); }
23440b57cec5SDimitry Andric
SettingsTerminate()23450b57cec5SDimitry Andric void Target::SettingsTerminate() { Process::SettingsTerminate(); }
23460b57cec5SDimitry Andric
GetDefaultExecutableSearchPaths()23470b57cec5SDimitry Andric FileSpecList Target::GetDefaultExecutableSearchPaths() {
23480b57cec5SDimitry Andric TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
23490b57cec5SDimitry Andric if (properties_sp)
23500b57cec5SDimitry Andric return properties_sp->GetExecutableSearchPaths();
23510b57cec5SDimitry Andric return FileSpecList();
23520b57cec5SDimitry Andric }
23530b57cec5SDimitry Andric
GetDefaultDebugFileSearchPaths()23540b57cec5SDimitry Andric FileSpecList Target::GetDefaultDebugFileSearchPaths() {
23550b57cec5SDimitry Andric TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
23560b57cec5SDimitry Andric if (properties_sp)
23570b57cec5SDimitry Andric return properties_sp->GetDebugFileSearchPaths();
23580b57cec5SDimitry Andric return FileSpecList();
23590b57cec5SDimitry Andric }
23600b57cec5SDimitry Andric
GetDefaultArchitecture()23610b57cec5SDimitry Andric ArchSpec Target::GetDefaultArchitecture() {
23620b57cec5SDimitry Andric TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
23630b57cec5SDimitry Andric if (properties_sp)
23640b57cec5SDimitry Andric return properties_sp->GetDefaultArchitecture();
23650b57cec5SDimitry Andric return ArchSpec();
23660b57cec5SDimitry Andric }
23670b57cec5SDimitry Andric
SetDefaultArchitecture(const ArchSpec & arch)23680b57cec5SDimitry Andric void Target::SetDefaultArchitecture(const ArchSpec &arch) {
23690b57cec5SDimitry Andric TargetPropertiesSP properties_sp(Target::GetGlobalProperties());
23700b57cec5SDimitry Andric if (properties_sp) {
23719dba64beSDimitry Andric LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET),
23729dba64beSDimitry Andric "Target::SetDefaultArchitecture setting target's "
23739dba64beSDimitry Andric "default architecture to {0} ({1})",
23749dba64beSDimitry Andric arch.GetArchitectureName(), arch.GetTriple().getTriple());
23750b57cec5SDimitry Andric return properties_sp->SetDefaultArchitecture(arch);
23760b57cec5SDimitry Andric }
23770b57cec5SDimitry Andric }
23780b57cec5SDimitry Andric
GetTargetFromContexts(const ExecutionContext * exe_ctx_ptr,const SymbolContext * sc_ptr)23790b57cec5SDimitry Andric Target *Target::GetTargetFromContexts(const ExecutionContext *exe_ctx_ptr,
23800b57cec5SDimitry Andric const SymbolContext *sc_ptr) {
23810b57cec5SDimitry Andric // The target can either exist in the "process" of ExecutionContext, or in
23820b57cec5SDimitry Andric // the "target_sp" member of SymbolContext. This accessor helper function
23830b57cec5SDimitry Andric // will get the target from one of these locations.
23840b57cec5SDimitry Andric
23850b57cec5SDimitry Andric Target *target = nullptr;
23860b57cec5SDimitry Andric if (sc_ptr != nullptr)
23870b57cec5SDimitry Andric target = sc_ptr->target_sp.get();
23880b57cec5SDimitry Andric if (target == nullptr && exe_ctx_ptr)
23890b57cec5SDimitry Andric target = exe_ctx_ptr->GetTargetPtr();
23900b57cec5SDimitry Andric return target;
23910b57cec5SDimitry Andric }
23920b57cec5SDimitry Andric
EvaluateExpression(llvm::StringRef expr,ExecutionContextScope * exe_scope,lldb::ValueObjectSP & result_valobj_sp,const EvaluateExpressionOptions & options,std::string * fixed_expression,ValueObject * ctx_obj)23930b57cec5SDimitry Andric ExpressionResults Target::EvaluateExpression(
23940b57cec5SDimitry Andric llvm::StringRef expr, ExecutionContextScope *exe_scope,
23950b57cec5SDimitry Andric lldb::ValueObjectSP &result_valobj_sp,
23960b57cec5SDimitry Andric const EvaluateExpressionOptions &options, std::string *fixed_expression,
23970b57cec5SDimitry Andric ValueObject *ctx_obj) {
23980b57cec5SDimitry Andric result_valobj_sp.reset();
23990b57cec5SDimitry Andric
24000b57cec5SDimitry Andric ExpressionResults execution_results = eExpressionSetupError;
24010b57cec5SDimitry Andric
24020b57cec5SDimitry Andric if (expr.empty())
24030b57cec5SDimitry Andric return execution_results;
24040b57cec5SDimitry Andric
24050b57cec5SDimitry Andric // We shouldn't run stop hooks in expressions.
24060b57cec5SDimitry Andric bool old_suppress_value = m_suppress_stop_hooks;
24070b57cec5SDimitry Andric m_suppress_stop_hooks = true;
24080b57cec5SDimitry Andric auto on_exit = llvm::make_scope_exit([this, old_suppress_value]() {
24099dba64beSDimitry Andric m_suppress_stop_hooks = old_suppress_value;
24109dba64beSDimitry Andric });
24110b57cec5SDimitry Andric
24120b57cec5SDimitry Andric ExecutionContext exe_ctx;
24130b57cec5SDimitry Andric
24140b57cec5SDimitry Andric if (exe_scope) {
24150b57cec5SDimitry Andric exe_scope->CalculateExecutionContext(exe_ctx);
24160b57cec5SDimitry Andric } else if (m_process_sp) {
24170b57cec5SDimitry Andric m_process_sp->CalculateExecutionContext(exe_ctx);
24180b57cec5SDimitry Andric } else {
24190b57cec5SDimitry Andric CalculateExecutionContext(exe_ctx);
24200b57cec5SDimitry Andric }
24210b57cec5SDimitry Andric
24220b57cec5SDimitry Andric // Make sure we aren't just trying to see the value of a persistent variable
24230b57cec5SDimitry Andric // (something like "$0")
24240b57cec5SDimitry Andric // Only check for persistent variables the expression starts with a '$'
24259dba64beSDimitry Andric lldb::ExpressionVariableSP persistent_var_sp;
24269dba64beSDimitry Andric if (expr[0] == '$') {
24279dba64beSDimitry Andric auto type_system_or_err =
24289dba64beSDimitry Andric GetScratchTypeSystemForLanguage(eLanguageTypeC);
24299dba64beSDimitry Andric if (auto err = type_system_or_err.takeError()) {
24309dba64beSDimitry Andric LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET),
24319dba64beSDimitry Andric std::move(err), "Unable to get scratch type system");
24329dba64beSDimitry Andric } else {
24339dba64beSDimitry Andric persistent_var_sp =
24349dba64beSDimitry Andric type_system_or_err->GetPersistentExpressionState()->GetVariable(expr);
24359dba64beSDimitry Andric }
24369dba64beSDimitry Andric }
24370b57cec5SDimitry Andric if (persistent_var_sp) {
24380b57cec5SDimitry Andric result_valobj_sp = persistent_var_sp->GetValueObject();
24390b57cec5SDimitry Andric execution_results = eExpressionCompleted;
24400b57cec5SDimitry Andric } else {
24410b57cec5SDimitry Andric llvm::StringRef prefix = GetExpressionPrefixContents();
24420b57cec5SDimitry Andric Status error;
24435ffd83dbSDimitry Andric execution_results = UserExpression::Evaluate(exe_ctx, options, expr, prefix,
24445ffd83dbSDimitry Andric result_valobj_sp, error,
24455ffd83dbSDimitry Andric fixed_expression, ctx_obj);
24460b57cec5SDimitry Andric }
24470b57cec5SDimitry Andric
24480b57cec5SDimitry Andric return execution_results;
24490b57cec5SDimitry Andric }
24500b57cec5SDimitry Andric
GetPersistentVariable(ConstString name)24519dba64beSDimitry Andric lldb::ExpressionVariableSP Target::GetPersistentVariable(ConstString name) {
24520b57cec5SDimitry Andric lldb::ExpressionVariableSP variable_sp;
24530b57cec5SDimitry Andric m_scratch_type_system_map.ForEach(
24540b57cec5SDimitry Andric [name, &variable_sp](TypeSystem *type_system) -> bool {
24550b57cec5SDimitry Andric if (PersistentExpressionState *persistent_state =
24560b57cec5SDimitry Andric type_system->GetPersistentExpressionState()) {
24570b57cec5SDimitry Andric variable_sp = persistent_state->GetVariable(name);
24580b57cec5SDimitry Andric
24590b57cec5SDimitry Andric if (variable_sp)
24600b57cec5SDimitry Andric return false; // Stop iterating the ForEach
24610b57cec5SDimitry Andric }
24620b57cec5SDimitry Andric return true; // Keep iterating the ForEach
24630b57cec5SDimitry Andric });
24640b57cec5SDimitry Andric return variable_sp;
24650b57cec5SDimitry Andric }
24660b57cec5SDimitry Andric
GetPersistentSymbol(ConstString name)24670b57cec5SDimitry Andric lldb::addr_t Target::GetPersistentSymbol(ConstString name) {
24680b57cec5SDimitry Andric lldb::addr_t address = LLDB_INVALID_ADDRESS;
24690b57cec5SDimitry Andric
24700b57cec5SDimitry Andric m_scratch_type_system_map.ForEach(
24710b57cec5SDimitry Andric [name, &address](TypeSystem *type_system) -> bool {
24720b57cec5SDimitry Andric if (PersistentExpressionState *persistent_state =
24730b57cec5SDimitry Andric type_system->GetPersistentExpressionState()) {
24740b57cec5SDimitry Andric address = persistent_state->LookupSymbol(name);
24750b57cec5SDimitry Andric if (address != LLDB_INVALID_ADDRESS)
24760b57cec5SDimitry Andric return false; // Stop iterating the ForEach
24770b57cec5SDimitry Andric }
24780b57cec5SDimitry Andric return true; // Keep iterating the ForEach
24790b57cec5SDimitry Andric });
24800b57cec5SDimitry Andric return address;
24810b57cec5SDimitry Andric }
24820b57cec5SDimitry Andric
GetEntryPointAddress()24839dba64beSDimitry Andric llvm::Expected<lldb_private::Address> Target::GetEntryPointAddress() {
24849dba64beSDimitry Andric Module *exe_module = GetExecutableModulePointer();
24859dba64beSDimitry Andric
24861e991466SDimitry Andric // Try to find the entry point address in the primary executable.
24871e991466SDimitry Andric const bool has_primary_executable = exe_module && exe_module->GetObjectFile();
24881e991466SDimitry Andric if (has_primary_executable) {
24899dba64beSDimitry Andric Address entry_addr = exe_module->GetObjectFile()->GetEntryPointAddress();
24909dba64beSDimitry Andric if (entry_addr.IsValid())
24919dba64beSDimitry Andric return entry_addr;
24929dba64beSDimitry Andric }
24939dba64beSDimitry Andric
24949dba64beSDimitry Andric const ModuleList &modules = GetImages();
24959dba64beSDimitry Andric const size_t num_images = modules.GetSize();
24969dba64beSDimitry Andric for (size_t idx = 0; idx < num_images; ++idx) {
24979dba64beSDimitry Andric ModuleSP module_sp(modules.GetModuleAtIndex(idx));
24989dba64beSDimitry Andric if (!module_sp || !module_sp->GetObjectFile())
24999dba64beSDimitry Andric continue;
25009dba64beSDimitry Andric
25019dba64beSDimitry Andric Address entry_addr = module_sp->GetObjectFile()->GetEntryPointAddress();
25021e991466SDimitry Andric if (entry_addr.IsValid())
25039dba64beSDimitry Andric return entry_addr;
25049dba64beSDimitry Andric }
25059dba64beSDimitry Andric
25061e991466SDimitry Andric // We haven't found the entry point address. Return an appropriate error.
25071e991466SDimitry Andric if (!has_primary_executable)
25081e991466SDimitry Andric return llvm::make_error<llvm::StringError>(
25091e991466SDimitry Andric "No primary executable found and could not find entry point address in "
25101e991466SDimitry Andric "any executable module",
25111e991466SDimitry Andric llvm::inconvertibleErrorCode());
25121e991466SDimitry Andric
25131e991466SDimitry Andric return llvm::make_error<llvm::StringError>(
25141e991466SDimitry Andric "Could not find entry point address for primary executable module \"" +
25151e991466SDimitry Andric exe_module->GetFileSpec().GetFilename().GetStringRef() + "\"",
25161e991466SDimitry Andric llvm::inconvertibleErrorCode());
25179dba64beSDimitry Andric }
25189dba64beSDimitry Andric
GetCallableLoadAddress(lldb::addr_t load_addr,AddressClass addr_class) const25190b57cec5SDimitry Andric lldb::addr_t Target::GetCallableLoadAddress(lldb::addr_t load_addr,
25200b57cec5SDimitry Andric AddressClass addr_class) const {
25210b57cec5SDimitry Andric auto arch_plugin = GetArchitecturePlugin();
25229dba64beSDimitry Andric return arch_plugin
25239dba64beSDimitry Andric ? arch_plugin->GetCallableLoadAddress(load_addr, addr_class)
25249dba64beSDimitry Andric : load_addr;
25250b57cec5SDimitry Andric }
25260b57cec5SDimitry Andric
GetOpcodeLoadAddress(lldb::addr_t load_addr,AddressClass addr_class) const25270b57cec5SDimitry Andric lldb::addr_t Target::GetOpcodeLoadAddress(lldb::addr_t load_addr,
25280b57cec5SDimitry Andric AddressClass addr_class) const {
25290b57cec5SDimitry Andric auto arch_plugin = GetArchitecturePlugin();
25309dba64beSDimitry Andric return arch_plugin ? arch_plugin->GetOpcodeLoadAddress(load_addr, addr_class)
25319dba64beSDimitry Andric : load_addr;
25320b57cec5SDimitry Andric }
25330b57cec5SDimitry Andric
GetBreakableLoadAddress(lldb::addr_t addr)25340b57cec5SDimitry Andric lldb::addr_t Target::GetBreakableLoadAddress(lldb::addr_t addr) {
25350b57cec5SDimitry Andric auto arch_plugin = GetArchitecturePlugin();
25369dba64beSDimitry Andric return arch_plugin ? arch_plugin->GetBreakableLoadAddress(addr, *this) : addr;
25370b57cec5SDimitry Andric }
25380b57cec5SDimitry Andric
GetSourceManager()25390b57cec5SDimitry Andric SourceManager &Target::GetSourceManager() {
25400b57cec5SDimitry Andric if (!m_source_manager_up)
25415ffd83dbSDimitry Andric m_source_manager_up = std::make_unique<SourceManager>(shared_from_this());
25420b57cec5SDimitry Andric return *m_source_manager_up;
25430b57cec5SDimitry Andric }
25440b57cec5SDimitry Andric
CreateStopHook(StopHook::StopHookKind kind)2545af732203SDimitry Andric Target::StopHookSP Target::CreateStopHook(StopHook::StopHookKind kind) {
25460b57cec5SDimitry Andric lldb::user_id_t new_uid = ++m_stop_hook_next_id;
2547af732203SDimitry Andric Target::StopHookSP stop_hook_sp;
2548af732203SDimitry Andric switch (kind) {
2549af732203SDimitry Andric case StopHook::StopHookKind::CommandBased:
2550af732203SDimitry Andric stop_hook_sp.reset(new StopHookCommandLine(shared_from_this(), new_uid));
2551af732203SDimitry Andric break;
2552af732203SDimitry Andric case StopHook::StopHookKind::ScriptBased:
2553af732203SDimitry Andric stop_hook_sp.reset(new StopHookScripted(shared_from_this(), new_uid));
2554af732203SDimitry Andric break;
2555af732203SDimitry Andric }
25560b57cec5SDimitry Andric m_stop_hooks[new_uid] = stop_hook_sp;
25570b57cec5SDimitry Andric return stop_hook_sp;
25580b57cec5SDimitry Andric }
25590b57cec5SDimitry Andric
UndoCreateStopHook(lldb::user_id_t user_id)2560af732203SDimitry Andric void Target::UndoCreateStopHook(lldb::user_id_t user_id) {
2561af732203SDimitry Andric if (!RemoveStopHookByID(user_id))
2562af732203SDimitry Andric return;
2563af732203SDimitry Andric if (user_id == m_stop_hook_next_id)
2564af732203SDimitry Andric m_stop_hook_next_id--;
2565af732203SDimitry Andric }
2566af732203SDimitry Andric
RemoveStopHookByID(lldb::user_id_t user_id)25670b57cec5SDimitry Andric bool Target::RemoveStopHookByID(lldb::user_id_t user_id) {
25680b57cec5SDimitry Andric size_t num_removed = m_stop_hooks.erase(user_id);
25690b57cec5SDimitry Andric return (num_removed != 0);
25700b57cec5SDimitry Andric }
25710b57cec5SDimitry Andric
RemoveAllStopHooks()25720b57cec5SDimitry Andric void Target::RemoveAllStopHooks() { m_stop_hooks.clear(); }
25730b57cec5SDimitry Andric
GetStopHookByID(lldb::user_id_t user_id)25740b57cec5SDimitry Andric Target::StopHookSP Target::GetStopHookByID(lldb::user_id_t user_id) {
25750b57cec5SDimitry Andric StopHookSP found_hook;
25760b57cec5SDimitry Andric
25770b57cec5SDimitry Andric StopHookCollection::iterator specified_hook_iter;
25780b57cec5SDimitry Andric specified_hook_iter = m_stop_hooks.find(user_id);
25790b57cec5SDimitry Andric if (specified_hook_iter != m_stop_hooks.end())
25800b57cec5SDimitry Andric found_hook = (*specified_hook_iter).second;
25810b57cec5SDimitry Andric return found_hook;
25820b57cec5SDimitry Andric }
25830b57cec5SDimitry Andric
SetStopHookActiveStateByID(lldb::user_id_t user_id,bool active_state)25840b57cec5SDimitry Andric bool Target::SetStopHookActiveStateByID(lldb::user_id_t user_id,
25850b57cec5SDimitry Andric bool active_state) {
25860b57cec5SDimitry Andric StopHookCollection::iterator specified_hook_iter;
25870b57cec5SDimitry Andric specified_hook_iter = m_stop_hooks.find(user_id);
25880b57cec5SDimitry Andric if (specified_hook_iter == m_stop_hooks.end())
25890b57cec5SDimitry Andric return false;
25900b57cec5SDimitry Andric
25910b57cec5SDimitry Andric (*specified_hook_iter).second->SetIsActive(active_state);
25920b57cec5SDimitry Andric return true;
25930b57cec5SDimitry Andric }
25940b57cec5SDimitry Andric
SetAllStopHooksActiveState(bool active_state)25950b57cec5SDimitry Andric void Target::SetAllStopHooksActiveState(bool active_state) {
25960b57cec5SDimitry Andric StopHookCollection::iterator pos, end = m_stop_hooks.end();
25970b57cec5SDimitry Andric for (pos = m_stop_hooks.begin(); pos != end; pos++) {
25980b57cec5SDimitry Andric (*pos).second->SetIsActive(active_state);
25990b57cec5SDimitry Andric }
26000b57cec5SDimitry Andric }
26010b57cec5SDimitry Andric
RunStopHooks()2602af732203SDimitry Andric bool Target::RunStopHooks() {
26030b57cec5SDimitry Andric if (m_suppress_stop_hooks)
2604af732203SDimitry Andric return false;
26050b57cec5SDimitry Andric
26060b57cec5SDimitry Andric if (!m_process_sp)
2607af732203SDimitry Andric return false;
26080b57cec5SDimitry Andric
26090b57cec5SDimitry Andric // Somebody might have restarted the process:
2610af732203SDimitry Andric // Still return false, the return value is about US restarting the target.
26110b57cec5SDimitry Andric if (m_process_sp->GetState() != eStateStopped)
2612af732203SDimitry Andric return false;
26130b57cec5SDimitry Andric
26140b57cec5SDimitry Andric if (m_stop_hooks.empty())
2615af732203SDimitry Andric return false;
26160b57cec5SDimitry Andric
26170b57cec5SDimitry Andric // If there aren't any active stop hooks, don't bother either.
26180b57cec5SDimitry Andric bool any_active_hooks = false;
26190b57cec5SDimitry Andric for (auto hook : m_stop_hooks) {
26200b57cec5SDimitry Andric if (hook.second->IsActive()) {
26210b57cec5SDimitry Andric any_active_hooks = true;
2622af732203SDimitry Andric break;
26230b57cec5SDimitry Andric }
26240b57cec5SDimitry Andric }
26250b57cec5SDimitry Andric if (!any_active_hooks)
2626af732203SDimitry Andric return false;
26270b57cec5SDimitry Andric
2628*5f7ddb14SDimitry Andric // <rdar://problem/12027563> make sure we check that we are not stopped
2629*5f7ddb14SDimitry Andric // because of us running a user expression since in that case we do not want
2630*5f7ddb14SDimitry Andric // to run the stop-hooks. Note, you can't just check whether the last stop
2631*5f7ddb14SDimitry Andric // was for a User Expression, because breakpoint commands get run before
2632*5f7ddb14SDimitry Andric // stop hooks, and one of them might have run an expression. You have
2633*5f7ddb14SDimitry Andric // to ensure you run the stop hooks once per natural stop.
2634*5f7ddb14SDimitry Andric uint32_t last_natural_stop = m_process_sp->GetModIDRef().GetLastNaturalStopID();
2635*5f7ddb14SDimitry Andric if (last_natural_stop != 0 && m_latest_stop_hook_id == last_natural_stop)
2636*5f7ddb14SDimitry Andric return false;
2637*5f7ddb14SDimitry Andric
2638*5f7ddb14SDimitry Andric m_latest_stop_hook_id = last_natural_stop;
2639*5f7ddb14SDimitry Andric
26400b57cec5SDimitry Andric std::vector<ExecutionContext> exc_ctx_with_reasons;
26410b57cec5SDimitry Andric
26420b57cec5SDimitry Andric ThreadList &cur_threadlist = m_process_sp->GetThreadList();
26430b57cec5SDimitry Andric size_t num_threads = cur_threadlist.GetSize();
26440b57cec5SDimitry Andric for (size_t i = 0; i < num_threads; i++) {
26450b57cec5SDimitry Andric lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex(i);
26460b57cec5SDimitry Andric if (cur_thread_sp->ThreadStoppedForAReason()) {
26470b57cec5SDimitry Andric lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0);
2648af732203SDimitry Andric exc_ctx_with_reasons.emplace_back(m_process_sp.get(), cur_thread_sp.get(),
2649af732203SDimitry Andric cur_frame_sp.get());
26500b57cec5SDimitry Andric }
26510b57cec5SDimitry Andric }
26520b57cec5SDimitry Andric
26530b57cec5SDimitry Andric // If no threads stopped for a reason, don't run the stop-hooks.
26540b57cec5SDimitry Andric size_t num_exe_ctx = exc_ctx_with_reasons.size();
26550b57cec5SDimitry Andric if (num_exe_ctx == 0)
2656af732203SDimitry Andric return false;
26570b57cec5SDimitry Andric
2658af732203SDimitry Andric StreamSP output_sp = m_debugger.GetAsyncOutputStream();
26590b57cec5SDimitry Andric
2660af732203SDimitry Andric bool auto_continue = false;
26610b57cec5SDimitry Andric bool hooks_ran = false;
26620b57cec5SDimitry Andric bool print_hook_header = (m_stop_hooks.size() != 1);
26630b57cec5SDimitry Andric bool print_thread_header = (num_exe_ctx != 1);
2664af732203SDimitry Andric bool should_stop = false;
2665af732203SDimitry Andric bool somebody_restarted = false;
26660b57cec5SDimitry Andric
2667af732203SDimitry Andric for (auto stop_entry : m_stop_hooks) {
2668af732203SDimitry Andric StopHookSP cur_hook_sp = stop_entry.second;
26690b57cec5SDimitry Andric if (!cur_hook_sp->IsActive())
26700b57cec5SDimitry Andric continue;
26710b57cec5SDimitry Andric
26720b57cec5SDimitry Andric bool any_thread_matched = false;
2673af732203SDimitry Andric for (auto exc_ctx : exc_ctx_with_reasons) {
2674af732203SDimitry Andric // We detect somebody restarted in the stop-hook loop, and broke out of
2675af732203SDimitry Andric // that loop back to here. So break out of here too.
2676af732203SDimitry Andric if (somebody_restarted)
2677af732203SDimitry Andric break;
2678af732203SDimitry Andric
2679af732203SDimitry Andric if (!cur_hook_sp->ExecutionContextPasses(exc_ctx))
2680af732203SDimitry Andric continue;
2681af732203SDimitry Andric
2682af732203SDimitry Andric // We only consult the auto-continue for a stop hook if it matched the
2683af732203SDimitry Andric // specifier.
2684af732203SDimitry Andric auto_continue |= cur_hook_sp->GetAutoContinue();
2685af732203SDimitry Andric
2686af732203SDimitry Andric if (!hooks_ran)
26870b57cec5SDimitry Andric hooks_ran = true;
2688af732203SDimitry Andric
26890b57cec5SDimitry Andric if (print_hook_header && !any_thread_matched) {
2690af732203SDimitry Andric StreamString s;
2691af732203SDimitry Andric cur_hook_sp->GetDescription(&s, eDescriptionLevelBrief);
2692af732203SDimitry Andric if (s.GetSize() != 0)
2693af732203SDimitry Andric output_sp->Printf("\n- Hook %" PRIu64 " (%s)\n", cur_hook_sp->GetID(),
2694af732203SDimitry Andric s.GetData());
26950b57cec5SDimitry Andric else
2696af732203SDimitry Andric output_sp->Printf("\n- Hook %" PRIu64 "\n", cur_hook_sp->GetID());
26970b57cec5SDimitry Andric any_thread_matched = true;
26980b57cec5SDimitry Andric }
26990b57cec5SDimitry Andric
27000b57cec5SDimitry Andric if (print_thread_header)
2701af732203SDimitry Andric output_sp->Printf("-- Thread %d\n",
2702af732203SDimitry Andric exc_ctx.GetThreadPtr()->GetIndexID());
27030b57cec5SDimitry Andric
2704af732203SDimitry Andric StopHook::StopHookResult this_result =
2705af732203SDimitry Andric cur_hook_sp->HandleStop(exc_ctx, output_sp);
2706af732203SDimitry Andric bool this_should_stop = true;
27070b57cec5SDimitry Andric
2708af732203SDimitry Andric switch (this_result) {
2709af732203SDimitry Andric case StopHook::StopHookResult::KeepStopped:
2710af732203SDimitry Andric // If this hook is set to auto-continue that should override the
2711af732203SDimitry Andric // HandleStop result...
2712af732203SDimitry Andric if (cur_hook_sp->GetAutoContinue())
2713af732203SDimitry Andric this_should_stop = false;
2714af732203SDimitry Andric else
2715af732203SDimitry Andric this_should_stop = true;
2716af732203SDimitry Andric
2717af732203SDimitry Andric break;
2718af732203SDimitry Andric case StopHook::StopHookResult::RequestContinue:
2719af732203SDimitry Andric this_should_stop = false;
2720af732203SDimitry Andric break;
2721af732203SDimitry Andric case StopHook::StopHookResult::AlreadyContinued:
2722af732203SDimitry Andric // We don't have a good way to prohibit people from restarting the
2723af732203SDimitry Andric // target willy nilly in a stop hook. If the hook did so, give a
2724af732203SDimitry Andric // gentle suggestion here and bag out if the hook processing.
2725af732203SDimitry Andric output_sp->Printf("\nAborting stop hooks, hook %" PRIu64
27260b57cec5SDimitry Andric " set the program running.\n"
27270b57cec5SDimitry Andric " Consider using '-G true' to make "
27280b57cec5SDimitry Andric "stop hooks auto-continue.\n",
27290b57cec5SDimitry Andric cur_hook_sp->GetID());
2730af732203SDimitry Andric somebody_restarted = true;
2731af732203SDimitry Andric break;
27320b57cec5SDimitry Andric }
2733af732203SDimitry Andric // If we're already restarted, stop processing stop hooks.
2734af732203SDimitry Andric // FIXME: if we are doing non-stop mode for real, we would have to
2735af732203SDimitry Andric // check that OUR thread was restarted, otherwise we should keep
2736af732203SDimitry Andric // processing stop hooks.
2737af732203SDimitry Andric if (somebody_restarted)
2738af732203SDimitry Andric break;
27390b57cec5SDimitry Andric
2740af732203SDimitry Andric // If anybody wanted to stop, we should all stop.
2741af732203SDimitry Andric if (!should_stop)
2742af732203SDimitry Andric should_stop = this_should_stop;
2743af732203SDimitry Andric }
2744af732203SDimitry Andric }
2745af732203SDimitry Andric
2746af732203SDimitry Andric output_sp->Flush();
2747af732203SDimitry Andric
2748af732203SDimitry Andric // If one of the commands in the stop hook already restarted the target,
2749af732203SDimitry Andric // report that fact.
2750af732203SDimitry Andric if (somebody_restarted)
2751af732203SDimitry Andric return true;
2752af732203SDimitry Andric
2753af732203SDimitry Andric // Finally, if auto-continue was requested, do it now:
2754af732203SDimitry Andric // We only compute should_stop against the hook results if a hook got to run
2755af732203SDimitry Andric // which is why we have to do this conjoint test.
2756af732203SDimitry Andric if ((hooks_ran && !should_stop) || auto_continue) {
2757af732203SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
2758af732203SDimitry Andric Status error = m_process_sp->PrivateResume();
2759af732203SDimitry Andric if (error.Success()) {
2760af732203SDimitry Andric LLDB_LOG(log, "Resuming from RunStopHooks");
2761af732203SDimitry Andric return true;
2762af732203SDimitry Andric } else {
2763af732203SDimitry Andric LLDB_LOG(log, "Resuming from RunStopHooks failed: {0}", error);
2764af732203SDimitry Andric return false;
2765af732203SDimitry Andric }
2766af732203SDimitry Andric }
2767af732203SDimitry Andric
2768af732203SDimitry Andric return false;
27690b57cec5SDimitry Andric }
27700b57cec5SDimitry Andric
GetGlobalProperties()27710b57cec5SDimitry Andric const TargetPropertiesSP &Target::GetGlobalProperties() {
27720b57cec5SDimitry Andric // NOTE: intentional leak so we don't crash if global destructor chain gets
27730b57cec5SDimitry Andric // called as other threads still use the result of this function
27740b57cec5SDimitry Andric static TargetPropertiesSP *g_settings_sp_ptr =
27750b57cec5SDimitry Andric new TargetPropertiesSP(new TargetProperties(nullptr));
27760b57cec5SDimitry Andric return *g_settings_sp_ptr;
27770b57cec5SDimitry Andric }
27780b57cec5SDimitry Andric
Install(ProcessLaunchInfo * launch_info)27790b57cec5SDimitry Andric Status Target::Install(ProcessLaunchInfo *launch_info) {
27800b57cec5SDimitry Andric Status error;
27810b57cec5SDimitry Andric PlatformSP platform_sp(GetPlatform());
27820b57cec5SDimitry Andric if (platform_sp) {
27830b57cec5SDimitry Andric if (platform_sp->IsRemote()) {
27840b57cec5SDimitry Andric if (platform_sp->IsConnected()) {
27855ffd83dbSDimitry Andric // Install all files that have an install path when connected to a
27865ffd83dbSDimitry Andric // remote platform. If target.auto-install-main-executable is set then
27875ffd83dbSDimitry Andric // also install the main executable even if it does not have an explicit
27885ffd83dbSDimitry Andric // install path specified.
27890b57cec5SDimitry Andric const ModuleList &modules = GetImages();
27900b57cec5SDimitry Andric const size_t num_images = modules.GetSize();
27910b57cec5SDimitry Andric for (size_t idx = 0; idx < num_images; ++idx) {
27920b57cec5SDimitry Andric ModuleSP module_sp(modules.GetModuleAtIndex(idx));
27930b57cec5SDimitry Andric if (module_sp) {
27940b57cec5SDimitry Andric const bool is_main_executable = module_sp == GetExecutableModule();
27950b57cec5SDimitry Andric FileSpec local_file(module_sp->GetFileSpec());
27960b57cec5SDimitry Andric if (local_file) {
27970b57cec5SDimitry Andric FileSpec remote_file(module_sp->GetRemoteInstallFileSpec());
27980b57cec5SDimitry Andric if (!remote_file) {
27995ffd83dbSDimitry Andric if (is_main_executable && GetAutoInstallMainExecutable()) {
28005ffd83dbSDimitry Andric // Automatically install the main executable.
28010b57cec5SDimitry Andric remote_file = platform_sp->GetRemoteWorkingDirectory();
28020b57cec5SDimitry Andric remote_file.AppendPathComponent(
28030b57cec5SDimitry Andric module_sp->GetFileSpec().GetFilename().GetCString());
28040b57cec5SDimitry Andric }
28050b57cec5SDimitry Andric }
28060b57cec5SDimitry Andric if (remote_file) {
28070b57cec5SDimitry Andric error = platform_sp->Install(local_file, remote_file);
28080b57cec5SDimitry Andric if (error.Success()) {
28090b57cec5SDimitry Andric module_sp->SetPlatformFileSpec(remote_file);
28100b57cec5SDimitry Andric if (is_main_executable) {
28110b57cec5SDimitry Andric platform_sp->SetFilePermissions(remote_file, 0700);
28120b57cec5SDimitry Andric if (launch_info)
28130b57cec5SDimitry Andric launch_info->SetExecutableFile(remote_file, false);
28140b57cec5SDimitry Andric }
28150b57cec5SDimitry Andric } else
28160b57cec5SDimitry Andric break;
28170b57cec5SDimitry Andric }
28180b57cec5SDimitry Andric }
28190b57cec5SDimitry Andric }
28200b57cec5SDimitry Andric }
28210b57cec5SDimitry Andric }
28220b57cec5SDimitry Andric }
28230b57cec5SDimitry Andric }
28240b57cec5SDimitry Andric return error;
28250b57cec5SDimitry Andric }
28260b57cec5SDimitry Andric
ResolveLoadAddress(addr_t load_addr,Address & so_addr,uint32_t stop_id)28270b57cec5SDimitry Andric bool Target::ResolveLoadAddress(addr_t load_addr, Address &so_addr,
28280b57cec5SDimitry Andric uint32_t stop_id) {
28290b57cec5SDimitry Andric return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr);
28300b57cec5SDimitry Andric }
28310b57cec5SDimitry Andric
ResolveFileAddress(lldb::addr_t file_addr,Address & resolved_addr)28320b57cec5SDimitry Andric bool Target::ResolveFileAddress(lldb::addr_t file_addr,
28330b57cec5SDimitry Andric Address &resolved_addr) {
28340b57cec5SDimitry Andric return m_images.ResolveFileAddress(file_addr, resolved_addr);
28350b57cec5SDimitry Andric }
28360b57cec5SDimitry Andric
SetSectionLoadAddress(const SectionSP & section_sp,addr_t new_section_load_addr,bool warn_multiple)28370b57cec5SDimitry Andric bool Target::SetSectionLoadAddress(const SectionSP §ion_sp,
28380b57cec5SDimitry Andric addr_t new_section_load_addr,
28390b57cec5SDimitry Andric bool warn_multiple) {
28400b57cec5SDimitry Andric const addr_t old_section_load_addr =
28410b57cec5SDimitry Andric m_section_load_history.GetSectionLoadAddress(
28420b57cec5SDimitry Andric SectionLoadHistory::eStopIDNow, section_sp);
28430b57cec5SDimitry Andric if (old_section_load_addr != new_section_load_addr) {
28440b57cec5SDimitry Andric uint32_t stop_id = 0;
28450b57cec5SDimitry Andric ProcessSP process_sp(GetProcessSP());
28460b57cec5SDimitry Andric if (process_sp)
28470b57cec5SDimitry Andric stop_id = process_sp->GetStopID();
28480b57cec5SDimitry Andric else
28490b57cec5SDimitry Andric stop_id = m_section_load_history.GetLastStopID();
28500b57cec5SDimitry Andric if (m_section_load_history.SetSectionLoadAddress(
28510b57cec5SDimitry Andric stop_id, section_sp, new_section_load_addr, warn_multiple))
28520b57cec5SDimitry Andric return true; // Return true if the section load address was changed...
28530b57cec5SDimitry Andric }
28540b57cec5SDimitry Andric return false; // Return false to indicate nothing changed
28550b57cec5SDimitry Andric }
28560b57cec5SDimitry Andric
UnloadModuleSections(const ModuleList & module_list)28570b57cec5SDimitry Andric size_t Target::UnloadModuleSections(const ModuleList &module_list) {
28580b57cec5SDimitry Andric size_t section_unload_count = 0;
28590b57cec5SDimitry Andric size_t num_modules = module_list.GetSize();
28600b57cec5SDimitry Andric for (size_t i = 0; i < num_modules; ++i) {
28610b57cec5SDimitry Andric section_unload_count +=
28620b57cec5SDimitry Andric UnloadModuleSections(module_list.GetModuleAtIndex(i));
28630b57cec5SDimitry Andric }
28640b57cec5SDimitry Andric return section_unload_count;
28650b57cec5SDimitry Andric }
28660b57cec5SDimitry Andric
UnloadModuleSections(const lldb::ModuleSP & module_sp)28670b57cec5SDimitry Andric size_t Target::UnloadModuleSections(const lldb::ModuleSP &module_sp) {
28680b57cec5SDimitry Andric uint32_t stop_id = 0;
28690b57cec5SDimitry Andric ProcessSP process_sp(GetProcessSP());
28700b57cec5SDimitry Andric if (process_sp)
28710b57cec5SDimitry Andric stop_id = process_sp->GetStopID();
28720b57cec5SDimitry Andric else
28730b57cec5SDimitry Andric stop_id = m_section_load_history.GetLastStopID();
28740b57cec5SDimitry Andric SectionList *sections = module_sp->GetSectionList();
28750b57cec5SDimitry Andric size_t section_unload_count = 0;
28760b57cec5SDimitry Andric if (sections) {
28770b57cec5SDimitry Andric const uint32_t num_sections = sections->GetNumSections(0);
28780b57cec5SDimitry Andric for (uint32_t i = 0; i < num_sections; ++i) {
28790b57cec5SDimitry Andric section_unload_count += m_section_load_history.SetSectionUnloaded(
28800b57cec5SDimitry Andric stop_id, sections->GetSectionAtIndex(i));
28810b57cec5SDimitry Andric }
28820b57cec5SDimitry Andric }
28830b57cec5SDimitry Andric return section_unload_count;
28840b57cec5SDimitry Andric }
28850b57cec5SDimitry Andric
SetSectionUnloaded(const lldb::SectionSP & section_sp)28860b57cec5SDimitry Andric bool Target::SetSectionUnloaded(const lldb::SectionSP §ion_sp) {
28870b57cec5SDimitry Andric uint32_t stop_id = 0;
28880b57cec5SDimitry Andric ProcessSP process_sp(GetProcessSP());
28890b57cec5SDimitry Andric if (process_sp)
28900b57cec5SDimitry Andric stop_id = process_sp->GetStopID();
28910b57cec5SDimitry Andric else
28920b57cec5SDimitry Andric stop_id = m_section_load_history.GetLastStopID();
28930b57cec5SDimitry Andric return m_section_load_history.SetSectionUnloaded(stop_id, section_sp);
28940b57cec5SDimitry Andric }
28950b57cec5SDimitry Andric
SetSectionUnloaded(const lldb::SectionSP & section_sp,addr_t load_addr)28960b57cec5SDimitry Andric bool Target::SetSectionUnloaded(const lldb::SectionSP §ion_sp,
28970b57cec5SDimitry Andric addr_t load_addr) {
28980b57cec5SDimitry Andric uint32_t stop_id = 0;
28990b57cec5SDimitry Andric ProcessSP process_sp(GetProcessSP());
29000b57cec5SDimitry Andric if (process_sp)
29010b57cec5SDimitry Andric stop_id = process_sp->GetStopID();
29020b57cec5SDimitry Andric else
29030b57cec5SDimitry Andric stop_id = m_section_load_history.GetLastStopID();
29040b57cec5SDimitry Andric return m_section_load_history.SetSectionUnloaded(stop_id, section_sp,
29050b57cec5SDimitry Andric load_addr);
29060b57cec5SDimitry Andric }
29070b57cec5SDimitry Andric
ClearAllLoadedSections()29080b57cec5SDimitry Andric void Target::ClearAllLoadedSections() { m_section_load_history.Clear(); }
29090b57cec5SDimitry Andric
Launch(ProcessLaunchInfo & launch_info,Stream * stream)29100b57cec5SDimitry Andric Status Target::Launch(ProcessLaunchInfo &launch_info, Stream *stream) {
29110b57cec5SDimitry Andric Status error;
29120b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET));
29130b57cec5SDimitry Andric
29149dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s() called for %s", __FUNCTION__,
29150b57cec5SDimitry Andric launch_info.GetExecutableFile().GetPath().c_str());
29160b57cec5SDimitry Andric
29170b57cec5SDimitry Andric StateType state = eStateInvalid;
29180b57cec5SDimitry Andric
29190b57cec5SDimitry Andric // Scope to temporarily get the process state in case someone has manually
29200b57cec5SDimitry Andric // remotely connected already to a process and we can skip the platform
29210b57cec5SDimitry Andric // launching.
29220b57cec5SDimitry Andric {
29230b57cec5SDimitry Andric ProcessSP process_sp(GetProcessSP());
29240b57cec5SDimitry Andric
29250b57cec5SDimitry Andric if (process_sp) {
29260b57cec5SDimitry Andric state = process_sp->GetState();
29279dba64beSDimitry Andric LLDB_LOGF(log,
29280b57cec5SDimitry Andric "Target::%s the process exists, and its current state is %s",
29290b57cec5SDimitry Andric __FUNCTION__, StateAsCString(state));
29300b57cec5SDimitry Andric } else {
29319dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s the process instance doesn't currently exist.",
29320b57cec5SDimitry Andric __FUNCTION__);
29330b57cec5SDimitry Andric }
29340b57cec5SDimitry Andric }
29350b57cec5SDimitry Andric
29360b57cec5SDimitry Andric launch_info.GetFlags().Set(eLaunchFlagDebug);
29370b57cec5SDimitry Andric
2938*5f7ddb14SDimitry Andric if (launch_info.IsScriptedProcess()) {
2939*5f7ddb14SDimitry Andric TargetPropertiesSP properties_sp = GetGlobalProperties();
2940*5f7ddb14SDimitry Andric
2941*5f7ddb14SDimitry Andric if (!properties_sp) {
2942*5f7ddb14SDimitry Andric LLDB_LOGF(log, "Target::%s Couldn't fetch target global properties.",
2943*5f7ddb14SDimitry Andric __FUNCTION__);
2944*5f7ddb14SDimitry Andric return error;
2945*5f7ddb14SDimitry Andric }
2946*5f7ddb14SDimitry Andric
2947*5f7ddb14SDimitry Andric // Only copy scripted process launch options.
2948*5f7ddb14SDimitry Andric ProcessLaunchInfo &default_launch_info =
2949*5f7ddb14SDimitry Andric const_cast<ProcessLaunchInfo &>(properties_sp->GetProcessLaunchInfo());
2950*5f7ddb14SDimitry Andric
2951*5f7ddb14SDimitry Andric default_launch_info.SetProcessPluginName("ScriptedProcess");
2952*5f7ddb14SDimitry Andric default_launch_info.SetScriptedProcessClassName(
2953*5f7ddb14SDimitry Andric launch_info.GetScriptedProcessClassName());
2954*5f7ddb14SDimitry Andric default_launch_info.SetScriptedProcessDictionarySP(
2955*5f7ddb14SDimitry Andric launch_info.GetScriptedProcessDictionarySP());
2956*5f7ddb14SDimitry Andric
2957*5f7ddb14SDimitry Andric SetProcessLaunchInfo(launch_info);
2958*5f7ddb14SDimitry Andric }
2959*5f7ddb14SDimitry Andric
29600b57cec5SDimitry Andric // Get the value of synchronous execution here. If you wait till after you
29610b57cec5SDimitry Andric // have started to run, then you could have hit a breakpoint, whose command
29620b57cec5SDimitry Andric // might switch the value, and then you'll pick up that incorrect value.
29630b57cec5SDimitry Andric Debugger &debugger = GetDebugger();
29640b57cec5SDimitry Andric const bool synchronous_execution =
29650b57cec5SDimitry Andric debugger.GetCommandInterpreter().GetSynchronous();
29660b57cec5SDimitry Andric
29670b57cec5SDimitry Andric PlatformSP platform_sp(GetPlatform());
29680b57cec5SDimitry Andric
29690b57cec5SDimitry Andric FinalizeFileActions(launch_info);
29700b57cec5SDimitry Andric
29710b57cec5SDimitry Andric if (state == eStateConnected) {
29720b57cec5SDimitry Andric if (launch_info.GetFlags().Test(eLaunchFlagLaunchInTTY)) {
29730b57cec5SDimitry Andric error.SetErrorString(
29740b57cec5SDimitry Andric "can't launch in tty when launching through a remote connection");
29750b57cec5SDimitry Andric return error;
29760b57cec5SDimitry Andric }
29770b57cec5SDimitry Andric }
29780b57cec5SDimitry Andric
29790b57cec5SDimitry Andric if (!launch_info.GetArchitecture().IsValid())
29800b57cec5SDimitry Andric launch_info.GetArchitecture() = GetArchitecture();
29810b57cec5SDimitry Andric
29820b57cec5SDimitry Andric // If we're not already connected to the process, and if we have a platform
29830b57cec5SDimitry Andric // that can launch a process for debugging, go ahead and do that here.
29840b57cec5SDimitry Andric if (state != eStateConnected && platform_sp &&
2985*5f7ddb14SDimitry Andric platform_sp->CanDebugProcess() && !launch_info.IsScriptedProcess()) {
29869dba64beSDimitry Andric LLDB_LOGF(log, "Target::%s asking the platform to debug the process",
29870b57cec5SDimitry Andric __FUNCTION__);
29880b57cec5SDimitry Andric
29890b57cec5SDimitry Andric // If there was a previous process, delete it before we make the new one.
29900b57cec5SDimitry Andric // One subtle point, we delete the process before we release the reference
29910b57cec5SDimitry Andric // to m_process_sp. That way even if we are the last owner, the process
29920b57cec5SDimitry Andric // will get Finalized before it gets destroyed.
29930b57cec5SDimitry Andric DeleteCurrentProcess();
29940b57cec5SDimitry Andric
29950b57cec5SDimitry Andric m_process_sp =
29960b57cec5SDimitry Andric GetPlatform()->DebugProcess(launch_info, debugger, this, error);
29970b57cec5SDimitry Andric
29980b57cec5SDimitry Andric } else {
29999dba64beSDimitry Andric LLDB_LOGF(log,
30009dba64beSDimitry Andric "Target::%s the platform doesn't know how to debug a "
30010b57cec5SDimitry Andric "process, getting a process plugin to do this for us.",
30020b57cec5SDimitry Andric __FUNCTION__);
30030b57cec5SDimitry Andric
30040b57cec5SDimitry Andric if (state == eStateConnected) {
30050b57cec5SDimitry Andric assert(m_process_sp);
30060b57cec5SDimitry Andric } else {
30070b57cec5SDimitry Andric // Use a Process plugin to construct the process.
30080b57cec5SDimitry Andric const char *plugin_name = launch_info.GetProcessPluginName();
3009af732203SDimitry Andric CreateProcess(launch_info.GetListener(), plugin_name, nullptr, false);
30100b57cec5SDimitry Andric }
30110b57cec5SDimitry Andric
30120b57cec5SDimitry Andric // Since we didn't have a platform launch the process, launch it here.
30130b57cec5SDimitry Andric if (m_process_sp)
30140b57cec5SDimitry Andric error = m_process_sp->Launch(launch_info);
30150b57cec5SDimitry Andric }
30160b57cec5SDimitry Andric
3017af732203SDimitry Andric if (!m_process_sp && error.Success())
30180b57cec5SDimitry Andric error.SetErrorString("failed to launch or debug process");
30190b57cec5SDimitry Andric
3020af732203SDimitry Andric if (!error.Success())
3021af732203SDimitry Andric return error;
3022af732203SDimitry Andric
3023af732203SDimitry Andric auto at_exit =
3024af732203SDimitry Andric llvm::make_scope_exit([&]() { m_process_sp->RestoreProcessEvents(); });
3025af732203SDimitry Andric
3026af732203SDimitry Andric if (!synchronous_execution &&
3027af732203SDimitry Andric launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
3028af732203SDimitry Andric return error;
3029af732203SDimitry Andric
30300b57cec5SDimitry Andric ListenerSP hijack_listener_sp(launch_info.GetHijackListener());
30310b57cec5SDimitry Andric if (!hijack_listener_sp) {
3032af732203SDimitry Andric hijack_listener_sp = Listener::MakeListener("lldb.Target.Launch.hijack");
30330b57cec5SDimitry Andric launch_info.SetHijackListener(hijack_listener_sp);
30340b57cec5SDimitry Andric m_process_sp->HijackProcessEvents(hijack_listener_sp);
30350b57cec5SDimitry Andric }
30360b57cec5SDimitry Andric
3037af732203SDimitry Andric switch (m_process_sp->WaitForProcessToStop(llvm::None, nullptr, false,
3038af732203SDimitry Andric hijack_listener_sp, nullptr)) {
3039af732203SDimitry Andric case eStateStopped: {
3040af732203SDimitry Andric if (launch_info.GetFlags().Test(eLaunchFlagStopAtEntry))
3041af732203SDimitry Andric break;
30420b57cec5SDimitry Andric if (synchronous_execution) {
30439dba64beSDimitry Andric // Now we have handled the stop-from-attach, and we are just
30449dba64beSDimitry Andric // switching to a synchronous resume. So we should switch to the
30459dba64beSDimitry Andric // SyncResume hijacker.
30460b57cec5SDimitry Andric m_process_sp->RestoreProcessEvents();
30470b57cec5SDimitry Andric m_process_sp->ResumeSynchronous(stream);
30480b57cec5SDimitry Andric } else {
30490b57cec5SDimitry Andric m_process_sp->RestoreProcessEvents();
30500b57cec5SDimitry Andric error = m_process_sp->PrivateResume();
30510b57cec5SDimitry Andric }
30520b57cec5SDimitry Andric if (!error.Success()) {
30530b57cec5SDimitry Andric Status error2;
30540b57cec5SDimitry Andric error2.SetErrorStringWithFormat(
30550b57cec5SDimitry Andric "process resume at entry point failed: %s", error.AsCString());
30560b57cec5SDimitry Andric error = error2;
30570b57cec5SDimitry Andric }
3058af732203SDimitry Andric } break;
3059af732203SDimitry Andric case eStateExited: {
30600b57cec5SDimitry Andric bool with_shell = !!launch_info.GetShell();
30610b57cec5SDimitry Andric const int exit_status = m_process_sp->GetExitStatus();
30620b57cec5SDimitry Andric const char *exit_desc = m_process_sp->GetExitDescription();
3063af732203SDimitry Andric std::string desc;
3064af732203SDimitry Andric if (exit_desc && exit_desc[0])
3065af732203SDimitry Andric desc = " (" + std::string(exit_desc) + ')';
30660b57cec5SDimitry Andric if (with_shell)
30670b57cec5SDimitry Andric error.SetErrorStringWithFormat(
3068af732203SDimitry Andric "process exited with status %i%s\n"
3069af732203SDimitry Andric "'r' and 'run' are aliases that default to launching through a "
3070af732203SDimitry Andric "shell.\n"
3071af732203SDimitry Andric "Try launching without going through a shell by using "
3072af732203SDimitry Andric "'process launch'.",
3073af732203SDimitry Andric exit_status, desc.c_str());
30740b57cec5SDimitry Andric else
3075af732203SDimitry Andric error.SetErrorStringWithFormat("process exited with status %i%s",
3076af732203SDimitry Andric exit_status, desc.c_str());
3077af732203SDimitry Andric } break;
3078af732203SDimitry Andric default:
3079af732203SDimitry Andric error.SetErrorStringWithFormat("initial process state wasn't stopped: %s",
3080af732203SDimitry Andric StateAsCString(state));
3081af732203SDimitry Andric break;
30820b57cec5SDimitry Andric }
30830b57cec5SDimitry Andric return error;
30840b57cec5SDimitry Andric }
30850b57cec5SDimitry Andric
SetTrace(const TraceSP & trace_sp)3086af732203SDimitry Andric void Target::SetTrace(const TraceSP &trace_sp) { m_trace_sp = trace_sp; }
3087af732203SDimitry Andric
GetTrace()3088*5f7ddb14SDimitry Andric TraceSP Target::GetTrace() { return m_trace_sp; }
3089*5f7ddb14SDimitry Andric
CreateTrace()3090*5f7ddb14SDimitry Andric llvm::Expected<TraceSP> Target::CreateTrace() {
3091*5f7ddb14SDimitry Andric if (!m_process_sp)
3092*5f7ddb14SDimitry Andric return llvm::createStringError(llvm::inconvertibleErrorCode(),
3093*5f7ddb14SDimitry Andric "A process is required for tracing");
3094*5f7ddb14SDimitry Andric if (m_trace_sp)
3095*5f7ddb14SDimitry Andric return llvm::createStringError(llvm::inconvertibleErrorCode(),
3096*5f7ddb14SDimitry Andric "A trace already exists for the target");
3097*5f7ddb14SDimitry Andric
3098*5f7ddb14SDimitry Andric llvm::Expected<TraceSupportedResponse> trace_type =
3099*5f7ddb14SDimitry Andric m_process_sp->TraceSupported();
3100*5f7ddb14SDimitry Andric if (!trace_type)
3101*5f7ddb14SDimitry Andric return llvm::createStringError(
3102*5f7ddb14SDimitry Andric llvm::inconvertibleErrorCode(), "Tracing is not supported. %s",
3103*5f7ddb14SDimitry Andric llvm::toString(trace_type.takeError()).c_str());
3104*5f7ddb14SDimitry Andric if (llvm::Expected<TraceSP> trace_sp =
3105*5f7ddb14SDimitry Andric Trace::FindPluginForLiveProcess(trace_type->name, *m_process_sp))
3106*5f7ddb14SDimitry Andric m_trace_sp = *trace_sp;
3107*5f7ddb14SDimitry Andric else
3108*5f7ddb14SDimitry Andric return llvm::createStringError(
3109*5f7ddb14SDimitry Andric llvm::inconvertibleErrorCode(),
3110*5f7ddb14SDimitry Andric "Couldn't create a Trace object for the process. %s",
3111*5f7ddb14SDimitry Andric llvm::toString(trace_sp.takeError()).c_str());
3112*5f7ddb14SDimitry Andric return m_trace_sp;
3113*5f7ddb14SDimitry Andric }
3114*5f7ddb14SDimitry Andric
GetTraceOrCreate()3115*5f7ddb14SDimitry Andric llvm::Expected<TraceSP> Target::GetTraceOrCreate() {
3116*5f7ddb14SDimitry Andric if (m_trace_sp)
3117*5f7ddb14SDimitry Andric return m_trace_sp;
3118*5f7ddb14SDimitry Andric return CreateTrace();
3119*5f7ddb14SDimitry Andric }
3120af732203SDimitry Andric
Attach(ProcessAttachInfo & attach_info,Stream * stream)31210b57cec5SDimitry Andric Status Target::Attach(ProcessAttachInfo &attach_info, Stream *stream) {
31220b57cec5SDimitry Andric auto state = eStateInvalid;
31230b57cec5SDimitry Andric auto process_sp = GetProcessSP();
31240b57cec5SDimitry Andric if (process_sp) {
31250b57cec5SDimitry Andric state = process_sp->GetState();
31260b57cec5SDimitry Andric if (process_sp->IsAlive() && state != eStateConnected) {
31270b57cec5SDimitry Andric if (state == eStateAttaching)
31280b57cec5SDimitry Andric return Status("process attach is in progress");
31290b57cec5SDimitry Andric return Status("a process is already being debugged");
31300b57cec5SDimitry Andric }
31310b57cec5SDimitry Andric }
31320b57cec5SDimitry Andric
31330b57cec5SDimitry Andric const ModuleSP old_exec_module_sp = GetExecutableModule();
31340b57cec5SDimitry Andric
31350b57cec5SDimitry Andric // If no process info was specified, then use the target executable name as
31360b57cec5SDimitry Andric // the process to attach to by default
31370b57cec5SDimitry Andric if (!attach_info.ProcessInfoSpecified()) {
31380b57cec5SDimitry Andric if (old_exec_module_sp)
31390b57cec5SDimitry Andric attach_info.GetExecutableFile().GetFilename() =
31400b57cec5SDimitry Andric old_exec_module_sp->GetPlatformFileSpec().GetFilename();
31410b57cec5SDimitry Andric
31420b57cec5SDimitry Andric if (!attach_info.ProcessInfoSpecified()) {
31430b57cec5SDimitry Andric return Status("no process specified, create a target with a file, or "
31440b57cec5SDimitry Andric "specify the --pid or --name");
31450b57cec5SDimitry Andric }
31460b57cec5SDimitry Andric }
31470b57cec5SDimitry Andric
31480b57cec5SDimitry Andric const auto platform_sp =
31490b57cec5SDimitry Andric GetDebugger().GetPlatformList().GetSelectedPlatform();
31500b57cec5SDimitry Andric ListenerSP hijack_listener_sp;
31510b57cec5SDimitry Andric const bool async = attach_info.GetAsync();
31520b57cec5SDimitry Andric if (!async) {
31530b57cec5SDimitry Andric hijack_listener_sp =
31540b57cec5SDimitry Andric Listener::MakeListener("lldb.Target.Attach.attach.hijack");
31550b57cec5SDimitry Andric attach_info.SetHijackListener(hijack_listener_sp);
31560b57cec5SDimitry Andric }
31570b57cec5SDimitry Andric
31580b57cec5SDimitry Andric Status error;
31590b57cec5SDimitry Andric if (state != eStateConnected && platform_sp != nullptr &&
31600b57cec5SDimitry Andric platform_sp->CanDebugProcess()) {
31610b57cec5SDimitry Andric SetPlatform(platform_sp);
31620b57cec5SDimitry Andric process_sp = platform_sp->Attach(attach_info, GetDebugger(), this, error);
31630b57cec5SDimitry Andric } else {
31640b57cec5SDimitry Andric if (state != eStateConnected) {
31650b57cec5SDimitry Andric const char *plugin_name = attach_info.GetProcessPluginName();
31660b57cec5SDimitry Andric process_sp =
31670b57cec5SDimitry Andric CreateProcess(attach_info.GetListenerForProcess(GetDebugger()),
3168af732203SDimitry Andric plugin_name, nullptr, false);
31690b57cec5SDimitry Andric if (process_sp == nullptr) {
31700b57cec5SDimitry Andric error.SetErrorStringWithFormat(
31710b57cec5SDimitry Andric "failed to create process using plugin %s",
31720b57cec5SDimitry Andric (plugin_name) ? plugin_name : "null");
31730b57cec5SDimitry Andric return error;
31740b57cec5SDimitry Andric }
31750b57cec5SDimitry Andric }
31760b57cec5SDimitry Andric if (hijack_listener_sp)
31770b57cec5SDimitry Andric process_sp->HijackProcessEvents(hijack_listener_sp);
31780b57cec5SDimitry Andric error = process_sp->Attach(attach_info);
31790b57cec5SDimitry Andric }
31800b57cec5SDimitry Andric
31810b57cec5SDimitry Andric if (error.Success() && process_sp) {
31820b57cec5SDimitry Andric if (async) {
31830b57cec5SDimitry Andric process_sp->RestoreProcessEvents();
31840b57cec5SDimitry Andric } else {
31850b57cec5SDimitry Andric state = process_sp->WaitForProcessToStop(
31860b57cec5SDimitry Andric llvm::None, nullptr, false, attach_info.GetHijackListener(), stream);
31870b57cec5SDimitry Andric process_sp->RestoreProcessEvents();
31880b57cec5SDimitry Andric
31890b57cec5SDimitry Andric if (state != eStateStopped) {
31900b57cec5SDimitry Andric const char *exit_desc = process_sp->GetExitDescription();
31910b57cec5SDimitry Andric if (exit_desc)
31920b57cec5SDimitry Andric error.SetErrorStringWithFormat("%s", exit_desc);
31930b57cec5SDimitry Andric else
31940b57cec5SDimitry Andric error.SetErrorString(
31950b57cec5SDimitry Andric "process did not stop (no such process or permission problem?)");
31960b57cec5SDimitry Andric process_sp->Destroy(false);
31970b57cec5SDimitry Andric }
31980b57cec5SDimitry Andric }
31990b57cec5SDimitry Andric }
32000b57cec5SDimitry Andric return error;
32010b57cec5SDimitry Andric }
32020b57cec5SDimitry Andric
FinalizeFileActions(ProcessLaunchInfo & info)32030b57cec5SDimitry Andric void Target::FinalizeFileActions(ProcessLaunchInfo &info) {
32040b57cec5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS));
32050b57cec5SDimitry Andric
32060b57cec5SDimitry Andric // Finalize the file actions, and if none were given, default to opening up a
32070b57cec5SDimitry Andric // pseudo terminal
32080b57cec5SDimitry Andric PlatformSP platform_sp = GetPlatform();
32090b57cec5SDimitry Andric const bool default_to_use_pty =
32100b57cec5SDimitry Andric m_platform_sp ? m_platform_sp->IsHost() : false;
32110b57cec5SDimitry Andric LLDB_LOG(
32120b57cec5SDimitry Andric log,
32130b57cec5SDimitry Andric "have platform={0}, platform_sp->IsHost()={1}, default_to_use_pty={2}",
32140b57cec5SDimitry Andric bool(platform_sp),
32150b57cec5SDimitry Andric platform_sp ? (platform_sp->IsHost() ? "true" : "false") : "n/a",
32160b57cec5SDimitry Andric default_to_use_pty);
32170b57cec5SDimitry Andric
32180b57cec5SDimitry Andric // If nothing for stdin or stdout or stderr was specified, then check the
32190b57cec5SDimitry Andric // process for any default settings that were set with "settings set"
32200b57cec5SDimitry Andric if (info.GetFileActionForFD(STDIN_FILENO) == nullptr ||
32210b57cec5SDimitry Andric info.GetFileActionForFD(STDOUT_FILENO) == nullptr ||
32220b57cec5SDimitry Andric info.GetFileActionForFD(STDERR_FILENO) == nullptr) {
32230b57cec5SDimitry Andric LLDB_LOG(log, "at least one of stdin/stdout/stderr was not set, evaluating "
32240b57cec5SDimitry Andric "default handling");
32250b57cec5SDimitry Andric
32260b57cec5SDimitry Andric if (info.GetFlags().Test(eLaunchFlagLaunchInTTY)) {
32270b57cec5SDimitry Andric // Do nothing, if we are launching in a remote terminal no file actions
32280b57cec5SDimitry Andric // should be done at all.
32290b57cec5SDimitry Andric return;
32300b57cec5SDimitry Andric }
32310b57cec5SDimitry Andric
32320b57cec5SDimitry Andric if (info.GetFlags().Test(eLaunchFlagDisableSTDIO)) {
32330b57cec5SDimitry Andric LLDB_LOG(log, "eLaunchFlagDisableSTDIO set, adding suppression action "
32340b57cec5SDimitry Andric "for stdin, stdout and stderr");
32350b57cec5SDimitry Andric info.AppendSuppressFileAction(STDIN_FILENO, true, false);
32360b57cec5SDimitry Andric info.AppendSuppressFileAction(STDOUT_FILENO, false, true);
32370b57cec5SDimitry Andric info.AppendSuppressFileAction(STDERR_FILENO, false, true);
32380b57cec5SDimitry Andric } else {
32390b57cec5SDimitry Andric // Check for any values that might have gotten set with any of: (lldb)
32400b57cec5SDimitry Andric // settings set target.input-path (lldb) settings set target.output-path
32410b57cec5SDimitry Andric // (lldb) settings set target.error-path
32420b57cec5SDimitry Andric FileSpec in_file_spec;
32430b57cec5SDimitry Andric FileSpec out_file_spec;
32440b57cec5SDimitry Andric FileSpec err_file_spec;
32450b57cec5SDimitry Andric // Only override with the target settings if we don't already have an
32460b57cec5SDimitry Andric // action for in, out or error
32470b57cec5SDimitry Andric if (info.GetFileActionForFD(STDIN_FILENO) == nullptr)
32480b57cec5SDimitry Andric in_file_spec = GetStandardInputPath();
32490b57cec5SDimitry Andric if (info.GetFileActionForFD(STDOUT_FILENO) == nullptr)
32500b57cec5SDimitry Andric out_file_spec = GetStandardOutputPath();
32510b57cec5SDimitry Andric if (info.GetFileActionForFD(STDERR_FILENO) == nullptr)
32520b57cec5SDimitry Andric err_file_spec = GetStandardErrorPath();
32530b57cec5SDimitry Andric
32540b57cec5SDimitry Andric LLDB_LOG(log, "target stdin='{0}', target stdout='{1}', stderr='{1}'",
32550b57cec5SDimitry Andric in_file_spec, out_file_spec, err_file_spec);
32560b57cec5SDimitry Andric
32570b57cec5SDimitry Andric if (in_file_spec) {
32580b57cec5SDimitry Andric info.AppendOpenFileAction(STDIN_FILENO, in_file_spec, true, false);
32590b57cec5SDimitry Andric LLDB_LOG(log, "appended stdin open file action for {0}", in_file_spec);
32600b57cec5SDimitry Andric }
32610b57cec5SDimitry Andric
32620b57cec5SDimitry Andric if (out_file_spec) {
32630b57cec5SDimitry Andric info.AppendOpenFileAction(STDOUT_FILENO, out_file_spec, false, true);
32640b57cec5SDimitry Andric LLDB_LOG(log, "appended stdout open file action for {0}",
32650b57cec5SDimitry Andric out_file_spec);
32660b57cec5SDimitry Andric }
32670b57cec5SDimitry Andric
32680b57cec5SDimitry Andric if (err_file_spec) {
32690b57cec5SDimitry Andric info.AppendOpenFileAction(STDERR_FILENO, err_file_spec, false, true);
32700b57cec5SDimitry Andric LLDB_LOG(log, "appended stderr open file action for {0}",
32710b57cec5SDimitry Andric err_file_spec);
32720b57cec5SDimitry Andric }
32730b57cec5SDimitry Andric
32740b57cec5SDimitry Andric if (default_to_use_pty &&
32750b57cec5SDimitry Andric (!in_file_spec || !out_file_spec || !err_file_spec)) {
32760b57cec5SDimitry Andric llvm::Error Err = info.SetUpPtyRedirection();
32770b57cec5SDimitry Andric LLDB_LOG_ERROR(log, std::move(Err), "SetUpPtyRedirection failed: {0}");
32780b57cec5SDimitry Andric }
32790b57cec5SDimitry Andric }
32800b57cec5SDimitry Andric }
32810b57cec5SDimitry Andric }
32820b57cec5SDimitry Andric
32830b57cec5SDimitry Andric // Target::StopHook
StopHook(lldb::TargetSP target_sp,lldb::user_id_t uid)32840b57cec5SDimitry Andric Target::StopHook::StopHook(lldb::TargetSP target_sp, lldb::user_id_t uid)
3285af732203SDimitry Andric : UserID(uid), m_target_sp(target_sp), m_specifier_sp(),
32860b57cec5SDimitry Andric m_thread_spec_up() {}
32870b57cec5SDimitry Andric
StopHook(const StopHook & rhs)32880b57cec5SDimitry Andric Target::StopHook::StopHook(const StopHook &rhs)
32890b57cec5SDimitry Andric : UserID(rhs.GetID()), m_target_sp(rhs.m_target_sp),
3290af732203SDimitry Andric m_specifier_sp(rhs.m_specifier_sp), m_thread_spec_up(),
3291af732203SDimitry Andric m_active(rhs.m_active), m_auto_continue(rhs.m_auto_continue) {
32920b57cec5SDimitry Andric if (rhs.m_thread_spec_up)
32935ffd83dbSDimitry Andric m_thread_spec_up = std::make_unique<ThreadSpec>(*rhs.m_thread_spec_up);
32940b57cec5SDimitry Andric }
32950b57cec5SDimitry Andric
SetSpecifier(SymbolContextSpecifier * specifier)32960b57cec5SDimitry Andric void Target::StopHook::SetSpecifier(SymbolContextSpecifier *specifier) {
32970b57cec5SDimitry Andric m_specifier_sp.reset(specifier);
32980b57cec5SDimitry Andric }
32990b57cec5SDimitry Andric
SetThreadSpecifier(ThreadSpec * specifier)33000b57cec5SDimitry Andric void Target::StopHook::SetThreadSpecifier(ThreadSpec *specifier) {
33010b57cec5SDimitry Andric m_thread_spec_up.reset(specifier);
33020b57cec5SDimitry Andric }
33030b57cec5SDimitry Andric
ExecutionContextPasses(const ExecutionContext & exc_ctx)3304af732203SDimitry Andric bool Target::StopHook::ExecutionContextPasses(const ExecutionContext &exc_ctx) {
3305af732203SDimitry Andric SymbolContextSpecifier *specifier = GetSpecifier();
3306af732203SDimitry Andric if (!specifier)
3307af732203SDimitry Andric return true;
3308af732203SDimitry Andric
3309af732203SDimitry Andric bool will_run = true;
3310af732203SDimitry Andric if (exc_ctx.GetFramePtr())
3311af732203SDimitry Andric will_run = GetSpecifier()->SymbolContextMatches(
3312af732203SDimitry Andric exc_ctx.GetFramePtr()->GetSymbolContext(eSymbolContextEverything));
3313af732203SDimitry Andric if (will_run && GetThreadSpecifier() != nullptr)
3314af732203SDimitry Andric will_run =
3315af732203SDimitry Andric GetThreadSpecifier()->ThreadPassesBasicTests(exc_ctx.GetThreadRef());
3316af732203SDimitry Andric
3317af732203SDimitry Andric return will_run;
3318af732203SDimitry Andric }
3319af732203SDimitry Andric
GetDescription(Stream * s,lldb::DescriptionLevel level) const33200b57cec5SDimitry Andric void Target::StopHook::GetDescription(Stream *s,
33210b57cec5SDimitry Andric lldb::DescriptionLevel level) const {
3322af732203SDimitry Andric
3323af732203SDimitry Andric // For brief descriptions, only print the subclass description:
3324af732203SDimitry Andric if (level == eDescriptionLevelBrief) {
3325af732203SDimitry Andric GetSubclassDescription(s, level);
3326af732203SDimitry Andric return;
3327af732203SDimitry Andric }
3328af732203SDimitry Andric
3329480093f4SDimitry Andric unsigned indent_level = s->GetIndentLevel();
33300b57cec5SDimitry Andric
33310b57cec5SDimitry Andric s->SetIndentLevel(indent_level + 2);
33320b57cec5SDimitry Andric
33330b57cec5SDimitry Andric s->Printf("Hook: %" PRIu64 "\n", GetID());
33340b57cec5SDimitry Andric if (m_active)
33350b57cec5SDimitry Andric s->Indent("State: enabled\n");
33360b57cec5SDimitry Andric else
33370b57cec5SDimitry Andric s->Indent("State: disabled\n");
33380b57cec5SDimitry Andric
33390b57cec5SDimitry Andric if (m_auto_continue)
33400b57cec5SDimitry Andric s->Indent("AutoContinue on\n");
33410b57cec5SDimitry Andric
33420b57cec5SDimitry Andric if (m_specifier_sp) {
33430b57cec5SDimitry Andric s->Indent();
33440b57cec5SDimitry Andric s->PutCString("Specifier:\n");
33450b57cec5SDimitry Andric s->SetIndentLevel(indent_level + 4);
33460b57cec5SDimitry Andric m_specifier_sp->GetDescription(s, level);
33470b57cec5SDimitry Andric s->SetIndentLevel(indent_level + 2);
33480b57cec5SDimitry Andric }
33490b57cec5SDimitry Andric
33500b57cec5SDimitry Andric if (m_thread_spec_up) {
33510b57cec5SDimitry Andric StreamString tmp;
33520b57cec5SDimitry Andric s->Indent("Thread:\n");
33530b57cec5SDimitry Andric m_thread_spec_up->GetDescription(&tmp, level);
33540b57cec5SDimitry Andric s->SetIndentLevel(indent_level + 4);
33550b57cec5SDimitry Andric s->Indent(tmp.GetString());
33560b57cec5SDimitry Andric s->PutCString("\n");
33570b57cec5SDimitry Andric s->SetIndentLevel(indent_level + 2);
33580b57cec5SDimitry Andric }
3359af732203SDimitry Andric GetSubclassDescription(s, level);
3360af732203SDimitry Andric }
33610b57cec5SDimitry Andric
GetSubclassDescription(Stream * s,lldb::DescriptionLevel level) const3362af732203SDimitry Andric void Target::StopHookCommandLine::GetSubclassDescription(
3363af732203SDimitry Andric Stream *s, lldb::DescriptionLevel level) const {
3364af732203SDimitry Andric // The brief description just prints the first command.
3365af732203SDimitry Andric if (level == eDescriptionLevelBrief) {
3366af732203SDimitry Andric if (m_commands.GetSize() == 1)
3367af732203SDimitry Andric s->PutCString(m_commands.GetStringAtIndex(0));
3368af732203SDimitry Andric return;
3369af732203SDimitry Andric }
33700b57cec5SDimitry Andric s->Indent("Commands: \n");
3371af732203SDimitry Andric s->SetIndentLevel(s->GetIndentLevel() + 4);
33720b57cec5SDimitry Andric uint32_t num_commands = m_commands.GetSize();
33730b57cec5SDimitry Andric for (uint32_t i = 0; i < num_commands; i++) {
33740b57cec5SDimitry Andric s->Indent(m_commands.GetStringAtIndex(i));
33750b57cec5SDimitry Andric s->PutCString("\n");
33760b57cec5SDimitry Andric }
3377af732203SDimitry Andric s->SetIndentLevel(s->GetIndentLevel() - 4);
3378af732203SDimitry Andric }
3379af732203SDimitry Andric
3380af732203SDimitry Andric // Target::StopHookCommandLine
SetActionFromString(const std::string & string)3381af732203SDimitry Andric void Target::StopHookCommandLine::SetActionFromString(const std::string &string) {
3382af732203SDimitry Andric GetCommands().SplitIntoLines(string);
3383af732203SDimitry Andric }
3384af732203SDimitry Andric
SetActionFromStrings(const std::vector<std::string> & strings)3385af732203SDimitry Andric void Target::StopHookCommandLine::SetActionFromStrings(
3386af732203SDimitry Andric const std::vector<std::string> &strings) {
3387af732203SDimitry Andric for (auto string : strings)
3388af732203SDimitry Andric GetCommands().AppendString(string.c_str());
3389af732203SDimitry Andric }
3390af732203SDimitry Andric
3391af732203SDimitry Andric Target::StopHook::StopHookResult
HandleStop(ExecutionContext & exc_ctx,StreamSP output_sp)3392af732203SDimitry Andric Target::StopHookCommandLine::HandleStop(ExecutionContext &exc_ctx,
3393af732203SDimitry Andric StreamSP output_sp) {
3394af732203SDimitry Andric assert(exc_ctx.GetTargetPtr() && "Can't call PerformAction on a context "
3395af732203SDimitry Andric "with no target");
3396af732203SDimitry Andric
3397af732203SDimitry Andric if (!m_commands.GetSize())
3398af732203SDimitry Andric return StopHookResult::KeepStopped;
3399af732203SDimitry Andric
3400af732203SDimitry Andric CommandReturnObject result(false);
3401af732203SDimitry Andric result.SetImmediateOutputStream(output_sp);
3402af732203SDimitry Andric result.SetInteractive(false);
3403af732203SDimitry Andric Debugger &debugger = exc_ctx.GetTargetPtr()->GetDebugger();
3404af732203SDimitry Andric CommandInterpreterRunOptions options;
3405af732203SDimitry Andric options.SetStopOnContinue(true);
3406af732203SDimitry Andric options.SetStopOnError(true);
3407af732203SDimitry Andric options.SetEchoCommands(false);
3408af732203SDimitry Andric options.SetPrintResults(true);
3409af732203SDimitry Andric options.SetPrintErrors(true);
3410af732203SDimitry Andric options.SetAddToHistory(false);
3411af732203SDimitry Andric
3412af732203SDimitry Andric // Force Async:
3413af732203SDimitry Andric bool old_async = debugger.GetAsyncExecution();
3414af732203SDimitry Andric debugger.SetAsyncExecution(true);
3415*5f7ddb14SDimitry Andric debugger.GetCommandInterpreter().HandleCommands(GetCommands(), exc_ctx,
3416af732203SDimitry Andric options, result);
3417af732203SDimitry Andric debugger.SetAsyncExecution(old_async);
3418af732203SDimitry Andric lldb::ReturnStatus status = result.GetStatus();
3419af732203SDimitry Andric if (status == eReturnStatusSuccessContinuingNoResult ||
3420af732203SDimitry Andric status == eReturnStatusSuccessContinuingResult)
3421af732203SDimitry Andric return StopHookResult::AlreadyContinued;
3422af732203SDimitry Andric return StopHookResult::KeepStopped;
3423af732203SDimitry Andric }
3424af732203SDimitry Andric
3425af732203SDimitry Andric // Target::StopHookScripted
SetScriptCallback(std::string class_name,StructuredData::ObjectSP extra_args_sp)3426af732203SDimitry Andric Status Target::StopHookScripted::SetScriptCallback(
3427af732203SDimitry Andric std::string class_name, StructuredData::ObjectSP extra_args_sp) {
3428af732203SDimitry Andric Status error;
3429af732203SDimitry Andric
3430af732203SDimitry Andric ScriptInterpreter *script_interp =
3431af732203SDimitry Andric GetTarget()->GetDebugger().GetScriptInterpreter();
3432af732203SDimitry Andric if (!script_interp) {
3433af732203SDimitry Andric error.SetErrorString("No script interpreter installed.");
3434af732203SDimitry Andric return error;
3435af732203SDimitry Andric }
3436af732203SDimitry Andric
3437af732203SDimitry Andric m_class_name = class_name;
3438af732203SDimitry Andric
3439af732203SDimitry Andric m_extra_args = new StructuredDataImpl();
3440af732203SDimitry Andric
3441af732203SDimitry Andric if (extra_args_sp)
3442af732203SDimitry Andric m_extra_args->SetObjectSP(extra_args_sp);
3443af732203SDimitry Andric
3444af732203SDimitry Andric m_implementation_sp = script_interp->CreateScriptedStopHook(
3445af732203SDimitry Andric GetTarget(), m_class_name.c_str(), m_extra_args, error);
3446af732203SDimitry Andric
3447af732203SDimitry Andric return error;
3448af732203SDimitry Andric }
3449af732203SDimitry Andric
3450af732203SDimitry Andric Target::StopHook::StopHookResult
HandleStop(ExecutionContext & exc_ctx,StreamSP output_sp)3451af732203SDimitry Andric Target::StopHookScripted::HandleStop(ExecutionContext &exc_ctx,
3452af732203SDimitry Andric StreamSP output_sp) {
3453af732203SDimitry Andric assert(exc_ctx.GetTargetPtr() && "Can't call HandleStop on a context "
3454af732203SDimitry Andric "with no target");
3455af732203SDimitry Andric
3456af732203SDimitry Andric ScriptInterpreter *script_interp =
3457af732203SDimitry Andric GetTarget()->GetDebugger().GetScriptInterpreter();
3458af732203SDimitry Andric if (!script_interp)
3459af732203SDimitry Andric return StopHookResult::KeepStopped;
3460af732203SDimitry Andric
3461af732203SDimitry Andric bool should_stop = script_interp->ScriptedStopHookHandleStop(
3462af732203SDimitry Andric m_implementation_sp, exc_ctx, output_sp);
3463af732203SDimitry Andric
3464af732203SDimitry Andric return should_stop ? StopHookResult::KeepStopped
3465af732203SDimitry Andric : StopHookResult::RequestContinue;
3466af732203SDimitry Andric }
3467af732203SDimitry Andric
GetSubclassDescription(Stream * s,lldb::DescriptionLevel level) const3468af732203SDimitry Andric void Target::StopHookScripted::GetSubclassDescription(
3469af732203SDimitry Andric Stream *s, lldb::DescriptionLevel level) const {
3470af732203SDimitry Andric if (level == eDescriptionLevelBrief) {
3471af732203SDimitry Andric s->PutCString(m_class_name);
3472af732203SDimitry Andric return;
3473af732203SDimitry Andric }
3474af732203SDimitry Andric s->Indent("Class:");
3475af732203SDimitry Andric s->Printf("%s\n", m_class_name.c_str());
3476af732203SDimitry Andric
3477af732203SDimitry Andric // Now print the extra args:
3478af732203SDimitry Andric // FIXME: We should use StructuredData.GetDescription on the m_extra_args
3479af732203SDimitry Andric // but that seems to rely on some printing plugin that doesn't exist.
3480af732203SDimitry Andric if (!m_extra_args->IsValid())
3481af732203SDimitry Andric return;
3482af732203SDimitry Andric StructuredData::ObjectSP object_sp = m_extra_args->GetObjectSP();
3483af732203SDimitry Andric if (!object_sp || !object_sp->IsValid())
3484af732203SDimitry Andric return;
3485af732203SDimitry Andric
3486af732203SDimitry Andric StructuredData::Dictionary *as_dict = object_sp->GetAsDictionary();
3487af732203SDimitry Andric if (!as_dict || !as_dict->IsValid())
3488af732203SDimitry Andric return;
3489af732203SDimitry Andric
3490af732203SDimitry Andric uint32_t num_keys = as_dict->GetSize();
3491af732203SDimitry Andric if (num_keys == 0)
3492af732203SDimitry Andric return;
3493af732203SDimitry Andric
3494af732203SDimitry Andric s->Indent("Args:\n");
3495af732203SDimitry Andric s->SetIndentLevel(s->GetIndentLevel() + 4);
3496af732203SDimitry Andric
3497af732203SDimitry Andric auto print_one_element = [&s](ConstString key,
3498af732203SDimitry Andric StructuredData::Object *object) {
3499af732203SDimitry Andric s->Indent();
3500af732203SDimitry Andric s->Printf("%s : %s\n", key.GetCString(),
3501af732203SDimitry Andric object->GetStringValue().str().c_str());
3502af732203SDimitry Andric return true;
3503af732203SDimitry Andric };
3504af732203SDimitry Andric
3505af732203SDimitry Andric as_dict->ForEach(print_one_element);
3506af732203SDimitry Andric
3507af732203SDimitry Andric s->SetIndentLevel(s->GetIndentLevel() - 4);
35080b57cec5SDimitry Andric }
35090b57cec5SDimitry Andric
35100b57cec5SDimitry Andric static constexpr OptionEnumValueElement g_dynamic_value_types[] = {
35119dba64beSDimitry Andric {
35129dba64beSDimitry Andric eNoDynamicValues,
35139dba64beSDimitry Andric "no-dynamic-values",
35149dba64beSDimitry Andric "Don't calculate the dynamic type of values",
35159dba64beSDimitry Andric },
35169dba64beSDimitry Andric {
35179dba64beSDimitry Andric eDynamicCanRunTarget,
35189dba64beSDimitry Andric "run-target",
35199dba64beSDimitry Andric "Calculate the dynamic type of values "
35209dba64beSDimitry Andric "even if you have to run the target.",
35219dba64beSDimitry Andric },
35229dba64beSDimitry Andric {
35239dba64beSDimitry Andric eDynamicDontRunTarget,
35249dba64beSDimitry Andric "no-run-target",
35259dba64beSDimitry Andric "Calculate the dynamic type of values, but don't run the target.",
35269dba64beSDimitry Andric },
35279dba64beSDimitry Andric };
35280b57cec5SDimitry Andric
GetDynamicValueTypes()35290b57cec5SDimitry Andric OptionEnumValues lldb_private::GetDynamicValueTypes() {
35300b57cec5SDimitry Andric return OptionEnumValues(g_dynamic_value_types);
35310b57cec5SDimitry Andric }
35320b57cec5SDimitry Andric
35330b57cec5SDimitry Andric static constexpr OptionEnumValueElement g_inline_breakpoint_enums[] = {
35349dba64beSDimitry Andric {
35359dba64beSDimitry Andric eInlineBreakpointsNever,
35369dba64beSDimitry Andric "never",
35379dba64beSDimitry Andric "Never look for inline breakpoint locations (fastest). This setting "
35389dba64beSDimitry Andric "should only be used if you know that no inlining occurs in your"
35399dba64beSDimitry Andric "programs.",
35409dba64beSDimitry Andric },
35419dba64beSDimitry Andric {
35429dba64beSDimitry Andric eInlineBreakpointsHeaders,
35439dba64beSDimitry Andric "headers",
35449dba64beSDimitry Andric "Only check for inline breakpoint locations when setting breakpoints "
35459dba64beSDimitry Andric "in header files, but not when setting breakpoint in implementation "
35469dba64beSDimitry Andric "source files (default).",
35479dba64beSDimitry Andric },
35489dba64beSDimitry Andric {
35499dba64beSDimitry Andric eInlineBreakpointsAlways,
35509dba64beSDimitry Andric "always",
35519dba64beSDimitry Andric "Always look for inline breakpoint locations when setting file and "
35529dba64beSDimitry Andric "line breakpoints (slower but most accurate).",
35539dba64beSDimitry Andric },
35549dba64beSDimitry Andric };
35550b57cec5SDimitry Andric
35560b57cec5SDimitry Andric enum x86DisassemblyFlavor {
35570b57cec5SDimitry Andric eX86DisFlavorDefault,
35580b57cec5SDimitry Andric eX86DisFlavorIntel,
35590b57cec5SDimitry Andric eX86DisFlavorATT
35600b57cec5SDimitry Andric };
35610b57cec5SDimitry Andric
35620b57cec5SDimitry Andric static constexpr OptionEnumValueElement g_x86_dis_flavor_value_types[] = {
35639dba64beSDimitry Andric {
35649dba64beSDimitry Andric eX86DisFlavorDefault,
35659dba64beSDimitry Andric "default",
35669dba64beSDimitry Andric "Disassembler default (currently att).",
35679dba64beSDimitry Andric },
35689dba64beSDimitry Andric {
35699dba64beSDimitry Andric eX86DisFlavorIntel,
35709dba64beSDimitry Andric "intel",
35719dba64beSDimitry Andric "Intel disassembler flavor.",
35729dba64beSDimitry Andric },
35739dba64beSDimitry Andric {
35749dba64beSDimitry Andric eX86DisFlavorATT,
35759dba64beSDimitry Andric "att",
35769dba64beSDimitry Andric "AT&T disassembler flavor.",
35779dba64beSDimitry Andric },
35789dba64beSDimitry Andric };
35790b57cec5SDimitry Andric
3580af732203SDimitry Andric static constexpr OptionEnumValueElement g_import_std_module_value_types[] = {
3581af732203SDimitry Andric {
3582af732203SDimitry Andric eImportStdModuleFalse,
3583af732203SDimitry Andric "false",
3584af732203SDimitry Andric "Never import the 'std' C++ module in the expression parser.",
3585af732203SDimitry Andric },
3586af732203SDimitry Andric {
3587af732203SDimitry Andric eImportStdModuleFallback,
3588af732203SDimitry Andric "fallback",
3589af732203SDimitry Andric "Retry evaluating expressions with an imported 'std' C++ module if they"
3590af732203SDimitry Andric " failed to parse without the module. This allows evaluating more "
3591af732203SDimitry Andric "complex expressions involving C++ standard library types."
3592af732203SDimitry Andric },
3593af732203SDimitry Andric {
3594af732203SDimitry Andric eImportStdModuleTrue,
3595af732203SDimitry Andric "true",
3596af732203SDimitry Andric "Always import the 'std' C++ module. This allows evaluating more "
3597af732203SDimitry Andric "complex expressions involving C++ standard library types. This feature"
3598af732203SDimitry Andric " is experimental."
3599af732203SDimitry Andric },
3600af732203SDimitry Andric };
3601af732203SDimitry Andric
36020b57cec5SDimitry Andric static constexpr OptionEnumValueElement g_hex_immediate_style_values[] = {
36039dba64beSDimitry Andric {
36049dba64beSDimitry Andric Disassembler::eHexStyleC,
36059dba64beSDimitry Andric "c",
36069dba64beSDimitry Andric "C-style (0xffff).",
36079dba64beSDimitry Andric },
36089dba64beSDimitry Andric {
36099dba64beSDimitry Andric Disassembler::eHexStyleAsm,
36109dba64beSDimitry Andric "asm",
36119dba64beSDimitry Andric "Asm-style (0ffffh).",
36129dba64beSDimitry Andric },
36139dba64beSDimitry Andric };
36140b57cec5SDimitry Andric
36150b57cec5SDimitry Andric static constexpr OptionEnumValueElement g_load_script_from_sym_file_values[] = {
36169dba64beSDimitry Andric {
36179dba64beSDimitry Andric eLoadScriptFromSymFileTrue,
36189dba64beSDimitry Andric "true",
36199dba64beSDimitry Andric "Load debug scripts inside symbol files",
36209dba64beSDimitry Andric },
36219dba64beSDimitry Andric {
36229dba64beSDimitry Andric eLoadScriptFromSymFileFalse,
36239dba64beSDimitry Andric "false",
36249dba64beSDimitry Andric "Do not load debug scripts inside symbol files.",
36259dba64beSDimitry Andric },
36269dba64beSDimitry Andric {
36279dba64beSDimitry Andric eLoadScriptFromSymFileWarn,
36289dba64beSDimitry Andric "warn",
36299dba64beSDimitry Andric "Warn about debug scripts inside symbol files but do not load them.",
36309dba64beSDimitry Andric },
36319dba64beSDimitry Andric };
36320b57cec5SDimitry Andric
36339dba64beSDimitry Andric static constexpr OptionEnumValueElement g_load_cwd_lldbinit_values[] = {
36349dba64beSDimitry Andric {
36359dba64beSDimitry Andric eLoadCWDlldbinitTrue,
36369dba64beSDimitry Andric "true",
36379dba64beSDimitry Andric "Load .lldbinit files from current directory",
36389dba64beSDimitry Andric },
36399dba64beSDimitry Andric {
36409dba64beSDimitry Andric eLoadCWDlldbinitFalse,
36419dba64beSDimitry Andric "false",
36429dba64beSDimitry Andric "Do not load .lldbinit files from current directory",
36439dba64beSDimitry Andric },
36449dba64beSDimitry Andric {
36459dba64beSDimitry Andric eLoadCWDlldbinitWarn,
36469dba64beSDimitry Andric "warn",
36479dba64beSDimitry Andric "Warn about loading .lldbinit files from current directory",
36489dba64beSDimitry Andric },
36499dba64beSDimitry Andric };
36500b57cec5SDimitry Andric
36510b57cec5SDimitry Andric static constexpr OptionEnumValueElement g_memory_module_load_level_values[] = {
36529dba64beSDimitry Andric {
36539dba64beSDimitry Andric eMemoryModuleLoadLevelMinimal,
36549dba64beSDimitry Andric "minimal",
36550b57cec5SDimitry Andric "Load minimal information when loading modules from memory. Currently "
36569dba64beSDimitry Andric "this setting loads sections only.",
36579dba64beSDimitry Andric },
36589dba64beSDimitry Andric {
36599dba64beSDimitry Andric eMemoryModuleLoadLevelPartial,
36609dba64beSDimitry Andric "partial",
36610b57cec5SDimitry Andric "Load partial information when loading modules from memory. Currently "
36629dba64beSDimitry Andric "this setting loads sections and function bounds.",
36639dba64beSDimitry Andric },
36649dba64beSDimitry Andric {
36659dba64beSDimitry Andric eMemoryModuleLoadLevelComplete,
36669dba64beSDimitry Andric "complete",
36670b57cec5SDimitry Andric "Load complete information when loading modules from memory. Currently "
36689dba64beSDimitry Andric "this setting loads sections and all symbols.",
36699dba64beSDimitry Andric },
36709dba64beSDimitry Andric };
36710b57cec5SDimitry Andric
36729dba64beSDimitry Andric #define LLDB_PROPERTIES_target
36739dba64beSDimitry Andric #include "TargetProperties.inc"
36740b57cec5SDimitry Andric
36750b57cec5SDimitry Andric enum {
36769dba64beSDimitry Andric #define LLDB_PROPERTIES_target
36779dba64beSDimitry Andric #include "TargetPropertiesEnum.inc"
36780b57cec5SDimitry Andric ePropertyExperimental,
36790b57cec5SDimitry Andric };
36800b57cec5SDimitry Andric
3681*5f7ddb14SDimitry Andric class TargetOptionValueProperties
3682*5f7ddb14SDimitry Andric : public Cloneable<TargetOptionValueProperties, OptionValueProperties> {
36830b57cec5SDimitry Andric public:
TargetOptionValueProperties(ConstString name)3684*5f7ddb14SDimitry Andric TargetOptionValueProperties(ConstString name) : Cloneable(name) {}
36850b57cec5SDimitry Andric
GetPropertyAtIndex(const ExecutionContext * exe_ctx,bool will_modify,uint32_t idx) const36860b57cec5SDimitry Andric const Property *GetPropertyAtIndex(const ExecutionContext *exe_ctx,
36870b57cec5SDimitry Andric bool will_modify,
36880b57cec5SDimitry Andric uint32_t idx) const override {
36890b57cec5SDimitry Andric // When getting the value for a key from the target options, we will always
36900b57cec5SDimitry Andric // try and grab the setting from the current target if there is one. Else
36910b57cec5SDimitry Andric // we just use the one from this instance.
36920b57cec5SDimitry Andric if (exe_ctx) {
36930b57cec5SDimitry Andric Target *target = exe_ctx->GetTargetPtr();
36940b57cec5SDimitry Andric if (target) {
36950b57cec5SDimitry Andric TargetOptionValueProperties *target_properties =
36960b57cec5SDimitry Andric static_cast<TargetOptionValueProperties *>(
36970b57cec5SDimitry Andric target->GetValueProperties().get());
36980b57cec5SDimitry Andric if (this != target_properties)
36990b57cec5SDimitry Andric return target_properties->ProtectedGetPropertyAtIndex(idx);
37000b57cec5SDimitry Andric }
37010b57cec5SDimitry Andric }
37020b57cec5SDimitry Andric return ProtectedGetPropertyAtIndex(idx);
37030b57cec5SDimitry Andric }
37040b57cec5SDimitry Andric };
37050b57cec5SDimitry Andric
37060b57cec5SDimitry Andric // TargetProperties
37075ffd83dbSDimitry Andric #define LLDB_PROPERTIES_target_experimental
37089dba64beSDimitry Andric #include "TargetProperties.inc"
37090b57cec5SDimitry Andric
37109dba64beSDimitry Andric enum {
37115ffd83dbSDimitry Andric #define LLDB_PROPERTIES_target_experimental
37129dba64beSDimitry Andric #include "TargetPropertiesEnum.inc"
37139dba64beSDimitry Andric };
37140b57cec5SDimitry Andric
3715*5f7ddb14SDimitry Andric class TargetExperimentalOptionValueProperties
3716*5f7ddb14SDimitry Andric : public Cloneable<TargetExperimentalOptionValueProperties,
3717*5f7ddb14SDimitry Andric OptionValueProperties> {
37180b57cec5SDimitry Andric public:
TargetExperimentalOptionValueProperties()37190b57cec5SDimitry Andric TargetExperimentalOptionValueProperties()
3720*5f7ddb14SDimitry Andric : Cloneable(ConstString(Properties::GetExperimentalSettingsName())) {}
37210b57cec5SDimitry Andric };
37220b57cec5SDimitry Andric
TargetExperimentalProperties()37230b57cec5SDimitry Andric TargetExperimentalProperties::TargetExperimentalProperties()
37240b57cec5SDimitry Andric : Properties(OptionValuePropertiesSP(
37250b57cec5SDimitry Andric new TargetExperimentalOptionValueProperties())) {
37265ffd83dbSDimitry Andric m_collection_sp->Initialize(g_target_experimental_properties);
37270b57cec5SDimitry Andric }
37280b57cec5SDimitry Andric
37290b57cec5SDimitry Andric // TargetProperties
TargetProperties(Target * target)37300b57cec5SDimitry Andric TargetProperties::TargetProperties(Target *target)
37315ffd83dbSDimitry Andric : Properties(), m_launch_info(), m_target(target) {
37320b57cec5SDimitry Andric if (target) {
3733*5f7ddb14SDimitry Andric m_collection_sp =
3734*5f7ddb14SDimitry Andric OptionValueProperties::CreateLocalCopy(*Target::GetGlobalProperties());
37350b57cec5SDimitry Andric
37360b57cec5SDimitry Andric // Set callbacks to update launch_info whenever "settins set" updated any
37370b57cec5SDimitry Andric // of these properties
37380b57cec5SDimitry Andric m_collection_sp->SetValueChangedCallback(
3739480093f4SDimitry Andric ePropertyArg0, [this] { Arg0ValueChangedCallback(); });
37400b57cec5SDimitry Andric m_collection_sp->SetValueChangedCallback(
3741480093f4SDimitry Andric ePropertyRunArgs, [this] { RunArgsValueChangedCallback(); });
37420b57cec5SDimitry Andric m_collection_sp->SetValueChangedCallback(
3743480093f4SDimitry Andric ePropertyEnvVars, [this] { EnvVarsValueChangedCallback(); });
37440b57cec5SDimitry Andric m_collection_sp->SetValueChangedCallback(
37455ffd83dbSDimitry Andric ePropertyUnsetEnvVars, [this] { EnvVarsValueChangedCallback(); });
37465ffd83dbSDimitry Andric m_collection_sp->SetValueChangedCallback(
37475ffd83dbSDimitry Andric ePropertyInheritEnv, [this] { EnvVarsValueChangedCallback(); });
37485ffd83dbSDimitry Andric m_collection_sp->SetValueChangedCallback(
3749480093f4SDimitry Andric ePropertyInputPath, [this] { InputPathValueChangedCallback(); });
37500b57cec5SDimitry Andric m_collection_sp->SetValueChangedCallback(
3751480093f4SDimitry Andric ePropertyOutputPath, [this] { OutputPathValueChangedCallback(); });
37520b57cec5SDimitry Andric m_collection_sp->SetValueChangedCallback(
3753480093f4SDimitry Andric ePropertyErrorPath, [this] { ErrorPathValueChangedCallback(); });
3754480093f4SDimitry Andric m_collection_sp->SetValueChangedCallback(ePropertyDetachOnError, [this] {
3755480093f4SDimitry Andric DetachOnErrorValueChangedCallback();
3756480093f4SDimitry Andric });
37570b57cec5SDimitry Andric m_collection_sp->SetValueChangedCallback(
3758480093f4SDimitry Andric ePropertyDisableASLR, [this] { DisableASLRValueChangedCallback(); });
37590b57cec5SDimitry Andric m_collection_sp->SetValueChangedCallback(
3760af732203SDimitry Andric ePropertyInheritTCC, [this] { InheritTCCValueChangedCallback(); });
3761af732203SDimitry Andric m_collection_sp->SetValueChangedCallback(
3762480093f4SDimitry Andric ePropertyDisableSTDIO, [this] { DisableSTDIOValueChangedCallback(); });
37630b57cec5SDimitry Andric
37645ffd83dbSDimitry Andric m_experimental_properties_up =
37655ffd83dbSDimitry Andric std::make_unique<TargetExperimentalProperties>();
37660b57cec5SDimitry Andric m_collection_sp->AppendProperty(
37670b57cec5SDimitry Andric ConstString(Properties::GetExperimentalSettingsName()),
37680b57cec5SDimitry Andric ConstString("Experimental settings - setting these won't produce "
37690b57cec5SDimitry Andric "errors if the setting is not present."),
37700b57cec5SDimitry Andric true, m_experimental_properties_up->GetValueProperties());
37710b57cec5SDimitry Andric } else {
37720b57cec5SDimitry Andric m_collection_sp =
37730b57cec5SDimitry Andric std::make_shared<TargetOptionValueProperties>(ConstString("target"));
37749dba64beSDimitry Andric m_collection_sp->Initialize(g_target_properties);
37755ffd83dbSDimitry Andric m_experimental_properties_up =
37765ffd83dbSDimitry Andric std::make_unique<TargetExperimentalProperties>();
37770b57cec5SDimitry Andric m_collection_sp->AppendProperty(
37780b57cec5SDimitry Andric ConstString(Properties::GetExperimentalSettingsName()),
37790b57cec5SDimitry Andric ConstString("Experimental settings - setting these won't produce "
37800b57cec5SDimitry Andric "errors if the setting is not present."),
37810b57cec5SDimitry Andric true, m_experimental_properties_up->GetValueProperties());
37820b57cec5SDimitry Andric m_collection_sp->AppendProperty(
37830b57cec5SDimitry Andric ConstString("process"), ConstString("Settings specific to processes."),
37840b57cec5SDimitry Andric true, Process::GetGlobalProperties()->GetValueProperties());
37850b57cec5SDimitry Andric }
37860b57cec5SDimitry Andric }
37870b57cec5SDimitry Andric
37880b57cec5SDimitry Andric TargetProperties::~TargetProperties() = default;
37890b57cec5SDimitry Andric
UpdateLaunchInfoFromProperties()37905ffd83dbSDimitry Andric void TargetProperties::UpdateLaunchInfoFromProperties() {
37915ffd83dbSDimitry Andric Arg0ValueChangedCallback();
37925ffd83dbSDimitry Andric RunArgsValueChangedCallback();
37935ffd83dbSDimitry Andric EnvVarsValueChangedCallback();
37945ffd83dbSDimitry Andric InputPathValueChangedCallback();
37955ffd83dbSDimitry Andric OutputPathValueChangedCallback();
37965ffd83dbSDimitry Andric ErrorPathValueChangedCallback();
37975ffd83dbSDimitry Andric DetachOnErrorValueChangedCallback();
37985ffd83dbSDimitry Andric DisableASLRValueChangedCallback();
3799af732203SDimitry Andric InheritTCCValueChangedCallback();
38005ffd83dbSDimitry Andric DisableSTDIOValueChangedCallback();
38015ffd83dbSDimitry Andric }
38025ffd83dbSDimitry Andric
GetInjectLocalVariables(ExecutionContext * exe_ctx) const38030b57cec5SDimitry Andric bool TargetProperties::GetInjectLocalVariables(
38040b57cec5SDimitry Andric ExecutionContext *exe_ctx) const {
38050b57cec5SDimitry Andric const Property *exp_property = m_collection_sp->GetPropertyAtIndex(
38060b57cec5SDimitry Andric exe_ctx, false, ePropertyExperimental);
38070b57cec5SDimitry Andric OptionValueProperties *exp_values =
38080b57cec5SDimitry Andric exp_property->GetValue()->GetAsProperties();
38090b57cec5SDimitry Andric if (exp_values)
38100b57cec5SDimitry Andric return exp_values->GetPropertyAtIndexAsBoolean(
38110b57cec5SDimitry Andric exe_ctx, ePropertyInjectLocalVars, true);
38120b57cec5SDimitry Andric else
38130b57cec5SDimitry Andric return true;
38140b57cec5SDimitry Andric }
38150b57cec5SDimitry Andric
SetInjectLocalVariables(ExecutionContext * exe_ctx,bool b)38160b57cec5SDimitry Andric void TargetProperties::SetInjectLocalVariables(ExecutionContext *exe_ctx,
38170b57cec5SDimitry Andric bool b) {
38180b57cec5SDimitry Andric const Property *exp_property =
38190b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndex(exe_ctx, true, ePropertyExperimental);
38200b57cec5SDimitry Andric OptionValueProperties *exp_values =
38210b57cec5SDimitry Andric exp_property->GetValue()->GetAsProperties();
38220b57cec5SDimitry Andric if (exp_values)
38230b57cec5SDimitry Andric exp_values->SetPropertyAtIndexAsBoolean(exe_ctx, ePropertyInjectLocalVars,
38240b57cec5SDimitry Andric true);
38250b57cec5SDimitry Andric }
38260b57cec5SDimitry Andric
GetDefaultArchitecture() const38270b57cec5SDimitry Andric ArchSpec TargetProperties::GetDefaultArchitecture() const {
38280b57cec5SDimitry Andric OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch(
38290b57cec5SDimitry Andric nullptr, ePropertyDefaultArch);
38300b57cec5SDimitry Andric if (value)
38310b57cec5SDimitry Andric return value->GetCurrentValue();
38320b57cec5SDimitry Andric return ArchSpec();
38330b57cec5SDimitry Andric }
38340b57cec5SDimitry Andric
SetDefaultArchitecture(const ArchSpec & arch)38350b57cec5SDimitry Andric void TargetProperties::SetDefaultArchitecture(const ArchSpec &arch) {
38360b57cec5SDimitry Andric OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch(
38370b57cec5SDimitry Andric nullptr, ePropertyDefaultArch);
38380b57cec5SDimitry Andric if (value)
38390b57cec5SDimitry Andric return value->SetCurrentValue(arch, true);
38400b57cec5SDimitry Andric }
38410b57cec5SDimitry Andric
GetMoveToNearestCode() const38420b57cec5SDimitry Andric bool TargetProperties::GetMoveToNearestCode() const {
38430b57cec5SDimitry Andric const uint32_t idx = ePropertyMoveToNearestCode;
38440b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
38459dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
38460b57cec5SDimitry Andric }
38470b57cec5SDimitry Andric
GetPreferDynamicValue() const38480b57cec5SDimitry Andric lldb::DynamicValueType TargetProperties::GetPreferDynamicValue() const {
38490b57cec5SDimitry Andric const uint32_t idx = ePropertyPreferDynamic;
38500b57cec5SDimitry Andric return (lldb::DynamicValueType)
38510b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndexAsEnumeration(
38529dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
38530b57cec5SDimitry Andric }
38540b57cec5SDimitry Andric
SetPreferDynamicValue(lldb::DynamicValueType d)38550b57cec5SDimitry Andric bool TargetProperties::SetPreferDynamicValue(lldb::DynamicValueType d) {
38560b57cec5SDimitry Andric const uint32_t idx = ePropertyPreferDynamic;
38570b57cec5SDimitry Andric return m_collection_sp->SetPropertyAtIndexAsEnumeration(nullptr, idx, d);
38580b57cec5SDimitry Andric }
38590b57cec5SDimitry Andric
GetPreloadSymbols() const38600b57cec5SDimitry Andric bool TargetProperties::GetPreloadSymbols() const {
38610b57cec5SDimitry Andric const uint32_t idx = ePropertyPreloadSymbols;
38620b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
38639dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
38640b57cec5SDimitry Andric }
38650b57cec5SDimitry Andric
SetPreloadSymbols(bool b)38660b57cec5SDimitry Andric void TargetProperties::SetPreloadSymbols(bool b) {
38670b57cec5SDimitry Andric const uint32_t idx = ePropertyPreloadSymbols;
38680b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
38690b57cec5SDimitry Andric }
38700b57cec5SDimitry Andric
GetDisableASLR() const38710b57cec5SDimitry Andric bool TargetProperties::GetDisableASLR() const {
38720b57cec5SDimitry Andric const uint32_t idx = ePropertyDisableASLR;
38730b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
38749dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
38750b57cec5SDimitry Andric }
38760b57cec5SDimitry Andric
SetDisableASLR(bool b)38770b57cec5SDimitry Andric void TargetProperties::SetDisableASLR(bool b) {
38780b57cec5SDimitry Andric const uint32_t idx = ePropertyDisableASLR;
38790b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
38800b57cec5SDimitry Andric }
38810b57cec5SDimitry Andric
GetInheritTCC() const3882af732203SDimitry Andric bool TargetProperties::GetInheritTCC() const {
3883af732203SDimitry Andric const uint32_t idx = ePropertyInheritTCC;
3884af732203SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
3885af732203SDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
3886af732203SDimitry Andric }
3887af732203SDimitry Andric
SetInheritTCC(bool b)3888af732203SDimitry Andric void TargetProperties::SetInheritTCC(bool b) {
3889af732203SDimitry Andric const uint32_t idx = ePropertyInheritTCC;
3890af732203SDimitry Andric m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
3891af732203SDimitry Andric }
3892af732203SDimitry Andric
GetDetachOnError() const38930b57cec5SDimitry Andric bool TargetProperties::GetDetachOnError() const {
38940b57cec5SDimitry Andric const uint32_t idx = ePropertyDetachOnError;
38950b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
38969dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
38970b57cec5SDimitry Andric }
38980b57cec5SDimitry Andric
SetDetachOnError(bool b)38990b57cec5SDimitry Andric void TargetProperties::SetDetachOnError(bool b) {
39000b57cec5SDimitry Andric const uint32_t idx = ePropertyDetachOnError;
39010b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
39020b57cec5SDimitry Andric }
39030b57cec5SDimitry Andric
GetDisableSTDIO() const39040b57cec5SDimitry Andric bool TargetProperties::GetDisableSTDIO() const {
39050b57cec5SDimitry Andric const uint32_t idx = ePropertyDisableSTDIO;
39060b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
39079dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
39080b57cec5SDimitry Andric }
39090b57cec5SDimitry Andric
SetDisableSTDIO(bool b)39100b57cec5SDimitry Andric void TargetProperties::SetDisableSTDIO(bool b) {
39110b57cec5SDimitry Andric const uint32_t idx = ePropertyDisableSTDIO;
39120b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
39130b57cec5SDimitry Andric }
39140b57cec5SDimitry Andric
GetDisassemblyFlavor() const39150b57cec5SDimitry Andric const char *TargetProperties::GetDisassemblyFlavor() const {
39160b57cec5SDimitry Andric const uint32_t idx = ePropertyDisassemblyFlavor;
39170b57cec5SDimitry Andric const char *return_value;
39180b57cec5SDimitry Andric
39190b57cec5SDimitry Andric x86DisassemblyFlavor flavor_value =
39200b57cec5SDimitry Andric (x86DisassemblyFlavor)m_collection_sp->GetPropertyAtIndexAsEnumeration(
39219dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
39220b57cec5SDimitry Andric return_value = g_x86_dis_flavor_value_types[flavor_value].string_value;
39230b57cec5SDimitry Andric return return_value;
39240b57cec5SDimitry Andric }
39250b57cec5SDimitry Andric
GetInlineStrategy() const39260b57cec5SDimitry Andric InlineStrategy TargetProperties::GetInlineStrategy() const {
39270b57cec5SDimitry Andric const uint32_t idx = ePropertyInlineStrategy;
39280b57cec5SDimitry Andric return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration(
39299dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
39300b57cec5SDimitry Andric }
39310b57cec5SDimitry Andric
GetArg0() const39320b57cec5SDimitry Andric llvm::StringRef TargetProperties::GetArg0() const {
39330b57cec5SDimitry Andric const uint32_t idx = ePropertyArg0;
39349dba64beSDimitry Andric return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx,
39359dba64beSDimitry Andric llvm::StringRef());
39360b57cec5SDimitry Andric }
39370b57cec5SDimitry Andric
SetArg0(llvm::StringRef arg)39380b57cec5SDimitry Andric void TargetProperties::SetArg0(llvm::StringRef arg) {
39390b57cec5SDimitry Andric const uint32_t idx = ePropertyArg0;
39409dba64beSDimitry Andric m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, arg);
39410b57cec5SDimitry Andric m_launch_info.SetArg0(arg);
39420b57cec5SDimitry Andric }
39430b57cec5SDimitry Andric
GetRunArguments(Args & args) const39440b57cec5SDimitry Andric bool TargetProperties::GetRunArguments(Args &args) const {
39450b57cec5SDimitry Andric const uint32_t idx = ePropertyRunArgs;
39460b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, idx, args);
39470b57cec5SDimitry Andric }
39480b57cec5SDimitry Andric
SetRunArguments(const Args & args)39490b57cec5SDimitry Andric void TargetProperties::SetRunArguments(const Args &args) {
39500b57cec5SDimitry Andric const uint32_t idx = ePropertyRunArgs;
39510b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, args);
39520b57cec5SDimitry Andric m_launch_info.GetArguments() = args;
39530b57cec5SDimitry Andric }
39540b57cec5SDimitry Andric
ComputeEnvironment() const39555ffd83dbSDimitry Andric Environment TargetProperties::ComputeEnvironment() const {
39565ffd83dbSDimitry Andric Environment env;
39575ffd83dbSDimitry Andric
39585ffd83dbSDimitry Andric if (m_target &&
39595ffd83dbSDimitry Andric m_collection_sp->GetPropertyAtIndexAsBoolean(
39605ffd83dbSDimitry Andric nullptr, ePropertyInheritEnv,
39615ffd83dbSDimitry Andric g_target_properties[ePropertyInheritEnv].default_uint_value != 0)) {
39625ffd83dbSDimitry Andric if (auto platform_sp = m_target->GetPlatform()) {
39635ffd83dbSDimitry Andric Environment platform_env = platform_sp->GetEnvironment();
39645ffd83dbSDimitry Andric for (const auto &KV : platform_env)
39655ffd83dbSDimitry Andric env[KV.first()] = KV.second;
39665ffd83dbSDimitry Andric }
39675ffd83dbSDimitry Andric }
39685ffd83dbSDimitry Andric
39695ffd83dbSDimitry Andric Args property_unset_env;
39705ffd83dbSDimitry Andric m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, ePropertyUnsetEnvVars,
39715ffd83dbSDimitry Andric property_unset_env);
39725ffd83dbSDimitry Andric for (const auto &var : property_unset_env)
39735ffd83dbSDimitry Andric env.erase(var.ref());
39745ffd83dbSDimitry Andric
39755ffd83dbSDimitry Andric Args property_env;
39765ffd83dbSDimitry Andric m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, ePropertyEnvVars,
39775ffd83dbSDimitry Andric property_env);
39785ffd83dbSDimitry Andric for (const auto &KV : Environment(property_env))
39795ffd83dbSDimitry Andric env[KV.first()] = KV.second;
39805ffd83dbSDimitry Andric
39815ffd83dbSDimitry Andric return env;
39825ffd83dbSDimitry Andric }
39835ffd83dbSDimitry Andric
GetEnvironment() const39840b57cec5SDimitry Andric Environment TargetProperties::GetEnvironment() const {
39855ffd83dbSDimitry Andric return ComputeEnvironment();
39860b57cec5SDimitry Andric }
39870b57cec5SDimitry Andric
SetEnvironment(Environment env)39880b57cec5SDimitry Andric void TargetProperties::SetEnvironment(Environment env) {
39890b57cec5SDimitry Andric // TODO: Get rid of the Args intermediate step
39900b57cec5SDimitry Andric const uint32_t idx = ePropertyEnvVars;
39910b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, Args(env));
39920b57cec5SDimitry Andric }
39930b57cec5SDimitry Andric
GetSkipPrologue() const39940b57cec5SDimitry Andric bool TargetProperties::GetSkipPrologue() const {
39950b57cec5SDimitry Andric const uint32_t idx = ePropertySkipPrologue;
39960b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
39979dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
39980b57cec5SDimitry Andric }
39990b57cec5SDimitry Andric
GetSourcePathMap() const40000b57cec5SDimitry Andric PathMappingList &TargetProperties::GetSourcePathMap() const {
40010b57cec5SDimitry Andric const uint32_t idx = ePropertySourceMap;
40020b57cec5SDimitry Andric OptionValuePathMappings *option_value =
40030b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings(nullptr,
40040b57cec5SDimitry Andric false, idx);
40050b57cec5SDimitry Andric assert(option_value);
40060b57cec5SDimitry Andric return option_value->GetCurrentValue();
40070b57cec5SDimitry Andric }
40080b57cec5SDimitry Andric
AppendExecutableSearchPaths(const FileSpec & dir)40090b57cec5SDimitry Andric void TargetProperties::AppendExecutableSearchPaths(const FileSpec &dir) {
40100b57cec5SDimitry Andric const uint32_t idx = ePropertyExecutableSearchPaths;
40110b57cec5SDimitry Andric OptionValueFileSpecList *option_value =
40120b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr,
40130b57cec5SDimitry Andric false, idx);
40140b57cec5SDimitry Andric assert(option_value);
40150b57cec5SDimitry Andric option_value->AppendCurrentValue(dir);
40160b57cec5SDimitry Andric }
40170b57cec5SDimitry Andric
GetExecutableSearchPaths()40180b57cec5SDimitry Andric FileSpecList TargetProperties::GetExecutableSearchPaths() {
40190b57cec5SDimitry Andric const uint32_t idx = ePropertyExecutableSearchPaths;
40200b57cec5SDimitry Andric const OptionValueFileSpecList *option_value =
40210b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr,
40220b57cec5SDimitry Andric false, idx);
40230b57cec5SDimitry Andric assert(option_value);
40240b57cec5SDimitry Andric return option_value->GetCurrentValue();
40250b57cec5SDimitry Andric }
40260b57cec5SDimitry Andric
GetDebugFileSearchPaths()40270b57cec5SDimitry Andric FileSpecList TargetProperties::GetDebugFileSearchPaths() {
40280b57cec5SDimitry Andric const uint32_t idx = ePropertyDebugFileSearchPaths;
40290b57cec5SDimitry Andric const OptionValueFileSpecList *option_value =
40300b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr,
40310b57cec5SDimitry Andric false, idx);
40320b57cec5SDimitry Andric assert(option_value);
40330b57cec5SDimitry Andric return option_value->GetCurrentValue();
40340b57cec5SDimitry Andric }
40350b57cec5SDimitry Andric
GetClangModuleSearchPaths()40360b57cec5SDimitry Andric FileSpecList TargetProperties::GetClangModuleSearchPaths() {
40370b57cec5SDimitry Andric const uint32_t idx = ePropertyClangModuleSearchPaths;
40380b57cec5SDimitry Andric const OptionValueFileSpecList *option_value =
40390b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr,
40400b57cec5SDimitry Andric false, idx);
40410b57cec5SDimitry Andric assert(option_value);
40420b57cec5SDimitry Andric return option_value->GetCurrentValue();
40430b57cec5SDimitry Andric }
40440b57cec5SDimitry Andric
GetEnableAutoImportClangModules() const40450b57cec5SDimitry Andric bool TargetProperties::GetEnableAutoImportClangModules() const {
40460b57cec5SDimitry Andric const uint32_t idx = ePropertyAutoImportClangModules;
40470b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
40489dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
40490b57cec5SDimitry Andric }
40500b57cec5SDimitry Andric
GetImportStdModule() const4051af732203SDimitry Andric ImportStdModule TargetProperties::GetImportStdModule() const {
40520b57cec5SDimitry Andric const uint32_t idx = ePropertyImportStdModule;
4053af732203SDimitry Andric return (ImportStdModule)m_collection_sp->GetPropertyAtIndexAsEnumeration(
4054af732203SDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
40550b57cec5SDimitry Andric }
40560b57cec5SDimitry Andric
GetEnableAutoApplyFixIts() const40570b57cec5SDimitry Andric bool TargetProperties::GetEnableAutoApplyFixIts() const {
40580b57cec5SDimitry Andric const uint32_t idx = ePropertyAutoApplyFixIts;
40590b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
40609dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
40610b57cec5SDimitry Andric }
40620b57cec5SDimitry Andric
GetNumberOfRetriesWithFixits() const40635ffd83dbSDimitry Andric uint64_t TargetProperties::GetNumberOfRetriesWithFixits() const {
40645ffd83dbSDimitry Andric const uint32_t idx = ePropertyRetriesWithFixIts;
40655ffd83dbSDimitry Andric return m_collection_sp->GetPropertyAtIndexAsUInt64(
40665ffd83dbSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
40675ffd83dbSDimitry Andric }
40685ffd83dbSDimitry Andric
GetEnableNotifyAboutFixIts() const40690b57cec5SDimitry Andric bool TargetProperties::GetEnableNotifyAboutFixIts() const {
40700b57cec5SDimitry Andric const uint32_t idx = ePropertyNotifyAboutFixIts;
40710b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
40729dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
40730b57cec5SDimitry Andric }
40740b57cec5SDimitry Andric
GetEnableSaveObjects() const40750b57cec5SDimitry Andric bool TargetProperties::GetEnableSaveObjects() const {
40760b57cec5SDimitry Andric const uint32_t idx = ePropertySaveObjects;
40770b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
40789dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
40790b57cec5SDimitry Andric }
40800b57cec5SDimitry Andric
GetEnableSyntheticValue() const40810b57cec5SDimitry Andric bool TargetProperties::GetEnableSyntheticValue() const {
40820b57cec5SDimitry Andric const uint32_t idx = ePropertyEnableSynthetic;
40830b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
40849dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
40859dba64beSDimitry Andric }
40869dba64beSDimitry Andric
GetMaxZeroPaddingInFloatFormat() const40879dba64beSDimitry Andric uint32_t TargetProperties::GetMaxZeroPaddingInFloatFormat() const {
40889dba64beSDimitry Andric const uint32_t idx = ePropertyMaxZeroPaddingInFloatFormat;
40899dba64beSDimitry Andric return m_collection_sp->GetPropertyAtIndexAsUInt64(
40909dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
40910b57cec5SDimitry Andric }
40920b57cec5SDimitry Andric
GetMaximumNumberOfChildrenToDisplay() const40930b57cec5SDimitry Andric uint32_t TargetProperties::GetMaximumNumberOfChildrenToDisplay() const {
40940b57cec5SDimitry Andric const uint32_t idx = ePropertyMaxChildrenCount;
40950b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsSInt64(
40969dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
40970b57cec5SDimitry Andric }
40980b57cec5SDimitry Andric
GetMaximumSizeOfStringSummary() const40990b57cec5SDimitry Andric uint32_t TargetProperties::GetMaximumSizeOfStringSummary() const {
41000b57cec5SDimitry Andric const uint32_t idx = ePropertyMaxSummaryLength;
41010b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsSInt64(
41029dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
41030b57cec5SDimitry Andric }
41040b57cec5SDimitry Andric
GetMaximumMemReadSize() const41050b57cec5SDimitry Andric uint32_t TargetProperties::GetMaximumMemReadSize() const {
41060b57cec5SDimitry Andric const uint32_t idx = ePropertyMaxMemReadSize;
41070b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsSInt64(
41089dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
41090b57cec5SDimitry Andric }
41100b57cec5SDimitry Andric
GetStandardInputPath() const41110b57cec5SDimitry Andric FileSpec TargetProperties::GetStandardInputPath() const {
41120b57cec5SDimitry Andric const uint32_t idx = ePropertyInputPath;
41130b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
41140b57cec5SDimitry Andric }
41150b57cec5SDimitry Andric
SetStandardInputPath(llvm::StringRef path)41160b57cec5SDimitry Andric void TargetProperties::SetStandardInputPath(llvm::StringRef path) {
41170b57cec5SDimitry Andric const uint32_t idx = ePropertyInputPath;
41180b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, path);
41190b57cec5SDimitry Andric }
41200b57cec5SDimitry Andric
GetStandardOutputPath() const41210b57cec5SDimitry Andric FileSpec TargetProperties::GetStandardOutputPath() const {
41220b57cec5SDimitry Andric const uint32_t idx = ePropertyOutputPath;
41230b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
41240b57cec5SDimitry Andric }
41250b57cec5SDimitry Andric
SetStandardOutputPath(llvm::StringRef path)41260b57cec5SDimitry Andric void TargetProperties::SetStandardOutputPath(llvm::StringRef path) {
41270b57cec5SDimitry Andric const uint32_t idx = ePropertyOutputPath;
41280b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, path);
41290b57cec5SDimitry Andric }
41300b57cec5SDimitry Andric
GetStandardErrorPath() const41310b57cec5SDimitry Andric FileSpec TargetProperties::GetStandardErrorPath() const {
41320b57cec5SDimitry Andric const uint32_t idx = ePropertyErrorPath;
41330b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx);
41340b57cec5SDimitry Andric }
41350b57cec5SDimitry Andric
SetStandardErrorPath(llvm::StringRef path)41360b57cec5SDimitry Andric void TargetProperties::SetStandardErrorPath(llvm::StringRef path) {
41370b57cec5SDimitry Andric const uint32_t idx = ePropertyErrorPath;
41380b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, path);
41390b57cec5SDimitry Andric }
41400b57cec5SDimitry Andric
GetLanguage() const41410b57cec5SDimitry Andric LanguageType TargetProperties::GetLanguage() const {
41420b57cec5SDimitry Andric OptionValueLanguage *value =
41430b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndexAsOptionValueLanguage(
41440b57cec5SDimitry Andric nullptr, ePropertyLanguage);
41450b57cec5SDimitry Andric if (value)
41460b57cec5SDimitry Andric return value->GetCurrentValue();
41470b57cec5SDimitry Andric return LanguageType();
41480b57cec5SDimitry Andric }
41490b57cec5SDimitry Andric
GetExpressionPrefixContents()41500b57cec5SDimitry Andric llvm::StringRef TargetProperties::GetExpressionPrefixContents() {
41510b57cec5SDimitry Andric const uint32_t idx = ePropertyExprPrefix;
41520b57cec5SDimitry Andric OptionValueFileSpec *file =
41530b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec(nullptr, false,
41540b57cec5SDimitry Andric idx);
41550b57cec5SDimitry Andric if (file) {
41560b57cec5SDimitry Andric DataBufferSP data_sp(file->GetFileContents());
41570b57cec5SDimitry Andric if (data_sp)
41580b57cec5SDimitry Andric return llvm::StringRef(
41590b57cec5SDimitry Andric reinterpret_cast<const char *>(data_sp->GetBytes()),
41600b57cec5SDimitry Andric data_sp->GetByteSize());
41610b57cec5SDimitry Andric }
41620b57cec5SDimitry Andric return "";
41630b57cec5SDimitry Andric }
41640b57cec5SDimitry Andric
GetExprErrorLimit() const4165af732203SDimitry Andric uint64_t TargetProperties::GetExprErrorLimit() const {
4166af732203SDimitry Andric const uint32_t idx = ePropertyExprErrorLimit;
4167af732203SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsUInt64(
4168af732203SDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
4169af732203SDimitry Andric }
4170af732203SDimitry Andric
GetBreakpointsConsultPlatformAvoidList()41710b57cec5SDimitry Andric bool TargetProperties::GetBreakpointsConsultPlatformAvoidList() {
41720b57cec5SDimitry Andric const uint32_t idx = ePropertyBreakpointUseAvoidList;
41730b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
41749dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
41750b57cec5SDimitry Andric }
41760b57cec5SDimitry Andric
GetUseHexImmediates() const41770b57cec5SDimitry Andric bool TargetProperties::GetUseHexImmediates() const {
41780b57cec5SDimitry Andric const uint32_t idx = ePropertyUseHexImmediates;
41790b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
41809dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
41810b57cec5SDimitry Andric }
41820b57cec5SDimitry Andric
GetUseFastStepping() const41830b57cec5SDimitry Andric bool TargetProperties::GetUseFastStepping() const {
41840b57cec5SDimitry Andric const uint32_t idx = ePropertyUseFastStepping;
41850b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
41869dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
41870b57cec5SDimitry Andric }
41880b57cec5SDimitry Andric
GetDisplayExpressionsInCrashlogs() const41890b57cec5SDimitry Andric bool TargetProperties::GetDisplayExpressionsInCrashlogs() const {
41900b57cec5SDimitry Andric const uint32_t idx = ePropertyDisplayExpressionsInCrashlogs;
41910b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
41929dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
41930b57cec5SDimitry Andric }
41940b57cec5SDimitry Andric
GetLoadScriptFromSymbolFile() const41950b57cec5SDimitry Andric LoadScriptFromSymFile TargetProperties::GetLoadScriptFromSymbolFile() const {
41960b57cec5SDimitry Andric const uint32_t idx = ePropertyLoadScriptFromSymbolFile;
41970b57cec5SDimitry Andric return (LoadScriptFromSymFile)
41980b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndexAsEnumeration(
41999dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
42000b57cec5SDimitry Andric }
42010b57cec5SDimitry Andric
GetLoadCWDlldbinitFile() const42020b57cec5SDimitry Andric LoadCWDlldbinitFile TargetProperties::GetLoadCWDlldbinitFile() const {
42030b57cec5SDimitry Andric const uint32_t idx = ePropertyLoadCWDlldbinitFile;
42040b57cec5SDimitry Andric return (LoadCWDlldbinitFile)m_collection_sp->GetPropertyAtIndexAsEnumeration(
42059dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
42060b57cec5SDimitry Andric }
42070b57cec5SDimitry Andric
GetHexImmediateStyle() const42080b57cec5SDimitry Andric Disassembler::HexImmediateStyle TargetProperties::GetHexImmediateStyle() const {
42090b57cec5SDimitry Andric const uint32_t idx = ePropertyHexImmediateStyle;
42100b57cec5SDimitry Andric return (Disassembler::HexImmediateStyle)
42110b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndexAsEnumeration(
42129dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
42130b57cec5SDimitry Andric }
42140b57cec5SDimitry Andric
GetMemoryModuleLoadLevel() const42150b57cec5SDimitry Andric MemoryModuleLoadLevel TargetProperties::GetMemoryModuleLoadLevel() const {
42160b57cec5SDimitry Andric const uint32_t idx = ePropertyMemoryModuleLoadLevel;
42170b57cec5SDimitry Andric return (MemoryModuleLoadLevel)
42180b57cec5SDimitry Andric m_collection_sp->GetPropertyAtIndexAsEnumeration(
42199dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value);
42200b57cec5SDimitry Andric }
42210b57cec5SDimitry Andric
GetUserSpecifiedTrapHandlerNames(Args & args) const42220b57cec5SDimitry Andric bool TargetProperties::GetUserSpecifiedTrapHandlerNames(Args &args) const {
42230b57cec5SDimitry Andric const uint32_t idx = ePropertyTrapHandlerNames;
42240b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, idx, args);
42250b57cec5SDimitry Andric }
42260b57cec5SDimitry Andric
SetUserSpecifiedTrapHandlerNames(const Args & args)42270b57cec5SDimitry Andric void TargetProperties::SetUserSpecifiedTrapHandlerNames(const Args &args) {
42280b57cec5SDimitry Andric const uint32_t idx = ePropertyTrapHandlerNames;
42290b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, args);
42300b57cec5SDimitry Andric }
42310b57cec5SDimitry Andric
GetDisplayRuntimeSupportValues() const42320b57cec5SDimitry Andric bool TargetProperties::GetDisplayRuntimeSupportValues() const {
42330b57cec5SDimitry Andric const uint32_t idx = ePropertyDisplayRuntimeSupportValues;
42340b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, false);
42350b57cec5SDimitry Andric }
42360b57cec5SDimitry Andric
SetDisplayRuntimeSupportValues(bool b)42370b57cec5SDimitry Andric void TargetProperties::SetDisplayRuntimeSupportValues(bool b) {
42380b57cec5SDimitry Andric const uint32_t idx = ePropertyDisplayRuntimeSupportValues;
42390b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
42400b57cec5SDimitry Andric }
42410b57cec5SDimitry Andric
GetDisplayRecognizedArguments() const42420b57cec5SDimitry Andric bool TargetProperties::GetDisplayRecognizedArguments() const {
42430b57cec5SDimitry Andric const uint32_t idx = ePropertyDisplayRecognizedArguments;
42440b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, false);
42450b57cec5SDimitry Andric }
42460b57cec5SDimitry Andric
SetDisplayRecognizedArguments(bool b)42470b57cec5SDimitry Andric void TargetProperties::SetDisplayRecognizedArguments(bool b) {
42480b57cec5SDimitry Andric const uint32_t idx = ePropertyDisplayRecognizedArguments;
42490b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
42500b57cec5SDimitry Andric }
42510b57cec5SDimitry Andric
GetNonStopModeEnabled() const42520b57cec5SDimitry Andric bool TargetProperties::GetNonStopModeEnabled() const {
42530b57cec5SDimitry Andric const uint32_t idx = ePropertyNonStopModeEnabled;
42540b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, false);
42550b57cec5SDimitry Andric }
42560b57cec5SDimitry Andric
SetNonStopModeEnabled(bool b)42570b57cec5SDimitry Andric void TargetProperties::SetNonStopModeEnabled(bool b) {
42580b57cec5SDimitry Andric const uint32_t idx = ePropertyNonStopModeEnabled;
42590b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
42600b57cec5SDimitry Andric }
42610b57cec5SDimitry Andric
GetProcessLaunchInfo() const4262*5f7ddb14SDimitry Andric const ProcessLaunchInfo &TargetProperties::GetProcessLaunchInfo() const {
42630b57cec5SDimitry Andric return m_launch_info;
42640b57cec5SDimitry Andric }
42650b57cec5SDimitry Andric
SetProcessLaunchInfo(const ProcessLaunchInfo & launch_info)42660b57cec5SDimitry Andric void TargetProperties::SetProcessLaunchInfo(
42670b57cec5SDimitry Andric const ProcessLaunchInfo &launch_info) {
42680b57cec5SDimitry Andric m_launch_info = launch_info;
42690b57cec5SDimitry Andric SetArg0(launch_info.GetArg0());
42700b57cec5SDimitry Andric SetRunArguments(launch_info.GetArguments());
42710b57cec5SDimitry Andric SetEnvironment(launch_info.GetEnvironment());
42720b57cec5SDimitry Andric const FileAction *input_file_action =
42730b57cec5SDimitry Andric launch_info.GetFileActionForFD(STDIN_FILENO);
42740b57cec5SDimitry Andric if (input_file_action) {
42750b57cec5SDimitry Andric SetStandardInputPath(input_file_action->GetPath());
42760b57cec5SDimitry Andric }
42770b57cec5SDimitry Andric const FileAction *output_file_action =
42780b57cec5SDimitry Andric launch_info.GetFileActionForFD(STDOUT_FILENO);
42790b57cec5SDimitry Andric if (output_file_action) {
42800b57cec5SDimitry Andric SetStandardOutputPath(output_file_action->GetPath());
42810b57cec5SDimitry Andric }
42820b57cec5SDimitry Andric const FileAction *error_file_action =
42830b57cec5SDimitry Andric launch_info.GetFileActionForFD(STDERR_FILENO);
42840b57cec5SDimitry Andric if (error_file_action) {
42850b57cec5SDimitry Andric SetStandardErrorPath(error_file_action->GetPath());
42860b57cec5SDimitry Andric }
42870b57cec5SDimitry Andric SetDetachOnError(launch_info.GetFlags().Test(lldb::eLaunchFlagDetachOnError));
42880b57cec5SDimitry Andric SetDisableASLR(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR));
4289af732203SDimitry Andric SetInheritTCC(
4290af732203SDimitry Andric launch_info.GetFlags().Test(lldb::eLaunchFlagInheritTCCFromParent));
42910b57cec5SDimitry Andric SetDisableSTDIO(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableSTDIO));
42920b57cec5SDimitry Andric }
42930b57cec5SDimitry Andric
GetRequireHardwareBreakpoints() const42940b57cec5SDimitry Andric bool TargetProperties::GetRequireHardwareBreakpoints() const {
42950b57cec5SDimitry Andric const uint32_t idx = ePropertyRequireHardwareBreakpoints;
42960b57cec5SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
42979dba64beSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
42980b57cec5SDimitry Andric }
42990b57cec5SDimitry Andric
SetRequireHardwareBreakpoints(bool b)43000b57cec5SDimitry Andric void TargetProperties::SetRequireHardwareBreakpoints(bool b) {
43010b57cec5SDimitry Andric const uint32_t idx = ePropertyRequireHardwareBreakpoints;
43020b57cec5SDimitry Andric m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b);
43030b57cec5SDimitry Andric }
43040b57cec5SDimitry Andric
GetAutoInstallMainExecutable() const43055ffd83dbSDimitry Andric bool TargetProperties::GetAutoInstallMainExecutable() const {
43065ffd83dbSDimitry Andric const uint32_t idx = ePropertyAutoInstallMainExecutable;
43075ffd83dbSDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
43085ffd83dbSDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
43095ffd83dbSDimitry Andric }
43105ffd83dbSDimitry Andric
Arg0ValueChangedCallback()4311480093f4SDimitry Andric void TargetProperties::Arg0ValueChangedCallback() {
4312480093f4SDimitry Andric m_launch_info.SetArg0(GetArg0());
43130b57cec5SDimitry Andric }
43140b57cec5SDimitry Andric
RunArgsValueChangedCallback()4315480093f4SDimitry Andric void TargetProperties::RunArgsValueChangedCallback() {
43160b57cec5SDimitry Andric Args args;
4317480093f4SDimitry Andric if (GetRunArguments(args))
4318480093f4SDimitry Andric m_launch_info.GetArguments() = args;
43190b57cec5SDimitry Andric }
43200b57cec5SDimitry Andric
EnvVarsValueChangedCallback()4321480093f4SDimitry Andric void TargetProperties::EnvVarsValueChangedCallback() {
43225ffd83dbSDimitry Andric m_launch_info.GetEnvironment() = ComputeEnvironment();
43230b57cec5SDimitry Andric }
43240b57cec5SDimitry Andric
InputPathValueChangedCallback()4325480093f4SDimitry Andric void TargetProperties::InputPathValueChangedCallback() {
4326480093f4SDimitry Andric m_launch_info.AppendOpenFileAction(STDIN_FILENO, GetStandardInputPath(), true,
4327480093f4SDimitry Andric false);
43280b57cec5SDimitry Andric }
43290b57cec5SDimitry Andric
OutputPathValueChangedCallback()4330480093f4SDimitry Andric void TargetProperties::OutputPathValueChangedCallback() {
4331480093f4SDimitry Andric m_launch_info.AppendOpenFileAction(STDOUT_FILENO, GetStandardOutputPath(),
4332480093f4SDimitry Andric false, true);
43330b57cec5SDimitry Andric }
43340b57cec5SDimitry Andric
ErrorPathValueChangedCallback()4335480093f4SDimitry Andric void TargetProperties::ErrorPathValueChangedCallback() {
4336480093f4SDimitry Andric m_launch_info.AppendOpenFileAction(STDERR_FILENO, GetStandardErrorPath(),
4337480093f4SDimitry Andric false, true);
43380b57cec5SDimitry Andric }
43390b57cec5SDimitry Andric
DetachOnErrorValueChangedCallback()4340480093f4SDimitry Andric void TargetProperties::DetachOnErrorValueChangedCallback() {
4341480093f4SDimitry Andric if (GetDetachOnError())
4342480093f4SDimitry Andric m_launch_info.GetFlags().Set(lldb::eLaunchFlagDetachOnError);
43430b57cec5SDimitry Andric else
4344480093f4SDimitry Andric m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDetachOnError);
43450b57cec5SDimitry Andric }
43460b57cec5SDimitry Andric
DisableASLRValueChangedCallback()4347480093f4SDimitry Andric void TargetProperties::DisableASLRValueChangedCallback() {
4348480093f4SDimitry Andric if (GetDisableASLR())
4349480093f4SDimitry Andric m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableASLR);
43500b57cec5SDimitry Andric else
4351480093f4SDimitry Andric m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableASLR);
43520b57cec5SDimitry Andric }
43530b57cec5SDimitry Andric
InheritTCCValueChangedCallback()4354af732203SDimitry Andric void TargetProperties::InheritTCCValueChangedCallback() {
4355af732203SDimitry Andric if (GetInheritTCC())
4356af732203SDimitry Andric m_launch_info.GetFlags().Set(lldb::eLaunchFlagInheritTCCFromParent);
4357af732203SDimitry Andric else
4358af732203SDimitry Andric m_launch_info.GetFlags().Clear(lldb::eLaunchFlagInheritTCCFromParent);
4359af732203SDimitry Andric }
4360af732203SDimitry Andric
DisableSTDIOValueChangedCallback()4361480093f4SDimitry Andric void TargetProperties::DisableSTDIOValueChangedCallback() {
4362480093f4SDimitry Andric if (GetDisableSTDIO())
4363480093f4SDimitry Andric m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableSTDIO);
43640b57cec5SDimitry Andric else
4365480093f4SDimitry Andric m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableSTDIO);
43660b57cec5SDimitry Andric }
43670b57cec5SDimitry Andric
GetDebugUtilityExpression() const4368*5f7ddb14SDimitry Andric bool TargetProperties::GetDebugUtilityExpression() const {
4369*5f7ddb14SDimitry Andric const uint32_t idx = ePropertyDebugUtilityExpression;
4370*5f7ddb14SDimitry Andric return m_collection_sp->GetPropertyAtIndexAsBoolean(
4371*5f7ddb14SDimitry Andric nullptr, idx, g_target_properties[idx].default_uint_value != 0);
4372*5f7ddb14SDimitry Andric }
4373*5f7ddb14SDimitry Andric
SetDebugUtilityExpression(bool debug)4374*5f7ddb14SDimitry Andric void TargetProperties::SetDebugUtilityExpression(bool debug) {
4375*5f7ddb14SDimitry Andric const uint32_t idx = ePropertyDebugUtilityExpression;
4376*5f7ddb14SDimitry Andric m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, debug);
4377*5f7ddb14SDimitry Andric }
4378*5f7ddb14SDimitry Andric
43790b57cec5SDimitry Andric // Target::TargetEventData
43800b57cec5SDimitry Andric
TargetEventData(const lldb::TargetSP & target_sp)43810b57cec5SDimitry Andric Target::TargetEventData::TargetEventData(const lldb::TargetSP &target_sp)
43820b57cec5SDimitry Andric : EventData(), m_target_sp(target_sp), m_module_list() {}
43830b57cec5SDimitry Andric
TargetEventData(const lldb::TargetSP & target_sp,const ModuleList & module_list)43840b57cec5SDimitry Andric Target::TargetEventData::TargetEventData(const lldb::TargetSP &target_sp,
43850b57cec5SDimitry Andric const ModuleList &module_list)
43860b57cec5SDimitry Andric : EventData(), m_target_sp(target_sp), m_module_list(module_list) {}
43870b57cec5SDimitry Andric
43880b57cec5SDimitry Andric Target::TargetEventData::~TargetEventData() = default;
43890b57cec5SDimitry Andric
GetFlavorString()43900b57cec5SDimitry Andric ConstString Target::TargetEventData::GetFlavorString() {
43910b57cec5SDimitry Andric static ConstString g_flavor("Target::TargetEventData");
43920b57cec5SDimitry Andric return g_flavor;
43930b57cec5SDimitry Andric }
43940b57cec5SDimitry Andric
Dump(Stream * s) const43950b57cec5SDimitry Andric void Target::TargetEventData::Dump(Stream *s) const {
43960b57cec5SDimitry Andric for (size_t i = 0; i < m_module_list.GetSize(); ++i) {
43970b57cec5SDimitry Andric if (i != 0)
43980b57cec5SDimitry Andric *s << ", ";
43990b57cec5SDimitry Andric m_module_list.GetModuleAtIndex(i)->GetDescription(
4400480093f4SDimitry Andric s->AsRawOstream(), lldb::eDescriptionLevelBrief);
44010b57cec5SDimitry Andric }
44020b57cec5SDimitry Andric }
44030b57cec5SDimitry Andric
44040b57cec5SDimitry Andric const Target::TargetEventData *
GetEventDataFromEvent(const Event * event_ptr)44050b57cec5SDimitry Andric Target::TargetEventData::GetEventDataFromEvent(const Event *event_ptr) {
44060b57cec5SDimitry Andric if (event_ptr) {
44070b57cec5SDimitry Andric const EventData *event_data = event_ptr->GetData();
44080b57cec5SDimitry Andric if (event_data &&
44090b57cec5SDimitry Andric event_data->GetFlavor() == TargetEventData::GetFlavorString())
44100b57cec5SDimitry Andric return static_cast<const TargetEventData *>(event_ptr->GetData());
44110b57cec5SDimitry Andric }
44120b57cec5SDimitry Andric return nullptr;
44130b57cec5SDimitry Andric }
44140b57cec5SDimitry Andric
GetTargetFromEvent(const Event * event_ptr)44150b57cec5SDimitry Andric TargetSP Target::TargetEventData::GetTargetFromEvent(const Event *event_ptr) {
44160b57cec5SDimitry Andric TargetSP target_sp;
44170b57cec5SDimitry Andric const TargetEventData *event_data = GetEventDataFromEvent(event_ptr);
44180b57cec5SDimitry Andric if (event_data)
44190b57cec5SDimitry Andric target_sp = event_data->m_target_sp;
44200b57cec5SDimitry Andric return target_sp;
44210b57cec5SDimitry Andric }
44220b57cec5SDimitry Andric
44230b57cec5SDimitry Andric ModuleList
GetModuleListFromEvent(const Event * event_ptr)44240b57cec5SDimitry Andric Target::TargetEventData::GetModuleListFromEvent(const Event *event_ptr) {
44250b57cec5SDimitry Andric ModuleList module_list;
44260b57cec5SDimitry Andric const TargetEventData *event_data = GetEventDataFromEvent(event_ptr);
44270b57cec5SDimitry Andric if (event_data)
44280b57cec5SDimitry Andric module_list = event_data->m_module_list;
44290b57cec5SDimitry Andric return module_list;
44300b57cec5SDimitry Andric }
44319dba64beSDimitry Andric
GetAPIMutex()44329dba64beSDimitry Andric std::recursive_mutex &Target::GetAPIMutex() {
44339dba64beSDimitry Andric if (GetProcessSP() && GetProcessSP()->CurrentThreadIsPrivateStateThread())
44349dba64beSDimitry Andric return m_private_mutex;
44359dba64beSDimitry Andric else
44369dba64beSDimitry Andric return m_mutex;
44379dba64beSDimitry Andric }
4438