blob: 6dd2f7aba7692fd4a33c5bd7af182ec8d4ed2531 [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
10#include "CommandObjectScript.h"
11
12// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Enrico Granataa37a0652011-07-24 00:14:56 +000016
Enrico Granata0a976142011-08-22 22:03:47 +000017#include "lldb/Core/DataVisualization.h"
Enrico Granataa37a0652011-07-24 00:14:56 +000018#include "lldb/Core/Debugger.h"
Jim Ingham40af72e2010-06-15 19:49:27 +000019#include "lldb/Interpreter/Args.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000020
21#include "lldb/Interpreter/CommandReturnObject.h"
22#include "lldb/Interpreter/ScriptInterpreter.h"
Caroline Tice2f88aad2011-01-14 00:29:16 +000023#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner30fdc8d2010-06-08 16:52:24 +000024
25using namespace lldb;
26using namespace lldb_private;
27
28//-------------------------------------------------------------------------
29// CommandObjectScript
30//-------------------------------------------------------------------------
31
Greg Claytona7015092010-09-18 01:14:36 +000032CommandObjectScript::CommandObjectScript (CommandInterpreter &interpreter, ScriptLanguage script_lang) :
Jim Ingham5a988412012-06-08 21:56:10 +000033 CommandObjectRaw (interpreter,
34 "script",
35 "Pass an expression to the script interpreter for evaluation and return the results. Drop into the interactive interpreter if no expression is given.",
36 "script [<script-expression-for-evaluation>]"),
Caroline Tice2f88aad2011-01-14 00:29:16 +000037 m_script_lang (script_lang)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000038{
39}
40
41CommandObjectScript::~CommandObjectScript ()
42{
43}
44
45bool
Jim Ingham5a988412012-06-08 21:56:10 +000046CommandObjectScript::DoExecute
Chris Lattner30fdc8d2010-06-08 16:52:24 +000047(
48 const char *command,
Chris Lattner30fdc8d2010-06-08 16:52:24 +000049 CommandReturnObject &result
50)
51{
Caroline Tice2f88aad2011-01-14 00:29:16 +000052 ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter ();
Chris Lattner30fdc8d2010-06-08 16:52:24 +000053
54 if (script_interpreter == NULL)
55 {
Greg Clayton710dd5a2011-01-08 20:28:42 +000056 result.AppendError("no script interpreter");
Chris Lattner30fdc8d2010-06-08 16:52:24 +000057 result.SetStatus (eReturnStatusFailed);
Jim Ingham28eb5712012-10-12 17:34:26 +000058 return false;
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059 }
60
Enrico Granatac482a192011-08-17 22:13:59 +000061 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 +000062
Enrico Granata85933ed2011-08-18 16:38:26 +000063 if (command == NULL || command[0] == '\0')
64 {
Greg Claytona7015092010-09-18 01:14:36 +000065 script_interpreter->ExecuteInterpreterLoop ();
Johnny Chen7dc2e472010-07-30 22:33:14 +000066 result.SetStatus (eReturnStatusSuccessFinishNoResult);
67 return result.Succeeded();
68 }
69
70 // We can do better when reporting the status of one-liner script execution.
Enrico Granata085577f2012-10-31 00:01:26 +000071 if (script_interpreter->ExecuteOneLine (command, &result))
Johnny Chen7dc2e472010-07-30 22:33:14 +000072 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Chris Lattner30fdc8d2010-06-08 16:52:24 +000073 else
Johnny Chen7dc2e472010-07-30 22:33:14 +000074 result.SetStatus(eReturnStatusFailed);
75
Chris Lattner30fdc8d2010-06-08 16:52:24 +000076 return result.Succeeded();
77}