blob: 8b1debb20b679a1c60525639a90fd1ebfc12c541 [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
Daniel Malea93a64302012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Eli Friedmanca93cc12010-06-09 07:37:52 +000012#include "lldb/API/SBDebugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013
Greg Claytone0d378b2011-03-24 21:19:54 +000014#include "lldb/lldb-private.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015
Zachary Turnere6e2bb32015-03-31 21:03:22 +000016#include "lldb/API/SystemInitializerFull.h"
Eli Friedmanca93cc12010-06-09 07:37:52 +000017#include "lldb/API/SBListener.h"
18#include "lldb/API/SBBroadcaster.h"
19#include "lldb/API/SBCommandInterpreter.h"
20#include "lldb/API/SBCommandReturnObject.h"
Greg Clayton2289fa42011-04-30 01:09:13 +000021#include "lldb/API/SBError.h"
Eli Friedmanca93cc12010-06-09 07:37:52 +000022#include "lldb/API/SBEvent.h"
23#include "lldb/API/SBFrame.h"
Caroline Tice3df9a8d2010-09-04 00:03:46 +000024#include "lldb/API/SBProcess.h"
25#include "lldb/API/SBSourceManager.h"
Caroline Ticedde9cff2010-09-20 05:20:02 +000026#include "lldb/API/SBStream.h"
Caroline Tice3df9a8d2010-09-04 00:03:46 +000027#include "lldb/API/SBStringList.h"
28#include "lldb/API/SBTarget.h"
29#include "lldb/API/SBThread.h"
Enrico Granata061858c2012-02-15 02:34:21 +000030#include "lldb/API/SBTypeCategory.h"
31#include "lldb/API/SBTypeFormat.h"
32#include "lldb/API/SBTypeFilter.h"
33#include "lldb/API/SBTypeNameSpecifier.h"
34#include "lldb/API/SBTypeSummary.h"
35#include "lldb/API/SBTypeSynthetic.h"
36
Greg Clayton6eee5aa2010-10-11 01:05:37 +000037#include "lldb/Core/Debugger.h"
38#include "lldb/Core/State.h"
Greg Clayton44d93782014-01-27 23:43:24 +000039#include "lldb/Core/StreamFile.h"
Enrico Granata5548cb52013-01-28 23:47:25 +000040#include "lldb/DataFormatters/DataVisualization.h"
Zachary Turnere6e2bb32015-03-31 21:03:22 +000041#include "lldb/Initialization/SystemLifetimeManager.h"
Greg Clayton6eee5aa2010-10-11 01:05:37 +000042#include "lldb/Interpreter/Args.h"
43#include "lldb/Interpreter/CommandInterpreter.h"
Greg Claytoncac9c5f2011-09-24 00:52:29 +000044#include "lldb/Interpreter/OptionGroupPlatform.h"
Greg Clayton6eee5aa2010-10-11 01:05:37 +000045#include "lldb/Target/Process.h"
46#include "lldb/Target/TargetList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047
Zachary Turnere6e2bb32015-03-31 21:03:22 +000048#include "llvm/Support/ManagedStatic.h"
Zachary Turner58a559c2014-08-27 20:15:09 +000049#include "llvm/Support/DynamicLibrary.h"
50
Chris Lattner30fdc8d2010-06-08 16:52:24 +000051using namespace lldb;
52using namespace lldb_private;
53
Greg Clayton5fb8f792013-12-02 19:35:49 +000054
Zachary Turner58a559c2014-08-27 20:15:09 +000055static llvm::sys::DynamicLibrary
Greg Clayton5fb8f792013-12-02 19:35:49 +000056LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& error)
57{
Zachary Turner58a559c2014-08-27 20:15:09 +000058 llvm::sys::DynamicLibrary dynlib = llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
59 if (dynlib.isValid())
Greg Clayton5fb8f792013-12-02 19:35:49 +000060 {
61 typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger);
62
63 lldb::SBDebugger debugger_sb(debugger_sp);
64 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) function.
65 // 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 +000066 LLDBCommandPluginInit init_func = (LLDBCommandPluginInit)dynlib.getAddressOfSymbol("_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
Greg Clayton5fb8f792013-12-02 19:35:49 +000067 if (init_func)
68 {
69 if (init_func(debugger_sb))
Zachary Turner58a559c2014-08-27 20:15:09 +000070 return dynlib;
Greg Clayton5fb8f792013-12-02 19:35:49 +000071 else
72 error.SetErrorString("plug-in refused to load (lldb::PluginInitialize(lldb::SBDebugger) returned false)");
73 }
74 else
75 {
76 error.SetErrorString("plug-in is missing the required initialization: lldb::PluginInitialize(lldb::SBDebugger)");
77 }
78 }
79 else
80 {
81 if (spec.Exists())
82 error.SetErrorString("this file does not represent a loadable dylib");
83 else
84 error.SetErrorString("no such file");
85 }
Zachary Turner58a559c2014-08-27 20:15:09 +000086 return llvm::sys::DynamicLibrary();
Greg Clayton5fb8f792013-12-02 19:35:49 +000087}
88
Zachary Turnere6e2bb32015-03-31 21:03:22 +000089static llvm::ManagedStatic<SystemLifetimeManager> g_debugger_lifetime;
90
91SBInputReader::SBInputReader()
92{
93}
94SBInputReader::~SBInputReader()
95{
96}
97
98SBError
99SBInputReader::Initialize(lldb::SBDebugger &sb_debugger,
100 unsigned long (*)(void *, lldb::SBInputReader *, lldb::InputReaderAction, char const *,
101 unsigned long),
102 void *, lldb::InputReaderGranularity, char const *, char const *, bool)
103{
104 return SBError();
105}
106
107void
108SBInputReader::SetIsDone(bool)
109{
110}
111bool
112SBInputReader::IsActive() const
113{
114 return false;
115}
116
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000117void
118SBDebugger::Initialize ()
119{
Greg Clayton5160ce52013-03-27 23:08:40 +0000120 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000121
122 if (log)
123 log->Printf ("SBDebugger::Initialize ()");
124
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000125 g_debugger_lifetime->Initialize(llvm::make_unique<SystemInitializerFull>(), LoadPlugin);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000126}
127
128void
129SBDebugger::Terminate ()
130{
Zachary Turnere6e2bb32015-03-31 21:03:22 +0000131 g_debugger_lifetime->Terminate();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000132}
133
Greg Clayton48e42542010-07-30 20:12:55 +0000134void
135SBDebugger::Clear ()
136{
Greg Clayton5160ce52013-03-27 23:08:40 +0000137 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000138
139 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000140 log->Printf ("SBDebugger(%p)::Clear ()",
141 static_cast<void*>(m_opaque_sp.get()));
142
Caroline Tice3d6086f2010-12-20 18:35:50 +0000143 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000144 m_opaque_sp->ClearIOHandlers ();
Caroline Ticeceb6b132010-10-26 03:11:13 +0000145
Greg Clayton48e42542010-07-30 20:12:55 +0000146 m_opaque_sp.reset();
147}
148
Greg Clayton66111032010-06-23 01:19:29 +0000149SBDebugger
150SBDebugger::Create()
151{
Jim Ingham228063c2012-02-21 02:23:08 +0000152 return SBDebugger::Create(false, NULL, NULL);
Jim Ingham06942692011-08-13 00:22:20 +0000153}
154
155SBDebugger
156SBDebugger::Create(bool source_init_files)
157{
Jim Ingham228063c2012-02-21 02:23:08 +0000158 return SBDebugger::Create (source_init_files, NULL, NULL);
159}
160
161SBDebugger
162SBDebugger::Create(bool source_init_files, lldb::LogOutputCallback callback, void *baton)
163
164{
Greg Clayton5160ce52013-03-27 23:08:40 +0000165 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000166
Greg Clayton66111032010-06-23 01:19:29 +0000167 SBDebugger debugger;
Greg Claytoncb172b12014-05-19 20:42:14 +0000168
169 // Currently we have issues if this function is called simultaneously on two different
170 // threads. The issues mainly revolve around the fact that the lldb_private::FormatManager
171 // uses global collections and having two threads parsing the .lldbinit files can cause
172 // mayhem. So to get around this for now we need to use a mutex to prevent bad things
173 // from happening.
174 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
175 Mutex::Locker locker(g_mutex);
176
Jim Ingham228063c2012-02-21 02:23:08 +0000177 debugger.reset(Debugger::CreateInstance(callback, baton));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000178
179 if (log)
180 {
181 SBStream sstr;
182 debugger.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000183 log->Printf ("SBDebugger::Create () => SBDebugger(%p): %s",
184 static_cast<void*>(debugger.m_opaque_sp.get()),
185 sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000186 }
187
Jim Ingham06942692011-08-13 00:22:20 +0000188 SBCommandInterpreter interp = debugger.GetCommandInterpreter();
189 if (source_init_files)
190 {
191 interp.get()->SkipLLDBInitFiles(false);
192 interp.get()->SkipAppInitFiles (false);
193 SBCommandReturnObject result;
194 interp.SourceInitFileInHomeDirectory(result);
195 }
196 else
197 {
198 interp.get()->SkipLLDBInitFiles(true);
199 interp.get()->SkipAppInitFiles (true);
200 }
Greg Clayton66111032010-06-23 01:19:29 +0000201 return debugger;
202}
203
Caroline Ticee02657b2011-01-22 01:02:07 +0000204void
205SBDebugger::Destroy (SBDebugger &debugger)
206{
Greg Clayton5160ce52013-03-27 23:08:40 +0000207 Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000208
Caroline Ticee02657b2011-01-22 01:02:07 +0000209 if (log)
210 {
211 SBStream sstr;
212 debugger.GetDescription (sstr);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000213 log->Printf ("SBDebugger::Destroy () => SBDebugger(%p): %s",
214 static_cast<void*>(debugger.m_opaque_sp.get()),
215 sstr.GetData());
Caroline Ticee02657b2011-01-22 01:02:07 +0000216 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000217
Caroline Ticee02657b2011-01-22 01:02:07 +0000218 Debugger::Destroy (debugger.m_opaque_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000219
Caroline Ticee02657b2011-01-22 01:02:07 +0000220 if (debugger.m_opaque_sp.get() != NULL)
221 debugger.m_opaque_sp.reset();
222}
223
Greg Claytonf9322412011-12-15 04:38:41 +0000224void
225SBDebugger::MemoryPressureDetected ()
226{
Greg Clayton0cd70862012-04-09 20:22:01 +0000227 // Since this function can be call asynchronously, we allow it to be
228 // non-mandatory. We have seen deadlocks with this function when called
229 // so we need to safeguard against this until we can determine what is
230 // causing the deadlocks.
Greg Clayton5160ce52013-03-27 23:08:40 +0000231 Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghamaebdf1b2012-06-07 19:08:07 +0000232
Greg Clayton0cd70862012-04-09 20:22:01 +0000233 const bool mandatory = false;
Jim Inghamaebdf1b2012-06-07 19:08:07 +0000234 if (log)
235 {
236 log->Printf ("SBDebugger::MemoryPressureDetected (), mandatory = %d", mandatory);
237 }
238
Greg Clayton0cd70862012-04-09 20:22:01 +0000239 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Claytonf9322412011-12-15 04:38:41 +0000240}
241
Greg Clayton66111032010-06-23 01:19:29 +0000242SBDebugger::SBDebugger () :
243 m_opaque_sp ()
244{
245}
246
Enrico Granata274fd6e2011-08-19 23:56:34 +0000247SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp) :
248 m_opaque_sp(debugger_sp)
249{
250}
251
Greg Claytonefabb122010-11-05 23:17:00 +0000252SBDebugger::SBDebugger(const SBDebugger &rhs) :
253 m_opaque_sp (rhs.m_opaque_sp)
254{
255}
256
257SBDebugger &
258SBDebugger::operator = (const SBDebugger &rhs)
259{
260 if (this != &rhs)
261 {
262 m_opaque_sp = rhs.m_opaque_sp;
263 }
264 return *this;
265}
266
Greg Clayton66111032010-06-23 01:19:29 +0000267SBDebugger::~SBDebugger ()
268{
269}
270
271bool
272SBDebugger::IsValid() const
273{
274 return m_opaque_sp.get() != NULL;
275}
276
277
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000278void
279SBDebugger::SetAsync (bool b)
280{
Greg Clayton66111032010-06-23 01:19:29 +0000281 if (m_opaque_sp)
282 m_opaque_sp->SetAsyncExecution(b);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000283}
284
Jim Inghame64f0dc2011-09-13 23:25:31 +0000285bool
286SBDebugger::GetAsync ()
287{
288 if (m_opaque_sp)
289 return m_opaque_sp->GetAsyncExecution();
290 else
291 return false;
292}
293
Greg Clayton6eee5aa2010-10-11 01:05:37 +0000294void
295SBDebugger::SkipLLDBInitFiles (bool b)
296{
297 if (m_opaque_sp)
298 m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles (b);
299}
300
Jim Ingham16e0c682011-08-12 23:34:31 +0000301void
302SBDebugger::SkipAppInitFiles (bool b)
303{
304 if (m_opaque_sp)
305 m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles (b);
306}
307
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000308// Shouldn't really be settable after initialization as this could cause lots of problems; don't want users
309// trying to switch modes in the middle of a debugging session.
310void
311SBDebugger::SetInputFileHandle (FILE *fh, bool transfer_ownership)
312{
Greg Clayton5160ce52013-03-27 23:08:40 +0000313 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000314
315 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000316 log->Printf ("SBDebugger(%p)::SetInputFileHandle (fh=%p, transfer_ownership=%i)",
317 static_cast<void*>(m_opaque_sp.get()),
318 static_cast<void*>(fh), transfer_ownership);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000319
Greg Clayton66111032010-06-23 01:19:29 +0000320 if (m_opaque_sp)
321 m_opaque_sp->SetInputFileHandle (fh, transfer_ownership);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000322}
323
324void
325SBDebugger::SetOutputFileHandle (FILE *fh, bool transfer_ownership)
326{
Greg Clayton5160ce52013-03-27 23:08:40 +0000327 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000328
329
330 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000331 log->Printf ("SBDebugger(%p)::SetOutputFileHandle (fh=%p, transfer_ownership=%i)",
332 static_cast<void*>(m_opaque_sp.get()),
333 static_cast<void*>(fh), transfer_ownership);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000334
Greg Clayton66111032010-06-23 01:19:29 +0000335 if (m_opaque_sp)
336 m_opaque_sp->SetOutputFileHandle (fh, transfer_ownership);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000337}
338
339void
340SBDebugger::SetErrorFileHandle (FILE *fh, bool transfer_ownership)
341{
Greg Clayton5160ce52013-03-27 23:08:40 +0000342 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000343
344
345 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000346 log->Printf ("SBDebugger(%p)::SetErrorFileHandle (fh=%p, transfer_ownership=%i)",
347 static_cast<void*>(m_opaque_sp.get()),
348 static_cast<void*>(fh), transfer_ownership);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000349
Greg Clayton66111032010-06-23 01:19:29 +0000350 if (m_opaque_sp)
351 m_opaque_sp->SetErrorFileHandle (fh, transfer_ownership);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000352}
353
354FILE *
355SBDebugger::GetInputFileHandle ()
356{
Greg Clayton66111032010-06-23 01:19:29 +0000357 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000358 {
359 StreamFileSP stream_file_sp (m_opaque_sp->GetInputFile());
360 if (stream_file_sp)
361 return stream_file_sp->GetFile().GetStream();
362 }
Greg Clayton66111032010-06-23 01:19:29 +0000363 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000364}
365
366FILE *
367SBDebugger::GetOutputFileHandle ()
368{
Greg Clayton66111032010-06-23 01:19:29 +0000369 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000370 {
371 StreamFileSP stream_file_sp (m_opaque_sp->GetOutputFile());
372 if (stream_file_sp)
373 return stream_file_sp->GetFile().GetStream();
374 }
Greg Clayton66111032010-06-23 01:19:29 +0000375 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000376}
377
378FILE *
379SBDebugger::GetErrorFileHandle ()
380{
Greg Clayton66111032010-06-23 01:19:29 +0000381 if (m_opaque_sp)
Greg Clayton44d93782014-01-27 23:43:24 +0000382 if (m_opaque_sp)
383 {
384 StreamFileSP stream_file_sp (m_opaque_sp->GetErrorFile());
385 if (stream_file_sp)
386 return stream_file_sp->GetFile().GetStream();
387 }
Greg Clayton66111032010-06-23 01:19:29 +0000388 return NULL;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000389}
390
Jim Inghamc5917d92012-11-30 20:23:19 +0000391void
392SBDebugger::SaveInputTerminalState()
393{
394 if (m_opaque_sp)
395 m_opaque_sp->SaveInputTerminalState();
396}
397
398void
399SBDebugger::RestoreInputTerminalState()
400{
401 if (m_opaque_sp)
402 m_opaque_sp->RestoreInputTerminalState();
403
404}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405SBCommandInterpreter
406SBDebugger::GetCommandInterpreter ()
407{
Greg Clayton5160ce52013-03-27 23:08:40 +0000408 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000409
Greg Clayton66111032010-06-23 01:19:29 +0000410 SBCommandInterpreter sb_interpreter;
411 if (m_opaque_sp)
412 sb_interpreter.reset (&m_opaque_sp->GetCommandInterpreter());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000413
Caroline Tice750cd172010-10-26 23:49:36 +0000414 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000415 log->Printf ("SBDebugger(%p)::GetCommandInterpreter () => SBCommandInterpreter(%p)",
416 static_cast<void*>(m_opaque_sp.get()),
417 static_cast<void*>(sb_interpreter.get()));
Caroline Tice750cd172010-10-26 23:49:36 +0000418
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000419 return sb_interpreter;
420}
421
422void
423SBDebugger::HandleCommand (const char *command)
424{
Greg Clayton66111032010-06-23 01:19:29 +0000425 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000426 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000427 TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
428 Mutex::Locker api_locker;
429 if (target_sp)
Jim Ingham10ebffa2012-05-04 23:02:50 +0000430 api_locker.Lock(target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000431
Greg Clayton66111032010-06-23 01:19:29 +0000432 SBCommandInterpreter sb_interpreter(GetCommandInterpreter ());
433 SBCommandReturnObject result;
434
435 sb_interpreter.HandleCommand (command, result, false);
436
437 if (GetErrorFileHandle() != NULL)
438 result.PutError (GetErrorFileHandle());
439 if (GetOutputFileHandle() != NULL)
440 result.PutOutput (GetOutputFileHandle());
441
442 if (m_opaque_sp->GetAsyncExecution() == false)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000443 {
Greg Clayton66111032010-06-23 01:19:29 +0000444 SBProcess process(GetCommandInterpreter().GetProcess ());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000445 ProcessSP process_sp (process.GetSP());
446 if (process_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000447 {
Greg Clayton66111032010-06-23 01:19:29 +0000448 EventSP event_sp;
449 Listener &lldb_listener = m_opaque_sp->GetListener();
Greg Claytonb9556ac2012-01-30 07:41:31 +0000450 while (lldb_listener.GetNextEventForBroadcaster (process_sp.get(), event_sp))
Greg Clayton66111032010-06-23 01:19:29 +0000451 {
452 SBEvent event(event_sp);
453 HandleProcessEvent (process, event, GetOutputFileHandle(), GetErrorFileHandle());
454 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000455 }
456 }
457 }
458}
459
460SBListener
461SBDebugger::GetListener ()
462{
Greg Clayton5160ce52013-03-27 23:08:40 +0000463 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000464
Greg Clayton66111032010-06-23 01:19:29 +0000465 SBListener sb_listener;
466 if (m_opaque_sp)
467 sb_listener.reset(&m_opaque_sp->GetListener(), false);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000468
Caroline Tice750cd172010-10-26 23:49:36 +0000469 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000470 log->Printf ("SBDebugger(%p)::GetListener () => SBListener(%p)",
471 static_cast<void*>(m_opaque_sp.get()),
472 static_cast<void*>(sb_listener.get()));
Caroline Tice750cd172010-10-26 23:49:36 +0000473
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000474 return sb_listener;
475}
476
477void
478SBDebugger::HandleProcessEvent (const SBProcess &process, const SBEvent &event, FILE *out, FILE *err)
479{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000480 if (!process.IsValid())
481 return;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000482
Greg Claytonb9556ac2012-01-30 07:41:31 +0000483 TargetSP target_sp (process.GetTarget().GetSP());
484 if (!target_sp)
485 return;
486
Greg Claytonaf67cec2010-12-20 20:49:23 +0000487 const uint32_t event_type = event.GetType();
488 char stdio_buffer[1024];
489 size_t len;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000490
Greg Claytonb9556ac2012-01-30 07:41:31 +0000491 Mutex::Locker api_locker (target_sp->GetAPIMutex());
Greg Claytonaf67cec2010-12-20 20:49:23 +0000492
493 if (event_type & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged))
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000494 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000495 // Drain stdout when we stop just in case we have any bytes
496 while ((len = process.GetSTDOUT (stdio_buffer, sizeof (stdio_buffer))) > 0)
497 if (out != NULL)
498 ::fwrite (stdio_buffer, 1, len, out);
499 }
500
501 if (event_type & (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged))
502 {
503 // Drain stderr when we stop just in case we have any bytes
504 while ((len = process.GetSTDERR (stdio_buffer, sizeof (stdio_buffer))) > 0)
505 if (err != NULL)
506 ::fwrite (stdio_buffer, 1, len, err);
507 }
508
509 if (event_type & Process::eBroadcastBitStateChanged)
510 {
511 StateType event_state = SBProcess::GetStateFromEvent (event);
512
513 if (event_state == eStateInvalid)
514 return;
515
516 bool is_stopped = StateIsStoppedState (event_state);
517 if (!is_stopped)
518 process.ReportEventState (event, out);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000519 }
520}
521
Jim Inghame37d6052011-09-13 00:29:56 +0000522SBSourceManager
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000523SBDebugger::GetSourceManager ()
524{
Jim Inghame37d6052011-09-13 00:29:56 +0000525 SBSourceManager sb_source_manager (*this);
526 return sb_source_manager;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000527}
528
529
530bool
531SBDebugger::GetDefaultArchitecture (char *arch_name, size_t arch_name_len)
532{
533 if (arch_name && arch_name_len)
534 {
Greg Clayton431ce672011-04-18 23:15:17 +0000535 ArchSpec default_arch = Target::GetDefaultArchitecture ();
Caroline Ticedaccaa92010-09-20 20:44:43 +0000536
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000537 if (default_arch.IsValid())
538 {
Greg Clayton431ce672011-04-18 23:15:17 +0000539 const std::string &triple_str = default_arch.GetTriple().str();
540 if (!triple_str.empty())
541 ::snprintf (arch_name, arch_name_len, "%s", triple_str.c_str());
542 else
543 ::snprintf (arch_name, arch_name_len, "%s", default_arch.GetArchitectureName());
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000544 return true;
545 }
546 }
547 if (arch_name && arch_name_len)
548 arch_name[0] = '\0';
549 return false;
550}
551
552
553bool
554SBDebugger::SetDefaultArchitecture (const char *arch_name)
555{
556 if (arch_name)
557 {
Greg Clayton70512312012-05-08 01:45:38 +0000558 ArchSpec arch (arch_name);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559 if (arch.IsValid())
560 {
Greg Clayton431ce672011-04-18 23:15:17 +0000561 Target::SetDefaultArchitecture (arch);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000562 return true;
563 }
564 }
565 return false;
566}
567
568ScriptLanguage
569SBDebugger::GetScriptingLanguage (const char *script_language_name)
570{
Greg Claytonaf67cec2010-12-20 20:49:23 +0000571
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000572 return Args::StringToScriptLanguage (script_language_name,
573 eScriptLanguageDefault,
574 NULL);
575}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000576
577const char *
578SBDebugger::GetVersionString ()
579{
Virgile Bellob2f1fb22013-08-23 12:44:05 +0000580 return lldb_private::GetVersion();
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000581}
582
583const char *
Greg Clayton431ce672011-04-18 23:15:17 +0000584SBDebugger::StateAsCString (StateType state)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000585{
Caroline Ticec2bbb492011-04-25 22:05:51 +0000586 return lldb_private::StateAsCString (state);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000587}
588
589bool
Greg Clayton431ce672011-04-18 23:15:17 +0000590SBDebugger::StateIsRunningState (StateType state)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000591{
Greg Clayton5160ce52013-03-27 23:08:40 +0000592 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000593
Caroline Ticec2bbb492011-04-25 22:05:51 +0000594 const bool result = lldb_private::StateIsRunningState (state);
Greg Clayton48381312010-10-30 04:51:46 +0000595 if (log)
596 log->Printf ("SBDebugger::StateIsRunningState (state=%s) => %i",
Greg Clayton431ce672011-04-18 23:15:17 +0000597 StateAsCString (state), result);
Greg Clayton48381312010-10-30 04:51:46 +0000598
599 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000600}
601
602bool
Greg Clayton431ce672011-04-18 23:15:17 +0000603SBDebugger::StateIsStoppedState (StateType state)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000604{
Greg Clayton5160ce52013-03-27 23:08:40 +0000605 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000606
Greg Clayton2637f822011-11-17 01:23:07 +0000607 const bool result = lldb_private::StateIsStoppedState (state, false);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000608 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000609 log->Printf ("SBDebugger::StateIsStoppedState (state=%s) => %i",
Greg Clayton431ce672011-04-18 23:15:17 +0000610 StateAsCString (state), result);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000611
Greg Clayton48381312010-10-30 04:51:46 +0000612 return result;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000613}
614
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000615lldb::SBTarget
616SBDebugger::CreateTarget (const char *filename,
617 const char *target_triple,
618 const char *platform_name,
619 bool add_dependent_modules,
620 lldb::SBError& sb_error)
621{
622 SBTarget sb_target;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000623 TargetSP target_sp;
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000624 if (m_opaque_sp)
625 {
626 sb_error.Clear();
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000627 OptionGroupPlatform platform_options (false);
628 platform_options.SetPlatformName (platform_name);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000629
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000630 sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
Greg Claytona0ca6602012-10-18 16:33:33 +0000631 filename,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000632 target_triple,
633 add_dependent_modules,
634 &platform_options,
635 target_sp);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000636
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000637 if (sb_error.Success())
Greg Claytonb9556ac2012-01-30 07:41:31 +0000638 sb_target.SetSP (target_sp);
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000639 }
640 else
641 {
642 sb_error.SetErrorString("invalid target");
643 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000644
Greg Clayton5160ce52013-03-27 23:08:40 +0000645 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000646 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000647 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, platform_name=%s, add_dependent_modules=%u, error=%s) => SBTarget(%p)",
648 static_cast<void*>(m_opaque_sp.get()), filename,
649 target_triple, platform_name, add_dependent_modules,
650 sb_error.GetCString(), static_cast<void*>(target_sp.get()));
651
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000652 return sb_target;
653}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000654
655SBTarget
656SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename,
657 const char *target_triple)
658{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000659 SBTarget sb_target;
660 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000661 if (m_opaque_sp)
662 {
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000663 const bool add_dependent_modules = true;
664 Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
Greg Claytona0ca6602012-10-18 16:33:33 +0000665 filename,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000666 target_triple,
667 add_dependent_modules,
668 NULL,
669 target_sp));
Greg Claytonb9556ac2012-01-30 07:41:31 +0000670 sb_target.SetSP (target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000671 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000672
Greg Clayton5160ce52013-03-27 23:08:40 +0000673 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000674 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000675 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)",
676 static_cast<void*>(m_opaque_sp.get()), filename,
677 target_triple, static_cast<void*>(target_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000678
Greg Claytonb9556ac2012-01-30 07:41:31 +0000679 return sb_target;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000680}
681
682SBTarget
Greg Clayton64195a22011-02-23 00:35:02 +0000683SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_cstr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000684{
Greg Clayton5160ce52013-03-27 23:08:40 +0000685 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000686
Greg Claytonb9556ac2012-01-30 07:41:31 +0000687 SBTarget sb_target;
688 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000689 if (m_opaque_sp)
690 {
Greg Clayton66111032010-06-23 01:19:29 +0000691 Error error;
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000692 const bool add_dependent_modules = true;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000693
Greg Claytona0ca6602012-10-18 16:33:33 +0000694 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
695 filename,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000696 arch_cstr,
697 add_dependent_modules,
698 NULL,
699 target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000700
701 if (error.Success())
702 {
Jim Ingham2976d002010-08-26 21:32:51 +0000703 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000704 sb_target.SetSP (target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000705 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000706 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000707
708 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000709 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)",
710 static_cast<void*>(m_opaque_sp.get()), filename, arch_cstr,
711 static_cast<void*>(target_sp.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000712
Greg Claytonb9556ac2012-01-30 07:41:31 +0000713 return sb_target;
Greg Clayton66111032010-06-23 01:19:29 +0000714}
715
716SBTarget
717SBDebugger::CreateTarget (const char *filename)
718{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000719 SBTarget sb_target;
720 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000721 if (m_opaque_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000722 {
Greg Clayton66111032010-06-23 01:19:29 +0000723 Error error;
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000724 const bool add_dependent_modules = true;
Greg Claytonbf702ce2014-11-13 18:30:06 +0000725 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
Greg Claytona0ca6602012-10-18 16:33:33 +0000726 filename,
Greg Claytonbf702ce2014-11-13 18:30:06 +0000727 NULL,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000728 add_dependent_modules,
Greg Claytonbf702ce2014-11-13 18:30:06 +0000729 NULL,
Greg Claytoncac9c5f2011-09-24 00:52:29 +0000730 target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000731
732 if (error.Success())
733 {
Jim Ingham2976d002010-08-26 21:32:51 +0000734 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000735 sb_target.SetSP (target_sp);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000736 }
737 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000738 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000739 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000740 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
741 static_cast<void*>(m_opaque_sp.get()), filename,
742 static_cast<void*>(target_sp.get()));
Greg Claytonb9556ac2012-01-30 07:41:31 +0000743 return sb_target;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000744}
745
Johnny Chen3794ad92011-06-15 21:24:24 +0000746bool
747SBDebugger::DeleteTarget (lldb::SBTarget &target)
748{
749 bool result = false;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000750 if (m_opaque_sp)
Johnny Chen3794ad92011-06-15 21:24:24 +0000751 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000752 TargetSP target_sp(target.GetSP());
753 if (target_sp)
754 {
755 // No need to lock, the target list is thread safe
756 result = m_opaque_sp->GetTargetList().DeleteTarget (target_sp);
757 target_sp->Destroy();
758 target.Clear();
Greg Clayton0cd70862012-04-09 20:22:01 +0000759 const bool mandatory = true;
760 ModuleList::RemoveOrphanSharedModules(mandatory);
Greg Claytonb9556ac2012-01-30 07:41:31 +0000761 }
Johnny Chen3794ad92011-06-15 21:24:24 +0000762 }
763
Greg Clayton5160ce52013-03-27 23:08:40 +0000764 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Johnny Chen3794ad92011-06-15 21:24:24 +0000765 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000766 log->Printf ("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
767 static_cast<void*>(m_opaque_sp.get()),
768 static_cast<void*>(target.m_opaque_sp.get()), result);
Johnny Chen3794ad92011-06-15 21:24:24 +0000769
770 return result;
771}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000772SBTarget
773SBDebugger::GetTargetAtIndex (uint32_t idx)
774{
Greg Clayton66111032010-06-23 01:19:29 +0000775 SBTarget sb_target;
776 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000777 {
778 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000779 sb_target.SetSP (m_opaque_sp->GetTargetList().GetTargetAtIndex (idx));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000780 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000781 return sb_target;
782}
783
Jim Ingham8499e1a2012-05-08 23:06:07 +0000784uint32_t
785SBDebugger::GetIndexOfTarget (lldb::SBTarget target)
786{
787
788 lldb::TargetSP target_sp = target.GetSP();
789 if (!target_sp)
790 return UINT32_MAX;
791
792 if (!m_opaque_sp)
793 return UINT32_MAX;
794
795 return m_opaque_sp->GetTargetList().GetIndexOfTarget (target.GetSP());
796}
797
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000798SBTarget
Virgile Bello997f6f72013-09-05 16:53:14 +0000799SBDebugger::FindTargetWithProcessID (lldb::pid_t pid)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000800{
Greg Clayton66111032010-06-23 01:19:29 +0000801 SBTarget sb_target;
802 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000803 {
804 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000805 sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000806 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000807 return sb_target;
808}
809
810SBTarget
811SBDebugger::FindTargetWithFileAndArch (const char *filename, const char *arch_name)
812{
Greg Clayton66111032010-06-23 01:19:29 +0000813 SBTarget sb_target;
814 if (m_opaque_sp && filename && filename[0])
815 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000816 // No need to lock, the target list is thread safe
Greg Claytoneb0103f2011-04-07 22:46:35 +0000817 ArchSpec arch (arch_name, m_opaque_sp->GetPlatformList().GetSelectedPlatform().get());
Greg Clayton274060b2010-10-20 20:54:39 +0000818 TargetSP target_sp (m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture (FileSpec(filename, false), arch_name ? &arch : NULL));
Greg Claytonb9556ac2012-01-30 07:41:31 +0000819 sb_target.SetSP (target_sp);
Greg Clayton66111032010-06-23 01:19:29 +0000820 }
821 return sb_target;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000822}
823
824SBTarget
Greg Clayton431ce672011-04-18 23:15:17 +0000825SBDebugger::FindTargetWithLLDBProcess (const ProcessSP &process_sp)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000826{
Greg Clayton66111032010-06-23 01:19:29 +0000827 SBTarget sb_target;
828 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000829 {
830 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000831 sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get()));
Greg Claytonaf67cec2010-12-20 20:49:23 +0000832 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000833 return sb_target;
834}
835
836
837uint32_t
838SBDebugger::GetNumTargets ()
839{
Greg Clayton66111032010-06-23 01:19:29 +0000840 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000841 {
842 // No need to lock, the target list is thread safe
Greg Clayton66111032010-06-23 01:19:29 +0000843 return m_opaque_sp->GetTargetList().GetNumTargets ();
Greg Claytonaf67cec2010-12-20 20:49:23 +0000844 }
Greg Clayton66111032010-06-23 01:19:29 +0000845 return 0;
846}
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000847
848SBTarget
Jim Ingham2976d002010-08-26 21:32:51 +0000849SBDebugger::GetSelectedTarget ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000850{
Greg Clayton5160ce52013-03-27 23:08:40 +0000851 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000852
Greg Clayton66111032010-06-23 01:19:29 +0000853 SBTarget sb_target;
Greg Claytonb9556ac2012-01-30 07:41:31 +0000854 TargetSP target_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000855 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +0000856 {
857 // No need to lock, the target list is thread safe
Greg Claytonb9556ac2012-01-30 07:41:31 +0000858 target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget ();
859 sb_target.SetSP (target_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000860 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000861
862 if (log)
863 {
864 SBStream sstr;
Greg Clayton431ce672011-04-18 23:15:17 +0000865 sb_target.GetDescription (sstr, eDescriptionLevelBrief);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000866 log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
867 static_cast<void*>(m_opaque_sp.get()),
868 static_cast<void*>(target_sp.get()), sstr.GetData());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000869 }
870
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000871 return sb_target;
872}
873
874void
Jim Inghame64f0dc2011-09-13 23:25:31 +0000875SBDebugger::SetSelectedTarget (SBTarget &sb_target)
876{
Greg Clayton5160ce52013-03-27 23:08:40 +0000877 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Jim Inghame64f0dc2011-09-13 23:25:31 +0000878
Greg Claytonb9556ac2012-01-30 07:41:31 +0000879 TargetSP target_sp (sb_target.GetSP());
Jim Inghame64f0dc2011-09-13 23:25:31 +0000880 if (m_opaque_sp)
881 {
Greg Claytonb9556ac2012-01-30 07:41:31 +0000882 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
Jim Inghame64f0dc2011-09-13 23:25:31 +0000883 }
884 if (log)
885 {
886 SBStream sstr;
887 sb_target.GetDescription (sstr, eDescriptionLevelBrief);
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000888 log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
889 static_cast<void*>(m_opaque_sp.get()),
890 static_cast<void*>(target_sp.get()), sstr.GetData());
Jim Inghame64f0dc2011-09-13 23:25:31 +0000891 }
892}
893
Greg Claytonfbb76342013-11-20 21:07:01 +0000894SBPlatform
895SBDebugger::GetSelectedPlatform()
896{
897 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
898
899 SBPlatform sb_platform;
900 DebuggerSP debugger_sp(m_opaque_sp);
901 if (debugger_sp)
902 {
903 sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform());
904 }
905 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000906 log->Printf ("SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
907 static_cast<void*>(m_opaque_sp.get()),
908 static_cast<void*>(sb_platform.GetSP().get()),
909 sb_platform.GetName());
Greg Claytonfbb76342013-11-20 21:07:01 +0000910 return sb_platform;
911}
912
913void
914SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform)
915{
916 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000917
Greg Claytonfbb76342013-11-20 21:07:01 +0000918 DebuggerSP debugger_sp(m_opaque_sp);
919 if (debugger_sp)
920 {
921 debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP());
922 }
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000923
Greg Claytonfbb76342013-11-20 21:07:01 +0000924 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000925 log->Printf ("SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
926 static_cast<void*>(m_opaque_sp.get()),
927 static_cast<void*>(sb_platform.GetSP().get()),
928 sb_platform.GetName());
Greg Claytonfbb76342013-11-20 21:07:01 +0000929}
930
Jim Inghame64f0dc2011-09-13 23:25:31 +0000931void
Enrico Granatac30a73a2012-09-06 22:02:28 +0000932SBDebugger::DispatchInput (void* baton, const void *data, size_t data_len)
Enrico Granata6b09d422012-09-06 21:58:25 +0000933{
934 DispatchInput (data,data_len);
935}
936
937void
Filipe Cabecinhasc3019992012-08-20 16:21:04 +0000938SBDebugger::DispatchInput (const void *data, size_t data_len)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000939{
Greg Clayton44d93782014-01-27 23:43:24 +0000940// Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
941//
942// if (log)
943// log->Printf ("SBDebugger(%p)::DispatchInput (data=\"%.*s\", size_t=%" PRIu64 ")",
944// m_opaque_sp.get(),
945// (int) data_len,
946// (const char *) data,
947// (uint64_t)data_len);
948//
949// if (m_opaque_sp)
950// m_opaque_sp->DispatchInput ((const char *) data, data_len);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000951}
952
953void
Caroline Ticeefed6132010-11-19 20:47:54 +0000954SBDebugger::DispatchInputInterrupt ()
955{
956 if (m_opaque_sp)
957 m_opaque_sp->DispatchInputInterrupt ();
958}
959
960void
961SBDebugger::DispatchInputEndOfFile ()
962{
963 if (m_opaque_sp)
964 m_opaque_sp->DispatchInputEndOfFile ();
965}
966
967void
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000968SBDebugger::PushInputReader (SBInputReader &reader)
969{
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000970}
Greg Clayton66111032010-06-23 01:19:29 +0000971
972void
Greg Clayton44d93782014-01-27 23:43:24 +0000973SBDebugger::RunCommandInterpreter (bool auto_handle_events,
974 bool spawn_thread)
Caroline Tice969ed3d2011-05-02 20:41:46 +0000975{
Caroline Tice969ed3d2011-05-02 20:41:46 +0000976 if (m_opaque_sp)
Jim Ingham26c7bf92014-10-11 00:38:27 +0000977 {
978 CommandInterpreterRunOptions options;
979
980 m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(auto_handle_events,
981 spawn_thread,
982 options);
983 }
984}
985
986void
987SBDebugger::RunCommandInterpreter (bool auto_handle_events,
988 bool spawn_thread,
989 SBCommandInterpreterRunOptions &options,
990 int &num_errors,
Jim Inghamffc9f1d2014-10-14 01:20:07 +0000991 bool &quit_requested,
992 bool &stopped_for_crash)
Jim Ingham26c7bf92014-10-11 00:38:27 +0000993
994{
995 if (m_opaque_sp)
996 {
997 CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
998 interp.RunCommandInterpreter(auto_handle_events, spawn_thread, options.ref());
999 num_errors = interp.GetNumErrors();
1000 quit_requested = interp.GetQuitRequested();
Jim Inghamffc9f1d2014-10-14 01:20:07 +00001001 stopped_for_crash = interp.GetStoppedForCrash();
Jim Ingham26c7bf92014-10-11 00:38:27 +00001002 }
Caroline Tice969ed3d2011-05-02 20:41:46 +00001003}
1004
1005void
Greg Clayton431ce672011-04-18 23:15:17 +00001006SBDebugger::reset (const DebuggerSP &debugger_sp)
Greg Clayton66111032010-06-23 01:19:29 +00001007{
1008 m_opaque_sp = debugger_sp;
1009}
1010
1011Debugger *
1012SBDebugger::get () const
1013{
1014 return m_opaque_sp.get();
1015}
1016
1017Debugger &
1018SBDebugger::ref () const
1019{
1020 assert (m_opaque_sp.get());
1021 return *m_opaque_sp;
1022}
1023
Greg Clayton9a377662011-10-01 02:59:24 +00001024const lldb::DebuggerSP &
1025SBDebugger::get_sp () const
1026{
1027 return m_opaque_sp;
1028}
Greg Clayton66111032010-06-23 01:19:29 +00001029
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001030SBDebugger
1031SBDebugger::FindDebuggerWithID (int id)
1032{
Greg Claytonaf67cec2010-12-20 20:49:23 +00001033 // No need to lock, the debugger list is thread safe
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001034 SBDebugger sb_debugger;
Greg Clayton431ce672011-04-18 23:15:17 +00001035 DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id);
Caroline Ticeebc1bb22010-06-30 16:22:25 +00001036 if (debugger_sp)
1037 sb_debugger.reset (debugger_sp);
1038 return sb_debugger;
1039}
Jim Inghame40e4212010-08-30 19:44:40 +00001040
Caroline Ticedd759852010-09-09 17:45:09 +00001041const char *
1042SBDebugger::GetInstanceName()
1043{
Greg Clayton6920b522012-08-22 18:39:03 +00001044 if (m_opaque_sp)
1045 return m_opaque_sp->GetInstanceName().AsCString();
1046 else
Caroline Ticedd759852010-09-09 17:45:09 +00001047 return NULL;
1048}
1049
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001050SBError
Caroline Ticedd759852010-09-09 17:45:09 +00001051SBDebugger::SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001052{
Greg Clayton6920b522012-08-22 18:39:03 +00001053 SBError sb_error;
1054 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName (ConstString(debugger_instance_name)));
1055 Error error;
1056 if (debugger_sp)
1057 {
1058 ExecutionContext exe_ctx (debugger_sp->GetCommandInterpreter().GetExecutionContext());
1059 error = debugger_sp->SetPropertyValue (&exe_ctx,
1060 eVarSetOperationAssign,
1061 var_name,
1062 value);
1063 }
1064 else
1065 {
1066 error.SetErrorStringWithFormat ("invalid debugger instance name '%s'", debugger_instance_name);
1067 }
1068 if (error.Fail())
1069 sb_error.SetError(error);
1070 return sb_error;
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001071}
1072
Greg Clayton431ce672011-04-18 23:15:17 +00001073SBStringList
Caroline Ticedd759852010-09-09 17:45:09 +00001074SBDebugger::GetInternalVariableValue (const char *var_name, const char *debugger_instance_name)
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001075{
1076 SBStringList ret_value;
Greg Clayton6920b522012-08-22 18:39:03 +00001077 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName (ConstString(debugger_instance_name)));
1078 Error error;
1079 if (debugger_sp)
1080 {
1081 ExecutionContext exe_ctx (debugger_sp->GetCommandInterpreter().GetExecutionContext());
1082 lldb::OptionValueSP value_sp (debugger_sp->GetPropertyValue (&exe_ctx,
1083 var_name,
1084 false,
1085 error));
1086 if (value_sp)
1087 {
1088 StreamString value_strm;
1089 value_sp->DumpValue (&exe_ctx, value_strm, OptionValue::eDumpOptionValue);
1090 const std::string &value_str = value_strm.GetString();
1091 if (!value_str.empty())
1092 {
1093 StringList string_list;
Greg Clayton44d93782014-01-27 23:43:24 +00001094 string_list.SplitIntoLines(value_str);
Greg Clayton6920b522012-08-22 18:39:03 +00001095 return SBStringList(&string_list);
1096 }
1097 }
1098 }
1099 return SBStringList();
Caroline Tice3df9a8d2010-09-04 00:03:46 +00001100}
1101
Greg Claytona7015092010-09-18 01:14:36 +00001102uint32_t
1103SBDebugger::GetTerminalWidth () const
1104{
1105 if (m_opaque_sp)
1106 return m_opaque_sp->GetTerminalWidth ();
1107 return 0;
1108}
1109
1110void
1111SBDebugger::SetTerminalWidth (uint32_t term_width)
1112{
1113 if (m_opaque_sp)
1114 m_opaque_sp->SetTerminalWidth (term_width);
1115}
1116
1117const char *
1118SBDebugger::GetPrompt() const
1119{
Greg Clayton5160ce52013-03-27 23:08:40 +00001120 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001121
Caroline Ticeceb6b132010-10-26 03:11:13 +00001122 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +00001123 log->Printf ("SBDebugger(%p)::GetPrompt () => \"%s\"",
1124 static_cast<void*>(m_opaque_sp.get()),
Caroline Tice750cd172010-10-26 23:49:36 +00001125 (m_opaque_sp ? m_opaque_sp->GetPrompt() : ""));
Caroline Ticeceb6b132010-10-26 03:11:13 +00001126
Greg Claytona7015092010-09-18 01:14:36 +00001127 if (m_opaque_sp)
1128 return m_opaque_sp->GetPrompt ();
1129 return 0;
1130}
1131
1132void
1133SBDebugger::SetPrompt (const char *prompt)
1134{
1135 if (m_opaque_sp)
1136 m_opaque_sp->SetPrompt (prompt);
1137}
1138
1139
Greg Clayton431ce672011-04-18 23:15:17 +00001140ScriptLanguage
Greg Claytona7015092010-09-18 01:14:36 +00001141SBDebugger::GetScriptLanguage() const
1142{
1143 if (m_opaque_sp)
1144 return m_opaque_sp->GetScriptLanguage ();
1145 return eScriptLanguageNone;
1146}
1147
1148void
Greg Clayton431ce672011-04-18 23:15:17 +00001149SBDebugger::SetScriptLanguage (ScriptLanguage script_lang)
Greg Claytona7015092010-09-18 01:14:36 +00001150{
1151 if (m_opaque_sp)
Greg Claytonaf67cec2010-12-20 20:49:23 +00001152 {
Greg Claytona7015092010-09-18 01:14:36 +00001153 m_opaque_sp->SetScriptLanguage (script_lang);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001154 }
Greg Claytona7015092010-09-18 01:14:36 +00001155}
1156
Jim Inghame40e4212010-08-30 19:44:40 +00001157bool
1158SBDebugger::SetUseExternalEditor (bool value)
1159{
1160 if (m_opaque_sp)
1161 return m_opaque_sp->SetUseExternalEditor (value);
Greg Claytonaf67cec2010-12-20 20:49:23 +00001162 return false;
Jim Inghame40e4212010-08-30 19:44:40 +00001163}
1164
1165bool
Caroline Ticedaccaa92010-09-20 20:44:43 +00001166SBDebugger::GetUseExternalEditor ()
Jim Inghame40e4212010-08-30 19:44:40 +00001167{
1168 if (m_opaque_sp)
Caroline Ticedaccaa92010-09-20 20:44:43 +00001169 return m_opaque_sp->GetUseExternalEditor ();
Greg Claytonaf67cec2010-12-20 20:49:23 +00001170 return false;
Jim Inghame40e4212010-08-30 19:44:40 +00001171}
1172
Caroline Ticedde9cff2010-09-20 05:20:02 +00001173bool
Michael Sartainc3ce7f272013-05-23 20:47:45 +00001174SBDebugger::SetUseColor (bool value)
1175{
1176 if (m_opaque_sp)
1177 return m_opaque_sp->SetUseColor (value);
1178 return false;
1179}
1180
1181bool
1182SBDebugger::GetUseColor () const
1183{
1184 if (m_opaque_sp)
1185 return m_opaque_sp->GetUseColor ();
1186 return false;
1187}
1188
1189bool
Caroline Ticedde9cff2010-09-20 05:20:02 +00001190SBDebugger::GetDescription (SBStream &description)
1191{
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001192 Stream &strm = description.ref();
1193
Caroline Ticedde9cff2010-09-20 05:20:02 +00001194 if (m_opaque_sp)
1195 {
1196 const char *name = m_opaque_sp->GetInstanceName().AsCString();
Greg Clayton431ce672011-04-18 23:15:17 +00001197 user_id_t id = m_opaque_sp->GetID();
Daniel Malead01b2952012-11-29 21:49:15 +00001198 strm.Printf ("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id);
Caroline Ticedde9cff2010-09-20 05:20:02 +00001199 }
1200 else
Greg Claytonda7bc7d2011-11-13 06:57:31 +00001201 strm.PutCString ("No value");
Caroline Ticedde9cff2010-09-20 05:20:02 +00001202
1203 return true;
1204}
Caroline Ticeefed6132010-11-19 20:47:54 +00001205
Greg Clayton431ce672011-04-18 23:15:17 +00001206user_id_t
Caroline Ticeefed6132010-11-19 20:47:54 +00001207SBDebugger::GetID()
1208{
1209 if (m_opaque_sp)
1210 return m_opaque_sp->GetID();
1211 return LLDB_INVALID_UID;
1212}
Greg Clayton2289fa42011-04-30 01:09:13 +00001213
1214
1215SBError
Greg Clayton615eb7e2014-09-19 20:11:50 +00001216SBDebugger::SetCurrentPlatform (const char *platform_name_cstr)
Greg Clayton2289fa42011-04-30 01:09:13 +00001217{
1218 SBError sb_error;
1219 if (m_opaque_sp)
1220 {
Greg Clayton615eb7e2014-09-19 20:11:50 +00001221 if (platform_name_cstr && platform_name_cstr[0])
Greg Clayton2289fa42011-04-30 01:09:13 +00001222 {
Greg Clayton615eb7e2014-09-19 20:11:50 +00001223 ConstString platform_name (platform_name_cstr);
1224 PlatformSP platform_sp (Platform::Find (platform_name));
1225
1226 if (platform_sp)
1227 {
1228 // Already have a platform with this name, just select it
1229 m_opaque_sp->GetPlatformList().SetSelectedPlatform(platform_sp);
1230 }
1231 else
1232 {
1233 // We don't have a platform by this name yet, create one
1234 platform_sp = Platform::Create (platform_name, sb_error.ref());
1235 if (platform_sp)
1236 {
1237 // We created the platform, now append and select it
1238 bool make_selected = true;
1239 m_opaque_sp->GetPlatformList().Append (platform_sp, make_selected);
1240 }
1241 }
Greg Clayton2289fa42011-04-30 01:09:13 +00001242 }
Greg Clayton615eb7e2014-09-19 20:11:50 +00001243 else
1244 {
1245 sb_error.ref().SetErrorString("invalid platform name");
1246 }
1247 }
1248 else
1249 {
1250 sb_error.ref().SetErrorString("invalid debugger");
Greg Clayton2289fa42011-04-30 01:09:13 +00001251 }
1252 return sb_error;
1253}
1254
Greg Claytonfc3f0272011-05-29 04:06:55 +00001255bool
Greg Claytonf3dd93c2011-06-17 03:31:01 +00001256SBDebugger::SetCurrentPlatformSDKRoot (const char *sysroot)
1257{
1258 if (m_opaque_sp)
1259 {
1260 PlatformSP platform_sp (m_opaque_sp->GetPlatformList().GetSelectedPlatform());
1261
1262 if (platform_sp)
1263 {
1264 platform_sp->SetSDKRootDirectory (ConstString (sysroot));
1265 return true;
1266 }
1267 }
1268 return false;
1269}
1270
1271bool
Greg Claytonfc3f0272011-05-29 04:06:55 +00001272SBDebugger::GetCloseInputOnEOF () const
1273{
1274 if (m_opaque_sp)
1275 return m_opaque_sp->GetCloseInputOnEOF ();
1276 return false;
1277}
1278
1279void
1280SBDebugger::SetCloseInputOnEOF (bool b)
1281{
1282 if (m_opaque_sp)
1283 m_opaque_sp->SetCloseInputOnEOF (b);
1284}
Enrico Granata061858c2012-02-15 02:34:21 +00001285
1286SBTypeCategory
1287SBDebugger::GetCategory (const char* category_name)
1288{
1289 if (!category_name || *category_name == 0)
1290 return SBTypeCategory();
1291
1292 TypeCategoryImplSP category_sp;
1293
1294 if (DataVisualization::Categories::GetCategory(ConstString(category_name), category_sp, false))
1295 return SBTypeCategory(category_sp);
1296 else
1297 return SBTypeCategory();
1298}
1299
1300SBTypeCategory
1301SBDebugger::CreateCategory (const char* category_name)
1302{
1303 if (!category_name || *category_name == 0)
1304 return SBTypeCategory();
1305
1306 TypeCategoryImplSP category_sp;
1307
1308 if (DataVisualization::Categories::GetCategory(ConstString(category_name), category_sp, true))
1309 return SBTypeCategory(category_sp);
1310 else
1311 return SBTypeCategory();
1312}
1313
1314bool
1315SBDebugger::DeleteCategory (const char* category_name)
1316{
1317 if (!category_name || *category_name == 0)
1318 return false;
1319
1320 return DataVisualization::Categories::Delete(ConstString(category_name));
1321}
1322
1323uint32_t
1324SBDebugger::GetNumCategories()
1325{
1326 return DataVisualization::Categories::GetCount();
1327}
1328
1329SBTypeCategory
1330SBDebugger::GetCategoryAtIndex (uint32_t index)
1331{
1332 return SBTypeCategory(DataVisualization::Categories::GetCategoryAtIndex(index));
1333}
1334
1335SBTypeCategory
1336SBDebugger::GetDefaultCategory()
1337{
1338 return GetCategory("default");
1339}
1340
1341SBTypeFormat
1342SBDebugger::GetFormatForType (SBTypeNameSpecifier type_name)
1343{
1344 SBTypeCategory default_category_sb = GetDefaultCategory();
1345 if (default_category_sb.GetEnabled())
1346 return default_category_sb.GetFormatForType(type_name);
1347 return SBTypeFormat();
1348}
1349
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001350#ifndef LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001351SBTypeSummary
1352SBDebugger::GetSummaryForType (SBTypeNameSpecifier type_name)
1353{
Enrico Granataa777dc22012-05-08 21:49:57 +00001354 if (type_name.IsValid() == false)
1355 return SBTypeSummary();
1356 return SBTypeSummary(DataVisualization::GetSummaryForType(type_name.GetSP()));
Enrico Granata061858c2012-02-15 02:34:21 +00001357}
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001358#endif // LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001359
1360SBTypeFilter
1361SBDebugger::GetFilterForType (SBTypeNameSpecifier type_name)
1362{
Enrico Granataa777dc22012-05-08 21:49:57 +00001363 if (type_name.IsValid() == false)
1364 return SBTypeFilter();
1365 return SBTypeFilter(DataVisualization::GetFilterForType(type_name.GetSP()));
Enrico Granata061858c2012-02-15 02:34:21 +00001366}
1367
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001368#ifndef LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001369SBTypeSynthetic
1370SBDebugger::GetSyntheticForType (SBTypeNameSpecifier type_name)
1371{
Enrico Granataa777dc22012-05-08 21:49:57 +00001372 if (type_name.IsValid() == false)
1373 return SBTypeSynthetic();
1374 return SBTypeSynthetic(DataVisualization::GetSyntheticForType(type_name.GetSP()));
Enrico Granata061858c2012-02-15 02:34:21 +00001375}
Jason Molendacf7e2dc2012-02-21 05:33:55 +00001376#endif // LLDB_DISABLE_PYTHON
Enrico Granata061858c2012-02-15 02:34:21 +00001377
Jim Ingham228063c2012-02-21 02:23:08 +00001378bool
1379SBDebugger::EnableLog (const char *channel, const char **categories)
1380{
1381 if (m_opaque_sp)
1382 {
1383 uint32_t log_options = LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1384 StreamString errors;
1385 return m_opaque_sp->EnableLog (channel, categories, NULL, log_options, errors);
1386
1387 }
1388 else
1389 return false;
1390}
Jim Ingham4f02b222012-02-22 22:49:20 +00001391
1392void
1393SBDebugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
1394{
1395 if (m_opaque_sp)
1396 {
1397 return m_opaque_sp->SetLoggingCallback (log_callback, baton);
1398 }
1399}
1400
1401