Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SBDebugger.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 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 9 | #include "SBReproducerPrivate.h" |
Alex Langford | d17cd90 | 2018-05-25 20:28:16 +0000 | [diff] [blame] | 10 | #include "SystemInitializerFull.h" |
| 11 | |
Eli Friedman | ca93cc1 | 2010-06-09 07:37:52 +0000 | [diff] [blame] | 12 | #include "lldb/API/SBDebugger.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 14 | #include "lldb/lldb-private.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | |
Eli Friedman | ca93cc1 | 2010-06-09 07:37:52 +0000 | [diff] [blame] | 16 | #include "lldb/API/SBBroadcaster.h" |
| 17 | #include "lldb/API/SBCommandInterpreter.h" |
| 18 | #include "lldb/API/SBCommandReturnObject.h" |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 19 | #include "lldb/API/SBError.h" |
Eli Friedman | ca93cc1 | 2010-06-09 07:37:52 +0000 | [diff] [blame] | 20 | #include "lldb/API/SBEvent.h" |
| 21 | #include "lldb/API/SBFrame.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 22 | #include "lldb/API/SBListener.h" |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 23 | #include "lldb/API/SBProcess.h" |
| 24 | #include "lldb/API/SBSourceManager.h" |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 25 | #include "lldb/API/SBStream.h" |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 26 | #include "lldb/API/SBStringList.h" |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 27 | #include "lldb/API/SBStructuredData.h" |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 28 | #include "lldb/API/SBTarget.h" |
| 29 | #include "lldb/API/SBThread.h" |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 30 | #include "lldb/API/SBTypeCategory.h" |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 31 | #include "lldb/API/SBTypeFilter.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 32 | #include "lldb/API/SBTypeFormat.h" |
Enrico Granata | 061858c | 2012-02-15 02:34:21 +0000 | [diff] [blame] | 33 | #include "lldb/API/SBTypeNameSpecifier.h" |
| 34 | #include "lldb/API/SBTypeSummary.h" |
| 35 | #include "lldb/API/SBTypeSynthetic.h" |
| 36 | |
Greg Clayton | 6eee5aa | 2010-10-11 01:05:37 +0000 | [diff] [blame] | 37 | #include "lldb/Core/Debugger.h" |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 38 | #include "lldb/Core/PluginManager.h" |
Greg Clayton | 44d9378 | 2014-01-27 23:43:24 +0000 | [diff] [blame] | 39 | #include "lldb/Core/StreamFile.h" |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 40 | #include "lldb/Core/StructuredDataImpl.h" |
Enrico Granata | 5548cb5 | 2013-01-28 23:47:25 +0000 | [diff] [blame] | 41 | #include "lldb/DataFormatters/DataVisualization.h" |
Pavel Labath | f1389e9 | 2018-02-19 15:06:28 +0000 | [diff] [blame] | 42 | #include "lldb/Host/XML.h" |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 43 | #include "lldb/Initialization/SystemLifetimeManager.h" |
Greg Clayton | 6eee5aa | 2010-10-11 01:05:37 +0000 | [diff] [blame] | 44 | #include "lldb/Interpreter/CommandInterpreter.h" |
Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 45 | #include "lldb/Interpreter/OptionArgParser.h" |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 46 | #include "lldb/Interpreter/OptionGroupPlatform.h" |
Greg Clayton | 6eee5aa | 2010-10-11 01:05:37 +0000 | [diff] [blame] | 47 | #include "lldb/Target/Process.h" |
| 48 | #include "lldb/Target/TargetList.h" |
Pavel Labath | 145d95c | 2018-04-17 18:53:35 +0000 | [diff] [blame] | 49 | #include "lldb/Utility/Args.h" |
Pavel Labath | d821c99 | 2018-08-07 11:07:21 +0000 | [diff] [blame] | 50 | #include "lldb/Utility/State.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 51 | |
Enrico Granata | d717cc9 | 2015-10-20 04:50:09 +0000 | [diff] [blame] | 52 | #include "llvm/ADT/STLExtras.h" |
Zachary Turner | 7b2e5a3 | 2016-09-16 19:09:12 +0000 | [diff] [blame] | 53 | #include "llvm/ADT/StringRef.h" |
Zachary Turner | 58a559c | 2014-08-27 20:15:09 +0000 | [diff] [blame] | 54 | #include "llvm/Support/DynamicLibrary.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | #include "llvm/Support/ManagedStatic.h" |
Zachary Turner | 58a559c | 2014-08-27 20:15:09 +0000 | [diff] [blame] | 56 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 57 | using namespace lldb; |
| 58 | using namespace lldb_private; |
| 59 | |
Jonas Devlieghere | d77c2e0 | 2019-03-02 00:20:26 +0000 | [diff] [blame] | 60 | /// Helper class for replaying commands through the reproducer. |
| 61 | class CommandLoader { |
| 62 | public: |
| 63 | CommandLoader(std::vector<std::string> files) : m_files(files) {} |
| 64 | |
| 65 | static std::unique_ptr<CommandLoader> Create() { |
| 66 | repro::Loader *loader = repro::Reproducer::Instance().GetLoader(); |
| 67 | if (!loader) |
| 68 | return {}; |
| 69 | |
| 70 | FileSpec file = loader->GetFile<repro::CommandInfo>(); |
| 71 | if (!file) |
| 72 | return {}; |
| 73 | |
| 74 | auto error_or_file = llvm::MemoryBuffer::getFile(file.GetPath()); |
| 75 | if (auto err = error_or_file.getError()) |
| 76 | return {}; |
| 77 | |
| 78 | std::vector<std::string> files; |
| 79 | llvm::yaml::Input yin((*error_or_file)->getBuffer()); |
| 80 | yin >> files; |
| 81 | |
| 82 | if (auto err = yin.error()) |
| 83 | return {}; |
| 84 | |
| 85 | return llvm::make_unique<CommandLoader>(std::move(files)); |
| 86 | } |
| 87 | |
| 88 | FILE *GetNextFile() { |
| 89 | if (m_index >= m_files.size()) |
| 90 | return nullptr; |
| 91 | return FileSystem::Instance().Fopen(m_files[m_index++].c_str(), "r"); |
| 92 | } |
| 93 | |
| 94 | private: |
| 95 | std::vector<std::string> m_files; |
| 96 | unsigned m_index = 0; |
| 97 | }; |
| 98 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 99 | static llvm::sys::DynamicLibrary LoadPlugin(const lldb::DebuggerSP &debugger_sp, |
| 100 | const FileSpec &spec, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 101 | Status &error) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 102 | llvm::sys::DynamicLibrary dynlib = |
| 103 | llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str()); |
| 104 | if (dynlib.isValid()) { |
| 105 | typedef bool (*LLDBCommandPluginInit)(lldb::SBDebugger & debugger); |
| 106 | |
| 107 | lldb::SBDebugger debugger_sb(debugger_sp); |
| 108 | // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) |
| 109 | // function. |
| 110 | // TODO: mangle this differently for your system - on OSX, the first |
| 111 | // underscore needs to be removed and the second one stays |
| 112 | LLDBCommandPluginInit init_func = |
Stephane Sezer | 22701b2 | 2017-10-24 23:46:00 +0000 | [diff] [blame] | 113 | (LLDBCommandPluginInit)(uintptr_t)dynlib.getAddressOfSymbol( |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 114 | "_ZN4lldb16PluginInitializeENS_10SBDebuggerE"); |
| 115 | if (init_func) { |
| 116 | if (init_func(debugger_sb)) |
| 117 | return dynlib; |
| 118 | else |
| 119 | error.SetErrorString("plug-in refused to load " |
| 120 | "(lldb::PluginInitialize(lldb::SBDebugger) " |
| 121 | "returned false)"); |
| 122 | } else { |
| 123 | error.SetErrorString("plug-in is missing the required initialization: " |
| 124 | "lldb::PluginInitialize(lldb::SBDebugger)"); |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 125 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 126 | } else { |
Jonas Devlieghere | dbd7fab | 2018-11-01 17:09:25 +0000 | [diff] [blame] | 127 | if (FileSystem::Instance().Exists(spec)) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 128 | error.SetErrorString("this file does not represent a loadable dylib"); |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 129 | else |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 130 | error.SetErrorString("no such file"); |
| 131 | } |
| 132 | return llvm::sys::DynamicLibrary(); |
Greg Clayton | 5fb8f79 | 2013-12-02 19:35:49 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 135 | static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime; |
| 136 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 137 | SBError SBInputReader::Initialize( |
| 138 | lldb::SBDebugger &sb_debugger, |
| 139 | unsigned long (*)(void *, lldb::SBInputReader *, lldb::InputReaderAction, |
| 140 | char const *, unsigned long), |
| 141 | void *, lldb::InputReaderGranularity, char const *, char const *, bool) { |
| 142 | return SBError(); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 145 | void SBInputReader::SetIsDone(bool b) { |
| 146 | LLDB_RECORD_METHOD(void, SBInputReader, SetIsDone, (bool), b); |
| 147 | } |
Eugene Zelenko | dbb0abb | 2015-10-31 01:22:59 +0000 | [diff] [blame] | 148 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 149 | bool SBInputReader::IsActive() const { |
| 150 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBInputReader, IsActive); |
Zachary Turner | e6e2bb3 | 2015-03-31 21:03:22 +0000 | [diff] [blame] | 151 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 152 | return false; |
| 153 | } |
| 154 | |
| 155 | SBDebugger::SBDebugger() { LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBDebugger); } |
Eugene Zelenko | dbb0abb | 2015-10-31 01:22:59 +0000 | [diff] [blame] | 156 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 157 | SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 158 | : m_opaque_sp(debugger_sp) { |
| 159 | LLDB_RECORD_CONSTRUCTOR(SBDebugger, (const lldb::DebuggerSP &), debugger_sp); |
| 160 | } |
Eugene Zelenko | dbb0abb | 2015-10-31 01:22:59 +0000 | [diff] [blame] | 161 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 162 | SBDebugger::SBDebugger(const SBDebugger &rhs) : m_opaque_sp(rhs.m_opaque_sp) { |
| 163 | LLDB_RECORD_CONSTRUCTOR(SBDebugger, (const lldb::SBDebugger &), rhs); |
| 164 | } |
Eugene Zelenko | dbb0abb | 2015-10-31 01:22:59 +0000 | [diff] [blame] | 165 | |
| 166 | SBDebugger::~SBDebugger() = default; |
| 167 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 168 | SBDebugger &SBDebugger::operator=(const SBDebugger &rhs) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 169 | LLDB_RECORD_METHOD(lldb::SBDebugger &, |
| 170 | SBDebugger, operator=,(const lldb::SBDebugger &), rhs); |
| 171 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 172 | if (this != &rhs) { |
| 173 | m_opaque_sp = rhs.m_opaque_sp; |
| 174 | } |
| 175 | return *this; |
Eugene Zelenko | dbb0abb | 2015-10-31 01:22:59 +0000 | [diff] [blame] | 176 | } |
| 177 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 178 | void SBDebugger::Initialize() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 179 | LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, Initialize); |
Jonas Devlieghere | 936c624 | 2019-02-21 22:26:16 +0000 | [diff] [blame] | 180 | SBError ignored = SBDebugger::InitializeWithErrorHandling(); |
Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 181 | } |
| 182 | |
Jonas Devlieghere | 936c624 | 2019-02-21 22:26:16 +0000 | [diff] [blame] | 183 | lldb::SBError SBDebugger::InitializeWithErrorHandling() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 184 | LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBError, SBDebugger, |
| 185 | InitializeWithErrorHandling); |
| 186 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 187 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 188 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 189 | if (log) |
| 190 | log->Printf("SBDebugger::Initialize ()"); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 191 | |
Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 192 | SBError error; |
| 193 | if (auto e = g_debugger_lifetime->Initialize( |
Jonas Devlieghere | 936c624 | 2019-02-21 22:26:16 +0000 | [diff] [blame] | 194 | llvm::make_unique<SystemInitializerFull>(), LoadPlugin)) { |
Jonas Devlieghere | 15eacd7 | 2018-12-03 17:28:29 +0000 | [diff] [blame] | 195 | error.SetError(Status(std::move(e))); |
| 196 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 197 | return LLDB_RECORD_RESULT(error); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 200 | void SBDebugger::Terminate() { |
| 201 | LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, Terminate); |
| 202 | |
| 203 | g_debugger_lifetime->Terminate(); |
| 204 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 205 | |
| 206 | void SBDebugger::Clear() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 207 | LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, Clear); |
| 208 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 209 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 210 | |
| 211 | if (log) |
| 212 | log->Printf("SBDebugger(%p)::Clear ()", |
| 213 | static_cast<void *>(m_opaque_sp.get())); |
| 214 | |
| 215 | if (m_opaque_sp) |
| 216 | m_opaque_sp->ClearIOHandlers(); |
| 217 | |
| 218 | m_opaque_sp.reset(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 219 | } |
| 220 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 221 | SBDebugger SBDebugger::Create() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 222 | LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBDebugger, SBDebugger, Create); |
| 223 | |
| 224 | return LLDB_RECORD_RESULT(SBDebugger::Create(false, nullptr, nullptr)); |
Greg Clayton | 48e4254 | 2010-07-30 20:12:55 +0000 | [diff] [blame] | 225 | } |
| 226 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 227 | SBDebugger SBDebugger::Create(bool source_init_files) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 228 | LLDB_RECORD_STATIC_METHOD(lldb::SBDebugger, SBDebugger, Create, (bool), |
| 229 | source_init_files); |
| 230 | |
| 231 | return LLDB_RECORD_RESULT( |
| 232 | SBDebugger::Create(source_init_files, nullptr, nullptr)); |
Jim Ingham | 0694269 | 2011-08-13 00:22:20 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 235 | SBDebugger SBDebugger::Create(bool source_init_files, |
| 236 | lldb::LogOutputCallback callback, void *baton) |
Jim Ingham | 228063c | 2012-02-21 02:23:08 +0000 | [diff] [blame] | 237 | |
| 238 | { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 239 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 240 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 241 | SBDebugger debugger; |
Greg Clayton | cb172b1 | 2014-05-19 20:42:14 +0000 | [diff] [blame] | 242 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 243 | // Currently we have issues if this function is called simultaneously on two |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 244 | // different threads. The issues mainly revolve around the fact that the |
| 245 | // lldb_private::FormatManager uses global collections and having two threads |
| 246 | // parsing the .lldbinit files can cause mayhem. So to get around this for |
| 247 | // now we need to use a mutex to prevent bad things from happening. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 248 | static std::recursive_mutex g_mutex; |
| 249 | std::lock_guard<std::recursive_mutex> guard(g_mutex); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 250 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 251 | debugger.reset(Debugger::CreateInstance(callback, baton)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 252 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 253 | if (log) { |
| 254 | SBStream sstr; |
| 255 | debugger.GetDescription(sstr); |
| 256 | log->Printf("SBDebugger::Create () => SBDebugger(%p): %s", |
| 257 | static_cast<void *>(debugger.m_opaque_sp.get()), |
| 258 | sstr.GetData()); |
| 259 | } |
| 260 | |
| 261 | SBCommandInterpreter interp = debugger.GetCommandInterpreter(); |
| 262 | if (source_init_files) { |
| 263 | interp.get()->SkipLLDBInitFiles(false); |
| 264 | interp.get()->SkipAppInitFiles(false); |
| 265 | SBCommandReturnObject result; |
| 266 | interp.SourceInitFileInHomeDirectory(result); |
| 267 | } else { |
| 268 | interp.get()->SkipLLDBInitFiles(true); |
| 269 | interp.get()->SkipAppInitFiles(true); |
| 270 | } |
| 271 | return debugger; |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 274 | void SBDebugger::Destroy(SBDebugger &debugger) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 275 | LLDB_RECORD_STATIC_METHOD(void, SBDebugger, Destroy, (lldb::SBDebugger &), |
| 276 | debugger); |
| 277 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 278 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 279 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 280 | if (log) { |
| 281 | SBStream sstr; |
| 282 | debugger.GetDescription(sstr); |
| 283 | log->Printf("SBDebugger::Destroy () => SBDebugger(%p): %s", |
| 284 | static_cast<void *>(debugger.m_opaque_sp.get()), |
| 285 | sstr.GetData()); |
| 286 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 287 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 288 | Debugger::Destroy(debugger.m_opaque_sp); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 289 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 290 | if (debugger.m_opaque_sp.get() != nullptr) |
| 291 | debugger.m_opaque_sp.reset(); |
Caroline Tice | e02657b | 2011-01-22 01:02:07 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 294 | void SBDebugger::MemoryPressureDetected() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 295 | LLDB_RECORD_STATIC_METHOD_NO_ARGS(void, SBDebugger, MemoryPressureDetected); |
| 296 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 297 | // Since this function can be call asynchronously, we allow it to be non- |
| 298 | // mandatory. We have seen deadlocks with this function when called so we |
| 299 | // need to safeguard against this until we can determine what is causing the |
| 300 | // deadlocks. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 301 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 302 | |
| 303 | const bool mandatory = false; |
| 304 | if (log) { |
| 305 | log->Printf("SBDebugger::MemoryPressureDetected (), mandatory = %d", |
| 306 | mandatory); |
| 307 | } |
| 308 | |
| 309 | ModuleList::RemoveOrphanSharedModules(mandatory); |
Greg Clayton | f932241 | 2011-12-15 04:38:41 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 312 | bool SBDebugger::IsValid() const { |
| 313 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, IsValid); |
| 314 | |
| 315 | return m_opaque_sp.get() != nullptr; |
| 316 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 317 | |
| 318 | void SBDebugger::SetAsync(bool b) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 319 | LLDB_RECORD_METHOD(void, SBDebugger, SetAsync, (bool), b); |
| 320 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 321 | if (m_opaque_sp) |
| 322 | m_opaque_sp->SetAsyncExecution(b); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 325 | bool SBDebugger::GetAsync() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 326 | LLDB_RECORD_METHOD_NO_ARGS(bool, SBDebugger, GetAsync); |
| 327 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 328 | return (m_opaque_sp ? m_opaque_sp->GetAsyncExecution() : false); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 331 | void SBDebugger::SkipLLDBInitFiles(bool b) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 332 | LLDB_RECORD_METHOD(void, SBDebugger, SkipLLDBInitFiles, (bool), b); |
| 333 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 334 | if (m_opaque_sp) |
| 335 | m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles(b); |
Jim Ingham | e64f0dc | 2011-09-13 23:25:31 +0000 | [diff] [blame] | 336 | } |
| 337 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 338 | void SBDebugger::SkipAppInitFiles(bool b) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 339 | LLDB_RECORD_METHOD(void, SBDebugger, SkipAppInitFiles, (bool), b); |
| 340 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 341 | if (m_opaque_sp) |
| 342 | m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles(b); |
Greg Clayton | 6eee5aa | 2010-10-11 01:05:37 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Adrian Prantl | 0509724 | 2018-04-30 16:49:04 +0000 | [diff] [blame] | 345 | // Shouldn't really be settable after initialization as this could cause lots |
| 346 | // of problems; don't want users trying to switch modes in the middle of a |
| 347 | // debugging session. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 348 | void SBDebugger::SetInputFileHandle(FILE *fh, bool transfer_ownership) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 349 | LLDB_RECORD_METHOD(void, SBDebugger, SetInputFileHandle, (FILE *, bool), fh, |
| 350 | transfer_ownership); |
| 351 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 352 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 353 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 354 | if (log) |
| 355 | log->Printf( |
| 356 | "SBDebugger(%p)::SetInputFileHandle (fh=%p, transfer_ownership=%i)", |
| 357 | static_cast<void *>(m_opaque_sp.get()), static_cast<void *>(fh), |
| 358 | transfer_ownership); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 359 | |
Jonas Devlieghere | d77c2e0 | 2019-03-02 00:20:26 +0000 | [diff] [blame] | 360 | if (!m_opaque_sp) |
| 361 | return; |
| 362 | |
| 363 | repro::DataRecorder *recorder = nullptr; |
| 364 | if (repro::Generator *g = repro::Reproducer::Instance().GetGenerator()) |
| 365 | recorder = g->GetOrCreate<repro::CommandProvider>().GetNewDataRecorder(); |
| 366 | |
| 367 | static std::unique_ptr<CommandLoader> loader = CommandLoader::Create(); |
| 368 | if (loader) |
| 369 | fh = loader->GetNextFile(); |
| 370 | |
| 371 | m_opaque_sp->SetInputFileHandle(fh, transfer_ownership, recorder); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 372 | } |
| 373 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 374 | void SBDebugger::SetOutputFileHandle(FILE *fh, bool transfer_ownership) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 375 | LLDB_RECORD_METHOD(void, SBDebugger, SetOutputFileHandle, (FILE *, bool), fh, |
| 376 | transfer_ownership); |
| 377 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 378 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 379 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 380 | if (log) |
| 381 | log->Printf( |
| 382 | "SBDebugger(%p)::SetOutputFileHandle (fh=%p, transfer_ownership=%i)", |
| 383 | static_cast<void *>(m_opaque_sp.get()), static_cast<void *>(fh), |
| 384 | transfer_ownership); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 385 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 386 | if (m_opaque_sp) |
| 387 | m_opaque_sp->SetOutputFileHandle(fh, transfer_ownership); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 390 | void SBDebugger::SetErrorFileHandle(FILE *fh, bool transfer_ownership) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 391 | LLDB_RECORD_METHOD(void, SBDebugger, SetErrorFileHandle, (FILE *, bool), fh, |
| 392 | transfer_ownership); |
| 393 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 394 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 395 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 396 | if (log) |
| 397 | log->Printf( |
| 398 | "SBDebugger(%p)::SetErrorFileHandle (fh=%p, transfer_ownership=%i)", |
| 399 | static_cast<void *>(m_opaque_sp.get()), static_cast<void *>(fh), |
| 400 | transfer_ownership); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 401 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 402 | if (m_opaque_sp) |
| 403 | m_opaque_sp->SetErrorFileHandle(fh, transfer_ownership); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 406 | FILE *SBDebugger::GetInputFileHandle() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 407 | LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetInputFileHandle); |
| 408 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 409 | if (m_opaque_sp) { |
| 410 | StreamFileSP stream_file_sp(m_opaque_sp->GetInputFile()); |
| 411 | if (stream_file_sp) |
| 412 | return stream_file_sp->GetFile().GetStream(); |
| 413 | } |
| 414 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 417 | FILE *SBDebugger::GetOutputFileHandle() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 418 | LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetOutputFileHandle); |
| 419 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 420 | if (m_opaque_sp) { |
| 421 | StreamFileSP stream_file_sp(m_opaque_sp->GetOutputFile()); |
| 422 | if (stream_file_sp) |
| 423 | return stream_file_sp->GetFile().GetStream(); |
| 424 | } |
| 425 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 428 | FILE *SBDebugger::GetErrorFileHandle() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 429 | LLDB_RECORD_METHOD_NO_ARGS(FILE *, SBDebugger, GetErrorFileHandle); |
| 430 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 431 | if (m_opaque_sp) { |
| 432 | StreamFileSP stream_file_sp(m_opaque_sp->GetErrorFile()); |
| 433 | if (stream_file_sp) |
| 434 | return stream_file_sp->GetFile().GetStream(); |
| 435 | } |
| 436 | return nullptr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 439 | void SBDebugger::SaveInputTerminalState() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 440 | LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, SaveInputTerminalState); |
| 441 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 442 | if (m_opaque_sp) |
| 443 | m_opaque_sp->SaveInputTerminalState(); |
Jim Ingham | c5917d9 | 2012-11-30 20:23:19 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 446 | void SBDebugger::RestoreInputTerminalState() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 447 | LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, RestoreInputTerminalState); |
| 448 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 449 | if (m_opaque_sp) |
| 450 | m_opaque_sp->RestoreInputTerminalState(); |
Jim Ingham | c5917d9 | 2012-11-30 20:23:19 +0000 | [diff] [blame] | 451 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 452 | SBCommandInterpreter SBDebugger::GetCommandInterpreter() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 453 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBCommandInterpreter, SBDebugger, |
| 454 | GetCommandInterpreter); |
| 455 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 456 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 457 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 458 | SBCommandInterpreter sb_interpreter; |
| 459 | if (m_opaque_sp) |
| 460 | sb_interpreter.reset(&m_opaque_sp->GetCommandInterpreter()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 461 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 462 | if (log) |
| 463 | log->Printf( |
| 464 | "SBDebugger(%p)::GetCommandInterpreter () => SBCommandInterpreter(%p)", |
| 465 | static_cast<void *>(m_opaque_sp.get()), |
| 466 | static_cast<void *>(sb_interpreter.get())); |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 467 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 468 | return LLDB_RECORD_RESULT(sb_interpreter); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 471 | void SBDebugger::HandleCommand(const char *command) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 472 | LLDB_RECORD_METHOD(void, SBDebugger, HandleCommand, (const char *), command); |
| 473 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 474 | if (m_opaque_sp) { |
| 475 | TargetSP target_sp(m_opaque_sp->GetSelectedTarget()); |
| 476 | std::unique_lock<std::recursive_mutex> lock; |
| 477 | if (target_sp) |
| 478 | lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 479 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 480 | SBCommandInterpreter sb_interpreter(GetCommandInterpreter()); |
| 481 | SBCommandReturnObject result; |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 482 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 483 | sb_interpreter.HandleCommand(command, result, false); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 484 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 485 | if (GetErrorFileHandle() != nullptr) |
| 486 | result.PutError(GetErrorFileHandle()); |
| 487 | if (GetOutputFileHandle() != nullptr) |
| 488 | result.PutOutput(GetOutputFileHandle()); |
Greg Clayton | 6611103 | 2010-06-23 01:19:29 +0000 | [diff] [blame] | 489 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 490 | if (!m_opaque_sp->GetAsyncExecution()) { |
| 491 | SBProcess process(GetCommandInterpreter().GetProcess()); |
| 492 | ProcessSP process_sp(process.GetSP()); |
| 493 | if (process_sp) { |
| 494 | EventSP event_sp; |
| 495 | ListenerSP lldb_listener_sp = m_opaque_sp->GetListener(); |
Pavel Labath | d35031e1 | 2016-11-30 10:41:42 +0000 | [diff] [blame] | 496 | while (lldb_listener_sp->GetEventForBroadcaster( |
| 497 | process_sp.get(), event_sp, std::chrono::seconds(0))) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 498 | SBEvent event(event_sp); |
| 499 | HandleProcessEvent(process, event, GetOutputFileHandle(), |
| 500 | GetErrorFileHandle()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 501 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 502 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 503 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 504 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 507 | SBListener SBDebugger::GetListener() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 508 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBListener, SBDebugger, GetListener); |
| 509 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 510 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 511 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 512 | SBListener sb_listener; |
| 513 | if (m_opaque_sp) |
| 514 | sb_listener.reset(m_opaque_sp->GetListener()); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 515 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 516 | if (log) |
| 517 | log->Printf("SBDebugger(%p)::GetListener () => SBListener(%p)", |
| 518 | static_cast<void *>(m_opaque_sp.get()), |
| 519 | static_cast<void *>(sb_listener.get())); |
Caroline Tice | 750cd17 | 2010-10-26 23:49:36 +0000 | [diff] [blame] | 520 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 521 | return LLDB_RECORD_RESULT(sb_listener); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 522 | } |
| 523 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 524 | void SBDebugger::HandleProcessEvent(const SBProcess &process, |
| 525 | const SBEvent &event, FILE *out, |
| 526 | FILE *err) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 527 | LLDB_RECORD_METHOD( |
| 528 | void, SBDebugger, HandleProcessEvent, |
| 529 | (const lldb::SBProcess &, const lldb::SBEvent &, FILE *, FILE *), process, |
| 530 | event, out, err); |
| 531 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 532 | if (!process.IsValid()) |
| 533 | return; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 534 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 535 | TargetSP target_sp(process.GetTarget().GetSP()); |
| 536 | if (!target_sp) |
| 537 | return; |
Greg Clayton | b9556ac | 2012-01-30 07:41:31 +0000 | [diff] [blame] | 538 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 539 | const uint32_t event_type = event.GetType(); |
| 540 | char stdio_buffer[1024]; |
| 541 | size_t len; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 542 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 543 | std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 544 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 545 | if (event_type & |
| 546 | (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged)) { |
| 547 | // Drain stdout when we stop just in case we have any bytes |
| 548 | while ((len = process.GetSTDOUT(stdio_buffer, sizeof(stdio_buffer))) > 0) |
| 549 | if (out != nullptr) |
| 550 | ::fwrite(stdio_buffer, 1, len, out); |
| 551 | } |
Todd Fiala | 7593001 | 2016-08-19 04:21:48 +0000 | [diff] [blame] | 552 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 553 | if (event_type & |
| 554 | (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged)) { |
| 555 | // Drain stderr when we stop just in case we have any bytes |
| 556 | while ((len = process.GetSTDERR(stdio_buffer, sizeof(stdio_buffer))) > 0) |
| 557 | if (err != nullptr) |
| 558 | ::fwrite(stdio_buffer, 1, len, err); |
| 559 | } |
| 560 | |
| 561 | if (event_type & Process::eBroadcastBitStateChanged) { |
| 562 | StateType event_state = SBProcess::GetStateFromEvent(event); |
| 563 | |
| 564 | if (event_state == eStateInvalid) |
| 565 | return; |
| 566 | |
| 567 | bool is_stopped = StateIsStoppedState(event_state); |
| 568 | if (!is_stopped) |
| 569 | process.ReportEventState(event, out); |
| 570 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 571 | } |
| 572 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 573 | SBSourceManager SBDebugger::GetSourceManager() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 574 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSourceManager, SBDebugger, |
| 575 | GetSourceManager); |
| 576 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 577 | SBSourceManager sb_source_manager(*this); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 578 | return LLDB_RECORD_RESULT(sb_source_manager); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 579 | } |
| 580 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 581 | bool SBDebugger::GetDefaultArchitecture(char *arch_name, size_t arch_name_len) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 582 | LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, GetDefaultArchitecture, |
| 583 | (char *, size_t), "", arch_name_len); |
| 584 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 585 | if (arch_name && arch_name_len) { |
| 586 | ArchSpec default_arch = Target::GetDefaultArchitecture(); |
Caroline Tice | daccaa9 | 2010-09-20 20:44:43 +0000 | [diff] [blame] | 587 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 588 | if (default_arch.IsValid()) { |
| 589 | const std::string &triple_str = default_arch.GetTriple().str(); |
| 590 | if (!triple_str.empty()) |
| 591 | ::snprintf(arch_name, arch_name_len, "%s", triple_str.c_str()); |
| 592 | else |
| 593 | ::snprintf(arch_name, arch_name_len, "%s", |
| 594 | default_arch.GetArchitectureName()); |
| 595 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 596 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 597 | } |
| 598 | if (arch_name && arch_name_len) |
| 599 | arch_name[0] = '\0'; |
| 600 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 601 | } |
| 602 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 603 | bool SBDebugger::SetDefaultArchitecture(const char *arch_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 604 | LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, SetDefaultArchitecture, |
| 605 | (const char *), arch_name); |
| 606 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 607 | if (arch_name) { |
| 608 | ArchSpec arch(arch_name); |
| 609 | if (arch.IsValid()) { |
| 610 | Target::SetDefaultArchitecture(arch); |
| 611 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 612 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 613 | } |
| 614 | return false; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | ScriptLanguage |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 618 | SBDebugger::GetScriptingLanguage(const char *script_language_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 619 | LLDB_RECORD_METHOD(lldb::ScriptLanguage, SBDebugger, GetScriptingLanguage, |
| 620 | (const char *), script_language_name); |
| 621 | |
Zachary Turner | 7b2e5a3 | 2016-09-16 19:09:12 +0000 | [diff] [blame] | 622 | if (!script_language_name) return eScriptLanguageDefault; |
Pavel Labath | 47cbf4a | 2018-04-10 09:03:59 +0000 | [diff] [blame] | 623 | return OptionArgParser::ToScriptLanguage( |
| 624 | llvm::StringRef(script_language_name), eScriptLanguageDefault, nullptr); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 625 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 626 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 627 | const char *SBDebugger::GetVersionString() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 628 | LLDB_RECORD_STATIC_METHOD_NO_ARGS(const char *, SBDebugger, GetVersionString); |
| 629 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 630 | return lldb_private::GetVersion(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 633 | const char *SBDebugger::StateAsCString(StateType state) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 634 | LLDB_RECORD_STATIC_METHOD(const char *, SBDebugger, StateAsCString, |
| 635 | (lldb::StateType), state); |
| 636 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 637 | return lldb_private::StateAsCString(state); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Pavel Labath | f1389e9 | 2018-02-19 15:06:28 +0000 | [diff] [blame] | 640 | static void AddBoolConfigEntry(StructuredData::Dictionary &dict, |
| 641 | llvm::StringRef name, bool value, |
| 642 | llvm::StringRef description) { |
| 643 | auto entry_up = llvm::make_unique<StructuredData::Dictionary>(); |
| 644 | entry_up->AddBooleanItem("value", value); |
| 645 | entry_up->AddStringItem("description", description); |
| 646 | dict.AddItem(name, std::move(entry_up)); |
| 647 | } |
| 648 | |
Pavel Labath | abc0c6a | 2018-06-28 14:23:04 +0000 | [diff] [blame] | 649 | static void AddLLVMTargets(StructuredData::Dictionary &dict) { |
| 650 | auto array_up = llvm::make_unique<StructuredData::Array>(); |
| 651 | #define LLVM_TARGET(target) \ |
| 652 | array_up->AddItem(llvm::make_unique<StructuredData::String>(#target)); |
| 653 | #include "llvm/Config/Targets.def" |
| 654 | auto entry_up = llvm::make_unique<StructuredData::Dictionary>(); |
| 655 | entry_up->AddItem("value", std::move(array_up)); |
| 656 | entry_up->AddStringItem("description", "A list of configured LLVM targets."); |
| 657 | dict.AddItem("targets", std::move(entry_up)); |
| 658 | } |
| 659 | |
Pavel Labath | f1389e9 | 2018-02-19 15:06:28 +0000 | [diff] [blame] | 660 | SBStructuredData SBDebugger::GetBuildConfiguration() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 661 | LLDB_RECORD_STATIC_METHOD_NO_ARGS(lldb::SBStructuredData, SBDebugger, |
| 662 | GetBuildConfiguration); |
| 663 | |
Pavel Labath | f1389e9 | 2018-02-19 15:06:28 +0000 | [diff] [blame] | 664 | auto config_up = llvm::make_unique<StructuredData::Dictionary>(); |
| 665 | AddBoolConfigEntry( |
| 666 | *config_up, "xml", XMLDocument::XMLEnabled(), |
| 667 | "A boolean value that indicates if XML support is enabled in LLDB"); |
Pavel Labath | abc0c6a | 2018-06-28 14:23:04 +0000 | [diff] [blame] | 668 | AddLLVMTargets(*config_up); |
Pavel Labath | f1389e9 | 2018-02-19 15:06:28 +0000 | [diff] [blame] | 669 | |
| 670 | SBStructuredData data; |
| 671 | data.m_impl_up->SetObjectSP(std::move(config_up)); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 672 | return LLDB_RECORD_RESULT(data); |
Pavel Labath | f1389e9 | 2018-02-19 15:06:28 +0000 | [diff] [blame] | 673 | } |
| 674 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 675 | bool SBDebugger::StateIsRunningState(StateType state) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 676 | LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, StateIsRunningState, |
| 677 | (lldb::StateType), state); |
| 678 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 679 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 680 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 681 | const bool result = lldb_private::StateIsRunningState(state); |
| 682 | if (log) |
| 683 | log->Printf("SBDebugger::StateIsRunningState (state=%s) => %i", |
| 684 | StateAsCString(state), result); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 685 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 686 | return result; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 687 | } |
| 688 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 689 | bool SBDebugger::StateIsStoppedState(StateType state) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 690 | LLDB_RECORD_STATIC_METHOD(bool, SBDebugger, StateIsStoppedState, |
| 691 | (lldb::StateType), state); |
| 692 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 693 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 694 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 695 | const bool result = lldb_private::StateIsStoppedState(state, false); |
| 696 | if (log) |
| 697 | log->Printf("SBDebugger::StateIsStoppedState (state=%s) => %i", |
| 698 | StateAsCString(state), result); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 699 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 700 | return result; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 703 | lldb::SBTarget SBDebugger::CreateTarget(const char *filename, |
| 704 | const char *target_triple, |
| 705 | const char *platform_name, |
| 706 | bool add_dependent_modules, |
| 707 | lldb::SBError &sb_error) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 708 | LLDB_RECORD_METHOD( |
| 709 | lldb::SBTarget, SBDebugger, CreateTarget, |
| 710 | (const char *, const char *, const char *, bool, lldb::SBError &), |
| 711 | filename, target_triple, platform_name, add_dependent_modules, sb_error); |
| 712 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 713 | SBTarget sb_target; |
| 714 | TargetSP target_sp; |
| 715 | if (m_opaque_sp) { |
| 716 | sb_error.Clear(); |
| 717 | OptionGroupPlatform platform_options(false); |
| 718 | platform_options.SetPlatformName(platform_name); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 719 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 720 | sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget( |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 721 | *m_opaque_sp, filename, target_triple, |
| 722 | add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 723 | &platform_options, target_sp); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 724 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 725 | if (sb_error.Success()) |
| 726 | sb_target.SetSP(target_sp); |
| 727 | } else { |
| 728 | sb_error.SetErrorString("invalid debugger"); |
| 729 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 730 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 731 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 732 | if (log) |
| 733 | log->Printf("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, " |
| 734 | "platform_name=%s, add_dependent_modules=%u, error=%s) => " |
| 735 | "SBTarget(%p)", |
| 736 | static_cast<void *>(m_opaque_sp.get()), filename, target_triple, |
| 737 | platform_name, add_dependent_modules, sb_error.GetCString(), |
| 738 | static_cast<void *>(target_sp.get())); |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 739 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 740 | return LLDB_RECORD_RESULT(sb_target); |
Greg Clayton | cac9c5f | 2011-09-24 00:52:29 +0000 | [diff] [blame] | 741 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 742 | |
| 743 | SBTarget |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 744 | SBDebugger::CreateTargetWithFileAndTargetTriple(const char *filename, |
| 745 | const char *target_triple) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 746 | LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, |
| 747 | CreateTargetWithFileAndTargetTriple, |
| 748 | (const char *, const char *), filename, target_triple); |
| 749 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 750 | SBTarget sb_target; |
| 751 | TargetSP target_sp; |
| 752 | if (m_opaque_sp) { |
| 753 | const bool add_dependent_modules = true; |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 754 | Status error(m_opaque_sp->GetTargetList().CreateTarget( |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 755 | *m_opaque_sp, filename, target_triple, |
| 756 | add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 757 | target_sp)); |
| 758 | sb_target.SetSP(target_sp); |
| 759 | } |
Saleem Abdulrasool | 324a103 | 2014-04-04 04:06:10 +0000 | [diff] [blame] | 760 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 761 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 762 | if (log) |
| 763 | log->Printf("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple " |
| 764 | "(filename=\"%s\", triple=%s) => SBTarget(%p)", |
| 765 | static_cast<void *>(m_opaque_sp.get()), filename, target_triple, |
| 766 | static_cast<void *>(target_sp.get())); |
Greg Clayton | 4838131 | 2010-10-30 04:51:46 +0000 | [diff] [blame] | 767 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 768 | return LLDB_RECORD_RESULT(sb_target); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 771 | SBTarget SBDebugger::CreateTargetWithFileAndArch(const char *filename, |
| 772 | const char *arch_cstr) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 773 | LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, CreateTargetWithFileAndArch, |
| 774 | (const char *, const char *), filename, arch_cstr); |
| 775 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 776 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
Caroline Tice | ceb6b13 | 2010-10-26 03:11:13 +0000 | [diff] [blame] | 777 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 778 | SBTarget sb_target; |
| 779 | TargetSP target_sp; |
| 780 | if (m_opaque_sp) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 781 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 782 | const bool add_dependent_modules = true; |
| 783 | |
| 784 | error = m_opaque_sp->GetTargetList().CreateTarget( |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 785 | *m_opaque_sp, filename, arch_cstr, |
| 786 | add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 787 | target_sp); |
| 788 | |
| 789 | if (error.Success()) { |
| 790 | m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get()); |
| 791 | sb_target.SetSP(target_sp); |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 792 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | if (log) |
| 796 | log->Printf("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", " |
| 797 | "arch=%s) => SBTarget(%p)", |
| 798 | static_cast<void *>(m_opaque_sp.get()), filename, arch_cstr, |
| 799 | static_cast<void *>(target_sp.get())); |
| 800 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 801 | return LLDB_RECORD_RESULT(sb_target); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | SBTarget SBDebugger::CreateTarget(const char *filename) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 805 | LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, CreateTarget, (const char *), |
| 806 | filename); |
| 807 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 808 | SBTarget sb_target; |
| 809 | TargetSP target_sp; |
| 810 | if (m_opaque_sp) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 811 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 812 | const bool add_dependent_modules = true; |
| 813 | error = m_opaque_sp->GetTargetList().CreateTarget( |
Jonas Devlieghere | f9a07e9 | 2018-09-20 09:09:05 +0000 | [diff] [blame] | 814 | *m_opaque_sp, filename, "", |
| 815 | add_dependent_modules ? eLoadDependentsYes : eLoadDependentsNo, nullptr, |
| 816 | target_sp); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 817 | |
| 818 | if (error.Success()) { |
| 819 | m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get()); |
| 820 | sb_target.SetSP(target_sp); |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 821 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 822 | } |
| 823 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 824 | if (log) |
| 825 | log->Printf( |
| 826 | "SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)", |
| 827 | static_cast<void *>(m_opaque_sp.get()), filename, |
| 828 | static_cast<void *>(target_sp.get())); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 829 | return LLDB_RECORD_RESULT(sb_target); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 830 | } |
| 831 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 832 | SBTarget SBDebugger::GetDummyTarget() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 833 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTarget, SBDebugger, GetDummyTarget); |
| 834 | |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 835 | SBTarget sb_target; |
| 836 | if (m_opaque_sp) { |
| 837 | sb_target.SetSP(m_opaque_sp->GetDummyTarget()->shared_from_this()); |
| 838 | } |
| 839 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 840 | if (log) |
| 841 | log->Printf( |
| 842 | "SBDebugger(%p)::GetDummyTarget() => SBTarget(%p)", |
| 843 | static_cast<void *>(m_opaque_sp.get()), |
| 844 | static_cast<void *>(sb_target.GetSP().get())); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 845 | return LLDB_RECORD_RESULT(sb_target); |
Jim Ingham | b842f2e | 2017-09-14 20:22:49 +0000 | [diff] [blame] | 846 | } |
| 847 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 848 | bool SBDebugger::DeleteTarget(lldb::SBTarget &target) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 849 | LLDB_RECORD_METHOD(bool, SBDebugger, DeleteTarget, (lldb::SBTarget &), |
| 850 | target); |
| 851 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 852 | bool result = false; |
| 853 | if (m_opaque_sp) { |
| 854 | TargetSP target_sp(target.GetSP()); |
| 855 | if (target_sp) { |
| 856 | // No need to lock, the target list is thread safe |
| 857 | result = m_opaque_sp->GetTargetList().DeleteTarget(target_sp); |
| 858 | target_sp->Destroy(); |
| 859 | target.Clear(); |
| 860 | const bool mandatory = true; |
| 861 | ModuleList::RemoveOrphanSharedModules(mandatory); |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 866 | if (log) |
| 867 | log->Printf("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i", |
| 868 | static_cast<void *>(m_opaque_sp.get()), |
| 869 | static_cast<void *>(target.m_opaque_sp.get()), result); |
| 870 | |
| 871 | return result; |
| 872 | } |
| 873 | |
| 874 | SBTarget SBDebugger::GetTargetAtIndex(uint32_t idx) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 875 | LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, GetTargetAtIndex, (uint32_t), |
| 876 | idx); |
| 877 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 878 | SBTarget sb_target; |
| 879 | if (m_opaque_sp) { |
| 880 | // No need to lock, the target list is thread safe |
| 881 | sb_target.SetSP(m_opaque_sp->GetTargetList().GetTargetAtIndex(idx)); |
| 882 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 883 | return LLDB_RECORD_RESULT(sb_target); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | uint32_t SBDebugger::GetIndexOfTarget(lldb::SBTarget target) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 887 | LLDB_RECORD_METHOD(uint32_t, SBDebugger, GetIndexOfTarget, (lldb::SBTarget), |
| 888 | target); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 889 | |
| 890 | lldb::TargetSP target_sp = target.GetSP(); |
| 891 | if (!target_sp) |
| 892 | return UINT32_MAX; |
| 893 | |
| 894 | if (!m_opaque_sp) |
| 895 | return UINT32_MAX; |
| 896 | |
| 897 | return m_opaque_sp->GetTargetList().GetIndexOfTarget(target.GetSP()); |
| 898 | } |
| 899 | |
| 900 | SBTarget SBDebugger::FindTargetWithProcessID(lldb::pid_t pid) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 901 | LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithProcessID, |
| 902 | (lldb::pid_t), pid); |
| 903 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 904 | SBTarget sb_target; |
| 905 | if (m_opaque_sp) { |
| 906 | // No need to lock, the target list is thread safe |
| 907 | sb_target.SetSP(m_opaque_sp->GetTargetList().FindTargetWithProcessID(pid)); |
| 908 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 909 | return LLDB_RECORD_RESULT(sb_target); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | SBTarget SBDebugger::FindTargetWithFileAndArch(const char *filename, |
| 913 | const char *arch_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 914 | LLDB_RECORD_METHOD(lldb::SBTarget, SBDebugger, FindTargetWithFileAndArch, |
| 915 | (const char *, const char *), filename, arch_name); |
| 916 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 917 | SBTarget sb_target; |
| 918 | if (m_opaque_sp && filename && filename[0]) { |
| 919 | // No need to lock, the target list is thread safe |
Pavel Labath | 7263f1b | 2017-10-31 10:56:03 +0000 | [diff] [blame] | 920 | ArchSpec arch = Platform::GetAugmentedArchSpec( |
| 921 | m_opaque_sp->GetPlatformList().GetSelectedPlatform().get(), arch_name); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 922 | TargetSP target_sp( |
| 923 | m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture( |
Jonas Devlieghere | 8f3be7a | 2018-11-01 21:05:36 +0000 | [diff] [blame] | 924 | FileSpec(filename), arch_name ? &arch : nullptr)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 925 | sb_target.SetSP(target_sp); |
| 926 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 927 | return LLDB_RECORD_RESULT(sb_target); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | SBTarget SBDebugger::FindTargetWithLLDBProcess(const ProcessSP &process_sp) { |
| 931 | SBTarget sb_target; |
| 932 | if (m_opaque_sp) { |
| 933 | // No need to lock, the target list is thread safe |
| 934 | sb_target.SetSP( |
| 935 | m_opaque_sp->GetTargetList().FindTargetWithProcess(process_sp.get())); |
| 936 | } |
| 937 | return sb_target; |
| 938 | } |
| 939 | |
| 940 | uint32_t SBDebugger::GetNumTargets() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 941 | LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumTargets); |
| 942 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 943 | if (m_opaque_sp) { |
| 944 | // No need to lock, the target list is thread safe |
| 945 | return m_opaque_sp->GetTargetList().GetNumTargets(); |
| 946 | } |
| 947 | return 0; |
| 948 | } |
| 949 | |
| 950 | SBTarget SBDebugger::GetSelectedTarget() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 951 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTarget, SBDebugger, GetSelectedTarget); |
| 952 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 953 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 954 | |
| 955 | SBTarget sb_target; |
| 956 | TargetSP target_sp; |
| 957 | if (m_opaque_sp) { |
| 958 | // No need to lock, the target list is thread safe |
| 959 | target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget(); |
| 960 | sb_target.SetSP(target_sp); |
| 961 | } |
| 962 | |
| 963 | if (log) { |
| 964 | SBStream sstr; |
| 965 | sb_target.GetDescription(sstr, eDescriptionLevelBrief); |
| 966 | log->Printf("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s", |
| 967 | static_cast<void *>(m_opaque_sp.get()), |
| 968 | static_cast<void *>(target_sp.get()), sstr.GetData()); |
| 969 | } |
| 970 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 971 | return LLDB_RECORD_RESULT(sb_target); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | void SBDebugger::SetSelectedTarget(SBTarget &sb_target) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 975 | LLDB_RECORD_METHOD(void, SBDebugger, SetSelectedTarget, (lldb::SBTarget &), |
| 976 | sb_target); |
| 977 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 978 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 979 | |
| 980 | TargetSP target_sp(sb_target.GetSP()); |
| 981 | if (m_opaque_sp) { |
| 982 | m_opaque_sp->GetTargetList().SetSelectedTarget(target_sp.get()); |
| 983 | } |
| 984 | if (log) { |
| 985 | SBStream sstr; |
| 986 | sb_target.GetDescription(sstr, eDescriptionLevelBrief); |
| 987 | log->Printf("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s", |
| 988 | static_cast<void *>(m_opaque_sp.get()), |
| 989 | static_cast<void *>(target_sp.get()), sstr.GetData()); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | SBPlatform SBDebugger::GetSelectedPlatform() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 994 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBPlatform, SBDebugger, GetSelectedPlatform); |
| 995 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 996 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 997 | |
| 998 | SBPlatform sb_platform; |
| 999 | DebuggerSP debugger_sp(m_opaque_sp); |
| 1000 | if (debugger_sp) { |
| 1001 | sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform()); |
| 1002 | } |
| 1003 | if (log) |
| 1004 | log->Printf("SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s", |
| 1005 | static_cast<void *>(m_opaque_sp.get()), |
| 1006 | static_cast<void *>(sb_platform.GetSP().get()), |
| 1007 | sb_platform.GetName()); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1008 | return LLDB_RECORD_RESULT(sb_platform); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | void SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1012 | LLDB_RECORD_METHOD(void, SBDebugger, SetSelectedPlatform, |
| 1013 | (lldb::SBPlatform &), sb_platform); |
| 1014 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1015 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1016 | |
| 1017 | DebuggerSP debugger_sp(m_opaque_sp); |
| 1018 | if (debugger_sp) { |
| 1019 | debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP()); |
| 1020 | } |
| 1021 | |
| 1022 | if (log) |
| 1023 | log->Printf("SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)", |
| 1024 | static_cast<void *>(m_opaque_sp.get()), |
| 1025 | static_cast<void *>(sb_platform.GetSP().get()), |
| 1026 | sb_platform.GetName()); |
| 1027 | } |
| 1028 | |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 1029 | uint32_t SBDebugger::GetNumPlatforms() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1030 | LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumPlatforms); |
| 1031 | |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 1032 | if (m_opaque_sp) { |
| 1033 | // No need to lock, the platform list is thread safe |
| 1034 | return m_opaque_sp->GetPlatformList().GetSize(); |
| 1035 | } |
| 1036 | return 0; |
| 1037 | } |
| 1038 | |
| 1039 | SBPlatform SBDebugger::GetPlatformAtIndex(uint32_t idx) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1040 | LLDB_RECORD_METHOD(lldb::SBPlatform, SBDebugger, GetPlatformAtIndex, |
| 1041 | (uint32_t), idx); |
| 1042 | |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 1043 | SBPlatform sb_platform; |
| 1044 | if (m_opaque_sp) { |
| 1045 | // No need to lock, the platform list is thread safe |
| 1046 | sb_platform.SetSP(m_opaque_sp->GetPlatformList().GetAtIndex(idx)); |
| 1047 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1048 | return LLDB_RECORD_RESULT(sb_platform); |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | uint32_t SBDebugger::GetNumAvailablePlatforms() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1052 | LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumAvailablePlatforms); |
| 1053 | |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 1054 | uint32_t idx = 0; |
| 1055 | while (true) { |
| 1056 | if (!PluginManager::GetPlatformPluginNameAtIndex(idx)) { |
| 1057 | break; |
| 1058 | } |
| 1059 | ++idx; |
| 1060 | } |
| 1061 | // +1 for the host platform, which should always appear first in the list. |
| 1062 | return idx + 1; |
| 1063 | } |
| 1064 | |
| 1065 | SBStructuredData SBDebugger::GetAvailablePlatformInfoAtIndex(uint32_t idx) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1066 | LLDB_RECORD_METHOD(lldb::SBStructuredData, SBDebugger, |
| 1067 | GetAvailablePlatformInfoAtIndex, (uint32_t), idx); |
| 1068 | |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 1069 | SBStructuredData data; |
| 1070 | auto platform_dict = llvm::make_unique<StructuredData::Dictionary>(); |
| 1071 | llvm::StringRef name_str("name"), desc_str("description"); |
| 1072 | |
| 1073 | if (idx == 0) { |
| 1074 | PlatformSP host_platform_sp(Platform::GetHostPlatform()); |
| 1075 | platform_dict->AddStringItem( |
| 1076 | name_str, host_platform_sp->GetPluginName().GetStringRef()); |
| 1077 | platform_dict->AddStringItem( |
| 1078 | desc_str, llvm::StringRef(host_platform_sp->GetDescription())); |
| 1079 | } else if (idx > 0) { |
| 1080 | const char *plugin_name = |
| 1081 | PluginManager::GetPlatformPluginNameAtIndex(idx - 1); |
| 1082 | if (!plugin_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1083 | return LLDB_RECORD_RESULT(data); |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 1084 | } |
| 1085 | platform_dict->AddStringItem(name_str, llvm::StringRef(plugin_name)); |
| 1086 | |
| 1087 | const char *plugin_desc = |
| 1088 | PluginManager::GetPlatformPluginDescriptionAtIndex(idx - 1); |
| 1089 | if (!plugin_desc) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1090 | return LLDB_RECORD_RESULT(data); |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 1091 | } |
| 1092 | platform_dict->AddStringItem(desc_str, llvm::StringRef(plugin_desc)); |
| 1093 | } |
| 1094 | |
| 1095 | data.m_impl_up->SetObjectSP( |
| 1096 | StructuredData::ObjectSP(platform_dict.release())); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1097 | return LLDB_RECORD_RESULT(data); |
Vadim Macagon | c10e34d | 2017-08-09 09:20:40 +0000 | [diff] [blame] | 1098 | } |
| 1099 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1100 | void SBDebugger::DispatchInput(void *baton, const void *data, size_t data_len) { |
| 1101 | DispatchInput(data, data_len); |
| 1102 | } |
| 1103 | |
| 1104 | void SBDebugger::DispatchInput(const void *data, size_t data_len) { |
| 1105 | // Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); |
| 1106 | // |
| 1107 | // if (log) |
| 1108 | // log->Printf ("SBDebugger(%p)::DispatchInput (data=\"%.*s\", |
| 1109 | // size_t=%" PRIu64 ")", |
| 1110 | // m_opaque_sp.get(), |
| 1111 | // (int) data_len, |
| 1112 | // (const char *) data, |
| 1113 | // (uint64_t)data_len); |
| 1114 | // |
| 1115 | // if (m_opaque_sp) |
| 1116 | // m_opaque_sp->DispatchInput ((const char *) data, data_len); |
| 1117 | } |
| 1118 | |
| 1119 | void SBDebugger::DispatchInputInterrupt() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1120 | LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, DispatchInputInterrupt); |
| 1121 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1122 | if (m_opaque_sp) |
| 1123 | m_opaque_sp->DispatchInputInterrupt(); |
| 1124 | } |
| 1125 | |
| 1126 | void SBDebugger::DispatchInputEndOfFile() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1127 | LLDB_RECORD_METHOD_NO_ARGS(void, SBDebugger, DispatchInputEndOfFile); |
| 1128 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1129 | if (m_opaque_sp) |
| 1130 | m_opaque_sp->DispatchInputEndOfFile(); |
| 1131 | } |
| 1132 | |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1133 | void SBDebugger::PushInputReader(SBInputReader &reader) { |
| 1134 | LLDB_RECORD_METHOD(void, SBDebugger, PushInputReader, (lldb::SBInputReader &), |
| 1135 | reader); |
| 1136 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1137 | |
| 1138 | void SBDebugger::RunCommandInterpreter(bool auto_handle_events, |
| 1139 | bool spawn_thread) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1140 | LLDB_RECORD_METHOD(void, SBDebugger, RunCommandInterpreter, (bool, bool), |
| 1141 | auto_handle_events, spawn_thread); |
| 1142 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1143 | if (m_opaque_sp) { |
| 1144 | CommandInterpreterRunOptions options; |
| 1145 | |
| 1146 | m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter( |
| 1147 | auto_handle_events, spawn_thread, options); |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | void SBDebugger::RunCommandInterpreter(bool auto_handle_events, |
| 1152 | bool spawn_thread, |
| 1153 | SBCommandInterpreterRunOptions &options, |
| 1154 | int &num_errors, bool &quit_requested, |
| 1155 | bool &stopped_for_crash) |
| 1156 | |
| 1157 | { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1158 | LLDB_RECORD_METHOD(void, SBDebugger, RunCommandInterpreter, |
| 1159 | (bool, bool, lldb::SBCommandInterpreterRunOptions &, int &, |
| 1160 | bool &, bool &), |
| 1161 | auto_handle_events, spawn_thread, options, num_errors, |
| 1162 | quit_requested, stopped_for_crash); |
| 1163 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1164 | if (m_opaque_sp) { |
| 1165 | CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter(); |
| 1166 | interp.RunCommandInterpreter(auto_handle_events, spawn_thread, |
| 1167 | options.ref()); |
| 1168 | num_errors = interp.GetNumErrors(); |
| 1169 | quit_requested = interp.GetQuitRequested(); |
| 1170 | stopped_for_crash = interp.GetStoppedForCrash(); |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | SBError SBDebugger::RunREPL(lldb::LanguageType language, |
| 1175 | const char *repl_options) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1176 | LLDB_RECORD_METHOD(lldb::SBError, SBDebugger, RunREPL, |
| 1177 | (lldb::LanguageType, const char *), language, |
| 1178 | repl_options); |
| 1179 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1180 | SBError error; |
| 1181 | if (m_opaque_sp) |
| 1182 | error.ref() = m_opaque_sp->RunREPL(language, repl_options); |
| 1183 | else |
| 1184 | error.SetErrorString("invalid debugger"); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1185 | return LLDB_RECORD_RESULT(error); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | void SBDebugger::reset(const DebuggerSP &debugger_sp) { |
| 1189 | m_opaque_sp = debugger_sp; |
| 1190 | } |
| 1191 | |
| 1192 | Debugger *SBDebugger::get() const { return m_opaque_sp.get(); } |
| 1193 | |
| 1194 | Debugger &SBDebugger::ref() const { |
| 1195 | assert(m_opaque_sp.get()); |
| 1196 | return *m_opaque_sp; |
| 1197 | } |
| 1198 | |
| 1199 | const lldb::DebuggerSP &SBDebugger::get_sp() const { return m_opaque_sp; } |
| 1200 | |
| 1201 | SBDebugger SBDebugger::FindDebuggerWithID(int id) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1202 | LLDB_RECORD_STATIC_METHOD(lldb::SBDebugger, SBDebugger, FindDebuggerWithID, |
| 1203 | (int), id); |
| 1204 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1205 | // No need to lock, the debugger list is thread safe |
| 1206 | SBDebugger sb_debugger; |
| 1207 | DebuggerSP debugger_sp = Debugger::FindDebuggerWithID(id); |
| 1208 | if (debugger_sp) |
| 1209 | sb_debugger.reset(debugger_sp); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1210 | return LLDB_RECORD_RESULT(sb_debugger); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | const char *SBDebugger::GetInstanceName() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1214 | LLDB_RECORD_METHOD_NO_ARGS(const char *, SBDebugger, GetInstanceName); |
| 1215 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1216 | return (m_opaque_sp ? m_opaque_sp->GetInstanceName().AsCString() : nullptr); |
| 1217 | } |
| 1218 | |
| 1219 | SBError SBDebugger::SetInternalVariable(const char *var_name, const char *value, |
| 1220 | const char *debugger_instance_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1221 | LLDB_RECORD_STATIC_METHOD(lldb::SBError, SBDebugger, SetInternalVariable, |
| 1222 | (const char *, const char *, const char *), |
| 1223 | var_name, value, debugger_instance_name); |
| 1224 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1225 | SBError sb_error; |
| 1226 | DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName( |
| 1227 | ConstString(debugger_instance_name))); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1228 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1229 | if (debugger_sp) { |
| 1230 | ExecutionContext exe_ctx( |
| 1231 | debugger_sp->GetCommandInterpreter().GetExecutionContext()); |
| 1232 | error = debugger_sp->SetPropertyValue(&exe_ctx, eVarSetOperationAssign, |
| 1233 | var_name, value); |
| 1234 | } else { |
| 1235 | error.SetErrorStringWithFormat("invalid debugger instance name '%s'", |
| 1236 | debugger_instance_name); |
| 1237 | } |
| 1238 | if (error.Fail()) |
| 1239 | sb_error.SetError(error); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1240 | return LLDB_RECORD_RESULT(sb_error); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
Greg Clayton | 431ce67 | 2011-04-18 23:15:17 +0000 | [diff] [blame] | 1243 | SBStringList |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1244 | SBDebugger::GetInternalVariableValue(const char *var_name, |
| 1245 | const char *debugger_instance_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1246 | LLDB_RECORD_STATIC_METHOD( |
| 1247 | lldb::SBStringList, SBDebugger, GetInternalVariableValue, |
| 1248 | (const char *, const char *), var_name, debugger_instance_name); |
| 1249 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1250 | SBStringList ret_value; |
| 1251 | DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName( |
| 1252 | ConstString(debugger_instance_name))); |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1253 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1254 | if (debugger_sp) { |
| 1255 | ExecutionContext exe_ctx( |
| 1256 | debugger_sp->GetCommandInterpreter().GetExecutionContext()); |
| 1257 | lldb::OptionValueSP value_sp( |
| 1258 | debugger_sp->GetPropertyValue(&exe_ctx, var_name, false, error)); |
| 1259 | if (value_sp) { |
| 1260 | StreamString value_strm; |
| 1261 | value_sp->DumpValue(&exe_ctx, value_strm, OptionValue::eDumpOptionValue); |
| 1262 | const std::string &value_str = value_strm.GetString(); |
| 1263 | if (!value_str.empty()) { |
| 1264 | StringList string_list; |
| 1265 | string_list.SplitIntoLines(value_str); |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1266 | return LLDB_RECORD_RESULT(SBStringList(&string_list)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1270 | return LLDB_RECORD_RESULT(SBStringList()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1271 | } |
| 1272 | |
| 1273 | uint32_t SBDebugger::GetTerminalWidth() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1274 | LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBDebugger, GetTerminalWidth); |
| 1275 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1276 | return (m_opaque_sp ? m_opaque_sp->GetTerminalWidth() : 0); |
| 1277 | } |
| 1278 | |
| 1279 | void SBDebugger::SetTerminalWidth(uint32_t term_width) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1280 | LLDB_RECORD_METHOD(void, SBDebugger, SetTerminalWidth, (uint32_t), |
| 1281 | term_width); |
| 1282 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1283 | if (m_opaque_sp) |
| 1284 | m_opaque_sp->SetTerminalWidth(term_width); |
| 1285 | } |
| 1286 | |
| 1287 | const char *SBDebugger::GetPrompt() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1288 | LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBDebugger, GetPrompt); |
| 1289 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1290 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1291 | |
| 1292 | if (log) |
| 1293 | log->Printf("SBDebugger(%p)::GetPrompt () => \"%s\"", |
| 1294 | static_cast<void *>(m_opaque_sp.get()), |
Zachary Turner | 514d8cd | 2016-09-23 18:06:53 +0000 | [diff] [blame] | 1295 | (m_opaque_sp ? m_opaque_sp->GetPrompt().str().c_str() : "")); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1296 | |
Zachary Turner | 514d8cd | 2016-09-23 18:06:53 +0000 | [diff] [blame] | 1297 | return (m_opaque_sp ? ConstString(m_opaque_sp->GetPrompt()).GetCString() |
| 1298 | : nullptr); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | void SBDebugger::SetPrompt(const char *prompt) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1302 | LLDB_RECORD_METHOD(void, SBDebugger, SetPrompt, (const char *), prompt); |
| 1303 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1304 | if (m_opaque_sp) |
Zachary Turner | 514d8cd | 2016-09-23 18:06:53 +0000 | [diff] [blame] | 1305 | m_opaque_sp->SetPrompt(llvm::StringRef::withNullAsEmpty(prompt)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 1308 | const char *SBDebugger::GetReproducerPath() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1309 | LLDB_RECORD_METHOD_CONST_NO_ARGS(const char *, SBDebugger, GetReproducerPath); |
| 1310 | |
Jonas Devlieghere | 9e046f0 | 2018-11-13 19:18:16 +0000 | [diff] [blame] | 1311 | return (m_opaque_sp |
| 1312 | ? ConstString(m_opaque_sp->GetReproducerPath()).GetCString() |
| 1313 | : nullptr); |
| 1314 | } |
| 1315 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1316 | ScriptLanguage SBDebugger::GetScriptLanguage() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1317 | LLDB_RECORD_METHOD_CONST_NO_ARGS(lldb::ScriptLanguage, SBDebugger, |
| 1318 | GetScriptLanguage); |
| 1319 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1320 | return (m_opaque_sp ? m_opaque_sp->GetScriptLanguage() : eScriptLanguageNone); |
| 1321 | } |
| 1322 | |
| 1323 | void SBDebugger::SetScriptLanguage(ScriptLanguage script_lang) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1324 | LLDB_RECORD_METHOD(void, SBDebugger, SetScriptLanguage, |
| 1325 | (lldb::ScriptLanguage), script_lang); |
| 1326 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1327 | if (m_opaque_sp) { |
| 1328 | m_opaque_sp->SetScriptLanguage(script_lang); |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | bool SBDebugger::SetUseExternalEditor(bool value) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1333 | LLDB_RECORD_METHOD(bool, SBDebugger, SetUseExternalEditor, (bool), value); |
| 1334 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1335 | return (m_opaque_sp ? m_opaque_sp->SetUseExternalEditor(value) : false); |
| 1336 | } |
| 1337 | |
| 1338 | bool SBDebugger::GetUseExternalEditor() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1339 | LLDB_RECORD_METHOD_NO_ARGS(bool, SBDebugger, GetUseExternalEditor); |
| 1340 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1341 | return (m_opaque_sp ? m_opaque_sp->GetUseExternalEditor() : false); |
| 1342 | } |
| 1343 | |
| 1344 | bool SBDebugger::SetUseColor(bool value) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1345 | LLDB_RECORD_METHOD(bool, SBDebugger, SetUseColor, (bool), value); |
| 1346 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1347 | return (m_opaque_sp ? m_opaque_sp->SetUseColor(value) : false); |
| 1348 | } |
| 1349 | |
| 1350 | bool SBDebugger::GetUseColor() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1351 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, GetUseColor); |
| 1352 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1353 | return (m_opaque_sp ? m_opaque_sp->GetUseColor() : false); |
| 1354 | } |
| 1355 | |
| 1356 | bool SBDebugger::GetDescription(SBStream &description) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1357 | LLDB_RECORD_METHOD(bool, SBDebugger, GetDescription, (lldb::SBStream &), |
| 1358 | description); |
| 1359 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1360 | Stream &strm = description.ref(); |
| 1361 | |
| 1362 | if (m_opaque_sp) { |
| 1363 | const char *name = m_opaque_sp->GetInstanceName().AsCString(); |
| 1364 | user_id_t id = m_opaque_sp->GetID(); |
| 1365 | strm.Printf("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id); |
| 1366 | } else |
| 1367 | strm.PutCString("No value"); |
| 1368 | |
| 1369 | return true; |
| 1370 | } |
| 1371 | |
| 1372 | user_id_t SBDebugger::GetID() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1373 | LLDB_RECORD_METHOD_NO_ARGS(lldb::user_id_t, SBDebugger, GetID); |
| 1374 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1375 | return (m_opaque_sp ? m_opaque_sp->GetID() : LLDB_INVALID_UID); |
| 1376 | } |
| 1377 | |
| 1378 | SBError SBDebugger::SetCurrentPlatform(const char *platform_name_cstr) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1379 | LLDB_RECORD_METHOD(lldb::SBError, SBDebugger, SetCurrentPlatform, |
| 1380 | (const char *), platform_name_cstr); |
| 1381 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1382 | SBError sb_error; |
| 1383 | if (m_opaque_sp) { |
| 1384 | if (platform_name_cstr && platform_name_cstr[0]) { |
| 1385 | ConstString platform_name(platform_name_cstr); |
| 1386 | PlatformSP platform_sp(Platform::Find(platform_name)); |
| 1387 | |
| 1388 | if (platform_sp) { |
| 1389 | // Already have a platform with this name, just select it |
| 1390 | m_opaque_sp->GetPlatformList().SetSelectedPlatform(platform_sp); |
| 1391 | } else { |
| 1392 | // We don't have a platform by this name yet, create one |
| 1393 | platform_sp = Platform::Create(platform_name, sb_error.ref()); |
| 1394 | if (platform_sp) { |
| 1395 | // We created the platform, now append and select it |
| 1396 | bool make_selected = true; |
| 1397 | m_opaque_sp->GetPlatformList().Append(platform_sp, make_selected); |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 1398 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1399 | } |
| 1400 | } else { |
| 1401 | sb_error.ref().SetErrorString("invalid platform name"); |
Greg Clayton | 6920b52 | 2012-08-22 18:39:03 +0000 | [diff] [blame] | 1402 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1403 | } else { |
| 1404 | sb_error.ref().SetErrorString("invalid debugger"); |
| 1405 | } |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1406 | return LLDB_RECORD_RESULT(sb_error); |
Caroline Tice | 3df9a8d | 2010-09-04 00:03:46 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1409 | bool SBDebugger::SetCurrentPlatformSDKRoot(const char *sysroot) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1410 | LLDB_RECORD_METHOD(bool, SBDebugger, SetCurrentPlatformSDKRoot, |
| 1411 | (const char *), sysroot); |
| 1412 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1413 | Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); |
| 1414 | if (m_opaque_sp) { |
| 1415 | PlatformSP platform_sp( |
| 1416 | m_opaque_sp->GetPlatformList().GetSelectedPlatform()); |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1417 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1418 | if (platform_sp) { |
| 1419 | if (log && sysroot) |
| 1420 | log->Printf("SBDebugger::SetCurrentPlatformSDKRoot (\"%s\")", sysroot); |
| 1421 | platform_sp->SetSDKRootDirectory(ConstString(sysroot)); |
| 1422 | return true; |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1423 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1424 | } |
| 1425 | return false; |
Greg Clayton | a701509 | 2010-09-18 01:14:36 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1428 | bool SBDebugger::GetCloseInputOnEOF() const { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1429 | LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBDebugger, GetCloseInputOnEOF); |
| 1430 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1431 | return (m_opaque_sp ? m_opaque_sp->GetCloseInputOnEOF() : false); |
Jim Ingham | e40e421 | 2010-08-30 19:44:40 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1434 | void SBDebugger::SetCloseInputOnEOF(bool b) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1435 | LLDB_RECORD_METHOD(void, SBDebugger, SetCloseInputOnEOF, (bool), b); |
| 1436 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1437 | if (m_opaque_sp) |
| 1438 | m_opaque_sp->SetCloseInputOnEOF(b); |
Jim Ingham | e40e421 | 2010-08-30 19:44:40 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1441 | SBTypeCategory SBDebugger::GetCategory(const char *category_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1442 | LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory, |
| 1443 | (const char *), category_name); |
| 1444 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1445 | if (!category_name || *category_name == 0) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1446 | return LLDB_RECORD_RESULT(SBTypeCategory()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1447 | |
| 1448 | TypeCategoryImplSP category_sp; |
| 1449 | |
| 1450 | if (DataVisualization::Categories::GetCategory(ConstString(category_name), |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1451 | category_sp, false)) { |
| 1452 | return LLDB_RECORD_RESULT(SBTypeCategory(category_sp)); |
| 1453 | } else { |
| 1454 | return LLDB_RECORD_RESULT(SBTypeCategory()); |
| 1455 | } |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1458 | SBTypeCategory SBDebugger::GetCategory(lldb::LanguageType lang_type) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1459 | LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategory, |
| 1460 | (lldb::LanguageType), lang_type); |
| 1461 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1462 | TypeCategoryImplSP category_sp; |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1463 | if (DataVisualization::Categories::GetCategory(lang_type, category_sp)) { |
| 1464 | return LLDB_RECORD_RESULT(SBTypeCategory(category_sp)); |
| 1465 | } else { |
| 1466 | return LLDB_RECORD_RESULT(SBTypeCategory()); |
| 1467 | } |
Michael Sartain | c3ce7f27 | 2013-05-23 20:47:45 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1470 | SBTypeCategory SBDebugger::CreateCategory(const char *category_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1471 | LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, CreateCategory, |
| 1472 | (const char *), category_name); |
| 1473 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1474 | if (!category_name || *category_name == 0) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1475 | return LLDB_RECORD_RESULT(SBTypeCategory()); |
Greg Clayton | da7bc7d | 2011-11-13 06:57:31 +0000 | [diff] [blame] | 1476 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1477 | TypeCategoryImplSP category_sp; |
| 1478 | |
| 1479 | if (DataVisualization::Categories::GetCategory(ConstString(category_name), |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1480 | category_sp, true)) { |
| 1481 | return LLDB_RECORD_RESULT(SBTypeCategory(category_sp)); |
| 1482 | } else { |
| 1483 | return LLDB_RECORD_RESULT(SBTypeCategory()); |
| 1484 | } |
Caroline Tice | dde9cff | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 1485 | } |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 1486 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1487 | bool SBDebugger::DeleteCategory(const char *category_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1488 | LLDB_RECORD_METHOD(bool, SBDebugger, DeleteCategory, (const char *), |
| 1489 | category_name); |
| 1490 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1491 | if (!category_name || *category_name == 0) |
| 1492 | return false; |
| 1493 | |
| 1494 | return DataVisualization::Categories::Delete(ConstString(category_name)); |
Caroline Tice | efed613 | 2010-11-19 20:47:54 +0000 | [diff] [blame] | 1495 | } |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 1496 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1497 | uint32_t SBDebugger::GetNumCategories() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1498 | LLDB_RECORD_METHOD_NO_ARGS(uint32_t, SBDebugger, GetNumCategories); |
| 1499 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1500 | return DataVisualization::Categories::GetCount(); |
Greg Clayton | 2289fa4 | 2011-04-30 01:09:13 +0000 | [diff] [blame] | 1501 | } |
| 1502 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1503 | SBTypeCategory SBDebugger::GetCategoryAtIndex(uint32_t index) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1504 | LLDB_RECORD_METHOD(lldb::SBTypeCategory, SBDebugger, GetCategoryAtIndex, |
| 1505 | (uint32_t), index); |
| 1506 | |
| 1507 | return LLDB_RECORD_RESULT( |
| 1508 | SBTypeCategory(DataVisualization::Categories::GetCategoryAtIndex(index))); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | SBTypeCategory SBDebugger::GetDefaultCategory() { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1512 | LLDB_RECORD_METHOD_NO_ARGS(lldb::SBTypeCategory, SBDebugger, |
| 1513 | GetDefaultCategory); |
| 1514 | |
| 1515 | return LLDB_RECORD_RESULT(GetCategory("default")); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
| 1518 | SBTypeFormat SBDebugger::GetFormatForType(SBTypeNameSpecifier type_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1519 | LLDB_RECORD_METHOD(lldb::SBTypeFormat, SBDebugger, GetFormatForType, |
| 1520 | (lldb::SBTypeNameSpecifier), type_name); |
| 1521 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1522 | SBTypeCategory default_category_sb = GetDefaultCategory(); |
| 1523 | if (default_category_sb.GetEnabled()) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1524 | return LLDB_RECORD_RESULT(default_category_sb.GetFormatForType(type_name)); |
| 1525 | return LLDB_RECORD_RESULT(SBTypeFormat()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | #ifndef LLDB_DISABLE_PYTHON |
| 1529 | SBTypeSummary SBDebugger::GetSummaryForType(SBTypeNameSpecifier type_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1530 | LLDB_RECORD_METHOD(lldb::SBTypeSummary, SBDebugger, GetSummaryForType, |
| 1531 | (lldb::SBTypeNameSpecifier), type_name); |
| 1532 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1533 | if (!type_name.IsValid()) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1534 | return LLDB_RECORD_RESULT(SBTypeSummary()); |
| 1535 | return LLDB_RECORD_RESULT( |
| 1536 | SBTypeSummary(DataVisualization::GetSummaryForType(type_name.GetSP()))); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1537 | } |
| 1538 | #endif // LLDB_DISABLE_PYTHON |
| 1539 | |
| 1540 | SBTypeFilter SBDebugger::GetFilterForType(SBTypeNameSpecifier type_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1541 | LLDB_RECORD_METHOD(lldb::SBTypeFilter, SBDebugger, GetFilterForType, |
| 1542 | (lldb::SBTypeNameSpecifier), type_name); |
| 1543 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1544 | if (!type_name.IsValid()) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1545 | return LLDB_RECORD_RESULT(SBTypeFilter()); |
| 1546 | return LLDB_RECORD_RESULT( |
| 1547 | SBTypeFilter(DataVisualization::GetFilterForType(type_name.GetSP()))); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | #ifndef LLDB_DISABLE_PYTHON |
| 1551 | SBTypeSynthetic SBDebugger::GetSyntheticForType(SBTypeNameSpecifier type_name) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1552 | LLDB_RECORD_METHOD(lldb::SBTypeSynthetic, SBDebugger, GetSyntheticForType, |
| 1553 | (lldb::SBTypeNameSpecifier), type_name); |
| 1554 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1555 | if (!type_name.IsValid()) |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1556 | return LLDB_RECORD_RESULT(SBTypeSynthetic()); |
| 1557 | return LLDB_RECORD_RESULT(SBTypeSynthetic( |
| 1558 | DataVisualization::GetSyntheticForType(type_name.GetSP()))); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1559 | } |
| 1560 | #endif // LLDB_DISABLE_PYTHON |
| 1561 | |
Pavel Labath | 5e33690 | 2017-03-01 10:08:40 +0000 | [diff] [blame] | 1562 | static llvm::ArrayRef<const char *> GetCategoryArray(const char **categories) { |
| 1563 | if (categories == nullptr) |
| 1564 | return {}; |
| 1565 | size_t len = 0; |
| 1566 | while (categories[len] != nullptr) |
| 1567 | ++len; |
| 1568 | return llvm::makeArrayRef(categories, len); |
| 1569 | } |
| 1570 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1571 | bool SBDebugger::EnableLog(const char *channel, const char **categories) { |
Jonas Devlieghere | baf5664 | 2019-03-06 00:06:00 +0000 | [diff] [blame^] | 1572 | LLDB_RECORD_METHOD(bool, SBDebugger, EnableLog, (const char *, const char **), |
| 1573 | channel, categories); |
| 1574 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1575 | if (m_opaque_sp) { |
| 1576 | uint32_t log_options = |
| 1577 | LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME; |
Pavel Labath | 775588c | 2017-03-15 09:06:58 +0000 | [diff] [blame] | 1578 | std::string error; |
| 1579 | llvm::raw_string_ostream error_stream(error); |
Pavel Labath | 5e33690 | 2017-03-01 10:08:40 +0000 | [diff] [blame] | 1580 | return m_opaque_sp->EnableLog(channel, GetCategoryArray(categories), "", |
Pavel Labath | 775588c | 2017-03-15 09:06:58 +0000 | [diff] [blame] | 1581 | log_options, error_stream); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1582 | } else |
Greg Clayton | f3dd93c | 2011-06-17 03:31:01 +0000 | [diff] [blame] | 1583 | return false; |
| 1584 | } |
| 1585 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1586 | void SBDebugger::SetLoggingCallback(lldb::LogOutputCallback log_callback, |
| 1587 | void *baton) { |
| 1588 | if (m_opaque_sp) { |
| 1589 | return m_opaque_sp->SetLoggingCallback(log_callback, baton); |
| 1590 | } |
Jim Ingham | 4f02b22 | 2012-02-22 22:49:20 +0000 | [diff] [blame] | 1591 | } |