Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBTarget.cpp --------------------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Eli Friedman | 4c5de69 | 2010-06-09 07:44:37 +0000 | [diff] [blame] | 10 | #include "lldb/API/SBTarget.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 11 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 12 | #include "lldb/lldb-public.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 14 | #include "lldb/API/SBBreakpoint.h" |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 15 | #include "lldb/API/SBDebugger.h" |
| 16 | #include "lldb/API/SBEvent.h" |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 17 | #include "lldb/API/SBExpressionOptions.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/API/SBFileSpec.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 19 | #include "lldb/API/SBListener.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/API/SBModule.h" |
Greg Clayton | 226cce2 | 2013-07-08 22:22:41 +0000 | [diff] [blame] | 21 | #include "lldb/API/SBModuleSpec.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 22 | #include "lldb/API/SBProcess.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | #include "lldb/API/SBSourceManager.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 24 | #include "lldb/API/SBStream.h" |
Jim Ingham | 76bb8d6 | 2016-04-28 01:40:57 +0000 | [diff] [blame] | 25 | #include "lldb/API/SBStringList.h" |
Davide Italiano | 4a6a2b1 | 2018-04-16 22:55:34 +0000 | [diff] [blame] | 26 | #include "lldb/API/SBStructuredData.h" |
Greg Clayton | fe356d3 | 2011-06-21 01:34:41 +0000 | [diff] [blame] | 27 | #include "lldb/API/SBSymbolContextList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 28 | #include "lldb/Breakpoint/BreakpointID.h" |
| 29 | #include "lldb/Breakpoint/BreakpointIDList.h" |
| 30 | #include "lldb/Breakpoint/BreakpointList.h" |
| 31 | #include "lldb/Breakpoint/BreakpointLocation.h" |
| 32 | #include "lldb/Core/Address.h" |
| 33 | #include "lldb/Core/AddressResolver.h" |
| 34 | #include "lldb/Core/AddressResolverName.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 35 | #include "lldb/Core/Debugger.h" |
| 36 | #include "lldb/Core/Disassembler.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 37 | #include "lldb/Core/Module.h" |
| 38 | #include "lldb/Core/ModuleSpec.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 39 | #include "lldb/Core/STLUtils.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 40 | #include "lldb/Core/SearchFilter.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 41 | #include "lldb/Core/Section.h" |
Davide Italiano | 4a6a2b1 | 2018-04-16 22:55:34 +0000 | [diff] [blame] | 42 | #include "lldb/Core/StructuredDataImpl.h" |
Enrico Granata | 347c2aa | 2013-10-08 21:49:02 +0000 | [diff] [blame] | 43 | #include "lldb/Core/ValueObjectConstResult.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 44 | #include "lldb/Core/ValueObjectList.h" |
| 45 | #include "lldb/Core/ValueObjectVariable.h" |
Greg Clayton | 7fb56d0 | 2011-02-01 01:31:41 +0000 | [diff] [blame] | 46 | #include "lldb/Host/Host.h" |
Zachary Turner | a78bd7f | 2015-03-03 23:11:11 +0000 | [diff] [blame] | 47 | #include "lldb/Symbol/ClangASTContext.h" |
| 48 | #include "lldb/Symbol/DeclVendor.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 49 | #include "lldb/Symbol/ObjectFile.h" |
Greg Clayton | ae088e5 | 2016-02-10 21:28:13 +0000 | [diff] [blame] | 50 | #include "lldb/Symbol/SymbolFile.h" |
Enrico Granata | 6f3533f | 2011-07-29 19:53:35 +0000 | [diff] [blame] | 51 | #include "lldb/Symbol/SymbolVendor.h" |
Greg Clayton | dea8cb4 | 2011-06-29 22:09:02 +0000 | [diff] [blame] | 52 | #include "lldb/Symbol/VariableList.h" |
Zachary Turner | 32abc6e | 2015-03-03 19:23:09 +0000 | [diff] [blame] | 53 | #include "lldb/Target/ABI.h" |
Jim Ingham | 0e0984e | 2015-09-02 01:06:46 +0000 | [diff] [blame] | 54 | #include "lldb/Target/Language.h" |
Jim Ingham | fab10e8 | 2012-03-06 00:37:27 +0000 | [diff] [blame] | 55 | #include "lldb/Target/LanguageRuntime.h" |
Zachary Turner | a78bd7f | 2015-03-03 23:11:11 +0000 | [diff] [blame] | 56 | #include "lldb/Target/ObjCLanguageRuntime.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | #include "lldb/Target/Process.h" |
Enrico Granata | b10e003 | 2015-03-04 21:33:45 +0000 | [diff] [blame] | 58 | #include "lldb/Target/StackFrame.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 59 | #include "lldb/Target/Target.h" |
| 60 | #include "lldb/Target/TargetList.h" |
Pavel Labath | 5f19b90 | 2017-11-13 16:16:33 +0000 | [diff] [blame] | 61 | #include "lldb/Utility/ArchSpec.h" |
Pavel Labath | 145d95c | 2018-04-17 18:53:35 +0000 | [diff] [blame] | 62 | #include "lldb/Utility/Args.h" |
Zachary Turner | 5713a05 | 2017-03-22 18:40:07 +0000 | [diff] [blame] | 63 | #include "lldb/Utility/FileSpec.h" |
Zachary Turner | 6f9e690 | 2017-03-03 20:56:28 +0000 | [diff] [blame] | 64 | #include "lldb/Utility/Log.h" |
Zachary Turner | bf9a773 | 2017-02-02 21:39:50 +0000 | [diff] [blame] | 65 | #include "lldb/Utility/RegularExpression.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 66 | |
James Y Knight | 2ad4821 | 2018-05-22 22:53:50 +0000 | [diff] [blame] | 67 | #include "Commands/CommandObjectBreakpoint.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 68 | #include "lldb/Interpreter/CommandReturnObject.h" |
Sean Callanan | 237c3ed | 2016-12-14 21:31:31 +0000 | [diff] [blame] | 69 | #include "llvm/Support/PrettyStackTrace.h" |
Carlo Kok | 0fd6fd4 | 2014-09-19 19:38:19 +0000 | [diff] [blame] | 70 | #include "llvm/Support/Regex.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 72 | using namespace lldb; |
| 73 | using namespace lldb_private; |
| 74 | |
| 75 | #define DEFAULT_DISASM_BYTE_SIZE 32 |
| 76 | |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 77 | namespace { |
| 78 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 79 | Status AttachToProcess(ProcessAttachInfo &attach_info, Target &target) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 80 | std::lock_guard<std::recursive_mutex> guard(target.GetAPIMutex()); |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 81 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 82 | auto process_sp = target.GetProcessSP(); |
| 83 | if (process_sp) { |
| 84 | const auto state = process_sp->GetState(); |
| 85 | if (process_sp->IsAlive() && state == eStateConnected) { |
| 86 | // If we are already connected, then we have already specified the |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 87 | // listener, so if a valid listener is supplied, we need to error out to |
| 88 | // let the client know. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 89 | if (attach_info.GetListener()) |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 90 | return Status("process is connected and already has a listener, pass " |
| 91 | "empty listener"); |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 92 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 93 | } |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 94 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 95 | return target.Attach(attach_info, nullptr); |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 98 | } // namespace |
Oleksiy Vyalov | 3738614 | 2015-02-10 22:49:57 +0000 | [diff] [blame] | 99 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 100 | //---------------------------------------------------------------------- |
| 101 | // SBTarget constructor |
| 102 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 103 | SBTarget::SBTarget() : m_opaque_sp() {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 104 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 105 | SBTarget::SBTarget(const SBTarget &rhs) : m_opaque_sp(rhs.m_opaque_sp) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 106 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 107 | SBTarget::SBTarget(const TargetSP &target_sp) : m_opaque_sp(target_sp) {} |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 108 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 109 | const SBTarget &SBTarget::operator=(const SBTarget &rhs) { |
| 110 | if (this != &rhs) |
| 111 | m_opaque_sp = rhs.m_opaque_sp; |
| 112 | return *this; |
Greg Clayton | efabb12 | 2010-11-05 23:17:00 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | //---------------------------------------------------------------------- |
| 116 | // Destructor |
| 117 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 118 | SBTarget::~SBTarget() {} |
| 119 | |
| 120 | bool SBTarget::EventIsTargetEvent(const SBEvent &event) { |
| 121 | return Target::TargetEventData::GetEventDataFromEvent(event.get()) != NULL; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 124 | SBTarget SBTarget::GetTargetFromEvent(const SBEvent &event) { |
| 125 | return Target::TargetEventData::GetTargetFromEvent(event.get()); |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 126 | } |
| 127 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 128 | uint32_t SBTarget::GetNumModulesFromEvent(const SBEvent &event) { |
| 129 | const ModuleList module_list = |
| 130 | Target::TargetEventData::GetModuleListFromEvent(event.get()); |
| 131 | return module_list.GetSize(); |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 134 | SBModule SBTarget::GetModuleAtIndexFromEvent(const uint32_t idx, |
| 135 | const SBEvent &event) { |
| 136 | const ModuleList module_list = |
| 137 | Target::TargetEventData::GetModuleListFromEvent(event.get()); |
| 138 | return SBModule(module_list.GetModuleAtIndex(idx)); |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 141 | const char *SBTarget::GetBroadcasterClassName() { |
| 142 | return Target::GetStaticBroadcasterClass().AsCString(); |
Ilia K | eb2c19a | 2015-03-10 21:59:55 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 145 | bool SBTarget::IsValid() const { |
| 146 | return m_opaque_sp.get() != NULL && m_opaque_sp->IsValid(); |
Jim Ingham | 4bddaeb | 2012-02-16 06:50:00 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 149 | SBProcess SBTarget::GetProcess() { |
| 150 | SBProcess sb_process; |
| 151 | ProcessSP process_sp; |
| 152 | TargetSP target_sp(GetSP()); |
| 153 | if (target_sp) { |
| 154 | process_sp = target_sp->GetProcessSP(); |
| 155 | sb_process.SetSP(process_sp); |
| 156 | } |
| 157 | |
| 158 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 159 | if (log) |
| 160 | log->Printf("SBTarget(%p)::GetProcess () => SBProcess(%p)", |
| 161 | static_cast<void *>(target_sp.get()), |
| 162 | static_cast<void *>(process_sp.get())); |
| 163 | |
| 164 | return sb_process; |
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 | SBPlatform SBTarget::GetPlatform() { |
| 168 | TargetSP target_sp(GetSP()); |
| 169 | if (!target_sp) |
| 170 | return SBPlatform(); |
| 171 | |
| 172 | SBPlatform platform; |
| 173 | platform.m_opaque_sp = target_sp->GetPlatform(); |
| 174 | |
| 175 | return platform; |
| 176 | } |
| 177 | |
| 178 | SBDebugger SBTarget::GetDebugger() const { |
| 179 | SBDebugger debugger; |
| 180 | TargetSP target_sp(GetSP()); |
| 181 | if (target_sp) |
| 182 | debugger.reset(target_sp->GetDebugger().shared_from_this()); |
| 183 | return debugger; |
| 184 | } |
| 185 | |
Davide Italiano | 4a6a2b1 | 2018-04-16 22:55:34 +0000 | [diff] [blame] | 186 | SBStructuredData SBTarget::GetStatistics() { |
| 187 | SBStructuredData data; |
| 188 | TargetSP target_sp(GetSP()); |
| 189 | if (!target_sp) |
| 190 | return data; |
| 191 | |
| 192 | auto stats_up = llvm::make_unique<StructuredData::Dictionary>(); |
| 193 | int i = 0; |
| 194 | for (auto &Entry : target_sp->GetStatistics()) { |
| 195 | std::string Desc = lldb_private::GetStatDescription( |
| 196 | static_cast<lldb_private::StatisticKind>(i)); |
| 197 | stats_up->AddIntegerItem(Desc, Entry); |
| 198 | i += 1; |
| 199 | } |
| 200 | |
| 201 | data.m_impl_up->SetObjectSP(std::move(stats_up)); |
| 202 | return data; |
| 203 | } |
| 204 | |
Davide Italiano | e174746 | 2018-09-28 23:27:54 +0000 | [diff] [blame] | 205 | void SBTarget::SetCollectingStats(bool v) { |
| 206 | TargetSP target_sp(GetSP()); |
| 207 | if (!target_sp) |
| 208 | return; |
| 209 | return target_sp->SetCollectingStats(v); |
| 210 | } |
| 211 | |
| 212 | bool SBTarget::GetCollectingStats() { |
| 213 | TargetSP target_sp(GetSP()); |
| 214 | if (!target_sp) |
| 215 | return false; |
| 216 | return target_sp->GetCollectingStats(); |
| 217 | } |
| 218 | |
| 219 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 220 | SBProcess SBTarget::LoadCore(const char *core_file) { |
Leonard Mosescu | e1bb517 | 2018-06-11 21:19:26 +0000 | [diff] [blame] | 221 | lldb::SBError error; // Ignored |
| 222 | return LoadCore(core_file, error); |
| 223 | } |
| 224 | |
| 225 | SBProcess SBTarget::LoadCore(const char *core_file, lldb::SBError &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 226 | SBProcess sb_process; |
| 227 | TargetSP target_sp(GetSP()); |
| 228 | if (target_sp) { |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 229 | FileSpec filespec(core_file); |
| 230 | FileSystem::Instance().Resolve(filespec); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 231 | ProcessSP process_sp(target_sp->CreateProcess( |
Zachary Turner | 3165945 | 2016-11-17 21:15:14 +0000 | [diff] [blame] | 232 | target_sp->GetDebugger().GetListener(), "", &filespec)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 233 | if (process_sp) { |
Leonard Mosescu | e1bb517 | 2018-06-11 21:19:26 +0000 | [diff] [blame] | 234 | error.SetError(process_sp->LoadCore()); |
| 235 | if (error.Success()) |
| 236 | sb_process.SetSP(process_sp); |
| 237 | } else { |
| 238 | error.SetErrorString("Failed to create the process"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 239 | } |
Leonard Mosescu | e1bb517 | 2018-06-11 21:19:26 +0000 | [diff] [blame] | 240 | } else { |
| 241 | error.SetErrorString("SBTarget is invalid"); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 242 | } |
| 243 | return sb_process; |
| 244 | } |
| 245 | |
| 246 | SBProcess SBTarget::LaunchSimple(char const **argv, char const **envp, |
| 247 | const char *working_directory) { |
| 248 | char *stdin_path = NULL; |
| 249 | char *stdout_path = NULL; |
| 250 | char *stderr_path = NULL; |
| 251 | uint32_t launch_flags = 0; |
| 252 | bool stop_at_entry = false; |
| 253 | SBError error; |
| 254 | SBListener listener = GetDebugger().GetListener(); |
| 255 | return Launch(listener, argv, envp, stdin_path, stdout_path, stderr_path, |
| 256 | working_directory, launch_flags, stop_at_entry, error); |
| 257 | } |
| 258 | |
| 259 | SBError SBTarget::Install() { |
| 260 | SBError sb_error; |
| 261 | TargetSP target_sp(GetSP()); |
| 262 | if (target_sp) { |
| 263 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 264 | sb_error.ref() = target_sp->Install(NULL); |
| 265 | } |
| 266 | return sb_error; |
| 267 | } |
| 268 | |
| 269 | SBProcess SBTarget::Launch(SBListener &listener, char const **argv, |
| 270 | char const **envp, const char *stdin_path, |
| 271 | const char *stdout_path, const char *stderr_path, |
| 272 | const char *working_directory, |
| 273 | uint32_t launch_flags, // See LaunchFlags |
| 274 | bool stop_at_entry, lldb::SBError &error) { |
| 275 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 276 | |
| 277 | SBProcess sb_process; |
| 278 | ProcessSP process_sp; |
| 279 | TargetSP target_sp(GetSP()); |
| 280 | |
| 281 | if (log) |
| 282 | log->Printf("SBTarget(%p)::Launch (argv=%p, envp=%p, stdin=%s, stdout=%s, " |
| 283 | "stderr=%s, working-dir=%s, launch_flags=0x%x, " |
| 284 | "stop_at_entry=%i, &error (%p))...", |
| 285 | static_cast<void *>(target_sp.get()), static_cast<void *>(argv), |
| 286 | static_cast<void *>(envp), stdin_path ? stdin_path : "NULL", |
| 287 | stdout_path ? stdout_path : "NULL", |
| 288 | stderr_path ? stderr_path : "NULL", |
| 289 | working_directory ? working_directory : "NULL", launch_flags, |
| 290 | stop_at_entry, static_cast<void *>(error.get())); |
| 291 | |
| 292 | if (target_sp) { |
| 293 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 294 | |
| 295 | if (stop_at_entry) |
| 296 | launch_flags |= eLaunchFlagStopAtEntry; |
| 297 | |
| 298 | if (getenv("LLDB_LAUNCH_FLAG_DISABLE_ASLR")) |
| 299 | launch_flags |= eLaunchFlagDisableASLR; |
| 300 | |
| 301 | StateType state = eStateInvalid; |
| 302 | process_sp = target_sp->GetProcessSP(); |
| 303 | if (process_sp) { |
| 304 | state = process_sp->GetState(); |
| 305 | |
| 306 | if (process_sp->IsAlive() && state != eStateConnected) { |
| 307 | if (state == eStateAttaching) |
| 308 | error.SetErrorString("process attach is in progress"); |
| 309 | else |
| 310 | error.SetErrorString("a process is already being debugged"); |
| 311 | return sb_process; |
| 312 | } |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 313 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 314 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 315 | if (state == eStateConnected) { |
| 316 | // If we are already connected, then we have already specified the |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 317 | // listener, so if a valid listener is supplied, we need to error out to |
| 318 | // let the client know. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 319 | if (listener.IsValid()) { |
| 320 | error.SetErrorString("process is connected and already has a listener, " |
| 321 | "pass empty listener"); |
| 322 | return sb_process; |
| 323 | } |
| 324 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 325 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 326 | if (getenv("LLDB_LAUNCH_FLAG_DISABLE_STDIO")) |
| 327 | launch_flags |= eLaunchFlagDisableSTDIO; |
| 328 | |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 329 | ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path), |
| 330 | FileSpec(stderr_path), |
| 331 | FileSpec(working_directory), launch_flags); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 332 | |
| 333 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
| 334 | if (exe_module) |
| 335 | launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); |
| 336 | if (argv) |
| 337 | launch_info.GetArguments().AppendArguments(argv); |
| 338 | if (envp) |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 339 | launch_info.GetEnvironment() = Environment(envp); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 340 | |
| 341 | if (listener.IsValid()) |
| 342 | launch_info.SetListener(listener.GetSP()); |
| 343 | |
| 344 | error.SetError(target_sp->Launch(launch_info, NULL)); |
| 345 | |
| 346 | sb_process.SetSP(target_sp->GetProcessSP()); |
| 347 | } else { |
| 348 | error.SetErrorString("SBTarget is invalid"); |
| 349 | } |
| 350 | |
| 351 | log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API); |
| 352 | if (log) |
| 353 | log->Printf("SBTarget(%p)::Launch (...) => SBProcess(%p), SBError(%s)", |
| 354 | static_cast<void *>(target_sp.get()), |
| 355 | static_cast<void *>(sb_process.GetSP().get()), |
| 356 | error.GetCString()); |
| 357 | |
| 358 | return sb_process; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 361 | SBProcess SBTarget::Launch(SBLaunchInfo &sb_launch_info, SBError &error) { |
| 362 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 363 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 364 | SBProcess sb_process; |
| 365 | TargetSP target_sp(GetSP()); |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 366 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 367 | if (log) |
| 368 | log->Printf("SBTarget(%p)::Launch (launch_info, error)...", |
| 369 | static_cast<void *>(target_sp.get())); |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 370 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 371 | if (target_sp) { |
| 372 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 373 | StateType state = eStateInvalid; |
Greg Clayton | 4d8ad55 | 2013-03-25 22:40:51 +0000 | [diff] [blame] | 374 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 375 | ProcessSP process_sp = target_sp->GetProcessSP(); |
| 376 | if (process_sp) { |
| 377 | state = process_sp->GetState(); |
| 378 | |
| 379 | if (process_sp->IsAlive() && state != eStateConnected) { |
| 380 | if (state == eStateAttaching) |
| 381 | error.SetErrorString("process attach is in progress"); |
| 382 | else |
| 383 | error.SetErrorString("a process is already being debugged"); |
| 384 | return sb_process; |
Greg Clayton | 4d8ad55 | 2013-03-25 22:40:51 +0000 | [diff] [blame] | 385 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 386 | } |
Greg Clayton | 4d8ad55 | 2013-03-25 22:40:51 +0000 | [diff] [blame] | 387 | } |
Greg Clayton | 4d8ad55 | 2013-03-25 22:40:51 +0000 | [diff] [blame] | 388 | |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 389 | lldb_private::ProcessLaunchInfo launch_info = sb_launch_info.ref(); |
Greg Clayton | bd82a5d | 2011-01-23 05:56:20 +0000 | [diff] [blame] | 390 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 391 | if (!launch_info.GetExecutableFile()) { |
| 392 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
| 393 | if (exe_module) |
| 394 | launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true); |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 395 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 396 | |
| 397 | const ArchSpec &arch_spec = target_sp->GetArchitecture(); |
| 398 | if (arch_spec.IsValid()) |
| 399 | launch_info.GetArchitecture() = arch_spec; |
| 400 | |
| 401 | error.SetError(target_sp->Launch(launch_info, NULL)); |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 402 | sb_launch_info.set_ref(launch_info); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 403 | sb_process.SetSP(target_sp->GetProcessSP()); |
| 404 | } else { |
| 405 | error.SetErrorString("SBTarget is invalid"); |
| 406 | } |
| 407 | |
| 408 | log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API); |
| 409 | if (log) |
| 410 | log->Printf("SBTarget(%p)::Launch (...) => SBProcess(%p)", |
| 411 | static_cast<void *>(target_sp.get()), |
| 412 | static_cast<void *>(sb_process.GetSP().get())); |
| 413 | |
| 414 | return sb_process; |
Greg Clayton | fbb7634 | 2013-11-20 21:07:01 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 417 | lldb::SBProcess SBTarget::Attach(SBAttachInfo &sb_attach_info, SBError &error) { |
| 418 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 419 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 420 | SBProcess sb_process; |
| 421 | TargetSP target_sp(GetSP()); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 422 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 423 | if (log) |
| 424 | log->Printf("SBTarget(%p)::Attach (sb_attach_info, error)...", |
| 425 | static_cast<void *>(target_sp.get())); |
Greg Clayton | acdbe81 | 2012-01-30 09:04:36 +0000 | [diff] [blame] | 426 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 427 | if (target_sp) { |
| 428 | ProcessAttachInfo &attach_info = sb_attach_info.ref(); |
| 429 | if (attach_info.ProcessIDIsValid() && !attach_info.UserIDIsValid()) { |
| 430 | PlatformSP platform_sp = target_sp->GetPlatform(); |
| 431 | // See if we can pre-verify if a process exists or not |
| 432 | if (platform_sp && platform_sp->IsConnected()) { |
| 433 | lldb::pid_t attach_pid = attach_info.GetProcessID(); |
| 434 | ProcessInstanceInfo instance_info; |
| 435 | if (platform_sp->GetProcessInfo(attach_pid, instance_info)) { |
| 436 | attach_info.SetUserID(instance_info.GetEffectiveUserID()); |
| 437 | } else { |
| 438 | error.ref().SetErrorStringWithFormat( |
| 439 | "no process found with process ID %" PRIu64, attach_pid); |
| 440 | if (log) { |
| 441 | log->Printf("SBTarget(%p)::Attach (...) => error %s", |
| 442 | static_cast<void *>(target_sp.get()), |
| 443 | error.GetCString()); |
| 444 | } |
| 445 | return sb_process; |
Greg Clayton | 931180e | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 446 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 447 | } |
Greg Clayton | 524e60b | 2010-10-06 22:10:17 +0000 | [diff] [blame] | 448 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 449 | error.SetError(AttachToProcess(attach_info, *target_sp)); |
| 450 | if (error.Success()) |
| 451 | sb_process.SetSP(target_sp->GetProcessSP()); |
| 452 | } else { |
| 453 | error.SetErrorString("SBTarget is invalid"); |
| 454 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 455 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 456 | if (log) |
| 457 | log->Printf("SBTarget(%p)::Attach (...) => SBProcess(%p)", |
| 458 | static_cast<void *>(target_sp.get()), |
| 459 | static_cast<void *>(sb_process.GetSP().get())); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 460 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 461 | return sb_process; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 462 | } |
| 463 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 464 | lldb::SBProcess SBTarget::AttachToProcessWithID( |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 465 | SBListener &listener, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 466 | lldb::pid_t pid, // The process ID to attach to |
| 467 | SBError &error // An error explaining what went wrong if attach fails |
| 468 | ) { |
| 469 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Sean Callanan | 575a454 | 2012-10-20 00:21:31 +0000 | [diff] [blame] | 470 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 471 | SBProcess sb_process; |
| 472 | TargetSP target_sp(GetSP()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 473 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 474 | if (log) |
| 475 | log->Printf("SBTarget(%p)::%s (listener, pid=%" PRId64 ", error)...", |
| 476 | static_cast<void *>(target_sp.get()), __FUNCTION__, pid); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 477 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 478 | if (target_sp) { |
| 479 | ProcessAttachInfo attach_info; |
| 480 | attach_info.SetProcessID(pid); |
| 481 | if (listener.IsValid()) |
| 482 | attach_info.SetListener(listener.GetSP()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 483 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 484 | ProcessInstanceInfo instance_info; |
| 485 | if (target_sp->GetPlatform()->GetProcessInfo(pid, instance_info)) |
| 486 | attach_info.SetUserID(instance_info.GetEffectiveUserID()); |
| 487 | |
| 488 | error.SetError(AttachToProcess(attach_info, *target_sp)); |
| 489 | if (error.Success()) |
| 490 | sb_process.SetSP(target_sp->GetProcessSP()); |
| 491 | } else |
| 492 | error.SetErrorString("SBTarget is invalid"); |
| 493 | |
| 494 | if (log) |
| 495 | log->Printf("SBTarget(%p)::%s (...) => SBProcess(%p)", |
| 496 | static_cast<void *>(target_sp.get()), __FUNCTION__, |
| 497 | static_cast<void *>(sb_process.GetSP().get())); |
| 498 | return sb_process; |
| 499 | } |
| 500 | |
| 501 | lldb::SBProcess SBTarget::AttachToProcessWithName( |
| 502 | SBListener &listener, |
| 503 | const char *name, // basename of process to attach to |
| 504 | bool wait_for, // if true wait for a new instance of "name" to be launched |
| 505 | SBError &error // An error explaining what went wrong if attach fails |
| 506 | ) { |
| 507 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 508 | |
| 509 | SBProcess sb_process; |
| 510 | TargetSP target_sp(GetSP()); |
| 511 | |
| 512 | if (log) |
| 513 | log->Printf("SBTarget(%p)::%s (listener, name=%s, wait_for=%s, error)...", |
| 514 | static_cast<void *>(target_sp.get()), __FUNCTION__, name, |
| 515 | wait_for ? "true" : "false"); |
| 516 | |
| 517 | if (name && target_sp) { |
| 518 | ProcessAttachInfo attach_info; |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 519 | attach_info.GetExecutableFile().SetFile(name, FileSpec::Style::native); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 520 | attach_info.SetWaitForLaunch(wait_for); |
| 521 | if (listener.IsValid()) |
| 522 | attach_info.SetListener(listener.GetSP()); |
| 523 | |
| 524 | error.SetError(AttachToProcess(attach_info, *target_sp)); |
| 525 | if (error.Success()) |
| 526 | sb_process.SetSP(target_sp->GetProcessSP()); |
| 527 | } else |
| 528 | error.SetErrorString("SBTarget is invalid"); |
| 529 | |
| 530 | if (log) |
| 531 | log->Printf("SBTarget(%p)::%s (...) => SBProcess(%p)", |
| 532 | static_cast<void *>(target_sp.get()), __FUNCTION__, |
| 533 | static_cast<void *>(sb_process.GetSP().get())); |
| 534 | return sb_process; |
| 535 | } |
| 536 | |
| 537 | lldb::SBProcess SBTarget::ConnectRemote(SBListener &listener, const char *url, |
| 538 | const char *plugin_name, |
| 539 | SBError &error) { |
| 540 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 541 | |
| 542 | SBProcess sb_process; |
| 543 | ProcessSP process_sp; |
| 544 | TargetSP target_sp(GetSP()); |
| 545 | |
| 546 | if (log) |
| 547 | log->Printf("SBTarget(%p)::ConnectRemote (listener, url=%s, " |
| 548 | "plugin_name=%s, error)...", |
| 549 | static_cast<void *>(target_sp.get()), url, plugin_name); |
| 550 | |
| 551 | if (target_sp) { |
| 552 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 553 | if (listener.IsValid()) |
| 554 | process_sp = |
| 555 | target_sp->CreateProcess(listener.m_opaque_sp, plugin_name, NULL); |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 556 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 557 | process_sp = target_sp->CreateProcess( |
| 558 | target_sp->GetDebugger().GetListener(), plugin_name, NULL); |
| 559 | |
| 560 | if (process_sp) { |
| 561 | sb_process.SetSP(process_sp); |
| 562 | error.SetError(process_sp->ConnectRemote(NULL, url)); |
| 563 | } else { |
| 564 | error.SetErrorString("unable to create lldb_private::Process"); |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 565 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 566 | } else { |
| 567 | error.SetErrorString("SBTarget is invalid"); |
| 568 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 569 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 570 | if (log) |
| 571 | log->Printf("SBTarget(%p)::ConnectRemote (...) => SBProcess(%p)", |
| 572 | static_cast<void *>(target_sp.get()), |
| 573 | static_cast<void *>(process_sp.get())); |
| 574 | return sb_process; |
James McIlree | 9631aae | 2011-03-04 00:31:13 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 577 | SBFileSpec SBTarget::GetExecutable() { |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 578 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 579 | SBFileSpec exe_file_spec; |
| 580 | TargetSP target_sp(GetSP()); |
| 581 | if (target_sp) { |
| 582 | Module *exe_module = target_sp->GetExecutableModulePointer(); |
| 583 | if (exe_module) |
| 584 | exe_file_spec.SetFileSpec(exe_module->GetFileSpec()); |
| 585 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 586 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 587 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 588 | if (log) { |
| 589 | log->Printf("SBTarget(%p)::GetExecutable () => SBFileSpec(%p)", |
| 590 | static_cast<void *>(target_sp.get()), |
| 591 | static_cast<const void *>(exe_file_spec.get())); |
| 592 | } |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 593 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 594 | return exe_file_spec; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 595 | } |
| 596 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 597 | bool SBTarget::operator==(const SBTarget &rhs) const { |
| 598 | return m_opaque_sp.get() == rhs.m_opaque_sp.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 601 | bool SBTarget::operator!=(const SBTarget &rhs) const { |
| 602 | return m_opaque_sp.get() != rhs.m_opaque_sp.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 603 | } |
| 604 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 605 | lldb::TargetSP SBTarget::GetSP() const { return m_opaque_sp; } |
| 606 | |
| 607 | void SBTarget::SetSP(const lldb::TargetSP &target_sp) { |
| 608 | m_opaque_sp = target_sp; |
Greg Clayton | 9a37766 | 2011-10-01 02:59:24 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 611 | lldb::SBAddress SBTarget::ResolveLoadAddress(lldb::addr_t vm_addr) { |
| 612 | lldb::SBAddress sb_addr; |
| 613 | Address &addr = sb_addr.ref(); |
| 614 | TargetSP target_sp(GetSP()); |
| 615 | if (target_sp) { |
| 616 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 617 | if (target_sp->ResolveLoadAddress(vm_addr, addr)) |
| 618 | return sb_addr; |
| 619 | } |
| 620 | |
| 621 | // We have a load address that isn't in a section, just return an address |
| 622 | // with the offset filled in (the address) and the section set to NULL |
| 623 | addr.SetRawAddress(vm_addr); |
| 624 | return sb_addr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 625 | } |
| 626 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 627 | lldb::SBAddress SBTarget::ResolveFileAddress(lldb::addr_t file_addr) { |
| 628 | lldb::SBAddress sb_addr; |
| 629 | Address &addr = sb_addr.ref(); |
| 630 | TargetSP target_sp(GetSP()); |
| 631 | if (target_sp) { |
| 632 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 633 | if (target_sp->ResolveFileAddress(file_addr, addr)) |
| 634 | return sb_addr; |
| 635 | } |
Greg Clayton | ac2eb9b | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 636 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 637 | addr.SetRawAddress(file_addr); |
| 638 | return sb_addr; |
Greg Clayton | ac2eb9b | 2010-12-12 19:25:26 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 641 | lldb::SBAddress SBTarget::ResolvePastLoadAddress(uint32_t stop_id, |
| 642 | lldb::addr_t vm_addr) { |
| 643 | lldb::SBAddress sb_addr; |
| 644 | Address &addr = sb_addr.ref(); |
| 645 | TargetSP target_sp(GetSP()); |
| 646 | if (target_sp) { |
| 647 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 648 | if (target_sp->ResolveLoadAddress(vm_addr, addr)) |
| 649 | return sb_addr; |
| 650 | } |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 651 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 652 | // We have a load address that isn't in a section, just return an address |
| 653 | // with the offset filled in (the address) and the section set to NULL |
| 654 | addr.SetRawAddress(vm_addr); |
| 655 | return sb_addr; |
Greg Clayton | d5944cd | 2013-12-06 01:12:00 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Greg Clayton | 5f2a4f9 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 658 | SBSymbolContext |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 659 | SBTarget::ResolveSymbolContextForAddress(const SBAddress &addr, |
| 660 | uint32_t resolve_scope) { |
| 661 | SBSymbolContext sc; |
Zachary Turner | 991e445 | 2018-10-25 20:45:19 +0000 | [diff] [blame] | 662 | SymbolContextItem scope = static_cast<SymbolContextItem>(resolve_scope); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 663 | if (addr.IsValid()) { |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 664 | TargetSP target_sp(GetSP()); |
| 665 | if (target_sp) |
Zachary Turner | 991e445 | 2018-10-25 20:45:19 +0000 | [diff] [blame] | 666 | target_sp->GetImages().ResolveSymbolContextForAddress(addr.ref(), scope, |
| 667 | sc.ref()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 668 | } |
| 669 | return sc; |
| 670 | } |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 671 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 672 | size_t SBTarget::ReadMemory(const SBAddress addr, void *buf, size_t size, |
| 673 | lldb::SBError &error) { |
| 674 | SBError sb_error; |
| 675 | size_t bytes_read = 0; |
| 676 | TargetSP target_sp(GetSP()); |
| 677 | if (target_sp) { |
| 678 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 679 | bytes_read = |
| 680 | target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref()); |
| 681 | } else { |
| 682 | sb_error.SetErrorString("invalid target"); |
| 683 | } |
| 684 | |
| 685 | return bytes_read; |
| 686 | } |
| 687 | |
| 688 | SBBreakpoint SBTarget::BreakpointCreateByLocation(const char *file, |
| 689 | uint32_t line) { |
| 690 | return SBBreakpoint( |
| 691 | BreakpointCreateByLocation(SBFileSpec(file, false), line)); |
Matthew Gardiner | c928de3 | 2014-10-22 07:22:56 +0000 | [diff] [blame] | 692 | } |
Greg Clayton | 5f2a4f9 | 2011-03-02 21:34:46 +0000 | [diff] [blame] | 693 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 694 | SBBreakpoint |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 695 | SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec, |
| 696 | uint32_t line) { |
| 697 | return BreakpointCreateByLocation(sb_file_spec, line, 0); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | SBBreakpoint |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 701 | SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec, |
| 702 | uint32_t line, lldb::addr_t offset) { |
Jim Ingham | 92d1960 | 2016-09-20 22:54:49 +0000 | [diff] [blame] | 703 | SBFileSpecList empty_list; |
| 704 | return BreakpointCreateByLocation(sb_file_spec, line, offset, empty_list); |
| 705 | } |
| 706 | |
| 707 | SBBreakpoint |
| 708 | SBTarget::BreakpointCreateByLocation(const SBFileSpec &sb_file_spec, |
| 709 | uint32_t line, lldb::addr_t offset, |
| 710 | SBFileSpecList &sb_module_list) { |
Adrian Prantl | 431b158 | 2018-08-30 15:11:00 +0000 | [diff] [blame] | 711 | return BreakpointCreateByLocation(sb_file_spec, line, 0, offset, |
| 712 | sb_module_list); |
| 713 | } |
| 714 | |
| 715 | SBBreakpoint SBTarget::BreakpointCreateByLocation( |
| 716 | const SBFileSpec &sb_file_spec, uint32_t line, uint32_t column, |
| 717 | lldb::addr_t offset, SBFileSpecList &sb_module_list) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 718 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Jim Ingham | 2411167 | 2016-03-09 18:59:13 +0000 | [diff] [blame] | 719 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 720 | SBBreakpoint sb_bp; |
| 721 | TargetSP target_sp(GetSP()); |
| 722 | if (target_sp && line != 0) { |
| 723 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 724 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 725 | const LazyBool check_inlines = eLazyBoolCalculate; |
| 726 | const LazyBool skip_prologue = eLazyBoolCalculate; |
| 727 | const bool internal = false; |
| 728 | const bool hardware = false; |
| 729 | const LazyBool move_to_nearest_code = eLazyBoolCalculate; |
Jim Ingham | 92d1960 | 2016-09-20 22:54:49 +0000 | [diff] [blame] | 730 | const FileSpecList *module_list = nullptr; |
| 731 | if (sb_module_list.GetSize() > 0) { |
| 732 | module_list = sb_module_list.get(); |
| 733 | } |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 734 | sb_bp = target_sp->CreateBreakpoint( |
Adrian Prantl | 431b158 | 2018-08-30 15:11:00 +0000 | [diff] [blame] | 735 | module_list, *sb_file_spec, line, column, offset, check_inlines, |
| 736 | skip_prologue, internal, hardware, move_to_nearest_code); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 737 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 738 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 739 | if (log) { |
| 740 | SBStream sstr; |
| 741 | sb_bp.GetDescription(sstr); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 742 | char path[PATH_MAX]; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 743 | sb_file_spec->GetPath(path, sizeof(path)); |
| 744 | log->Printf("SBTarget(%p)::BreakpointCreateByLocation ( %s:%u ) => " |
| 745 | "SBBreakpoint(%p): %s", |
| 746 | static_cast<void *>(target_sp.get()), path, line, |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 747 | static_cast<void *>(sb_bp.GetSP().get()), sstr.GetData()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 748 | } |
Greg Clayton | d5944cd | 2013-12-06 01:12:00 +0000 | [diff] [blame] | 749 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 750 | return sb_bp; |
| 751 | } |
| 752 | |
| 753 | SBBreakpoint SBTarget::BreakpointCreateByName(const char *symbol_name, |
| 754 | const char *module_name) { |
| 755 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 756 | |
| 757 | SBBreakpoint sb_bp; |
| 758 | TargetSP target_sp(GetSP()); |
| 759 | if (target_sp.get()) { |
| 760 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 761 | |
| 762 | const bool internal = false; |
| 763 | const bool hardware = false; |
| 764 | const LazyBool skip_prologue = eLazyBoolCalculate; |
| 765 | const lldb::addr_t offset = 0; |
| 766 | if (module_name && module_name[0]) { |
| 767 | FileSpecList module_spec_list; |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 768 | module_spec_list.Append(FileSpec(module_name)); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 769 | sb_bp = target_sp->CreateBreakpoint( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 770 | &module_spec_list, NULL, symbol_name, eFunctionNameTypeAuto, |
| 771 | eLanguageTypeUnknown, offset, skip_prologue, internal, hardware); |
| 772 | } else { |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 773 | sb_bp = target_sp->CreateBreakpoint( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 774 | NULL, NULL, symbol_name, eFunctionNameTypeAuto, eLanguageTypeUnknown, |
| 775 | offset, skip_prologue, internal, hardware); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 776 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | if (log) |
| 780 | log->Printf("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", " |
| 781 | "module=\"%s\") => SBBreakpoint(%p)", |
| 782 | static_cast<void *>(target_sp.get()), symbol_name, module_name, |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 783 | static_cast<void *>(sb_bp.GetSP().get())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 784 | |
| 785 | return sb_bp; |
| 786 | } |
| 787 | |
| 788 | lldb::SBBreakpoint |
| 789 | SBTarget::BreakpointCreateByName(const char *symbol_name, |
| 790 | const SBFileSpecList &module_list, |
| 791 | const SBFileSpecList &comp_unit_list) { |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 792 | lldb::FunctionNameType name_type_mask = eFunctionNameTypeAuto; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 793 | return BreakpointCreateByName(symbol_name, name_type_mask, |
| 794 | eLanguageTypeUnknown, module_list, |
| 795 | comp_unit_list); |
| 796 | } |
| 797 | |
| 798 | lldb::SBBreakpoint SBTarget::BreakpointCreateByName( |
| 799 | const char *symbol_name, uint32_t name_type_mask, |
| 800 | const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) { |
| 801 | return BreakpointCreateByName(symbol_name, name_type_mask, |
| 802 | eLanguageTypeUnknown, module_list, |
| 803 | comp_unit_list); |
| 804 | } |
| 805 | |
| 806 | lldb::SBBreakpoint SBTarget::BreakpointCreateByName( |
| 807 | const char *symbol_name, uint32_t name_type_mask, |
| 808 | LanguageType symbol_language, const SBFileSpecList &module_list, |
| 809 | const SBFileSpecList &comp_unit_list) { |
| 810 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 811 | |
| 812 | SBBreakpoint sb_bp; |
| 813 | TargetSP target_sp(GetSP()); |
| 814 | if (target_sp && symbol_name && symbol_name[0]) { |
| 815 | const bool internal = false; |
| 816 | const bool hardware = false; |
| 817 | const LazyBool skip_prologue = eLazyBoolCalculate; |
| 818 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 819 | FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask); |
| 820 | sb_bp = target_sp->CreateBreakpoint(module_list.get(), comp_unit_list.get(), |
| 821 | symbol_name, mask, symbol_language, 0, |
| 822 | skip_prologue, internal, hardware); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | if (log) |
| 826 | log->Printf("SBTarget(%p)::BreakpointCreateByName (symbol=\"%s\", " |
| 827 | "name_type: %d) => SBBreakpoint(%p)", |
| 828 | static_cast<void *>(target_sp.get()), symbol_name, |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 829 | name_type_mask, static_cast<void *>(sb_bp.GetSP().get())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 830 | |
| 831 | return sb_bp; |
| 832 | } |
| 833 | |
| 834 | lldb::SBBreakpoint SBTarget::BreakpointCreateByNames( |
| 835 | const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask, |
| 836 | const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) { |
| 837 | return BreakpointCreateByNames(symbol_names, num_names, name_type_mask, |
| 838 | eLanguageTypeUnknown, module_list, |
| 839 | comp_unit_list); |
| 840 | } |
| 841 | |
| 842 | lldb::SBBreakpoint SBTarget::BreakpointCreateByNames( |
| 843 | const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask, |
| 844 | LanguageType symbol_language, const SBFileSpecList &module_list, |
| 845 | const SBFileSpecList &comp_unit_list) { |
| 846 | return BreakpointCreateByNames(symbol_names, num_names, name_type_mask, |
| 847 | eLanguageTypeUnknown, 0, module_list, |
| 848 | comp_unit_list); |
| 849 | } |
| 850 | |
| 851 | lldb::SBBreakpoint SBTarget::BreakpointCreateByNames( |
| 852 | const char *symbol_names[], uint32_t num_names, uint32_t name_type_mask, |
| 853 | LanguageType symbol_language, lldb::addr_t offset, |
| 854 | const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) { |
| 855 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 856 | |
| 857 | SBBreakpoint sb_bp; |
| 858 | TargetSP target_sp(GetSP()); |
| 859 | if (target_sp && num_names > 0) { |
| 860 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 861 | const bool internal = false; |
| 862 | const bool hardware = false; |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 863 | FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 864 | const LazyBool skip_prologue = eLazyBoolCalculate; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 865 | sb_bp = target_sp->CreateBreakpoint( |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 866 | module_list.get(), comp_unit_list.get(), symbol_names, num_names, mask, |
| 867 | symbol_language, offset, skip_prologue, internal, hardware); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | if (log) { |
| 871 | log->Printf("SBTarget(%p)::BreakpointCreateByName (symbols={", |
| 872 | static_cast<void *>(target_sp.get())); |
| 873 | for (uint32_t i = 0; i < num_names; i++) { |
| 874 | char sep; |
| 875 | if (i < num_names - 1) |
| 876 | sep = ','; |
| 877 | else |
| 878 | sep = '}'; |
| 879 | if (symbol_names[i] != NULL) |
| 880 | log->Printf("\"%s\"%c ", symbol_names[i], sep); |
| 881 | else |
| 882 | log->Printf("\"<NULL>\"%c ", sep); |
| 883 | } |
| 884 | log->Printf("name_type: %d) => SBBreakpoint(%p)", name_type_mask, |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 885 | static_cast<void *>(sb_bp.GetSP().get())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | return sb_bp; |
| 889 | } |
| 890 | |
| 891 | SBBreakpoint SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex, |
| 892 | const char *module_name) { |
| 893 | SBFileSpecList module_spec_list; |
| 894 | SBFileSpecList comp_unit_list; |
| 895 | if (module_name && module_name[0]) { |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 896 | module_spec_list.Append(FileSpec(module_name)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 897 | } |
| 898 | return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown, |
| 899 | module_spec_list, comp_unit_list); |
| 900 | } |
| 901 | |
| 902 | lldb::SBBreakpoint |
| 903 | SBTarget::BreakpointCreateByRegex(const char *symbol_name_regex, |
| 904 | const SBFileSpecList &module_list, |
| 905 | const SBFileSpecList &comp_unit_list) { |
| 906 | return BreakpointCreateByRegex(symbol_name_regex, eLanguageTypeUnknown, |
| 907 | module_list, comp_unit_list); |
| 908 | } |
| 909 | |
| 910 | lldb::SBBreakpoint SBTarget::BreakpointCreateByRegex( |
| 911 | const char *symbol_name_regex, LanguageType symbol_language, |
| 912 | const SBFileSpecList &module_list, const SBFileSpecList &comp_unit_list) { |
| 913 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 914 | |
| 915 | SBBreakpoint sb_bp; |
| 916 | TargetSP target_sp(GetSP()); |
| 917 | if (target_sp && symbol_name_regex && symbol_name_regex[0]) { |
| 918 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 919 | RegularExpression regexp((llvm::StringRef(symbol_name_regex))); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 920 | const bool internal = false; |
| 921 | const bool hardware = false; |
| 922 | const LazyBool skip_prologue = eLazyBoolCalculate; |
| 923 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 924 | sb_bp = target_sp->CreateFuncRegexBreakpoint( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 925 | module_list.get(), comp_unit_list.get(), regexp, symbol_language, |
| 926 | skip_prologue, internal, hardware); |
| 927 | } |
| 928 | |
| 929 | if (log) |
| 930 | log->Printf("SBTarget(%p)::BreakpointCreateByRegex (symbol_regex=\"%s\") " |
| 931 | "=> SBBreakpoint(%p)", |
| 932 | static_cast<void *>(target_sp.get()), symbol_name_regex, |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 933 | static_cast<void *>(sb_bp.GetSP().get())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 934 | |
| 935 | return sb_bp; |
| 936 | } |
| 937 | |
| 938 | SBBreakpoint SBTarget::BreakpointCreateByAddress(addr_t address) { |
| 939 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 940 | |
| 941 | SBBreakpoint sb_bp; |
| 942 | TargetSP target_sp(GetSP()); |
| 943 | if (target_sp) { |
| 944 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 945 | const bool hardware = false; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 946 | sb_bp = target_sp->CreateBreakpoint(address, false, hardware); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | if (log) |
| 950 | log->Printf("SBTarget(%p)::BreakpointCreateByAddress (address=%" PRIu64 |
| 951 | ") => SBBreakpoint(%p)", |
| 952 | static_cast<void *>(target_sp.get()), |
| 953 | static_cast<uint64_t>(address), |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 954 | static_cast<void *>(sb_bp.GetSP().get())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 955 | |
| 956 | return sb_bp; |
| 957 | } |
| 958 | |
| 959 | SBBreakpoint SBTarget::BreakpointCreateBySBAddress(SBAddress &sb_address) { |
| 960 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 961 | |
| 962 | SBBreakpoint sb_bp; |
| 963 | TargetSP target_sp(GetSP()); |
| 964 | if (!sb_address.IsValid()) { |
| 965 | if (log) |
| 966 | log->Printf("SBTarget(%p)::BreakpointCreateBySBAddress called with " |
| 967 | "invalid address", |
| 968 | static_cast<void *>(target_sp.get())); |
| 969 | return sb_bp; |
| 970 | } |
| 971 | |
| 972 | if (target_sp) { |
| 973 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 974 | const bool hardware = false; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 975 | sb_bp = target_sp->CreateBreakpoint(sb_address.ref(), false, hardware); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | if (log) { |
| 979 | SBStream s; |
| 980 | sb_address.GetDescription(s); |
| 981 | log->Printf("SBTarget(%p)::BreakpointCreateBySBAddress (address=%s) => " |
| 982 | "SBBreakpoint(%p)", |
| 983 | static_cast<void *>(target_sp.get()), s.GetData(), |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 984 | static_cast<void *>(sb_bp.GetSP().get())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | return sb_bp; |
| 988 | } |
| 989 | |
| 990 | lldb::SBBreakpoint |
| 991 | SBTarget::BreakpointCreateBySourceRegex(const char *source_regex, |
| 992 | const lldb::SBFileSpec &source_file, |
| 993 | const char *module_name) { |
| 994 | SBFileSpecList module_spec_list; |
| 995 | |
| 996 | if (module_name && module_name[0]) { |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 997 | module_spec_list.Append(FileSpec(module_name)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | SBFileSpecList source_file_list; |
| 1001 | if (source_file.IsValid()) { |
| 1002 | source_file_list.Append(source_file); |
| 1003 | } |
| 1004 | |
| 1005 | return BreakpointCreateBySourceRegex(source_regex, module_spec_list, |
| 1006 | source_file_list); |
| 1007 | } |
| 1008 | |
| 1009 | lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex( |
| 1010 | const char *source_regex, const SBFileSpecList &module_list, |
| 1011 | const lldb::SBFileSpecList &source_file_list) { |
| 1012 | return BreakpointCreateBySourceRegex(source_regex, module_list, |
| 1013 | source_file_list, SBStringList()); |
| 1014 | } |
| 1015 | |
| 1016 | lldb::SBBreakpoint SBTarget::BreakpointCreateBySourceRegex( |
| 1017 | const char *source_regex, const SBFileSpecList &module_list, |
| 1018 | const lldb::SBFileSpecList &source_file_list, |
| 1019 | const SBStringList &func_names) { |
| 1020 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1021 | |
| 1022 | SBBreakpoint sb_bp; |
| 1023 | TargetSP target_sp(GetSP()); |
| 1024 | if (target_sp && source_regex && source_regex[0]) { |
| 1025 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1026 | const bool hardware = false; |
| 1027 | const LazyBool move_to_nearest_code = eLazyBoolCalculate; |
Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 1028 | RegularExpression regexp((llvm::StringRef(source_regex))); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1029 | std::unordered_set<std::string> func_names_set; |
| 1030 | for (size_t i = 0; i < func_names.GetSize(); i++) { |
| 1031 | func_names_set.insert(func_names.GetStringAtIndex(i)); |
| 1032 | } |
| 1033 | |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 1034 | sb_bp = target_sp->CreateSourceRegexBreakpoint( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1035 | module_list.get(), source_file_list.get(), func_names_set, regexp, |
| 1036 | false, hardware, move_to_nearest_code); |
| 1037 | } |
| 1038 | |
| 1039 | if (log) |
| 1040 | log->Printf("SBTarget(%p)::BreakpointCreateByRegex (source_regex=\"%s\") " |
| 1041 | "=> SBBreakpoint(%p)", |
| 1042 | static_cast<void *>(target_sp.get()), source_regex, |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 1043 | static_cast<void *>(sb_bp.GetSP().get())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1044 | |
| 1045 | return sb_bp; |
| 1046 | } |
| 1047 | |
| 1048 | lldb::SBBreakpoint |
| 1049 | SBTarget::BreakpointCreateForException(lldb::LanguageType language, |
| 1050 | bool catch_bp, bool throw_bp) { |
| 1051 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1052 | |
| 1053 | SBBreakpoint sb_bp; |
| 1054 | TargetSP target_sp(GetSP()); |
| 1055 | if (target_sp) { |
| 1056 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1057 | const bool hardware = false; |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 1058 | sb_bp = target_sp->CreateExceptionBreakpoint(language, catch_bp, throw_bp, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1059 | hardware); |
| 1060 | } |
| 1061 | |
| 1062 | if (log) |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 1063 | log->Printf("SBTarget(%p)::BreakpointCreateForException (Language: %s, catch: " |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1064 | "%s throw: %s) => SBBreakpoint(%p)", |
| 1065 | static_cast<void *>(target_sp.get()), |
| 1066 | Language::GetNameForLanguageType(language), |
| 1067 | catch_bp ? "on" : "off", throw_bp ? "on" : "off", |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 1068 | static_cast<void *>(sb_bp.GetSP().get())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1069 | |
| 1070 | return sb_bp; |
| 1071 | } |
| 1072 | |
Jim Ingham | 3815e70 | 2018-09-13 21:35:32 +0000 | [diff] [blame] | 1073 | lldb::SBBreakpoint |
| 1074 | SBTarget::BreakpointCreateFromScript(const char *class_name, |
| 1075 | SBStructuredData &extra_args, |
| 1076 | const SBFileSpecList &module_list, |
| 1077 | const SBFileSpecList &file_list, |
| 1078 | bool request_hardware) |
| 1079 | { |
| 1080 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1081 | |
| 1082 | SBBreakpoint sb_bp; |
| 1083 | TargetSP target_sp(GetSP()); |
| 1084 | if (target_sp) { |
| 1085 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1086 | Status error; |
| 1087 | |
| 1088 | StructuredData::ObjectSP obj_sp = extra_args.m_impl_up->GetObjectSP(); |
| 1089 | sb_bp = |
| 1090 | target_sp->CreateScriptedBreakpoint(class_name, |
| 1091 | module_list.get(), |
| 1092 | file_list.get(), |
| 1093 | false, /* internal */ |
| 1094 | request_hardware, |
| 1095 | obj_sp, |
| 1096 | &error); |
| 1097 | } |
| 1098 | if (log) |
| 1099 | log->Printf("SBTarget(%p)::BreakpointCreateFromScript (class name: %s) " |
| 1100 | " => SBBreakpoint(%p)", |
| 1101 | static_cast<void *>(target_sp.get()), |
| 1102 | class_name, |
| 1103 | static_cast<void *>(sb_bp.GetSP().get())); |
| 1104 | |
| 1105 | return sb_bp; |
| 1106 | } |
| 1107 | |
| 1108 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1109 | uint32_t SBTarget::GetNumBreakpoints() const { |
| 1110 | TargetSP target_sp(GetSP()); |
| 1111 | if (target_sp) { |
| 1112 | // The breakpoint list is thread safe, no need to lock |
| 1113 | return target_sp->GetBreakpointList().GetSize(); |
| 1114 | } |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | SBBreakpoint SBTarget::GetBreakpointAtIndex(uint32_t idx) const { |
| 1119 | SBBreakpoint sb_breakpoint; |
| 1120 | TargetSP target_sp(GetSP()); |
| 1121 | if (target_sp) { |
| 1122 | // The breakpoint list is thread safe, no need to lock |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 1123 | sb_breakpoint = target_sp->GetBreakpointList().GetBreakpointAtIndex(idx); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1124 | } |
| 1125 | return sb_breakpoint; |
| 1126 | } |
| 1127 | |
| 1128 | bool SBTarget::BreakpointDelete(break_id_t bp_id) { |
| 1129 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1130 | |
| 1131 | bool result = false; |
| 1132 | TargetSP target_sp(GetSP()); |
| 1133 | if (target_sp) { |
| 1134 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1135 | result = target_sp->RemoveBreakpointByID(bp_id); |
| 1136 | } |
| 1137 | |
| 1138 | if (log) |
| 1139 | log->Printf("SBTarget(%p)::BreakpointDelete (bp_id=%d) => %i", |
| 1140 | static_cast<void *>(target_sp.get()), |
| 1141 | static_cast<uint32_t>(bp_id), result); |
| 1142 | |
| 1143 | return result; |
| 1144 | } |
| 1145 | |
| 1146 | SBBreakpoint SBTarget::FindBreakpointByID(break_id_t bp_id) { |
| 1147 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1148 | |
| 1149 | SBBreakpoint sb_breakpoint; |
| 1150 | TargetSP target_sp(GetSP()); |
| 1151 | if (target_sp && bp_id != LLDB_INVALID_BREAK_ID) { |
| 1152 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 1153 | sb_breakpoint = target_sp->GetBreakpointByID(bp_id); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | if (log) |
| 1157 | log->Printf( |
| 1158 | "SBTarget(%p)::FindBreakpointByID (bp_id=%d) => SBBreakpoint(%p)", |
| 1159 | static_cast<void *>(target_sp.get()), static_cast<uint32_t>(bp_id), |
Pavel Labath | 6ac8403 | 2017-02-27 11:05:34 +0000 | [diff] [blame] | 1160 | static_cast<void *>(sb_breakpoint.GetSP().get())); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1161 | |
| 1162 | return sb_breakpoint; |
| 1163 | } |
| 1164 | |
Jim Ingham | ff9a91e | 2016-09-21 01:21:19 +0000 | [diff] [blame] | 1165 | bool SBTarget::FindBreakpointsByName(const char *name, |
| 1166 | SBBreakpointList &bkpts) { |
| 1167 | TargetSP target_sp(GetSP()); |
| 1168 | if (target_sp) { |
| 1169 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1170 | BreakpointList bkpt_list(false); |
| 1171 | bool is_valid = |
| 1172 | target_sp->GetBreakpointList().FindBreakpointsByName(name, bkpt_list); |
| 1173 | if (!is_valid) |
| 1174 | return false; |
| 1175 | for (BreakpointSP bkpt_sp : bkpt_list.Breakpoints()) { |
| 1176 | bkpts.AppendByID(bkpt_sp->GetID()); |
| 1177 | } |
| 1178 | } |
| 1179 | return true; |
| 1180 | } |
| 1181 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1182 | void SBTarget::GetBreakpointNames(SBStringList &names) |
| 1183 | { |
| 1184 | names.Clear(); |
| 1185 | |
| 1186 | TargetSP target_sp(GetSP()); |
| 1187 | if (target_sp) { |
| 1188 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1189 | |
| 1190 | std::vector<std::string> name_vec; |
| 1191 | target_sp->GetBreakpointNames(name_vec); |
| 1192 | for (auto name : name_vec) |
| 1193 | names.AppendString(name.c_str()); |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | void SBTarget::DeleteBreakpointName(const char *name) |
| 1198 | { |
| 1199 | TargetSP target_sp(GetSP()); |
| 1200 | if (target_sp) { |
| 1201 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1202 | target_sp->DeleteBreakpointName(ConstString(name)); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1203 | } |
| 1204 | } |
| 1205 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1206 | bool SBTarget::EnableAllBreakpoints() { |
| 1207 | TargetSP target_sp(GetSP()); |
| 1208 | if (target_sp) { |
| 1209 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1210 | target_sp->EnableAllowedBreakpoints(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1211 | return true; |
| 1212 | } |
| 1213 | return false; |
| 1214 | } |
| 1215 | |
| 1216 | bool SBTarget::DisableAllBreakpoints() { |
| 1217 | TargetSP target_sp(GetSP()); |
| 1218 | if (target_sp) { |
| 1219 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1220 | target_sp->DisableAllowedBreakpoints(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1221 | return true; |
| 1222 | } |
| 1223 | return false; |
| 1224 | } |
| 1225 | |
| 1226 | bool SBTarget::DeleteAllBreakpoints() { |
| 1227 | TargetSP target_sp(GetSP()); |
| 1228 | if (target_sp) { |
| 1229 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 1230 | target_sp->RemoveAllowedBreakpoints(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1231 | return true; |
| 1232 | } |
| 1233 | return false; |
| 1234 | } |
| 1235 | |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1236 | lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file, |
| 1237 | SBBreakpointList &new_bps) { |
Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 1238 | SBStringList empty_name_list; |
| 1239 | return BreakpointsCreateFromFile(source_file, empty_name_list, new_bps); |
| 1240 | } |
| 1241 | |
| 1242 | lldb::SBError SBTarget::BreakpointsCreateFromFile(SBFileSpec &source_file, |
| 1243 | SBStringList &matching_names, |
| 1244 | SBBreakpointList &new_bps) { |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1245 | SBError sberr; |
| 1246 | TargetSP target_sp(GetSP()); |
| 1247 | if (!target_sp) { |
| 1248 | sberr.SetErrorString( |
| 1249 | "BreakpointCreateFromFile called with invalid target."); |
| 1250 | return sberr; |
| 1251 | } |
| 1252 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1253 | |
| 1254 | BreakpointIDList bp_ids; |
Jim Ingham | 3acdf38 | 2016-09-22 22:20:28 +0000 | [diff] [blame] | 1255 | |
| 1256 | std::vector<std::string> name_vector; |
| 1257 | size_t num_names = matching_names.GetSize(); |
| 1258 | for (size_t i = 0; i < num_names; i++) |
| 1259 | name_vector.push_back(matching_names.GetStringAtIndex(i)); |
| 1260 | |
| 1261 | sberr.ref() = target_sp->CreateBreakpointsFromFile(source_file.ref(), |
| 1262 | name_vector, bp_ids); |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1263 | if (sberr.Fail()) |
| 1264 | return sberr; |
| 1265 | |
| 1266 | size_t num_bkpts = bp_ids.GetSize(); |
| 1267 | for (size_t i = 0; i < num_bkpts; i++) { |
| 1268 | BreakpointID bp_id = bp_ids.GetBreakpointIDAtIndex(i); |
| 1269 | new_bps.AppendByID(bp_id.GetBreakpointID()); |
| 1270 | } |
| 1271 | return sberr; |
| 1272 | } |
| 1273 | |
| 1274 | lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file) { |
| 1275 | SBError sberr; |
| 1276 | TargetSP target_sp(GetSP()); |
| 1277 | if (!target_sp) { |
| 1278 | sberr.SetErrorString("BreakpointWriteToFile called with invalid target."); |
| 1279 | return sberr; |
| 1280 | } |
| 1281 | SBBreakpointList bkpt_list(*this); |
| 1282 | return BreakpointsWriteToFile(dest_file, bkpt_list); |
| 1283 | } |
| 1284 | |
| 1285 | lldb::SBError SBTarget::BreakpointsWriteToFile(SBFileSpec &dest_file, |
Jim Ingham | 2d3628e | 2016-09-22 23:42:42 +0000 | [diff] [blame] | 1286 | SBBreakpointList &bkpt_list, |
| 1287 | bool append) { |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1288 | SBError sberr; |
| 1289 | TargetSP target_sp(GetSP()); |
| 1290 | if (!target_sp) { |
| 1291 | sberr.SetErrorString("BreakpointWriteToFile called with invalid target."); |
| 1292 | return sberr; |
| 1293 | } |
| 1294 | |
| 1295 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1296 | BreakpointIDList bp_id_list; |
| 1297 | bkpt_list.CopyToBreakpointIDList(bp_id_list); |
Jim Ingham | 2d3628e | 2016-09-22 23:42:42 +0000 | [diff] [blame] | 1298 | sberr.ref() = target_sp->SerializeBreakpointsToFile(dest_file.ref(), |
| 1299 | bp_id_list, append); |
Jim Ingham | 01f1666 | 2016-09-14 19:07:35 +0000 | [diff] [blame] | 1300 | return sberr; |
| 1301 | } |
| 1302 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1303 | uint32_t SBTarget::GetNumWatchpoints() const { |
| 1304 | TargetSP target_sp(GetSP()); |
| 1305 | if (target_sp) { |
| 1306 | // The watchpoint list is thread safe, no need to lock |
| 1307 | return target_sp->GetWatchpointList().GetSize(); |
| 1308 | } |
| 1309 | return 0; |
| 1310 | } |
| 1311 | |
| 1312 | SBWatchpoint SBTarget::GetWatchpointAtIndex(uint32_t idx) const { |
| 1313 | SBWatchpoint sb_watchpoint; |
| 1314 | TargetSP target_sp(GetSP()); |
| 1315 | if (target_sp) { |
| 1316 | // The watchpoint list is thread safe, no need to lock |
| 1317 | sb_watchpoint.SetSP(target_sp->GetWatchpointList().GetByIndex(idx)); |
| 1318 | } |
| 1319 | return sb_watchpoint; |
| 1320 | } |
| 1321 | |
| 1322 | bool SBTarget::DeleteWatchpoint(watch_id_t wp_id) { |
| 1323 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1324 | |
| 1325 | bool result = false; |
| 1326 | TargetSP target_sp(GetSP()); |
| 1327 | if (target_sp) { |
| 1328 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1329 | std::unique_lock<std::recursive_mutex> lock; |
| 1330 | target_sp->GetWatchpointList().GetListMutex(lock); |
| 1331 | result = target_sp->RemoveWatchpointByID(wp_id); |
| 1332 | } |
| 1333 | |
| 1334 | if (log) |
| 1335 | log->Printf("SBTarget(%p)::WatchpointDelete (wp_id=%d) => %i", |
| 1336 | static_cast<void *>(target_sp.get()), |
| 1337 | static_cast<uint32_t>(wp_id), result); |
| 1338 | |
| 1339 | return result; |
| 1340 | } |
| 1341 | |
| 1342 | SBWatchpoint SBTarget::FindWatchpointByID(lldb::watch_id_t wp_id) { |
| 1343 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1344 | |
| 1345 | SBWatchpoint sb_watchpoint; |
| 1346 | lldb::WatchpointSP watchpoint_sp; |
| 1347 | TargetSP target_sp(GetSP()); |
| 1348 | if (target_sp && wp_id != LLDB_INVALID_WATCH_ID) { |
| 1349 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1350 | std::unique_lock<std::recursive_mutex> lock; |
| 1351 | target_sp->GetWatchpointList().GetListMutex(lock); |
| 1352 | watchpoint_sp = target_sp->GetWatchpointList().FindByID(wp_id); |
| 1353 | sb_watchpoint.SetSP(watchpoint_sp); |
| 1354 | } |
| 1355 | |
| 1356 | if (log) |
| 1357 | log->Printf( |
| 1358 | "SBTarget(%p)::FindWatchpointByID (bp_id=%d) => SBWatchpoint(%p)", |
| 1359 | static_cast<void *>(target_sp.get()), static_cast<uint32_t>(wp_id), |
| 1360 | static_cast<void *>(watchpoint_sp.get())); |
| 1361 | |
| 1362 | return sb_watchpoint; |
| 1363 | } |
| 1364 | |
| 1365 | lldb::SBWatchpoint SBTarget::WatchAddress(lldb::addr_t addr, size_t size, |
| 1366 | bool read, bool write, |
| 1367 | SBError &error) { |
| 1368 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1369 | |
| 1370 | SBWatchpoint sb_watchpoint; |
| 1371 | lldb::WatchpointSP watchpoint_sp; |
| 1372 | TargetSP target_sp(GetSP()); |
| 1373 | if (target_sp && (read || write) && addr != LLDB_INVALID_ADDRESS && |
| 1374 | size > 0) { |
| 1375 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1376 | uint32_t watch_type = 0; |
| 1377 | if (read) |
| 1378 | watch_type |= LLDB_WATCH_TYPE_READ; |
| 1379 | if (write) |
| 1380 | watch_type |= LLDB_WATCH_TYPE_WRITE; |
| 1381 | if (watch_type == 0) { |
| 1382 | error.SetErrorString( |
| 1383 | "Can't create a watchpoint that is neither read nor write."); |
| 1384 | return sb_watchpoint; |
| 1385 | } |
| 1386 | |
| 1387 | // Target::CreateWatchpoint() is thread safe. |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1388 | Status cw_error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1389 | // This API doesn't take in a type, so we can't figure out what it is. |
| 1390 | CompilerType *type = NULL; |
| 1391 | watchpoint_sp = |
| 1392 | target_sp->CreateWatchpoint(addr, size, type, watch_type, cw_error); |
| 1393 | error.SetError(cw_error); |
| 1394 | sb_watchpoint.SetSP(watchpoint_sp); |
| 1395 | } |
| 1396 | |
| 1397 | if (log) |
| 1398 | log->Printf("SBTarget(%p)::WatchAddress (addr=0x%" PRIx64 |
| 1399 | ", 0x%u) => SBWatchpoint(%p)", |
| 1400 | static_cast<void *>(target_sp.get()), addr, |
| 1401 | static_cast<uint32_t>(size), |
| 1402 | static_cast<void *>(watchpoint_sp.get())); |
| 1403 | |
| 1404 | return sb_watchpoint; |
| 1405 | } |
| 1406 | |
| 1407 | bool SBTarget::EnableAllWatchpoints() { |
| 1408 | TargetSP target_sp(GetSP()); |
| 1409 | if (target_sp) { |
| 1410 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1411 | std::unique_lock<std::recursive_mutex> lock; |
| 1412 | target_sp->GetWatchpointList().GetListMutex(lock); |
| 1413 | target_sp->EnableAllWatchpoints(); |
| 1414 | return true; |
| 1415 | } |
| 1416 | return false; |
| 1417 | } |
| 1418 | |
| 1419 | bool SBTarget::DisableAllWatchpoints() { |
| 1420 | TargetSP target_sp(GetSP()); |
| 1421 | if (target_sp) { |
| 1422 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1423 | std::unique_lock<std::recursive_mutex> lock; |
| 1424 | target_sp->GetWatchpointList().GetListMutex(lock); |
| 1425 | target_sp->DisableAllWatchpoints(); |
| 1426 | return true; |
| 1427 | } |
| 1428 | return false; |
| 1429 | } |
| 1430 | |
| 1431 | SBValue SBTarget::CreateValueFromAddress(const char *name, SBAddress addr, |
| 1432 | SBType type) { |
| 1433 | SBValue sb_value; |
| 1434 | lldb::ValueObjectSP new_value_sp; |
| 1435 | if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) { |
| 1436 | lldb::addr_t load_addr(addr.GetLoadAddress(*this)); |
| 1437 | ExecutionContext exe_ctx( |
| 1438 | ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false))); |
| 1439 | CompilerType ast_type(type.GetSP()->GetCompilerType(true)); |
| 1440 | new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, |
| 1441 | exe_ctx, ast_type); |
| 1442 | } |
| 1443 | sb_value.SetSP(new_value_sp); |
| 1444 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1445 | if (log) { |
| 1446 | if (new_value_sp) |
| 1447 | log->Printf("SBTarget(%p)::CreateValueFromAddress => \"%s\"", |
| 1448 | static_cast<void *>(m_opaque_sp.get()), |
| 1449 | new_value_sp->GetName().AsCString()); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1450 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1451 | log->Printf("SBTarget(%p)::CreateValueFromAddress => NULL", |
| 1452 | static_cast<void *>(m_opaque_sp.get())); |
| 1453 | } |
| 1454 | return sb_value; |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1457 | lldb::SBValue SBTarget::CreateValueFromData(const char *name, lldb::SBData data, |
| 1458 | lldb::SBType type) { |
| 1459 | SBValue sb_value; |
| 1460 | lldb::ValueObjectSP new_value_sp; |
| 1461 | if (IsValid() && name && *name && data.IsValid() && type.IsValid()) { |
| 1462 | DataExtractorSP extractor(*data); |
| 1463 | ExecutionContext exe_ctx( |
| 1464 | ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false))); |
| 1465 | CompilerType ast_type(type.GetSP()->GetCompilerType(true)); |
| 1466 | new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, |
| 1467 | exe_ctx, ast_type); |
| 1468 | } |
| 1469 | sb_value.SetSP(new_value_sp); |
| 1470 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1471 | if (log) { |
| 1472 | if (new_value_sp) |
| 1473 | log->Printf("SBTarget(%p)::CreateValueFromData => \"%s\"", |
| 1474 | static_cast<void *>(m_opaque_sp.get()), |
| 1475 | new_value_sp->GetName().AsCString()); |
| 1476 | else |
| 1477 | log->Printf("SBTarget(%p)::CreateValueFromData => NULL", |
| 1478 | static_cast<void *>(m_opaque_sp.get())); |
| 1479 | } |
| 1480 | return sb_value; |
Greg Clayton | e14e192 | 2012-12-04 02:22:16 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1483 | lldb::SBValue SBTarget::CreateValueFromExpression(const char *name, |
| 1484 | const char *expr) { |
| 1485 | SBValue sb_value; |
| 1486 | lldb::ValueObjectSP new_value_sp; |
| 1487 | if (IsValid() && name && *name && expr && *expr) { |
| 1488 | ExecutionContext exe_ctx( |
| 1489 | ExecutionContextRef(ExecutionContext(m_opaque_sp.get(), false))); |
| 1490 | new_value_sp = |
| 1491 | ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx); |
| 1492 | } |
| 1493 | sb_value.SetSP(new_value_sp); |
| 1494 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1495 | if (log) { |
| 1496 | if (new_value_sp) |
| 1497 | log->Printf("SBTarget(%p)::CreateValueFromExpression => \"%s\"", |
| 1498 | static_cast<void *>(m_opaque_sp.get()), |
| 1499 | new_value_sp->GetName().AsCString()); |
| 1500 | else |
| 1501 | log->Printf("SBTarget(%p)::CreateValueFromExpression => NULL", |
| 1502 | static_cast<void *>(m_opaque_sp.get())); |
| 1503 | } |
| 1504 | return sb_value; |
| 1505 | } |
| 1506 | |
| 1507 | bool SBTarget::DeleteAllWatchpoints() { |
| 1508 | TargetSP target_sp(GetSP()); |
| 1509 | if (target_sp) { |
| 1510 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 1511 | std::unique_lock<std::recursive_mutex> lock; |
| 1512 | target_sp->GetWatchpointList().GetListMutex(lock); |
| 1513 | target_sp->RemoveAllWatchpoints(); |
| 1514 | return true; |
| 1515 | } |
| 1516 | return false; |
| 1517 | } |
| 1518 | |
Alexander Polyakov | 3e7b9db | 2018-08-07 20:23:57 +0000 | [diff] [blame] | 1519 | void SBTarget::AppendImageSearchPath(const char *from, const char *to, |
| 1520 | lldb::SBError &error) { |
| 1521 | TargetSP target_sp(GetSP()); |
| 1522 | if (!target_sp) |
| 1523 | return error.SetErrorString("invalid target"); |
| 1524 | |
| 1525 | const ConstString csFrom(from), csTo(to); |
| 1526 | if (!csFrom) |
| 1527 | return error.SetErrorString("<from> path can't be empty"); |
| 1528 | if (!csTo) |
| 1529 | return error.SetErrorString("<to> path can't be empty"); |
| 1530 | |
| 1531 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1532 | if (log) |
| 1533 | log->Printf("SBTarget(%p)::%s: '%s' -> '%s'", |
| 1534 | static_cast<void *>(target_sp.get()), __FUNCTION__, |
| 1535 | from, to); |
| 1536 | target_sp->GetImageSearchPathList().Append(csFrom, csTo, true); |
| 1537 | } |
| 1538 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1539 | lldb::SBModule SBTarget::AddModule(const char *path, const char *triple, |
| 1540 | const char *uuid_cstr) { |
| 1541 | return AddModule(path, triple, uuid_cstr, NULL); |
| 1542 | } |
| 1543 | |
| 1544 | lldb::SBModule SBTarget::AddModule(const char *path, const char *triple, |
| 1545 | const char *uuid_cstr, const char *symfile) { |
| 1546 | lldb::SBModule sb_module; |
| 1547 | TargetSP target_sp(GetSP()); |
| 1548 | if (target_sp) { |
| 1549 | ModuleSpec module_spec; |
| 1550 | if (path) |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1551 | module_spec.GetFileSpec().SetFile(path, FileSpec::Style::native); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1552 | |
| 1553 | if (uuid_cstr) |
Pavel Labath | a174bcb | 2018-06-21 15:24:39 +0000 | [diff] [blame] | 1554 | module_spec.GetUUID().SetFromStringRef(uuid_cstr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1555 | |
| 1556 | if (triple) |
Pavel Labath | 7263f1b | 2017-10-31 10:56:03 +0000 | [diff] [blame] | 1557 | module_spec.GetArchitecture() = Platform::GetAugmentedArchSpec( |
| 1558 | target_sp->GetPlatform().get(), triple); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1559 | else |
| 1560 | module_spec.GetArchitecture() = target_sp->GetArchitecture(); |
| 1561 | |
| 1562 | if (symfile) |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 1563 | module_spec.GetSymbolFileSpec().SetFile(symfile, FileSpec::Style::native); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1564 | |
| 1565 | sb_module.SetSP(target_sp->GetSharedModule(module_spec)); |
| 1566 | } |
| 1567 | return sb_module; |
| 1568 | } |
| 1569 | |
| 1570 | lldb::SBModule SBTarget::AddModule(const SBModuleSpec &module_spec) { |
| 1571 | lldb::SBModule sb_module; |
| 1572 | TargetSP target_sp(GetSP()); |
| 1573 | if (target_sp) |
| 1574 | sb_module.SetSP(target_sp->GetSharedModule(*module_spec.m_opaque_ap)); |
| 1575 | return sb_module; |
| 1576 | } |
| 1577 | |
| 1578 | bool SBTarget::AddModule(lldb::SBModule &module) { |
| 1579 | TargetSP target_sp(GetSP()); |
| 1580 | if (target_sp) { |
| 1581 | target_sp->GetImages().AppendIfNeeded(module.GetSP()); |
| 1582 | return true; |
| 1583 | } |
| 1584 | return false; |
| 1585 | } |
| 1586 | |
| 1587 | uint32_t SBTarget::GetNumModules() const { |
| 1588 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1589 | |
| 1590 | uint32_t num = 0; |
| 1591 | TargetSP target_sp(GetSP()); |
| 1592 | if (target_sp) { |
| 1593 | // The module list is thread safe, no need to lock |
| 1594 | num = target_sp->GetImages().GetSize(); |
| 1595 | } |
| 1596 | |
| 1597 | if (log) |
| 1598 | log->Printf("SBTarget(%p)::GetNumModules () => %d", |
| 1599 | static_cast<void *>(target_sp.get()), num); |
| 1600 | |
| 1601 | return num; |
| 1602 | } |
| 1603 | |
| 1604 | void SBTarget::Clear() { |
| 1605 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1606 | |
| 1607 | if (log) |
| 1608 | log->Printf("SBTarget(%p)::Clear ()", |
| 1609 | static_cast<void *>(m_opaque_sp.get())); |
| 1610 | |
| 1611 | m_opaque_sp.reset(); |
| 1612 | } |
| 1613 | |
| 1614 | SBModule SBTarget::FindModule(const SBFileSpec &sb_file_spec) { |
| 1615 | SBModule sb_module; |
| 1616 | TargetSP target_sp(GetSP()); |
| 1617 | if (target_sp && sb_file_spec.IsValid()) { |
| 1618 | ModuleSpec module_spec(*sb_file_spec); |
| 1619 | // The module list is thread safe, no need to lock |
| 1620 | sb_module.SetSP(target_sp->GetImages().FindFirstModule(module_spec)); |
| 1621 | } |
| 1622 | return sb_module; |
| 1623 | } |
| 1624 | |
Alexander Polyakov | da0c081 | 2018-07-03 14:22:44 +0000 | [diff] [blame] | 1625 | SBSymbolContextList |
| 1626 | SBTarget::FindCompileUnits(const SBFileSpec &sb_file_spec) { |
| 1627 | SBSymbolContextList sb_sc_list; |
| 1628 | const TargetSP target_sp(GetSP()); |
| 1629 | if (target_sp && sb_file_spec.IsValid()) { |
| 1630 | const bool append = true; |
| 1631 | target_sp->GetImages().FindCompileUnits(*sb_file_spec, |
| 1632 | append, *sb_sc_list); |
| 1633 | } |
| 1634 | return sb_sc_list; |
| 1635 | } |
| 1636 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1637 | lldb::ByteOrder SBTarget::GetByteOrder() { |
| 1638 | TargetSP target_sp(GetSP()); |
| 1639 | if (target_sp) |
| 1640 | return target_sp->GetArchitecture().GetByteOrder(); |
| 1641 | return eByteOrderInvalid; |
| 1642 | } |
| 1643 | |
| 1644 | const char *SBTarget::GetTriple() { |
| 1645 | TargetSP target_sp(GetSP()); |
| 1646 | if (target_sp) { |
| 1647 | std::string triple(target_sp->GetArchitecture().GetTriple().str()); |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1648 | // Unique the string so we don't run into ownership issues since the const |
| 1649 | // strings put the string into the string pool once and the strings never |
| 1650 | // comes out |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1651 | ConstString const_triple(triple.c_str()); |
| 1652 | return const_triple.GetCString(); |
| 1653 | } |
| 1654 | return NULL; |
| 1655 | } |
| 1656 | |
| 1657 | uint32_t SBTarget::GetDataByteSize() { |
| 1658 | TargetSP target_sp(GetSP()); |
| 1659 | if (target_sp) { |
| 1660 | return target_sp->GetArchitecture().GetDataByteSize(); |
| 1661 | } |
| 1662 | return 0; |
| 1663 | } |
| 1664 | |
| 1665 | uint32_t SBTarget::GetCodeByteSize() { |
| 1666 | TargetSP target_sp(GetSP()); |
| 1667 | if (target_sp) { |
| 1668 | return target_sp->GetArchitecture().GetCodeByteSize(); |
| 1669 | } |
| 1670 | return 0; |
| 1671 | } |
| 1672 | |
| 1673 | uint32_t SBTarget::GetAddressByteSize() { |
| 1674 | TargetSP target_sp(GetSP()); |
| 1675 | if (target_sp) |
| 1676 | return target_sp->GetArchitecture().GetAddressByteSize(); |
| 1677 | return sizeof(void *); |
| 1678 | } |
| 1679 | |
| 1680 | SBModule SBTarget::GetModuleAtIndex(uint32_t idx) { |
| 1681 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1682 | |
| 1683 | SBModule sb_module; |
| 1684 | ModuleSP module_sp; |
| 1685 | TargetSP target_sp(GetSP()); |
| 1686 | if (target_sp) { |
| 1687 | // The module list is thread safe, no need to lock |
| 1688 | module_sp = target_sp->GetImages().GetModuleAtIndex(idx); |
| 1689 | sb_module.SetSP(module_sp); |
| 1690 | } |
| 1691 | |
| 1692 | if (log) |
| 1693 | log->Printf("SBTarget(%p)::GetModuleAtIndex (idx=%d) => SBModule(%p)", |
| 1694 | static_cast<void *>(target_sp.get()), idx, |
| 1695 | static_cast<void *>(module_sp.get())); |
| 1696 | |
| 1697 | return sb_module; |
| 1698 | } |
| 1699 | |
| 1700 | bool SBTarget::RemoveModule(lldb::SBModule module) { |
| 1701 | TargetSP target_sp(GetSP()); |
| 1702 | if (target_sp) |
| 1703 | return target_sp->GetImages().Remove(module.GetSP()); |
| 1704 | return false; |
| 1705 | } |
| 1706 | |
| 1707 | SBBroadcaster SBTarget::GetBroadcaster() const { |
| 1708 | Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1709 | |
| 1710 | TargetSP target_sp(GetSP()); |
| 1711 | SBBroadcaster broadcaster(target_sp.get(), false); |
| 1712 | |
| 1713 | if (log) |
| 1714 | log->Printf("SBTarget(%p)::GetBroadcaster () => SBBroadcaster(%p)", |
| 1715 | static_cast<void *>(target_sp.get()), |
| 1716 | static_cast<void *>(broadcaster.get())); |
| 1717 | |
| 1718 | return broadcaster; |
| 1719 | } |
| 1720 | |
| 1721 | bool SBTarget::GetDescription(SBStream &description, |
| 1722 | lldb::DescriptionLevel description_level) { |
| 1723 | Stream &strm = description.ref(); |
| 1724 | |
| 1725 | TargetSP target_sp(GetSP()); |
| 1726 | if (target_sp) { |
| 1727 | target_sp->Dump(&strm, description_level); |
| 1728 | } else |
| 1729 | strm.PutCString("No value"); |
| 1730 | |
| 1731 | return true; |
| 1732 | } |
| 1733 | |
| 1734 | lldb::SBSymbolContextList SBTarget::FindFunctions(const char *name, |
| 1735 | uint32_t name_type_mask) { |
| 1736 | lldb::SBSymbolContextList sb_sc_list; |
Zachary Turner | 117b1fa | 2018-10-25 20:45:40 +0000 | [diff] [blame] | 1737 | if (!name | !name[0]) |
| 1738 | return sb_sc_list; |
| 1739 | |
| 1740 | TargetSP target_sp(GetSP()); |
| 1741 | if (!target_sp) |
| 1742 | return sb_sc_list; |
| 1743 | |
| 1744 | const bool symbols_ok = true; |
| 1745 | const bool inlines_ok = true; |
| 1746 | const bool append = true; |
| 1747 | FunctionNameType mask = static_cast<FunctionNameType>(name_type_mask); |
| 1748 | target_sp->GetImages().FindFunctions(ConstString(name), mask, symbols_ok, |
| 1749 | inlines_ok, append, *sb_sc_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1750 | return sb_sc_list; |
Jim Ingham | 763b2b2 | 2015-07-07 22:12:17 +0000 | [diff] [blame] | 1751 | } |
Greg Clayton | e14e192 | 2012-12-04 02:22:16 +0000 | [diff] [blame] | 1752 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1753 | lldb::SBSymbolContextList SBTarget::FindGlobalFunctions(const char *name, |
| 1754 | uint32_t max_matches, |
| 1755 | MatchType matchtype) { |
| 1756 | lldb::SBSymbolContextList sb_sc_list; |
| 1757 | if (name && name[0]) { |
Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 1758 | llvm::StringRef name_ref(name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1759 | TargetSP target_sp(GetSP()); |
| 1760 | if (target_sp) { |
| 1761 | std::string regexstr; |
| 1762 | switch (matchtype) { |
| 1763 | case eMatchTypeRegex: |
Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 1764 | target_sp->GetImages().FindFunctions(RegularExpression(name_ref), true, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1765 | true, true, *sb_sc_list); |
| 1766 | break; |
| 1767 | case eMatchTypeStartsWith: |
| 1768 | regexstr = llvm::Regex::escape(name) + ".*"; |
Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 1769 | target_sp->GetImages().FindFunctions(RegularExpression(regexstr), true, |
| 1770 | true, true, *sb_sc_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1771 | break; |
| 1772 | default: |
| 1773 | target_sp->GetImages().FindFunctions(ConstString(name), |
| 1774 | eFunctionNameTypeAny, true, true, |
| 1775 | true, *sb_sc_list); |
| 1776 | break; |
| 1777 | } |
| 1778 | } |
| 1779 | } |
| 1780 | return sb_sc_list; |
| 1781 | } |
| 1782 | |
| 1783 | lldb::SBType SBTarget::FindFirstType(const char *typename_cstr) { |
| 1784 | TargetSP target_sp(GetSP()); |
| 1785 | if (typename_cstr && typename_cstr[0] && target_sp) { |
| 1786 | ConstString const_typename(typename_cstr); |
| 1787 | SymbolContext sc; |
| 1788 | const bool exact_match = false; |
| 1789 | |
| 1790 | const ModuleList &module_list = target_sp->GetImages(); |
| 1791 | size_t count = module_list.GetSize(); |
| 1792 | for (size_t idx = 0; idx < count; idx++) { |
| 1793 | ModuleSP module_sp(module_list.GetModuleAtIndex(idx)); |
| 1794 | if (module_sp) { |
| 1795 | TypeSP type_sp( |
| 1796 | module_sp->FindFirstType(sc, const_typename, exact_match)); |
| 1797 | if (type_sp) |
| 1798 | return SBType(type_sp); |
| 1799 | } |
| 1800 | } |
| 1801 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 1802 | // Didn't find the type in the symbols; try the Objective-C runtime if one |
| 1803 | // is installed |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1804 | |
| 1805 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 1806 | |
| 1807 | if (process_sp) { |
| 1808 | ObjCLanguageRuntime *objc_language_runtime = |
| 1809 | process_sp->GetObjCLanguageRuntime(); |
| 1810 | |
| 1811 | if (objc_language_runtime) { |
| 1812 | DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor(); |
| 1813 | |
| 1814 | if (objc_decl_vendor) { |
| 1815 | std::vector<clang::NamedDecl *> decls; |
| 1816 | |
| 1817 | if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) { |
| 1818 | if (CompilerType type = ClangASTContext::GetTypeForDecl(decls[0])) { |
| 1819 | return SBType(type); |
| 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | } |
| 1824 | } |
| 1825 | |
| 1826 | // No matches, search for basic typename matches |
| 1827 | ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); |
| 1828 | if (clang_ast) |
| 1829 | return SBType(ClangASTContext::GetBasicType(clang_ast->getASTContext(), |
| 1830 | const_typename)); |
| 1831 | } |
| 1832 | return SBType(); |
| 1833 | } |
| 1834 | |
| 1835 | SBType SBTarget::GetBasicType(lldb::BasicType type) { |
| 1836 | TargetSP target_sp(GetSP()); |
| 1837 | if (target_sp) { |
| 1838 | ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); |
| 1839 | if (clang_ast) |
| 1840 | return SBType( |
| 1841 | ClangASTContext::GetBasicType(clang_ast->getASTContext(), type)); |
| 1842 | } |
| 1843 | return SBType(); |
| 1844 | } |
| 1845 | |
| 1846 | lldb::SBTypeList SBTarget::FindTypes(const char *typename_cstr) { |
| 1847 | SBTypeList sb_type_list; |
| 1848 | TargetSP target_sp(GetSP()); |
| 1849 | if (typename_cstr && typename_cstr[0] && target_sp) { |
| 1850 | ModuleList &images = target_sp->GetImages(); |
| 1851 | ConstString const_typename(typename_cstr); |
| 1852 | bool exact_match = false; |
| 1853 | SymbolContext sc; |
| 1854 | TypeList type_list; |
| 1855 | llvm::DenseSet<SymbolFile *> searched_symbol_files; |
| 1856 | uint32_t num_matches = |
| 1857 | images.FindTypes(sc, const_typename, exact_match, UINT32_MAX, |
| 1858 | searched_symbol_files, type_list); |
| 1859 | |
| 1860 | if (num_matches > 0) { |
| 1861 | for (size_t idx = 0; idx < num_matches; idx++) { |
| 1862 | TypeSP type_sp(type_list.GetTypeAtIndex(idx)); |
| 1863 | if (type_sp) |
| 1864 | sb_type_list.Append(SBType(type_sp)); |
| 1865 | } |
| 1866 | } |
| 1867 | |
| 1868 | // Try the Objective-C runtime if one is installed |
| 1869 | |
| 1870 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 1871 | |
| 1872 | if (process_sp) { |
| 1873 | ObjCLanguageRuntime *objc_language_runtime = |
| 1874 | process_sp->GetObjCLanguageRuntime(); |
| 1875 | |
| 1876 | if (objc_language_runtime) { |
| 1877 | DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor(); |
| 1878 | |
| 1879 | if (objc_decl_vendor) { |
| 1880 | std::vector<clang::NamedDecl *> decls; |
| 1881 | |
| 1882 | if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) { |
| 1883 | for (clang::NamedDecl *decl : decls) { |
| 1884 | if (CompilerType type = ClangASTContext::GetTypeForDecl(decl)) { |
| 1885 | sb_type_list.Append(SBType(type)); |
| 1886 | } |
| 1887 | } |
| 1888 | } |
| 1889 | } |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | if (sb_type_list.GetSize() == 0) { |
| 1894 | // No matches, search for basic typename matches |
| 1895 | ClangASTContext *clang_ast = target_sp->GetScratchClangASTContext(); |
| 1896 | if (clang_ast) |
| 1897 | sb_type_list.Append(SBType(ClangASTContext::GetBasicType( |
| 1898 | clang_ast->getASTContext(), const_typename))); |
| 1899 | } |
| 1900 | } |
| 1901 | return sb_type_list; |
| 1902 | } |
| 1903 | |
| 1904 | SBValueList SBTarget::FindGlobalVariables(const char *name, |
| 1905 | uint32_t max_matches) { |
| 1906 | SBValueList sb_value_list; |
| 1907 | |
| 1908 | TargetSP target_sp(GetSP()); |
| 1909 | if (name && target_sp) { |
| 1910 | VariableList variable_list; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1911 | const uint32_t match_count = target_sp->GetImages().FindGlobalVariables( |
Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 1912 | ConstString(name), max_matches, variable_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1913 | |
| 1914 | if (match_count > 0) { |
| 1915 | ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); |
| 1916 | if (exe_scope == NULL) |
| 1917 | exe_scope = target_sp.get(); |
| 1918 | for (uint32_t i = 0; i < match_count; ++i) { |
| 1919 | lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create( |
| 1920 | exe_scope, variable_list.GetVariableAtIndex(i))); |
| 1921 | if (valobj_sp) |
| 1922 | sb_value_list.Append(SBValue(valobj_sp)); |
| 1923 | } |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | return sb_value_list; |
| 1928 | } |
| 1929 | |
| 1930 | SBValueList SBTarget::FindGlobalVariables(const char *name, |
| 1931 | uint32_t max_matches, |
| 1932 | MatchType matchtype) { |
| 1933 | SBValueList sb_value_list; |
| 1934 | |
| 1935 | TargetSP target_sp(GetSP()); |
| 1936 | if (name && target_sp) { |
Zachary Turner | 95eae42 | 2016-09-21 16:01:28 +0000 | [diff] [blame] | 1937 | llvm::StringRef name_ref(name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1938 | VariableList variable_list; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1939 | |
| 1940 | std::string regexstr; |
| 1941 | uint32_t match_count; |
| 1942 | switch (matchtype) { |
| 1943 | case eMatchTypeNormal: |
| 1944 | match_count = target_sp->GetImages().FindGlobalVariables( |
Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 1945 | ConstString(name), max_matches, variable_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1946 | break; |
| 1947 | case eMatchTypeRegex: |
| 1948 | match_count = target_sp->GetImages().FindGlobalVariables( |
Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 1949 | RegularExpression(name_ref), max_matches, variable_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1950 | break; |
| 1951 | case eMatchTypeStartsWith: |
| 1952 | regexstr = llvm::Regex::escape(name) + ".*"; |
| 1953 | match_count = target_sp->GetImages().FindGlobalVariables( |
Pavel Labath | 34cda14 | 2018-05-31 09:46:26 +0000 | [diff] [blame] | 1954 | RegularExpression(regexstr), max_matches, variable_list); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1955 | break; |
| 1956 | } |
| 1957 | |
| 1958 | if (match_count > 0) { |
| 1959 | ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); |
| 1960 | if (exe_scope == NULL) |
| 1961 | exe_scope = target_sp.get(); |
| 1962 | for (uint32_t i = 0; i < match_count; ++i) { |
| 1963 | lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create( |
| 1964 | exe_scope, variable_list.GetVariableAtIndex(i))); |
| 1965 | if (valobj_sp) |
| 1966 | sb_value_list.Append(SBValue(valobj_sp)); |
| 1967 | } |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | return sb_value_list; |
| 1972 | } |
| 1973 | |
| 1974 | lldb::SBValue SBTarget::FindFirstGlobalVariable(const char *name) { |
| 1975 | SBValueList sb_value_list(FindGlobalVariables(name, 1)); |
| 1976 | if (sb_value_list.IsValid() && sb_value_list.GetSize() > 0) |
| 1977 | return sb_value_list.GetValueAtIndex(0); |
| 1978 | return SBValue(); |
| 1979 | } |
| 1980 | |
| 1981 | SBSourceManager SBTarget::GetSourceManager() { |
| 1982 | SBSourceManager source_manager(*this); |
| 1983 | return source_manager; |
| 1984 | } |
| 1985 | |
| 1986 | lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr, |
| 1987 | uint32_t count) { |
| 1988 | return ReadInstructions(base_addr, count, NULL); |
| 1989 | } |
| 1990 | |
| 1991 | lldb::SBInstructionList SBTarget::ReadInstructions(lldb::SBAddress base_addr, |
| 1992 | uint32_t count, |
| 1993 | const char *flavor_string) { |
| 1994 | SBInstructionList sb_instructions; |
| 1995 | |
| 1996 | TargetSP target_sp(GetSP()); |
| 1997 | if (target_sp) { |
| 1998 | Address *addr_ptr = base_addr.get(); |
| 1999 | |
| 2000 | if (addr_ptr) { |
| 2001 | DataBufferHeap data( |
| 2002 | target_sp->GetArchitecture().GetMaximumOpcodeByteSize() * count, 0); |
| 2003 | bool prefer_file_cache = false; |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 2004 | lldb_private::Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2005 | lldb::addr_t load_addr = LLDB_INVALID_ADDRESS; |
| 2006 | const size_t bytes_read = |
| 2007 | target_sp->ReadMemory(*addr_ptr, prefer_file_cache, data.GetBytes(), |
| 2008 | data.GetByteSize(), error, &load_addr); |
| 2009 | const bool data_from_file = load_addr == LLDB_INVALID_ADDRESS; |
| 2010 | sb_instructions.SetDisassembler(Disassembler::DisassembleBytes( |
| 2011 | target_sp->GetArchitecture(), NULL, flavor_string, *addr_ptr, |
| 2012 | data.GetBytes(), bytes_read, count, data_from_file)); |
| 2013 | } |
| 2014 | } |
| 2015 | |
| 2016 | return sb_instructions; |
| 2017 | } |
| 2018 | |
| 2019 | lldb::SBInstructionList SBTarget::GetInstructions(lldb::SBAddress base_addr, |
| 2020 | const void *buf, |
| 2021 | size_t size) { |
| 2022 | return GetInstructionsWithFlavor(base_addr, NULL, buf, size); |
| 2023 | } |
| 2024 | |
| 2025 | lldb::SBInstructionList |
| 2026 | SBTarget::GetInstructionsWithFlavor(lldb::SBAddress base_addr, |
| 2027 | const char *flavor_string, const void *buf, |
| 2028 | size_t size) { |
| 2029 | SBInstructionList sb_instructions; |
| 2030 | |
| 2031 | TargetSP target_sp(GetSP()); |
| 2032 | if (target_sp) { |
| 2033 | Address addr; |
| 2034 | |
| 2035 | if (base_addr.get()) |
| 2036 | addr = *base_addr.get(); |
| 2037 | |
| 2038 | const bool data_from_file = true; |
| 2039 | |
| 2040 | sb_instructions.SetDisassembler(Disassembler::DisassembleBytes( |
| 2041 | target_sp->GetArchitecture(), NULL, flavor_string, addr, buf, size, |
| 2042 | UINT32_MAX, data_from_file)); |
| 2043 | } |
| 2044 | |
| 2045 | return sb_instructions; |
| 2046 | } |
| 2047 | |
| 2048 | lldb::SBInstructionList SBTarget::GetInstructions(lldb::addr_t base_addr, |
| 2049 | const void *buf, |
| 2050 | size_t size) { |
| 2051 | return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), NULL, buf, |
| 2052 | size); |
| 2053 | } |
| 2054 | |
| 2055 | lldb::SBInstructionList |
| 2056 | SBTarget::GetInstructionsWithFlavor(lldb::addr_t base_addr, |
| 2057 | const char *flavor_string, const void *buf, |
| 2058 | size_t size) { |
| 2059 | return GetInstructionsWithFlavor(ResolveLoadAddress(base_addr), flavor_string, |
| 2060 | buf, size); |
| 2061 | } |
| 2062 | |
| 2063 | SBError SBTarget::SetSectionLoadAddress(lldb::SBSection section, |
| 2064 | lldb::addr_t section_base_addr) { |
| 2065 | SBError sb_error; |
| 2066 | TargetSP target_sp(GetSP()); |
| 2067 | if (target_sp) { |
| 2068 | if (!section.IsValid()) { |
| 2069 | sb_error.SetErrorStringWithFormat("invalid section"); |
| 2070 | } else { |
| 2071 | SectionSP section_sp(section.GetSP()); |
| 2072 | if (section_sp) { |
| 2073 | if (section_sp->IsThreadSpecific()) { |
| 2074 | sb_error.SetErrorString( |
| 2075 | "thread specific sections are not yet supported"); |
| 2076 | } else { |
| 2077 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 2078 | if (target_sp->SetSectionLoadAddress(section_sp, section_base_addr)) { |
| 2079 | ModuleSP module_sp(section_sp->GetModule()); |
| 2080 | if (module_sp) { |
| 2081 | ModuleList module_list; |
| 2082 | module_list.Append(module_sp); |
| 2083 | target_sp->ModulesDidLoad(module_list); |
| 2084 | } |
| 2085 | // Flush info in the process (stack frames, etc) |
| 2086 | if (process_sp) |
| 2087 | process_sp->Flush(); |
| 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | } |
| 2092 | } else { |
| 2093 | sb_error.SetErrorString("invalid target"); |
| 2094 | } |
| 2095 | return sb_error; |
| 2096 | } |
| 2097 | |
| 2098 | SBError SBTarget::ClearSectionLoadAddress(lldb::SBSection section) { |
| 2099 | SBError sb_error; |
| 2100 | |
| 2101 | TargetSP target_sp(GetSP()); |
| 2102 | if (target_sp) { |
| 2103 | if (!section.IsValid()) { |
| 2104 | sb_error.SetErrorStringWithFormat("invalid section"); |
| 2105 | } else { |
| 2106 | SectionSP section_sp(section.GetSP()); |
| 2107 | if (section_sp) { |
| 2108 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 2109 | if (target_sp->SetSectionUnloaded(section_sp)) { |
| 2110 | ModuleSP module_sp(section_sp->GetModule()); |
| 2111 | if (module_sp) { |
| 2112 | ModuleList module_list; |
| 2113 | module_list.Append(module_sp); |
| 2114 | target_sp->ModulesDidUnload(module_list, false); |
| 2115 | } |
| 2116 | // Flush info in the process (stack frames, etc) |
| 2117 | if (process_sp) |
| 2118 | process_sp->Flush(); |
| 2119 | } |
| 2120 | } else { |
| 2121 | sb_error.SetErrorStringWithFormat("invalid section"); |
| 2122 | } |
| 2123 | } |
| 2124 | } else { |
| 2125 | sb_error.SetErrorStringWithFormat("invalid target"); |
| 2126 | } |
| 2127 | return sb_error; |
| 2128 | } |
| 2129 | |
| 2130 | SBError SBTarget::SetModuleLoadAddress(lldb::SBModule module, |
| 2131 | int64_t slide_offset) { |
| 2132 | SBError sb_error; |
| 2133 | |
| 2134 | TargetSP target_sp(GetSP()); |
| 2135 | if (target_sp) { |
| 2136 | ModuleSP module_sp(module.GetSP()); |
| 2137 | if (module_sp) { |
| 2138 | bool changed = false; |
| 2139 | if (module_sp->SetLoadAddress(*target_sp, slide_offset, true, changed)) { |
| 2140 | // The load was successful, make sure that at least some sections |
| 2141 | // changed before we notify that our module was loaded. |
| 2142 | if (changed) { |
| 2143 | ModuleList module_list; |
| 2144 | module_list.Append(module_sp); |
| 2145 | target_sp->ModulesDidLoad(module_list); |
| 2146 | // Flush info in the process (stack frames, etc) |
| 2147 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 2148 | if (process_sp) |
| 2149 | process_sp->Flush(); |
| 2150 | } |
| 2151 | } |
| 2152 | } else { |
| 2153 | sb_error.SetErrorStringWithFormat("invalid module"); |
| 2154 | } |
| 2155 | |
| 2156 | } else { |
| 2157 | sb_error.SetErrorStringWithFormat("invalid target"); |
| 2158 | } |
| 2159 | return sb_error; |
| 2160 | } |
| 2161 | |
| 2162 | SBError SBTarget::ClearModuleLoadAddress(lldb::SBModule module) { |
| 2163 | SBError sb_error; |
| 2164 | |
| 2165 | char path[PATH_MAX]; |
| 2166 | TargetSP target_sp(GetSP()); |
| 2167 | if (target_sp) { |
| 2168 | ModuleSP module_sp(module.GetSP()); |
| 2169 | if (module_sp) { |
| 2170 | ObjectFile *objfile = module_sp->GetObjectFile(); |
| 2171 | if (objfile) { |
| 2172 | SectionList *section_list = objfile->GetSectionList(); |
| 2173 | if (section_list) { |
| 2174 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 2175 | |
| 2176 | bool changed = false; |
| 2177 | const size_t num_sections = section_list->GetSize(); |
| 2178 | for (size_t sect_idx = 0; sect_idx < num_sections; ++sect_idx) { |
| 2179 | SectionSP section_sp(section_list->GetSectionAtIndex(sect_idx)); |
| 2180 | if (section_sp) |
| 2181 | changed |= target_sp->SetSectionUnloaded(section_sp); |
| 2182 | } |
| 2183 | if (changed) { |
| 2184 | ModuleList module_list; |
| 2185 | module_list.Append(module_sp); |
| 2186 | target_sp->ModulesDidUnload(module_list, false); |
| 2187 | // Flush info in the process (stack frames, etc) |
| 2188 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 2189 | if (process_sp) |
| 2190 | process_sp->Flush(); |
| 2191 | } |
| 2192 | } else { |
| 2193 | module_sp->GetFileSpec().GetPath(path, sizeof(path)); |
| 2194 | sb_error.SetErrorStringWithFormat("no sections in object file '%s'", |
| 2195 | path); |
| 2196 | } |
| 2197 | } else { |
| 2198 | module_sp->GetFileSpec().GetPath(path, sizeof(path)); |
| 2199 | sb_error.SetErrorStringWithFormat("no object file for module '%s'", |
| 2200 | path); |
| 2201 | } |
| 2202 | } else { |
| 2203 | sb_error.SetErrorStringWithFormat("invalid module"); |
| 2204 | } |
| 2205 | } else { |
| 2206 | sb_error.SetErrorStringWithFormat("invalid target"); |
| 2207 | } |
| 2208 | return sb_error; |
| 2209 | } |
| 2210 | |
| 2211 | lldb::SBSymbolContextList SBTarget::FindSymbols(const char *name, |
| 2212 | lldb::SymbolType symbol_type) { |
| 2213 | SBSymbolContextList sb_sc_list; |
| 2214 | if (name && name[0]) { |
| 2215 | TargetSP target_sp(GetSP()); |
| 2216 | if (target_sp) { |
| 2217 | bool append = true; |
| 2218 | target_sp->GetImages().FindSymbolsWithNameAndType( |
| 2219 | ConstString(name), symbol_type, *sb_sc_list, append); |
| 2220 | } |
| 2221 | } |
| 2222 | return sb_sc_list; |
| 2223 | } |
| 2224 | |
| 2225 | lldb::SBValue SBTarget::EvaluateExpression(const char *expr) { |
| 2226 | TargetSP target_sp(GetSP()); |
| 2227 | if (!target_sp) |
| 2228 | return SBValue(); |
| 2229 | |
| 2230 | SBExpressionOptions options; |
| 2231 | lldb::DynamicValueType fetch_dynamic_value = |
| 2232 | target_sp->GetPreferDynamicValue(); |
| 2233 | options.SetFetchDynamicValue(fetch_dynamic_value); |
| 2234 | options.SetUnwindOnError(true); |
| 2235 | return EvaluateExpression(expr, options); |
| 2236 | } |
| 2237 | |
| 2238 | lldb::SBValue SBTarget::EvaluateExpression(const char *expr, |
| 2239 | const SBExpressionOptions &options) { |
| 2240 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Saleem Abdulrasool | 6010f97 | 2016-04-22 23:08:34 +0000 | [diff] [blame] | 2241 | #if !defined(LLDB_DISABLE_PYTHON) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2242 | Log *expr_log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_EXPRESSIONS)); |
Saleem Abdulrasool | 6010f97 | 2016-04-22 23:08:34 +0000 | [diff] [blame] | 2243 | #endif |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2244 | SBValue expr_result; |
| 2245 | ExpressionResults exe_results = eExpressionSetupError; |
| 2246 | ValueObjectSP expr_value_sp; |
| 2247 | TargetSP target_sp(GetSP()); |
| 2248 | StackFrame *frame = NULL; |
| 2249 | if (target_sp) { |
| 2250 | if (expr == NULL || expr[0] == '\0') { |
| 2251 | if (log) |
| 2252 | log->Printf( |
| 2253 | "SBTarget::EvaluateExpression called with an empty expression"); |
| 2254 | return expr_result; |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 2255 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2256 | |
| 2257 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
| 2258 | ExecutionContext exe_ctx(m_opaque_sp.get()); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2259 | |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 2260 | if (log) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2261 | log->Printf("SBTarget()::EvaluateExpression (expr=\"%s\")...", expr); |
| 2262 | |
| 2263 | frame = exe_ctx.GetFramePtr(); |
| 2264 | Target *target = exe_ctx.GetTargetPtr(); |
| 2265 | |
| 2266 | if (target) { |
| 2267 | #ifdef LLDB_CONFIGURATION_DEBUG |
| 2268 | StreamString frame_description; |
| 2269 | if (frame) |
| 2270 | frame->DumpUsingSettingsFormat(&frame_description); |
Jim Ingham | 8f7db52 | 2016-12-15 00:30:30 +0000 | [diff] [blame] | 2271 | llvm::PrettyStackTraceFormat stack_trace( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2272 | "SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = " |
| 2273 | "%u) %s", |
| 2274 | expr, options.GetFetchDynamicValue(), |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 2275 | frame_description.GetString().str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2276 | #endif |
| 2277 | exe_results = |
| 2278 | target->EvaluateExpression(expr, frame, expr_value_sp, options.ref()); |
| 2279 | |
| 2280 | expr_result.SetSP(expr_value_sp, options.GetFetchDynamicValue()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2281 | } else { |
| 2282 | if (log) |
| 2283 | log->Printf("SBTarget::EvaluateExpression () => error: could not " |
| 2284 | "reconstruct frame object for this SBTarget."); |
| 2285 | } |
| 2286 | } |
| 2287 | #ifndef LLDB_DISABLE_PYTHON |
| 2288 | if (expr_log) |
| 2289 | expr_log->Printf("** [SBTarget::EvaluateExpression] Expression result is " |
| 2290 | "%s, summary %s **", |
| 2291 | expr_result.GetValue(), expr_result.GetSummary()); |
| 2292 | |
| 2293 | if (log) |
| 2294 | log->Printf("SBTarget(%p)::EvaluateExpression (expr=\"%s\") => SBValue(%p) " |
| 2295 | "(execution result=%d)", |
| 2296 | static_cast<void *>(frame), expr, |
| 2297 | static_cast<void *>(expr_value_sp.get()), exe_results); |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 2298 | #endif |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 2299 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2300 | return expr_result; |
Greg Clayton | 4b63a5c | 2013-01-04 18:10:18 +0000 | [diff] [blame] | 2301 | } |
| 2302 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2303 | lldb::addr_t SBTarget::GetStackRedZoneSize() { |
| 2304 | TargetSP target_sp(GetSP()); |
| 2305 | if (target_sp) { |
| 2306 | ABISP abi_sp; |
| 2307 | ProcessSP process_sp(target_sp->GetProcessSP()); |
| 2308 | if (process_sp) |
| 2309 | abi_sp = process_sp->GetABI(); |
| 2310 | else |
Jason Molenda | 43294c9 | 2017-06-29 02:57:03 +0000 | [diff] [blame] | 2311 | abi_sp = ABI::FindPlugin(ProcessSP(), target_sp->GetArchitecture()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2312 | if (abi_sp) |
| 2313 | return abi_sp->GetRedZoneSize(); |
| 2314 | } |
| 2315 | return 0; |
Greg Clayton | 13fbb99 | 2013-02-01 00:47:49 +0000 | [diff] [blame] | 2316 | } |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 2317 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2318 | lldb::SBLaunchInfo SBTarget::GetLaunchInfo() const { |
| 2319 | lldb::SBLaunchInfo launch_info(NULL); |
| 2320 | TargetSP target_sp(GetSP()); |
| 2321 | if (target_sp) |
Pavel Labath | 62930e5 | 2018-01-10 11:57:31 +0000 | [diff] [blame] | 2322 | launch_info.set_ref(m_opaque_sp->GetProcessLaunchInfo()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2323 | return launch_info; |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 2324 | } |
| 2325 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 2326 | void SBTarget::SetLaunchInfo(const lldb::SBLaunchInfo &launch_info) { |
| 2327 | TargetSP target_sp(GetSP()); |
| 2328 | if (target_sp) |
| 2329 | m_opaque_sp->SetProcessLaunchInfo(launch_info.ref()); |
Ilia K | 8f37ca5 | 2015-02-13 14:31:06 +0000 | [diff] [blame] | 2330 | } |