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