SBCommandInterpreter.cpp revision d6ec8aaa74c926cab7147259cdf772b1338d0336
1//===-- SBCommandInterpreter.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/lldb-types.h"
11#include "lldb/Core/Args.h"
12#include "lldb/Core/SourceManager.h"
13#include "lldb/Core/Listener.h"
14#include "lldb/Interpreter/CommandInterpreter.h"
15#include "lldb/Interpreter/CommandReturnObject.h"
16#include "lldb/Target/Target.h"
17
18#include "lldb/API/SBBroadcaster.h"
19#include "lldb/API/SBDebugger.h"
20#include "lldb/API/SBCommandReturnObject.h"
21#include "lldb/API/SBCommandContext.h"
22#include "lldb/API/SBSourceManager.h"
23#include "lldb/API/SBCommandInterpreter.h"
24#include "lldb/API/SBProcess.h"
25#include "lldb/API/SBTarget.h"
26#include "lldb/API/SBListener.h"
27#include "lldb/API/SBStringList.h"
28
29using namespace lldb;
30using namespace lldb_private;
31
32
33SBCommandInterpreter::SBCommandInterpreter (CommandInterpreter &interpreter) :
34    m_interpreter (interpreter)
35{
36}
37
38SBCommandInterpreter::~SBCommandInterpreter ()
39{
40}
41
42bool
43SBCommandInterpreter::CommandExists (const char *cmd)
44{
45    return m_interpreter.CommandExists (cmd);
46}
47
48bool
49SBCommandInterpreter::AliasExists (const char *cmd)
50{
51    return m_interpreter.AliasExists (cmd);
52}
53
54bool
55SBCommandInterpreter::UserCommandExists (const char *cmd)
56{
57    return m_interpreter.UserCommandExists (cmd);
58}
59
60lldb::ReturnStatus
61SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history)
62{
63    result.Clear();
64    m_interpreter.HandleCommand (command_line, add_to_history, result.GetLLDBObjectRef());
65    return result.GetStatus();
66}
67
68int
69SBCommandInterpreter::HandleCompletion (const char *current_line,
70                                        const char *cursor,
71                                        const char *last_char,
72                                        int match_start_point,
73                                        int max_return_elements,
74                                        SBStringList &matches)
75{
76    int num_completions;
77    lldb_private::StringList lldb_matches;
78    num_completions =  m_interpreter.HandleCompletion (current_line, cursor, last_char, match_start_point,
79                                                       max_return_elements, lldb_matches);
80
81    SBStringList temp_list (&lldb_matches);
82    matches.AppendList (temp_list);
83
84    return num_completions;
85}
86
87const char **
88SBCommandInterpreter::GetEnvironmentVariables ()
89{
90    const Args *env_vars =  m_interpreter.GetEnvironmentVariables();
91    if (env_vars)
92        return env_vars->GetConstArgumentVector ();
93    return NULL;
94}
95
96bool
97SBCommandInterpreter::HasCommands ()
98{
99    return m_interpreter.HasCommands();
100}
101
102bool
103SBCommandInterpreter::HasAliases ()
104{
105    return m_interpreter.HasAliases();
106}
107
108bool
109SBCommandInterpreter::HasUserCommands ()
110{
111    return m_interpreter.HasUserCommands ();
112}
113
114bool
115SBCommandInterpreter::HasAliasOptions ()
116{
117    return m_interpreter.HasAliasOptions ();
118}
119
120bool
121SBCommandInterpreter::HasInterpreterVariables ()
122{
123    return m_interpreter.HasInterpreterVariables ();
124}
125
126SBProcess
127SBCommandInterpreter::GetProcess ()
128{
129    SBProcess process;
130    CommandContext *context = m_interpreter.Context();
131    if (context)
132    {
133        Target *target = context->GetTarget();
134        if (target)
135            process.SetProcess(target->GetProcessSP());
136    }
137    return process;
138}
139
140ssize_t
141SBCommandInterpreter::WriteToScriptInterpreter (const char *src)
142{
143    if (src)
144        return WriteToScriptInterpreter (src, strlen(src));
145    return 0;
146}
147
148ssize_t
149SBCommandInterpreter::WriteToScriptInterpreter (const char *src, size_t src_len)
150{
151    if (src && src[0])
152    {
153        ScriptInterpreter *script_interpreter = m_interpreter.GetScriptInterpreter();
154        if (script_interpreter)
155            return ::write (script_interpreter->GetMasterFileDescriptor(), src, src_len);
156    }
157    return 0;
158}
159
160
161CommandInterpreter *
162SBCommandInterpreter::GetLLDBObjectPtr ()
163{
164    return &m_interpreter;
165}
166
167CommandInterpreter &
168SBCommandInterpreter::GetLLDBObjectRef ()
169{
170    return m_interpreter;
171}
172
173void
174SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &result)
175{
176    result.Clear();
177    m_interpreter.SourceInitFile (false, result.GetLLDBObjectRef());
178}
179
180void
181SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnObject &result)
182{
183    result.Clear();
184    m_interpreter.SourceInitFile (true, result.GetLLDBObjectRef());
185}
186
187SBBroadcaster
188SBCommandInterpreter::GetBroadcaster ()
189{
190    SBBroadcaster broadcaster (&m_interpreter, false);
191    return broadcaster;
192}
193
194