blob: db4f74ea70123fc485b3ad10f8b98219726d43df [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
Daniel Malead891f9b2012-12-05 00:20:57 +000010#include "lldb/lldb-python.h"
11
Chris Lattner24943d22010-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 Granata9ae7cef2011-07-24 00:14:56 +000018
Enrico Granata0be2e9b2011-08-22 22:03:47 +000019#include "lldb/Core/DataVisualization.h"
Enrico Granata9ae7cef2011-07-24 00:14:56 +000020#include "lldb/Core/Debugger.h"
Jim Ingham84cdc152010-06-15 19:49:27 +000021#include "lldb/Interpreter/Args.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022
23#include "lldb/Interpreter/CommandReturnObject.h"
24#include "lldb/Interpreter/ScriptInterpreter.h"
Caroline Tice0aa2e552011-01-14 00:29:16 +000025#include "lldb/Interpreter/CommandInterpreter.h"
Chris Lattner24943d22010-06-08 16:52:24 +000026
27using namespace lldb;
28using namespace lldb_private;
29
30//-------------------------------------------------------------------------
31// CommandObjectScript
32//-------------------------------------------------------------------------
33
Greg Clayton238c0a12010-09-18 01:14:36 +000034CommandObjectScript::CommandObjectScript (CommandInterpreter &interpreter, ScriptLanguage script_lang) :
Jim Inghamda26bd22012-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.",
38 "script [<script-expression-for-evaluation>]"),
Caroline Tice0aa2e552011-01-14 00:29:16 +000039 m_script_lang (script_lang)
Chris Lattner24943d22010-06-08 16:52:24 +000040{
41}
42
43CommandObjectScript::~CommandObjectScript ()
44{
45}
46
47bool
Jim Inghamda26bd22012-06-08 21:56:10 +000048CommandObjectScript::DoExecute
Chris Lattner24943d22010-06-08 16:52:24 +000049(
50 const char *command,
Chris Lattner24943d22010-06-08 16:52:24 +000051 CommandReturnObject &result
52)
53{
Caroline Tice0aa2e552011-01-14 00:29:16 +000054 ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter ();
Chris Lattner24943d22010-06-08 16:52:24 +000055
56 if (script_interpreter == NULL)
57 {
Greg Clayton5d187e52011-01-08 20:28:42 +000058 result.AppendError("no script interpreter");
Chris Lattner24943d22010-06-08 16:52:24 +000059 result.SetStatus (eReturnStatusFailed);
Jim Ingham6f01c932012-10-12 17:34:26 +000060 return false;
Chris Lattner24943d22010-06-08 16:52:24 +000061 }
62
Enrico Granataf501c592011-08-17 22:13:59 +000063 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 +000064
Enrico Granata1c617432011-08-18 16:38:26 +000065 if (command == NULL || command[0] == '\0')
66 {
Greg Clayton238c0a12010-09-18 01:14:36 +000067 script_interpreter->ExecuteInterpreterLoop ();
Johnny Chen60dde642010-07-30 22:33:14 +000068 result.SetStatus (eReturnStatusSuccessFinishNoResult);
69 return result.Succeeded();
70 }
71
72 // We can do better when reporting the status of one-liner script execution.
Enrico Granatafd670c22012-10-31 00:01:26 +000073 if (script_interpreter->ExecuteOneLine (command, &result))
Johnny Chen60dde642010-07-30 22:33:14 +000074 result.SetStatus(eReturnStatusSuccessFinishNoResult);
Chris Lattner24943d22010-06-08 16:52:24 +000075 else
Johnny Chen60dde642010-07-30 22:33:14 +000076 result.SetStatus(eReturnStatusFailed);
77
Chris Lattner24943d22010-06-08 16:52:24 +000078 return result.Succeeded();
79}