blob: 7011c2e7f2b00d1cd267582680f137c1c36832f1 [file] [log] [blame]
Chris Lattner24943d22010-06-08 16:52:24 +00001//===-- ScriptInterpreter.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/Interpreter/ScriptInterpreter.h"
11
12#include <string>
13#include <stdlib.h>
14#include <stdio.h>
15
16#include "lldb/Core/Error.h"
17#include "lldb/Core/Stream.h"
18#include "lldb/Core/StringList.h"
19#include "lldb/Interpreter/CommandReturnObject.h"
Caroline Tice0aa2e552011-01-14 00:29:16 +000020#include "lldb/Interpreter/ScriptInterpreterPython.h"
Jason Molendadea5ea72010-06-09 21:28:42 +000021#include "lldb/Utility/PseudoTerminal.h"
Chris Lattner24943d22010-06-08 16:52:24 +000022
23using namespace lldb;
24using namespace lldb_private;
25
Caroline Tice0aa2e552011-01-14 00:29:16 +000026ScriptInterpreter::ScriptInterpreter (CommandInterpreter &interpreter, lldb::ScriptLanguage script_lang) :
Greg Clayton238c0a12010-09-18 01:14:36 +000027 m_interpreter (interpreter),
Chris Lattner24943d22010-06-08 16:52:24 +000028 m_script_lang (script_lang),
Caroline Tice0aa2e552011-01-14 00:29:16 +000029 m_interpreter_pty (),
30 m_pty_slave_name ()
Chris Lattner24943d22010-06-08 16:52:24 +000031{
32 if (m_interpreter_pty.OpenFirstAvailableMaster (O_RDWR|O_NOCTTY, NULL, 0))
33 {
34 const char *slave_name = m_interpreter_pty.GetSlaveName(NULL, 0);
35 if (slave_name)
36 m_pty_slave_name.assign(slave_name);
37 }
38}
39
40ScriptInterpreter::~ScriptInterpreter ()
41{
42 m_interpreter_pty.CloseMasterFileDescriptor();
43}
44
Caroline Tice0aa2e552011-01-14 00:29:16 +000045CommandInterpreter &
46ScriptInterpreter::GetCommandInterpreter ()
47{
48 return m_interpreter;
49}
50
Chris Lattner24943d22010-06-08 16:52:24 +000051const char *
52ScriptInterpreter::GetScriptInterpreterPtyName ()
53{
54 return m_pty_slave_name.c_str();
55}
56
57int
58ScriptInterpreter::GetMasterFileDescriptor ()
59{
60 return m_interpreter_pty.GetMasterFileDescriptor();
61}
62
63void
64ScriptInterpreter::CollectDataForBreakpointCommandCallback
65(
Chris Lattner24943d22010-06-08 16:52:24 +000066 BreakpointOptions *bp_options,
67 CommandReturnObject &result
68)
69{
70 result.SetStatus (eReturnStatusFailed);
71 result.AppendError ("ScriptInterpreter::GetScriptCommands(StringList &) is not implemented.");
72}
73
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000074std::string
75ScriptInterpreter::LanguageToString (lldb::ScriptLanguage language)
76{
77 std::string return_value;
Chris Lattner24943d22010-06-08 16:52:24 +000078
Caroline Tice6e4c5ce2010-09-04 00:03:46 +000079 switch (language)
80 {
81 case eScriptLanguageNone:
82 return_value = "None";
83 break;
84 case eScriptLanguagePython:
85 return_value = "Python";
86 break;
87
88 }
89
90 return return_value;
91}
Caroline Tice0aa2e552011-01-14 00:29:16 +000092
93void
Greg Claytone86cbb92011-03-22 01:14:58 +000094ScriptInterpreter::InitializeInterpreter (SWIGInitCallback python_swig_init_callback,
95 SWIGBreakpointCallbackFunction python_swig_breakpoint_callback)
Caroline Tice0aa2e552011-01-14 00:29:16 +000096{
Greg Claytone86cbb92011-03-22 01:14:58 +000097 ScriptInterpreterPython::InitializeInterpreter (python_swig_init_callback,
98 python_swig_breakpoint_callback);
Caroline Tice0aa2e552011-01-14 00:29:16 +000099}
100
101void
Greg Claytone86cbb92011-03-22 01:14:58 +0000102ScriptInterpreter::TerminateInterpreter ()
Caroline Tice0aa2e552011-01-14 00:29:16 +0000103{
Greg Claytone86cbb92011-03-22 01:14:58 +0000104 ScriptInterpreterPython::TerminateInterpreter ();
Caroline Tice0aa2e552011-01-14 00:29:16 +0000105}
106