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