2010-06-09 00:52:24 +08:00
|
|
|
//===-- SBCommandInterpreter.cpp --------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/lldb-types.h"
|
2010-06-16 03:49:27 +08:00
|
|
|
#include "lldb/Interpreter/Args.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
#include "lldb/Core/SourceManager.h"
|
|
|
|
#include "lldb/Core/Listener.h"
|
|
|
|
#include "lldb/Interpreter/CommandInterpreter.h"
|
|
|
|
#include "lldb/Interpreter/CommandReturnObject.h"
|
|
|
|
#include "lldb/Target/Target.h"
|
|
|
|
|
2010-06-09 15:37:52 +08:00
|
|
|
#include "lldb/API/SBBroadcaster.h"
|
|
|
|
#include "lldb/API/SBDebugger.h"
|
|
|
|
#include "lldb/API/SBCommandReturnObject.h"
|
|
|
|
#include "lldb/API/SBCommandContext.h"
|
|
|
|
#include "lldb/API/SBSourceManager.h"
|
|
|
|
#include "lldb/API/SBCommandInterpreter.h"
|
|
|
|
#include "lldb/API/SBProcess.h"
|
|
|
|
#include "lldb/API/SBTarget.h"
|
|
|
|
#include "lldb/API/SBListener.h"
|
|
|
|
#include "lldb/API/SBStringList.h"
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
SBCommandInterpreter::SBCommandInterpreter (CommandInterpreter *interpreter) :
|
|
|
|
m_opaque_ptr (interpreter)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SBCommandInterpreter::~SBCommandInterpreter ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
bool
|
|
|
|
SBCommandInterpreter::IsValid() const
|
|
|
|
{
|
|
|
|
return m_opaque_ptr != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
bool
|
|
|
|
SBCommandInterpreter::CommandExists (const char *cmd)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->CommandExists (cmd);
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBCommandInterpreter::AliasExists (const char *cmd)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->AliasExists (cmd);
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBCommandInterpreter::UserCommandExists (const char *cmd)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->UserCommandExists (cmd);
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lldb::ReturnStatus
|
|
|
|
SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history)
|
|
|
|
{
|
|
|
|
result.Clear();
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
|
|
|
m_opaque_ptr->HandleCommand (command_line, add_to_history, result.ref());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->AppendError ("SBCommandInterpreter is not valid");
|
|
|
|
result->SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return result.GetStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SBCommandInterpreter::HandleCompletion (const char *current_line,
|
|
|
|
const char *cursor,
|
|
|
|
const char *last_char,
|
|
|
|
int match_start_point,
|
|
|
|
int max_return_elements,
|
|
|
|
SBStringList &matches)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
int num_completions = 0;
|
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
|
|
|
lldb_private::StringList lldb_matches;
|
|
|
|
num_completions = m_opaque_ptr->HandleCompletion (current_line, cursor, last_char, match_start_point,
|
|
|
|
max_return_elements, lldb_matches);
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
SBStringList temp_list (&lldb_matches);
|
|
|
|
matches.AppendList (temp_list);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return num_completions;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char **
|
|
|
|
SBCommandInterpreter::GetEnvironmentVariables ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
|
|
|
const Args *env_vars = m_opaque_ptr->GetEnvironmentVariables();
|
|
|
|
if (env_vars)
|
|
|
|
return env_vars->GetConstArgumentVector ();
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBCommandInterpreter::HasCommands ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->HasCommands();
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBCommandInterpreter::HasAliases ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->HasAliases();
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBCommandInterpreter::HasUserCommands ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->HasUserCommands ();
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBCommandInterpreter::HasAliasOptions ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->HasAliasOptions ();
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SBCommandInterpreter::HasInterpreterVariables ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
return m_opaque_ptr->HasInterpreterVariables ();
|
|
|
|
return false;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBProcess
|
|
|
|
SBCommandInterpreter::GetProcess ()
|
|
|
|
{
|
|
|
|
SBProcess process;
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
Debugger &debugger = m_opaque_ptr->GetDebugger();
|
2010-08-27 05:32:51 +08:00
|
|
|
Target *target = debugger.GetSelectedTarget().get();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (target)
|
|
|
|
process.SetProcess(target->GetProcessSP());
|
|
|
|
}
|
|
|
|
return process;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
SBCommandInterpreter::WriteToScriptInterpreter (const char *src)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr && src && src[0])
|
2010-06-09 00:52:24 +08:00
|
|
|
return WriteToScriptInterpreter (src, strlen(src));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t
|
|
|
|
SBCommandInterpreter::WriteToScriptInterpreter (const char *src, size_t src_len)
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr && src && src[0])
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
ScriptInterpreter *script_interpreter = m_opaque_ptr->GetScriptInterpreter();
|
2010-06-09 00:52:24 +08:00
|
|
|
if (script_interpreter)
|
|
|
|
return ::write (script_interpreter->GetMasterFileDescriptor(), src, src_len);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CommandInterpreter *
|
2010-06-23 09:19:29 +08:00
|
|
|
SBCommandInterpreter::get ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
return m_opaque_ptr;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CommandInterpreter &
|
2010-06-23 09:19:29 +08:00
|
|
|
SBCommandInterpreter::ref ()
|
2010-06-09 00:52:24 +08:00
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
assert (m_opaque_ptr);
|
|
|
|
return *m_opaque_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBCommandInterpreter::reset (lldb_private::CommandInterpreter *interpreter)
|
|
|
|
{
|
|
|
|
m_opaque_ptr = interpreter;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &result)
|
|
|
|
{
|
|
|
|
result.Clear();
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
|
|
|
m_opaque_ptr->SourceInitFile (false, result.ref());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->AppendError ("SBCommandInterpreter is not valid");
|
|
|
|
result->SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnObject &result)
|
|
|
|
{
|
|
|
|
result.Clear();
|
2010-06-23 09:19:29 +08:00
|
|
|
if (m_opaque_ptr)
|
|
|
|
{
|
|
|
|
m_opaque_ptr->SourceInitFile (true, result.ref());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result->AppendError ("SBCommandInterpreter is not valid");
|
|
|
|
result->SetStatus (eReturnStatusFailed);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SBBroadcaster
|
|
|
|
SBCommandInterpreter::GetBroadcaster ()
|
|
|
|
{
|
2010-06-23 09:19:29 +08:00
|
|
|
SBBroadcaster broadcaster (m_opaque_ptr, false);
|
2010-06-09 00:52:24 +08:00
|
|
|
return broadcaster;
|
|
|
|
}
|
|
|
|
|