blob: fca43d6682ecc40affd467be3ec58d6376be3b99 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBDebugger.cpp ------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Eli Friedmanca93cc12010-06-09 07:37:52 +000010#include "lldb/API/SBDebugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011
Greg Claytone0d378b2011-03-24 21:19:54 +000012#include "lldb/lldb-private.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
Zachary Turnere6e2bb32015-03-31 21:03:22 +000014#include "lldb/API/SystemInitializerFull.h"
Eli Friedmanca93cc12010-06-09 07:37:52 +000015#include "lldb/API/SBListener.h"
16#include "lldb/API/SBBroadcaster.h"
17#include "lldb/API/SBCommandInterpreter.h"
18#include "lldb/API/SBCommandReturnObject.h"
Greg Clayton2289fa42011-04-30 01:09:13 +000019#include "lldb/API/SBError.h"
Eli Friedmanca93cc12010-06-09 07:37:52 +000020#include "lldb/API/SBEvent.h"
21#include "lldb/API/SBFrame.h"
Caroline Tice3df9a8d2010-09-04 00:03:46 +000022#include "lldb/API/SBProcess.h"
23#include "lldb/API/SBSourceManager.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000024#include "lldb/API/SBStream.h"
Caroline Tice3df9a8d2010-09-04 00:03:46 +000025#include "lldb/API/SBStringList.h"
26#include "lldb/API/SBTarget.h"
27#include "lldb/API/SBThread.h"
Enrico Granata061858c2012-02-15 02:34:21 +000028#include "lldb/API/SBTypeCategory.h"
29#include "lldb/API/SBTypeFormat.h"
30#include "lldb/API/SBTypeFilter.h"
31#include "lldb/API/SBTypeNameSpecifier.h"
32#include "lldb/API/SBTypeSummary.h"
33#include "lldb/API/SBTypeSynthetic.h"
34
Greg Clayton6eee5aa2010-10-11 01:05:37 +000035#include "lldb/Core/Debugger.h"
36#include "lldb/Core/State.h"
Greg Clayton44d93782014-01-27 23:43:24 +000037#include "lldb/Core/StreamFile.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000038#include "lldb/DataFormatters/DataVisualization.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000039#include "lldb/Initialization/SystemLifetimeManager.h"
Greg Clayton6eee5aa2010-10-11 01:05:37 +000040#include "lldb/Interpreter/Args.h"
41#include "lldb/Interpreter/CommandInterpreter.h"
Greg Claytoncac9c5f2011-09-24 00:52:29 +000042#include "lldb/Interpreter/OptionGroupPlatform.h"
Greg Clayton6eee5aa2010-10-11 01:05:37 +000043#include "lldb/Target/Process.h"
44#include "lldb/Target/TargetList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000045
Enrico Granatad717cc92015-10-20 04:50:09 +000046#include "llvm/ADT/STLExtras.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000047#include "llvm/Support/ManagedStatic.h"
Zachary Turner58a559c2014-08-27 20:15:09 +000048#include "llvm/Support/DynamicLibrary.h"
49
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050using namespace lldb;
51using namespace lldb_private;
52
Greg Clayton5fb8f792013-12-02 19:35:49 +000053
Zachary Turner58a559c2014-08-27 20:15:09 +000054static llvm::sys::DynamicLibrary
Greg Clayton5fb8f792013-12-02 19:35:49 +000055LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& error)
56{
Zachary Turner58a559c2014-08-27 20:15:09 +000057 llvm::sys::DynamicLibrary dynlib = llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
58 if (dynlib.isValid())
Greg Clayton5fb8f792013-12-02 19:35:49 +000059 {
60 typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger);
61
62 lldb::SBDebugger debugger_sb(debugger_sp);
63 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) function.
64 // TODO: mangle this differently for your system - on OSX, the first underscore needs to be removed and the second one stays
Zachary Turner58a559c2014-08-27 20:15:09 +000065 LLDBCommandPluginInit init_func = (LLDBCommandPluginInit)dynlib.getAddressOfSymbol("_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
Greg Clayton5fb8f792013-12-02 19:35:49 +000066 if (init_func)
67 {
68 if (init_func(debugger_sb))
Zachary Turner58a559c2014-08-27 20:15:09 +000069 return dynlib;
Greg Clayton5fb8f792013-12-02 19:35:49 +000070 else
71 error.SetErrorString("plug-in refused to load (lldb::PluginInitialize(lldb::SBDebugger) returned false)");
72 }
73 else
74 {
75 error.SetErrorString("plug-in is missing the required initialization: lldb::PluginInitialize(lldb::SBDebugger)");
76 }
77 }
78 else
79 {
80 if (spec.Exists())
81 error.SetErrorString("this file does not represent a loadable dylib");
82 else
83 error.SetErrorString("no such file");
84 }
Zachary Turner58a559c2014-08-27 20:15:09 +000085 return llvm::sys::DynamicLibrary();
Greg Clayton5fb8f792013-12-02 19:35:49 +000086}
87
Zachary Turnere6e2bb32015-03-31 21:03:22 +000088static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime;
89
90SBInputReader::SBInputReader()
91{
92}
93SBInputReader::~SBInputReader()
94{
95}
96
97SBError
98SBInputReader::Initialize(lldb::SBDebugger &sb_debugger,
99 unsigned long (*)(void *, lldb::SBInputReader *, lldb::InputReaderAction, char const *,
100 unsigned long),
101 void *, lldb::InputReaderGranularity, char const *, char const *, bool)
102{
103 return SBError();
104}
105
106void
107SBInputReader::SetIsDone(bool)
108{
109}
110bool
111SBInputReader::IsActive() const
112{
113 return false;
114}
115
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000116void
117SBDebugger::Initialize ()
118{
Greg Clayton5160ce52013-03-27 23:08:40 +0000119 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000120
121 if (log)
122 log->Printf ("SBDebugger::Initialize ()");
123
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000124 g_debugger_lifetime->Initialize(llvm::make_unique<SystemInitializerFull>(), LoadPlugin);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000125}
126
127void
128SBDebugger::Terminate ()
129{
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000130 g_debugger_lifetime->Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000131}
132
Greg Clayton48e42542010-07-30 20:12:55 +0000133void
134SBDebugger::Clear ()
135{
Greg Clayton5160ce52013-03-27 23:08:40 +0000136 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000137
138 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000139 log->Printf ("SBDebugger(%p)::Clear ()",
140 static_cast<void*>(m_opaque_sp.get()));
141
Caroline Tice3d6086f2010-12-20 18:35:50 +0000142 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000143 m_opaque_sp->ClearIOHandlers ();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000144
Greg Clayton48e42542010-07-30 20:12:55 +0000145 m_opaque_sp.reset();
146}
147
Greg Clayton66111032010-06-23 01:19:29 +0000148SBDebugger
149SBDebugger::Create()
150{
Jim Ingham228063c2012-02-21 02:23:08 +0000151 return SBDebugger::Create(false, NULL, NULL);
Jim Ingham06942692011-08-13 00:22:20 +0000152}
153
154SBDebugger
155SBDebugger::Create(bool source_init_files)
156{
Jim Ingham228063c2012-02-21 02:23:08 +0000157 return SBDebugger::Create (source_init_files, NULL, NULL);
158}
159
160SBDebugger
161SBDebugger::Create(bool source_init_files, lldb::LogOutputCallback callback, void *baton)
162
163{
Greg Clayton5160ce52013-03-27 23:08:40 +0000164 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000165
Greg Clayton66111032010-06-23 01:19:29 +0000166 SBDebugger debugger;
Greg Claytoncb172b12014-05-19 20:42:14 +0000167
168 // Currently we have issues if this function is called simultaneously on two different
169 // threads. The issues mainly revolve around the fact that the lldb_private::FormatManager
170 // uses global collections and having two threads parsing the .lldbinit files can cause
171 // mayhem. So to get around this for now we need to use a mutex to prevent bad things
172 // from happening.
173 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
174 Mutex::Locker locker(g_mutex);
175
Jim Ingham228063c2012-02-21 02:23:08 +0000176 debugger.reset(Debugger::CreateInstance(callback, baton));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000177
178 if (log)
179 {
180 SBStream sstr;
181 debugger.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000182 log->Printf ("SBDebugger::Create () => SBDebugger(%p): %s",
183 static_cast<void*>(debugger.m_opaque_sp.get()),
184 sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000185 }
186
Jim Ingham06942692011-08-13 00:22:20 +0000187 SBCommandInterpreter interp = debugger.GetCommandInterpreter();
188 if (source_init_files)
189 {
190 interp.get()->SkipLLDBInitFiles(false);
191 interp.get()->SkipAppInitFiles (false);
192 SBCommandReturnObject result;
193 interp.SourceInitFileInHomeDirectory(result);
194 }
195 else
196 {
197 interp.get()->SkipLLDBInitFiles(true);
198 interp.get()->SkipAppInitFiles (true);
199 }
Greg Clayton66111032010-06-23 01:19:29 +0000200 return debugger;
201}
202
Caroline Ticee02657b2011-01-22 01:02:07 +0000203void
204SBDebugger::Destroy (SBDebugger &debugger)
205{
Greg Clayton5160ce52013-03-27 23:08:40 +0000206 Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000207
Caroline Ticee02657b2011-01-22 01:02:07 +0000208 if (log)
209 {
210 SBStream sstr;
211 debugger.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000212 log->Printf ("SBDebugger::Destroy () => SBDebugger(%p): %s",
213 static_cast<void*>(debugger.m_opaque_sp.get()),
214 sstr.GetData());
Caroline Ticee02657b2011-01-22 01:02:07 +0000215 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000216
Caroline Ticee02657b2011-01-22 01:02:07 +0000217 Debugger::Destroy (debugger.m_opaque_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000218
Caroline Ticee02657b2011-01-22 01:02:07 +0000219 if (debugger.m_opaque_sp.get() != NULL)
220 debugger.m_opaque_sp.reset();
221}
222
Greg Claytonf9322412011-12-15 04:38:41 +0000223void
224SBDebugger::MemoryPressureDetected ()
225{
Greg Clayton0cd70862012-04-09 20:22:01 +0000226 // Since this function can be call asynchronously, we allow it to be
227 // non-mandatory. We have seen deadlocks with this function when called
228 // so we need to safeguard against this until we can determine what is
229 // causing the deadlocks.
Greg Clayton5160ce52013-03-27 23:08:40 +0000230 Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamaebdf1b2012-06-07 19:08:07 +0000231
Greg Clayton0cd70862012-04-09 20:22:01 +0000232 const bool mandatory = false;
Jim Inghamaebdf1b2012-06-07 19:08:07 +0000233 if (log)
234 {
235 log->Printf ("SBDebugger::MemoryPressureDetected (), mandatory = %d", mandatory);
236 }
237
Greg Clayton0cd70862012-04-09 20:22:01 +0000238 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Claytonf9322412011-12-15 04:38:41 +0000239}
240
Greg Clayton66111032010-06-23 01:19:29 +0000241SBDebugger::SBDebugger () :
242 m_opaque_sp ()
243{
244}
245
Enrico Granata274fd6e2011-08-19 23:56:34 +0000246SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp) :
247 m_opaque_sp(debugger_sp)
248{
249}
250
Greg Claytonefabb122010-11-05 23:17:00 +0000251SBDebugger::SBDebugger(const SBDebugger &rhs) :
252 m_opaque_sp (rhs.m_opaque_sp)
253{
254}
255
256SBDebugger &
257SBDebugger::operator = (const SBDebugger &rhs)
258{
259 if (this != &rhs)
260 {
261 m_opaque_sp = rhs.m_opaque_sp;
262 }
263 return *this;
264}
265
Greg Clayton66111032010-06-23 01:19:29 +0000266SBDebugger::~SBDebugger ()
267{
268}
269
270bool
271SBDebugger::IsValid() const
272{
273 return m_opaque_sp.get() != NULL;
274}
275
276
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000277void
278SBDebugger::SetAsync (bool b)
279{
Greg Clayton66111032010-06-23 01:19:29 +0000280 if (m_opaque_sp)
281 m_opaque_sp->SetAsyncExecution(b);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000282}
283
Jim Inghame64f0dc2011-09-13 23:25:31 +0000284bool
285SBDebugger::GetAsync ()
286{
287 if (m_opaque_sp)
288 return m_opaque_sp->GetAsyncExecution();
289 else
290 return false;
291}
292
Greg Clayton6eee5aa2010-10-11 01:05:37 +0000293void
294SBDebugger::SkipLLDBInitFiles (bool b)
295{
296 if (m_opaque_sp)
297 m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles (b);
298}
299
Jim Ingham16e0c682011-08-12 23:34:31 +0000300void
301SBDebugger::SkipAppInitFiles (bool b)
302{
303 if (m_opaque_sp)
304 m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles (b);
305}
306
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000307// Shouldn't really be settable after initialization as this could cause lots of problems; don't want users
308// trying to switch modes in the middle of a debugging session.
309void
310SBDebugger::SetInputFileHandle (FILE *fh, bool transfer_ownership)
311{
Greg Clayton5160ce52013-03-27 23:08:40 +0000312 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000313
314 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000315 log->Printf ("SBDebugger(%p)::SetInputFileHandle (fh=%p, transfer_ownership=%i)",
316 static_cast<void*>(m_opaque_sp.get()),
317 static_cast<void*>(fh), transfer_ownership);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000318
Greg Clayton66111032010-06-23 01:19:29 +0000319 if (m_opaque_sp)
320 m_opaque_sp->SetInputFileHandle (fh, transfer_ownership);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000321}
322
323void
324SBDebugger::SetOutputFileHandle (FILE *fh, bool transfer_ownership)
325{
Greg Clayton5160ce52013-03-27 23:08:40 +0000326 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000327
328
329 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000330 log->Printf ("SBDebugger(%p)::SetOutputFileHandle (fh=%p, transfer_ownership=%i)",
331 static_cast<void*>(m_opaque_sp.get()),
332 static_cast<void*>(fh), transfer_ownership);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000333
Greg Clayton66111032010-06-23 01:19:29 +0000334 if (m_opaque_sp)
335 m_opaque_sp->SetOutputFileHandle (fh, transfer_ownership);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000336}
337
338void
339SBDebugger::SetErrorFileHandle (FILE *fh, bool transfer_ownership)
340{
Greg Clayton5160ce52013-03-27 23:08:40 +0000341 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000342
343
344 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000345 log->Printf ("SBDebugger(%p)::SetErrorFileHandle (fh=%p, transfer_ownership=%i)",
346 static_cast<void*>(m_opaque_sp.get()),
347 static_cast<void*>(fh), transfer_ownership);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000348
Greg Clayton66111032010-06-23 01:19:29 +0000349 if (m_opaque_sp)
350 m_opaque_sp->SetErrorFileHandle (fh, transfer_ownership);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000351}
352
353FILE *
354SBDebugger::GetInputFileHandle ()
355{
Greg Clayton66111032010-06-23 01:19:29 +0000356 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000357 {
358 StreamFileSP stream_file_sp (m_opaque_sp->GetInputFile());
359 if (stream_file_sp)
360 return stream_file_sp->GetFile().GetStream();
361 }
Greg Clayton66111032010-06-23 01:19:29 +0000362 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000363}
364
365FILE *
366SBDebugger::GetOutputFileHandle ()
367{
Greg Clayton66111032010-06-23 01:19:29 +0000368 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000369 {
370 StreamFileSP stream_file_sp (m_opaque_sp->GetOutputFile());
371 if (stream_file_sp)
372 return stream_file_sp->GetFile().GetStream();
373 }
Greg Clayton66111032010-06-23 01:19:29 +0000374 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000375}
376
377FILE *
378SBDebugger::GetErrorFileHandle ()
379{
Greg Clayton66111032010-06-23 01:19:29 +0000380 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000381 if (m_opaque_sp)
382 {
383 StreamFileSP stream_file_sp (m_opaque_sp->GetErrorFile());
384 if (stream_file_sp)
385 return stream_file_sp->GetFile().GetStream();
386 }
Greg Clayton66111032010-06-23 01:19:29 +0000387 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000388}
389
Jim Inghamc5917d92012-11-30 20:23:19 +0000390void
391SBDebugger::SaveInputTerminalState()
392{
393 if (m_opaque_sp)
394 m_opaque_sp->SaveInputTerminalState();
395}
396
397void
398SBDebugger::RestoreInputTerminalState()
399{
400 if (m_opaque_sp)
401 m_opaque_sp->RestoreInputTerminalState();
402
403}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000404SBCommandInterpreter
405SBDebugger::GetCommandInterpreter ()
406{
Greg Clayton5160ce52013-03-27 23:08:40 +0000407 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000408
Greg Clayton66111032010-06-23 01:19:29 +0000409 SBCommandInterpreter sb_interpreter;
410 if (m_opaque_sp)
411 sb_interpreter.reset (&m_opaque_sp->GetCommandInterpreter());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000412
Caroline Tice750cd172010-10-26 23:49:36 +0000413 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000414 log->Printf ("SBDebugger(%p)::GetCommandInterpreter () => SBCommandInterpreter(%p)",
415 static_cast<void*>(m_opaque_sp.get()),
416 static_cast<void*>(sb_interpreter.get()));
Caroline Tice750cd172010-10-26 23:49:36 +0000417
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000418 return sb_interpreter;
419}
420
421void
422SBDebugger::HandleCommand (const char *command)
423{
Greg Clayton66111032010-06-23 01:19:29 +0000424 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000425 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000426 TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
427 Mutex::Locker api_locker;
428 if (target_sp)
Jim Ingham10ebffa2012-05-04 23:02:50 +0000429 api_locker.Lock(target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000430
Greg Clayton66111032010-06-23 01:19:29 +0000431 SBCommandInterpreter sb_interpreter(GetCommandInterpreter ());
432 SBCommandReturnObject result;
433
434 sb_interpreter.HandleCommand (command, result, false);
435
436 if (GetErrorFileHandle() != NULL)
437 result.PutError (GetErrorFileHandle());
438 if (GetOutputFileHandle() != NULL)
439 result.PutOutput (GetOutputFileHandle());
440
441 if (m_opaque_sp->GetAsyncExecution() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000442 {
Greg Clayton66111032010-06-23 01:19:29 +0000443 SBProcess process(GetCommandInterpreter().GetProcess ());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000444 ProcessSP process_sp (process.GetSP());
445 if (process_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000446 {
Greg Clayton66111032010-06-23 01:19:29 +0000447 EventSP event_sp;
448 Listener &lldb_listener = m_opaque_sp->GetListener();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000449 while (lldb_listener.GetNextEventForBroadcaster (process_sp.get(), event_sp))
Greg Clayton66111032010-06-23 01:19:29 +0000450 {
451 SBEvent event(event_sp);
452 HandleProcessEvent (process, event, GetOutputFileHandle(), GetErrorFileHandle());
453 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000454 }
455 }
456 }
457}
458
459SBListener
460SBDebugger::GetListener ()
461{
Greg Clayton5160ce52013-03-27 23:08:40 +0000462 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000463
Greg Clayton66111032010-06-23 01:19:29 +0000464 SBListener sb_listener;
465 if (m_opaque_sp)
466 sb_listener.reset(&m_opaque_sp->GetListener(), false);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000467
Caroline Tice750cd172010-10-26 23:49:36 +0000468 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000469 log->Printf ("SBDebugger(%p)::GetListener () => SBListener(%p)",
470 static_cast<void*>(m_opaque_sp.get()),
471 static_cast<void*>(sb_listener.get()));
Caroline Tice750cd172010-10-26 23:49:36 +0000472
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000473 return sb_listener;
474}
475
476void
477SBDebugger::HandleProcessEvent (const SBProcess &process, const SBEvent &event, FILE *out, FILE *err)
478{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000479 if (!process.IsValid())
480 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481
Greg Claytonb9556ac2012-01-30 07:41:31 +0000482 TargetSP target_sp (process.GetTarget().GetSP());
483 if (!target_sp)
484 return;
485
Greg Claytonaf67cec2010-12-20 20:49:23 +0000486 const uint32_t event_type = event.GetType();
487 char stdio_buffer[1024];
488 size_t len;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000489
Greg Claytonb9556ac2012-01-30 07:41:31 +0000490 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000491
492 if (event_type & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000493 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000494 // Drain stdout when we stop just in case we have any bytes
495 while ((len = process.GetSTDOUT (stdio_buffer, sizeof (stdio_buffer))) > 0)
496 if (out != NULL)
497 ::fwrite (stdio_buffer, 1, len, out);
498 }
499
500 if (event_type & (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged))
501 {
502 // Drain stderr when we stop just in case we have any bytes
503 while ((len = process.GetSTDERR (stdio_buffer, sizeof (stdio_buffer))) > 0)
504 if (err != NULL)
505 ::fwrite (stdio_buffer, 1, len, err);
506 }
507
508 if (event_type & Process::eBroadcastBitStateChanged)
509 {
510 StateType event_state = SBProcess::GetStateFromEvent (event);
511
512 if (event_state == eStateInvalid)
513 return;
514
515 bool is_stopped = StateIsStoppedState (event_state);
516 if (!is_stopped)
517 process.ReportEventState (event, out);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000518 }
519}
520
Jim Inghame37d6052011-09-13 00:29:56 +0000521SBSourceManager
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000522SBDebugger::GetSourceManager ()
523{
Jim Inghame37d6052011-09-13 00:29:56 +0000524 SBSourceManager sb_source_manager (*this);
525 return sb_source_manager;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000526}
527
528
529bool
530SBDebugger::GetDefaultArchitecture (char *arch_name, size_t arch_name_len)
531{
532 if (arch_name && arch_name_len)
533 {
Greg Clayton431ce672011-04-18 23:15:17 +0000534 ArchSpec default_arch = Target::GetDefaultArchitecture ();
Caroline Ticedaccaa92010-09-20 20:44:43 +0000535
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000536 if (default_arch.IsValid())
537 {
Greg Clayton431ce672011-04-18 23:15:17 +0000538 const std::string &triple_str = default_arch.GetTriple().str();
539 if (!triple_str.empty())
540 ::snprintf (arch_name, arch_name_len, "%s", triple_str.c_str());
541 else
542 ::snprintf (arch_name, arch_name_len, "%s", default_arch.GetArchitectureName());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000543 return true;
544 }
545 }
546 if (arch_name && arch_name_len)
547 arch_name[0] = '\0';
548 return false;
549}
550
551
552bool
553SBDebugger::SetDefaultArchitecture (const char *arch_name)
554{
555 if (arch_name)
556 {
Greg Clayton70512312012-05-08 01:45:38 +0000557 ArchSpec arch (arch_name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000558 if (arch.IsValid())
559 {
Greg Clayton431ce672011-04-18 23:15:17 +0000560 Target::SetDefaultArchitecture (arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000561 return true;
562 }
563 }
564 return false;
565}
566
567ScriptLanguage
568SBDebugger::GetScriptingLanguage (const char *script_language_name)
569{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000570
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000571 return Args::StringToScriptLanguage (script_language_name,
572 eScriptLanguageDefault,
573 NULL);
574}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000575
576const char *
577SBDebugger::GetVersionString ()
578{
Virgile Bellob2f1fb22013-08-23 12:44:05 +0000579 return lldb_private::GetVersion();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000580}
581
582const char *
Greg Clayton431ce672011-04-18 23:15:17 +0000583SBDebugger::StateAsCString (StateType state)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000584{
Caroline Ticec2bbb492011-04-25 22:05:51 +0000585 return lldb_private::StateAsCString (state);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000586}
587
588bool
Greg Clayton431ce672011-04-18 23:15:17 +0000589SBDebugger::StateIsRunningState (StateType state)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000590{
Greg Clayton5160ce52013-03-27 23:08:40 +0000591 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000592
Caroline Ticec2bbb492011-04-25 22:05:51 +0000593 const bool result = lldb_private::StateIsRunningState (state);
Greg Clayton48381312010-10-30 04:51:46 +0000594 if (log)
595 log->Printf ("SBDebugger::StateIsRunningState (state=%s) => %i",
Greg Clayton431ce672011-04-18 23:15:17 +0000596 StateAsCString (state), result);
Greg Clayton48381312010-10-30 04:51:46 +0000597
598 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000599}
600
601bool
Greg Clayton431ce672011-04-18 23:15:17 +0000602SBDebugger::StateIsStoppedState (StateType state)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000603{
Greg Clayton5160ce52013-03-27 23:08:40 +0000604 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000605
Greg Clayton2637f822011-11-17 01:23:07 +0000606 const bool result = lldb_private::StateIsStoppedState (state, false);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000607 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000608 log->Printf ("SBDebugger::StateIsStoppedState (state=%s) => %i",
Greg Clayton431ce672011-04-18 23:15:17 +0000609 StateAsCString (state), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000610
Greg Clayton48381312010-10-30 04:51:46 +0000611 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000612}
613
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000614lldb::SBTarget
615SBDebugger::CreateTarget (const char *filename,
616 const char *target_triple,
617 const char *platform_name,
618 bool add_dependent_modules,
619 lldb::SBError& sb_error)
620{
621 SBTarget sb_target;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000622 TargetSP target_sp;
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000623 if (m_opaque_sp)
624 {
625 sb_error.Clear();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000626 OptionGroupPlatform platform_options (false);
627 platform_options.SetPlatformName (platform_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000628
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000629 sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
Greg Claytona0ca6602012-10-18 16:33:33 +0000630 filename,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000631 target_triple,
632 add_dependent_modules,
633 &platform_options,
634 target_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000635
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000636 if (sb_error.Success())
Greg Claytonb9556ac2012-01-30 07:41:31 +0000637 sb_target.SetSP (target_sp);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000638 }
639 else
640 {
641 sb_error.SetErrorString("invalid target");
642 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000643
Greg Clayton5160ce52013-03-27 23:08:40 +0000644 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000645 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000646 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, platform_name=%s, add_dependent_modules=%u, error=%s) => SBTarget(%p)",
647 static_cast<void*>(m_opaque_sp.get()), filename,
648 target_triple, platform_name, add_dependent_modules,
649 sb_error.GetCString(), static_cast<void*>(target_sp.get()));
650
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000651 return sb_target;
652}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000653
654SBTarget
655SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename,
656 const char *target_triple)
657{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000658 SBTarget sb_target;
659 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000660 if (m_opaque_sp)
661 {
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000662 const bool add_dependent_modules = true;
663 Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
Greg Claytona0ca6602012-10-18 16:33:33 +0000664 filename,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000665 target_triple,
666 add_dependent_modules,
667 NULL,
668 target_sp));
Greg Claytonb9556ac2012-01-30 07:41:31 +0000669 sb_target.SetSP (target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000670 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000671
Greg Clayton5160ce52013-03-27 23:08:40 +0000672 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000673 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000674 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)",
675 static_cast<void*>(m_opaque_sp.get()), filename,
676 target_triple, static_cast<void*>(target_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000677
Greg Claytonb9556ac2012-01-30 07:41:31 +0000678 return sb_target;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000679}
680
681SBTarget
Greg Clayton64195a22011-02-23 00:35:02 +0000682SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_cstr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000683{
Greg Clayton5160ce52013-03-27 23:08:40 +0000684 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000685
Greg Claytonb9556ac2012-01-30 07:41:31 +0000686 SBTarget sb_target;
687 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000688 if (m_opaque_sp)
689 {
Greg Clayton66111032010-06-23 01:19:29 +0000690 Error error;
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000691 const bool add_dependent_modules = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000692
Greg Claytona0ca6602012-10-18 16:33:33 +0000693 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
694 filename,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000695 arch_cstr,
696 add_dependent_modules,
697 NULL,
698 target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000699
700 if (error.Success())
701 {
Jim Ingham2976d002010-08-26 21:32:51 +0000702 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000703 sb_target.SetSP (target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000704 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000705 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000706
707 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000708 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)",
709 static_cast<void*>(m_opaque_sp.get()), filename, arch_cstr,
710 static_cast<void*>(target_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000711
Greg Claytonb9556ac2012-01-30 07:41:31 +0000712 return sb_target;
Greg Clayton66111032010-06-23 01:19:29 +0000713}
714
715SBTarget
716SBDebugger::CreateTarget (const char *filename)
717{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000718 SBTarget sb_target;
719 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000720 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000721 {
Greg Clayton66111032010-06-23 01:19:29 +0000722 Error error;
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000723 const bool add_dependent_modules = true;
Greg Claytonbf702ce2014-11-13 18:30:06 +0000724 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
Greg Claytona0ca6602012-10-18 16:33:33 +0000725 filename,
Greg Claytonbf702ce2014-11-13 18:30:06 +0000726 NULL,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000727 add_dependent_modules,
Greg Claytonbf702ce2014-11-13 18:30:06 +0000728 NULL,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000729 target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000730
731 if (error.Success())
732 {
Jim Ingham2976d002010-08-26 21:32:51 +0000733 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000734 sb_target.SetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000735 }
736 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000737 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000738 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000739 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
740 static_cast<void*>(m_opaque_sp.get()), filename,
741 static_cast<void*>(target_sp.get()));
Greg Claytonb9556ac2012-01-30 07:41:31 +0000742 return sb_target;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000743}
744
Johnny Chen3794ad92011-06-15 21:24:24 +0000745bool
746SBDebugger::DeleteTarget (lldb::SBTarget &target)
747{
748 bool result = false;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000749 if (m_opaque_sp)
Johnny Chen3794ad92011-06-15 21:24:24 +0000750 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000751 TargetSP target_sp(target.GetSP());
752 if (target_sp)
753 {
754 // No need to lock, the target list is thread safe
755 result = m_opaque_sp->GetTargetList().DeleteTarget (target_sp);
756 target_sp->Destroy();
757 target.Clear();
Greg Clayton0cd70862012-04-09 20:22:01 +0000758 const bool mandatory = true;
759 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Claytonb9556ac2012-01-30 07:41:31 +0000760 }
Johnny Chen3794ad92011-06-15 21:24:24 +0000761 }
762
Greg Clayton5160ce52013-03-27 23:08:40 +0000763 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen3794ad92011-06-15 21:24:24 +0000764 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000765 log->Printf ("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
766 static_cast<void*>(m_opaque_sp.get()),
767 static_cast<void*>(target.m_opaque_sp.get()), result);
Johnny Chen3794ad92011-06-15 21:24:24 +0000768
769 return result;
770}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000771SBTarget
772SBDebugger::GetTargetAtIndex (uint32_t idx)
773{
Greg Clayton66111032010-06-23 01:19:29 +0000774 SBTarget sb_target;
775 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000776 {
777 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000778 sb_target.SetSP (m_opaque_sp->GetTargetList().GetTargetAtIndex (idx));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000779 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000780 return sb_target;
781}
782
Jim Ingham8499e1a2012-05-08 23:06:07 +0000783uint32_t
784SBDebugger::GetIndexOfTarget (lldb::SBTarget target)
785{
786
787 lldb::TargetSP target_sp = target.GetSP();
788 if (!target_sp)
789 return UINT32_MAX;
790
791 if (!m_opaque_sp)
792 return UINT32_MAX;
793
794 return m_opaque_sp->GetTargetList().GetIndexOfTarget (target.GetSP());
795}
796
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000797SBTarget
Virgile Bello997f6f72013-09-05 16:53:14 +0000798SBDebugger::FindTargetWithProcessID (lldb::pid_t pid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000799{
Greg Clayton66111032010-06-23 01:19:29 +0000800 SBTarget sb_target;
801 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000802 {
803 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000804 sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000805 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000806 return sb_target;
807}
808
809SBTarget
810SBDebugger::FindTargetWithFileAndArch (const char *filename, const char *arch_name)
811{
Greg Clayton66111032010-06-23 01:19:29 +0000812 SBTarget sb_target;
813 if (m_opaque_sp && filename && filename[0])
814 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000815 // No need to lock, the target list is thread safe
Greg Claytoneb0103f2011-04-07 22:46:35 +0000816 ArchSpec arch (arch_name, m_opaque_sp->GetPlatformList().GetSelectedPlatform().get());
Greg Clayton274060b2010-10-20 20:54:39 +0000817 TargetSP target_sp (m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture (FileSpec(filename, false), arch_name ? &arch : NULL));
Greg Claytonb9556ac2012-01-30 07:41:31 +0000818 sb_target.SetSP (target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000819 }
820 return sb_target;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000821}
822
823SBTarget
Greg Clayton431ce672011-04-18 23:15:17 +0000824SBDebugger::FindTargetWithLLDBProcess (const ProcessSP &process_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000825{
Greg Clayton66111032010-06-23 01:19:29 +0000826 SBTarget sb_target;
827 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000828 {
829 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000830 sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get()));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000831 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000832 return sb_target;
833}
834
835
836uint32_t
837SBDebugger::GetNumTargets ()
838{
Greg Clayton66111032010-06-23 01:19:29 +0000839 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000840 {
841 // No need to lock, the target list is thread safe
Greg Clayton66111032010-06-23 01:19:29 +0000842 return m_opaque_sp->GetTargetList().GetNumTargets ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000843 }
Greg Clayton66111032010-06-23 01:19:29 +0000844 return 0;
845}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000846
847SBTarget
Jim Ingham2976d002010-08-26 21:32:51 +0000848SBDebugger::GetSelectedTarget ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000849{
Greg Clayton5160ce52013-03-27 23:08:40 +0000850 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000851
Greg Clayton66111032010-06-23 01:19:29 +0000852 SBTarget sb_target;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000853 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000854 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000855 {
856 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000857 target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget ();
858 sb_target.SetSP (target_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000859 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000860
861 if (log)
862 {
863 SBStream sstr;
Greg Clayton431ce672011-04-18 23:15:17 +0000864 sb_target.GetDescription (sstr, eDescriptionLevelBrief);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000865 log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
866 static_cast<void*>(m_opaque_sp.get()),
867 static_cast<void*>(target_sp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000868 }
869
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000870 return sb_target;
871}
872
873void
Jim Inghame64f0dc2011-09-13 23:25:31 +0000874SBDebugger::SetSelectedTarget (SBTarget &sb_target)
875{
Greg Clayton5160ce52013-03-27 23:08:40 +0000876 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghame64f0dc2011-09-13 23:25:31 +0000877
Greg Claytonb9556ac2012-01-30 07:41:31 +0000878 TargetSP target_sp (sb_target.GetSP());
Jim Inghame64f0dc2011-09-13 23:25:31 +0000879 if (m_opaque_sp)
880 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000881 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
Jim Inghame64f0dc2011-09-13 23:25:31 +0000882 }
883 if (log)
884 {
885 SBStream sstr;
886 sb_target.GetDescription (sstr, eDescriptionLevelBrief);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000887 log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
888 static_cast<void*>(m_opaque_sp.get()),
889 static_cast<void*>(target_sp.get()), sstr.GetData());
Jim Inghame64f0dc2011-09-13 23:25:31 +0000890 }
891}
892
Greg Claytonfbb76342013-11-20 21:07:01 +0000893SBPlatform
894SBDebugger::GetSelectedPlatform()
895{
896 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
897
898 SBPlatform sb_platform;
899 DebuggerSP debugger_sp(m_opaque_sp);
900 if (debugger_sp)
901 {
902 sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform());
903 }
904 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000905 log->Printf ("SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
906 static_cast<void*>(m_opaque_sp.get()),
907 static_cast<void*>(sb_platform.GetSP().get()),
908 sb_platform.GetName());
Greg Claytonfbb76342013-11-20 21:07:01 +0000909 return sb_platform;
910}
911
912void
913SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform)
914{
915 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000916
Greg Claytonfbb76342013-11-20 21:07:01 +0000917 DebuggerSP debugger_sp(m_opaque_sp);
918 if (debugger_sp)
919 {
920 debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP());
921 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000922
Greg Claytonfbb76342013-11-20 21:07:01 +0000923 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000924 log->Printf ("SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
925 static_cast<void*>(m_opaque_sp.get()),
926 static_cast<void*>(sb_platform.GetSP().get()),
927 sb_platform.GetName());
Greg Claytonfbb76342013-11-20 21:07:01 +0000928}
929
Jim Inghame64f0dc2011-09-13 23:25:31 +0000930void
Enrico Granatac30a73a2012-09-06 22:02:28 +0000931SBDebugger::DispatchInput (void* baton, const void *data, size_t data_len)
Enrico Granata6b09d422012-09-06 21:58:25 +0000932{
933 DispatchInput (data,data_len);
934}
935
936void
Filipe Cabecinhasc3019992012-08-20 16:21:04 +0000937SBDebugger::DispatchInput (const void *data, size_t data_len)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000938{
Greg Clayton44d93782014-01-27 23:43:24 +0000939// Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
940//
941// if (log)
942// log->Printf ("SBDebugger(%p)::DispatchInput (data=\"%.*s\", size_t=%" PRIu64 ")",
943// m_opaque_sp.get(),
944// (int) data_len,
945// (const char *) data,
946// (uint64_t)data_len);
947//
948// if (m_opaque_sp)
949// m_opaque_sp->DispatchInput ((const char *) data, data_len);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000950}
951
952void
Caroline Ticeefed6132010-11-19 20:47:54 +0000953SBDebugger::DispatchInputInterrupt ()
954{
955 if (m_opaque_sp)
956 m_opaque_sp->DispatchInputInterrupt ();
957}
958
959void
960SBDebugger::DispatchInputEndOfFile ()
961{
962 if (m_opaque_sp)
963 m_opaque_sp->DispatchInputEndOfFile ();
964}
965
966void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000967SBDebugger::PushInputReader (SBInputReader &reader)
968{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000969}
Greg Clayton66111032010-06-23 01:19:29 +0000970
971void
Greg Clayton44d93782014-01-27 23:43:24 +0000972SBDebugger::RunCommandInterpreter (bool auto_handle_events,
973 bool spawn_thread)
Caroline Tice969ed3d2011-05-02 20:41:46 +0000974{
Caroline Tice969ed3d2011-05-02 20:41:46 +0000975 if (m_opaque_sp)
Jim Ingham26c7bf92014-10-11 00:38:27 +0000976 {
977 CommandInterpreterRunOptions options;
978
979 m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(auto_handle_events,
980 spawn_thread,
981 options);
982 }
983}
984
985void
986SBDebugger::RunCommandInterpreter (bool auto_handle_events,
987 bool spawn_thread,
988 SBCommandInterpreterRunOptions &options,
989 int &num_errors,
Jim Inghamffc9f1d2014-10-14 01:20:07 +0000990 bool &quit_requested,
991 bool &stopped_for_crash)
Jim Ingham26c7bf92014-10-11 00:38:27 +0000992
993{
994 if (m_opaque_sp)
995 {
996 CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
997 interp.RunCommandInterpreter(auto_handle_events, spawn_thread, options.ref());
998 num_errors = interp.GetNumErrors();
999 quit_requested = interp.GetQuitRequested();
Jim Inghamffc9f1d2014-10-14 01:20:07 +00001000 stopped_for_crash = interp.GetStoppedForCrash();
Jim Ingham26c7bf92014-10-11 00:38:27 +00001001 }
Caroline Tice969ed3d2011-05-02 20:41:46 +00001002}
1003
Sean Callanan3e7e9152015-10-20 00:23:46 +00001004SBError
1005SBDebugger::RunREPL (lldb::LanguageType language, const char *repl_options)
1006{
1007 SBError error;
1008 if (m_opaque_sp)
1009 error.ref() = m_opaque_sp->RunREPL(language, repl_options);
1010 else
1011 error.SetErrorString ("invalid debugger");
1012 return error;
1013}
1014
Caroline Tice969ed3d2011-05-02 20:41:46 +00001015void
Greg Clayton431ce672011-04-18 23:15:17 +00001016SBDebugger::reset (const DebuggerSP &debugger_sp)
Greg Clayton66111032010-06-23 01:19:29 +00001017{
1018 m_opaque_sp = debugger_sp;
1019}
1020
1021Debugger *
1022SBDebugger::get () const
1023{
1024 return m_opaque_sp.get();
1025}
1026
1027Debugger &
1028SBDebugger::ref () const
1029{
1030 assert (m_opaque_sp.get());
1031 return *m_opaque_sp;
1032}
1033
Greg Clayton9a377662011-10-01 02:59:24 +00001034const lldb::DebuggerSP &
1035SBDebugger::get_sp () const
1036{
1037 return m_opaque_sp;
1038}
Greg Clayton66111032010-06-23 01:19:29 +00001039
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001040SBDebugger
1041SBDebugger::FindDebuggerWithID (int id)
1042{
Greg Claytonaf67cec2010-12-20 20:49:23 +00001043 // No need to lock, the debugger list is thread safe
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001044 SBDebugger sb_debugger;
Greg Clayton431ce672011-04-18 23:15:17 +00001045 DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id);
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001046 if (debugger_sp)
1047 sb_debugger.reset (debugger_sp);
1048 return sb_debugger;
1049}
Jim Inghame40e4212010-08-30 19:44:40 +00001050
Caroline Ticedd759852010-09-09 17:45:09 +00001051const char *
1052SBDebugger::GetInstanceName()
1053{
Greg Clayton6920b522012-08-22 18:39:03 +00001054 if (m_opaque_sp)
1055 return m_opaque_sp->GetInstanceName().AsCString();
1056 else
Caroline Ticedd759852010-09-09 17:45:09 +00001057 return NULL;
1058}
1059
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001060SBError
Caroline Ticedd759852010-09-09 17:45:09 +00001061SBDebugger::SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001062{
Greg Clayton6920b522012-08-22 18:39:03 +00001063 SBError sb_error;
1064 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName (ConstString(debugger_instance_name)));
1065 Error error;
1066 if (debugger_sp)
1067 {
1068 ExecutionContext exe_ctx (debugger_sp->GetCommandInterpreter().GetExecutionContext());
1069 error = debugger_sp->SetPropertyValue (&exe_ctx,
1070 eVarSetOperationAssign,
1071 var_name,
1072 value);
1073 }
1074 else
1075 {
1076 error.SetErrorStringWithFormat ("invalid debugger instance name '%s'", debugger_instance_name);
1077 }
1078 if (error.Fail())
1079 sb_error.SetError(error);
1080 return sb_error;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001081}
1082
Greg Clayton431ce672011-04-18 23:15:17 +00001083SBStringList
Caroline Ticedd759852010-09-09 17:45:09 +00001084SBDebugger::GetInternalVariableValue (const char *var_name, const char *debugger_instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001085{
1086 SBStringList ret_value;
Greg Clayton6920b522012-08-22 18:39:03 +00001087 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName (ConstString(debugger_instance_name)));
1088 Error error;
1089 if (debugger_sp)
1090 {
1091 ExecutionContext exe_ctx (debugger_sp->GetCommandInterpreter().GetExecutionContext());
1092 lldb::OptionValueSP value_sp (debugger_sp->GetPropertyValue (&exe_ctx,
1093 var_name,
1094 false,
1095 error));
1096 if (value_sp)
1097 {
1098 StreamString value_strm;
1099 value_sp->DumpValue (&exe_ctx, value_strm, OptionValue::eDumpOptionValue);
1100 const std::string &value_str = value_strm.GetString();
1101 if (!value_str.empty())
1102 {
1103 StringList string_list;
Greg Clayton44d93782014-01-27 23:43:24 +00001104 string_list.SplitIntoLines(value_str);
Greg Clayton6920b522012-08-22 18:39:03 +00001105 return SBStringList(&string_list);
1106 }
1107 }
1108 }
1109 return SBStringList();
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001110}
1111
Greg Claytona7015092010-09-18 01:14:36 +00001112uint32_t
1113SBDebugger::GetTerminalWidth () const
1114{
1115 if (m_opaque_sp)
1116 return m_opaque_sp->GetTerminalWidth ();
1117 return 0;
1118}
1119
1120void
1121SBDebugger::SetTerminalWidth (uint32_t term_width)
1122{
1123 if (m_opaque_sp)
1124 m_opaque_sp->SetTerminalWidth (term_width);
1125}
1126
1127const char *
1128SBDebugger::GetPrompt() const
1129{
Greg Clayton5160ce52013-03-27 23:08:40 +00001130 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001131
Caroline Ticeceb6b132010-10-26 03:11:13 +00001132 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001133 log->Printf ("SBDebugger(%p)::GetPrompt () => \"%s\"",
1134 static_cast<void*>(m_opaque_sp.get()),
Caroline Tice750cd172010-10-26 23:49:36 +00001135 (m_opaque_sp ? m_opaque_sp->GetPrompt() : ""));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001136
Greg Claytona7015092010-09-18 01:14:36 +00001137 if (m_opaque_sp)
1138 return m_opaque_sp->GetPrompt ();
1139 return 0;
1140}
1141
1142void
1143SBDebugger::SetPrompt (const char *prompt)
1144{
1145 if (m_opaque_sp)
1146 m_opaque_sp->SetPrompt (prompt);
1147}
1148
1149
Greg Clayton431ce672011-04-18 23:15:17 +00001150ScriptLanguage
Greg Claytona7015092010-09-18 01:14:36 +00001151SBDebugger::GetScriptLanguage() const
1152{
1153 if (m_opaque_sp)
1154 return m_opaque_sp->GetScriptLanguage ();
1155 return eScriptLanguageNone;
1156}
1157
1158void
Greg Clayton431ce672011-04-18 23:15:17 +00001159SBDebugger::SetScriptLanguage (ScriptLanguage script_lang)
Greg Claytona7015092010-09-18 01:14:36 +00001160{
1161 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001162 {
Greg Claytona7015092010-09-18 01:14:36 +00001163 m_opaque_sp->SetScriptLanguage (script_lang);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001164 }
Greg Claytona7015092010-09-18 01:14:36 +00001165}
1166
Jim Inghame40e4212010-08-30 19:44:40 +00001167bool
1168SBDebugger::SetUseExternalEditor (bool value)
1169{
1170 if (m_opaque_sp)
1171 return m_opaque_sp->SetUseExternalEditor (value);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001172 return false;
Jim Inghame40e4212010-08-30 19:44:40 +00001173}
1174
1175bool
Caroline Ticedaccaa92010-09-20 20:44:43 +00001176SBDebugger::GetUseExternalEditor ()
Jim Inghame40e4212010-08-30 19:44:40 +00001177{
1178 if (m_opaque_sp)
Caroline Ticedaccaa92010-09-20 20:44:43 +00001179 return m_opaque_sp->GetUseExternalEditor ();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001180 return false;
Jim Inghame40e4212010-08-30 19:44:40 +00001181}
1182
Caroline Ticedde9cff2010-09-20 05:20:02 +00001183bool
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001184SBDebugger::SetUseColor (bool value)
1185{
1186 if (m_opaque_sp)
1187 return m_opaque_sp->SetUseColor (value);
1188 return false;
1189}
1190
1191bool
1192SBDebugger::GetUseColor () const
1193{
1194 if (m_opaque_sp)
1195 return m_opaque_sp->GetUseColor ();
1196 return false;
1197}
1198
1199bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001200SBDebugger::GetDescription (SBStream &description)
1201{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001202 Stream &strm = description.ref();
1203
Caroline Ticedde9cff2010-09-20 05:20:02 +00001204 if (m_opaque_sp)
1205 {
1206 const char *name = m_opaque_sp->GetInstanceName().AsCString();
Greg Clayton431ce672011-04-18 23:15:17 +00001207 user_id_t id = m_opaque_sp->GetID();
Daniel Malead01b2952012-11-29 21:49:15 +00001208 strm.Printf ("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001209 }
1210 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001211 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +00001212
1213 return true;
1214}
Caroline Ticeefed6132010-11-19 20:47:54 +00001215
Greg Clayton431ce672011-04-18 23:15:17 +00001216user_id_t
Caroline Ticeefed6132010-11-19 20:47:54 +00001217SBDebugger::GetID()
1218{
1219 if (m_opaque_sp)
1220 return m_opaque_sp->GetID();
1221 return LLDB_INVALID_UID;
1222}
Greg Clayton2289fa42011-04-30 01:09:13 +00001223
1224
1225SBError
Greg Clayton615eb7e2014-09-19 20:11:50 +00001226SBDebugger::SetCurrentPlatform (const char *platform_name_cstr)
Greg Clayton2289fa42011-04-30 01:09:13 +00001227{
1228 SBError sb_error;
1229 if (m_opaque_sp)
1230 {
Greg Clayton615eb7e2014-09-19 20:11:50 +00001231 if (platform_name_cstr && platform_name_cstr[0])
Greg Clayton2289fa42011-04-30 01:09:13 +00001232 {
Greg Clayton615eb7e2014-09-19 20:11:50 +00001233 ConstString platform_name (platform_name_cstr);
1234 PlatformSP platform_sp (Platform::Find (platform_name));
1235
1236 if (platform_sp)
1237 {
1238 // Already have a platform with this name, just select it
1239 m_opaque_sp->GetPlatformList().SetSelectedPlatform(platform_sp);
1240 }
1241 else
1242 {
1243 // We don't have a platform by this name yet, create one
1244 platform_sp = Platform::Create (platform_name, sb_error.ref());
1245 if (platform_sp)
1246 {
1247 // We created the platform, now append and select it
1248 bool make_selected = true;
1249 m_opaque_sp->GetPlatformList().Append (platform_sp, make_selected);
1250 }
1251 }
Greg Clayton2289fa42011-04-30 01:09:13 +00001252 }
Greg Clayton615eb7e2014-09-19 20:11:50 +00001253 else
1254 {
1255 sb_error.ref().SetErrorString("invalid platform name");
1256 }
1257 }
1258 else
1259 {
1260 sb_error.ref().SetErrorString("invalid debugger");
Greg Clayton2289fa42011-04-30 01:09:13 +00001261 }
1262 return sb_error;
1263}
1264
Greg Claytonfc3f0272011-05-29 04:06:55 +00001265bool
Greg Claytonf3dd93c2011-06-17 03:31:01 +00001266SBDebugger::SetCurrentPlatformSDKRoot (const char *sysroot)
1267{
1268 if (m_opaque_sp)
1269 {
1270 PlatformSP platform_sp (m_opaque_sp->GetPlatformList().GetSelectedPlatform());
1271
1272 if (platform_sp)
1273 {
1274 platform_sp->SetSDKRootDirectory (ConstString (sysroot));
1275 return true;
1276 }
1277 }
1278 return false;
1279}
1280
1281bool
Greg Claytonfc3f0272011-05-29 04:06:55 +00001282SBDebugger::GetCloseInputOnEOF () const
1283{
1284 if (m_opaque_sp)
1285 return m_opaque_sp->GetCloseInputOnEOF ();
1286 return false;
1287}
1288
1289void
1290SBDebugger::SetCloseInputOnEOF (bool b)
1291{
1292 if (m_opaque_sp)
1293 m_opaque_sp->SetCloseInputOnEOF (b);
1294}
Enrico Granata061858c2012-02-15 02:34:21 +00001295
1296SBTypeCategory
1297SBDebugger::GetCategory (const char* category_name)
1298{
1299 if (!category_name || *category_name == 0)
1300 return SBTypeCategory();
1301
1302 TypeCategoryImplSP category_sp;
1303
1304 if (DataVisualization::Categories::GetCategory(ConstString(category_name), category_sp, false))
1305 return SBTypeCategory(category_sp);
1306 else
1307 return SBTypeCategory();
1308}
1309
1310SBTypeCategory
1311SBDebugger::CreateCategory (const char* category_name)
1312{
1313 if (!category_name || *category_name == 0)
1314 return SBTypeCategory();
1315
1316 TypeCategoryImplSP category_sp;
1317
1318 if (DataVisualization::Categories::GetCategory(ConstString(category_name), category_sp, true))
1319 return SBTypeCategory(category_sp);
1320 else
1321 return SBTypeCategory();
1322}
1323
1324bool
1325SBDebugger::DeleteCategory (const char* category_name)
1326{
1327 if (!category_name || *category_name == 0)
1328 return false;
1329
1330 return DataVisualization::Categories::Delete(ConstString(category_name));
1331}
1332
1333uint32_t
1334SBDebugger::GetNumCategories()
1335{
1336 return DataVisualization::Categories::GetCount();
1337}
1338
1339SBTypeCategory
1340SBDebugger::GetCategoryAtIndex (uint32_t index)
1341{
1342 return SBTypeCategory(DataVisualization::Categories::GetCategoryAtIndex(index));
1343}
1344
1345SBTypeCategory
1346SBDebugger::GetDefaultCategory()
1347{
1348 return GetCategory("default");
1349}
1350
1351SBTypeFormat
1352SBDebugger::GetFormatForType (SBTypeNameSpecifier type_name)
1353{
1354 SBTypeCategory default_category_sb = GetDefaultCategory();
1355 if (default_category_sb.GetEnabled())
1356 return default_category_sb.GetFormatForType(type_name);
1357 return SBTypeFormat();
1358}
1359
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001360#ifndef LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001361SBTypeSummary
1362SBDebugger::GetSummaryForType (SBTypeNameSpecifier type_name)
1363{
Enrico Granataa777dc22012-05-08 21:49:57 +00001364 if (type_name.IsValid() == false)
1365 return SBTypeSummary();
1366 return SBTypeSummary(DataVisualization::GetSummaryForType(type_name.GetSP()));
Enrico Granata061858c2012-02-15 02:34:21 +00001367}
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001368#endif // LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001369
1370SBTypeFilter
1371SBDebugger::GetFilterForType (SBTypeNameSpecifier type_name)
1372{
Enrico Granataa777dc22012-05-08 21:49:57 +00001373 if (type_name.IsValid() == false)
1374 return SBTypeFilter();
1375 return SBTypeFilter(DataVisualization::GetFilterForType(type_name.GetSP()));
Enrico Granata061858c2012-02-15 02:34:21 +00001376}
1377
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001378#ifndef LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001379SBTypeSynthetic
1380SBDebugger::GetSyntheticForType (SBTypeNameSpecifier type_name)
1381{
Enrico Granataa777dc22012-05-08 21:49:57 +00001382 if (type_name.IsValid() == false)
1383 return SBTypeSynthetic();
1384 return SBTypeSynthetic(DataVisualization::GetSyntheticForType(type_name.GetSP()));
Enrico Granata061858c2012-02-15 02:34:21 +00001385}
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001386#endif // LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001387
Jim Ingham228063c2012-02-21 02:23:08 +00001388bool
1389SBDebugger::EnableLog (const char *channel, const char **categories)
1390{
1391 if (m_opaque_sp)
1392 {
1393 uint32_t log_options = LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1394 StreamString errors;
1395 return m_opaque_sp->EnableLog (channel, categories, NULL, log_options, errors);
1396
1397 }
1398 else
1399 return false;
1400}
Jim Ingham4f02b222012-02-22 22:49:20 +00001401
1402void
1403SBDebugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
1404{
1405 if (m_opaque_sp)
1406 {
1407 return m_opaque_sp->SetLoggingCallback (log_callback, baton);
1408 }
1409}
1410
1411