blob: cd1e28e71155757fb7ad4c8bef81d527d98a8f1f [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- SBCommandInterpreter.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
10#include "lldb/lldb-types.h"
Zachary Turner2c1f46d2015-07-30 20:28:07 +000011
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "lldb/Core/Listener.h"
13#include "lldb/Interpreter/CommandInterpreter.h"
Enrico Granata21dfcd92012-09-28 23:57:51 +000014#include "lldb/Interpreter/CommandObjectMultiword.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000015#include "lldb/Interpreter/CommandReturnObject.h"
16#include "lldb/Target/Target.h"
17
Eli Friedmanca93cc12010-06-09 07:37:52 +000018#include "lldb/API/SBBroadcaster.h"
Eli Friedmanca93cc12010-06-09 07:37:52 +000019#include "lldb/API/SBCommandReturnObject.h"
Eli Friedmanca93cc12010-06-09 07:37:52 +000020#include "lldb/API/SBCommandInterpreter.h"
Ilia Kaf10e1c2015-03-21 10:53:37 +000021#include "lldb/API/SBEvent.h"
Jim Inghamffc9f1d2014-10-14 01:20:07 +000022#include "lldb/API/SBExecutionContext.h"
Eli Friedmanca93cc12010-06-09 07:37:52 +000023#include "lldb/API/SBProcess.h"
24#include "lldb/API/SBTarget.h"
25#include "lldb/API/SBListener.h"
Caroline Ticeceb6b132010-10-26 03:11:13 +000026#include "lldb/API/SBStream.h"
Eli Friedmanca93cc12010-06-09 07:37:52 +000027#include "lldb/API/SBStringList.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000028
29using namespace lldb;
30using namespace lldb_private;
31
Jim Ingham26c7bf92014-10-11 00:38:27 +000032SBCommandInterpreterRunOptions::SBCommandInterpreterRunOptions()
33{
34 m_opaque_up.reset(new CommandInterpreterRunOptions());
35}
36
37SBCommandInterpreterRunOptions::~SBCommandInterpreterRunOptions()
38{
39
40}
41
42bool
43SBCommandInterpreterRunOptions::GetStopOnContinue () const
44{
45 return m_opaque_up->GetStopOnContinue();
46}
47
48void
49SBCommandInterpreterRunOptions::SetStopOnContinue (bool stop_on_continue)
50{
51 m_opaque_up->SetStopOnContinue(stop_on_continue);
52}
53
54bool
55SBCommandInterpreterRunOptions::GetStopOnError () const
56{
57 return m_opaque_up->GetStopOnError();
58}
59
60void
61SBCommandInterpreterRunOptions::SetStopOnError (bool stop_on_error)
62{
63 m_opaque_up->SetStopOnError(stop_on_error);
64}
65
66bool
67SBCommandInterpreterRunOptions::GetStopOnCrash () const
68{
69 return m_opaque_up->GetStopOnCrash();
70}
71
72void
73SBCommandInterpreterRunOptions::SetStopOnCrash (bool stop_on_crash)
74{
75 m_opaque_up->SetStopOnCrash(stop_on_crash);
76}
77
78bool
79SBCommandInterpreterRunOptions::GetEchoCommands () const
80{
81 return m_opaque_up->GetEchoCommands();
82}
83
84void
85SBCommandInterpreterRunOptions::SetEchoCommands (bool echo_commands)
86{
87 m_opaque_up->SetEchoCommands(echo_commands);
88}
89
90bool
91SBCommandInterpreterRunOptions::GetPrintResults () const
92{
93 return m_opaque_up->GetPrintResults();
94}
95
96void
97SBCommandInterpreterRunOptions::SetPrintResults (bool print_results)
98{
99 m_opaque_up->SetPrintResults(print_results);
100}
101
102bool
103SBCommandInterpreterRunOptions::GetAddToHistory () const
104{
105 return m_opaque_up->GetAddToHistory();
106}
107
108void
109SBCommandInterpreterRunOptions::SetAddToHistory (bool add_to_history)
110{
111 m_opaque_up->SetAddToHistory(add_to_history);
112}
113
114lldb_private::CommandInterpreterRunOptions *
115SBCommandInterpreterRunOptions::get () const
116{
117 return m_opaque_up.get();
118}
119
120lldb_private::CommandInterpreterRunOptions &
121SBCommandInterpreterRunOptions::ref () const
122{
123 return *m_opaque_up.get();
124}
125
Enrico Granata21dfcd92012-09-28 23:57:51 +0000126class CommandPluginInterfaceImplementation : public CommandObjectParsed
127{
128public:
129 CommandPluginInterfaceImplementation (CommandInterpreter &interpreter,
130 const char *name,
131 lldb::SBCommandPluginInterface* backend,
132 const char *help = NULL,
133 const char *syntax = NULL,
134 uint32_t flags = 0) :
135 CommandObjectParsed (interpreter, name, help, syntax, flags),
136 m_backend(backend) {}
137
138 virtual bool
Greg Clayton3a18e312012-10-08 22:41:53 +0000139 IsRemovable() const { return true; }
Enrico Granata21dfcd92012-09-28 23:57:51 +0000140
141protected:
142 virtual bool
143 DoExecute (Args& command, CommandReturnObject &result)
144 {
145 SBCommandReturnObject sb_return(&result);
146 SBCommandInterpreter sb_interpreter(&m_interpreter);
147 SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this());
148 bool ret = m_backend->DoExecute (debugger_sb,(char**)command.GetArgumentVector(), sb_return);
149 sb_return.Release();
150 return ret;
151 }
152 lldb::SBCommandPluginInterface* m_backend;
153};
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000154
Greg Clayton66111032010-06-23 01:19:29 +0000155SBCommandInterpreter::SBCommandInterpreter (CommandInterpreter *interpreter) :
156 m_opaque_ptr (interpreter)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000157{
Greg Clayton5160ce52013-03-27 23:08:40 +0000158 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000159
160 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000161 log->Printf ("SBCommandInterpreter::SBCommandInterpreter (interpreter=%p)"
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000162 " => SBCommandInterpreter(%p)",
163 static_cast<void*>(interpreter),
164 static_cast<void*>(m_opaque_ptr));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000165}
166
Greg Claytonefabb122010-11-05 23:17:00 +0000167SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs) :
168 m_opaque_ptr (rhs.m_opaque_ptr)
169{
170}
171
172const SBCommandInterpreter &
173SBCommandInterpreter::operator = (const SBCommandInterpreter &rhs)
174{
175 m_opaque_ptr = rhs.m_opaque_ptr;
176 return *this;
177}
178
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000179SBCommandInterpreter::~SBCommandInterpreter ()
180{
181}
182
183bool
Greg Clayton66111032010-06-23 01:19:29 +0000184SBCommandInterpreter::IsValid() const
185{
186 return m_opaque_ptr != NULL;
187}
188
189
190bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000191SBCommandInterpreter::CommandExists (const char *cmd)
192{
Johnny Chen872e0622011-12-19 21:16:29 +0000193 if (cmd && m_opaque_ptr)
Greg Clayton66111032010-06-23 01:19:29 +0000194 return m_opaque_ptr->CommandExists (cmd);
195 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000196}
197
198bool
199SBCommandInterpreter::AliasExists (const char *cmd)
200{
Johnny Chen872e0622011-12-19 21:16:29 +0000201 if (cmd && m_opaque_ptr)
Greg Clayton66111032010-06-23 01:19:29 +0000202 return m_opaque_ptr->AliasExists (cmd);
203 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000204}
205
Greg Clayton44d93782014-01-27 23:43:24 +0000206bool
207SBCommandInterpreter::IsActive ()
208{
209 if (m_opaque_ptr)
210 return m_opaque_ptr->IsActive ();
211 return false;
212}
213
214const char *
215SBCommandInterpreter::GetIOHandlerControlSequence(char ch)
216{
217 if (m_opaque_ptr)
218 return m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence (ch).GetCString();
219 return NULL;
220}
221
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000222lldb::ReturnStatus
223SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history)
224{
Jim Inghamffc9f1d2014-10-14 01:20:07 +0000225 SBExecutionContext sb_exe_ctx;
226 return HandleCommand (command_line, sb_exe_ctx, result, add_to_history);
227}
228
229lldb::ReturnStatus
230SBCommandInterpreter::HandleCommand (const char *command_line, SBExecutionContext &override_context, SBCommandReturnObject &result, bool add_to_history)
231{
Greg Clayton5160ce52013-03-27 23:08:40 +0000232 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000233
234 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000235 log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p), add_to_history=%i)",
236 static_cast<void*>(m_opaque_ptr), command_line,
237 static_cast<void*>(result.get()), add_to_history);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000238
Jim Inghamffc9f1d2014-10-14 01:20:07 +0000239 ExecutionContext ctx, *ctx_ptr;
240 if (override_context.get())
241 {
242 ctx = override_context.get()->Lock(true);
243 ctx_ptr = &ctx;
244 }
245 else
246 ctx_ptr = nullptr;
247
248
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000249 result.Clear();
Johnny Chen872e0622011-12-19 21:16:29 +0000250 if (command_line && m_opaque_ptr)
Greg Clayton66111032010-06-23 01:19:29 +0000251 {
Greg Clayton45a44f32014-07-15 00:25:59 +0000252 result.ref().SetInteractive(false);
Jim Inghamffc9f1d2014-10-14 01:20:07 +0000253 m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref(), ctx_ptr);
Greg Clayton66111032010-06-23 01:19:29 +0000254 }
255 else
256 {
Johnny Chen872e0622011-12-19 21:16:29 +0000257 result->AppendError ("SBCommandInterpreter or the command line is not valid");
Greg Clayton66111032010-06-23 01:19:29 +0000258 result->SetStatus (eReturnStatusFailed);
259 }
Caroline Ticeceb6b132010-10-26 03:11:13 +0000260
Caroline Tice7b9da4a2010-10-27 21:23:37 +0000261 // We need to get the value again, in case the command disabled the log!
262 log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000263 if (log)
264 {
265 SBStream sstr;
266 result.GetDescription (sstr);
Greg Claytoncfd1ace2010-10-31 03:01:06 +0000267 log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p): %s, add_to_history=%i) => %i",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000268 static_cast<void*>(m_opaque_ptr), command_line,
269 static_cast<void*>(result.get()), sstr.GetData(),
270 add_to_history, result.GetStatus());
Caroline Ticeceb6b132010-10-26 03:11:13 +0000271 }
272
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000273 return result.GetStatus();
274}
275
Jim Inghamffc9f1d2014-10-14 01:20:07 +0000276void
277SBCommandInterpreter::HandleCommandsFromFile (lldb::SBFileSpec &file,
278 lldb::SBExecutionContext &override_context,
279 lldb::SBCommandInterpreterRunOptions &options,
280 lldb::SBCommandReturnObject result)
281{
282 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
283
284 if (log)
285 {
286 SBStream s;
287 file.GetDescription (s);
288 log->Printf ("SBCommandInterpreter(%p)::HandleCommandsFromFile (file=\"%s\", SBCommandReturnObject(%p))",
289 static_cast<void*>(m_opaque_ptr), s.GetData(),
290 static_cast<void*>(result.get()));
291 }
292
293 if (!m_opaque_ptr)
294 {
295 result->AppendError ("SBCommandInterpreter is not valid.");
296 result->SetStatus (eReturnStatusFailed);
297 return;
298 }
299
300 if (!file.IsValid())
301 {
302 SBStream s;
303 file.GetDescription (s);
304 result->AppendErrorWithFormat ("File is not valid: %s.", s.GetData());
305 result->SetStatus (eReturnStatusFailed);
306 }
307
308 FileSpec tmp_spec = file.ref();
309 ExecutionContext ctx, *ctx_ptr;
310 if (override_context.get())
311 {
312 ctx = override_context.get()->Lock(true);
313 ctx_ptr = &ctx;
314 }
315 else
316 ctx_ptr = nullptr;
317
318
319 m_opaque_ptr->HandleCommandsFromFile (tmp_spec, ctx_ptr, options.ref(), result.ref());
320
321}
322
323
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000324int
325SBCommandInterpreter::HandleCompletion (const char *current_line,
326 const char *cursor,
327 const char *last_char,
328 int match_start_point,
329 int max_return_elements,
330 SBStringList &matches)
331{
Greg Clayton5160ce52013-03-27 23:08:40 +0000332 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton66111032010-06-23 01:19:29 +0000333 int num_completions = 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000334
Jim Inghamac012602011-12-05 19:24:15 +0000335 // Sanity check the arguments that are passed in:
336 // cursor & last_char have to be within the current_line.
337 if (current_line == NULL || cursor == NULL || last_char == NULL)
338 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000339
Jim Inghamac012602011-12-05 19:24:15 +0000340 if (cursor < current_line || last_char < current_line)
341 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000342
Jim Inghamac012602011-12-05 19:24:15 +0000343 size_t current_line_size = strlen (current_line);
Saleem Abdulrasool3985c8c2014-04-02 03:51:35 +0000344 if (cursor - current_line > static_cast<ptrdiff_t>(current_line_size) ||
345 last_char - current_line > static_cast<ptrdiff_t>(current_line_size))
Jim Inghamac012602011-12-05 19:24:15 +0000346 return 0;
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000347
Jim Ingham389512d2012-06-26 01:21:59 +0000348 if (log)
Daniel Malead01b2952012-11-29 21:49:15 +0000349 log->Printf ("SBCommandInterpreter(%p)::HandleCompletion (current_line=\"%s\", cursor at: %" PRId64 ", last char at: %" PRId64 ", match_start_point: %d, max_return_elements: %d)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000350 static_cast<void*>(m_opaque_ptr), current_line,
351 static_cast<uint64_t>(cursor - current_line),
352 static_cast<uint64_t>(last_char - current_line),
353 match_start_point, max_return_elements);
354
Greg Clayton66111032010-06-23 01:19:29 +0000355 if (m_opaque_ptr)
356 {
357 lldb_private::StringList lldb_matches;
358 num_completions = m_opaque_ptr->HandleCompletion (current_line, cursor, last_char, match_start_point,
359 max_return_elements, lldb_matches);
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000360
Greg Clayton66111032010-06-23 01:19:29 +0000361 SBStringList temp_list (&lldb_matches);
362 matches.AppendList (temp_list);
363 }
Jim Ingham389512d2012-06-26 01:21:59 +0000364 if (log)
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000365 log->Printf ("SBCommandInterpreter(%p)::HandleCompletion - Found %d completions.",
366 static_cast<void*>(m_opaque_ptr), num_completions);
367
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000368 return num_completions;
369}
370
Jim Ingham969795f2011-09-21 01:17:13 +0000371int
372SBCommandInterpreter::HandleCompletion (const char *current_line,
373 uint32_t cursor_pos,
374 int match_start_point,
375 int max_return_elements,
376 lldb::SBStringList &matches)
377{
378 const char *cursor = current_line + cursor_pos;
379 const char *last_char = current_line + strlen (current_line);
380 return HandleCompletion (current_line, cursor, last_char, match_start_point, max_return_elements, matches);
381}
382
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000383bool
384SBCommandInterpreter::HasCommands ()
385{
Greg Clayton66111032010-06-23 01:19:29 +0000386 if (m_opaque_ptr)
387 return m_opaque_ptr->HasCommands();
388 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000389}
390
391bool
392SBCommandInterpreter::HasAliases ()
393{
Greg Clayton66111032010-06-23 01:19:29 +0000394 if (m_opaque_ptr)
395 return m_opaque_ptr->HasAliases();
396 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000397}
398
399bool
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000400SBCommandInterpreter::HasAliasOptions ()
401{
Greg Clayton66111032010-06-23 01:19:29 +0000402 if (m_opaque_ptr)
403 return m_opaque_ptr->HasAliasOptions ();
404 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000405}
406
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000407SBProcess
408SBCommandInterpreter::GetProcess ()
409{
Greg Claytonb9556ac2012-01-30 07:41:31 +0000410 SBProcess sb_process;
411 ProcessSP process_sp;
Greg Clayton66111032010-06-23 01:19:29 +0000412 if (m_opaque_ptr)
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000413 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000414 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
415 if (target_sp)
416 {
417 Mutex::Locker api_locker(target_sp->GetAPIMutex());
Greg Claytonb9556ac2012-01-30 07:41:31 +0000418 process_sp = target_sp->GetProcessSP();
419 sb_process.SetSP(process_sp);
Greg Claytonaf67cec2010-12-20 20:49:23 +0000420 }
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000421 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000422 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000423
424 if (log)
425 log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000426 static_cast<void*>(m_opaque_ptr),
427 static_cast<void*>(process_sp.get()));
Greg Clayton48381312010-10-30 04:51:46 +0000428
Greg Claytonb9556ac2012-01-30 07:41:31 +0000429 return sb_process;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000430}
431
Enrico Granata21dfcd92012-09-28 23:57:51 +0000432SBDebugger
433SBCommandInterpreter::GetDebugger ()
434{
435 SBDebugger sb_debugger;
436 if (m_opaque_ptr)
437 sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this());
Greg Clayton5160ce52013-03-27 23:08:40 +0000438 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000439
Enrico Granata21dfcd92012-09-28 23:57:51 +0000440 if (log)
441 log->Printf ("SBCommandInterpreter(%p)::GetDebugger () => SBDebugger(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000442 static_cast<void*>(m_opaque_ptr),
443 static_cast<void*>(sb_debugger.get()));
444
Enrico Granata21dfcd92012-09-28 23:57:51 +0000445 return sb_debugger;
446}
447
Ilia Kacf28be2015-03-23 22:45:13 +0000448bool
449SBCommandInterpreter::GetPromptOnQuit()
450{
451 if (m_opaque_ptr)
452 return m_opaque_ptr->GetPromptOnQuit();
453 return false;
454}
455
456void
457SBCommandInterpreter::SetPromptOnQuit (bool b)
458{
459 if (m_opaque_ptr)
460 m_opaque_ptr->SetPromptOnQuit(b);
461}
462
Adrian McCarthy2304b6f2015-04-23 20:00:25 +0000463void
464SBCommandInterpreter::ResolveCommand(const char *command_line, SBCommandReturnObject &result)
465{
466 result.Clear();
467 if (command_line && m_opaque_ptr)
468 {
469 m_opaque_ptr->ResolveCommand(command_line, result.ref());
470 }
471 else
472 {
473 result->AppendError("SBCommandInterpreter or the command line is not valid");
474 result->SetStatus(eReturnStatusFailed);
475 }
476}
477
478
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000479CommandInterpreter *
Greg Clayton66111032010-06-23 01:19:29 +0000480SBCommandInterpreter::get ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000481{
Greg Clayton66111032010-06-23 01:19:29 +0000482 return m_opaque_ptr;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000483}
484
485CommandInterpreter &
Greg Clayton66111032010-06-23 01:19:29 +0000486SBCommandInterpreter::ref ()
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000487{
Greg Clayton66111032010-06-23 01:19:29 +0000488 assert (m_opaque_ptr);
489 return *m_opaque_ptr;
490}
491
492void
493SBCommandInterpreter::reset (lldb_private::CommandInterpreter *interpreter)
494{
495 m_opaque_ptr = interpreter;
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000496}
497
498void
499SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &result)
500{
501 result.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000502 if (m_opaque_ptr)
503 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000504 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
505 Mutex::Locker api_locker;
506 if (target_sp)
Jim Ingham10ebffa2012-05-04 23:02:50 +0000507 api_locker.Lock(target_sp->GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000508 m_opaque_ptr->SourceInitFile (false, result.ref());
509 }
510 else
511 {
512 result->AppendError ("SBCommandInterpreter is not valid");
513 result->SetStatus (eReturnStatusFailed);
514 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000515 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000516
517 if (log)
518 log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInHomeDirectory (&SBCommandReturnObject(%p))",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000519 static_cast<void*>(m_opaque_ptr),
520 static_cast<void*>(result.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000521}
522
523void
524SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnObject &result)
525{
526 result.Clear();
Greg Clayton66111032010-06-23 01:19:29 +0000527 if (m_opaque_ptr)
528 {
Greg Claytonaf67cec2010-12-20 20:49:23 +0000529 TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget());
530 Mutex::Locker api_locker;
531 if (target_sp)
Jim Ingham10ebffa2012-05-04 23:02:50 +0000532 api_locker.Lock(target_sp->GetAPIMutex());
Greg Clayton66111032010-06-23 01:19:29 +0000533 m_opaque_ptr->SourceInitFile (true, result.ref());
534 }
535 else
536 {
537 result->AppendError ("SBCommandInterpreter is not valid");
538 result->SetStatus (eReturnStatusFailed);
539 }
Greg Clayton5160ce52013-03-27 23:08:40 +0000540 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Greg Clayton48381312010-10-30 04:51:46 +0000541
542 if (log)
543 log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInCurrentWorkingDirectory (&SBCommandReturnObject(%p))",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000544 static_cast<void*>(m_opaque_ptr),
545 static_cast<void*>(result.get()));
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000546}
547
548SBBroadcaster
549SBCommandInterpreter::GetBroadcaster ()
550{
Greg Clayton5160ce52013-03-27 23:08:40 +0000551 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000552
Greg Clayton66111032010-06-23 01:19:29 +0000553 SBBroadcaster broadcaster (m_opaque_ptr, false);
Caroline Ticeceb6b132010-10-26 03:11:13 +0000554
555 if (log)
Greg Clayton48381312010-10-30 04:51:46 +0000556 log->Printf ("SBCommandInterpreter(%p)::GetBroadcaster() => SBBroadcaster(%p)",
Saleem Abdulrasool324a1032014-04-04 04:06:10 +0000557 static_cast<void*>(m_opaque_ptr), static_cast<void*>(broadcaster.get()));
Caroline Ticeceb6b132010-10-26 03:11:13 +0000558
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000559 return broadcaster;
560}
561
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000562const char *
563SBCommandInterpreter::GetBroadcasterClass ()
564{
Ilia K8a00a562015-03-17 16:54:52 +0000565 return CommandInterpreter::GetStaticBroadcasterClass().AsCString();
Jim Ingham4bddaeb2012-02-16 06:50:00 +0000566}
567
Greg Clayton9d0402b2011-02-20 02:15:07 +0000568const char *
569SBCommandInterpreter::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type)
570{
571 return CommandObject::GetArgumentTypeAsCString (arg_type);
572}
573
574const char *
575SBCommandInterpreter::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type)
576{
577 return CommandObject::GetArgumentDescriptionAsCString (arg_type);
578}
579
Greg Claytona9f7b792012-02-29 04:21:24 +0000580bool
Ilia Kaf10e1c2015-03-21 10:53:37 +0000581SBCommandInterpreter::EventIsCommandInterpreterEvent (const lldb::SBEvent &event)
582{
Ilia Kf9e5dc12015-03-21 11:11:07 +0000583 return event.GetBroadcasterClass() == SBCommandInterpreter::GetBroadcasterClass();
Ilia Kaf10e1c2015-03-21 10:53:37 +0000584}
585
586bool
Greg Claytona9f7b792012-02-29 04:21:24 +0000587SBCommandInterpreter::SetCommandOverrideCallback (const char *command_name,
588 lldb::CommandOverrideCallback callback,
589 void *baton)
590{
591 if (command_name && command_name[0] && m_opaque_ptr)
592 {
Greg Claytonaf6f2752012-05-08 04:29:20 +0000593 std::string command_name_str (command_name);
594 CommandObject *cmd_obj = m_opaque_ptr->GetCommandObjectForCommand(command_name_str);
Greg Claytona9f7b792012-02-29 04:21:24 +0000595 if (cmd_obj)
596 {
Greg Claytonaf6f2752012-05-08 04:29:20 +0000597 assert(command_name_str.empty());
Greg Claytona9f7b792012-02-29 04:21:24 +0000598 cmd_obj->SetOverrideCallback (callback, baton);
599 return true;
600 }
601 }
602 return false;
603}
Greg Clayton9d0402b2011-02-20 02:15:07 +0000604
Enrico Granata21dfcd92012-09-28 23:57:51 +0000605lldb::SBCommand
606SBCommandInterpreter::AddMultiwordCommand (const char* name, const char* help)
607{
608 CommandObjectMultiword *new_command = new CommandObjectMultiword(*m_opaque_ptr,name,help);
609 new_command->SetRemovable (true);
610 lldb::CommandObjectSP new_command_sp(new_command);
611 if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
612 return lldb::SBCommand(new_command_sp);
613 return lldb::SBCommand();
614}
615
616lldb::SBCommand
617SBCommandInterpreter::AddCommand (const char* name, lldb::SBCommandPluginInterface* impl, const char* help)
618{
619 lldb::CommandObjectSP new_command_sp;
620 new_command_sp.reset(new CommandPluginInterfaceImplementation(*m_opaque_ptr,name,impl,help));
621
622 if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true))
623 return lldb::SBCommand(new_command_sp);
624 return lldb::SBCommand();
625}
626
627SBCommand::SBCommand ()
628{}
629
630SBCommand::SBCommand (lldb::CommandObjectSP cmd_sp) : m_opaque_sp (cmd_sp)
631{}
632
633bool
634SBCommand::IsValid ()
635{
636 return (bool)m_opaque_sp;
637}
638
639const char*
640SBCommand::GetName ()
641{
642 if (IsValid ())
643 return m_opaque_sp->GetCommandName ();
644 return NULL;
645}
646
647const char*
648SBCommand::GetHelp ()
649{
650 if (IsValid ())
651 return m_opaque_sp->GetHelp ();
652 return NULL;
653}
654
Enrico Granatacc342da2015-03-13 22:32:11 +0000655const char*
656SBCommand::GetHelpLong ()
657{
658 if (IsValid ())
659 return m_opaque_sp->GetHelpLong ();
660 return NULL;
661}
662
663void
664SBCommand::SetHelp (const char* help)
665{
666 if (IsValid())
667 m_opaque_sp->SetHelp(help);
668}
669
670void
671SBCommand::SetHelpLong (const char* help)
672{
673 if (IsValid())
674 m_opaque_sp->SetHelpLong(help);
675}
676
Enrico Granata21dfcd92012-09-28 23:57:51 +0000677lldb::SBCommand
678SBCommand::AddMultiwordCommand (const char* name, const char* help)
679{
680 if (!IsValid ())
681 return lldb::SBCommand();
682 if (m_opaque_sp->IsMultiwordObject() == false)
683 return lldb::SBCommand();
684 CommandObjectMultiword *new_command = new CommandObjectMultiword(m_opaque_sp->GetCommandInterpreter(),name,help);
685 new_command->SetRemovable (true);
686 lldb::CommandObjectSP new_command_sp(new_command);
687 if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp))
688 return lldb::SBCommand(new_command_sp);
689 return lldb::SBCommand();
690}
691
692lldb::SBCommand
693SBCommand::AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help)
694{
695 if (!IsValid ())
696 return lldb::SBCommand();
697 if (m_opaque_sp->IsMultiwordObject() == false)
698 return lldb::SBCommand();
699 lldb::CommandObjectSP new_command_sp;
700 new_command_sp.reset(new CommandPluginInterfaceImplementation(m_opaque_sp->GetCommandInterpreter(),name,impl,help));
701 if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp))
702 return lldb::SBCommand(new_command_sp);
703 return lldb::SBCommand();
704}
Enrico Granatae87764f2015-05-27 05:04:35 +0000705
706uint32_t
707SBCommand::GetFlags ()
708{
709 if (!IsValid())
710 return 0;
711 return m_opaque_sp->GetFlags().Get();
712}
713
714void
715SBCommand::SetFlags (uint32_t flags)
716{
717 if (IsValid())
718 m_opaque_sp->GetFlags().Set(flags);
719}