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