Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Target.cpp ----------------------------------------------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Pavel Labath | 181b823 | 2018-12-14 15:59:49 +0000 | [diff] [blame] | 9 | #include "lldb/Target/Target.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 10 | #include "Plugins/ExpressionParser/Clang/ClangModulesDeclVendor.h" |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 11 | #include "lldb/Breakpoint/BreakpointIDList.h" |
Alex Langford | 7f9c9f2 | 2019-06-21 19:43:07 +0000 | [diff] [blame] | 12 | #include "lldb/Breakpoint/BreakpointPrecondition.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Breakpoint/BreakpointResolver.h" |
| 14 | #include "lldb/Breakpoint/BreakpointResolverAddress.h" |
| 15 | #include "lldb/Breakpoint/BreakpointResolverFileLine.h" |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 16 | #include "lldb/Breakpoint/BreakpointResolverFileRegex.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 17 | #include "lldb/Breakpoint/BreakpointResolverName.h" |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 18 | #include "lldb/Breakpoint/BreakpointResolverScripted.h" |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 19 | #include "lldb/Breakpoint/Watchpoint.h" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Debugger.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Module.h" |
| 22 | #include "lldb/Core/ModuleSpec.h" |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 23 | #include "lldb/Core/PluginManager.h" |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 24 | #include "lldb/Core/SearchFilter.h" |
Pavel Labath | 181b823 | 2018-12-14 15:59:49 +0000 | [diff] [blame] | 25 | #include "lldb/Core/Section.h" |
Greg Clayton | 9585fbf | 2013-03-19 00:20:55 +0000 | [diff] [blame] | 26 | #include "lldb/Core/SourceManager.h" |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 27 | #include "lldb/Core/StreamFile.h" |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 28 | #include "lldb/Core/StructuredDataImpl.h" |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 29 | #include "lldb/Core/ValueObject.h" |
Sean Callanan | 6681041 | 2015-10-19 23:11:07 +0000 | [diff] [blame] | 30 | #include "lldb/Expression/REPL.h" |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 31 | #include "lldb/Expression/UserExpression.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | #include "lldb/Host/Host.h" |
Pavel Labath | b6dbe9a | 2017-07-18 13:14:01 +0000 | [diff] [blame] | 33 | #include "lldb/Host/PosixApi.h" |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 34 | #include "lldb/Interpreter/CommandInterpreter.h" |
| 35 | #include "lldb/Interpreter/CommandReturnObject.h" |
Johnny Chen | b90827e | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 36 | #include "lldb/Interpreter/OptionGroupWatchpoint.h" |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 37 | #include "lldb/Interpreter/OptionValues.h" |
| 38 | #include "lldb/Interpreter/Property.h" |
Zachary Turner | a78bd7f | 2015-03-03 23:11:11 +0000 | [diff] [blame] | 39 | #include "lldb/Symbol/ClangASTContext.h" |
Alex Langford | 2c3c045 | 2019-07-11 23:45:35 +0000 | [diff] [blame] | 40 | #include "lldb/Symbol/ClangASTImporter.h" |
Bhushan D. Attarde | 7f3daed | 2015-08-26 06:04:54 +0000 | [diff] [blame] | 41 | #include "lldb/Symbol/Function.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 42 | #include "lldb/Symbol/ObjectFile.h" |
Bhushan D. Attarde | 7f3daed | 2015-08-26 06:04:54 +0000 | [diff] [blame] | 43 | #include "lldb/Symbol/Symbol.h" |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 44 | #include "lldb/Target/Language.h" |
Zachary Turner | a78bd7f | 2015-03-03 23:11:11 +0000 | [diff] [blame] | 45 | #include "lldb/Target/LanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | #include "lldb/Target/Process.h" |
Greg Clayton | d5944cd | 2013-12-06 01:12:00 +0000 | [diff] [blame] | 47 | #include "lldb/Target/SectionLoadList.h" |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 48 | #include "lldb/Target/StackFrame.h" |
Jason Molenda | eef5106 | 2013-11-05 03:57:19 +0000 | [diff] [blame] | 49 | #include "lldb/Target/SystemRuntime.h" |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 50 | #include "lldb/Target/Thread.h" |
| 51 | #include "lldb/Target/ThreadSpec.h" |
Pavel Labath | 181b823 | 2018-12-14 15:59:49 +0000 | [diff] [blame] | 52 | #include "lldb/Utility/Event.h" |
Zachary Turner | 5713a05 | 2017-03-22 18:40:07 +0000 | [diff] [blame] | 53 | #include "lldb/Utility/FileSpec.h" |
Sean Callanan | 9a6940c | 2015-10-21 00:36:34 +0000 | [diff] [blame] | 54 | #include "lldb/Utility/LLDBAssert.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 55 | #include "lldb/Utility/Log.h" |
Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 56 | #include "lldb/Utility/State.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 57 | #include "lldb/Utility/StreamString.h" |
Pavel Labath | 38d0632 | 2017-06-29 14:32:17 +0000 | [diff] [blame] | 58 | #include "lldb/Utility/Timer.h" |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 59 | |
Tatyana Krasnukha | f62e23d | 2019-06-10 21:13:37 +0000 | [diff] [blame] | 60 | #include "llvm/ADT/ScopeExit.h" |
| 61 | |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 62 | #include <memory> |
Pavel Labath | 181b823 | 2018-12-14 15:59:49 +0000 | [diff] [blame] | 63 | #include <mutex> |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | |
| 65 | using namespace lldb; |
| 66 | using namespace lldb_private; |
| 67 | |
Pavel Labath | 43d3541 | 2016-12-06 11:24:51 +0000 | [diff] [blame] | 68 | constexpr std::chrono::milliseconds EvaluateExpressionOptions::default_timeout; |
| 69 | |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 70 | Target::Arch::Arch(const ArchSpec &spec) |
| 71 | : m_spec(spec), |
| 72 | m_plugin_up(PluginManager::CreateArchitectureInstance(spec)) {} |
| 73 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 74 | const Target::Arch &Target::Arch::operator=(const ArchSpec &spec) { |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 75 | m_spec = spec; |
| 76 | m_plugin_up = PluginManager::CreateArchitectureInstance(spec); |
| 77 | return *this; |
| 78 | } |
| 79 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | ConstString &Target::GetStaticBroadcasterClass() { |
| 81 | static ConstString class_name("lldb.target"); |
| 82 | return class_name; |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 85 | Target::Target(Debugger &debugger, const ArchSpec &target_arch, |
| 86 | const lldb::PlatformSP &platform_sp, bool is_dummy_target) |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 87 | : TargetProperties(this), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 88 | Broadcaster(debugger.GetBroadcasterManager(), |
| 89 | Target::GetStaticBroadcasterClass().AsCString()), |
| 90 | ExecutionContextScope(), m_debugger(debugger), m_platform_sp(platform_sp), |
Davide Italiano | 24fff24 | 2018-04-13 18:02:39 +0000 | [diff] [blame] | 91 | m_mutex(), m_arch(target_arch), m_images(this), m_section_load_history(), |
| 92 | m_breakpoint_list(false), m_internal_breakpoint_list(true), |
| 93 | m_watchpoint_list(), m_process_sp(), m_search_filter_sp(), |
| 94 | m_image_search_paths(ImageSearchPathsChanged, this), m_ast_importer_sp(), |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 95 | m_source_manager_up(), m_stop_hooks(), m_stop_hook_next_id(0), |
Davide Italiano | 24fff24 | 2018-04-13 18:02:39 +0000 | [diff] [blame] | 96 | m_valid(true), m_suppress_stop_hooks(false), |
| 97 | m_is_dummy_target(is_dummy_target), |
| 98 | m_stats_storage(static_cast<int>(StatisticKind::StatisticMax)) |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 99 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 100 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 101 | SetEventName(eBroadcastBitBreakpointChanged, "breakpoint-changed"); |
| 102 | SetEventName(eBroadcastBitModulesLoaded, "modules-loaded"); |
| 103 | SetEventName(eBroadcastBitModulesUnloaded, "modules-unloaded"); |
| 104 | SetEventName(eBroadcastBitWatchpointChanged, "watchpoint-changed"); |
| 105 | SetEventName(eBroadcastBitSymbolsLoaded, "symbols-loaded"); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 106 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | CheckInWithManager(); |
Greg Clayton | cfd1ace | 2010-10-31 03:01:06 +0000 | [diff] [blame] | 108 | |
Jonas Devlieghere | eaedc5e | 2019-07-23 17:03:37 +0000 | [diff] [blame] | 109 | LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT), |
| 110 | "{0} Target::Target()", static_cast<void *>(this)); |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 111 | if (target_arch.IsValid()) { |
Jonas Devlieghere | b2a9cf7 | 2019-07-22 23:48:01 +0000 | [diff] [blame] | 112 | LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET), |
Jonas Devlieghere | eaedc5e | 2019-07-23 17:03:37 +0000 | [diff] [blame] | 113 | "Target::Target created with architecture {0} ({1})", |
Jonas Devlieghere | b2a9cf7 | 2019-07-22 23:48:01 +0000 | [diff] [blame] | 114 | target_arch.GetArchitectureName(), |
| 115 | target_arch.GetTriple().getTriple().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 116 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 119 | Target::~Target() { |
| 120 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_OBJECT)); |
Jonas Devlieghere | eaedc5e | 2019-07-23 17:03:37 +0000 | [diff] [blame] | 121 | LLDB_LOG(log, "{0} Target::~Target()", static_cast<void *>(this)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 122 | DeleteCurrentProcess(); |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 125 | void Target::PrimeFromDummyTarget(Target *target) { |
| 126 | if (!target) |
| 127 | return; |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 128 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 129 | m_stop_hooks = target->m_stop_hooks; |
| 130 | |
| 131 | for (BreakpointSP breakpoint_sp : target->m_breakpoint_list.Breakpoints()) { |
| 132 | if (breakpoint_sp->IsInternal()) |
| 133 | continue; |
| 134 | |
| 135 | BreakpointSP new_bp(new Breakpoint(*this, *breakpoint_sp.get())); |
| 136 | AddBreakpoint(new_bp, false); |
| 137 | } |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 138 | |
| 139 | for (auto bp_name_entry : target->m_breakpoint_names) { |
| 140 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 141 | BreakpointName *new_bp_name = new BreakpointName(*bp_name_entry.second); |
| 142 | AddBreakpointName(new_bp_name); |
| 143 | } |
Jim Ingham | 893c932 | 2014-11-22 01:42:44 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 146 | void Target::Dump(Stream *s, lldb::DescriptionLevel description_level) { |
| 147 | // s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); |
| 148 | if (description_level != lldb::eDescriptionLevelBrief) { |
| 149 | s->Indent(); |
| 150 | s->PutCString("Target\n"); |
| 151 | s->IndentMore(); |
| 152 | m_images.Dump(s); |
| 153 | m_breakpoint_list.Dump(s); |
| 154 | m_internal_breakpoint_list.Dump(s); |
| 155 | s->IndentLess(); |
| 156 | } else { |
| 157 | Module *exe_module = GetExecutableModulePointer(); |
| 158 | if (exe_module) |
| 159 | s->PutCString(exe_module->GetFileSpec().GetFilename().GetCString()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 160 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 161 | s->PutCString("No executable module."); |
| 162 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 165 | void Target::CleanupProcess() { |
| 166 | // Do any cleanup of the target we need to do between process instances. |
| 167 | // NB It is better to do this before destroying the process in case the |
| 168 | // clean up needs some help from the process. |
| 169 | m_breakpoint_list.ClearAllBreakpointSites(); |
| 170 | m_internal_breakpoint_list.ClearAllBreakpointSites(); |
| 171 | // Disable watchpoints just on the debugger side. |
| 172 | std::unique_lock<std::recursive_mutex> lock; |
| 173 | this->GetWatchpointList().GetListMutex(lock); |
| 174 | DisableAllWatchpoints(false); |
| 175 | ClearAllWatchpointHitCounts(); |
| 176 | ClearAllWatchpointHistoricValues(); |
Greg Clayton | 90ba811 | 2012-12-05 00:16:59 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 179 | void Target::DeleteCurrentProcess() { |
| 180 | if (m_process_sp) { |
Greg Clayton | d5944cd | 2013-12-06 01:12:00 +0000 | [diff] [blame] | 181 | m_section_load_history.Clear(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 182 | if (m_process_sp->IsAlive()) |
| 183 | m_process_sp->Destroy(false); |
| 184 | |
| 185 | m_process_sp->Finalize(); |
| 186 | |
| 187 | CleanupProcess(); |
| 188 | |
| 189 | m_process_sp.reset(); |
| 190 | } |
Greg Clayton | 3418c85 | 2011-08-10 02:10:13 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 193 | const lldb::ProcessSP &Target::CreateProcess(ListenerSP listener_sp, |
Zachary Turner | 3165945 | 2016-11-17 21:15:14 +0000 | [diff] [blame] | 194 | llvm::StringRef plugin_name, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 195 | const FileSpec *crash_file) { |
Pavel Labath | cb8c699 | 2019-01-07 10:59:57 +0000 | [diff] [blame] | 196 | if (!listener_sp) |
| 197 | listener_sp = GetDebugger().GetListener(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 198 | DeleteCurrentProcess(); |
| 199 | m_process_sp = Process::FindPlugin(shared_from_this(), plugin_name, |
| 200 | listener_sp, crash_file); |
| 201 | return m_process_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | const lldb::ProcessSP &Target::GetProcessSP() const { return m_process_sp; } |
| 205 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 206 | lldb::REPLSP Target::GetREPL(Status &err, lldb::LanguageType language, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 207 | const char *repl_options, bool can_create) { |
| 208 | if (language == eLanguageTypeUnknown) { |
| 209 | std::set<LanguageType> repl_languages; |
| 210 | |
| 211 | Language::GetLanguagesSupportingREPLs(repl_languages); |
| 212 | |
| 213 | if (repl_languages.size() == 1) { |
| 214 | language = *repl_languages.begin(); |
| 215 | } else if (repl_languages.size() == 0) { |
| 216 | err.SetErrorStringWithFormat( |
| 217 | "LLDB isn't configured with REPL support for any languages."); |
| 218 | return REPLSP(); |
| 219 | } else { |
| 220 | err.SetErrorStringWithFormat( |
| 221 | "Multiple possible REPL languages. Please specify a language."); |
| 222 | return REPLSP(); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | REPLMap::iterator pos = m_repl_map.find(language); |
| 227 | |
| 228 | if (pos != m_repl_map.end()) { |
| 229 | return pos->second; |
| 230 | } |
| 231 | |
| 232 | if (!can_create) { |
| 233 | err.SetErrorStringWithFormat( |
| 234 | "Couldn't find an existing REPL for %s, and can't create a new one", |
| 235 | Language::GetNameForLanguageType(language)); |
| 236 | return lldb::REPLSP(); |
| 237 | } |
| 238 | |
| 239 | Debugger *const debugger = nullptr; |
| 240 | lldb::REPLSP ret = REPL::Create(err, language, debugger, this, repl_options); |
| 241 | |
| 242 | if (ret) { |
| 243 | m_repl_map[language] = ret; |
| 244 | return m_repl_map[language]; |
| 245 | } |
| 246 | |
| 247 | if (err.Success()) { |
| 248 | err.SetErrorStringWithFormat("Couldn't create a REPL for %s", |
| 249 | Language::GetNameForLanguageType(language)); |
| 250 | } |
| 251 | |
| 252 | return lldb::REPLSP(); |
| 253 | } |
| 254 | |
| 255 | void Target::SetREPL(lldb::LanguageType language, lldb::REPLSP repl_sp) { |
| 256 | lldbassert(!m_repl_map.count(language)); |
| 257 | |
| 258 | m_repl_map[language] = repl_sp; |
| 259 | } |
| 260 | |
| 261 | void Target::Destroy() { |
| 262 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 263 | m_valid = false; |
| 264 | DeleteCurrentProcess(); |
| 265 | m_platform_sp.reset(); |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 266 | m_arch = ArchSpec(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 267 | ClearModules(true); |
| 268 | m_section_load_history.Clear(); |
| 269 | const bool notify = false; |
| 270 | m_breakpoint_list.RemoveAll(notify); |
| 271 | m_internal_breakpoint_list.RemoveAll(notify); |
| 272 | m_last_created_breakpoint.reset(); |
| 273 | m_last_created_watchpoint.reset(); |
| 274 | m_search_filter_sp.reset(); |
| 275 | m_image_search_paths.Clear(notify); |
| 276 | m_stop_hooks.clear(); |
| 277 | m_stop_hook_next_id = 0; |
| 278 | m_suppress_stop_hooks = false; |
| 279 | } |
| 280 | |
| 281 | BreakpointList &Target::GetBreakpointList(bool internal) { |
| 282 | if (internal) |
| 283 | return m_internal_breakpoint_list; |
| 284 | else |
| 285 | return m_breakpoint_list; |
| 286 | } |
| 287 | |
| 288 | const BreakpointList &Target::GetBreakpointList(bool internal) const { |
| 289 | if (internal) |
| 290 | return m_internal_breakpoint_list; |
| 291 | else |
| 292 | return m_breakpoint_list; |
| 293 | } |
| 294 | |
| 295 | BreakpointSP Target::GetBreakpointByID(break_id_t break_id) { |
| 296 | BreakpointSP bp_sp; |
| 297 | |
| 298 | if (LLDB_BREAK_ID_IS_INTERNAL(break_id)) |
| 299 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID(break_id); |
| 300 | else |
| 301 | bp_sp = m_breakpoint_list.FindBreakpointByID(break_id); |
| 302 | |
| 303 | return bp_sp; |
| 304 | } |
| 305 | |
| 306 | BreakpointSP Target::CreateSourceRegexBreakpoint( |
| 307 | const FileSpecList *containingModules, |
| 308 | const FileSpecList *source_file_spec_list, |
| 309 | const std::unordered_set<std::string> &function_names, |
| 310 | RegularExpression &source_regex, bool internal, bool hardware, |
| 311 | LazyBool move_to_nearest_code) { |
| 312 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList( |
| 313 | containingModules, source_file_spec_list)); |
| 314 | if (move_to_nearest_code == eLazyBoolCalculate) |
| 315 | move_to_nearest_code = GetMoveToNearestCode() ? eLazyBoolYes : eLazyBoolNo; |
| 316 | BreakpointResolverSP resolver_sp(new BreakpointResolverFileRegex( |
| 317 | nullptr, source_regex, function_names, |
| 318 | !static_cast<bool>(move_to_nearest_code))); |
| 319 | |
| 320 | return CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true); |
| 321 | } |
| 322 | |
| 323 | BreakpointSP Target::CreateBreakpoint(const FileSpecList *containingModules, |
| 324 | const FileSpec &file, uint32_t line_no, |
Adrian Prantl | 431b158 | 2018-08-30 15:11:00 +0000 | [diff] [blame] | 325 | uint32_t column, lldb::addr_t offset, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 326 | LazyBool check_inlines, |
| 327 | LazyBool skip_prologue, bool internal, |
| 328 | bool hardware, |
| 329 | LazyBool move_to_nearest_code) { |
| 330 | FileSpec remapped_file; |
Greg Clayton | 86188d8 | 2018-05-21 14:14:36 +0000 | [diff] [blame] | 331 | if (!GetSourcePathMap().ReverseRemapPath(file, remapped_file)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 332 | remapped_file = file; |
| 333 | |
| 334 | if (check_inlines == eLazyBoolCalculate) { |
| 335 | const InlineStrategy inline_strategy = GetInlineStrategy(); |
| 336 | switch (inline_strategy) { |
| 337 | case eInlineBreakpointsNever: |
| 338 | check_inlines = eLazyBoolNo; |
| 339 | break; |
| 340 | |
| 341 | case eInlineBreakpointsHeaders: |
| 342 | if (remapped_file.IsSourceImplementationFile()) |
| 343 | check_inlines = eLazyBoolNo; |
| 344 | else |
| 345 | check_inlines = eLazyBoolYes; |
| 346 | break; |
| 347 | |
| 348 | case eInlineBreakpointsAlways: |
| 349 | check_inlines = eLazyBoolYes; |
| 350 | break; |
| 351 | } |
| 352 | } |
| 353 | SearchFilterSP filter_sp; |
| 354 | if (check_inlines == eLazyBoolNo) { |
| 355 | // Not checking for inlines, we are looking only for matching compile units |
| 356 | FileSpecList compile_unit_list; |
| 357 | compile_unit_list.Append(remapped_file); |
| 358 | filter_sp = GetSearchFilterForModuleAndCUList(containingModules, |
| 359 | &compile_unit_list); |
| 360 | } else { |
| 361 | filter_sp = GetSearchFilterForModuleList(containingModules); |
| 362 | } |
| 363 | if (skip_prologue == eLazyBoolCalculate) |
| 364 | skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo; |
| 365 | if (move_to_nearest_code == eLazyBoolCalculate) |
| 366 | move_to_nearest_code = GetMoveToNearestCode() ? eLazyBoolYes : eLazyBoolNo; |
| 367 | |
| 368 | BreakpointResolverSP resolver_sp(new BreakpointResolverFileLine( |
Adrian Prantl | 431b158 | 2018-08-30 15:11:00 +0000 | [diff] [blame] | 369 | nullptr, remapped_file, line_no, column, offset, check_inlines, |
| 370 | skip_prologue, !static_cast<bool>(move_to_nearest_code))); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 371 | return CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true); |
| 372 | } |
| 373 | |
| 374 | BreakpointSP Target::CreateBreakpoint(lldb::addr_t addr, bool internal, |
| 375 | bool hardware) { |
| 376 | Address so_addr; |
| 377 | |
| 378 | // Check for any reason we want to move this breakpoint to other address. |
| 379 | addr = GetBreakableLoadAddress(addr); |
| 380 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 381 | // Attempt to resolve our load address if possible, though it is ok if it |
| 382 | // doesn't resolve to section/offset. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 383 | |
| 384 | // Try and resolve as a load address if possible |
| 385 | GetSectionLoadList().ResolveLoadAddress(addr, so_addr); |
| 386 | if (!so_addr.IsValid()) { |
| 387 | // The address didn't resolve, so just set this as an absolute address |
| 388 | so_addr.SetOffset(addr); |
| 389 | } |
| 390 | BreakpointSP bp_sp(CreateBreakpoint(so_addr, internal, hardware)); |
| 391 | return bp_sp; |
| 392 | } |
| 393 | |
| 394 | BreakpointSP Target::CreateBreakpoint(const Address &addr, bool internal, |
| 395 | bool hardware) { |
| 396 | SearchFilterSP filter_sp( |
| 397 | new SearchFilterForUnconstrainedSearches(shared_from_this())); |
| 398 | BreakpointResolverSP resolver_sp( |
| 399 | new BreakpointResolverAddress(nullptr, addr)); |
| 400 | return CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, false); |
| 401 | } |
| 402 | |
| 403 | lldb::BreakpointSP |
| 404 | Target::CreateAddressInModuleBreakpoint(lldb::addr_t file_addr, bool internal, |
| 405 | const FileSpec *file_spec, |
| 406 | bool request_hardware) { |
| 407 | SearchFilterSP filter_sp( |
| 408 | new SearchFilterForUnconstrainedSearches(shared_from_this())); |
| 409 | BreakpointResolverSP resolver_sp( |
| 410 | new BreakpointResolverAddress(nullptr, file_addr, file_spec)); |
| 411 | return CreateBreakpoint(filter_sp, resolver_sp, internal, request_hardware, |
| 412 | false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 415 | BreakpointSP Target::CreateBreakpoint( |
| 416 | const FileSpecList *containingModules, |
| 417 | const FileSpecList *containingSourceFiles, const char *func_name, |
| 418 | FunctionNameType func_name_type_mask, LanguageType language, |
| 419 | lldb::addr_t offset, LazyBool skip_prologue, bool internal, bool hardware) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 420 | BreakpointSP bp_sp; |
| 421 | if (func_name) { |
| 422 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList( |
| 423 | containingModules, containingSourceFiles)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 424 | |
Greg Clayton | 03da4cc | 2013-04-19 21:31:16 +0000 | [diff] [blame] | 425 | if (skip_prologue == eLazyBoolCalculate) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 426 | skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo; |
| 427 | if (language == lldb::eLanguageTypeUnknown) |
| 428 | language = GetLanguage(); |
| 429 | |
| 430 | BreakpointResolverSP resolver_sp(new BreakpointResolverName( |
| 431 | nullptr, func_name, func_name_type_mask, language, Breakpoint::Exact, |
| 432 | offset, skip_prologue)); |
| 433 | bp_sp = CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true); |
| 434 | } |
| 435 | return bp_sp; |
| 436 | } |
| 437 | |
| 438 | lldb::BreakpointSP |
| 439 | Target::CreateBreakpoint(const FileSpecList *containingModules, |
| 440 | const FileSpecList *containingSourceFiles, |
| 441 | const std::vector<std::string> &func_names, |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 442 | FunctionNameType func_name_type_mask, |
| 443 | LanguageType language, lldb::addr_t offset, |
| 444 | LazyBool skip_prologue, bool internal, bool hardware) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 445 | BreakpointSP bp_sp; |
| 446 | size_t num_names = func_names.size(); |
| 447 | if (num_names > 0) { |
| 448 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList( |
| 449 | containingModules, containingSourceFiles)); |
| 450 | |
| 451 | if (skip_prologue == eLazyBoolCalculate) |
| 452 | skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo; |
| 453 | if (language == lldb::eLanguageTypeUnknown) |
| 454 | language = GetLanguage(); |
| 455 | |
| 456 | BreakpointResolverSP resolver_sp( |
| 457 | new BreakpointResolverName(nullptr, func_names, func_name_type_mask, |
| 458 | language, offset, skip_prologue)); |
| 459 | bp_sp = CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true); |
| 460 | } |
| 461 | return bp_sp; |
| 462 | } |
| 463 | |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 464 | BreakpointSP |
| 465 | Target::CreateBreakpoint(const FileSpecList *containingModules, |
| 466 | const FileSpecList *containingSourceFiles, |
| 467 | const char *func_names[], size_t num_names, |
| 468 | FunctionNameType func_name_type_mask, |
| 469 | LanguageType language, lldb::addr_t offset, |
| 470 | LazyBool skip_prologue, bool internal, bool hardware) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 471 | BreakpointSP bp_sp; |
| 472 | if (num_names > 0) { |
| 473 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList( |
| 474 | containingModules, containingSourceFiles)); |
| 475 | |
| 476 | if (skip_prologue == eLazyBoolCalculate) { |
| 477 | if (offset == 0) |
Greg Clayton | 03da4cc | 2013-04-19 21:31:16 +0000 | [diff] [blame] | 478 | skip_prologue = GetSkipPrologue() ? eLazyBoolYes : eLazyBoolNo; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 479 | else |
| 480 | skip_prologue = eLazyBoolNo; |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 481 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 482 | if (language == lldb::eLanguageTypeUnknown) |
| 483 | language = GetLanguage(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 484 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 485 | BreakpointResolverSP resolver_sp(new BreakpointResolverName( |
| 486 | nullptr, func_names, num_names, func_name_type_mask, language, offset, |
| 487 | skip_prologue)); |
| 488 | resolver_sp->SetOffset(offset); |
| 489 | bp_sp = CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true); |
| 490 | } |
| 491 | return bp_sp; |
Jim Ingham | 133e0fb | 2012-03-03 02:05:11 +0000 | [diff] [blame] | 492 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 493 | |
| 494 | SearchFilterSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 495 | Target::GetSearchFilterForModule(const FileSpec *containingModule) { |
| 496 | SearchFilterSP filter_sp; |
| 497 | if (containingModule != nullptr) { |
| 498 | // TODO: We should look into sharing module based search filters |
| 499 | // across many breakpoints like we do for the simple target based one |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 500 | filter_sp = std::make_shared<SearchFilterByModule>(shared_from_this(), |
| 501 | *containingModule); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 502 | } else { |
| 503 | if (!m_search_filter_sp) |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 504 | m_search_filter_sp = |
| 505 | std::make_shared<SearchFilterForUnconstrainedSearches>( |
| 506 | shared_from_this()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 507 | filter_sp = m_search_filter_sp; |
| 508 | } |
| 509 | return filter_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | } |
| 511 | |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 512 | SearchFilterSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 513 | Target::GetSearchFilterForModuleList(const FileSpecList *containingModules) { |
| 514 | SearchFilterSP filter_sp; |
| 515 | if (containingModules && containingModules->GetSize() != 0) { |
| 516 | // TODO: We should look into sharing module based search filters |
| 517 | // across many breakpoints like we do for the simple target based one |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 518 | filter_sp = std::make_shared<SearchFilterByModuleList>(shared_from_this(), |
| 519 | *containingModules); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 520 | } else { |
| 521 | if (!m_search_filter_sp) |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 522 | m_search_filter_sp = |
| 523 | std::make_shared<SearchFilterForUnconstrainedSearches>( |
| 524 | shared_from_this()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 525 | filter_sp = m_search_filter_sp; |
| 526 | } |
| 527 | return filter_sp; |
Jim Ingham | 969795f | 2011-09-21 01:17:13 +0000 | [diff] [blame] | 528 | } |
| 529 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 530 | SearchFilterSP Target::GetSearchFilterForModuleAndCUList( |
| 531 | const FileSpecList *containingModules, |
| 532 | const FileSpecList *containingSourceFiles) { |
| 533 | if (containingSourceFiles == nullptr || containingSourceFiles->GetSize() == 0) |
| 534 | return GetSearchFilterForModuleList(containingModules); |
| 535 | |
| 536 | SearchFilterSP filter_sp; |
| 537 | if (containingModules == nullptr) { |
| 538 | // We could make a special "CU List only SearchFilter". Better yet was if |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 539 | // these could be composable, but that will take a little reworking. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 540 | |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 541 | filter_sp = std::make_shared<SearchFilterByModuleListAndCU>( |
| 542 | shared_from_this(), FileSpecList(), *containingSourceFiles); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 543 | } else { |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 544 | filter_sp = std::make_shared<SearchFilterByModuleListAndCU>( |
| 545 | shared_from_this(), *containingModules, *containingSourceFiles); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 546 | } |
| 547 | return filter_sp; |
Jim Ingham | 87df91b | 2011-09-23 00:54:11 +0000 | [diff] [blame] | 548 | } |
| 549 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 550 | BreakpointSP Target::CreateFuncRegexBreakpoint( |
| 551 | const FileSpecList *containingModules, |
| 552 | const FileSpecList *containingSourceFiles, RegularExpression &func_regex, |
| 553 | lldb::LanguageType requested_language, LazyBool skip_prologue, |
| 554 | bool internal, bool hardware) { |
| 555 | SearchFilterSP filter_sp(GetSearchFilterForModuleAndCUList( |
| 556 | containingModules, containingSourceFiles)); |
| 557 | bool skip = (skip_prologue == eLazyBoolCalculate) |
| 558 | ? GetSkipPrologue() |
| 559 | : static_cast<bool>(skip_prologue); |
| 560 | BreakpointResolverSP resolver_sp(new BreakpointResolverName( |
| 561 | nullptr, func_regex, requested_language, 0, skip)); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 562 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 563 | return CreateBreakpoint(filter_sp, resolver_sp, internal, hardware, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 566 | lldb::BreakpointSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 567 | Target::CreateExceptionBreakpoint(enum lldb::LanguageType language, |
| 568 | bool catch_bp, bool throw_bp, bool internal, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 569 | Args *additional_args, Status *error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 570 | BreakpointSP exc_bkpt_sp = LanguageRuntime::CreateExceptionBreakpoint( |
| 571 | *this, language, catch_bp, throw_bp, internal); |
| 572 | if (exc_bkpt_sp && additional_args) { |
Alex Langford | 7f9c9f2 | 2019-06-21 19:43:07 +0000 | [diff] [blame] | 573 | BreakpointPreconditionSP precondition_sp = exc_bkpt_sp->GetPrecondition(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 574 | if (precondition_sp && additional_args) { |
| 575 | if (error) |
| 576 | *error = precondition_sp->ConfigurePrecondition(*additional_args); |
| 577 | else |
| 578 | precondition_sp->ConfigurePrecondition(*additional_args); |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 579 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 580 | } |
| 581 | return exc_bkpt_sp; |
Jim Ingham | 219ba19 | 2012-03-05 04:47:34 +0000 | [diff] [blame] | 582 | } |
Jim Ingham | a72b31c | 2015-04-22 19:42:18 +0000 | [diff] [blame] | 583 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 584 | lldb::BreakpointSP Target::CreateScriptedBreakpoint( |
| 585 | const llvm::StringRef class_name, const FileSpecList *containingModules, |
| 586 | const FileSpecList *containingSourceFiles, bool internal, |
| 587 | bool request_hardware, StructuredData::ObjectSP extra_args_sp, |
| 588 | Status *creation_error) { |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 589 | SearchFilterSP filter_sp; |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 590 | |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 591 | lldb::SearchDepth depth = lldb::eSearchDepthTarget; |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 592 | bool has_files = |
| 593 | containingSourceFiles && containingSourceFiles->GetSize() > 0; |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 594 | bool has_modules = containingModules && containingModules->GetSize() > 0; |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 595 | |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 596 | if (has_files && has_modules) { |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 597 | filter_sp = GetSearchFilterForModuleAndCUList(containingModules, |
| 598 | containingSourceFiles); |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 599 | } else if (has_files) { |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 600 | filter_sp = |
| 601 | GetSearchFilterForModuleAndCUList(nullptr, containingSourceFiles); |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 602 | } else if (has_modules) { |
| 603 | filter_sp = GetSearchFilterForModuleList(containingModules); |
| 604 | } else { |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 605 | filter_sp = std::make_shared<SearchFilterForUnconstrainedSearches>( |
| 606 | shared_from_this()); |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 607 | } |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 608 | |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 609 | StructuredDataImpl *extra_args_impl = new StructuredDataImpl(); |
| 610 | if (extra_args_sp) |
| 611 | extra_args_impl->SetObjectSP(extra_args_sp); |
Jonas Devlieghere | 2b29b43 | 2019-04-26 22:43:16 +0000 | [diff] [blame] | 612 | |
| 613 | BreakpointResolverSP resolver_sp(new BreakpointResolverScripted( |
| 614 | nullptr, class_name, depth, extra_args_impl, |
| 615 | *GetDebugger().GetScriptInterpreter())); |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 616 | return CreateBreakpoint(filter_sp, resolver_sp, internal, false, true); |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 617 | } |
| 618 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 619 | BreakpointSP Target::CreateBreakpoint(SearchFilterSP &filter_sp, |
| 620 | BreakpointResolverSP &resolver_sp, |
| 621 | bool internal, bool request_hardware, |
| 622 | bool resolve_indirect_symbols) { |
| 623 | BreakpointSP bp_sp; |
| 624 | if (filter_sp && resolver_sp) { |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 625 | const bool hardware = request_hardware || GetRequireHardwareBreakpoints(); |
| 626 | bp_sp.reset(new Breakpoint(*this, filter_sp, resolver_sp, hardware, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 627 | resolve_indirect_symbols)); |
| 628 | resolver_sp->SetBreakpoint(bp_sp.get()); |
| 629 | AddBreakpoint(bp_sp, internal); |
| 630 | } |
| 631 | return bp_sp; |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 632 | } |
| 633 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 634 | void Target::AddBreakpoint(lldb::BreakpointSP bp_sp, bool internal) { |
| 635 | if (!bp_sp) |
| 636 | return; |
| 637 | if (internal) |
| 638 | m_internal_breakpoint_list.Add(bp_sp, false); |
| 639 | else |
| 640 | m_breakpoint_list.Add(bp_sp, true); |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 641 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 642 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); |
| 643 | if (log) { |
| 644 | StreamString s; |
| 645 | bp_sp->GetDescription(&s, lldb::eDescriptionLevelVerbose); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 646 | LLDB_LOGF(log, "Target::%s (internal = %s) => break_id = %s\n", |
| 647 | __FUNCTION__, bp_sp->IsInternal() ? "yes" : "no", s.GetData()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 648 | } |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 649 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 650 | bp_sp->ResolveBreakpoint(); |
Jim Ingham | 33df7cd | 2014-12-06 01:28:03 +0000 | [diff] [blame] | 651 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 652 | if (!internal) { |
| 653 | m_last_created_breakpoint = bp_sp; |
| 654 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 655 | } |
| 656 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 657 | void Target::AddNameToBreakpoint(BreakpointID &id, const char *name, |
| 658 | Status &error) { |
| 659 | BreakpointSP bp_sp = |
| 660 | m_breakpoint_list.FindBreakpointByID(id.GetBreakpointID()); |
| 661 | if (!bp_sp) { |
| 662 | StreamString s; |
| 663 | id.GetDescription(&s, eDescriptionLevelBrief); |
| 664 | error.SetErrorStringWithFormat("Could not find breakpoint %s", s.GetData()); |
| 665 | return; |
| 666 | } |
| 667 | AddNameToBreakpoint(bp_sp, name, error); |
| 668 | } |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 669 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 670 | void Target::AddNameToBreakpoint(BreakpointSP &bp_sp, const char *name, |
| 671 | Status &error) { |
| 672 | if (!bp_sp) |
| 673 | return; |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 674 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 675 | BreakpointName *bp_name = FindBreakpointName(ConstString(name), true, error); |
| 676 | if (!bp_name) |
| 677 | return; |
| 678 | |
| 679 | bp_name->ConfigureBreakpoint(bp_sp); |
| 680 | bp_sp->AddName(name); |
| 681 | } |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 682 | |
| 683 | void Target::AddBreakpointName(BreakpointName *bp_name) { |
| 684 | m_breakpoint_names.insert(std::make_pair(bp_name->GetName(), bp_name)); |
| 685 | } |
| 686 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 687 | BreakpointName *Target::FindBreakpointName(ConstString name, bool can_create, |
| 688 | Status &error) { |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 689 | BreakpointID::StringIsBreakpointName(name.GetStringRef(), error); |
| 690 | if (!error.Success()) |
| 691 | return nullptr; |
| 692 | |
| 693 | BreakpointNameList::iterator iter = m_breakpoint_names.find(name); |
| 694 | if (iter == m_breakpoint_names.end()) { |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 695 | if (!can_create) { |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 696 | error.SetErrorStringWithFormat("Breakpoint name \"%s\" doesn't exist and " |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 697 | "can_create is false.", |
| 698 | name.AsCString()); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 699 | return nullptr; |
| 700 | } |
| 701 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 702 | iter = m_breakpoint_names |
| 703 | .insert(std::make_pair(name, new BreakpointName(name))) |
| 704 | .first; |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 705 | } |
| 706 | return (iter->second); |
| 707 | } |
| 708 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 709 | void Target::DeleteBreakpointName(ConstString name) { |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 710 | BreakpointNameList::iterator iter = m_breakpoint_names.find(name); |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 711 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 712 | if (iter != m_breakpoint_names.end()) { |
| 713 | const char *name_cstr = name.AsCString(); |
| 714 | m_breakpoint_names.erase(iter); |
| 715 | for (auto bp_sp : m_breakpoint_list.Breakpoints()) |
| 716 | bp_sp->RemoveName(name_cstr); |
| 717 | } |
| 718 | } |
| 719 | |
| 720 | void Target::RemoveNameFromBreakpoint(lldb::BreakpointSP &bp_sp, |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 721 | ConstString name) { |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 722 | bp_sp->RemoveName(name.AsCString()); |
| 723 | } |
| 724 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 725 | void Target::ConfigureBreakpointName( |
| 726 | BreakpointName &bp_name, const BreakpointOptions &new_options, |
| 727 | const BreakpointName::Permissions &new_permissions) { |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 728 | bp_name.GetOptions().CopyOverSetOptions(new_options); |
| 729 | bp_name.GetPermissions().MergeInto(new_permissions); |
| 730 | ApplyNameToBreakpoints(bp_name); |
| 731 | } |
| 732 | |
| 733 | void Target::ApplyNameToBreakpoints(BreakpointName &bp_name) { |
| 734 | BreakpointList bkpts_with_name(false); |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 735 | m_breakpoint_list.FindBreakpointsByName(bp_name.GetName().AsCString(), |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 736 | bkpts_with_name); |
| 737 | |
| 738 | for (auto bp_sp : bkpts_with_name.Breakpoints()) |
| 739 | bp_name.ConfigureBreakpoint(bp_sp); |
| 740 | } |
| 741 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 742 | void Target::GetBreakpointNames(std::vector<std::string> &names) { |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 743 | names.clear(); |
| 744 | for (auto bp_name : m_breakpoint_names) { |
| 745 | names.push_back(bp_name.first.AsCString()); |
| 746 | } |
Jonas Devlieghere | 9bbba27 | 2019-01-08 23:25:06 +0000 | [diff] [blame] | 747 | llvm::sort(names.begin(), names.end()); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 750 | bool Target::ProcessIsValid() { |
| 751 | return (m_process_sp && m_process_sp->IsAlive()); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 752 | } |
| 753 | |
Jason Molenda | c0e793d | 2018-11-09 22:33:26 +0000 | [diff] [blame] | 754 | static bool CheckIfWatchpointsSupported(Target *target, Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 755 | uint32_t num_supported_hardware_watchpoints; |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 756 | Status rc = target->GetProcessSP()->GetWatchpointSupportInfo( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 757 | num_supported_hardware_watchpoints); |
Jason Molenda | c0e793d | 2018-11-09 22:33:26 +0000 | [diff] [blame] | 758 | |
| 759 | // If unable to determine the # of watchpoints available, |
| 760 | // assume they are supported. |
| 761 | if (rc.Fail()) |
| 762 | return true; |
| 763 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 764 | if (num_supported_hardware_watchpoints == 0) { |
| 765 | error.SetErrorStringWithFormat( |
| 766 | "Target supports (%u) hardware watchpoint slots.\n", |
| 767 | num_supported_hardware_watchpoints); |
| 768 | return false; |
| 769 | } |
| 770 | return true; |
Johnny Chen | b90827e | 2012-06-04 23:19:54 +0000 | [diff] [blame] | 771 | } |
| 772 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 773 | // See also Watchpoint::SetWatchpointType(uint32_t type) and the |
| 774 | // OptionGroupWatchpoint::WatchType enum type. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 775 | WatchpointSP Target::CreateWatchpoint(lldb::addr_t addr, size_t size, |
| 776 | const CompilerType *type, uint32_t kind, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 777 | Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 778 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 779 | LLDB_LOGF(log, |
| 780 | "Target::%s (addr = 0x%8.8" PRIx64 " size = %" PRIu64 |
| 781 | " type = %u)\n", |
| 782 | __FUNCTION__, addr, (uint64_t)size, kind); |
Johnny Chen | 0c40637 | 2011-09-14 20:23:45 +0000 | [diff] [blame] | 783 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 784 | WatchpointSP wp_sp; |
| 785 | if (!ProcessIsValid()) { |
| 786 | error.SetErrorString("process is not alive"); |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 787 | return wp_sp; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 788 | } |
Johnny Chen | 887062a | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 789 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 790 | if (addr == LLDB_INVALID_ADDRESS || size == 0) { |
| 791 | if (size == 0) |
| 792 | error.SetErrorString("cannot set a watchpoint with watch_size of 0"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 793 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 794 | error.SetErrorStringWithFormat("invalid watch address: %" PRIu64, addr); |
| 795 | return wp_sp; |
| 796 | } |
| 797 | |
| 798 | if (!LLDB_WATCH_TYPE_IS_VALID(kind)) { |
| 799 | error.SetErrorStringWithFormat("invalid watchpoint type: %d", kind); |
| 800 | } |
| 801 | |
Jason Molenda | c0e793d | 2018-11-09 22:33:26 +0000 | [diff] [blame] | 802 | if (!CheckIfWatchpointsSupported(this, error)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 803 | return wp_sp; |
| 804 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 805 | // Currently we only support one watchpoint per address, with total number of |
| 806 | // watchpoints limited by the hardware which the inferior is running on. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 807 | |
| 808 | // Grab the list mutex while doing operations. |
| 809 | const bool notify = false; // Don't notify about all the state changes we do |
| 810 | // on creating the watchpoint. |
| 811 | std::unique_lock<std::recursive_mutex> lock; |
| 812 | this->GetWatchpointList().GetListMutex(lock); |
| 813 | WatchpointSP matched_sp = m_watchpoint_list.FindByAddress(addr); |
| 814 | if (matched_sp) { |
| 815 | size_t old_size = matched_sp->GetByteSize(); |
| 816 | uint32_t old_type = |
| 817 | (matched_sp->WatchpointRead() ? LLDB_WATCH_TYPE_READ : 0) | |
| 818 | (matched_sp->WatchpointWrite() ? LLDB_WATCH_TYPE_WRITE : 0); |
| 819 | // Return the existing watchpoint if both size and type match. |
| 820 | if (size == old_size && kind == old_type) { |
| 821 | wp_sp = matched_sp; |
| 822 | wp_sp->SetEnabled(false, notify); |
| 823 | } else { |
| 824 | // Nil the matched watchpoint; we will be creating a new one. |
| 825 | m_process_sp->DisableWatchpoint(matched_sp.get(), notify); |
| 826 | m_watchpoint_list.Remove(matched_sp->GetID(), true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 827 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | if (!wp_sp) { |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 831 | wp_sp = std::make_shared<Watchpoint>(*this, addr, size, type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 832 | wp_sp->SetWatchpointType(kind, notify); |
| 833 | m_watchpoint_list.Add(wp_sp, true); |
| 834 | } |
| 835 | |
| 836 | error = m_process_sp->EnableWatchpoint(wp_sp.get(), notify); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 837 | LLDB_LOGF(log, "Target::%s (creation of watchpoint %s with id = %u)\n", |
| 838 | __FUNCTION__, error.Success() ? "succeeded" : "failed", |
| 839 | wp_sp->GetID()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 840 | |
| 841 | if (error.Fail()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 842 | // Enabling the watchpoint on the device side failed. Remove the said |
| 843 | // watchpoint from the list maintained by the target instance. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 844 | m_watchpoint_list.Remove(wp_sp->GetID(), true); |
| 845 | // See if we could provide more helpful error message. |
| 846 | if (!OptionGroupWatchpoint::IsWatchSizeSupported(size)) |
| 847 | error.SetErrorStringWithFormat( |
| 848 | "watch size of %" PRIu64 " is not supported", (uint64_t)size); |
| 849 | |
| 850 | wp_sp.reset(); |
| 851 | } else |
| 852 | m_last_created_watchpoint = wp_sp; |
| 853 | return wp_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 854 | } |
| 855 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 856 | void Target::RemoveAllowedBreakpoints() { |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 857 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 858 | LLDB_LOGF(log, "Target::%s \n", __FUNCTION__); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 859 | |
| 860 | m_breakpoint_list.RemoveAllowed(true); |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 861 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 862 | m_last_created_breakpoint.reset(); |
| 863 | } |
| 864 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 865 | void Target::RemoveAllBreakpoints(bool internal_also) { |
| 866 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 867 | LLDB_LOGF(log, "Target::%s (internal_also = %s)\n", __FUNCTION__, |
| 868 | internal_also ? "yes" : "no"); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 869 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 870 | m_breakpoint_list.RemoveAll(true); |
| 871 | if (internal_also) |
| 872 | m_internal_breakpoint_list.RemoveAll(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 873 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 874 | m_last_created_breakpoint.reset(); |
| 875 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 876 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 877 | void Target::DisableAllBreakpoints(bool internal_also) { |
| 878 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 879 | LLDB_LOGF(log, "Target::%s (internal_also = %s)\n", __FUNCTION__, |
| 880 | internal_also ? "yes" : "no"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 881 | |
| 882 | m_breakpoint_list.SetEnabledAll(false); |
| 883 | if (internal_also) |
| 884 | m_internal_breakpoint_list.SetEnabledAll(false); |
| 885 | } |
| 886 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 887 | void Target::DisableAllowedBreakpoints() { |
| 888 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 889 | LLDB_LOGF(log, "Target::%s", __FUNCTION__); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 890 | |
| 891 | m_breakpoint_list.SetEnabledAllowed(false); |
| 892 | } |
| 893 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 894 | void Target::EnableAllBreakpoints(bool internal_also) { |
| 895 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 896 | LLDB_LOGF(log, "Target::%s (internal_also = %s)\n", __FUNCTION__, |
| 897 | internal_also ? "yes" : "no"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 898 | |
| 899 | m_breakpoint_list.SetEnabledAll(true); |
| 900 | if (internal_also) |
| 901 | m_internal_breakpoint_list.SetEnabledAll(true); |
| 902 | } |
| 903 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 904 | void Target::EnableAllowedBreakpoints() { |
| 905 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 906 | LLDB_LOGF(log, "Target::%s", __FUNCTION__); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 907 | |
| 908 | m_breakpoint_list.SetEnabledAllowed(true); |
| 909 | } |
| 910 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 911 | bool Target::RemoveBreakpointByID(break_id_t break_id) { |
| 912 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 913 | LLDB_LOGF(log, "Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, |
| 914 | break_id, LLDB_BREAK_ID_IS_INTERNAL(break_id) ? "yes" : "no"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 915 | |
| 916 | if (DisableBreakpointByID(break_id)) { |
| 917 | if (LLDB_BREAK_ID_IS_INTERNAL(break_id)) |
| 918 | m_internal_breakpoint_list.Remove(break_id, false); |
| 919 | else { |
| 920 | if (m_last_created_breakpoint) { |
| 921 | if (m_last_created_breakpoint->GetID() == break_id) |
| 922 | m_last_created_breakpoint.reset(); |
| 923 | } |
| 924 | m_breakpoint_list.Remove(break_id, true); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 925 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 926 | return true; |
| 927 | } |
| 928 | return false; |
| 929 | } |
| 930 | |
| 931 | bool Target::DisableBreakpointByID(break_id_t break_id) { |
| 932 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 933 | LLDB_LOGF(log, "Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, |
| 934 | break_id, LLDB_BREAK_ID_IS_INTERNAL(break_id) ? "yes" : "no"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 935 | |
| 936 | BreakpointSP bp_sp; |
| 937 | |
| 938 | if (LLDB_BREAK_ID_IS_INTERNAL(break_id)) |
| 939 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID(break_id); |
| 940 | else |
| 941 | bp_sp = m_breakpoint_list.FindBreakpointByID(break_id); |
| 942 | if (bp_sp) { |
| 943 | bp_sp->SetEnabled(false); |
| 944 | return true; |
| 945 | } |
| 946 | return false; |
| 947 | } |
| 948 | |
| 949 | bool Target::EnableBreakpointByID(break_id_t break_id) { |
| 950 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_BREAKPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 951 | LLDB_LOGF(log, "Target::%s (break_id = %i, internal = %s)\n", __FUNCTION__, |
| 952 | break_id, LLDB_BREAK_ID_IS_INTERNAL(break_id) ? "yes" : "no"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 953 | |
| 954 | BreakpointSP bp_sp; |
| 955 | |
| 956 | if (LLDB_BREAK_ID_IS_INTERNAL(break_id)) |
| 957 | bp_sp = m_internal_breakpoint_list.FindBreakpointByID(break_id); |
| 958 | else |
| 959 | bp_sp = m_breakpoint_list.FindBreakpointByID(break_id); |
| 960 | |
| 961 | if (bp_sp) { |
| 962 | bp_sp->SetEnabled(true); |
| 963 | return true; |
| 964 | } |
| 965 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 966 | } |
| 967 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 968 | Status Target::SerializeBreakpointsToFile(const FileSpec &file, |
| 969 | const BreakpointIDList &bp_ids, |
| 970 | bool append) { |
| 971 | Status error; |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 972 | |
| 973 | if (!file) { |
| 974 | error.SetErrorString("Invalid FileSpec."); |
| 975 | return error; |
| 976 | } |
| 977 | |
| 978 | std::string path(file.GetPath()); |
Jim Ingham | 2d3628e | 2016-09-22 23:42:42 +0000 | [diff] [blame] | 979 | StructuredData::ObjectSP input_data_sp; |
| 980 | |
| 981 | StructuredData::ArraySP break_store_sp; |
| 982 | StructuredData::Array *break_store_ptr = nullptr; |
| 983 | |
| 984 | if (append) { |
| 985 | input_data_sp = StructuredData::ParseJSONFromFile(file, error); |
| 986 | if (error.Success()) { |
| 987 | break_store_ptr = input_data_sp->GetAsArray(); |
| 988 | if (!break_store_ptr) { |
| 989 | error.SetErrorStringWithFormat( |
| 990 | "Tried to append to invalid input file %s", path.c_str()); |
| 991 | return error; |
| 992 | } |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | if (!break_store_ptr) { |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 997 | break_store_sp = std::make_shared<StructuredData::Array>(); |
Jim Ingham | 2d3628e | 2016-09-22 23:42:42 +0000 | [diff] [blame] | 998 | break_store_ptr = break_store_sp.get(); |
| 999 | } |
| 1000 | |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1001 | StreamFile out_file(path.c_str(), |
| 1002 | File::OpenOptions::eOpenOptionTruncate | |
| 1003 | File::OpenOptions::eOpenOptionWrite | |
| 1004 | File::OpenOptions::eOpenOptionCanCreate | |
| 1005 | File::OpenOptions::eOpenOptionCloseOnExec, |
| 1006 | lldb::eFilePermissionsFileDefault); |
| 1007 | if (!out_file.GetFile().IsValid()) { |
| 1008 | error.SetErrorStringWithFormat("Unable to open output file: %s.", |
| 1009 | path.c_str()); |
| 1010 | return error; |
| 1011 | } |
| 1012 | |
| 1013 | std::unique_lock<std::recursive_mutex> lock; |
| 1014 | GetBreakpointList().GetListMutex(lock); |
| 1015 | |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1016 | if (bp_ids.GetSize() == 0) { |
| 1017 | const BreakpointList &breakpoints = GetBreakpointList(); |
| 1018 | |
| 1019 | size_t num_breakpoints = breakpoints.GetSize(); |
| 1020 | for (size_t i = 0; i < num_breakpoints; i++) { |
| 1021 | Breakpoint *bp = breakpoints.GetBreakpointAtIndex(i).get(); |
| 1022 | StructuredData::ObjectSP bkpt_save_sp = bp->SerializeToStructuredData(); |
| 1023 | // If a breakpoint can't serialize it, just ignore it for now: |
| 1024 | if (bkpt_save_sp) |
Jim Ingham | 2d3628e | 2016-09-22 23:42:42 +0000 | [diff] [blame] | 1025 | break_store_ptr->AddItem(bkpt_save_sp); |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1026 | } |
| 1027 | } else { |
| 1028 | |
| 1029 | std::unordered_set<lldb::break_id_t> processed_bkpts; |
| 1030 | const size_t count = bp_ids.GetSize(); |
| 1031 | for (size_t i = 0; i < count; ++i) { |
| 1032 | BreakpointID cur_bp_id = bp_ids.GetBreakpointIDAtIndex(i); |
| 1033 | lldb::break_id_t bp_id = cur_bp_id.GetBreakpointID(); |
| 1034 | |
| 1035 | if (bp_id != LLDB_INVALID_BREAK_ID) { |
| 1036 | // Only do each breakpoint once: |
| 1037 | std::pair<std::unordered_set<lldb::break_id_t>::iterator, bool> |
| 1038 | insert_result = processed_bkpts.insert(bp_id); |
| 1039 | if (!insert_result.second) |
| 1040 | continue; |
| 1041 | |
| 1042 | Breakpoint *bp = GetBreakpointByID(bp_id).get(); |
| 1043 | StructuredData::ObjectSP bkpt_save_sp = bp->SerializeToStructuredData(); |
| 1044 | // If the user explicitly asked to serialize a breakpoint, and we |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1045 | // can't, then raise an error: |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1046 | if (!bkpt_save_sp) { |
| 1047 | error.SetErrorStringWithFormat("Unable to serialize breakpoint %d", |
| 1048 | bp_id); |
| 1049 | return error; |
| 1050 | } |
Jim Ingham | 2d3628e | 2016-09-22 23:42:42 +0000 | [diff] [blame] | 1051 | break_store_ptr->AddItem(bkpt_save_sp); |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1052 | } |
| 1053 | } |
| 1054 | } |
| 1055 | |
Jim Ingham | 2d3628e | 2016-09-22 23:42:42 +0000 | [diff] [blame] | 1056 | break_store_ptr->Dump(out_file, false); |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1057 | out_file.PutChar('\n'); |
| 1058 | return error; |
| 1059 | } |
| 1060 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1061 | Status Target::CreateBreakpointsFromFile(const FileSpec &file, |
| 1062 | BreakpointIDList &new_bps) { |
Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 1063 | std::vector<std::string> no_names; |
| 1064 | return CreateBreakpointsFromFile(file, no_names, new_bps); |
| 1065 | } |
| 1066 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1067 | Status Target::CreateBreakpointsFromFile(const FileSpec &file, |
| 1068 | std::vector<std::string> &names, |
| 1069 | BreakpointIDList &new_bps) { |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1070 | std::unique_lock<std::recursive_mutex> lock; |
| 1071 | GetBreakpointList().GetListMutex(lock); |
| 1072 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1073 | Status error; |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1074 | StructuredData::ObjectSP input_data_sp = |
| 1075 | StructuredData::ParseJSONFromFile(file, error); |
| 1076 | if (!error.Success()) { |
| 1077 | return error; |
| 1078 | } else if (!input_data_sp || !input_data_sp->IsValid()) { |
| 1079 | error.SetErrorStringWithFormat("Invalid JSON from input file: %s.", |
| 1080 | file.GetPath().c_str()); |
| 1081 | return error; |
| 1082 | } |
| 1083 | |
| 1084 | StructuredData::Array *bkpt_array = input_data_sp->GetAsArray(); |
| 1085 | if (!bkpt_array) { |
| 1086 | error.SetErrorStringWithFormat( |
| 1087 | "Invalid breakpoint data from input file: %s.", file.GetPath().c_str()); |
| 1088 | return error; |
| 1089 | } |
| 1090 | |
| 1091 | size_t num_bkpts = bkpt_array->GetSize(); |
Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 1092 | size_t num_names = names.size(); |
| 1093 | |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1094 | for (size_t i = 0; i < num_bkpts; i++) { |
| 1095 | StructuredData::ObjectSP bkpt_object_sp = bkpt_array->GetItemAtIndex(i); |
| 1096 | // Peel off the breakpoint key, and feed the rest to the Breakpoint: |
| 1097 | StructuredData::Dictionary *bkpt_dict = bkpt_object_sp->GetAsDictionary(); |
| 1098 | if (!bkpt_dict) { |
| 1099 | error.SetErrorStringWithFormat( |
| 1100 | "Invalid breakpoint data for element %zu from input file: %s.", i, |
| 1101 | file.GetPath().c_str()); |
| 1102 | return error; |
| 1103 | } |
| 1104 | StructuredData::ObjectSP bkpt_data_sp = |
| 1105 | bkpt_dict->GetValueForKey(Breakpoint::GetSerializationKey()); |
Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 1106 | if (num_names && |
| 1107 | !Breakpoint::SerializedBreakpointMatchesNames(bkpt_data_sp, names)) |
| 1108 | continue; |
| 1109 | |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1110 | BreakpointSP bkpt_sp = |
| 1111 | Breakpoint::CreateFromStructuredData(*this, bkpt_data_sp, error); |
| 1112 | if (!error.Success()) { |
| 1113 | error.SetErrorStringWithFormat( |
| 1114 | "Error restoring breakpoint %zu from %s: %s.", i, |
| 1115 | file.GetPath().c_str(), error.AsCString()); |
| 1116 | return error; |
| 1117 | } |
| 1118 | new_bps.AddBreakpointID(BreakpointID(bkpt_sp->GetID())); |
| 1119 | } |
| 1120 | return error; |
| 1121 | } |
| 1122 | |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 1123 | // The flag 'end_to_end', default to true, signifies that the operation is |
| 1124 | // performed end to end, for both the debugger and the debuggee. |
| 1125 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1126 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end |
| 1127 | // to end operations. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1128 | bool Target::RemoveAllWatchpoints(bool end_to_end) { |
| 1129 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1130 | LLDB_LOGF(log, "Target::%s\n", __FUNCTION__); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1131 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1132 | if (!end_to_end) { |
| 1133 | m_watchpoint_list.RemoveAll(true); |
| 1134 | return true; |
| 1135 | } |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 1136 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1137 | // Otherwise, it's an end to end operation. |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 1138 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1139 | if (!ProcessIsValid()) |
| 1140 | return false; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1141 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1142 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
| 1143 | for (size_t i = 0; i < num_watchpoints; ++i) { |
| 1144 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 1145 | if (!wp_sp) |
| 1146 | return false; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1147 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1148 | Status rc = m_process_sp->DisableWatchpoint(wp_sp.get()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1149 | if (rc.Fail()) |
| 1150 | return false; |
| 1151 | } |
| 1152 | m_watchpoint_list.RemoveAll(true); |
| 1153 | m_last_created_watchpoint.reset(); |
| 1154 | return true; // Success! |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1157 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end |
| 1158 | // to end operations. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1159 | bool Target::DisableAllWatchpoints(bool end_to_end) { |
| 1160 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1161 | LLDB_LOGF(log, "Target::%s\n", __FUNCTION__); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1162 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1163 | if (!end_to_end) { |
| 1164 | m_watchpoint_list.SetEnabledAll(false); |
| 1165 | return true; |
| 1166 | } |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 1167 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1168 | // Otherwise, it's an end to end operation. |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 1169 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1170 | if (!ProcessIsValid()) |
| 1171 | return false; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1172 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1173 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
| 1174 | for (size_t i = 0; i < num_watchpoints; ++i) { |
| 1175 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 1176 | if (!wp_sp) |
| 1177 | return false; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1178 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1179 | Status rc = m_process_sp->DisableWatchpoint(wp_sp.get()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1180 | if (rc.Fail()) |
| 1181 | return false; |
| 1182 | } |
| 1183 | return true; // Success! |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1184 | } |
| 1185 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1186 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list for end |
| 1187 | // to end operations. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1188 | bool Target::EnableAllWatchpoints(bool end_to_end) { |
| 1189 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1190 | LLDB_LOGF(log, "Target::%s\n", __FUNCTION__); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1191 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1192 | if (!end_to_end) { |
| 1193 | m_watchpoint_list.SetEnabledAll(true); |
| 1194 | return true; |
| 1195 | } |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 1196 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1197 | // Otherwise, it's an end to end operation. |
Johnny Chen | edf5037 | 2011-09-23 21:21:43 +0000 | [diff] [blame] | 1198 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1199 | if (!ProcessIsValid()) |
| 1200 | return false; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1201 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1202 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
| 1203 | for (size_t i = 0; i < num_watchpoints; ++i) { |
| 1204 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 1205 | if (!wp_sp) |
| 1206 | return false; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1207 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1208 | Status rc = m_process_sp->EnableWatchpoint(wp_sp.get()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1209 | if (rc.Fail()) |
| 1210 | return false; |
| 1211 | } |
| 1212 | return true; // Success! |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
Johnny Chen | a4d6bc9 | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 1215 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1216 | bool Target::ClearAllWatchpointHitCounts() { |
| 1217 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1218 | LLDB_LOGF(log, "Target::%s\n", __FUNCTION__); |
Johnny Chen | a4d6bc9 | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 1219 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1220 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
| 1221 | for (size_t i = 0; i < num_watchpoints; ++i) { |
| 1222 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 1223 | if (!wp_sp) |
| 1224 | return false; |
Johnny Chen | a4d6bc9 | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 1225 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1226 | wp_sp->ResetHitCount(); |
| 1227 | } |
| 1228 | return true; // Success! |
Johnny Chen | a4d6bc9 | 2012-02-25 06:44:30 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Enrico Granata | 5e3fe04 | 2015-02-11 00:37:54 +0000 | [diff] [blame] | 1231 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1232 | bool Target::ClearAllWatchpointHistoricValues() { |
| 1233 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1234 | LLDB_LOGF(log, "Target::%s\n", __FUNCTION__); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1235 | |
| 1236 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
| 1237 | for (size_t i = 0; i < num_watchpoints; ++i) { |
| 1238 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 1239 | if (!wp_sp) |
| 1240 | return false; |
| 1241 | |
| 1242 | wp_sp->ResetHistoricValues(); |
| 1243 | } |
| 1244 | return true; // Success! |
Enrico Granata | 5e3fe04 | 2015-02-11 00:37:54 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1247 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list during |
| 1248 | // these operations. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1249 | bool Target::IgnoreAllWatchpoints(uint32_t ignore_count) { |
| 1250 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1251 | LLDB_LOGF(log, "Target::%s\n", __FUNCTION__); |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 1252 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1253 | if (!ProcessIsValid()) |
| 1254 | return false; |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 1255 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1256 | size_t num_watchpoints = m_watchpoint_list.GetSize(); |
| 1257 | for (size_t i = 0; i < num_watchpoints; ++i) { |
| 1258 | WatchpointSP wp_sp = m_watchpoint_list.GetByIndex(i); |
| 1259 | if (!wp_sp) |
| 1260 | return false; |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 1261 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1262 | wp_sp->SetIgnoreCount(ignore_count); |
| 1263 | } |
| 1264 | return true; // Success! |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 1265 | } |
| 1266 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1267 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1268 | bool Target::DisableWatchpointByID(lldb::watch_id_t watch_id) { |
| 1269 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1270 | LLDB_LOGF(log, "Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1271 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1272 | if (!ProcessIsValid()) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1273 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1274 | |
| 1275 | WatchpointSP wp_sp = m_watchpoint_list.FindByID(watch_id); |
| 1276 | if (wp_sp) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1277 | Status rc = m_process_sp->DisableWatchpoint(wp_sp.get()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1278 | if (rc.Success()) |
| 1279 | return true; |
| 1280 | |
| 1281 | // Else, fallthrough. |
| 1282 | } |
| 1283 | return false; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1286 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1287 | bool Target::EnableWatchpointByID(lldb::watch_id_t watch_id) { |
| 1288 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1289 | LLDB_LOGF(log, "Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1290 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1291 | if (!ProcessIsValid()) |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1292 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1293 | |
| 1294 | WatchpointSP wp_sp = m_watchpoint_list.FindByID(watch_id); |
| 1295 | if (wp_sp) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1296 | Status rc = m_process_sp->EnableWatchpoint(wp_sp.get()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1297 | if (rc.Success()) |
| 1298 | return true; |
| 1299 | |
| 1300 | // Else, fallthrough. |
| 1301 | } |
| 1302 | return false; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1303 | } |
| 1304 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1305 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1306 | bool Target::RemoveWatchpointByID(lldb::watch_id_t watch_id) { |
| 1307 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1308 | LLDB_LOGF(log, "Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1309 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1310 | WatchpointSP watch_to_remove_sp = m_watchpoint_list.FindByID(watch_id); |
| 1311 | if (watch_to_remove_sp == m_last_created_watchpoint) |
| 1312 | m_last_created_watchpoint.reset(); |
| 1313 | |
| 1314 | if (DisableWatchpointByID(watch_id)) { |
| 1315 | m_watchpoint_list.Remove(watch_id, true); |
| 1316 | return true; |
| 1317 | } |
| 1318 | return false; |
Johnny Chen | 86364b4 | 2011-09-20 23:28:55 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
Johnny Chen | 01a6786 | 2011-10-14 00:42:25 +0000 | [diff] [blame] | 1321 | // Assumption: Caller holds the list mutex lock for m_watchpoint_list. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1322 | bool Target::IgnoreWatchpointByID(lldb::watch_id_t watch_id, |
| 1323 | uint32_t ignore_count) { |
| 1324 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_WATCHPOINTS)); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1325 | LLDB_LOGF(log, "Target::%s (watch_id = %i)\n", __FUNCTION__, watch_id); |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 1326 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1327 | if (!ProcessIsValid()) |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 1328 | return false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1329 | |
| 1330 | WatchpointSP wp_sp = m_watchpoint_list.FindByID(watch_id); |
| 1331 | if (wp_sp) { |
| 1332 | wp_sp->SetIgnoreCount(ignore_count); |
| 1333 | return true; |
| 1334 | } |
| 1335 | return false; |
Johnny Chen | 6cc60e8 | 2011-10-05 21:35:46 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1338 | ModuleSP Target::GetExecutableModule() { |
| 1339 | // search for the first executable in the module list |
| 1340 | for (size_t i = 0; i < m_images.GetSize(); ++i) { |
| 1341 | ModuleSP module_sp = m_images.GetModuleAtIndex(i); |
| 1342 | lldb_private::ObjectFile *obj = module_sp->GetObjectFile(); |
| 1343 | if (obj == nullptr) |
| 1344 | continue; |
| 1345 | if (obj->GetType() == ObjectFile::Type::eTypeExecutable) |
| 1346 | return module_sp; |
| 1347 | } |
| 1348 | // as fall back return the first module loaded |
| 1349 | return m_images.GetModuleAtIndex(0); |
Greg Clayton | aa149cb | 2011-08-11 02:48:45 +0000 | [diff] [blame] | 1350 | } |
| 1351 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1352 | Module *Target::GetExecutableModulePointer() { |
| 1353 | return GetExecutableModule().get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1356 | static void LoadScriptingResourceForModule(const ModuleSP &module_sp, |
| 1357 | Target *target) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1358 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1359 | StreamString feedback_stream; |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1360 | if (module_sp && !module_sp->LoadScriptingResourceInTarget( |
| 1361 | target, error, &feedback_stream)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1362 | if (error.AsCString()) |
| 1363 | target->GetDebugger().GetErrorFile()->Printf( |
| 1364 | "unable to load scripting data for module %s - error reported was " |
| 1365 | "%s\n", |
| 1366 | module_sp->GetFileSpec().GetFileNameStrippingExtension().GetCString(), |
| 1367 | error.AsCString()); |
| 1368 | } |
| 1369 | if (feedback_stream.GetSize()) |
| 1370 | target->GetDebugger().GetErrorFile()->Printf("%s\n", |
| 1371 | feedback_stream.GetData()); |
Enrico Granata | 1759848 | 2012-11-08 02:22:02 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1374 | void Target::ClearModules(bool delete_locations) { |
| 1375 | ModulesDidUnload(m_images, delete_locations); |
| 1376 | m_section_load_history.Clear(); |
| 1377 | m_images.Clear(); |
| 1378 | m_scratch_type_system_map.Clear(); |
| 1379 | m_ast_importer_sp.reset(); |
Greg Clayton | 095eeaa | 2013-11-05 23:28:00 +0000 | [diff] [blame] | 1380 | } |
| 1381 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1382 | void Target::DidExec() { |
| 1383 | // When a process exec's we need to know about it so we can do some cleanup. |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 1384 | m_breakpoint_list.RemoveInvalidLocations(m_arch.GetSpec()); |
| 1385 | m_internal_breakpoint_list.RemoveInvalidLocations(m_arch.GetSpec()); |
Greg Clayton | b35db63 | 2013-11-09 00:03:31 +0000 | [diff] [blame] | 1386 | } |
| 1387 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1388 | void Target::SetExecutableModule(ModuleSP &executable_sp, |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 1389 | LoadDependentFiles load_dependent_files) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1390 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET)); |
| 1391 | ClearModules(false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1392 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1393 | if (executable_sp) { |
Pavel Labath | f9d1647 | 2017-05-15 13:02:37 +0000 | [diff] [blame] | 1394 | static Timer::Category func_cat(LLVM_PRETTY_FUNCTION); |
| 1395 | Timer scoped_timer(func_cat, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1396 | "Target::SetExecutableModule (executable = '%s')", |
| 1397 | executable_sp->GetFileSpec().GetPath().c_str()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1398 | |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1399 | const bool notify = true; |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1400 | m_images.Append(executable_sp, |
| 1401 | notify); // The first image is our executable file |
Jason Molenda | e1b68ad | 2012-12-05 00:25:49 +0000 | [diff] [blame] | 1402 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1403 | // If we haven't set an architecture yet, reset our architecture based on |
| 1404 | // what we found in the executable module. |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 1405 | if (!m_arch.GetSpec().IsValid()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1406 | m_arch = executable_sp->GetArchitecture(); |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 1407 | LLDB_LOG(log, |
| 1408 | "setting architecture to {0} ({1}) based on executable file", |
| 1409 | m_arch.GetSpec().GetArchitectureName(), |
| 1410 | m_arch.GetSpec().GetTriple().getTriple()); |
Jason Molenda | dad8af4 | 2015-11-10 04:11:37 +0000 | [diff] [blame] | 1411 | } |
| 1412 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1413 | FileSpecList dependent_files; |
| 1414 | ObjectFile *executable_objfile = executable_sp->GetObjectFile(); |
Jonas Devlieghere | 041e68f | 2018-09-27 06:59:15 +0000 | [diff] [blame] | 1415 | bool load_dependents = true; |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 1416 | switch (load_dependent_files) { |
| 1417 | case eLoadDependentsDefault: |
Jonas Devlieghere | 041e68f | 2018-09-27 06:59:15 +0000 | [diff] [blame] | 1418 | load_dependents = executable_sp->IsExecutable(); |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 1419 | break; |
| 1420 | case eLoadDependentsYes: |
Jonas Devlieghere | 041e68f | 2018-09-27 06:59:15 +0000 | [diff] [blame] | 1421 | load_dependents = true; |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 1422 | break; |
| 1423 | case eLoadDependentsNo: |
Jonas Devlieghere | 041e68f | 2018-09-27 06:59:15 +0000 | [diff] [blame] | 1424 | load_dependents = false; |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 1425 | break; |
| 1426 | } |
Greg Clayton | 095eeaa | 2013-11-05 23:28:00 +0000 | [diff] [blame] | 1427 | |
Jonas Devlieghere | 041e68f | 2018-09-27 06:59:15 +0000 | [diff] [blame] | 1428 | if (executable_objfile && load_dependents) { |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1429 | ModuleList added_modules; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1430 | executable_objfile->GetDependentModules(dependent_files); |
| 1431 | for (uint32_t i = 0; i < dependent_files.GetSize(); i++) { |
| 1432 | FileSpec dependent_file_spec( |
| 1433 | dependent_files.GetFileSpecPointerAtIndex(i)); |
| 1434 | FileSpec platform_dependent_file_spec; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1435 | if (m_platform_sp) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1436 | m_platform_sp->GetFileWithUUID(dependent_file_spec, nullptr, |
| 1437 | platform_dependent_file_spec); |
| 1438 | else |
| 1439 | platform_dependent_file_spec = dependent_file_spec; |
| 1440 | |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 1441 | ModuleSpec module_spec(platform_dependent_file_spec, m_arch.GetSpec()); |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1442 | ModuleSP image_module_sp( |
| 1443 | GetOrCreateModule(module_spec, false /* notify */)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1444 | if (image_module_sp) { |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1445 | added_modules.AppendIfNeeded(image_module_sp, false); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1446 | ObjectFile *objfile = image_module_sp->GetObjectFile(); |
| 1447 | if (objfile) |
| 1448 | objfile->GetDependentModules(dependent_files); |
| 1449 | } |
| 1450 | } |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1451 | ModulesDidLoad(added_modules); |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 1452 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1453 | } |
Jim Ingham | c6674fd | 2011-10-28 23:14:11 +0000 | [diff] [blame] | 1454 | } |
| 1455 | |
Greg Clayton | 19c8f39 | 2018-08-06 16:56:10 +0000 | [diff] [blame] | 1456 | bool Target::SetArchitecture(const ArchSpec &arch_spec, bool set_platform) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1457 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET)); |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 1458 | bool missing_local_arch = !m_arch.GetSpec().IsValid(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1459 | bool replace_local_arch = true; |
| 1460 | bool compatible_local_arch = false; |
| 1461 | ArchSpec other(arch_spec); |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 1462 | |
Greg Clayton | 19c8f39 | 2018-08-06 16:56:10 +0000 | [diff] [blame] | 1463 | // Changing the architecture might mean that the currently selected platform |
| 1464 | // isn't compatible. Set the platform correctly if we are asked to do so, |
| 1465 | // otherwise assume the user will set the platform manually. |
| 1466 | if (set_platform) { |
| 1467 | if (other.IsValid()) { |
| 1468 | auto platform_sp = GetPlatform(); |
| 1469 | if (!platform_sp || |
| 1470 | !platform_sp->IsCompatibleArchitecture(other, false, nullptr)) { |
| 1471 | ArchSpec platform_arch; |
| 1472 | auto arch_platform_sp = |
| 1473 | Platform::GetPlatformForArchitecture(other, &platform_arch); |
| 1474 | if (arch_platform_sp) { |
| 1475 | SetPlatform(arch_platform_sp); |
| 1476 | if (platform_arch.IsValid()) |
| 1477 | other = platform_arch; |
| 1478 | } |
| 1479 | } |
| 1480 | } |
| 1481 | } |
| 1482 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1483 | if (!missing_local_arch) { |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 1484 | if (m_arch.GetSpec().IsCompatibleMatch(arch_spec)) { |
| 1485 | other.MergeFrom(m_arch.GetSpec()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1486 | |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 1487 | if (m_arch.GetSpec().IsCompatibleMatch(other)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1488 | compatible_local_arch = true; |
| 1489 | bool arch_changed, vendor_changed, os_changed, os_ver_changed, |
| 1490 | env_changed; |
| 1491 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1492 | m_arch.GetSpec().PiecewiseTripleCompare(other, arch_changed, |
| 1493 | vendor_changed, os_changed, |
| 1494 | os_ver_changed, env_changed); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1495 | |
| 1496 | if (!arch_changed && !vendor_changed && !os_changed && !env_changed) |
| 1497 | replace_local_arch = false; |
| 1498 | } |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | if (compatible_local_arch || missing_local_arch) { |
| 1503 | // If we haven't got a valid arch spec, or the architectures are compatible |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1504 | // update the architecture, unless the one we already have is more |
| 1505 | // specified |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1506 | if (replace_local_arch) |
| 1507 | m_arch = other; |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 1508 | LLDB_LOG(log, "set architecture to {0} ({1})", |
| 1509 | m_arch.GetSpec().GetArchitectureName(), |
| 1510 | m_arch.GetSpec().GetTriple().getTriple()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1511 | return true; |
| 1512 | } |
| 1513 | |
| 1514 | // If we have an executable file, try to reset the executable to the desired |
| 1515 | // architecture |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1516 | LLDB_LOGF(log, "Target::SetArchitecture changing architecture to %s (%s)", |
| 1517 | arch_spec.GetArchitectureName(), |
| 1518 | arch_spec.GetTriple().getTriple().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1519 | m_arch = other; |
| 1520 | ModuleSP executable_sp = GetExecutableModule(); |
| 1521 | |
| 1522 | ClearModules(true); |
| 1523 | // Need to do something about unsetting breakpoints. |
| 1524 | |
| 1525 | if (executable_sp) { |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1526 | LLDB_LOGF(log, |
| 1527 | "Target::SetArchitecture Trying to select executable file " |
| 1528 | "architecture %s (%s)", |
| 1529 | arch_spec.GetArchitectureName(), |
| 1530 | arch_spec.GetTriple().getTriple().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1531 | ModuleSpec module_spec(executable_sp->GetFileSpec(), other); |
Frederic Riss | acbf005 | 2019-04-23 20:17:04 +0000 | [diff] [blame] | 1532 | FileSpecList search_paths = GetExecutableSearchPaths(); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1533 | Status error = ModuleList::GetSharedModule(module_spec, executable_sp, |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1534 | &search_paths, nullptr, nullptr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1535 | |
| 1536 | if (!error.Fail() && executable_sp) { |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 1537 | SetExecutableModule(executable_sp, eLoadDependentsYes); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1538 | return true; |
| 1539 | } |
| 1540 | } |
| 1541 | return false; |
Greg Clayton | db59823 | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1542 | } |
| 1543 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1544 | bool Target::MergeArchitecture(const ArchSpec &arch_spec) { |
Jason Molenda | df9f796 | 2018-10-23 23:45:56 +0000 | [diff] [blame] | 1545 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1546 | if (arch_spec.IsValid()) { |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 1547 | if (m_arch.GetSpec().IsCompatibleMatch(arch_spec)) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1548 | // The current target arch is compatible with "arch_spec", see if we can |
| 1549 | // improve our current architecture using bits from "arch_spec" |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 1550 | |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 1551 | LLDB_LOGF(log, |
| 1552 | "Target::MergeArchitecture target has arch %s, merging with " |
| 1553 | "arch %s", |
| 1554 | m_arch.GetSpec().GetTriple().getTriple().c_str(), |
| 1555 | arch_spec.GetTriple().getTriple().c_str()); |
Jason Molenda | df9f796 | 2018-10-23 23:45:56 +0000 | [diff] [blame] | 1556 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1557 | // Merge bits from arch_spec into "merged_arch" and set our architecture |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 1558 | ArchSpec merged_arch(m_arch.GetSpec()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1559 | merged_arch.MergeFrom(arch_spec); |
| 1560 | return SetArchitecture(merged_arch); |
| 1561 | } else { |
| 1562 | // The new architecture is different, we just need to replace it |
| 1563 | return SetArchitecture(arch_spec); |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1564 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1565 | } |
| 1566 | return false; |
| 1567 | } |
Greg Clayton | c749eb8 | 2011-07-11 05:12:02 +0000 | [diff] [blame] | 1568 | |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1569 | void Target::NotifyWillClearList(const ModuleList &module_list) {} |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1570 | |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1571 | void Target::NotifyModuleAdded(const ModuleList &module_list, |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1572 | const ModuleSP &module_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1573 | // A module is being added to this target for the first time |
| 1574 | if (m_valid) { |
| 1575 | ModuleList my_module_list; |
| 1576 | my_module_list.Append(module_sp); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1577 | ModulesDidLoad(my_module_list); |
| 1578 | } |
| 1579 | } |
| 1580 | |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1581 | void Target::NotifyModuleRemoved(const ModuleList &module_list, |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1582 | const ModuleSP &module_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1583 | // A module is being removed from this target. |
| 1584 | if (m_valid) { |
| 1585 | ModuleList my_module_list; |
| 1586 | my_module_list.Append(module_sp); |
| 1587 | ModulesDidUnload(my_module_list, false); |
| 1588 | } |
| 1589 | } |
| 1590 | |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1591 | void Target::NotifyModuleUpdated(const ModuleList &module_list, |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1592 | const ModuleSP &old_module_sp, |
| 1593 | const ModuleSP &new_module_sp) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1594 | // A module is replacing an already added module |
| 1595 | if (m_valid) { |
| 1596 | m_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced(old_module_sp, |
| 1597 | new_module_sp); |
| 1598 | m_internal_breakpoint_list.UpdateBreakpointsWhenModuleIsReplaced( |
| 1599 | old_module_sp, new_module_sp); |
| 1600 | } |
| 1601 | } |
| 1602 | |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1603 | void Target::NotifyModulesRemoved(lldb_private::ModuleList &module_list) { |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1604 | ModulesDidUnload(module_list, false); |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1605 | } |
| 1606 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1607 | void Target::ModulesDidLoad(ModuleList &module_list) { |
Jason Molenda | a38b8c8 | 2019-04-22 22:42:29 +0000 | [diff] [blame] | 1608 | const size_t num_images = module_list.GetSize(); |
| 1609 | if (m_valid && num_images) { |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1610 | for (size_t idx = 0; idx < num_images; ++idx) { |
Jason Molenda | a38b8c8 | 2019-04-22 22:42:29 +0000 | [diff] [blame] | 1611 | ModuleSP module_sp(module_list.GetModuleAtIndex(idx)); |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1612 | LoadScriptingResourceForModule(module_sp, this); |
| 1613 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1614 | m_breakpoint_list.UpdateBreakpoints(module_list, true, false); |
| 1615 | m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false); |
| 1616 | if (m_process_sp) { |
| 1617 | m_process_sp->ModulesDidLoad(module_list); |
| 1618 | } |
| 1619 | BroadcastEvent(eBroadcastBitModulesLoaded, |
| 1620 | new TargetEventData(this->shared_from_this(), module_list)); |
| 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | void Target::SymbolsDidLoad(ModuleList &module_list) { |
| 1625 | if (m_valid && module_list.GetSize()) { |
| 1626 | if (m_process_sp) { |
Alex Langford | b978f72 | 2019-06-03 23:12:11 +0000 | [diff] [blame] | 1627 | for (LanguageRuntime *runtime : m_process_sp->GetLanguageRuntimes()) { |
| 1628 | runtime->SymbolsDidLoad(module_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | m_breakpoint_list.UpdateBreakpoints(module_list, true, false); |
| 1633 | m_internal_breakpoint_list.UpdateBreakpoints(module_list, true, false); |
| 1634 | BroadcastEvent(eBroadcastBitSymbolsLoaded, |
| 1635 | new TargetEventData(this->shared_from_this(), module_list)); |
| 1636 | } |
| 1637 | } |
| 1638 | |
| 1639 | void Target::ModulesDidUnload(ModuleList &module_list, bool delete_locations) { |
| 1640 | if (m_valid && module_list.GetSize()) { |
| 1641 | UnloadModuleSections(module_list); |
| 1642 | m_breakpoint_list.UpdateBreakpoints(module_list, false, delete_locations); |
| 1643 | m_internal_breakpoint_list.UpdateBreakpoints(module_list, false, |
| 1644 | delete_locations); |
| 1645 | BroadcastEvent(eBroadcastBitModulesUnloaded, |
| 1646 | new TargetEventData(this->shared_from_this(), module_list)); |
| 1647 | } |
| 1648 | } |
| 1649 | |
| 1650 | bool Target::ModuleIsExcludedForUnconstrainedSearches( |
| 1651 | const FileSpec &module_file_spec) { |
| 1652 | if (GetBreakpointsConsultPlatformAvoidList()) { |
| 1653 | ModuleList matchingModules; |
| 1654 | ModuleSpec module_spec(module_file_spec); |
| 1655 | size_t num_modules = GetImages().FindModules(module_spec, matchingModules); |
| 1656 | |
| 1657 | // If there is more than one module for this file spec, only return true if |
| 1658 | // ALL the modules are on the |
| 1659 | // black list. |
| 1660 | if (num_modules > 0) { |
| 1661 | for (size_t i = 0; i < num_modules; i++) { |
| 1662 | if (!ModuleIsExcludedForUnconstrainedSearches( |
| 1663 | matchingModules.GetModuleAtIndex(i))) |
| 1664 | return false; |
| 1665 | } |
| 1666 | return true; |
| 1667 | } |
| 1668 | } |
| 1669 | return false; |
| 1670 | } |
| 1671 | |
| 1672 | bool Target::ModuleIsExcludedForUnconstrainedSearches( |
| 1673 | const lldb::ModuleSP &module_sp) { |
| 1674 | if (GetBreakpointsConsultPlatformAvoidList()) { |
| 1675 | if (m_platform_sp) |
| 1676 | return m_platform_sp->ModuleIsExcludedForUnconstrainedSearches(*this, |
| 1677 | module_sp); |
| 1678 | } |
| 1679 | return false; |
| 1680 | } |
| 1681 | |
| 1682 | size_t Target::ReadMemoryFromFileCache(const Address &addr, void *dst, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1683 | size_t dst_len, Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1684 | SectionSP section_sp(addr.GetSection()); |
| 1685 | if (section_sp) { |
| 1686 | // If the contents of this section are encrypted, the on-disk file is |
| 1687 | // unusable. Read only from live memory. |
| 1688 | if (section_sp->IsEncrypted()) { |
| 1689 | error.SetErrorString("section is encrypted"); |
| 1690 | return 0; |
| 1691 | } |
| 1692 | ModuleSP module_sp(section_sp->GetModule()); |
| 1693 | if (module_sp) { |
| 1694 | ObjectFile *objfile = section_sp->GetModule()->GetObjectFile(); |
| 1695 | if (objfile) { |
| 1696 | size_t bytes_read = objfile->ReadSectionData( |
| 1697 | section_sp.get(), addr.GetOffset(), dst, dst_len); |
Greg Clayton | db59823 | 2011-01-07 01:57:07 +0000 | [diff] [blame] | 1698 | if (bytes_read > 0) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1699 | return bytes_read; |
Greg Clayton | dda4f7b | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 1700 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1701 | error.SetErrorStringWithFormat("error reading data from section %s", |
| 1702 | section_sp->GetName().GetCString()); |
| 1703 | } else |
| 1704 | error.SetErrorString("address isn't from a object file"); |
| 1705 | } else |
| 1706 | error.SetErrorString("address isn't in a module"); |
| 1707 | } else |
| 1708 | error.SetErrorString("address doesn't contain a section that points to a " |
| 1709 | "section in a object file"); |
| 1710 | |
| 1711 | return 0; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1714 | size_t Target::ReadMemory(const Address &addr, bool prefer_file_cache, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1715 | void *dst, size_t dst_len, Status &error, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1716 | lldb::addr_t *load_addr_ptr) { |
| 1717 | error.Clear(); |
| 1718 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1719 | // if we end up reading this from process memory, we will fill this with the |
| 1720 | // actual load address |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1721 | if (load_addr_ptr) |
| 1722 | *load_addr_ptr = LLDB_INVALID_ADDRESS; |
| 1723 | |
| 1724 | size_t bytes_read = 0; |
| 1725 | |
| 1726 | addr_t load_addr = LLDB_INVALID_ADDRESS; |
| 1727 | addr_t file_addr = LLDB_INVALID_ADDRESS; |
| 1728 | Address resolved_addr; |
| 1729 | if (!addr.IsSectionOffset()) { |
| 1730 | SectionLoadList §ion_load_list = GetSectionLoadList(); |
| 1731 | if (section_load_list.IsEmpty()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1732 | // No sections are loaded, so we must assume we are not running yet and |
| 1733 | // anything we are given is a file address. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1734 | file_addr = addr.GetOffset(); // "addr" doesn't have a section, so its |
| 1735 | // offset is the file address |
| 1736 | m_images.ResolveFileAddress(file_addr, resolved_addr); |
| 1737 | } else { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1738 | // We have at least one section loaded. This can be because we have |
| 1739 | // manually loaded some sections with "target modules load ..." or |
| 1740 | // because we have have a live process that has sections loaded through |
| 1741 | // the dynamic loader |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1742 | load_addr = addr.GetOffset(); // "addr" doesn't have a section, so its |
| 1743 | // offset is the load address |
| 1744 | section_load_list.ResolveLoadAddress(load_addr, resolved_addr); |
| 1745 | } |
| 1746 | } |
| 1747 | if (!resolved_addr.IsValid()) |
| 1748 | resolved_addr = addr; |
| 1749 | |
| 1750 | if (prefer_file_cache) { |
| 1751 | bytes_read = ReadMemoryFromFileCache(resolved_addr, dst, dst_len, error); |
| 1752 | if (bytes_read > 0) |
| 1753 | return bytes_read; |
| 1754 | } |
| 1755 | |
| 1756 | if (ProcessIsValid()) { |
| 1757 | if (load_addr == LLDB_INVALID_ADDRESS) |
| 1758 | load_addr = resolved_addr.GetLoadAddress(this); |
| 1759 | |
| 1760 | if (load_addr == LLDB_INVALID_ADDRESS) { |
| 1761 | ModuleSP addr_module_sp(resolved_addr.GetModule()); |
| 1762 | if (addr_module_sp && addr_module_sp->GetFileSpec()) |
Zachary Turner | 827d5d7 | 2016-12-16 04:27:00 +0000 | [diff] [blame] | 1763 | error.SetErrorStringWithFormatv( |
| 1764 | "{0:F}[{1:x+}] can't be resolved, {0:F} is not currently loaded", |
| 1765 | addr_module_sp->GetFileSpec(), resolved_addr.GetFileAddress()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1766 | else |
| 1767 | error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved", |
| 1768 | resolved_addr.GetFileAddress()); |
| 1769 | } else { |
| 1770 | bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error); |
| 1771 | if (bytes_read != dst_len) { |
| 1772 | if (error.Success()) { |
| 1773 | if (bytes_read == 0) |
| 1774 | error.SetErrorStringWithFormat( |
| 1775 | "read memory from 0x%" PRIx64 " failed", load_addr); |
| 1776 | else |
| 1777 | error.SetErrorStringWithFormat( |
| 1778 | "only %" PRIu64 " of %" PRIu64 |
| 1779 | " bytes were read from memory at 0x%" PRIx64, |
| 1780 | (uint64_t)bytes_read, (uint64_t)dst_len, load_addr); |
| 1781 | } |
| 1782 | } |
| 1783 | if (bytes_read) { |
| 1784 | if (load_addr_ptr) |
| 1785 | *load_addr_ptr = load_addr; |
| 1786 | return bytes_read; |
| 1787 | } |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1788 | // If the address is not section offset we have an address that doesn't |
| 1789 | // resolve to any address in any currently loaded shared libraries and we |
| 1790 | // failed to read memory so there isn't anything more we can do. If it is |
| 1791 | // section offset, we might be able to read cached memory from the object |
| 1792 | // file. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1793 | if (!resolved_addr.IsSectionOffset()) |
| 1794 | return 0; |
| 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | if (!prefer_file_cache && resolved_addr.IsSectionOffset()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1799 | // If we didn't already try and read from the object file cache, then try |
| 1800 | // it after failing to read from the process. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1801 | return ReadMemoryFromFileCache(resolved_addr, dst, dst_len, error); |
| 1802 | } |
| 1803 | return 0; |
| 1804 | } |
| 1805 | |
| 1806 | size_t Target::ReadCStringFromMemory(const Address &addr, std::string &out_str, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1807 | Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1808 | char buf[256]; |
| 1809 | out_str.clear(); |
| 1810 | addr_t curr_addr = addr.GetLoadAddress(this); |
| 1811 | Address address(addr); |
Jonas Devlieghere | 09ad8c8 | 2019-05-24 00:44:33 +0000 | [diff] [blame] | 1812 | while (true) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1813 | size_t length = ReadCStringFromMemory(address, buf, sizeof(buf), error); |
| 1814 | if (length == 0) |
| 1815 | break; |
| 1816 | out_str.append(buf, length); |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1817 | // If we got "length - 1" bytes, we didn't get the whole C string, we need |
| 1818 | // to read some more characters |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1819 | if (length == sizeof(buf) - 1) |
| 1820 | curr_addr += length; |
| 1821 | else |
| 1822 | break; |
| 1823 | address = Address(curr_addr); |
| 1824 | } |
| 1825 | return out_str.size(); |
| 1826 | } |
| 1827 | |
| 1828 | size_t Target::ReadCStringFromMemory(const Address &addr, char *dst, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1829 | size_t dst_max_len, Status &result_error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1830 | size_t total_cstr_len = 0; |
| 1831 | if (dst && dst_max_len) { |
| 1832 | result_error.Clear(); |
| 1833 | // NULL out everything just to be safe |
| 1834 | memset(dst, 0, dst_max_len); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1835 | Status error; |
Enrico Granata | 6b4ddc6 | 2013-01-21 19:20:50 +0000 | [diff] [blame] | 1836 | addr_t curr_addr = addr.GetLoadAddress(this); |
| 1837 | Address address(addr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1838 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1839 | // We could call m_process_sp->GetMemoryCacheLineSize() but I don't think |
| 1840 | // this really needs to be tied to the memory cache subsystem's cache line |
| 1841 | // size, so leave this as a fixed constant. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1842 | const size_t cache_line_size = 512; |
| 1843 | |
| 1844 | size_t bytes_left = dst_max_len - 1; |
| 1845 | char *curr_dst = dst; |
| 1846 | |
| 1847 | while (bytes_left > 0) { |
| 1848 | addr_t cache_line_bytes_left = |
| 1849 | cache_line_size - (curr_addr % cache_line_size); |
| 1850 | addr_t bytes_to_read = |
| 1851 | std::min<addr_t>(bytes_left, cache_line_bytes_left); |
| 1852 | size_t bytes_read = |
| 1853 | ReadMemory(address, false, curr_dst, bytes_to_read, error); |
| 1854 | |
| 1855 | if (bytes_read == 0) { |
| 1856 | result_error = error; |
| 1857 | dst[total_cstr_len] = '\0'; |
| 1858 | break; |
| 1859 | } |
| 1860 | const size_t len = strlen(curr_dst); |
| 1861 | |
| 1862 | total_cstr_len += len; |
| 1863 | |
| 1864 | if (len < bytes_to_read) |
| 1865 | break; |
| 1866 | |
| 1867 | curr_dst += bytes_read; |
| 1868 | curr_addr += bytes_read; |
| 1869 | bytes_left -= bytes_read; |
| 1870 | address = Address(curr_addr); |
Enrico Granata | 6b4ddc6 | 2013-01-21 19:20:50 +0000 | [diff] [blame] | 1871 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1872 | } else { |
| 1873 | if (dst == nullptr) |
| 1874 | result_error.SetErrorString("invalid arguments"); |
Enrico Granata | 6b4ddc6 | 2013-01-21 19:20:50 +0000 | [diff] [blame] | 1875 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1876 | result_error.Clear(); |
| 1877 | } |
| 1878 | return total_cstr_len; |
Enrico Granata | 6b4ddc6 | 2013-01-21 19:20:50 +0000 | [diff] [blame] | 1879 | } |
| 1880 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1881 | size_t Target::ReadScalarIntegerFromMemory(const Address &addr, |
| 1882 | bool prefer_file_cache, |
| 1883 | uint32_t byte_size, bool is_signed, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1884 | Scalar &scalar, Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1885 | uint64_t uval; |
| 1886 | |
| 1887 | if (byte_size <= sizeof(uval)) { |
| 1888 | size_t bytes_read = |
| 1889 | ReadMemory(addr, prefer_file_cache, &uval, byte_size, error); |
| 1890 | if (bytes_read == byte_size) { |
Pavel Labath | 13e37d4 | 2017-10-25 21:05:31 +0000 | [diff] [blame] | 1891 | DataExtractor data(&uval, sizeof(uval), m_arch.GetSpec().GetByteOrder(), |
| 1892 | m_arch.GetSpec().GetAddressByteSize()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1893 | lldb::offset_t offset = 0; |
| 1894 | if (byte_size <= 4) |
| 1895 | scalar = data.GetMaxU32(&offset, byte_size); |
| 1896 | else |
| 1897 | scalar = data.GetMaxU64(&offset, byte_size); |
| 1898 | |
| 1899 | if (is_signed) |
| 1900 | scalar.SignExtend(byte_size * 8); |
| 1901 | return bytes_read; |
| 1902 | } |
| 1903 | } else { |
| 1904 | error.SetErrorStringWithFormat( |
| 1905 | "byte size of %u is too large for integer scalar type", byte_size); |
| 1906 | } |
| 1907 | return 0; |
| 1908 | } |
| 1909 | |
| 1910 | uint64_t Target::ReadUnsignedIntegerFromMemory(const Address &addr, |
| 1911 | bool prefer_file_cache, |
| 1912 | size_t integer_byte_size, |
| 1913 | uint64_t fail_value, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1914 | Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1915 | Scalar scalar; |
| 1916 | if (ReadScalarIntegerFromMemory(addr, prefer_file_cache, integer_byte_size, |
| 1917 | false, scalar, error)) |
| 1918 | return scalar.ULongLong(fail_value); |
| 1919 | return fail_value; |
| 1920 | } |
| 1921 | |
| 1922 | bool Target::ReadPointerFromMemory(const Address &addr, bool prefer_file_cache, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1923 | Status &error, Address &pointer_addr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1924 | Scalar scalar; |
| 1925 | if (ReadScalarIntegerFromMemory(addr, prefer_file_cache, |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1926 | m_arch.GetSpec().GetAddressByteSize(), false, |
| 1927 | scalar, error)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1928 | addr_t pointer_vm_addr = scalar.ULongLong(LLDB_INVALID_ADDRESS); |
| 1929 | if (pointer_vm_addr != LLDB_INVALID_ADDRESS) { |
| 1930 | SectionLoadList §ion_load_list = GetSectionLoadList(); |
| 1931 | if (section_load_list.IsEmpty()) { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1932 | // No sections are loaded, so we must assume we are not running yet and |
| 1933 | // anything we are given is a file address. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1934 | m_images.ResolveFileAddress(pointer_vm_addr, pointer_addr); |
| 1935 | } else { |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1936 | // We have at least one section loaded. This can be because we have |
| 1937 | // manually loaded some sections with "target modules load ..." or |
| 1938 | // because we have have a live process that has sections loaded through |
| 1939 | // the dynamic loader |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1940 | section_load_list.ResolveLoadAddress(pointer_vm_addr, pointer_addr); |
| 1941 | } |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1942 | // We weren't able to resolve the pointer value, so just return an |
| 1943 | // address with no section |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1944 | if (!pointer_addr.IsValid()) |
| 1945 | pointer_addr.SetOffset(pointer_vm_addr); |
| 1946 | return true; |
| 1947 | } |
| 1948 | } |
| 1949 | return false; |
| 1950 | } |
| 1951 | |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 1952 | ModuleSP Target::GetOrCreateModule(const ModuleSpec &module_spec, bool notify, |
| 1953 | Status *error_ptr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1954 | ModuleSP module_sp; |
| 1955 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1956 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1957 | |
| 1958 | // First see if we already have this module in our module list. If we do, |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1959 | // then we're done, we don't need to consult the shared modules list. But |
| 1960 | // only do this if we are passed a UUID. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1961 | |
| 1962 | if (module_spec.GetUUID().IsValid()) |
| 1963 | module_sp = m_images.FindFirstModule(module_spec); |
| 1964 | |
| 1965 | if (!module_sp) { |
| 1966 | ModuleSP old_module_sp; // This will get filled in if we have a new version |
| 1967 | // of the library |
| 1968 | bool did_create_module = false; |
Frederic Riss | acbf005 | 2019-04-23 20:17:04 +0000 | [diff] [blame] | 1969 | FileSpecList search_paths = GetExecutableSearchPaths(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1970 | // If there are image search path entries, try to use them first to acquire |
| 1971 | // a suitable image. |
| 1972 | if (m_image_search_paths.GetSize()) { |
| 1973 | ModuleSpec transformed_spec(module_spec); |
| 1974 | if (m_image_search_paths.RemapPath( |
| 1975 | module_spec.GetFileSpec().GetDirectory(), |
| 1976 | transformed_spec.GetFileSpec().GetDirectory())) { |
| 1977 | transformed_spec.GetFileSpec().GetFilename() = |
| 1978 | module_spec.GetFileSpec().GetFilename(); |
| 1979 | error = ModuleList::GetSharedModule(transformed_spec, module_sp, |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1980 | &search_paths, &old_module_sp, |
| 1981 | &did_create_module); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | if (!module_sp) { |
| 1986 | // If we have a UUID, we can check our global shared module list in case |
| 1987 | // we already have it. If we don't have a valid UUID, then we can't since |
| 1988 | // the path in "module_spec" will be a platform path, and we will need to |
| 1989 | // let the platform find that file. For example, we could be asking for |
| 1990 | // "/usr/lib/dyld" and if we do not have a UUID, we don't want to pick |
| 1991 | // the local copy of "/usr/lib/dyld" since our platform could be a remote |
| 1992 | // platform that has its own "/usr/lib/dyld" in an SDK or in a local file |
| 1993 | // cache. |
| 1994 | if (module_spec.GetUUID().IsValid()) { |
| 1995 | // We have a UUID, it is OK to check the global module list... |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 1996 | error = |
| 1997 | ModuleList::GetSharedModule(module_spec, module_sp, &search_paths, |
| 1998 | &old_module_sp, &did_create_module); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | if (!module_sp) { |
| 2002 | // The platform is responsible for finding and caching an appropriate |
| 2003 | // module in the shared module cache. |
| 2004 | if (m_platform_sp) { |
| 2005 | error = m_platform_sp->GetSharedModule( |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2006 | module_spec, m_process_sp.get(), module_sp, &search_paths, |
| 2007 | &old_module_sp, &did_create_module); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2008 | } else { |
| 2009 | error.SetErrorString("no platform is currently set"); |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 2010 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2011 | } |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 2012 | } |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 2013 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2014 | // We found a module that wasn't in our target list. Let's make sure that |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2015 | // there wasn't an equivalent module in the list already, and if there was, |
| 2016 | // let's remove it. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2017 | if (module_sp) { |
| 2018 | ObjectFile *objfile = module_sp->GetObjectFile(); |
| 2019 | if (objfile) { |
| 2020 | switch (objfile->GetType()) { |
| 2021 | case ObjectFile::eTypeCoreFile: /// A core file that has a checkpoint of |
| 2022 | /// a program's execution state |
| 2023 | case ObjectFile::eTypeExecutable: /// A normal executable |
| 2024 | case ObjectFile::eTypeDynamicLinker: /// The platform's dynamic linker |
| 2025 | /// executable |
| 2026 | case ObjectFile::eTypeObjectFile: /// An intermediate object file |
| 2027 | case ObjectFile::eTypeSharedLibrary: /// A shared library that can be |
| 2028 | /// used during execution |
| 2029 | break; |
| 2030 | case ObjectFile::eTypeDebugInfo: /// An object file that contains only |
| 2031 | /// debug information |
| 2032 | if (error_ptr) |
| 2033 | error_ptr->SetErrorString("debug info files aren't valid target " |
| 2034 | "modules, please specify an executable"); |
| 2035 | return ModuleSP(); |
| 2036 | case ObjectFile::eTypeStubLibrary: /// A library that can be linked |
| 2037 | /// against but not used for |
| 2038 | /// execution |
| 2039 | if (error_ptr) |
| 2040 | error_ptr->SetErrorString("stub libraries aren't valid target " |
| 2041 | "modules, please specify an executable"); |
| 2042 | return ModuleSP(); |
| 2043 | default: |
| 2044 | if (error_ptr) |
| 2045 | error_ptr->SetErrorString( |
| 2046 | "unsupported file type, please specify an executable"); |
| 2047 | return ModuleSP(); |
Greg Clayton | d16e1e5 | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 2048 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2049 | // GetSharedModule is not guaranteed to find the old shared module, for |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2050 | // instance in the common case where you pass in the UUID, it is only |
| 2051 | // going to find the one module matching the UUID. In fact, it has no |
| 2052 | // good way to know what the "old module" relevant to this target is, |
| 2053 | // since there might be many copies of a module with this file spec in |
| 2054 | // various running debug sessions, but only one of them will belong to |
| 2055 | // this target. So let's remove the UUID from the module list, and look |
| 2056 | // in the target's module list. Only do this if there is SOMETHING else |
| 2057 | // in the module spec... |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2058 | if (!old_module_sp) { |
| 2059 | if (module_spec.GetUUID().IsValid() && |
| 2060 | !module_spec.GetFileSpec().GetFilename().IsEmpty() && |
| 2061 | !module_spec.GetFileSpec().GetDirectory().IsEmpty()) { |
| 2062 | ModuleSpec module_spec_copy(module_spec.GetFileSpec()); |
| 2063 | module_spec_copy.GetUUID().Clear(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2064 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2065 | ModuleList found_modules; |
| 2066 | size_t num_found = |
| 2067 | m_images.FindModules(module_spec_copy, found_modules); |
| 2068 | if (num_found == 1) { |
| 2069 | old_module_sp = found_modules.GetModuleAtIndex(0); |
Jim Ingham | 4a94c91 | 2012-05-17 18:38:42 +0000 | [diff] [blame] | 2070 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2071 | } |
Greg Clayton | b69bb2e | 2012-04-27 00:58:27 +0000 | [diff] [blame] | 2072 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2073 | |
Jim Ingham | 7fca8c0 | 2017-04-28 00:51:06 +0000 | [diff] [blame] | 2074 | // Preload symbols outside of any lock, so hopefully we can do this for |
| 2075 | // each library in parallel. |
| 2076 | if (GetPreloadSymbols()) |
| 2077 | module_sp->PreloadSymbols(); |
| 2078 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2079 | if (old_module_sp && m_images.GetIndexForModule(old_module_sp.get()) != |
| 2080 | LLDB_INVALID_INDEX32) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2081 | m_images.ReplaceModule(old_module_sp, module_sp); |
| 2082 | Module *old_module_ptr = old_module_sp.get(); |
| 2083 | old_module_sp.reset(); |
| 2084 | ModuleList::RemoveSharedModuleIfOrphaned(old_module_ptr); |
Jason Molenda | 1724a17 | 2019-04-08 23:03:02 +0000 | [diff] [blame] | 2085 | } else { |
| 2086 | m_images.Append(module_sp, notify); |
| 2087 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2088 | } else |
| 2089 | module_sp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2090 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2091 | } |
| 2092 | if (error_ptr) |
| 2093 | *error_ptr = error; |
| 2094 | return module_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2095 | } |
| 2096 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2097 | TargetSP Target::CalculateTarget() { return shared_from_this(); } |
| 2098 | |
| 2099 | ProcessSP Target::CalculateProcess() { return m_process_sp; } |
| 2100 | |
| 2101 | ThreadSP Target::CalculateThread() { return ThreadSP(); } |
| 2102 | |
| 2103 | StackFrameSP Target::CalculateStackFrame() { return StackFrameSP(); } |
| 2104 | |
| 2105 | void Target::CalculateExecutionContext(ExecutionContext &exe_ctx) { |
| 2106 | exe_ctx.Clear(); |
| 2107 | exe_ctx.SetTargetPtr(this); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2110 | PathMappingList &Target::GetImageSearchPathList() { |
| 2111 | return m_image_search_paths; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2112 | } |
| 2113 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2114 | void Target::ImageSearchPathsChanged(const PathMappingList &path_list, |
| 2115 | void *baton) { |
| 2116 | Target *target = (Target *)baton; |
| 2117 | ModuleSP exe_module_sp(target->GetExecutableModule()); |
| 2118 | if (exe_module_sp) |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 2119 | target->SetExecutableModule(exe_module_sp, eLoadDependentsYes); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2120 | } |
| 2121 | |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2122 | llvm::Expected<TypeSystem &> |
| 2123 | Target::GetScratchTypeSystemForLanguage(lldb::LanguageType language, |
| 2124 | bool create_on_demand) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2125 | if (!m_valid) |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2126 | return llvm::make_error<llvm::StringError>("Invalid Target", |
| 2127 | llvm::inconvertibleErrorCode()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2128 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2129 | if (language == eLanguageTypeMipsAssembler // GNU AS and LLVM use it for all |
| 2130 | // assembly code |
| 2131 | || language == eLanguageTypeUnknown) { |
| 2132 | std::set<lldb::LanguageType> languages_for_types; |
| 2133 | std::set<lldb::LanguageType> languages_for_expressions; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2134 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2135 | Language::GetLanguagesSupportingTypeSystems(languages_for_types, |
| 2136 | languages_for_expressions); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 2137 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2138 | if (languages_for_expressions.count(eLanguageTypeC)) { |
| 2139 | language = eLanguageTypeC; // LLDB's default. Override by setting the |
| 2140 | // target language. |
| 2141 | } else { |
| 2142 | if (languages_for_expressions.empty()) { |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2143 | return llvm::make_error<llvm::StringError>( |
| 2144 | "No expression support for any languages", |
| 2145 | llvm::inconvertibleErrorCode()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2146 | } else { |
| 2147 | language = *languages_for_expressions.begin(); |
| 2148 | } |
Sean Callanan | a994b0b | 2015-10-02 18:40:30 +0000 | [diff] [blame] | 2149 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2150 | } |
Sean Callanan | b92bd75 | 2015-10-01 16:28:02 +0000 | [diff] [blame] | 2151 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2152 | return m_scratch_type_system_map.GetTypeSystemForLanguage(language, this, |
| 2153 | create_on_demand); |
Sean Callanan | b92bd75 | 2015-10-01 16:28:02 +0000 | [diff] [blame] | 2154 | } |
| 2155 | |
Alex Langford | 70402bf | 2019-07-31 20:47:38 +0000 | [diff] [blame] | 2156 | std::vector<TypeSystem *> Target::GetScratchTypeSystems(bool create_on_demand) { |
| 2157 | if (!m_valid) |
| 2158 | return {}; |
| 2159 | |
| 2160 | std::vector<TypeSystem *> scratch_type_systems; |
| 2161 | |
| 2162 | std::set<lldb::LanguageType> languages_for_types; |
| 2163 | std::set<lldb::LanguageType> languages_for_expressions; |
| 2164 | |
| 2165 | Language::GetLanguagesSupportingTypeSystems(languages_for_types, |
| 2166 | languages_for_expressions); |
| 2167 | |
| 2168 | for (auto lang : languages_for_expressions) { |
| 2169 | auto type_system_or_err = |
| 2170 | GetScratchTypeSystemForLanguage(lang, create_on_demand); |
| 2171 | if (!type_system_or_err) |
| 2172 | LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET), |
| 2173 | type_system_or_err.takeError(), |
| 2174 | "Language '{}' has expression support but no scratch type " |
| 2175 | "system available", |
| 2176 | Language::GetNameForLanguageType(lang)); |
| 2177 | else |
| 2178 | scratch_type_systems.emplace_back(&type_system_or_err.get()); |
| 2179 | } |
| 2180 | |
| 2181 | return scratch_type_systems; |
| 2182 | } |
| 2183 | |
Sean Callanan | b92bd75 | 2015-10-01 16:28:02 +0000 | [diff] [blame] | 2184 | PersistentExpressionState * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2185 | Target::GetPersistentExpressionStateForLanguage(lldb::LanguageType language) { |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2186 | auto type_system_or_err = GetScratchTypeSystemForLanguage(language, true); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2187 | |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2188 | if (auto err = type_system_or_err.takeError()) { |
| 2189 | LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET), |
| 2190 | std::move(err), |
| 2191 | "Unable to get persistent expression state for language {}", |
| 2192 | Language::GetNameForLanguageType(language)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2193 | return nullptr; |
| 2194 | } |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2195 | |
| 2196 | return type_system_or_err->GetPersistentExpressionState(); |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2199 | UserExpression *Target::GetUserExpressionForLanguage( |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 2200 | llvm::StringRef expr, llvm::StringRef prefix, lldb::LanguageType language, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2201 | Expression::ResultType desired_type, |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2202 | const EvaluateExpressionOptions &options, ValueObject *ctx_obj, |
| 2203 | Status &error) { |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2204 | auto type_system_or_err = GetScratchTypeSystemForLanguage(language); |
| 2205 | if (auto err = type_system_or_err.takeError()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2206 | error.SetErrorStringWithFormat( |
| 2207 | "Could not find type system for language %s: %s", |
| 2208 | Language::GetNameForLanguageType(language), |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2209 | llvm::toString(std::move(err)).c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2210 | return nullptr; |
| 2211 | } |
| 2212 | |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2213 | auto *user_expr = type_system_or_err->GetUserExpression( |
| 2214 | expr, prefix, language, desired_type, options, ctx_obj); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2215 | if (!user_expr) |
| 2216 | error.SetErrorStringWithFormat( |
| 2217 | "Could not create an expression for language %s", |
| 2218 | Language::GetNameForLanguageType(language)); |
| 2219 | |
| 2220 | return user_expr; |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2223 | FunctionCaller *Target::GetFunctionCallerForLanguage( |
| 2224 | lldb::LanguageType language, const CompilerType &return_type, |
| 2225 | const Address &function_address, const ValueList &arg_value_list, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2226 | const char *name, Status &error) { |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2227 | auto type_system_or_err = GetScratchTypeSystemForLanguage(language); |
| 2228 | if (auto err = type_system_or_err.takeError()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2229 | error.SetErrorStringWithFormat( |
| 2230 | "Could not find type system for language %s: %s", |
| 2231 | Language::GetNameForLanguageType(language), |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2232 | llvm::toString(std::move(err)).c_str()); |
| 2233 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2236 | auto *persistent_fn = type_system_or_err->GetFunctionCaller( |
| 2237 | return_type, function_address, arg_value_list, name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2238 | if (!persistent_fn) |
| 2239 | error.SetErrorStringWithFormat( |
| 2240 | "Could not create an expression for language %s", |
| 2241 | Language::GetNameForLanguageType(language)); |
| 2242 | |
| 2243 | return persistent_fn; |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | UtilityFunction * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2247 | Target::GetUtilityFunctionForLanguage(const char *text, |
| 2248 | lldb::LanguageType language, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2249 | const char *name, Status &error) { |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2250 | auto type_system_or_err = GetScratchTypeSystemForLanguage(language); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2251 | |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2252 | if (auto err = type_system_or_err.takeError()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2253 | error.SetErrorStringWithFormat( |
| 2254 | "Could not find type system for language %s: %s", |
| 2255 | Language::GetNameForLanguageType(language), |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2256 | llvm::toString(std::move(err)).c_str()); |
| 2257 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2258 | } |
| 2259 | |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2260 | auto *utility_fn = type_system_or_err->GetUtilityFunction(text, name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2261 | if (!utility_fn) |
| 2262 | error.SetErrorStringWithFormat( |
| 2263 | "Could not create an expression for language %s", |
| 2264 | Language::GetNameForLanguageType(language)); |
| 2265 | |
| 2266 | return utility_fn; |
Jim Ingham | 151c032 | 2015-09-15 21:13:50 +0000 | [diff] [blame] | 2267 | } |
| 2268 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2269 | ClangASTContext *Target::GetScratchClangASTContext(bool create_on_demand) { |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2270 | if (!m_valid) |
| 2271 | return nullptr; |
| 2272 | |
| 2273 | auto type_system_or_err = |
| 2274 | GetScratchTypeSystemForLanguage(eLanguageTypeC, create_on_demand); |
| 2275 | if (auto err = type_system_or_err.takeError()) { |
| 2276 | LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET), |
| 2277 | std::move(err), "Couldn't get scratch ClangASTContext"); |
| 2278 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2279 | } |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2280 | return llvm::dyn_cast<ClangASTContext>(&type_system_or_err.get()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | ClangASTImporterSP Target::GetClangASTImporter() { |
| 2284 | if (m_valid) { |
| 2285 | if (!m_ast_importer_sp) { |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 2286 | m_ast_importer_sp = std::make_shared<ClangASTImporter>(); |
Sean Callanan | 4bf80d5 | 2011-11-15 22:27:19 +0000 | [diff] [blame] | 2287 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2288 | return m_ast_importer_sp; |
| 2289 | } |
| 2290 | return ClangASTImporterSP(); |
Sean Callanan | b92bd75 | 2015-10-01 16:28:02 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2293 | void Target::SettingsInitialize() { Process::SettingsInitialize(); } |
| 2294 | |
| 2295 | void Target::SettingsTerminate() { Process::SettingsTerminate(); } |
| 2296 | |
| 2297 | FileSpecList Target::GetDefaultExecutableSearchPaths() { |
| 2298 | TargetPropertiesSP properties_sp(Target::GetGlobalProperties()); |
| 2299 | if (properties_sp) |
| 2300 | return properties_sp->GetExecutableSearchPaths(); |
| 2301 | return FileSpecList(); |
Sean Callanan | 686b231 | 2011-11-16 18:20:47 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2304 | FileSpecList Target::GetDefaultDebugFileSearchPaths() { |
| 2305 | TargetPropertiesSP properties_sp(Target::GetGlobalProperties()); |
| 2306 | if (properties_sp) |
| 2307 | return properties_sp->GetDebugFileSearchPaths(); |
| 2308 | return FileSpecList(); |
Greg Clayton | 99d0faf | 2010-11-18 23:32:35 +0000 | [diff] [blame] | 2309 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2310 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2311 | ArchSpec Target::GetDefaultArchitecture() { |
| 2312 | TargetPropertiesSP properties_sp(Target::GetGlobalProperties()); |
| 2313 | if (properties_sp) |
| 2314 | return properties_sp->GetDefaultArchitecture(); |
| 2315 | return ArchSpec(); |
Greg Clayton | c859e2d | 2012-02-13 23:10:39 +0000 | [diff] [blame] | 2316 | } |
| 2317 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2318 | void Target::SetDefaultArchitecture(const ArchSpec &arch) { |
| 2319 | TargetPropertiesSP properties_sp(Target::GetGlobalProperties()); |
| 2320 | if (properties_sp) { |
Jonas Devlieghere | b2a9cf7 | 2019-07-22 23:48:01 +0000 | [diff] [blame] | 2321 | LLDB_LOG(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET), |
| 2322 | "Target::SetDefaultArchitecture setting target's " |
Jonas Devlieghere | eaedc5e | 2019-07-23 17:03:37 +0000 | [diff] [blame] | 2323 | "default architecture to {0} ({1})", |
| 2324 | arch.GetArchitectureName(), arch.GetTriple().getTriple()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2325 | return properties_sp->SetDefaultArchitecture(arch); |
| 2326 | } |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2329 | Target *Target::GetTargetFromContexts(const ExecutionContext *exe_ctx_ptr, |
| 2330 | const SymbolContext *sc_ptr) { |
| 2331 | // The target can either exist in the "process" of ExecutionContext, or in |
| 2332 | // the "target_sp" member of SymbolContext. This accessor helper function |
| 2333 | // will get the target from one of these locations. |
| 2334 | |
| 2335 | Target *target = nullptr; |
| 2336 | if (sc_ptr != nullptr) |
| 2337 | target = sc_ptr->target_sp.get(); |
| 2338 | if (target == nullptr && exe_ctx_ptr) |
| 2339 | target = exe_ctx_ptr->GetTargetPtr(); |
| 2340 | return target; |
Sean Callanan | 8505434 | 2015-04-03 15:39:47 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2343 | ExpressionResults Target::EvaluateExpression( |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 2344 | llvm::StringRef expr, ExecutionContextScope *exe_scope, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2345 | lldb::ValueObjectSP &result_valobj_sp, |
Aleksandr Urakov | 40624a0 | 2019-02-05 09:14:36 +0000 | [diff] [blame] | 2346 | const EvaluateExpressionOptions &options, std::string *fixed_expression, |
| 2347 | ValueObject *ctx_obj) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2348 | result_valobj_sp.reset(); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2349 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2350 | ExpressionResults execution_results = eExpressionSetupError; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 2351 | |
Zachary Turner | c5d7df9 | 2016-11-08 04:52:16 +0000 | [diff] [blame] | 2352 | if (expr.empty()) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2353 | return execution_results; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2354 | |
Tatyana Krasnukha | f62e23d | 2019-06-10 21:13:37 +0000 | [diff] [blame] | 2355 | // We shouldn't run stop hooks in expressions. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2356 | bool old_suppress_value = m_suppress_stop_hooks; |
| 2357 | m_suppress_stop_hooks = true; |
Tatyana Krasnukha | f62e23d | 2019-06-10 21:13:37 +0000 | [diff] [blame] | 2358 | auto on_exit = llvm::make_scope_exit([this, old_suppress_value]() { |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2359 | m_suppress_stop_hooks = old_suppress_value; |
| 2360 | }); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2361 | |
| 2362 | ExecutionContext exe_ctx; |
| 2363 | |
| 2364 | if (exe_scope) { |
| 2365 | exe_scope->CalculateExecutionContext(exe_ctx); |
| 2366 | } else if (m_process_sp) { |
| 2367 | m_process_sp->CalculateExecutionContext(exe_ctx); |
| 2368 | } else { |
| 2369 | CalculateExecutionContext(exe_ctx); |
| 2370 | } |
| 2371 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2372 | // Make sure we aren't just trying to see the value of a persistent variable |
| 2373 | // (something like "$0") |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2374 | // Only check for persistent variables the expression starts with a '$' |
Alex Langford | 0e252e3 | 2019-07-30 22:12:34 +0000 | [diff] [blame] | 2375 | lldb::ExpressionVariableSP persistent_var_sp; |
| 2376 | if (expr[0] == '$') { |
| 2377 | auto type_system_or_err = |
| 2378 | GetScratchTypeSystemForLanguage(eLanguageTypeC); |
| 2379 | if (auto err = type_system_or_err.takeError()) { |
| 2380 | LLDB_LOG_ERROR(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_TARGET), |
| 2381 | std::move(err), "Unable to get scratch type system"); |
| 2382 | } else { |
| 2383 | persistent_var_sp = |
| 2384 | type_system_or_err->GetPersistentExpressionState()->GetVariable(expr); |
| 2385 | } |
| 2386 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2387 | if (persistent_var_sp) { |
| 2388 | result_valobj_sp = persistent_var_sp->GetValueObject(); |
| 2389 | execution_results = eExpressionCompleted; |
| 2390 | } else { |
Pavel Labath | 50251fc | 2017-12-21 10:54:30 +0000 | [diff] [blame] | 2391 | llvm::StringRef prefix = GetExpressionPrefixContents(); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2392 | Status error; |
Alex Langford | 81dbc02 | 2019-03-05 03:33:34 +0000 | [diff] [blame] | 2393 | execution_results = |
| 2394 | UserExpression::Evaluate(exe_ctx, options, expr, prefix, |
| 2395 | result_valobj_sp, error, fixed_expression, |
| 2396 | nullptr, // Module |
| 2397 | ctx_obj); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2398 | } |
| 2399 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2400 | return execution_results; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 2401 | } |
| 2402 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2403 | lldb::ExpressionVariableSP Target::GetPersistentVariable(ConstString name) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2404 | lldb::ExpressionVariableSP variable_sp; |
| 2405 | m_scratch_type_system_map.ForEach( |
Zachary Turner | 3bc714b | 2017-03-02 00:05:25 +0000 | [diff] [blame] | 2406 | [name, &variable_sp](TypeSystem *type_system) -> bool { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2407 | if (PersistentExpressionState *persistent_state = |
| 2408 | type_system->GetPersistentExpressionState()) { |
| 2409 | variable_sp = persistent_state->GetVariable(name); |
Greg Clayton | 5beec21 | 2015-10-08 21:04:34 +0000 | [diff] [blame] | 2410 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2411 | if (variable_sp) |
| 2412 | return false; // Stop iterating the ForEach |
Sean Callanan | 8f1f9a1 | 2015-09-30 19:57:57 +0000 | [diff] [blame] | 2413 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2414 | return true; // Keep iterating the ForEach |
| 2415 | }); |
| 2416 | return variable_sp; |
Zachary Turner | 32abc6e | 2015-03-03 19:23:09 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 2419 | lldb::addr_t Target::GetPersistentSymbol(ConstString name) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2420 | lldb::addr_t address = LLDB_INVALID_ADDRESS; |
| 2421 | |
| 2422 | m_scratch_type_system_map.ForEach( |
Zachary Turner | 3bc714b | 2017-03-02 00:05:25 +0000 | [diff] [blame] | 2423 | [name, &address](TypeSystem *type_system) -> bool { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2424 | if (PersistentExpressionState *persistent_state = |
| 2425 | type_system->GetPersistentExpressionState()) { |
| 2426 | address = persistent_state->LookupSymbol(name); |
| 2427 | if (address != LLDB_INVALID_ADDRESS) |
| 2428 | return false; // Stop iterating the ForEach |
Sean Callanan | b92bd75 | 2015-10-01 16:28:02 +0000 | [diff] [blame] | 2429 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2430 | return true; // Keep iterating the ForEach |
| 2431 | }); |
| 2432 | return address; |
Sean Callanan | b92bd75 | 2015-10-01 16:28:02 +0000 | [diff] [blame] | 2433 | } |
| 2434 | |
Jonas Devlieghere | 0288c26 | 2019-07-19 00:52:08 +0000 | [diff] [blame] | 2435 | llvm::Expected<lldb_private::Address> Target::GetEntryPointAddress() { |
Jason Molenda | 956761a | 2019-07-18 20:55:24 +0000 | [diff] [blame] | 2436 | Module *exe_module = GetExecutableModulePointer(); |
Jonas Devlieghere | 0288c26 | 2019-07-19 00:52:08 +0000 | [diff] [blame] | 2437 | llvm::Error error = llvm::Error::success(); |
| 2438 | assert(!error); // Check the success value when assertions are enabled. |
Jason Molenda | 956761a | 2019-07-18 20:55:24 +0000 | [diff] [blame] | 2439 | |
| 2440 | if (!exe_module || !exe_module->GetObjectFile()) { |
Jonas Devlieghere | 0288c26 | 2019-07-19 00:52:08 +0000 | [diff] [blame] | 2441 | error = llvm::make_error<llvm::StringError>("No primary executable found", |
| 2442 | llvm::inconvertibleErrorCode()); |
Jason Molenda | 956761a | 2019-07-18 20:55:24 +0000 | [diff] [blame] | 2443 | } else { |
Jonas Devlieghere | 0288c26 | 2019-07-19 00:52:08 +0000 | [diff] [blame] | 2444 | Address entry_addr = exe_module->GetObjectFile()->GetEntryPointAddress(); |
| 2445 | if (entry_addr.IsValid()) |
| 2446 | return entry_addr; |
| 2447 | |
| 2448 | error = llvm::make_error<llvm::StringError>( |
| 2449 | "Could not find entry point address for executable module \"" + |
| 2450 | exe_module->GetFileSpec().GetFilename().GetStringRef() + "\"", |
| 2451 | llvm::inconvertibleErrorCode()); |
Jason Molenda | 956761a | 2019-07-18 20:55:24 +0000 | [diff] [blame] | 2452 | } |
| 2453 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2454 | const ModuleList &modules = GetImages(); |
| 2455 | const size_t num_images = modules.GetSize(); |
| 2456 | for (size_t idx = 0; idx < num_images; ++idx) { |
| 2457 | ModuleSP module_sp(modules.GetModuleAtIndex(idx)); |
| 2458 | if (!module_sp || !module_sp->GetObjectFile()) |
| 2459 | continue; |
Jonas Devlieghere | 0288c26 | 2019-07-19 00:52:08 +0000 | [diff] [blame] | 2460 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2461 | Address entry_addr = module_sp->GetObjectFile()->GetEntryPointAddress(); |
| 2462 | if (entry_addr.IsValid()) { |
| 2463 | // Discard the error. |
| 2464 | llvm::consumeError(std::move(error)); |
| 2465 | return entry_addr; |
Jason Molenda | 956761a | 2019-07-18 20:55:24 +0000 | [diff] [blame] | 2466 | } |
| 2467 | } |
| 2468 | |
Jonas Devlieghere | 0288c26 | 2019-07-19 00:52:08 +0000 | [diff] [blame] | 2469 | return std::move(error); |
Jason Molenda | 956761a | 2019-07-18 20:55:24 +0000 | [diff] [blame] | 2470 | } |
| 2471 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2472 | lldb::addr_t Target::GetCallableLoadAddress(lldb::addr_t load_addr, |
| 2473 | AddressClass addr_class) const { |
Tatyana Krasnukha | 7aa9e7b | 2018-09-21 18:56:44 +0000 | [diff] [blame] | 2474 | auto arch_plugin = GetArchitecturePlugin(); |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2475 | return arch_plugin |
| 2476 | ? arch_plugin->GetCallableLoadAddress(load_addr, addr_class) |
| 2477 | : load_addr; |
Greg Clayton | f3ef3d2 | 2011-05-22 22:46:53 +0000 | [diff] [blame] | 2478 | } |
| 2479 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2480 | lldb::addr_t Target::GetOpcodeLoadAddress(lldb::addr_t load_addr, |
| 2481 | AddressClass addr_class) const { |
Tatyana Krasnukha | 7aa9e7b | 2018-09-21 18:56:44 +0000 | [diff] [blame] | 2482 | auto arch_plugin = GetArchitecturePlugin(); |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2483 | return arch_plugin ? arch_plugin->GetOpcodeLoadAddress(load_addr, addr_class) |
| 2484 | : load_addr; |
Bhushan D. Attarde | 7f3daed | 2015-08-26 06:04:54 +0000 | [diff] [blame] | 2485 | } |
| 2486 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2487 | lldb::addr_t Target::GetBreakableLoadAddress(lldb::addr_t addr) { |
Tatyana Krasnukha | 7aa9e7b | 2018-09-21 18:56:44 +0000 | [diff] [blame] | 2488 | auto arch_plugin = GetArchitecturePlugin(); |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2489 | return arch_plugin ? arch_plugin->GetBreakableLoadAddress(addr, *this) : addr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2490 | } |
| 2491 | |
| 2492 | SourceManager &Target::GetSourceManager() { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 2493 | if (!m_source_manager_up) |
| 2494 | m_source_manager_up.reset(new SourceManager(shared_from_this())); |
| 2495 | return *m_source_manager_up; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2496 | } |
| 2497 | |
| 2498 | ClangModulesDeclVendor *Target::GetClangModulesDeclVendor() { |
| 2499 | static std::mutex s_clang_modules_decl_vendor_mutex; // If this is contended |
| 2500 | // we can make it |
| 2501 | // per-target |
| 2502 | |
| 2503 | { |
| 2504 | std::lock_guard<std::mutex> guard(s_clang_modules_decl_vendor_mutex); |
| 2505 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 2506 | if (!m_clang_modules_decl_vendor_up) { |
| 2507 | m_clang_modules_decl_vendor_up.reset( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2508 | ClangModulesDeclVendor::Create(*this)); |
| 2509 | } |
| 2510 | } |
| 2511 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 2512 | return m_clang_modules_decl_vendor_up.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | Target::StopHookSP Target::CreateStopHook() { |
| 2516 | lldb::user_id_t new_uid = ++m_stop_hook_next_id; |
| 2517 | Target::StopHookSP stop_hook_sp(new StopHook(shared_from_this(), new_uid)); |
| 2518 | m_stop_hooks[new_uid] = stop_hook_sp; |
| 2519 | return stop_hook_sp; |
| 2520 | } |
| 2521 | |
| 2522 | bool Target::RemoveStopHookByID(lldb::user_id_t user_id) { |
| 2523 | size_t num_removed = m_stop_hooks.erase(user_id); |
| 2524 | return (num_removed != 0); |
| 2525 | } |
| 2526 | |
| 2527 | void Target::RemoveAllStopHooks() { m_stop_hooks.clear(); } |
| 2528 | |
| 2529 | Target::StopHookSP Target::GetStopHookByID(lldb::user_id_t user_id) { |
| 2530 | StopHookSP found_hook; |
| 2531 | |
| 2532 | StopHookCollection::iterator specified_hook_iter; |
| 2533 | specified_hook_iter = m_stop_hooks.find(user_id); |
| 2534 | if (specified_hook_iter != m_stop_hooks.end()) |
| 2535 | found_hook = (*specified_hook_iter).second; |
| 2536 | return found_hook; |
| 2537 | } |
| 2538 | |
| 2539 | bool Target::SetStopHookActiveStateByID(lldb::user_id_t user_id, |
| 2540 | bool active_state) { |
| 2541 | StopHookCollection::iterator specified_hook_iter; |
| 2542 | specified_hook_iter = m_stop_hooks.find(user_id); |
| 2543 | if (specified_hook_iter == m_stop_hooks.end()) |
| 2544 | return false; |
| 2545 | |
| 2546 | (*specified_hook_iter).second->SetIsActive(active_state); |
| 2547 | return true; |
| 2548 | } |
| 2549 | |
| 2550 | void Target::SetAllStopHooksActiveState(bool active_state) { |
| 2551 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 2552 | for (pos = m_stop_hooks.begin(); pos != end; pos++) { |
| 2553 | (*pos).second->SetIsActive(active_state); |
| 2554 | } |
| 2555 | } |
| 2556 | |
| 2557 | void Target::RunStopHooks() { |
| 2558 | if (m_suppress_stop_hooks) |
| 2559 | return; |
| 2560 | |
| 2561 | if (!m_process_sp) |
| 2562 | return; |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2563 | |
Jim Ingham | 45816d6 | 2017-12-05 02:34:05 +0000 | [diff] [blame] | 2564 | // Somebody might have restarted the process: |
| 2565 | if (m_process_sp->GetState() != eStateStopped) |
| 2566 | return; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2567 | |
| 2568 | // <rdar://problem/12027563> make sure we check that we are not stopped |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2569 | // because of us running a user expression since in that case we do not want |
| 2570 | // to run the stop-hooks |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2571 | if (m_process_sp->GetModIDRef().IsLastResumeForUserExpression()) |
| 2572 | return; |
| 2573 | |
| 2574 | if (m_stop_hooks.empty()) |
| 2575 | return; |
| 2576 | |
| 2577 | StopHookCollection::iterator pos, end = m_stop_hooks.end(); |
| 2578 | |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 2579 | // If there aren't any active stop hooks, don't bother either. |
| 2580 | // Also see if any of the active hooks want to auto-continue. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2581 | bool any_active_hooks = false; |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 2582 | bool auto_continue = false; |
| 2583 | for (auto hook : m_stop_hooks) { |
| 2584 | if (hook.second->IsActive()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2585 | any_active_hooks = true; |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 2586 | auto_continue |= hook.second->GetAutoContinue(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2587 | } |
| 2588 | } |
| 2589 | if (!any_active_hooks) |
| 2590 | return; |
| 2591 | |
| 2592 | CommandReturnObject result; |
| 2593 | |
| 2594 | std::vector<ExecutionContext> exc_ctx_with_reasons; |
| 2595 | std::vector<SymbolContext> sym_ctx_with_reasons; |
| 2596 | |
| 2597 | ThreadList &cur_threadlist = m_process_sp->GetThreadList(); |
| 2598 | size_t num_threads = cur_threadlist.GetSize(); |
| 2599 | for (size_t i = 0; i < num_threads; i++) { |
| 2600 | lldb::ThreadSP cur_thread_sp = cur_threadlist.GetThreadAtIndex(i); |
| 2601 | if (cur_thread_sp->ThreadStoppedForAReason()) { |
| 2602 | lldb::StackFrameSP cur_frame_sp = cur_thread_sp->GetStackFrameAtIndex(0); |
| 2603 | exc_ctx_with_reasons.push_back(ExecutionContext( |
| 2604 | m_process_sp.get(), cur_thread_sp.get(), cur_frame_sp.get())); |
| 2605 | sym_ctx_with_reasons.push_back( |
| 2606 | cur_frame_sp->GetSymbolContext(eSymbolContextEverything)); |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | // If no threads stopped for a reason, don't run the stop-hooks. |
| 2611 | size_t num_exe_ctx = exc_ctx_with_reasons.size(); |
| 2612 | if (num_exe_ctx == 0) |
| 2613 | return; |
| 2614 | |
| 2615 | result.SetImmediateOutputStream(m_debugger.GetAsyncOutputStream()); |
| 2616 | result.SetImmediateErrorStream(m_debugger.GetAsyncErrorStream()); |
| 2617 | |
| 2618 | bool keep_going = true; |
| 2619 | bool hooks_ran = false; |
| 2620 | bool print_hook_header = (m_stop_hooks.size() != 1); |
| 2621 | bool print_thread_header = (num_exe_ctx != 1); |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 2622 | bool did_restart = false; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2623 | |
| 2624 | for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++) { |
| 2625 | // result.Clear(); |
| 2626 | StopHookSP cur_hook_sp = (*pos).second; |
| 2627 | if (!cur_hook_sp->IsActive()) |
| 2628 | continue; |
| 2629 | |
| 2630 | bool any_thread_matched = false; |
| 2631 | for (size_t i = 0; keep_going && i < num_exe_ctx; i++) { |
| 2632 | if ((cur_hook_sp->GetSpecifier() == nullptr || |
| 2633 | cur_hook_sp->GetSpecifier()->SymbolContextMatches( |
| 2634 | sym_ctx_with_reasons[i])) && |
| 2635 | (cur_hook_sp->GetThreadSpecifier() == nullptr || |
| 2636 | cur_hook_sp->GetThreadSpecifier()->ThreadPassesBasicTests( |
| 2637 | exc_ctx_with_reasons[i].GetThreadRef()))) { |
| 2638 | if (!hooks_ran) { |
| 2639 | hooks_ran = true; |
| 2640 | } |
| 2641 | if (print_hook_header && !any_thread_matched) { |
| 2642 | const char *cmd = |
| 2643 | (cur_hook_sp->GetCommands().GetSize() == 1 |
| 2644 | ? cur_hook_sp->GetCommands().GetStringAtIndex(0) |
| 2645 | : nullptr); |
| 2646 | if (cmd) |
| 2647 | result.AppendMessageWithFormat("\n- Hook %" PRIu64 " (%s)\n", |
| 2648 | cur_hook_sp->GetID(), cmd); |
| 2649 | else |
| 2650 | result.AppendMessageWithFormat("\n- Hook %" PRIu64 "\n", |
| 2651 | cur_hook_sp->GetID()); |
| 2652 | any_thread_matched = true; |
| 2653 | } |
| 2654 | |
| 2655 | if (print_thread_header) |
| 2656 | result.AppendMessageWithFormat( |
| 2657 | "-- Thread %d\n", |
| 2658 | exc_ctx_with_reasons[i].GetThreadPtr()->GetIndexID()); |
| 2659 | |
| 2660 | CommandInterpreterRunOptions options; |
| 2661 | options.SetStopOnContinue(true); |
| 2662 | options.SetStopOnError(true); |
| 2663 | options.SetEchoCommands(false); |
| 2664 | options.SetPrintResults(true); |
Jonas Devlieghere | c0b48ab | 2019-05-08 01:23:47 +0000 | [diff] [blame] | 2665 | options.SetPrintErrors(true); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2666 | options.SetAddToHistory(false); |
| 2667 | |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 2668 | // Force Async: |
| 2669 | bool old_async = GetDebugger().GetAsyncExecution(); |
| 2670 | GetDebugger().SetAsyncExecution(true); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2671 | GetDebugger().GetCommandInterpreter().HandleCommands( |
| 2672 | cur_hook_sp->GetCommands(), &exc_ctx_with_reasons[i], options, |
| 2673 | result); |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 2674 | GetDebugger().SetAsyncExecution(old_async); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2675 | // If the command started the target going again, we should bag out of |
| 2676 | // running the stop hooks. |
| 2677 | if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) || |
| 2678 | (result.GetStatus() == eReturnStatusSuccessContinuingResult)) { |
Jim Ingham | 45816d6 | 2017-12-05 02:34:05 +0000 | [diff] [blame] | 2679 | // But only complain if there were more stop hooks to do: |
| 2680 | StopHookCollection::iterator tmp = pos; |
| 2681 | if (++tmp != end) |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2682 | result.AppendMessageWithFormat( |
| 2683 | "\nAborting stop hooks, hook %" PRIu64 |
| 2684 | " set the program running.\n" |
| 2685 | " Consider using '-G true' to make " |
| 2686 | "stop hooks auto-continue.\n", |
| 2687 | cur_hook_sp->GetID()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2688 | keep_going = false; |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 2689 | did_restart = true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2690 | } |
| 2691 | } |
| 2692 | } |
| 2693 | } |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 2694 | // Finally, if auto-continue was requested, do it now: |
| 2695 | if (!did_restart && auto_continue) |
| 2696 | m_process_sp->PrivateResume(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2697 | |
| 2698 | result.GetImmediateOutputStream()->Flush(); |
| 2699 | result.GetImmediateErrorStream()->Flush(); |
| 2700 | } |
| 2701 | |
| 2702 | const TargetPropertiesSP &Target::GetGlobalProperties() { |
| 2703 | // NOTE: intentional leak so we don't crash if global destructor chain gets |
| 2704 | // called as other threads still use the result of this function |
Pavel Labath | 5f05ea8 | 2016-10-19 15:12:45 +0000 | [diff] [blame] | 2705 | static TargetPropertiesSP *g_settings_sp_ptr = |
| 2706 | new TargetPropertiesSP(new TargetProperties(nullptr)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2707 | return *g_settings_sp_ptr; |
| 2708 | } |
| 2709 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2710 | Status Target::Install(ProcessLaunchInfo *launch_info) { |
| 2711 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2712 | PlatformSP platform_sp(GetPlatform()); |
| 2713 | if (platform_sp) { |
| 2714 | if (platform_sp->IsRemote()) { |
| 2715 | if (platform_sp->IsConnected()) { |
| 2716 | // Install all files that have an install path, and always install the |
| 2717 | // main executable when connected to a remote platform |
| 2718 | const ModuleList &modules = GetImages(); |
| 2719 | const size_t num_images = modules.GetSize(); |
| 2720 | for (size_t idx = 0; idx < num_images; ++idx) { |
| 2721 | ModuleSP module_sp(modules.GetModuleAtIndex(idx)); |
| 2722 | if (module_sp) { |
| 2723 | const bool is_main_executable = module_sp == GetExecutableModule(); |
| 2724 | FileSpec local_file(module_sp->GetFileSpec()); |
| 2725 | if (local_file) { |
| 2726 | FileSpec remote_file(module_sp->GetRemoteInstallFileSpec()); |
| 2727 | if (!remote_file) { |
| 2728 | if (is_main_executable) // TODO: add setting for always |
| 2729 | // installing main executable??? |
| 2730 | { |
| 2731 | // Always install the main executable |
| 2732 | remote_file = platform_sp->GetRemoteWorkingDirectory(); |
| 2733 | remote_file.AppendPathComponent( |
| 2734 | module_sp->GetFileSpec().GetFilename().GetCString()); |
| 2735 | } |
| 2736 | } |
| 2737 | if (remote_file) { |
| 2738 | error = platform_sp->Install(local_file, remote_file); |
| 2739 | if (error.Success()) { |
| 2740 | module_sp->SetPlatformFileSpec(remote_file); |
| 2741 | if (is_main_executable) { |
| 2742 | platform_sp->SetFilePermissions(remote_file, 0700); |
| 2743 | if (launch_info) |
| 2744 | launch_info->SetExecutableFile(remote_file, false); |
| 2745 | } |
| 2746 | } else |
| 2747 | break; |
| 2748 | } |
| 2749 | } |
| 2750 | } |
| 2751 | } |
| 2752 | } |
| 2753 | } |
| 2754 | } |
| 2755 | return error; |
| 2756 | } |
| 2757 | |
| 2758 | bool Target::ResolveLoadAddress(addr_t load_addr, Address &so_addr, |
| 2759 | uint32_t stop_id) { |
| 2760 | return m_section_load_history.ResolveLoadAddress(stop_id, load_addr, so_addr); |
| 2761 | } |
| 2762 | |
| 2763 | bool Target::ResolveFileAddress(lldb::addr_t file_addr, |
| 2764 | Address &resolved_addr) { |
| 2765 | return m_images.ResolveFileAddress(file_addr, resolved_addr); |
| 2766 | } |
| 2767 | |
| 2768 | bool Target::SetSectionLoadAddress(const SectionSP §ion_sp, |
| 2769 | addr_t new_section_load_addr, |
| 2770 | bool warn_multiple) { |
| 2771 | const addr_t old_section_load_addr = |
| 2772 | m_section_load_history.GetSectionLoadAddress( |
| 2773 | SectionLoadHistory::eStopIDNow, section_sp); |
| 2774 | if (old_section_load_addr != new_section_load_addr) { |
| 2775 | uint32_t stop_id = 0; |
| 2776 | ProcessSP process_sp(GetProcessSP()); |
| 2777 | if (process_sp) |
| 2778 | stop_id = process_sp->GetStopID(); |
Greg Clayton | b09c538 | 2013-12-13 17:20:18 +0000 | [diff] [blame] | 2779 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2780 | stop_id = m_section_load_history.GetLastStopID(); |
| 2781 | if (m_section_load_history.SetSectionLoadAddress( |
| 2782 | stop_id, section_sp, new_section_load_addr, warn_multiple)) |
| 2783 | return true; // Return true if the section load address was changed... |
| 2784 | } |
| 2785 | return false; // Return false to indicate nothing changed |
| 2786 | } |
Todd Fiala | ac33cc9 | 2014-10-09 01:02:08 +0000 | [diff] [blame] | 2787 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2788 | size_t Target::UnloadModuleSections(const ModuleList &module_list) { |
| 2789 | size_t section_unload_count = 0; |
| 2790 | size_t num_modules = module_list.GetSize(); |
| 2791 | for (size_t i = 0; i < num_modules; ++i) { |
| 2792 | section_unload_count += |
| 2793 | UnloadModuleSections(module_list.GetModuleAtIndex(i)); |
| 2794 | } |
| 2795 | return section_unload_count; |
| 2796 | } |
Todd Fiala | 015d818 | 2014-07-22 23:41:36 +0000 | [diff] [blame] | 2797 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2798 | size_t Target::UnloadModuleSections(const lldb::ModuleSP &module_sp) { |
| 2799 | uint32_t stop_id = 0; |
| 2800 | ProcessSP process_sp(GetProcessSP()); |
| 2801 | if (process_sp) |
| 2802 | stop_id = process_sp->GetStopID(); |
| 2803 | else |
| 2804 | stop_id = m_section_load_history.GetLastStopID(); |
| 2805 | SectionList *sections = module_sp->GetSectionList(); |
| 2806 | size_t section_unload_count = 0; |
| 2807 | if (sections) { |
| 2808 | const uint32_t num_sections = sections->GetNumSections(0); |
| 2809 | for (uint32_t i = 0; i < num_sections; ++i) { |
| 2810 | section_unload_count += m_section_load_history.SetSectionUnloaded( |
| 2811 | stop_id, sections->GetSectionAtIndex(i)); |
Greg Clayton | b09c538 | 2013-12-13 17:20:18 +0000 | [diff] [blame] | 2812 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2813 | } |
| 2814 | return section_unload_count; |
| 2815 | } |
| 2816 | |
| 2817 | bool Target::SetSectionUnloaded(const lldb::SectionSP §ion_sp) { |
| 2818 | uint32_t stop_id = 0; |
| 2819 | ProcessSP process_sp(GetProcessSP()); |
| 2820 | if (process_sp) |
| 2821 | stop_id = process_sp->GetStopID(); |
| 2822 | else |
| 2823 | stop_id = m_section_load_history.GetLastStopID(); |
| 2824 | return m_section_load_history.SetSectionUnloaded(stop_id, section_sp); |
| 2825 | } |
| 2826 | |
| 2827 | bool Target::SetSectionUnloaded(const lldb::SectionSP §ion_sp, |
| 2828 | addr_t load_addr) { |
| 2829 | uint32_t stop_id = 0; |
| 2830 | ProcessSP process_sp(GetProcessSP()); |
| 2831 | if (process_sp) |
| 2832 | stop_id = process_sp->GetStopID(); |
| 2833 | else |
| 2834 | stop_id = m_section_load_history.GetLastStopID(); |
| 2835 | return m_section_load_history.SetSectionUnloaded(stop_id, section_sp, |
| 2836 | load_addr); |
| 2837 | } |
| 2838 | |
| 2839 | void Target::ClearAllLoadedSections() { m_section_load_history.Clear(); } |
| 2840 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2841 | Status Target::Launch(ProcessLaunchInfo &launch_info, Stream *stream) { |
| 2842 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2843 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_TARGET)); |
| 2844 | |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 2845 | LLDB_LOGF(log, "Target::%s() called for %s", __FUNCTION__, |
| 2846 | launch_info.GetExecutableFile().GetPath().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2847 | |
| 2848 | StateType state = eStateInvalid; |
| 2849 | |
| 2850 | // Scope to temporarily get the process state in case someone has manually |
| 2851 | // remotely connected already to a process and we can skip the platform |
| 2852 | // launching. |
| 2853 | { |
| 2854 | ProcessSP process_sp(GetProcessSP()); |
| 2855 | |
| 2856 | if (process_sp) { |
| 2857 | state = process_sp->GetState(); |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 2858 | LLDB_LOGF(log, |
| 2859 | "Target::%s the process exists, and its current state is %s", |
| 2860 | __FUNCTION__, StateAsCString(state)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2861 | } else { |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 2862 | LLDB_LOGF(log, "Target::%s the process instance doesn't currently exist.", |
| 2863 | __FUNCTION__); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2864 | } |
| 2865 | } |
| 2866 | |
| 2867 | launch_info.GetFlags().Set(eLaunchFlagDebug); |
| 2868 | |
| 2869 | // Get the value of synchronous execution here. If you wait till after you |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 2870 | // have started to run, then you could have hit a breakpoint, whose command |
| 2871 | // might switch the value, and then you'll pick up that incorrect value. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2872 | Debugger &debugger = GetDebugger(); |
| 2873 | const bool synchronous_execution = |
| 2874 | debugger.GetCommandInterpreter().GetSynchronous(); |
| 2875 | |
| 2876 | PlatformSP platform_sp(GetPlatform()); |
| 2877 | |
Pavel Labath | 8e55dde | 2019-01-08 11:55:19 +0000 | [diff] [blame] | 2878 | FinalizeFileActions(launch_info); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2879 | |
| 2880 | if (state == eStateConnected) { |
| 2881 | if (launch_info.GetFlags().Test(eLaunchFlagLaunchInTTY)) { |
| 2882 | error.SetErrorString( |
| 2883 | "can't launch in tty when launching through a remote connection"); |
| 2884 | return error; |
| 2885 | } |
| 2886 | } |
| 2887 | |
| 2888 | if (!launch_info.GetArchitecture().IsValid()) |
| 2889 | launch_info.GetArchitecture() = GetArchitecture(); |
| 2890 | |
| 2891 | // If we're not already connected to the process, and if we have a platform |
| 2892 | // that can launch a process for debugging, go ahead and do that here. |
| 2893 | if (state != eStateConnected && platform_sp && |
| 2894 | platform_sp->CanDebugProcess()) { |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 2895 | LLDB_LOGF(log, "Target::%s asking the platform to debug the process", |
| 2896 | __FUNCTION__); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2897 | |
Jim Ingham | 362d022 | 2018-12-18 01:49:02 +0000 | [diff] [blame] | 2898 | // If there was a previous process, delete it before we make the new one. |
| 2899 | // One subtle point, we delete the process before we release the reference |
| 2900 | // to m_process_sp. That way even if we are the last owner, the process |
| 2901 | // will get Finalized before it gets destroyed. |
| 2902 | DeleteCurrentProcess(); |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2903 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2904 | m_process_sp = |
| 2905 | GetPlatform()->DebugProcess(launch_info, debugger, this, error); |
| 2906 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2907 | } else { |
Jonas Devlieghere | 63e5fb7 | 2019-07-24 17:56:10 +0000 | [diff] [blame] | 2908 | LLDB_LOGF(log, |
| 2909 | "Target::%s the platform doesn't know how to debug a " |
| 2910 | "process, getting a process plugin to do this for us.", |
| 2911 | __FUNCTION__); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2912 | |
| 2913 | if (state == eStateConnected) { |
| 2914 | assert(m_process_sp); |
| 2915 | } else { |
| 2916 | // Use a Process plugin to construct the process. |
| 2917 | const char *plugin_name = launch_info.GetProcessPluginName(); |
Pavel Labath | cb8c699 | 2019-01-07 10:59:57 +0000 | [diff] [blame] | 2918 | CreateProcess(launch_info.GetListener(), plugin_name, nullptr); |
Greg Clayton | b09c538 | 2013-12-13 17:20:18 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2921 | // Since we didn't have a platform launch the process, launch it here. |
| 2922 | if (m_process_sp) |
| 2923 | error = m_process_sp->Launch(launch_info); |
| 2924 | } |
| 2925 | |
| 2926 | if (!m_process_sp) { |
Greg Clayton | b09c538 | 2013-12-13 17:20:18 +0000 | [diff] [blame] | 2927 | if (error.Success()) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2928 | error.SetErrorString("failed to launch or debug process"); |
Greg Clayton | b09c538 | 2013-12-13 17:20:18 +0000 | [diff] [blame] | 2929 | return error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | if (error.Success()) { |
| 2933 | if (synchronous_execution || |
| 2934 | !launch_info.GetFlags().Test(eLaunchFlagStopAtEntry)) { |
| 2935 | ListenerSP hijack_listener_sp(launch_info.GetHijackListener()); |
| 2936 | if (!hijack_listener_sp) { |
| 2937 | hijack_listener_sp = |
| 2938 | Listener::MakeListener("lldb.Target.Launch.hijack"); |
| 2939 | launch_info.SetHijackListener(hijack_listener_sp); |
| 2940 | m_process_sp->HijackProcessEvents(hijack_listener_sp); |
| 2941 | } |
| 2942 | |
| 2943 | StateType state = m_process_sp->WaitForProcessToStop( |
Pavel Labath | e3e21cf | 2016-11-30 11:56:32 +0000 | [diff] [blame] | 2944 | llvm::None, nullptr, false, hijack_listener_sp, nullptr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2945 | |
| 2946 | if (state == eStateStopped) { |
| 2947 | if (!launch_info.GetFlags().Test(eLaunchFlagStopAtEntry)) { |
| 2948 | if (synchronous_execution) { |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 2949 | // Now we have handled the stop-from-attach, and we are just |
| 2950 | // switching to a synchronous resume. So we should switch to the |
| 2951 | // SyncResume hijacker. |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 2952 | m_process_sp->RestoreProcessEvents(); |
| 2953 | m_process_sp->ResumeSynchronous(stream); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2954 | } else { |
| 2955 | m_process_sp->RestoreProcessEvents(); |
| 2956 | error = m_process_sp->PrivateResume(); |
| 2957 | } |
| 2958 | if (!error.Success()) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2959 | Status error2; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2960 | error2.SetErrorStringWithFormat( |
| 2961 | "process resume at entry point failed: %s", error.AsCString()); |
| 2962 | error = error2; |
| 2963 | } |
| 2964 | } |
| 2965 | } else if (state == eStateExited) { |
| 2966 | bool with_shell = !!launch_info.GetShell(); |
| 2967 | const int exit_status = m_process_sp->GetExitStatus(); |
| 2968 | const char *exit_desc = m_process_sp->GetExitDescription(); |
| 2969 | #define LAUNCH_SHELL_MESSAGE \ |
| 2970 | "\n'r' and 'run' are aliases that default to launching through a " \ |
| 2971 | "shell.\nTry launching without going through a shell by using 'process " \ |
| 2972 | "launch'." |
| 2973 | if (exit_desc && exit_desc[0]) { |
| 2974 | if (with_shell) |
| 2975 | error.SetErrorStringWithFormat( |
| 2976 | "process exited with status %i (%s)" LAUNCH_SHELL_MESSAGE, |
| 2977 | exit_status, exit_desc); |
| 2978 | else |
| 2979 | error.SetErrorStringWithFormat("process exited with status %i (%s)", |
| 2980 | exit_status, exit_desc); |
| 2981 | } else { |
| 2982 | if (with_shell) |
| 2983 | error.SetErrorStringWithFormat( |
| 2984 | "process exited with status %i" LAUNCH_SHELL_MESSAGE, |
| 2985 | exit_status); |
| 2986 | else |
| 2987 | error.SetErrorStringWithFormat("process exited with status %i", |
| 2988 | exit_status); |
| 2989 | } |
| 2990 | } else { |
| 2991 | error.SetErrorStringWithFormat( |
| 2992 | "initial process state wasn't stopped: %s", StateAsCString(state)); |
| 2993 | } |
| 2994 | } |
| 2995 | m_process_sp->RestoreProcessEvents(); |
| 2996 | } else { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2997 | Status error2; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2998 | error2.SetErrorStringWithFormat("process launch failed: %s", |
| 2999 | error.AsCString()); |
| 3000 | error = error2; |
| 3001 | } |
| 3002 | return error; |
Greg Clayton | b09c538 | 2013-12-13 17:20:18 +0000 | [diff] [blame] | 3003 | } |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3004 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 3005 | Status Target::Attach(ProcessAttachInfo &attach_info, Stream *stream) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3006 | auto state = eStateInvalid; |
| 3007 | auto process_sp = GetProcessSP(); |
| 3008 | if (process_sp) { |
| 3009 | state = process_sp->GetState(); |
| 3010 | if (process_sp->IsAlive() && state != eStateConnected) { |
| 3011 | if (state == eStateAttaching) |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 3012 | return Status("process attach is in progress"); |
| 3013 | return Status("a process is already being debugged"); |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3014 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3015 | } |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3016 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3017 | const ModuleSP old_exec_module_sp = GetExecutableModule(); |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3018 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3019 | // If no process info was specified, then use the target executable name as |
| 3020 | // the process to attach to by default |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3021 | if (!attach_info.ProcessInfoSpecified()) { |
| 3022 | if (old_exec_module_sp) |
| 3023 | attach_info.GetExecutableFile().GetFilename() = |
| 3024 | old_exec_module_sp->GetPlatformFileSpec().GetFilename(); |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3025 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3026 | if (!attach_info.ProcessInfoSpecified()) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 3027 | return Status("no process specified, create a target with a file, or " |
| 3028 | "specify the --pid or --name"); |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3029 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3030 | } |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3031 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3032 | const auto platform_sp = |
| 3033 | GetDebugger().GetPlatformList().GetSelectedPlatform(); |
| 3034 | ListenerSP hijack_listener_sp; |
| 3035 | const bool async = attach_info.GetAsync(); |
| 3036 | if (!async) { |
| 3037 | hijack_listener_sp = |
| 3038 | Listener::MakeListener("lldb.Target.Attach.attach.hijack"); |
| 3039 | attach_info.SetHijackListener(hijack_listener_sp); |
| 3040 | } |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3041 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 3042 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3043 | if (state != eStateConnected && platform_sp != nullptr && |
| 3044 | platform_sp->CanDebugProcess()) { |
| 3045 | SetPlatform(platform_sp); |
| 3046 | process_sp = platform_sp->Attach(attach_info, GetDebugger(), this, error); |
| 3047 | } else { |
| 3048 | if (state != eStateConnected) { |
| 3049 | const char *plugin_name = attach_info.GetProcessPluginName(); |
| 3050 | process_sp = |
| 3051 | CreateProcess(attach_info.GetListenerForProcess(GetDebugger()), |
| 3052 | plugin_name, nullptr); |
| 3053 | if (process_sp == nullptr) { |
| 3054 | error.SetErrorStringWithFormat( |
| 3055 | "failed to create process using plugin %s", |
| 3056 | (plugin_name) ? plugin_name : "null"); |
| 3057 | return error; |
| 3058 | } |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3059 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3060 | if (hijack_listener_sp) |
| 3061 | process_sp->HijackProcessEvents(hijack_listener_sp); |
| 3062 | error = process_sp->Attach(attach_info); |
| 3063 | } |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3064 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3065 | if (error.Success() && process_sp) { |
| 3066 | if (async) { |
| 3067 | process_sp->RestoreProcessEvents(); |
| 3068 | } else { |
| 3069 | state = process_sp->WaitForProcessToStop( |
Pavel Labath | e3e21cf | 2016-11-30 11:56:32 +0000 | [diff] [blame] | 3070 | llvm::None, nullptr, false, attach_info.GetHijackListener(), stream); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3071 | process_sp->RestoreProcessEvents(); |
| 3072 | |
| 3073 | if (state != eStateStopped) { |
| 3074 | const char *exit_desc = process_sp->GetExitDescription(); |
| 3075 | if (exit_desc) |
| 3076 | error.SetErrorStringWithFormat("%s", exit_desc); |
Greg Clayton | e75e5d8 | 2015-10-20 00:14:20 +0000 | [diff] [blame] | 3077 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3078 | error.SetErrorString( |
| 3079 | "process did not stop (no such process or permission problem?)"); |
| 3080 | process_sp->Destroy(false); |
| 3081 | } |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3082 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3083 | } |
| 3084 | return error; |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 3085 | } |
| 3086 | |
Pavel Labath | 8e55dde | 2019-01-08 11:55:19 +0000 | [diff] [blame] | 3087 | void Target::FinalizeFileActions(ProcessLaunchInfo &info) { |
| 3088 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_PROCESS)); |
| 3089 | |
| 3090 | // Finalize the file actions, and if none were given, default to opening up a |
| 3091 | // pseudo terminal |
| 3092 | PlatformSP platform_sp = GetPlatform(); |
| 3093 | const bool default_to_use_pty = |
| 3094 | m_platform_sp ? m_platform_sp->IsHost() : false; |
| 3095 | LLDB_LOG( |
| 3096 | log, |
| 3097 | "have platform={0}, platform_sp->IsHost()={1}, default_to_use_pty={2}", |
| 3098 | bool(platform_sp), |
| 3099 | platform_sp ? (platform_sp->IsHost() ? "true" : "false") : "n/a", |
| 3100 | default_to_use_pty); |
| 3101 | |
| 3102 | // If nothing for stdin or stdout or stderr was specified, then check the |
| 3103 | // process for any default settings that were set with "settings set" |
| 3104 | if (info.GetFileActionForFD(STDIN_FILENO) == nullptr || |
| 3105 | info.GetFileActionForFD(STDOUT_FILENO) == nullptr || |
| 3106 | info.GetFileActionForFD(STDERR_FILENO) == nullptr) { |
| 3107 | LLDB_LOG(log, "at least one of stdin/stdout/stderr was not set, evaluating " |
| 3108 | "default handling"); |
| 3109 | |
| 3110 | if (info.GetFlags().Test(eLaunchFlagLaunchInTTY)) { |
| 3111 | // Do nothing, if we are launching in a remote terminal no file actions |
| 3112 | // should be done at all. |
| 3113 | return; |
| 3114 | } |
| 3115 | |
| 3116 | if (info.GetFlags().Test(eLaunchFlagDisableSTDIO)) { |
| 3117 | LLDB_LOG(log, "eLaunchFlagDisableSTDIO set, adding suppression action " |
| 3118 | "for stdin, stdout and stderr"); |
| 3119 | info.AppendSuppressFileAction(STDIN_FILENO, true, false); |
| 3120 | info.AppendSuppressFileAction(STDOUT_FILENO, false, true); |
| 3121 | info.AppendSuppressFileAction(STDERR_FILENO, false, true); |
| 3122 | } else { |
| 3123 | // Check for any values that might have gotten set with any of: (lldb) |
| 3124 | // settings set target.input-path (lldb) settings set target.output-path |
| 3125 | // (lldb) settings set target.error-path |
| 3126 | FileSpec in_file_spec; |
| 3127 | FileSpec out_file_spec; |
| 3128 | FileSpec err_file_spec; |
| 3129 | // Only override with the target settings if we don't already have an |
| 3130 | // action for in, out or error |
| 3131 | if (info.GetFileActionForFD(STDIN_FILENO) == nullptr) |
| 3132 | in_file_spec = GetStandardInputPath(); |
| 3133 | if (info.GetFileActionForFD(STDOUT_FILENO) == nullptr) |
| 3134 | out_file_spec = GetStandardOutputPath(); |
| 3135 | if (info.GetFileActionForFD(STDERR_FILENO) == nullptr) |
| 3136 | err_file_spec = GetStandardErrorPath(); |
| 3137 | |
| 3138 | LLDB_LOG(log, "target stdin='{0}', target stdout='{1}', stderr='{1}'", |
| 3139 | in_file_spec, out_file_spec, err_file_spec); |
| 3140 | |
| 3141 | if (in_file_spec) { |
| 3142 | info.AppendOpenFileAction(STDIN_FILENO, in_file_spec, true, false); |
| 3143 | LLDB_LOG(log, "appended stdin open file action for {0}", in_file_spec); |
| 3144 | } |
| 3145 | |
| 3146 | if (out_file_spec) { |
| 3147 | info.AppendOpenFileAction(STDOUT_FILENO, out_file_spec, false, true); |
| 3148 | LLDB_LOG(log, "appended stdout open file action for {0}", |
| 3149 | out_file_spec); |
| 3150 | } |
| 3151 | |
| 3152 | if (err_file_spec) { |
| 3153 | info.AppendOpenFileAction(STDERR_FILENO, err_file_spec, false, true); |
| 3154 | LLDB_LOG(log, "appended stderr open file action for {0}", |
| 3155 | err_file_spec); |
| 3156 | } |
| 3157 | |
| 3158 | if (default_to_use_pty && |
| 3159 | (!in_file_spec || !out_file_spec || !err_file_spec)) { |
| 3160 | llvm::Error Err = info.SetUpPtyRedirection(); |
| 3161 | LLDB_LOG_ERROR(log, std::move(Err), "SetUpPtyRedirection failed: {0}"); |
| 3162 | } |
| 3163 | } |
| 3164 | } |
| 3165 | } |
| 3166 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3167 | // Target::StopHook |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3168 | Target::StopHook::StopHook(lldb::TargetSP target_sp, lldb::user_id_t uid) |
| 3169 | : UserID(uid), m_target_sp(target_sp), m_commands(), m_specifier_sp(), |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 3170 | m_thread_spec_up() {} |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3171 | |
| 3172 | Target::StopHook::StopHook(const StopHook &rhs) |
| 3173 | : UserID(rhs.GetID()), m_target_sp(rhs.m_target_sp), |
| 3174 | m_commands(rhs.m_commands), m_specifier_sp(rhs.m_specifier_sp), |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 3175 | m_thread_spec_up(), m_active(rhs.m_active), |
| 3176 | m_auto_continue(rhs.m_auto_continue) { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 3177 | if (rhs.m_thread_spec_up) |
| 3178 | m_thread_spec_up.reset(new ThreadSpec(*rhs.m_thread_spec_up)); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3179 | } |
| 3180 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 3181 | Target::StopHook::~StopHook() = default; |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3182 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3183 | void Target::StopHook::SetSpecifier(SymbolContextSpecifier *specifier) { |
| 3184 | m_specifier_sp.reset(specifier); |
Zachary Turner | 32abc6e | 2015-03-03 19:23:09 +0000 | [diff] [blame] | 3185 | } |
| 3186 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3187 | void Target::StopHook::SetThreadSpecifier(ThreadSpec *specifier) { |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 3188 | m_thread_spec_up.reset(specifier); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3189 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3190 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3191 | void Target::StopHook::GetDescription(Stream *s, |
| 3192 | lldb::DescriptionLevel level) const { |
| 3193 | int indent_level = s->GetIndentLevel(); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3194 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3195 | s->SetIndentLevel(indent_level + 2); |
| 3196 | |
| 3197 | s->Printf("Hook: %" PRIu64 "\n", GetID()); |
| 3198 | if (m_active) |
| 3199 | s->Indent("State: enabled\n"); |
| 3200 | else |
| 3201 | s->Indent("State: disabled\n"); |
| 3202 | |
Jim Ingham | 3139fc9 | 2019-03-01 18:13:38 +0000 | [diff] [blame] | 3203 | if (m_auto_continue) |
| 3204 | s->Indent("AutoContinue on\n"); |
| 3205 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3206 | if (m_specifier_sp) { |
| 3207 | s->Indent(); |
| 3208 | s->PutCString("Specifier:\n"); |
| 3209 | s->SetIndentLevel(indent_level + 4); |
| 3210 | m_specifier_sp->GetDescription(s, level); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3211 | s->SetIndentLevel(indent_level + 2); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3212 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3213 | |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 3214 | if (m_thread_spec_up) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3215 | StreamString tmp; |
| 3216 | s->Indent("Thread:\n"); |
Jonas Devlieghere | d5b4403 | 2019-02-13 06:25:41 +0000 | [diff] [blame] | 3217 | m_thread_spec_up->GetDescription(&tmp, level); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3218 | s->SetIndentLevel(indent_level + 4); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 3219 | s->Indent(tmp.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3220 | s->PutCString("\n"); |
| 3221 | s->SetIndentLevel(indent_level + 2); |
| 3222 | } |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3223 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3224 | s->Indent("Commands: \n"); |
| 3225 | s->SetIndentLevel(indent_level + 4); |
| 3226 | uint32_t num_commands = m_commands.GetSize(); |
| 3227 | for (uint32_t i = 0; i < num_commands; i++) { |
| 3228 | s->Indent(m_commands.GetStringAtIndex(i)); |
| 3229 | s->PutCString("\n"); |
| 3230 | } |
| 3231 | s->SetIndentLevel(indent_level); |
Jim Ingham | 9575d84 | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 3232 | } |
| 3233 | |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 3234 | static constexpr OptionEnumValueElement g_dynamic_value_types[] = { |
Jonas Devlieghere | e063ecc | 2019-08-02 00:18:44 +0000 | [diff] [blame^] | 3235 | { |
| 3236 | eNoDynamicValues, |
| 3237 | "no-dynamic-values", |
| 3238 | "Don't calculate the dynamic type of values", |
| 3239 | }, |
| 3240 | { |
| 3241 | eDynamicCanRunTarget, |
| 3242 | "run-target", |
| 3243 | "Calculate the dynamic type of values " |
| 3244 | "even if you have to run the target.", |
| 3245 | }, |
| 3246 | { |
| 3247 | eDynamicDontRunTarget, |
| 3248 | "no-run-target", |
| 3249 | "Calculate the dynamic type of values, but don't run the target.", |
| 3250 | }, |
| 3251 | }; |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 3252 | |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 3253 | OptionEnumValues lldb_private::GetDynamicValueTypes() { |
| 3254 | return OptionEnumValues(g_dynamic_value_types); |
| 3255 | } |
| 3256 | |
| 3257 | static constexpr OptionEnumValueElement g_inline_breakpoint_enums[] = { |
Jonas Devlieghere | e063ecc | 2019-08-02 00:18:44 +0000 | [diff] [blame^] | 3258 | { |
| 3259 | eInlineBreakpointsNever, |
| 3260 | "never", |
| 3261 | "Never look for inline breakpoint locations (fastest). This setting " |
| 3262 | "should only be used if you know that no inlining occurs in your" |
| 3263 | "programs.", |
| 3264 | }, |
| 3265 | { |
| 3266 | eInlineBreakpointsHeaders, |
| 3267 | "headers", |
| 3268 | "Only check for inline breakpoint locations when setting breakpoints " |
| 3269 | "in header files, but not when setting breakpoint in implementation " |
| 3270 | "source files (default).", |
| 3271 | }, |
| 3272 | { |
| 3273 | eInlineBreakpointsAlways, |
| 3274 | "always", |
| 3275 | "Always look for inline breakpoint locations when setting file and " |
| 3276 | "line breakpoints (slower but most accurate).", |
| 3277 | }, |
| 3278 | }; |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3279 | |
Fangrui Song | efe8e7e | 2019-05-14 08:55:50 +0000 | [diff] [blame] | 3280 | enum x86DisassemblyFlavor { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3281 | eX86DisFlavorDefault, |
| 3282 | eX86DisFlavorIntel, |
| 3283 | eX86DisFlavorATT |
Fangrui Song | efe8e7e | 2019-05-14 08:55:50 +0000 | [diff] [blame] | 3284 | }; |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 3285 | |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 3286 | static constexpr OptionEnumValueElement g_x86_dis_flavor_value_types[] = { |
Jonas Devlieghere | e063ecc | 2019-08-02 00:18:44 +0000 | [diff] [blame^] | 3287 | { |
| 3288 | eX86DisFlavorDefault, |
| 3289 | "default", |
| 3290 | "Disassembler default (currently att).", |
| 3291 | }, |
| 3292 | { |
| 3293 | eX86DisFlavorIntel, |
| 3294 | "intel", |
| 3295 | "Intel disassembler flavor.", |
| 3296 | }, |
| 3297 | { |
| 3298 | eX86DisFlavorATT, |
| 3299 | "att", |
| 3300 | "AT&T disassembler flavor.", |
| 3301 | }, |
| 3302 | }; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3303 | |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 3304 | static constexpr OptionEnumValueElement g_hex_immediate_style_values[] = { |
Jonas Devlieghere | e063ecc | 2019-08-02 00:18:44 +0000 | [diff] [blame^] | 3305 | { |
| 3306 | Disassembler::eHexStyleC, |
| 3307 | "c", |
| 3308 | "C-style (0xffff).", |
| 3309 | }, |
| 3310 | { |
| 3311 | Disassembler::eHexStyleAsm, |
| 3312 | "asm", |
| 3313 | "Asm-style (0ffffh).", |
| 3314 | }, |
| 3315 | }; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3316 | |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 3317 | static constexpr OptionEnumValueElement g_load_script_from_sym_file_values[] = { |
Jonas Devlieghere | e063ecc | 2019-08-02 00:18:44 +0000 | [diff] [blame^] | 3318 | { |
| 3319 | eLoadScriptFromSymFileTrue, |
| 3320 | "true", |
| 3321 | "Load debug scripts inside symbol files", |
| 3322 | }, |
| 3323 | { |
| 3324 | eLoadScriptFromSymFileFalse, |
| 3325 | "false", |
| 3326 | "Do not load debug scripts inside symbol files.", |
| 3327 | }, |
| 3328 | { |
| 3329 | eLoadScriptFromSymFileWarn, |
| 3330 | "warn", |
| 3331 | "Warn about debug scripts inside symbol files but do not load them.", |
| 3332 | }, |
| 3333 | }; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3334 | |
Jonas Devlieghere | e063ecc | 2019-08-02 00:18:44 +0000 | [diff] [blame^] | 3335 | static constexpr OptionEnumValueElement g_load_cwd_lldbinit_values[] = { |
| 3336 | { |
| 3337 | eLoadCWDlldbinitTrue, |
| 3338 | "true", |
| 3339 | "Load .lldbinit files from current directory", |
| 3340 | }, |
| 3341 | { |
| 3342 | eLoadCWDlldbinitFalse, |
| 3343 | "false", |
| 3344 | "Do not load .lldbinit files from current directory", |
| 3345 | }, |
| 3346 | { |
| 3347 | eLoadCWDlldbinitWarn, |
| 3348 | "warn", |
| 3349 | "Warn about loading .lldbinit files from current directory", |
| 3350 | }, |
| 3351 | }; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3352 | |
Tatyana Krasnukha | 8fe53c49 | 2018-09-26 18:50:19 +0000 | [diff] [blame] | 3353 | static constexpr OptionEnumValueElement g_memory_module_load_level_values[] = { |
Jonas Devlieghere | e063ecc | 2019-08-02 00:18:44 +0000 | [diff] [blame^] | 3354 | { |
| 3355 | eMemoryModuleLoadLevelMinimal, |
| 3356 | "minimal", |
| 3357 | "Load minimal information when loading modules from memory. Currently " |
| 3358 | "this setting loads sections only.", |
| 3359 | }, |
| 3360 | { |
| 3361 | eMemoryModuleLoadLevelPartial, |
| 3362 | "partial", |
| 3363 | "Load partial information when loading modules from memory. Currently " |
| 3364 | "this setting loads sections and function bounds.", |
| 3365 | }, |
| 3366 | { |
| 3367 | eMemoryModuleLoadLevelComplete, |
| 3368 | "complete", |
| 3369 | "Load complete information when loading modules from memory. Currently " |
| 3370 | "this setting loads sections and all symbols.", |
| 3371 | }, |
| 3372 | }; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3373 | |
Jonas Devlieghere | 971f9ca | 2019-07-25 21:36:37 +0000 | [diff] [blame] | 3374 | #define LLDB_PROPERTIES_target |
Jordan Rupprecht | 6a253d3 | 2019-07-29 17:22:10 +0000 | [diff] [blame] | 3375 | #include "TargetProperties.inc" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3376 | |
| 3377 | enum { |
Jonas Devlieghere | 971f9ca | 2019-07-25 21:36:37 +0000 | [diff] [blame] | 3378 | #define LLDB_PROPERTIES_target |
Jordan Rupprecht | 6a253d3 | 2019-07-29 17:22:10 +0000 | [diff] [blame] | 3379 | #include "TargetPropertiesEnum.inc" |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 3380 | ePropertyExperimental, |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 3381 | }; |
| 3382 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3383 | class TargetOptionValueProperties : public OptionValueProperties { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3384 | public: |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 3385 | TargetOptionValueProperties(ConstString name) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3386 | : OptionValueProperties(name), m_target(nullptr), m_got_host_env(false) {} |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 3387 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3388 | // This constructor is used when creating TargetOptionValueProperties when it |
| 3389 | // is part of a new lldb_private::Target instance. It will copy all current |
| 3390 | // global property values as needed |
| 3391 | TargetOptionValueProperties(Target *target, |
| 3392 | const TargetPropertiesSP &target_properties_sp) |
| 3393 | : OptionValueProperties(*target_properties_sp->GetValueProperties()), |
| 3394 | m_target(target), m_got_host_env(false) {} |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3395 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3396 | const Property *GetPropertyAtIndex(const ExecutionContext *exe_ctx, |
| 3397 | bool will_modify, |
| 3398 | uint32_t idx) const override { |
| 3399 | // When getting the value for a key from the target options, we will always |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3400 | // try and grab the setting from the current target if there is one. Else |
| 3401 | // we just use the one from this instance. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3402 | if (idx == ePropertyEnvVars) |
| 3403 | GetHostEnvironmentIfNeeded(); |
| 3404 | |
| 3405 | if (exe_ctx) { |
| 3406 | Target *target = exe_ctx->GetTargetPtr(); |
| 3407 | if (target) { |
| 3408 | TargetOptionValueProperties *target_properties = |
| 3409 | static_cast<TargetOptionValueProperties *>( |
| 3410 | target->GetValueProperties().get()); |
| 3411 | if (this != target_properties) |
| 3412 | return target_properties->ProtectedGetPropertyAtIndex(idx); |
| 3413 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3414 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3415 | return ProtectedGetPropertyAtIndex(idx); |
| 3416 | } |
| 3417 | |
| 3418 | lldb::TargetSP GetTargetSP() { return m_target->shared_from_this(); } |
| 3419 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3420 | protected: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3421 | void GetHostEnvironmentIfNeeded() const { |
| 3422 | if (!m_got_host_env) { |
| 3423 | if (m_target) { |
| 3424 | m_got_host_env = true; |
| 3425 | const uint32_t idx = ePropertyInheritEnv; |
| 3426 | if (GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3427 | nullptr, idx, g_target_properties[idx].default_uint_value != 0)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3428 | PlatformSP platform_sp(m_target->GetPlatform()); |
| 3429 | if (platform_sp) { |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 3430 | Environment env = platform_sp->GetEnvironment(); |
| 3431 | OptionValueDictionary *env_dict = |
| 3432 | GetPropertyAtIndexAsOptionValueDictionary(nullptr, |
| 3433 | ePropertyEnvVars); |
| 3434 | if (env_dict) { |
| 3435 | const bool can_replace = false; |
| 3436 | for (const auto &KV : env) { |
| 3437 | // Don't allow existing keys to be replaced with ones we get |
| 3438 | // from the platform environment |
| 3439 | env_dict->SetValueForKey( |
| 3440 | ConstString(KV.first()), |
| 3441 | OptionValueSP(new OptionValueString(KV.second.c_str())), |
| 3442 | can_replace); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3443 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3444 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3445 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3446 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3447 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3448 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3449 | } |
| 3450 | Target *m_target; |
| 3451 | mutable bool m_got_host_env; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3452 | }; |
| 3453 | |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 3454 | // TargetProperties |
Jonas Devlieghere | 971f9ca | 2019-07-25 21:36:37 +0000 | [diff] [blame] | 3455 | #define LLDB_PROPERTIES_experimental |
Jordan Rupprecht | 6a253d3 | 2019-07-29 17:22:10 +0000 | [diff] [blame] | 3456 | #include "TargetProperties.inc" |
Jim Ingham | bed6779 | 2016-07-07 18:25:48 +0000 | [diff] [blame] | 3457 | |
Jonas Devlieghere | 971f9ca | 2019-07-25 21:36:37 +0000 | [diff] [blame] | 3458 | enum { |
| 3459 | #define LLDB_PROPERTIES_experimental |
Jordan Rupprecht | 6a253d3 | 2019-07-29 17:22:10 +0000 | [diff] [blame] | 3460 | #include "TargetPropertiesEnum.inc" |
Jonas Devlieghere | 971f9ca | 2019-07-25 21:36:37 +0000 | [diff] [blame] | 3461 | }; |
Jim Ingham | bed6779 | 2016-07-07 18:25:48 +0000 | [diff] [blame] | 3462 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3463 | class TargetExperimentalOptionValueProperties : public OptionValueProperties { |
Jim Ingham | bed6779 | 2016-07-07 18:25:48 +0000 | [diff] [blame] | 3464 | public: |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3465 | TargetExperimentalOptionValueProperties() |
| 3466 | : OptionValueProperties( |
| 3467 | ConstString(Properties::GetExperimentalSettingsName())) {} |
Jim Ingham | bed6779 | 2016-07-07 18:25:48 +0000 | [diff] [blame] | 3468 | }; |
| 3469 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3470 | TargetExperimentalProperties::TargetExperimentalProperties() |
| 3471 | : Properties(OptionValuePropertiesSP( |
| 3472 | new TargetExperimentalOptionValueProperties())) { |
| 3473 | m_collection_sp->Initialize(g_experimental_properties); |
Jim Ingham | bed6779 | 2016-07-07 18:25:48 +0000 | [diff] [blame] | 3474 | } |
| 3475 | |
Jim Ingham | bed6779 | 2016-07-07 18:25:48 +0000 | [diff] [blame] | 3476 | // TargetProperties |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3477 | TargetProperties::TargetProperties(Target *target) |
| 3478 | : Properties(), m_launch_info() { |
| 3479 | if (target) { |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 3480 | m_collection_sp = std::make_shared<TargetOptionValueProperties>( |
| 3481 | target, Target::GetGlobalProperties()); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 3482 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 3483 | // Set callbacks to update launch_info whenever "settins set" updated any |
| 3484 | // of these properties |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3485 | m_collection_sp->SetValueChangedCallback( |
| 3486 | ePropertyArg0, TargetProperties::Arg0ValueChangedCallback, this); |
| 3487 | m_collection_sp->SetValueChangedCallback( |
| 3488 | ePropertyRunArgs, TargetProperties::RunArgsValueChangedCallback, this); |
| 3489 | m_collection_sp->SetValueChangedCallback( |
| 3490 | ePropertyEnvVars, TargetProperties::EnvVarsValueChangedCallback, this); |
| 3491 | m_collection_sp->SetValueChangedCallback( |
| 3492 | ePropertyInputPath, TargetProperties::InputPathValueChangedCallback, |
| 3493 | this); |
| 3494 | m_collection_sp->SetValueChangedCallback( |
| 3495 | ePropertyOutputPath, TargetProperties::OutputPathValueChangedCallback, |
| 3496 | this); |
| 3497 | m_collection_sp->SetValueChangedCallback( |
| 3498 | ePropertyErrorPath, TargetProperties::ErrorPathValueChangedCallback, |
| 3499 | this); |
| 3500 | m_collection_sp->SetValueChangedCallback( |
| 3501 | ePropertyDetachOnError, |
| 3502 | TargetProperties::DetachOnErrorValueChangedCallback, this); |
| 3503 | m_collection_sp->SetValueChangedCallback( |
| 3504 | ePropertyDisableASLR, TargetProperties::DisableASLRValueChangedCallback, |
| 3505 | this); |
| 3506 | m_collection_sp->SetValueChangedCallback( |
| 3507 | ePropertyDisableSTDIO, |
| 3508 | TargetProperties::DisableSTDIOValueChangedCallback, this); |
Jim Ingham | bed6779 | 2016-07-07 18:25:48 +0000 | [diff] [blame] | 3509 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3510 | m_experimental_properties_up.reset(new TargetExperimentalProperties()); |
| 3511 | m_collection_sp->AppendProperty( |
| 3512 | ConstString(Properties::GetExperimentalSettingsName()), |
| 3513 | ConstString("Experimental settings - setting these won't produce " |
| 3514 | "errors if the setting is not present."), |
| 3515 | true, m_experimental_properties_up->GetValueProperties()); |
Jim Ingham | bed6779 | 2016-07-07 18:25:48 +0000 | [diff] [blame] | 3516 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3517 | // Update m_launch_info once it was created |
| 3518 | Arg0ValueChangedCallback(this, nullptr); |
| 3519 | RunArgsValueChangedCallback(this, nullptr); |
| 3520 | // EnvVarsValueChangedCallback(this, nullptr); // FIXME: cause segfault in |
| 3521 | // Target::GetPlatform() |
| 3522 | InputPathValueChangedCallback(this, nullptr); |
| 3523 | OutputPathValueChangedCallback(this, nullptr); |
| 3524 | ErrorPathValueChangedCallback(this, nullptr); |
| 3525 | DetachOnErrorValueChangedCallback(this, nullptr); |
| 3526 | DisableASLRValueChangedCallback(this, nullptr); |
| 3527 | DisableSTDIOValueChangedCallback(this, nullptr); |
| 3528 | } else { |
Jonas Devlieghere | 796ac80 | 2019-02-11 23:13:08 +0000 | [diff] [blame] | 3529 | m_collection_sp = |
| 3530 | std::make_shared<TargetOptionValueProperties>(ConstString("target")); |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3531 | m_collection_sp->Initialize(g_target_properties); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3532 | m_experimental_properties_up.reset(new TargetExperimentalProperties()); |
| 3533 | m_collection_sp->AppendProperty( |
| 3534 | ConstString(Properties::GetExperimentalSettingsName()), |
| 3535 | ConstString("Experimental settings - setting these won't produce " |
| 3536 | "errors if the setting is not present."), |
| 3537 | true, m_experimental_properties_up->GetValueProperties()); |
| 3538 | m_collection_sp->AppendProperty( |
| 3539 | ConstString("process"), ConstString("Settings specific to processes."), |
| 3540 | true, Process::GetGlobalProperties()->GetValueProperties()); |
| 3541 | } |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 3542 | } |
| 3543 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 3544 | TargetProperties::~TargetProperties() = default; |
| 3545 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3546 | bool TargetProperties::GetInjectLocalVariables( |
| 3547 | ExecutionContext *exe_ctx) const { |
| 3548 | const Property *exp_property = m_collection_sp->GetPropertyAtIndex( |
| 3549 | exe_ctx, false, ePropertyExperimental); |
| 3550 | OptionValueProperties *exp_values = |
| 3551 | exp_property->GetValue()->GetAsProperties(); |
| 3552 | if (exp_values) |
| 3553 | return exp_values->GetPropertyAtIndexAsBoolean( |
| 3554 | exe_ctx, ePropertyInjectLocalVars, true); |
| 3555 | else |
| 3556 | return true; |
Jim Ingham | bed6779 | 2016-07-07 18:25:48 +0000 | [diff] [blame] | 3557 | } |
| 3558 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3559 | void TargetProperties::SetInjectLocalVariables(ExecutionContext *exe_ctx, |
| 3560 | bool b) { |
| 3561 | const Property *exp_property = |
| 3562 | m_collection_sp->GetPropertyAtIndex(exe_ctx, true, ePropertyExperimental); |
| 3563 | OptionValueProperties *exp_values = |
| 3564 | exp_property->GetValue()->GetAsProperties(); |
| 3565 | if (exp_values) |
| 3566 | exp_values->SetPropertyAtIndexAsBoolean(exe_ctx, ePropertyInjectLocalVars, |
| 3567 | true); |
Jim Ingham | bed6779 | 2016-07-07 18:25:48 +0000 | [diff] [blame] | 3568 | } |
| 3569 | |
Sean Callanan | 68e4423 | 2017-09-28 20:20:25 +0000 | [diff] [blame] | 3570 | bool TargetProperties::GetUseModernTypeLookup() const { |
| 3571 | const Property *exp_property = m_collection_sp->GetPropertyAtIndex( |
| 3572 | nullptr, false, ePropertyExperimental); |
| 3573 | OptionValueProperties *exp_values = |
| 3574 | exp_property->GetValue()->GetAsProperties(); |
| 3575 | if (exp_values) |
| 3576 | return exp_values->GetPropertyAtIndexAsBoolean( |
| 3577 | nullptr, ePropertyUseModernTypeLookup, true); |
| 3578 | else |
| 3579 | return true; |
| 3580 | } |
| 3581 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3582 | ArchSpec TargetProperties::GetDefaultArchitecture() const { |
| 3583 | OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch( |
| 3584 | nullptr, ePropertyDefaultArch); |
| 3585 | if (value) |
| 3586 | return value->GetCurrentValue(); |
| 3587 | return ArchSpec(); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3588 | } |
| 3589 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3590 | void TargetProperties::SetDefaultArchitecture(const ArchSpec &arch) { |
| 3591 | OptionValueArch *value = m_collection_sp->GetPropertyAtIndexAsOptionValueArch( |
| 3592 | nullptr, ePropertyDefaultArch); |
| 3593 | if (value) |
| 3594 | return value->SetCurrentValue(arch, true); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3595 | } |
| 3596 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3597 | bool TargetProperties::GetMoveToNearestCode() const { |
| 3598 | const uint32_t idx = ePropertyMoveToNearestCode; |
| 3599 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3600 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Ilia K | 055ad9b | 2015-05-18 13:41:01 +0000 | [diff] [blame] | 3601 | } |
| 3602 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3603 | lldb::DynamicValueType TargetProperties::GetPreferDynamicValue() const { |
| 3604 | const uint32_t idx = ePropertyPreferDynamic; |
| 3605 | return (lldb::DynamicValueType) |
| 3606 | m_collection_sp->GetPropertyAtIndexAsEnumeration( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3607 | nullptr, idx, g_target_properties[idx].default_uint_value); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3608 | } |
| 3609 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3610 | bool TargetProperties::SetPreferDynamicValue(lldb::DynamicValueType d) { |
| 3611 | const uint32_t idx = ePropertyPreferDynamic; |
| 3612 | return m_collection_sp->SetPropertyAtIndexAsEnumeration(nullptr, idx, d); |
Greg Clayton | 1548440 | 2015-05-15 18:40:24 +0000 | [diff] [blame] | 3613 | } |
| 3614 | |
Jim Ingham | 7fca8c0 | 2017-04-28 00:51:06 +0000 | [diff] [blame] | 3615 | bool TargetProperties::GetPreloadSymbols() const { |
| 3616 | const uint32_t idx = ePropertyPreloadSymbols; |
| 3617 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3618 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Jim Ingham | 7fca8c0 | 2017-04-28 00:51:06 +0000 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | void TargetProperties::SetPreloadSymbols(bool b) { |
| 3622 | const uint32_t idx = ePropertyPreloadSymbols; |
| 3623 | m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
| 3624 | } |
| 3625 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3626 | bool TargetProperties::GetDisableASLR() const { |
| 3627 | const uint32_t idx = ePropertyDisableASLR; |
| 3628 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3629 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3630 | } |
| 3631 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3632 | void TargetProperties::SetDisableASLR(bool b) { |
| 3633 | const uint32_t idx = ePropertyDisableASLR; |
| 3634 | m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3635 | } |
| 3636 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3637 | bool TargetProperties::GetDetachOnError() const { |
| 3638 | const uint32_t idx = ePropertyDetachOnError; |
| 3639 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3640 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Jim Ingham | 106d028 | 2014-06-25 02:32:56 +0000 | [diff] [blame] | 3641 | } |
| 3642 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3643 | void TargetProperties::SetDetachOnError(bool b) { |
| 3644 | const uint32_t idx = ePropertyDetachOnError; |
| 3645 | m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
Jim Ingham | 106d028 | 2014-06-25 02:32:56 +0000 | [diff] [blame] | 3646 | } |
| 3647 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3648 | bool TargetProperties::GetDisableSTDIO() const { |
| 3649 | const uint32_t idx = ePropertyDisableSTDIO; |
| 3650 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3651 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3652 | } |
| 3653 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3654 | void TargetProperties::SetDisableSTDIO(bool b) { |
| 3655 | const uint32_t idx = ePropertyDisableSTDIO; |
| 3656 | m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3657 | } |
| 3658 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3659 | const char *TargetProperties::GetDisassemblyFlavor() const { |
| 3660 | const uint32_t idx = ePropertyDisassemblyFlavor; |
| 3661 | const char *return_value; |
| 3662 | |
| 3663 | x86DisassemblyFlavor flavor_value = |
| 3664 | (x86DisassemblyFlavor)m_collection_sp->GetPropertyAtIndexAsEnumeration( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3665 | nullptr, idx, g_target_properties[idx].default_uint_value); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3666 | return_value = g_x86_dis_flavor_value_types[flavor_value].string_value; |
| 3667 | return return_value; |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 3668 | } |
| 3669 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3670 | InlineStrategy TargetProperties::GetInlineStrategy() const { |
| 3671 | const uint32_t idx = ePropertyInlineStrategy; |
| 3672 | return (InlineStrategy)m_collection_sp->GetPropertyAtIndexAsEnumeration( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3673 | nullptr, idx, g_target_properties[idx].default_uint_value); |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 3674 | } |
| 3675 | |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 3676 | llvm::StringRef TargetProperties::GetArg0() const { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3677 | const uint32_t idx = ePropertyArg0; |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 3678 | return m_collection_sp->GetPropertyAtIndexAsString(nullptr, idx, |
| 3679 | llvm::StringRef()); |
Greg Clayton | 4539255 | 2012-10-17 22:57:12 +0000 | [diff] [blame] | 3680 | } |
| 3681 | |
Zachary Turner | 31d97a5 | 2016-11-17 18:08:12 +0000 | [diff] [blame] | 3682 | void TargetProperties::SetArg0(llvm::StringRef arg) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3683 | const uint32_t idx = ePropertyArg0; |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 3684 | m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, arg); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3685 | m_launch_info.SetArg0(arg); |
Greg Clayton | 4539255 | 2012-10-17 22:57:12 +0000 | [diff] [blame] | 3686 | } |
| 3687 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3688 | bool TargetProperties::GetRunArguments(Args &args) const { |
| 3689 | const uint32_t idx = ePropertyRunArgs; |
| 3690 | return m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, idx, args); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3691 | } |
| 3692 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3693 | void TargetProperties::SetRunArguments(const Args &args) { |
| 3694 | const uint32_t idx = ePropertyRunArgs; |
| 3695 | m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, args); |
| 3696 | m_launch_info.GetArguments() = args; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3697 | } |
| 3698 | |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 3699 | Environment TargetProperties::GetEnvironment() const { |
| 3700 | // TODO: Get rid of the Args intermediate step |
| 3701 | Args env; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3702 | const uint32_t idx = ePropertyEnvVars; |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 3703 | m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, idx, env); |
| 3704 | return Environment(env); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3705 | } |
| 3706 | |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 3707 | void TargetProperties::SetEnvironment(Environment env) { |
| 3708 | // TODO: Get rid of the Args intermediate step |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3709 | const uint32_t idx = ePropertyEnvVars; |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 3710 | m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, Args(env)); |
| 3711 | m_launch_info.GetEnvironment() = std::move(env); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 3712 | } |
| 3713 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3714 | bool TargetProperties::GetSkipPrologue() const { |
| 3715 | const uint32_t idx = ePropertySkipPrologue; |
| 3716 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3717 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3718 | } |
| 3719 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3720 | PathMappingList &TargetProperties::GetSourcePathMap() const { |
| 3721 | const uint32_t idx = ePropertySourceMap; |
| 3722 | OptionValuePathMappings *option_value = |
| 3723 | m_collection_sp->GetPropertyAtIndexAsOptionValuePathMappings(nullptr, |
| 3724 | false, idx); |
| 3725 | assert(option_value); |
| 3726 | return option_value->GetCurrentValue(); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3727 | } |
| 3728 | |
Jonas Devlieghere | d360775 | 2019-07-19 00:56:26 +0000 | [diff] [blame] | 3729 | void TargetProperties::AppendExecutableSearchPaths(const FileSpec &dir) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3730 | const uint32_t idx = ePropertyExecutableSearchPaths; |
| 3731 | OptionValueFileSpecList *option_value = |
| 3732 | m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, |
| 3733 | false, idx); |
| 3734 | assert(option_value); |
Frederic Riss | acbf005 | 2019-04-23 20:17:04 +0000 | [diff] [blame] | 3735 | option_value->AppendCurrentValue(dir); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3736 | } |
| 3737 | |
Frederic Riss | acbf005 | 2019-04-23 20:17:04 +0000 | [diff] [blame] | 3738 | FileSpecList TargetProperties::GetExecutableSearchPaths() { |
| 3739 | const uint32_t idx = ePropertyExecutableSearchPaths; |
| 3740 | const OptionValueFileSpecList *option_value = |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3741 | m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, |
| 3742 | false, idx); |
| 3743 | assert(option_value); |
| 3744 | return option_value->GetCurrentValue(); |
Michael Sartain | a7499c9 | 2013-07-01 19:45:50 +0000 | [diff] [blame] | 3745 | } |
| 3746 | |
Frederic Riss | acbf005 | 2019-04-23 20:17:04 +0000 | [diff] [blame] | 3747 | FileSpecList TargetProperties::GetDebugFileSearchPaths() { |
| 3748 | const uint32_t idx = ePropertyDebugFileSearchPaths; |
| 3749 | const OptionValueFileSpecList *option_value = |
| 3750 | m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, |
| 3751 | false, idx); |
| 3752 | assert(option_value); |
| 3753 | return option_value->GetCurrentValue(); |
| 3754 | } |
| 3755 | |
| 3756 | FileSpecList TargetProperties::GetClangModuleSearchPaths() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3757 | const uint32_t idx = ePropertyClangModuleSearchPaths; |
Frederic Riss | acbf005 | 2019-04-23 20:17:04 +0000 | [diff] [blame] | 3758 | const OptionValueFileSpecList *option_value = |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3759 | m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpecList(nullptr, |
| 3760 | false, idx); |
| 3761 | assert(option_value); |
| 3762 | return option_value->GetCurrentValue(); |
Sean Callanan | 8505434 | 2015-04-03 15:39:47 +0000 | [diff] [blame] | 3763 | } |
| 3764 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3765 | bool TargetProperties::GetEnableAutoImportClangModules() const { |
| 3766 | const uint32_t idx = ePropertyAutoImportClangModules; |
| 3767 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3768 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Sean Callanan | f0c5aeb | 2015-04-20 16:31:29 +0000 | [diff] [blame] | 3769 | } |
| 3770 | |
Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 3771 | bool TargetProperties::GetEnableImportStdModule() const { |
| 3772 | const uint32_t idx = ePropertyImportStdModule; |
| 3773 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3774 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Raphael Isemann | 6c0bbfc | 2019-03-12 17:09:33 +0000 | [diff] [blame] | 3775 | } |
| 3776 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3777 | bool TargetProperties::GetEnableAutoApplyFixIts() const { |
| 3778 | const uint32_t idx = ePropertyAutoApplyFixIts; |
| 3779 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3780 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Jim Ingham | a1e541b | 2016-03-25 01:57:14 +0000 | [diff] [blame] | 3781 | } |
| 3782 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3783 | bool TargetProperties::GetEnableNotifyAboutFixIts() const { |
| 3784 | const uint32_t idx = ePropertyNotifyAboutFixIts; |
| 3785 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3786 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Jim Ingham | e5ee6f0 | 2016-03-29 22:00:08 +0000 | [diff] [blame] | 3787 | } |
| 3788 | |
Sean Callanan | 5deb06e | 2016-09-26 20:18:51 +0000 | [diff] [blame] | 3789 | bool TargetProperties::GetEnableSaveObjects() const { |
| 3790 | const uint32_t idx = ePropertySaveObjects; |
| 3791 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3792 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Sean Callanan | 5deb06e | 2016-09-26 20:18:51 +0000 | [diff] [blame] | 3793 | } |
| 3794 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3795 | bool TargetProperties::GetEnableSyntheticValue() const { |
| 3796 | const uint32_t idx = ePropertyEnableSynthetic; |
| 3797 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3798 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3799 | } |
| 3800 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3801 | uint32_t TargetProperties::GetMaximumNumberOfChildrenToDisplay() const { |
| 3802 | const uint32_t idx = ePropertyMaxChildrenCount; |
| 3803 | return m_collection_sp->GetPropertyAtIndexAsSInt64( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3804 | nullptr, idx, g_target_properties[idx].default_uint_value); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3805 | } |
| 3806 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3807 | uint32_t TargetProperties::GetMaximumSizeOfStringSummary() const { |
| 3808 | const uint32_t idx = ePropertyMaxSummaryLength; |
| 3809 | return m_collection_sp->GetPropertyAtIndexAsSInt64( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3810 | nullptr, idx, g_target_properties[idx].default_uint_value); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3811 | } |
| 3812 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3813 | uint32_t TargetProperties::GetMaximumMemReadSize() const { |
| 3814 | const uint32_t idx = ePropertyMaxMemReadSize; |
| 3815 | return m_collection_sp->GetPropertyAtIndexAsSInt64( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3816 | nullptr, idx, g_target_properties[idx].default_uint_value); |
Enrico Granata | d325bf9 | 2013-06-04 22:54:16 +0000 | [diff] [blame] | 3817 | } |
| 3818 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3819 | FileSpec TargetProperties::GetStandardInputPath() const { |
| 3820 | const uint32_t idx = ePropertyInputPath; |
| 3821 | return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3822 | } |
| 3823 | |
Zachary Turner | 27a5c2b | 2016-09-23 22:11:51 +0000 | [diff] [blame] | 3824 | void TargetProperties::SetStandardInputPath(llvm::StringRef path) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3825 | const uint32_t idx = ePropertyInputPath; |
Zachary Turner | 27a5c2b | 2016-09-23 22:11:51 +0000 | [diff] [blame] | 3826 | m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, path); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3827 | } |
| 3828 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3829 | FileSpec TargetProperties::GetStandardOutputPath() const { |
| 3830 | const uint32_t idx = ePropertyOutputPath; |
| 3831 | return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
Zachary Turner | 27a5c2b | 2016-09-23 22:11:51 +0000 | [diff] [blame] | 3834 | void TargetProperties::SetStandardOutputPath(llvm::StringRef path) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3835 | const uint32_t idx = ePropertyOutputPath; |
Zachary Turner | 27a5c2b | 2016-09-23 22:11:51 +0000 | [diff] [blame] | 3836 | m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, path); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3837 | } |
| 3838 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3839 | FileSpec TargetProperties::GetStandardErrorPath() const { |
| 3840 | const uint32_t idx = ePropertyErrorPath; |
| 3841 | return m_collection_sp->GetPropertyAtIndexAsFileSpec(nullptr, idx); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3842 | } |
| 3843 | |
Zachary Turner | 27a5c2b | 2016-09-23 22:11:51 +0000 | [diff] [blame] | 3844 | void TargetProperties::SetStandardErrorPath(llvm::StringRef path) { |
| 3845 | const uint32_t idx = ePropertyErrorPath; |
| 3846 | m_collection_sp->SetPropertyAtIndexAsString(nullptr, idx, path); |
| 3847 | } |
| 3848 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3849 | LanguageType TargetProperties::GetLanguage() const { |
| 3850 | OptionValueLanguage *value = |
| 3851 | m_collection_sp->GetPropertyAtIndexAsOptionValueLanguage( |
| 3852 | nullptr, ePropertyLanguage); |
| 3853 | if (value) |
| 3854 | return value->GetCurrentValue(); |
| 3855 | return LanguageType(); |
Dawn Perchik | 23b1dec | 2015-07-21 22:05:07 +0000 | [diff] [blame] | 3856 | } |
| 3857 | |
Pavel Labath | 50251fc | 2017-12-21 10:54:30 +0000 | [diff] [blame] | 3858 | llvm::StringRef TargetProperties::GetExpressionPrefixContents() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3859 | const uint32_t idx = ePropertyExprPrefix; |
| 3860 | OptionValueFileSpec *file = |
| 3861 | m_collection_sp->GetPropertyAtIndexAsOptionValueFileSpec(nullptr, false, |
| 3862 | idx); |
| 3863 | if (file) { |
Pavel Labath | 50251fc | 2017-12-21 10:54:30 +0000 | [diff] [blame] | 3864 | DataBufferSP data_sp(file->GetFileContents()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3865 | if (data_sp) |
Pavel Labath | 50251fc | 2017-12-21 10:54:30 +0000 | [diff] [blame] | 3866 | return llvm::StringRef( |
| 3867 | reinterpret_cast<const char *>(data_sp->GetBytes()), |
| 3868 | data_sp->GetByteSize()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3869 | } |
Pavel Labath | 50251fc | 2017-12-21 10:54:30 +0000 | [diff] [blame] | 3870 | return ""; |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3873 | bool TargetProperties::GetBreakpointsConsultPlatformAvoidList() { |
| 3874 | const uint32_t idx = ePropertyBreakpointUseAvoidList; |
| 3875 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3876 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3877 | } |
| 3878 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3879 | bool TargetProperties::GetUseHexImmediates() const { |
| 3880 | const uint32_t idx = ePropertyUseHexImmediates; |
| 3881 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3882 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Daniel Malea | d79ae05 | 2013-08-07 21:54:09 +0000 | [diff] [blame] | 3883 | } |
| 3884 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3885 | bool TargetProperties::GetUseFastStepping() const { |
| 3886 | const uint32_t idx = ePropertyUseFastStepping; |
| 3887 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3888 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Jim Ingham | 17d023f | 2013-03-13 17:58:04 +0000 | [diff] [blame] | 3889 | } |
| 3890 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3891 | bool TargetProperties::GetDisplayExpressionsInCrashlogs() const { |
| 3892 | const uint32_t idx = ePropertyDisplayExpressionsInCrashlogs; |
| 3893 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3894 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Greg Clayton | fb6621e | 2013-12-06 21:59:52 +0000 | [diff] [blame] | 3895 | } |
| 3896 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3897 | LoadScriptFromSymFile TargetProperties::GetLoadScriptFromSymbolFile() const { |
| 3898 | const uint32_t idx = ePropertyLoadScriptFromSymbolFile; |
| 3899 | return (LoadScriptFromSymFile) |
| 3900 | m_collection_sp->GetPropertyAtIndexAsEnumeration( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3901 | nullptr, idx, g_target_properties[idx].default_uint_value); |
Enrico Granata | 2ea43cd | 2013-05-13 17:03:52 +0000 | [diff] [blame] | 3902 | } |
| 3903 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3904 | LoadCWDlldbinitFile TargetProperties::GetLoadCWDlldbinitFile() const { |
| 3905 | const uint32_t idx = ePropertyLoadCWDlldbinitFile; |
| 3906 | return (LoadCWDlldbinitFile)m_collection_sp->GetPropertyAtIndexAsEnumeration( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3907 | nullptr, idx, g_target_properties[idx].default_uint_value); |
Jason Molenda | 878ae01 | 2016-02-19 00:05:17 +0000 | [diff] [blame] | 3908 | } |
| 3909 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3910 | Disassembler::HexImmediateStyle TargetProperties::GetHexImmediateStyle() const { |
| 3911 | const uint32_t idx = ePropertyHexImmediateStyle; |
| 3912 | return (Disassembler::HexImmediateStyle) |
| 3913 | m_collection_sp->GetPropertyAtIndexAsEnumeration( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3914 | nullptr, idx, g_target_properties[idx].default_uint_value); |
Daniel Malea | d79ae05 | 2013-08-07 21:54:09 +0000 | [diff] [blame] | 3915 | } |
| 3916 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3917 | MemoryModuleLoadLevel TargetProperties::GetMemoryModuleLoadLevel() const { |
| 3918 | const uint32_t idx = ePropertyMemoryModuleLoadLevel; |
| 3919 | return (MemoryModuleLoadLevel) |
| 3920 | m_collection_sp->GetPropertyAtIndexAsEnumeration( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3921 | nullptr, idx, g_target_properties[idx].default_uint_value); |
Greg Clayton | fd814c5 | 2013-08-13 01:42:25 +0000 | [diff] [blame] | 3922 | } |
| 3923 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3924 | bool TargetProperties::GetUserSpecifiedTrapHandlerNames(Args &args) const { |
| 3925 | const uint32_t idx = ePropertyTrapHandlerNames; |
| 3926 | return m_collection_sp->GetPropertyAtIndexAsArgs(nullptr, idx, args); |
Jason Molenda | a4bea72 | 2014-02-14 05:06:49 +0000 | [diff] [blame] | 3927 | } |
Greg Clayton | fd814c5 | 2013-08-13 01:42:25 +0000 | [diff] [blame] | 3928 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3929 | void TargetProperties::SetUserSpecifiedTrapHandlerNames(const Args &args) { |
| 3930 | const uint32_t idx = ePropertyTrapHandlerNames; |
| 3931 | m_collection_sp->SetPropertyAtIndexFromArgs(nullptr, idx, args); |
Jason Molenda | a4bea72 | 2014-02-14 05:06:49 +0000 | [diff] [blame] | 3932 | } |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 3933 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3934 | bool TargetProperties::GetDisplayRuntimeSupportValues() const { |
| 3935 | const uint32_t idx = ePropertyDisplayRuntimeSupportValues; |
| 3936 | return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, false); |
Enrico Granata | 560558e | 2015-02-11 02:35:39 +0000 | [diff] [blame] | 3937 | } |
| 3938 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3939 | void TargetProperties::SetDisplayRuntimeSupportValues(bool b) { |
| 3940 | const uint32_t idx = ePropertyDisplayRuntimeSupportValues; |
| 3941 | m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
Enrico Granata | 560558e | 2015-02-11 02:35:39 +0000 | [diff] [blame] | 3942 | } |
| 3943 | |
Kuba Mracek | 4c7f5d5 | 2018-12-20 23:38:19 +0000 | [diff] [blame] | 3944 | bool TargetProperties::GetDisplayRecognizedArguments() const { |
| 3945 | const uint32_t idx = ePropertyDisplayRecognizedArguments; |
| 3946 | return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, false); |
| 3947 | } |
| 3948 | |
| 3949 | void TargetProperties::SetDisplayRecognizedArguments(bool b) { |
| 3950 | const uint32_t idx = ePropertyDisplayRecognizedArguments; |
| 3951 | m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
| 3952 | } |
| 3953 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3954 | bool TargetProperties::GetNonStopModeEnabled() const { |
| 3955 | const uint32_t idx = ePropertyNonStopModeEnabled; |
| 3956 | return m_collection_sp->GetPropertyAtIndexAsBoolean(nullptr, idx, false); |
Ewan Crawford | 78baa19 | 2015-05-13 09:18:18 +0000 | [diff] [blame] | 3957 | } |
| 3958 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3959 | void TargetProperties::SetNonStopModeEnabled(bool b) { |
| 3960 | const uint32_t idx = ePropertyNonStopModeEnabled; |
| 3961 | m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
Ewan Crawford | aa7eda7 | 2015-06-24 15:14:26 +0000 | [diff] [blame] | 3962 | } |
| 3963 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3964 | const ProcessLaunchInfo &TargetProperties::GetProcessLaunchInfo() { |
| 3965 | m_launch_info.SetArg0(GetArg0()); // FIXME: Arg0 callback doesn't work |
| 3966 | return m_launch_info; |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 3967 | } |
| 3968 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3969 | void TargetProperties::SetProcessLaunchInfo( |
| 3970 | const ProcessLaunchInfo &launch_info) { |
| 3971 | m_launch_info = launch_info; |
| 3972 | SetArg0(launch_info.GetArg0()); |
| 3973 | SetRunArguments(launch_info.GetArguments()); |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 3974 | SetEnvironment(launch_info.GetEnvironment()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3975 | const FileAction *input_file_action = |
| 3976 | launch_info.GetFileActionForFD(STDIN_FILENO); |
| 3977 | if (input_file_action) { |
Zachary Turner | 27a5c2b | 2016-09-23 22:11:51 +0000 | [diff] [blame] | 3978 | SetStandardInputPath(input_file_action->GetPath()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3979 | } |
| 3980 | const FileAction *output_file_action = |
| 3981 | launch_info.GetFileActionForFD(STDOUT_FILENO); |
| 3982 | if (output_file_action) { |
Zachary Turner | 27a5c2b | 2016-09-23 22:11:51 +0000 | [diff] [blame] | 3983 | SetStandardOutputPath(output_file_action->GetPath()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3984 | } |
| 3985 | const FileAction *error_file_action = |
| 3986 | launch_info.GetFileActionForFD(STDERR_FILENO); |
| 3987 | if (error_file_action) { |
Zachary Turner | 27a5c2b | 2016-09-23 22:11:51 +0000 | [diff] [blame] | 3988 | SetStandardErrorPath(error_file_action->GetPath()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 3989 | } |
| 3990 | SetDetachOnError(launch_info.GetFlags().Test(lldb::eLaunchFlagDetachOnError)); |
| 3991 | SetDisableASLR(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR)); |
| 3992 | SetDisableSTDIO(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableSTDIO)); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 3993 | } |
| 3994 | |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 3995 | bool TargetProperties::GetRequireHardwareBreakpoints() const { |
| 3996 | const uint32_t idx = ePropertyRequireHardwareBreakpoints; |
| 3997 | return m_collection_sp->GetPropertyAtIndexAsBoolean( |
Jonas Devlieghere | a8ea595 | 2019-07-29 16:41:30 +0000 | [diff] [blame] | 3998 | nullptr, idx, g_target_properties[idx].default_uint_value != 0); |
Jonas Devlieghere | e103ae9 | 2018-11-15 01:18:15 +0000 | [diff] [blame] | 3999 | } |
| 4000 | |
| 4001 | void TargetProperties::SetRequireHardwareBreakpoints(bool b) { |
| 4002 | const uint32_t idx = ePropertyRequireHardwareBreakpoints; |
| 4003 | m_collection_sp->SetPropertyAtIndexAsBoolean(nullptr, idx, b); |
| 4004 | } |
| 4005 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4006 | void TargetProperties::Arg0ValueChangedCallback(void *target_property_ptr, |
| 4007 | OptionValue *) { |
| 4008 | TargetProperties *this_ = |
| 4009 | reinterpret_cast<TargetProperties *>(target_property_ptr); |
| 4010 | this_->m_launch_info.SetArg0(this_->GetArg0()); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 4011 | } |
| 4012 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4013 | void TargetProperties::RunArgsValueChangedCallback(void *target_property_ptr, |
| 4014 | OptionValue *) { |
| 4015 | TargetProperties *this_ = |
| 4016 | reinterpret_cast<TargetProperties *>(target_property_ptr); |
| 4017 | Args args; |
| 4018 | if (this_->GetRunArguments(args)) |
| 4019 | this_->m_launch_info.GetArguments() = args; |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 4020 | } |
| 4021 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4022 | void TargetProperties::EnvVarsValueChangedCallback(void *target_property_ptr, |
| 4023 | OptionValue *) { |
| 4024 | TargetProperties *this_ = |
| 4025 | reinterpret_cast<TargetProperties *>(target_property_ptr); |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 4026 | this_->m_launch_info.GetEnvironment() = this_->GetEnvironment(); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 4027 | } |
| 4028 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4029 | void TargetProperties::InputPathValueChangedCallback(void *target_property_ptr, |
| 4030 | OptionValue *) { |
| 4031 | TargetProperties *this_ = |
| 4032 | reinterpret_cast<TargetProperties *>(target_property_ptr); |
| 4033 | this_->m_launch_info.AppendOpenFileAction( |
| 4034 | STDIN_FILENO, this_->GetStandardInputPath(), true, false); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 4035 | } |
| 4036 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4037 | void TargetProperties::OutputPathValueChangedCallback(void *target_property_ptr, |
| 4038 | OptionValue *) { |
| 4039 | TargetProperties *this_ = |
| 4040 | reinterpret_cast<TargetProperties *>(target_property_ptr); |
| 4041 | this_->m_launch_info.AppendOpenFileAction( |
| 4042 | STDOUT_FILENO, this_->GetStandardOutputPath(), false, true); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 4043 | } |
| 4044 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4045 | void TargetProperties::ErrorPathValueChangedCallback(void *target_property_ptr, |
| 4046 | OptionValue *) { |
| 4047 | TargetProperties *this_ = |
| 4048 | reinterpret_cast<TargetProperties *>(target_property_ptr); |
| 4049 | this_->m_launch_info.AppendOpenFileAction( |
| 4050 | STDERR_FILENO, this_->GetStandardErrorPath(), false, true); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 4051 | } |
| 4052 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4053 | void TargetProperties::DetachOnErrorValueChangedCallback( |
| 4054 | void *target_property_ptr, OptionValue *) { |
| 4055 | TargetProperties *this_ = |
| 4056 | reinterpret_cast<TargetProperties *>(target_property_ptr); |
| 4057 | if (this_->GetDetachOnError()) |
| 4058 | this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDetachOnError); |
| 4059 | else |
| 4060 | this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDetachOnError); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 4061 | } |
| 4062 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4063 | void TargetProperties::DisableASLRValueChangedCallback( |
| 4064 | void *target_property_ptr, OptionValue *) { |
| 4065 | TargetProperties *this_ = |
| 4066 | reinterpret_cast<TargetProperties *>(target_property_ptr); |
| 4067 | if (this_->GetDisableASLR()) |
| 4068 | this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableASLR); |
| 4069 | else |
| 4070 | this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableASLR); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 4071 | } |
| 4072 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4073 | void TargetProperties::DisableSTDIOValueChangedCallback( |
| 4074 | void *target_property_ptr, OptionValue *) { |
| 4075 | TargetProperties *this_ = |
| 4076 | reinterpret_cast<TargetProperties *>(target_property_ptr); |
| 4077 | if (this_->GetDisableSTDIO()) |
| 4078 | this_->m_launch_info.GetFlags().Set(lldb::eLaunchFlagDisableSTDIO); |
| 4079 | else |
| 4080 | this_->m_launch_info.GetFlags().Clear(lldb::eLaunchFlagDisableSTDIO); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 4081 | } |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 4082 | |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 4083 | // Target::TargetEventData |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 4084 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4085 | Target::TargetEventData::TargetEventData(const lldb::TargetSP &target_sp) |
| 4086 | : EventData(), m_target_sp(target_sp), m_module_list() {} |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 4087 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4088 | Target::TargetEventData::TargetEventData(const lldb::TargetSP &target_sp, |
| 4089 | const ModuleList &module_list) |
| 4090 | : EventData(), m_target_sp(target_sp), m_module_list(module_list) {} |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 4091 | |
Eugene Zelenko | 8f30a65 | 2015-10-23 18:39:37 +0000 | [diff] [blame] | 4092 | Target::TargetEventData::~TargetEventData() = default; |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 4093 | |
Adrian Prantl | 0e4c482 | 2019-03-06 21:22:25 +0000 | [diff] [blame] | 4094 | ConstString Target::TargetEventData::GetFlavorString() { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4095 | static ConstString g_flavor("Target::TargetEventData"); |
| 4096 | return g_flavor; |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 4097 | } |
| 4098 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4099 | void Target::TargetEventData::Dump(Stream *s) const { |
| 4100 | for (size_t i = 0; i < m_module_list.GetSize(); ++i) { |
| 4101 | if (i != 0) |
| 4102 | *s << ", "; |
| 4103 | m_module_list.GetModuleAtIndex(i)->GetDescription( |
| 4104 | s, lldb::eDescriptionLevelBrief); |
| 4105 | } |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | const Target::TargetEventData * |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4109 | Target::TargetEventData::GetEventDataFromEvent(const Event *event_ptr) { |
| 4110 | if (event_ptr) { |
| 4111 | const EventData *event_data = event_ptr->GetData(); |
| 4112 | if (event_data && |
| 4113 | event_data->GetFlavor() == TargetEventData::GetFlavorString()) |
| 4114 | return static_cast<const TargetEventData *>(event_ptr->GetData()); |
| 4115 | } |
| 4116 | return nullptr; |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 4117 | } |
| 4118 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4119 | TargetSP Target::TargetEventData::GetTargetFromEvent(const Event *event_ptr) { |
| 4120 | TargetSP target_sp; |
| 4121 | const TargetEventData *event_data = GetEventDataFromEvent(event_ptr); |
| 4122 | if (event_data) |
| 4123 | target_sp = event_data->m_target_sp; |
| 4124 | return target_sp; |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 4125 | } |
| 4126 | |
| 4127 | ModuleList |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 4128 | Target::TargetEventData::GetModuleListFromEvent(const Event *event_ptr) { |
| 4129 | ModuleList module_list; |
| 4130 | const TargetEventData *event_data = GetEventDataFromEvent(event_ptr); |
| 4131 | if (event_data) |
| 4132 | module_list = event_data->m_module_list; |
| 4133 | return module_list; |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 4134 | } |