blob: d2e64fc988e6a1841aedfee797284f21c3e67d1c [file] [log] [blame]
Chris Lattner24943d22010-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 Granata9ae7cef2011-07-24 00:14:56 +000016
17#include "lldb/Core/Debugger.h"
Enrico Granataf501c592011-08-17 22:13:59 +000018#include "lldb/Core/FormatManager.h"
Jim Ingham84cdc152010-06-15 19:49:27 +000019#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000020
21#include "lldb/Interpreter/CommandReturnObject.h"
22#include "lldb/Interpreter/ScriptInterpreter.h"
Caroline Tice0aa2e552011-01-14 00:29:16 +000023#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner24943d22010-06-08 16:52:24 +000024
25using namespace lldb;
26using namespace lldb_private;
27
28//-------------------------------------------------------------------------
29// CommandObjectScript
30//-------------------------------------------------------------------------
31
Greg Clayton238c0a12010-09-18 01:14:36 +000032CommandObjectScript::CommandObjectScript (CommandInterpreter &interpreter, ScriptLanguage script_lang) :
33 CommandObject (interpreter,
34 "script",
Caroline Ticec1ad82e2010-09-07 22:38:08 +000035 "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 Tice0aa2e552011-01-14 00:29:16 +000037 m_script_lang (script_lang)
Chris Lattner24943d22010-06-08 16:52:24 +000038{
39}
40
41CommandObjectScript::~CommandObjectScript ()
42{
43}
44
45bool
46CommandObjectScript::ExecuteRawCommandString
47(
48 const char *command,
Chris Lattner24943d22010-06-08 16:52:24 +000049 CommandReturnObject &result
50)
51{
Caroline Tice0aa2e552011-01-14 00:29:16 +000052 ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter ();
Chris Lattner24943d22010-06-08 16:52:24 +000053
54 if (script_interpreter == NULL)
55 {
Greg Clayton5d187e52011-01-08 20:28:42 +000056 result.AppendError("no script interpreter");
Chris Lattner24943d22010-06-08 16:52:24 +000057 result.SetStatus (eReturnStatusFailed);
58 }
59
Enrico Granataf501c592011-08-17 22:13:59 +000060 DataVisualization::ForceUpdate(); // script might change Python code we use for formatting.. make sure we keep up to date with it
Enrico Granata9ae7cef2011-07-24 00:14:56 +000061
Johnny Chen60dde642010-07-30 22:33:14 +000062 if (command == NULL || command[0] == '\0') {
Greg Clayton238c0a12010-09-18 01:14:36 +000063 script_interpreter->ExecuteInterpreterLoop ();
Johnny Chen60dde642010-07-30 22:33:14 +000064 result.SetStatus (eReturnStatusSuccessFinishNoResult);
65 return result.Succeeded();
66 }
67
68 // We can do better when reporting the status of one-liner script execution.
Greg Clayton238c0a12010-09-18 01:14:36 +000069 if (script_interpreter->ExecuteOneLine (command, &result))
Johnny Chen60dde642010-07-30 22:33:14 +000070 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +000071 else
Johnny Chen60dde642010-07-30 22:33:14 +000072 result.SetStatus(eReturnStatusFailed);
73
Chris Lattner24943d22010-06-08 16:52:24 +000074 return result.Succeeded();
75}
76
77bool
78CommandObjectScript::WantsRawCommandString()
79{
80 return true;
81}
82
83bool
84CommandObjectScript::Execute
85(
86 Args& command,
Chris Lattner24943d22010-06-08 16:52:24 +000087 CommandReturnObject &result
88)
89{
Greg Clayton63094e02010-06-23 01:19:29 +000090 // everything should be handled in ExecuteRawCommandString
91 return false;
Chris Lattner24943d22010-06-08 16:52:24 +000092}
93