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