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