blob: 042e9c69cab6da2d45fca78d3478d7137ea35806 [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
Zachary Turnere6e2bb32015-03-31 21:03:22 +000046#include "llvm/Support/ManagedStatic.h"
Zachary Turner58a559c2014-08-27 20:15:09 +000047#include "llvm/Support/DynamicLibrary.h"
48
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049using namespace lldb;
50using namespace lldb_private;
51
Greg Clayton5fb8f792013-12-02 19:35:49 +000052
Zachary Turner58a559c2014-08-27 20:15:09 +000053static llvm::sys::DynamicLibrary
Greg Clayton5fb8f792013-12-02 19:35:49 +000054LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& error)
55{
Zachary Turner58a559c2014-08-27 20:15:09 +000056 llvm::sys::DynamicLibrary dynlib = llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
57 if (dynlib.isValid())
Greg Clayton5fb8f792013-12-02 19:35:49 +000058 {
59 typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger);
60
61 lldb::SBDebugger debugger_sb(debugger_sp);
62 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) function.
63 // 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 +000064 LLDBCommandPluginInit init_func = (LLDBCommandPluginInit)dynlib.getAddressOfSymbol("_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
Greg Clayton5fb8f792013-12-02 19:35:49 +000065 if (init_func)
66 {
67 if (init_func(debugger_sb))
Zachary Turner58a559c2014-08-27 20:15:09 +000068 return dynlib;
Greg Clayton5fb8f792013-12-02 19:35:49 +000069 else
70 error.SetErrorString("plug-in refused to load (lldb::PluginInitialize(lldb::SBDebugger) returned false)");
71 }
72 else
73 {
74 error.SetErrorString("plug-in is missing the required initialization: lldb::PluginInitialize(lldb::SBDebugger)");
75 }
76 }
77 else
78 {
79 if (spec.Exists())
80 error.SetErrorString("this file does not represent a loadable dylib");
81 else
82 error.SetErrorString("no such file");
83 }
Zachary Turner58a559c2014-08-27 20:15:09 +000084 return llvm::sys::DynamicLibrary();
Greg Clayton5fb8f792013-12-02 19:35:49 +000085}
86
Zachary Turnere6e2bb32015-03-31 21:03:22 +000087static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime;
88
89SBInputReader::SBInputReader()
90{
91}
92SBInputReader::~SBInputReader()
93{
94}
95
96SBError
97SBInputReader::Initialize(lldb::SBDebugger &sb_debugger,
98 unsigned long (*)(void *, lldb::SBInputReader *, lldb::InputReaderAction, char const *,
99 unsigned long),
100 void *, lldb::InputReaderGranularity, char const *, char const *, bool)
101{
102 return SBError();
103}
104
105void
106SBInputReader::SetIsDone(bool)
107{
108}
109bool
110SBInputReader::IsActive() const
111{
112 return false;
113}
114
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000115void
116SBDebugger::Initialize ()
117{
Greg Clayton5160ce52013-03-27 23:08:40 +0000118 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000119
120 if (log)
121 log->Printf ("SBDebugger::Initialize ()");
122
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000123 g_debugger_lifetime->Initialize(llvm::make_unique<SystemInitializerFull>(), LoadPlugin);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000124}
125
126void
127SBDebugger::Terminate ()
128{
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000129 g_debugger_lifetime->Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000130}
131
Greg Clayton48e42542010-07-30 20:12:55 +0000132void
133SBDebugger::Clear ()
134{
Greg Clayton5160ce52013-03-27 23:08:40 +0000135 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000136
137 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000138 log->Printf ("SBDebugger(%p)::Clear ()",
139 static_cast<void*>(m_opaque_sp.get()));
140
Caroline Tice3d6086f2010-12-20 18:35:50 +0000141 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000142 m_opaque_sp->ClearIOHandlers ();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000143
Greg Clayton48e42542010-07-30 20:12:55 +0000144 m_opaque_sp.reset();
145}
146
Greg Clayton66111032010-06-23 01:19:29 +0000147SBDebugger
148SBDebugger::Create()
149{
Jim Ingham228063c2012-02-21 02:23:08 +0000150 return SBDebugger::Create(false, NULL, NULL);
Jim Ingham06942692011-08-13 00:22:20 +0000151}
152
153SBDebugger
154SBDebugger::Create(bool source_init_files)
155{
Jim Ingham228063c2012-02-21 02:23:08 +0000156 return SBDebugger::Create (source_init_files, NULL, NULL);
157}
158
159SBDebugger
160SBDebugger::Create(bool source_init_files, lldb::LogOutputCallback callback, void *baton)
161
162{
Greg Clayton5160ce52013-03-27 23:08:40 +0000163 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000164
Greg Clayton66111032010-06-23 01:19:29 +0000165 SBDebugger debugger;
Greg Claytoncb172b12014-05-19 20:42:14 +0000166
167 // Currently we have issues if this function is called simultaneously on two different
168 // threads. The issues mainly revolve around the fact that the lldb_private::FormatManager
169 // uses global collections and having two threads parsing the .lldbinit files can cause
170 // mayhem. So to get around this for now we need to use a mutex to prevent bad things
171 // from happening.
172 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
173 Mutex::Locker locker(g_mutex);
174
Jim Ingham228063c2012-02-21 02:23:08 +0000175 debugger.reset(Debugger::CreateInstance(callback, baton));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000176
177 if (log)
178 {
179 SBStream sstr;
180 debugger.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000181 log->Printf ("SBDebugger::Create () => SBDebugger(%p): %s",
182 static_cast<void*>(debugger.m_opaque_sp.get()),
183 sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000184 }
185
Jim Ingham06942692011-08-13 00:22:20 +0000186 SBCommandInterpreter interp = debugger.GetCommandInterpreter();
187 if (source_init_files)
188 {
189 interp.get()->SkipLLDBInitFiles(false);
190 interp.get()->SkipAppInitFiles (false);
191 SBCommandReturnObject result;
192 interp.SourceInitFileInHomeDirectory(result);
193 }
194 else
195 {
196 interp.get()->SkipLLDBInitFiles(true);
197 interp.get()->SkipAppInitFiles (true);
198 }
Greg Clayton66111032010-06-23 01:19:29 +0000199 return debugger;
200}
201
Caroline Ticee02657b2011-01-22 01:02:07 +0000202void
203SBDebugger::Destroy (SBDebugger &debugger)
204{
Greg Clayton5160ce52013-03-27 23:08:40 +0000205 Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000206
Caroline Ticee02657b2011-01-22 01:02:07 +0000207 if (log)
208 {
209 SBStream sstr;
210 debugger.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000211 log->Printf ("SBDebugger::Destroy () => SBDebugger(%p): %s",
212 static_cast<void*>(debugger.m_opaque_sp.get()),
213 sstr.GetData());
Caroline Ticee02657b2011-01-22 01:02:07 +0000214 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000215
Caroline Ticee02657b2011-01-22 01:02:07 +0000216 Debugger::Destroy (debugger.m_opaque_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000217
Caroline Ticee02657b2011-01-22 01:02:07 +0000218 if (debugger.m_opaque_sp.get() != NULL)
219 debugger.m_opaque_sp.reset();
220}
221
Greg Claytonf9322412011-12-15 04:38:41 +0000222void
223SBDebugger::MemoryPressureDetected ()
224{
Greg Clayton0cd70862012-04-09 20:22:01 +0000225 // Since this function can be call asynchronously, we allow it to be
226 // non-mandatory. We have seen deadlocks with this function when called
227 // so we need to safeguard against this until we can determine what is
228 // causing the deadlocks.
Greg Clayton5160ce52013-03-27 23:08:40 +0000229 Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamaebdf1b2012-06-07 19:08:07 +0000230
Greg Clayton0cd70862012-04-09 20:22:01 +0000231 const bool mandatory = false;
Jim Inghamaebdf1b2012-06-07 19:08:07 +0000232 if (log)
233 {
234 log->Printf ("SBDebugger::MemoryPressureDetected (), mandatory = %d", mandatory);
235 }
236
Greg Clayton0cd70862012-04-09 20:22:01 +0000237 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Claytonf9322412011-12-15 04:38:41 +0000238}
239
Greg Clayton66111032010-06-23 01:19:29 +0000240SBDebugger::SBDebugger () :
241 m_opaque_sp ()
242{
243}
244
Enrico Granata274fd6e2011-08-19 23:56:34 +0000245SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp) :
246 m_opaque_sp(debugger_sp)
247{
248}
249
Greg Claytonefabb122010-11-05 23:17:00 +0000250SBDebugger::SBDebugger(const SBDebugger &rhs) :
251 m_opaque_sp (rhs.m_opaque_sp)
252{
253}
254
255SBDebugger &
256SBDebugger::operator = (const SBDebugger &rhs)
257{
258 if (this != &rhs)
259 {
260 m_opaque_sp = rhs.m_opaque_sp;
261 }
262 return *this;
263}
264
Greg Clayton66111032010-06-23 01:19:29 +0000265SBDebugger::~SBDebugger ()
266{
267}
268
269bool
270SBDebugger::IsValid() const
271{
272 return m_opaque_sp.get() != NULL;
273}
274
275
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000276void
277SBDebugger::SetAsync (bool b)
278{
Greg Clayton66111032010-06-23 01:19:29 +0000279 if (m_opaque_sp)
280 m_opaque_sp->SetAsyncExecution(b);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000281}
282
Jim Inghame64f0dc2011-09-13 23:25:31 +0000283bool
284SBDebugger::GetAsync ()
285{
286 if (m_opaque_sp)
287 return m_opaque_sp->GetAsyncExecution();
288 else
289 return false;
290}
291
Greg Clayton6eee5aa2010-10-11 01:05:37 +0000292void
293SBDebugger::SkipLLDBInitFiles (bool b)
294{
295 if (m_opaque_sp)
296 m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles (b);
297}
298
Jim Ingham16e0c682011-08-12 23:34:31 +0000299void
300SBDebugger::SkipAppInitFiles (bool b)
301{
302 if (m_opaque_sp)
303 m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles (b);
304}
305
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000306// Shouldn't really be settable after initialization as this could cause lots of problems; don't want users
307// trying to switch modes in the middle of a debugging session.
308void
309SBDebugger::SetInputFileHandle (FILE *fh, bool transfer_ownership)
310{
Greg Clayton5160ce52013-03-27 23:08:40 +0000311 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000312
313 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000314 log->Printf ("SBDebugger(%p)::SetInputFileHandle (fh=%p, transfer_ownership=%i)",
315 static_cast<void*>(m_opaque_sp.get()),
316 static_cast<void*>(fh), transfer_ownership);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000317
Greg Clayton66111032010-06-23 01:19:29 +0000318 if (m_opaque_sp)
319 m_opaque_sp->SetInputFileHandle (fh, transfer_ownership);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000320}
321
322void
323SBDebugger::SetOutputFileHandle (FILE *fh, bool transfer_ownership)
324{
Greg Clayton5160ce52013-03-27 23:08:40 +0000325 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000326
327
328 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000329 log->Printf ("SBDebugger(%p)::SetOutputFileHandle (fh=%p, transfer_ownership=%i)",
330 static_cast<void*>(m_opaque_sp.get()),
331 static_cast<void*>(fh), transfer_ownership);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000332
Greg Clayton66111032010-06-23 01:19:29 +0000333 if (m_opaque_sp)
334 m_opaque_sp->SetOutputFileHandle (fh, transfer_ownership);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000335}
336
337void
338SBDebugger::SetErrorFileHandle (FILE *fh, bool transfer_ownership)
339{
Greg Clayton5160ce52013-03-27 23:08:40 +0000340 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000341
342
343 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000344 log->Printf ("SBDebugger(%p)::SetErrorFileHandle (fh=%p, transfer_ownership=%i)",
345 static_cast<void*>(m_opaque_sp.get()),
346 static_cast<void*>(fh), transfer_ownership);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000347
Greg Clayton66111032010-06-23 01:19:29 +0000348 if (m_opaque_sp)
349 m_opaque_sp->SetErrorFileHandle (fh, transfer_ownership);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000350}
351
352FILE *
353SBDebugger::GetInputFileHandle ()
354{
Greg Clayton66111032010-06-23 01:19:29 +0000355 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000356 {
357 StreamFileSP stream_file_sp (m_opaque_sp->GetInputFile());
358 if (stream_file_sp)
359 return stream_file_sp->GetFile().GetStream();
360 }
Greg Clayton66111032010-06-23 01:19:29 +0000361 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000362}
363
364FILE *
365SBDebugger::GetOutputFileHandle ()
366{
Greg Clayton66111032010-06-23 01:19:29 +0000367 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000368 {
369 StreamFileSP stream_file_sp (m_opaque_sp->GetOutputFile());
370 if (stream_file_sp)
371 return stream_file_sp->GetFile().GetStream();
372 }
Greg Clayton66111032010-06-23 01:19:29 +0000373 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000374}
375
376FILE *
377SBDebugger::GetErrorFileHandle ()
378{
Greg Clayton66111032010-06-23 01:19:29 +0000379 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000380 if (m_opaque_sp)
381 {
382 StreamFileSP stream_file_sp (m_opaque_sp->GetErrorFile());
383 if (stream_file_sp)
384 return stream_file_sp->GetFile().GetStream();
385 }
Greg Clayton66111032010-06-23 01:19:29 +0000386 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000387}
388
Jim Inghamc5917d92012-11-30 20:23:19 +0000389void
390SBDebugger::SaveInputTerminalState()
391{
392 if (m_opaque_sp)
393 m_opaque_sp->SaveInputTerminalState();
394}
395
396void
397SBDebugger::RestoreInputTerminalState()
398{
399 if (m_opaque_sp)
400 m_opaque_sp->RestoreInputTerminalState();
401
402}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000403SBCommandInterpreter
404SBDebugger::GetCommandInterpreter ()
405{
Greg Clayton5160ce52013-03-27 23:08:40 +0000406 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000407
Greg Clayton66111032010-06-23 01:19:29 +0000408 SBCommandInterpreter sb_interpreter;
409 if (m_opaque_sp)
410 sb_interpreter.reset (&m_opaque_sp->GetCommandInterpreter());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000411
Caroline Tice750cd172010-10-26 23:49:36 +0000412 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000413 log->Printf ("SBDebugger(%p)::GetCommandInterpreter () => SBCommandInterpreter(%p)",
414 static_cast<void*>(m_opaque_sp.get()),
415 static_cast<void*>(sb_interpreter.get()));
Caroline Tice750cd172010-10-26 23:49:36 +0000416
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000417 return sb_interpreter;
418}
419
420void
421SBDebugger::HandleCommand (const char *command)
422{
Greg Clayton66111032010-06-23 01:19:29 +0000423 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000424 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000425 TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
426 Mutex::Locker api_locker;
427 if (target_sp)
Jim Ingham10ebffa2012-05-04 23:02:50 +0000428 api_locker.Lock(target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000429
Greg Clayton66111032010-06-23 01:19:29 +0000430 SBCommandInterpreter sb_interpreter(GetCommandInterpreter ());
431 SBCommandReturnObject result;
432
433 sb_interpreter.HandleCommand (command, result, false);
434
435 if (GetErrorFileHandle() != NULL)
436 result.PutError (GetErrorFileHandle());
437 if (GetOutputFileHandle() != NULL)
438 result.PutOutput (GetOutputFileHandle());
439
440 if (m_opaque_sp->GetAsyncExecution() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000441 {
Greg Clayton66111032010-06-23 01:19:29 +0000442 SBProcess process(GetCommandInterpreter().GetProcess ());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000443 ProcessSP process_sp (process.GetSP());
444 if (process_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000445 {
Greg Clayton66111032010-06-23 01:19:29 +0000446 EventSP event_sp;
447 Listener &lldb_listener = m_opaque_sp->GetListener();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000448 while (lldb_listener.GetNextEventForBroadcaster (process_sp.get(), event_sp))
Greg Clayton66111032010-06-23 01:19:29 +0000449 {
450 SBEvent event(event_sp);
451 HandleProcessEvent (process, event, GetOutputFileHandle(), GetErrorFileHandle());
452 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000453 }
454 }
455 }
456}
457
458SBListener
459SBDebugger::GetListener ()
460{
Greg Clayton5160ce52013-03-27 23:08:40 +0000461 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000462
Greg Clayton66111032010-06-23 01:19:29 +0000463 SBListener sb_listener;
464 if (m_opaque_sp)
465 sb_listener.reset(&m_opaque_sp->GetListener(), false);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000466
Caroline Tice750cd172010-10-26 23:49:36 +0000467 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000468 log->Printf ("SBDebugger(%p)::GetListener () => SBListener(%p)",
469 static_cast<void*>(m_opaque_sp.get()),
470 static_cast<void*>(sb_listener.get()));
Caroline Tice750cd172010-10-26 23:49:36 +0000471
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000472 return sb_listener;
473}
474
475void
476SBDebugger::HandleProcessEvent (const SBProcess &process, const SBEvent &event, FILE *out, FILE *err)
477{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000478 if (!process.IsValid())
479 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000480
Greg Claytonb9556ac2012-01-30 07:41:31 +0000481 TargetSP target_sp (process.GetTarget().GetSP());
482 if (!target_sp)
483 return;
484
Greg Claytonaf67cec2010-12-20 20:49:23 +0000485 const uint32_t event_type = event.GetType();
486 char stdio_buffer[1024];
487 size_t len;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000488
Greg Claytonb9556ac2012-01-30 07:41:31 +0000489 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000490
491 if (event_type & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000492 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000493 // Drain stdout when we stop just in case we have any bytes
494 while ((len = process.GetSTDOUT (stdio_buffer, sizeof (stdio_buffer))) > 0)
495 if (out != NULL)
496 ::fwrite (stdio_buffer, 1, len, out);
497 }
498
499 if (event_type & (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged))
500 {
501 // Drain stderr when we stop just in case we have any bytes
502 while ((len = process.GetSTDERR (stdio_buffer, sizeof (stdio_buffer))) > 0)
503 if (err != NULL)
504 ::fwrite (stdio_buffer, 1, len, err);
505 }
506
507 if (event_type & Process::eBroadcastBitStateChanged)
508 {
509 StateType event_state = SBProcess::GetStateFromEvent (event);
510
511 if (event_state == eStateInvalid)
512 return;
513
514 bool is_stopped = StateIsStoppedState (event_state);
515 if (!is_stopped)
516 process.ReportEventState (event, out);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000517 }
518}
519
Jim Inghame37d6052011-09-13 00:29:56 +0000520SBSourceManager
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521SBDebugger::GetSourceManager ()
522{
Jim Inghame37d6052011-09-13 00:29:56 +0000523 SBSourceManager sb_source_manager (*this);
524 return sb_source_manager;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000525}
526
527
528bool
529SBDebugger::GetDefaultArchitecture (char *arch_name, size_t arch_name_len)
530{
531 if (arch_name && arch_name_len)
532 {
Greg Clayton431ce672011-04-18 23:15:17 +0000533 ArchSpec default_arch = Target::GetDefaultArchitecture ();
Caroline Ticedaccaa92010-09-20 20:44:43 +0000534
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000535 if (default_arch.IsValid())
536 {
Greg Clayton431ce672011-04-18 23:15:17 +0000537 const std::string &triple_str = default_arch.GetTriple().str();
538 if (!triple_str.empty())
539 ::snprintf (arch_name, arch_name_len, "%s", triple_str.c_str());
540 else
541 ::snprintf (arch_name, arch_name_len, "%s", default_arch.GetArchitectureName());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000542 return true;
543 }
544 }
545 if (arch_name && arch_name_len)
546 arch_name[0] = '\0';
547 return false;
548}
549
550
551bool
552SBDebugger::SetDefaultArchitecture (const char *arch_name)
553{
554 if (arch_name)
555 {
Greg Clayton70512312012-05-08 01:45:38 +0000556 ArchSpec arch (arch_name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000557 if (arch.IsValid())
558 {
Greg Clayton431ce672011-04-18 23:15:17 +0000559 Target::SetDefaultArchitecture (arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000560 return true;
561 }
562 }
563 return false;
564}
565
566ScriptLanguage
567SBDebugger::GetScriptingLanguage (const char *script_language_name)
568{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000569
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000570 return Args::StringToScriptLanguage (script_language_name,
571 eScriptLanguageDefault,
572 NULL);
573}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000574
575const char *
576SBDebugger::GetVersionString ()
577{
Virgile Bellob2f1fb22013-08-23 12:44:05 +0000578 return lldb_private::GetVersion();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000579}
580
581const char *
Greg Clayton431ce672011-04-18 23:15:17 +0000582SBDebugger::StateAsCString (StateType state)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000583{
Caroline Ticec2bbb492011-04-25 22:05:51 +0000584 return lldb_private::StateAsCString (state);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585}
586
587bool
Greg Clayton431ce672011-04-18 23:15:17 +0000588SBDebugger::StateIsRunningState (StateType state)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000589{
Greg Clayton5160ce52013-03-27 23:08:40 +0000590 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000591
Caroline Ticec2bbb492011-04-25 22:05:51 +0000592 const bool result = lldb_private::StateIsRunningState (state);
Greg Clayton48381312010-10-30 04:51:46 +0000593 if (log)
594 log->Printf ("SBDebugger::StateIsRunningState (state=%s) => %i",
Greg Clayton431ce672011-04-18 23:15:17 +0000595 StateAsCString (state), result);
Greg Clayton48381312010-10-30 04:51:46 +0000596
597 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000598}
599
600bool
Greg Clayton431ce672011-04-18 23:15:17 +0000601SBDebugger::StateIsStoppedState (StateType state)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000602{
Greg Clayton5160ce52013-03-27 23:08:40 +0000603 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000604
Greg Clayton2637f822011-11-17 01:23:07 +0000605 const bool result = lldb_private::StateIsStoppedState (state, false);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000606 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000607 log->Printf ("SBDebugger::StateIsStoppedState (state=%s) => %i",
Greg Clayton431ce672011-04-18 23:15:17 +0000608 StateAsCString (state), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000609
Greg Clayton48381312010-10-30 04:51:46 +0000610 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000611}
612
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000613lldb::SBTarget
614SBDebugger::CreateTarget (const char *filename,
615 const char *target_triple,
616 const char *platform_name,
617 bool add_dependent_modules,
618 lldb::SBError& sb_error)
619{
620 SBTarget sb_target;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000621 TargetSP target_sp;
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000622 if (m_opaque_sp)
623 {
624 sb_error.Clear();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000625 OptionGroupPlatform platform_options (false);
626 platform_options.SetPlatformName (platform_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000627
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000628 sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
Greg Claytona0ca6602012-10-18 16:33:33 +0000629 filename,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000630 target_triple,
631 add_dependent_modules,
632 &platform_options,
633 target_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000634
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000635 if (sb_error.Success())
Greg Claytonb9556ac2012-01-30 07:41:31 +0000636 sb_target.SetSP (target_sp);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000637 }
638 else
639 {
640 sb_error.SetErrorString("invalid target");
641 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000642
Greg Clayton5160ce52013-03-27 23:08:40 +0000643 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000644 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000645 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, platform_name=%s, add_dependent_modules=%u, error=%s) => SBTarget(%p)",
646 static_cast<void*>(m_opaque_sp.get()), filename,
647 target_triple, platform_name, add_dependent_modules,
648 sb_error.GetCString(), static_cast<void*>(target_sp.get()));
649
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000650 return sb_target;
651}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000652
653SBTarget
654SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename,
655 const char *target_triple)
656{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000657 SBTarget sb_target;
658 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000659 if (m_opaque_sp)
660 {
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000661 const bool add_dependent_modules = true;
662 Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
Greg Claytona0ca6602012-10-18 16:33:33 +0000663 filename,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000664 target_triple,
665 add_dependent_modules,
666 NULL,
667 target_sp));
Greg Claytonb9556ac2012-01-30 07:41:31 +0000668 sb_target.SetSP (target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000669 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000670
Greg Clayton5160ce52013-03-27 23:08:40 +0000671 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000672 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000673 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)",
674 static_cast<void*>(m_opaque_sp.get()), filename,
675 target_triple, static_cast<void*>(target_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000676
Greg Claytonb9556ac2012-01-30 07:41:31 +0000677 return sb_target;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000678}
679
680SBTarget
Greg Clayton64195a22011-02-23 00:35:02 +0000681SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_cstr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000682{
Greg Clayton5160ce52013-03-27 23:08:40 +0000683 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000684
Greg Claytonb9556ac2012-01-30 07:41:31 +0000685 SBTarget sb_target;
686 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000687 if (m_opaque_sp)
688 {
Greg Clayton66111032010-06-23 01:19:29 +0000689 Error error;
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000690 const bool add_dependent_modules = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000691
Greg Claytona0ca6602012-10-18 16:33:33 +0000692 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
693 filename,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000694 arch_cstr,
695 add_dependent_modules,
696 NULL,
697 target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000698
699 if (error.Success())
700 {
Jim Ingham2976d002010-08-26 21:32:51 +0000701 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000702 sb_target.SetSP (target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000703 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000704 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000705
706 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000707 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)",
708 static_cast<void*>(m_opaque_sp.get()), filename, arch_cstr,
709 static_cast<void*>(target_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000710
Greg Claytonb9556ac2012-01-30 07:41:31 +0000711 return sb_target;
Greg Clayton66111032010-06-23 01:19:29 +0000712}
713
714SBTarget
715SBDebugger::CreateTarget (const char *filename)
716{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000717 SBTarget sb_target;
718 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000719 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000720 {
Greg Clayton66111032010-06-23 01:19:29 +0000721 Error error;
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000722 const bool add_dependent_modules = true;
Greg Claytonbf702ce2014-11-13 18:30:06 +0000723 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
Greg Claytona0ca6602012-10-18 16:33:33 +0000724 filename,
Greg Claytonbf702ce2014-11-13 18:30:06 +0000725 NULL,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000726 add_dependent_modules,
Greg Claytonbf702ce2014-11-13 18:30:06 +0000727 NULL,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000728 target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000729
730 if (error.Success())
731 {
Jim Ingham2976d002010-08-26 21:32:51 +0000732 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000733 sb_target.SetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000734 }
735 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000736 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000737 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000738 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
739 static_cast<void*>(m_opaque_sp.get()), filename,
740 static_cast<void*>(target_sp.get()));
Greg Claytonb9556ac2012-01-30 07:41:31 +0000741 return sb_target;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000742}
743
Johnny Chen3794ad92011-06-15 21:24:24 +0000744bool
745SBDebugger::DeleteTarget (lldb::SBTarget &target)
746{
747 bool result = false;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000748 if (m_opaque_sp)
Johnny Chen3794ad92011-06-15 21:24:24 +0000749 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000750 TargetSP target_sp(target.GetSP());
751 if (target_sp)
752 {
753 // No need to lock, the target list is thread safe
754 result = m_opaque_sp->GetTargetList().DeleteTarget (target_sp);
755 target_sp->Destroy();
756 target.Clear();
Greg Clayton0cd70862012-04-09 20:22:01 +0000757 const bool mandatory = true;
758 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Claytonb9556ac2012-01-30 07:41:31 +0000759 }
Johnny Chen3794ad92011-06-15 21:24:24 +0000760 }
761
Greg Clayton5160ce52013-03-27 23:08:40 +0000762 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen3794ad92011-06-15 21:24:24 +0000763 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000764 log->Printf ("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
765 static_cast<void*>(m_opaque_sp.get()),
766 static_cast<void*>(target.m_opaque_sp.get()), result);
Johnny Chen3794ad92011-06-15 21:24:24 +0000767
768 return result;
769}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000770SBTarget
771SBDebugger::GetTargetAtIndex (uint32_t idx)
772{
Greg Clayton66111032010-06-23 01:19:29 +0000773 SBTarget sb_target;
774 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000775 {
776 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000777 sb_target.SetSP (m_opaque_sp->GetTargetList().GetTargetAtIndex (idx));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000778 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000779 return sb_target;
780}
781
Jim Ingham8499e1a2012-05-08 23:06:07 +0000782uint32_t
783SBDebugger::GetIndexOfTarget (lldb::SBTarget target)
784{
785
786 lldb::TargetSP target_sp = target.GetSP();
787 if (!target_sp)
788 return UINT32_MAX;
789
790 if (!m_opaque_sp)
791 return UINT32_MAX;
792
793 return m_opaque_sp->GetTargetList().GetIndexOfTarget (target.GetSP());
794}
795
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000796SBTarget
Virgile Bello997f6f72013-09-05 16:53:14 +0000797SBDebugger::FindTargetWithProcessID (lldb::pid_t pid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000798{
Greg Clayton66111032010-06-23 01:19:29 +0000799 SBTarget sb_target;
800 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000801 {
802 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000803 sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000804 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000805 return sb_target;
806}
807
808SBTarget
809SBDebugger::FindTargetWithFileAndArch (const char *filename, const char *arch_name)
810{
Greg Clayton66111032010-06-23 01:19:29 +0000811 SBTarget sb_target;
812 if (m_opaque_sp && filename && filename[0])
813 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000814 // No need to lock, the target list is thread safe
Greg Claytoneb0103f2011-04-07 22:46:35 +0000815 ArchSpec arch (arch_name, m_opaque_sp->GetPlatformList().GetSelectedPlatform().get());
Greg Clayton274060b2010-10-20 20:54:39 +0000816 TargetSP target_sp (m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture (FileSpec(filename, false), arch_name ? &arch : NULL));
Greg Claytonb9556ac2012-01-30 07:41:31 +0000817 sb_target.SetSP (target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000818 }
819 return sb_target;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000820}
821
822SBTarget
Greg Clayton431ce672011-04-18 23:15:17 +0000823SBDebugger::FindTargetWithLLDBProcess (const ProcessSP &process_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000824{
Greg Clayton66111032010-06-23 01:19:29 +0000825 SBTarget sb_target;
826 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000827 {
828 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000829 sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get()));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000830 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000831 return sb_target;
832}
833
834
835uint32_t
836SBDebugger::GetNumTargets ()
837{
Greg Clayton66111032010-06-23 01:19:29 +0000838 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000839 {
840 // No need to lock, the target list is thread safe
Greg Clayton66111032010-06-23 01:19:29 +0000841 return m_opaque_sp->GetTargetList().GetNumTargets ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000842 }
Greg Clayton66111032010-06-23 01:19:29 +0000843 return 0;
844}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000845
846SBTarget
Jim Ingham2976d002010-08-26 21:32:51 +0000847SBDebugger::GetSelectedTarget ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000848{
Greg Clayton5160ce52013-03-27 23:08:40 +0000849 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000850
Greg Clayton66111032010-06-23 01:19:29 +0000851 SBTarget sb_target;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000852 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000853 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000854 {
855 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000856 target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget ();
857 sb_target.SetSP (target_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000858 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000859
860 if (log)
861 {
862 SBStream sstr;
Greg Clayton431ce672011-04-18 23:15:17 +0000863 sb_target.GetDescription (sstr, eDescriptionLevelBrief);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000864 log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
865 static_cast<void*>(m_opaque_sp.get()),
866 static_cast<void*>(target_sp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000867 }
868
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000869 return sb_target;
870}
871
872void
Jim Inghame64f0dc2011-09-13 23:25:31 +0000873SBDebugger::SetSelectedTarget (SBTarget &sb_target)
874{
Greg Clayton5160ce52013-03-27 23:08:40 +0000875 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghame64f0dc2011-09-13 23:25:31 +0000876
Greg Claytonb9556ac2012-01-30 07:41:31 +0000877 TargetSP target_sp (sb_target.GetSP());
Jim Inghame64f0dc2011-09-13 23:25:31 +0000878 if (m_opaque_sp)
879 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000880 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
Jim Inghame64f0dc2011-09-13 23:25:31 +0000881 }
882 if (log)
883 {
884 SBStream sstr;
885 sb_target.GetDescription (sstr, eDescriptionLevelBrief);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000886 log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
887 static_cast<void*>(m_opaque_sp.get()),
888 static_cast<void*>(target_sp.get()), sstr.GetData());
Jim Inghame64f0dc2011-09-13 23:25:31 +0000889 }
890}
891
Greg Claytonfbb76342013-11-20 21:07:01 +0000892SBPlatform
893SBDebugger::GetSelectedPlatform()
894{
895 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
896
897 SBPlatform sb_platform;
898 DebuggerSP debugger_sp(m_opaque_sp);
899 if (debugger_sp)
900 {
901 sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform());
902 }
903 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000904 log->Printf ("SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
905 static_cast<void*>(m_opaque_sp.get()),
906 static_cast<void*>(sb_platform.GetSP().get()),
907 sb_platform.GetName());
Greg Claytonfbb76342013-11-20 21:07:01 +0000908 return sb_platform;
909}
910
911void
912SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform)
913{
914 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000915
Greg Claytonfbb76342013-11-20 21:07:01 +0000916 DebuggerSP debugger_sp(m_opaque_sp);
917 if (debugger_sp)
918 {
919 debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP());
920 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000921
Greg Claytonfbb76342013-11-20 21:07:01 +0000922 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000923 log->Printf ("SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
924 static_cast<void*>(m_opaque_sp.get()),
925 static_cast<void*>(sb_platform.GetSP().get()),
926 sb_platform.GetName());
Greg Claytonfbb76342013-11-20 21:07:01 +0000927}
928
Jim Inghame64f0dc2011-09-13 23:25:31 +0000929void
Enrico Granatac30a73a2012-09-06 22:02:28 +0000930SBDebugger::DispatchInput (void* baton, const void *data, size_t data_len)
Enrico Granata6b09d422012-09-06 21:58:25 +0000931{
932 DispatchInput (data,data_len);
933}
934
935void
Filipe Cabecinhasc3019992012-08-20 16:21:04 +0000936SBDebugger::DispatchInput (const void *data, size_t data_len)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000937{
Greg Clayton44d93782014-01-27 23:43:24 +0000938// Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
939//
940// if (log)
941// log->Printf ("SBDebugger(%p)::DispatchInput (data=\"%.*s\", size_t=%" PRIu64 ")",
942// m_opaque_sp.get(),
943// (int) data_len,
944// (const char *) data,
945// (uint64_t)data_len);
946//
947// if (m_opaque_sp)
948// m_opaque_sp->DispatchInput ((const char *) data, data_len);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000949}
950
951void
Caroline Ticeefed6132010-11-19 20:47:54 +0000952SBDebugger::DispatchInputInterrupt ()
953{
954 if (m_opaque_sp)
955 m_opaque_sp->DispatchInputInterrupt ();
956}
957
958void
959SBDebugger::DispatchInputEndOfFile ()
960{
961 if (m_opaque_sp)
962 m_opaque_sp->DispatchInputEndOfFile ();
963}
964
965void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000966SBDebugger::PushInputReader (SBInputReader &reader)
967{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000968}
Greg Clayton66111032010-06-23 01:19:29 +0000969
970void
Greg Clayton44d93782014-01-27 23:43:24 +0000971SBDebugger::RunCommandInterpreter (bool auto_handle_events,
972 bool spawn_thread)
Caroline Tice969ed3d2011-05-02 20:41:46 +0000973{
Caroline Tice969ed3d2011-05-02 20:41:46 +0000974 if (m_opaque_sp)
Jim Ingham26c7bf92014-10-11 00:38:27 +0000975 {
976 CommandInterpreterRunOptions options;
977
978 m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(auto_handle_events,
979 spawn_thread,
980 options);
981 }
982}
983
984void
985SBDebugger::RunCommandInterpreter (bool auto_handle_events,
986 bool spawn_thread,
987 SBCommandInterpreterRunOptions &options,
988 int &num_errors,
Jim Inghamffc9f1d2014-10-14 01:20:07 +0000989 bool &quit_requested,
990 bool &stopped_for_crash)
Jim Ingham26c7bf92014-10-11 00:38:27 +0000991
992{
993 if (m_opaque_sp)
994 {
995 CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
996 interp.RunCommandInterpreter(auto_handle_events, spawn_thread, options.ref());
997 num_errors = interp.GetNumErrors();
998 quit_requested = interp.GetQuitRequested();
Jim Inghamffc9f1d2014-10-14 01:20:07 +0000999 stopped_for_crash = interp.GetStoppedForCrash();
Jim Ingham26c7bf92014-10-11 00:38:27 +00001000 }
Caroline Tice969ed3d2011-05-02 20:41:46 +00001001}
1002
Sean Callanan3e7e9152015-10-20 00:23:46 +00001003SBError
1004SBDebugger::RunREPL (lldb::LanguageType language, const char *repl_options)
1005{
1006 SBError error;
1007 if (m_opaque_sp)
1008 error.ref() = m_opaque_sp->RunREPL(language, repl_options);
1009 else
1010 error.SetErrorString ("invalid debugger");
1011 return error;
1012}
1013
Caroline Tice969ed3d2011-05-02 20:41:46 +00001014void
Greg Clayton431ce672011-04-18 23:15:17 +00001015SBDebugger::reset (const DebuggerSP &debugger_sp)
Greg Clayton66111032010-06-23 01:19:29 +00001016{
1017 m_opaque_sp = debugger_sp;
1018}
1019
1020Debugger *
1021SBDebugger::get () const
1022{
1023 return m_opaque_sp.get();
1024}
1025
1026Debugger &
1027SBDebugger::ref () const
1028{
1029 assert (m_opaque_sp.get());
1030 return *m_opaque_sp;
1031}
1032
Greg Clayton9a377662011-10-01 02:59:24 +00001033const lldb::DebuggerSP &
1034SBDebugger::get_sp () const
1035{
1036 return m_opaque_sp;
1037}
Greg Clayton66111032010-06-23 01:19:29 +00001038
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001039SBDebugger
1040SBDebugger::FindDebuggerWithID (int id)
1041{
Greg Claytonaf67cec2010-12-20 20:49:23 +00001042 // No need to lock, the debugger list is thread safe
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001043 SBDebugger sb_debugger;
Greg Clayton431ce672011-04-18 23:15:17 +00001044 DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id);
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001045 if (debugger_sp)
1046 sb_debugger.reset (debugger_sp);
1047 return sb_debugger;
1048}
Jim Inghame40e4212010-08-30 19:44:40 +00001049
Caroline Ticedd759852010-09-09 17:45:09 +00001050const char *
1051SBDebugger::GetInstanceName()
1052{
Greg Clayton6920b522012-08-22 18:39:03 +00001053 if (m_opaque_sp)
1054 return m_opaque_sp->GetInstanceName().AsCString();
1055 else
Caroline Ticedd759852010-09-09 17:45:09 +00001056 return NULL;
1057}
1058
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001059SBError
Caroline Ticedd759852010-09-09 17:45:09 +00001060SBDebugger::SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001061{
Greg Clayton6920b522012-08-22 18:39:03 +00001062 SBError sb_error;
1063 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName (ConstString(debugger_instance_name)));
1064 Error error;
1065 if (debugger_sp)
1066 {
1067 ExecutionContext exe_ctx (debugger_sp->GetCommandInterpreter().GetExecutionContext());
1068 error = debugger_sp->SetPropertyValue (&exe_ctx,
1069 eVarSetOperationAssign,
1070 var_name,
1071 value);
1072 }
1073 else
1074 {
1075 error.SetErrorStringWithFormat ("invalid debugger instance name '%s'", debugger_instance_name);
1076 }
1077 if (error.Fail())
1078 sb_error.SetError(error);
1079 return sb_error;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001080}
1081
Greg Clayton431ce672011-04-18 23:15:17 +00001082SBStringList
Caroline Ticedd759852010-09-09 17:45:09 +00001083SBDebugger::GetInternalVariableValue (const char *var_name, const char *debugger_instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001084{
1085 SBStringList ret_value;
Greg Clayton6920b522012-08-22 18:39:03 +00001086 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName (ConstString(debugger_instance_name)));
1087 Error error;
1088 if (debugger_sp)
1089 {
1090 ExecutionContext exe_ctx (debugger_sp->GetCommandInterpreter().GetExecutionContext());
1091 lldb::OptionValueSP value_sp (debugger_sp->GetPropertyValue (&exe_ctx,
1092 var_name,
1093 false,
1094 error));
1095 if (value_sp)
1096 {
1097 StreamString value_strm;
1098 value_sp->DumpValue (&exe_ctx, value_strm, OptionValue::eDumpOptionValue);
1099 const std::string &value_str = value_strm.GetString();
1100 if (!value_str.empty())
1101 {
1102 StringList string_list;
Greg Clayton44d93782014-01-27 23:43:24 +00001103 string_list.SplitIntoLines(value_str);
Greg Clayton6920b522012-08-22 18:39:03 +00001104 return SBStringList(&string_list);
1105 }
1106 }
1107 }
1108 return SBStringList();
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001109}
1110
Greg Claytona7015092010-09-18 01:14:36 +00001111uint32_t
1112SBDebugger::GetTerminalWidth () const
1113{
1114 if (m_opaque_sp)
1115 return m_opaque_sp->GetTerminalWidth ();
1116 return 0;
1117}
1118
1119void
1120SBDebugger::SetTerminalWidth (uint32_t term_width)
1121{
1122 if (m_opaque_sp)
1123 m_opaque_sp->SetTerminalWidth (term_width);
1124}
1125
1126const char *
1127SBDebugger::GetPrompt() const
1128{
Greg Clayton5160ce52013-03-27 23:08:40 +00001129 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001130
Caroline Ticeceb6b132010-10-26 03:11:13 +00001131 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001132 log->Printf ("SBDebugger(%p)::GetPrompt () => \"%s\"",
1133 static_cast<void*>(m_opaque_sp.get()),
Caroline Tice750cd172010-10-26 23:49:36 +00001134 (m_opaque_sp ? m_opaque_sp->GetPrompt() : ""));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001135
Greg Claytona7015092010-09-18 01:14:36 +00001136 if (m_opaque_sp)
1137 return m_opaque_sp->GetPrompt ();
1138 return 0;
1139}
1140
1141void
1142SBDebugger::SetPrompt (const char *prompt)
1143{
1144 if (m_opaque_sp)
1145 m_opaque_sp->SetPrompt (prompt);
1146}
1147
1148
Greg Clayton431ce672011-04-18 23:15:17 +00001149ScriptLanguage
Greg Claytona7015092010-09-18 01:14:36 +00001150SBDebugger::GetScriptLanguage() const
1151{
1152 if (m_opaque_sp)
1153 return m_opaque_sp->GetScriptLanguage ();
1154 return eScriptLanguageNone;
1155}
1156
1157void
Greg Clayton431ce672011-04-18 23:15:17 +00001158SBDebugger::SetScriptLanguage (ScriptLanguage script_lang)
Greg Claytona7015092010-09-18 01:14:36 +00001159{
1160 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001161 {
Greg Claytona7015092010-09-18 01:14:36 +00001162 m_opaque_sp->SetScriptLanguage (script_lang);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001163 }
Greg Claytona7015092010-09-18 01:14:36 +00001164}
1165
Jim Inghame40e4212010-08-30 19:44:40 +00001166bool
1167SBDebugger::SetUseExternalEditor (bool value)
1168{
1169 if (m_opaque_sp)
1170 return m_opaque_sp->SetUseExternalEditor (value);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001171 return false;
Jim Inghame40e4212010-08-30 19:44:40 +00001172}
1173
1174bool
Caroline Ticedaccaa92010-09-20 20:44:43 +00001175SBDebugger::GetUseExternalEditor ()
Jim Inghame40e4212010-08-30 19:44:40 +00001176{
1177 if (m_opaque_sp)
Caroline Ticedaccaa92010-09-20 20:44:43 +00001178 return m_opaque_sp->GetUseExternalEditor ();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001179 return false;
Jim Inghame40e4212010-08-30 19:44:40 +00001180}
1181
Caroline Ticedde9cff2010-09-20 05:20:02 +00001182bool
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001183SBDebugger::SetUseColor (bool value)
1184{
1185 if (m_opaque_sp)
1186 return m_opaque_sp->SetUseColor (value);
1187 return false;
1188}
1189
1190bool
1191SBDebugger::GetUseColor () const
1192{
1193 if (m_opaque_sp)
1194 return m_opaque_sp->GetUseColor ();
1195 return false;
1196}
1197
1198bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001199SBDebugger::GetDescription (SBStream &description)
1200{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001201 Stream &strm = description.ref();
1202
Caroline Ticedde9cff2010-09-20 05:20:02 +00001203 if (m_opaque_sp)
1204 {
1205 const char *name = m_opaque_sp->GetInstanceName().AsCString();
Greg Clayton431ce672011-04-18 23:15:17 +00001206 user_id_t id = m_opaque_sp->GetID();
Daniel Malead01b2952012-11-29 21:49:15 +00001207 strm.Printf ("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001208 }
1209 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001210 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +00001211
1212 return true;
1213}
Caroline Ticeefed6132010-11-19 20:47:54 +00001214
Greg Clayton431ce672011-04-18 23:15:17 +00001215user_id_t
Caroline Ticeefed6132010-11-19 20:47:54 +00001216SBDebugger::GetID()
1217{
1218 if (m_opaque_sp)
1219 return m_opaque_sp->GetID();
1220 return LLDB_INVALID_UID;
1221}
Greg Clayton2289fa42011-04-30 01:09:13 +00001222
1223
1224SBError
Greg Clayton615eb7e2014-09-19 20:11:50 +00001225SBDebugger::SetCurrentPlatform (const char *platform_name_cstr)
Greg Clayton2289fa42011-04-30 01:09:13 +00001226{
1227 SBError sb_error;
1228 if (m_opaque_sp)
1229 {
Greg Clayton615eb7e2014-09-19 20:11:50 +00001230 if (platform_name_cstr && platform_name_cstr[0])
Greg Clayton2289fa42011-04-30 01:09:13 +00001231 {
Greg Clayton615eb7e2014-09-19 20:11:50 +00001232 ConstString platform_name (platform_name_cstr);
1233 PlatformSP platform_sp (Platform::Find (platform_name));
1234
1235 if (platform_sp)
1236 {
1237 // Already have a platform with this name, just select it
1238 m_opaque_sp->GetPlatformList().SetSelectedPlatform(platform_sp);
1239 }
1240 else
1241 {
1242 // We don't have a platform by this name yet, create one
1243 platform_sp = Platform::Create (platform_name, sb_error.ref());
1244 if (platform_sp)
1245 {
1246 // We created the platform, now append and select it
1247 bool make_selected = true;
1248 m_opaque_sp->GetPlatformList().Append (platform_sp, make_selected);
1249 }
1250 }
Greg Clayton2289fa42011-04-30 01:09:13 +00001251 }
Greg Clayton615eb7e2014-09-19 20:11:50 +00001252 else
1253 {
1254 sb_error.ref().SetErrorString("invalid platform name");
1255 }
1256 }
1257 else
1258 {
1259 sb_error.ref().SetErrorString("invalid debugger");
Greg Clayton2289fa42011-04-30 01:09:13 +00001260 }
1261 return sb_error;
1262}
1263
Greg Claytonfc3f0272011-05-29 04:06:55 +00001264bool
Greg Claytonf3dd93c2011-06-17 03:31:01 +00001265SBDebugger::SetCurrentPlatformSDKRoot (const char *sysroot)
1266{
1267 if (m_opaque_sp)
1268 {
1269 PlatformSP platform_sp (m_opaque_sp->GetPlatformList().GetSelectedPlatform());
1270
1271 if (platform_sp)
1272 {
1273 platform_sp->SetSDKRootDirectory (ConstString (sysroot));
1274 return true;
1275 }
1276 }
1277 return false;
1278}
1279
1280bool
Greg Claytonfc3f0272011-05-29 04:06:55 +00001281SBDebugger::GetCloseInputOnEOF () const
1282{
1283 if (m_opaque_sp)
1284 return m_opaque_sp->GetCloseInputOnEOF ();
1285 return false;
1286}
1287
1288void
1289SBDebugger::SetCloseInputOnEOF (bool b)
1290{
1291 if (m_opaque_sp)
1292 m_opaque_sp->SetCloseInputOnEOF (b);
1293}
Enrico Granata061858c2012-02-15 02:34:21 +00001294
1295SBTypeCategory
1296SBDebugger::GetCategory (const char* category_name)
1297{
1298 if (!category_name || *category_name == 0)
1299 return SBTypeCategory();
1300
1301 TypeCategoryImplSP category_sp;
1302
1303 if (DataVisualization::Categories::GetCategory(ConstString(category_name), category_sp, false))
1304 return SBTypeCategory(category_sp);
1305 else
1306 return SBTypeCategory();
1307}
1308
1309SBTypeCategory
1310SBDebugger::CreateCategory (const char* category_name)
1311{
1312 if (!category_name || *category_name == 0)
1313 return SBTypeCategory();
1314
1315 TypeCategoryImplSP category_sp;
1316
1317 if (DataVisualization::Categories::GetCategory(ConstString(category_name), category_sp, true))
1318 return SBTypeCategory(category_sp);
1319 else
1320 return SBTypeCategory();
1321}
1322
1323bool
1324SBDebugger::DeleteCategory (const char* category_name)
1325{
1326 if (!category_name || *category_name == 0)
1327 return false;
1328
1329 return DataVisualization::Categories::Delete(ConstString(category_name));
1330}
1331
1332uint32_t
1333SBDebugger::GetNumCategories()
1334{
1335 return DataVisualization::Categories::GetCount();
1336}
1337
1338SBTypeCategory
1339SBDebugger::GetCategoryAtIndex (uint32_t index)
1340{
1341 return SBTypeCategory(DataVisualization::Categories::GetCategoryAtIndex(index));
1342}
1343
1344SBTypeCategory
1345SBDebugger::GetDefaultCategory()
1346{
1347 return GetCategory("default");
1348}
1349
1350SBTypeFormat
1351SBDebugger::GetFormatForType (SBTypeNameSpecifier type_name)
1352{
1353 SBTypeCategory default_category_sb = GetDefaultCategory();
1354 if (default_category_sb.GetEnabled())
1355 return default_category_sb.GetFormatForType(type_name);
1356 return SBTypeFormat();
1357}
1358
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001359#ifndef LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001360SBTypeSummary
1361SBDebugger::GetSummaryForType (SBTypeNameSpecifier type_name)
1362{
Enrico Granataa777dc22012-05-08 21:49:57 +00001363 if (type_name.IsValid() == false)
1364 return SBTypeSummary();
1365 return SBTypeSummary(DataVisualization::GetSummaryForType(type_name.GetSP()));
Enrico Granata061858c2012-02-15 02:34:21 +00001366}
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001367#endif // LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001368
1369SBTypeFilter
1370SBDebugger::GetFilterForType (SBTypeNameSpecifier type_name)
1371{
Enrico Granataa777dc22012-05-08 21:49:57 +00001372 if (type_name.IsValid() == false)
1373 return SBTypeFilter();
1374 return SBTypeFilter(DataVisualization::GetFilterForType(type_name.GetSP()));
Enrico Granata061858c2012-02-15 02:34:21 +00001375}
1376
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001377#ifndef LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001378SBTypeSynthetic
1379SBDebugger::GetSyntheticForType (SBTypeNameSpecifier type_name)
1380{
Enrico Granataa777dc22012-05-08 21:49:57 +00001381 if (type_name.IsValid() == false)
1382 return SBTypeSynthetic();
1383 return SBTypeSynthetic(DataVisualization::GetSyntheticForType(type_name.GetSP()));
Enrico Granata061858c2012-02-15 02:34:21 +00001384}
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001385#endif // LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001386
Jim Ingham228063c2012-02-21 02:23:08 +00001387bool
1388SBDebugger::EnableLog (const char *channel, const char **categories)
1389{
1390 if (m_opaque_sp)
1391 {
1392 uint32_t log_options = LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1393 StreamString errors;
1394 return m_opaque_sp->EnableLog (channel, categories, NULL, log_options, errors);
1395
1396 }
1397 else
1398 return false;
1399}
Jim Ingham4f02b222012-02-22 22:49:20 +00001400
1401void
1402SBDebugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
1403{
1404 if (m_opaque_sp)
1405 {
1406 return m_opaque_sp->SetLoggingCallback (log_callback, baton);
1407 }
1408}
1409
1410