blob: 204270fa5845b44104a4f121e97f37bb471e878b [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001//===-- CommandObjectScript.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
Chris Lattner30fdc8d2010-06-08 16:52:24 +000012#include "CommandObjectScript.h"
13
14// C Includes
15// C++ Includes
16// Other libraries and framework includes
17// Project includes
Enrico Granataa37a0652011-07-24 00:14:56 +000018
Enrico Granata0a976142011-08-22 22:03:47 +000019#include "lldb/Core/DataVisualization.h"
Enrico Granataa37a0652011-07-24 00:14:56 +000020#include "lldb/Core/Debugger.h"
Jim Ingham40af72e2010-06-15 19:49:27 +000021#include "lldb/Interpreter/Args.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000022
23#include "lldb/Interpreter/CommandReturnObject.h"
24#include "lldb/Interpreter/ScriptInterpreter.h"
Caroline Tice2f88aad2011-01-14 00:29:16 +000025#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000026
27using namespace lldb;
28using namespace lldb_private;
29
30//-------------------------------------------------------------------------
31// CommandObjectScript
32//-------------------------------------------------------------------------
33
Greg Claytona7015092010-09-18 01:14:36 +000034CommandObjectScript::CommandObjectScript (CommandInterpreter &interpreter, ScriptLanguage script_lang) :
Jim Ingham5a988412012-06-08 21:56:10 +000035 CommandObjectRaw (interpreter,
36 "script",
37 "Pass an expression to the script interpreter for evaluation and return the results. Drop into the interactive interpreter if no expression is given.",
Daniel Maleaa85e6b62012-12-07 22:21:08 +000038 "script [<script-expression-for-evaluation>]")
Chris Lattner30fdc8d2010-06-08 16:52:24 +000039{
40}
41
42CommandObjectScript::~CommandObjectScript ()
43{
44}
45
46bool
Jim Ingham5a988412012-06-08 21:56:10 +000047CommandObjectScript::DoExecute
Chris Lattner30fdc8d2010-06-08 16:52:24 +000048(
49 const char *command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000050 CommandReturnObject &result
51)
52{
Caroline Tice2f88aad2011-01-14 00:29:16 +000053 ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000054
55 if (script_interpreter == NULL)
56 {
Greg Clayton710dd5a2011-01-08 20:28:42 +000057 result.AppendError("no script interpreter");
Chris Lattner30fdc8d2010-06-08 16:52:24 +000058 result.SetStatus (eReturnStatusFailed);
Jim Ingham28eb5712012-10-12 17:34:26 +000059 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000060 }
61
Enrico Granatac482a192011-08-17 22:13:59 +000062 DataVisualization::ForceUpdate(); // script might change Python code we use for formatting.. make sure we keep up to date with it
Enrico Granataa37a0652011-07-24 00:14:56 +000063
Enrico Granata85933ed2011-08-18 16:38:26 +000064 if (command == NULL || command[0] == '\0')
65 {
Greg Claytona7015092010-09-18 01:14:36 +000066 script_interpreter->ExecuteInterpreterLoop ();
Johnny Chen7dc2e472010-07-30 22:33:14 +000067 result.SetStatus (eReturnStatusSuccessFinishNoResult);
68 return result.Succeeded();
69 }
70
71 // We can do better when reporting the status of one-liner script execution.
Enrico Granata085577f2012-10-31 00:01:26 +000072 if (script_interpreter->ExecuteOneLine (command, &result))
Johnny Chen7dc2e472010-07-30 22:33:14 +000073 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000074 else
Johnny Chen7dc2e472010-07-30 22:33:14 +000075 result.SetStatus(eReturnStatusFailed);
76
Chris Lattner30fdc8d2010-06-08 16:52:24 +000077 return result.Succeeded();
78}