2010-06-09 00:52:24 +08:00
//===-- CommandObjectSettings.cpp -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
2012-12-05 08:20:57 +08:00
# include "lldb/lldb-python.h"
2010-06-09 00:52:24 +08:00
# include "CommandObjectSettings.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
# include "lldb/Interpreter/CommandInterpreter.h"
# include "lldb/Interpreter/CommandReturnObject.h"
2010-09-04 08:03:46 +08:00
# include "lldb/Interpreter/CommandCompletions.h"
2010-06-09 00:52:24 +08:00
using namespace lldb ;
using namespace lldb_private ;
2012-06-09 05:56:10 +08:00
# include "llvm/ADT/StringRef.h"
2010-06-09 00:52:24 +08:00
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
// CommandObjectSettingsSet
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
class CommandObjectSettingsSet : public CommandObjectRaw
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
public :
CommandObjectSettingsSet ( CommandInterpreter & interpreter ) :
CommandObjectRaw ( interpreter ,
" settings set " ,
" Set or change the value of a single debugger setting variable. " ,
NULL ) ,
m_options ( interpreter )
{
CommandArgumentEntry arg1 ;
CommandArgumentEntry arg2 ;
CommandArgumentData var_name_arg ;
CommandArgumentData value_arg ;
2010-10-05 06:28:36 +08:00
2012-06-09 05:56:10 +08:00
// Define the first (and only) variant of this arg.
var_name_arg . arg_type = eArgTypeSettingVariableName ;
var_name_arg . arg_repetition = eArgRepeatPlain ;
2010-10-05 06:28:36 +08:00
2012-06-09 05:56:10 +08:00
// There is only one variant this argument could be; put it into the argument entry.
arg1 . push_back ( var_name_arg ) ;
2010-10-05 06:28:36 +08:00
2012-06-09 05:56:10 +08:00
// Define the first (and only) variant of this arg.
value_arg . arg_type = eArgTypeValue ;
value_arg . arg_repetition = eArgRepeatPlain ;
2010-10-05 06:28:36 +08:00
2012-06-09 05:56:10 +08:00
// There is only one variant this argument could be; put it into the argument entry.
arg2 . push_back ( value_arg ) ;
2010-10-05 06:28:36 +08:00
2012-06-09 05:56:10 +08:00
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg1 ) ;
m_arguments . push_back ( arg2 ) ;
SetHelpLong (
2010-12-10 08:26:54 +08:00
" When setting a dictionary or array variable, you can set multiple entries \n \
at once by giving the values to the set command . For example : \ n \
\ n \
2012-08-23 01:17:09 +08:00
( lldb ) settings set target . run - args value1 value2 value3 \ n \
( lldb ) settings set target . env - vars MYPATH = ~ / . : / usr / bin SOME_ENV_VAR = 12345 \ n \
2010-12-10 08:26:54 +08:00
\ n \
2011-11-08 10:43:13 +08:00
( lldb ) settings show target . run - args \ n \
2010-12-10 08:26:54 +08:00
[ 0 ] : ' value1 ' \ n \
[ 1 ] : ' value2 ' \ n \
[ 3 ] : ' value3 ' \ n \
2011-11-08 10:43:13 +08:00
( lldb ) settings show target . env - vars \ n \
2010-12-10 08:26:54 +08:00
' MYPATH = ~ / . : / usr / bin ' \ n \
' SOME_ENV_VAR = 12345 ' \ n \
\ n \
Warning : The ' set ' command re - sets the entire array or dictionary . If you \ n \
just want to add , remove or update individual values ( or add something to \ n \
the end ) , use one of the other settings sub - commands : append , replace , \ n \
insert - before or insert - after . \ n " );
2012-06-09 05:56:10 +08:00
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
virtual
~ CommandObjectSettingsSet ( ) { }
2012-01-20 03:22:41 +08:00
2012-06-09 05:56:10 +08:00
// Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
virtual bool
WantsCompletion ( ) { return true ; }
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
virtual Options *
GetOptions ( )
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
return & m_options ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
class CommandOptions : public Options
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
public :
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
CommandOptions ( CommandInterpreter & interpreter ) :
Options ( interpreter ) ,
2012-08-23 01:17:09 +08:00
m_global ( false )
2010-09-04 08:03:46 +08:00
{
}
2012-06-09 05:56:10 +08:00
virtual
~ CommandOptions ( ) { }
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
virtual Error
SetOptionValue ( uint32_t option_idx , const char * option_arg )
{
Error error ;
2012-12-04 08:32:51 +08:00
const int short_option = m_getopt_table [ option_idx ] . val ;
2012-06-09 05:56:10 +08:00
switch ( short_option )
{
2012-08-23 01:17:09 +08:00
case ' g ' :
m_global = true ;
2012-06-09 05:56:10 +08:00
break ;
default :
error . SetErrorStringWithFormat ( " unrecognized options '%c' " , short_option ) ;
break ;
}
return error ;
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
void
OptionParsingStarting ( )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
m_global = false ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
const OptionDefinition *
GetDefinitions ( )
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
return g_option_table ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
// Options table: Required for subclasses of Options.
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
static OptionDefinition g_option_table [ ] ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Instance variables to hold the values for command options.
2010-09-04 08:03:46 +08:00
2012-08-23 01:17:09 +08:00
bool m_global ;
2012-06-09 05:56:10 +08:00
} ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
virtual int
HandleArgumentCompletion ( Args & input ,
int & cursor_index ,
int & cursor_char_position ,
OptionElementVector & opt_element_vector ,
int match_start_point ,
int max_return_elements ,
bool & word_complete ,
StringList & matches )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
std : : string completion_str ( input . GetArgumentAtIndex ( cursor_index ) , cursor_char_position ) ;
2012-06-09 05:56:10 +08:00
2012-08-23 01:17:09 +08:00
const size_t argc = input . GetArgumentCount ( ) ;
const char * arg = NULL ;
int setting_var_idx ;
2014-04-02 11:51:35 +08:00
for ( setting_var_idx = 1 ; setting_var_idx < static_cast < int > ( argc ) ;
+ + setting_var_idx )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
arg = input . GetArgumentAtIndex ( setting_var_idx ) ;
if ( arg & & arg [ 0 ] ! = ' - ' )
break ; // We found our setting variable name index
}
if ( cursor_index = = setting_var_idx )
{
// Attempting to complete setting variable name
2012-06-09 05:56:10 +08:00
CommandCompletions : : InvokeCommonCompletionCallbacks ( m_interpreter ,
CommandCompletions : : eSettingsNameCompletion ,
completion_str . c_str ( ) ,
match_start_point ,
max_return_elements ,
NULL ,
word_complete ,
matches ) ;
}
2012-08-23 01:17:09 +08:00
else
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
arg = input . GetArgumentAtIndex ( cursor_index ) ;
if ( arg )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
if ( arg [ 0 ] = = ' - ' )
{
// Complete option name
}
else
{
// Complete setting value
const char * setting_var_name = input . GetArgumentAtIndex ( setting_var_idx ) ;
Error error ;
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
lldb : : OptionValueSP value_sp ( m_interpreter . GetDebugger ( ) . GetPropertyValue ( & m_exe_ctx , setting_var_name , false , error ) ) ;
2012-08-23 01:17:09 +08:00
if ( value_sp )
{
value_sp - > AutoComplete ( m_interpreter ,
completion_str . c_str ( ) ,
match_start_point ,
max_return_elements ,
word_complete ,
matches ) ;
}
}
2012-06-09 05:56:10 +08:00
}
}
return matches . GetSize ( ) ;
}
protected :
virtual bool
DoExecute ( const char * command , CommandReturnObject & result )
{
Args cmd_args ( command ) ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Process possible options.
if ( ! ParseOptions ( cmd_args , result ) )
return false ;
2010-09-04 08:03:46 +08:00
2012-08-23 01:17:09 +08:00
const size_t argc = cmd_args . GetArgumentCount ( ) ;
if ( ( argc < 2 ) & & ( ! m_options . m_global ) )
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
result . AppendError ( " 'settings set' takes more arguments " ) ;
2010-09-04 08:03:46 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2012-06-09 05:56:10 +08:00
return false ;
2011-04-20 06:32:36 +08:00
}
2012-06-09 05:56:10 +08:00
const char * var_name = cmd_args . GetArgumentAtIndex ( 0 ) ;
if ( ( var_name = = NULL ) | | ( var_name [ 0 ] = = ' \0 ' ) )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
result . AppendError ( " 'settings set' command requires a valid variable name " ) ;
2012-06-09 05:56:10 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
// Split the raw command into var_name and value pair.
llvm : : StringRef raw_str ( command ) ;
2013-03-06 07:52:49 +08:00
std : : string var_value_string = raw_str . split ( var_name ) . second . str ( ) ;
const char * var_value_cstr = Args : : StripSpaces ( var_value_string , true , true , false ) ;
2012-06-09 05:56:10 +08:00
2012-08-23 01:17:09 +08:00
Error error ;
if ( m_options . m_global )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
error = m_interpreter . GetDebugger ( ) . SetPropertyValue ( NULL ,
eVarSetOperationAssign ,
var_name ,
2013-03-06 07:52:49 +08:00
var_value_cstr ) ;
2012-08-23 01:17:09 +08:00
}
if ( error . Success ( ) )
{
2013-05-21 06:29:23 +08:00
// FIXME this is the same issue as the one in commands script import
// we could be setting target.load-script-from-symbol-file which would cause
// Python scripts to be loaded, which could run LLDB commands
// (e.g. settings set target.process.python-os-plugin-path) and cause a crash
// if we did not clear the command's exe_ctx first
ExecutionContext exe_ctx ( m_exe_ctx ) ;
m_exe_ctx . Clear ( ) ;
error = m_interpreter . GetDebugger ( ) . SetPropertyValue ( & exe_ctx ,
2012-08-23 01:17:09 +08:00
eVarSetOperationAssign ,
var_name ,
2013-03-06 07:52:49 +08:00
var_value_cstr ) ;
2012-08-23 01:17:09 +08:00
}
if ( error . Fail ( ) )
{
result . AppendError ( error . AsCString ( ) ) ;
2010-09-04 08:03:46 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2012-08-23 01:17:09 +08:00
return false ;
2010-09-04 08:03:46 +08:00
}
else
{
2012-08-23 01:17:09 +08:00
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
return result . Succeeded ( ) ;
}
private :
CommandOptions m_options ;
} ;
2010-06-09 00:52:24 +08:00
2012-06-09 05:56:10 +08:00
OptionDefinition
CommandObjectSettingsSet : : CommandOptions : : g_option_table [ ] =
2010-09-04 08:03:46 +08:00
{
2014-07-10 00:31:49 +08:00
{ LLDB_OPT_SET_2 , false , " global " , ' g ' , OptionParser : : eNoArgument , NULL , NULL , 0 , eArgTypeNone , " Apply the new value to the global default value. " } ,
{ 0 , false , NULL , 0 , 0 , NULL , NULL , 0 , eArgTypeNone , NULL }
2012-06-09 05:56:10 +08:00
} ;
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
// CommandObjectSettingsShow -- Show current values
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
class CommandObjectSettingsShow : public CommandObjectParsed
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
public :
CommandObjectSettingsShow ( CommandInterpreter & interpreter ) :
CommandObjectParsed ( interpreter ,
" settings show " ,
" Show the specified internal debugger setting variable and its value, or show all the currently set variables and their values, if nothing is specified. " ,
NULL )
{
CommandArgumentEntry arg1 ;
CommandArgumentData var_name_arg ;
2010-10-05 06:28:36 +08:00
2012-06-09 05:56:10 +08:00
// Define the first (and only) variant of this arg.
var_name_arg . arg_type = eArgTypeSettingVariableName ;
var_name_arg . arg_repetition = eArgRepeatOptional ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// There is only one variant this argument could be; put it into the argument entry.
arg1 . push_back ( var_name_arg ) ;
2010-06-09 00:52:24 +08:00
2012-06-09 05:56:10 +08:00
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg1 ) ;
}
2010-06-09 00:52:24 +08:00
2012-06-09 05:56:10 +08:00
virtual
~ CommandObjectSettingsShow ( ) { }
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
virtual int
HandleArgumentCompletion ( Args & input ,
int & cursor_index ,
int & cursor_char_position ,
OptionElementVector & opt_element_vector ,
int match_start_point ,
int max_return_elements ,
bool & word_complete ,
StringList & matches )
2010-09-15 14:56:39 +08:00
{
2012-08-23 01:17:09 +08:00
std : : string completion_str ( input . GetArgumentAtIndex ( cursor_index ) , cursor_char_position ) ;
2012-06-09 05:56:10 +08:00
CommandCompletions : : InvokeCommonCompletionCallbacks ( m_interpreter ,
CommandCompletions : : eSettingsNameCompletion ,
completion_str . c_str ( ) ,
match_start_point ,
max_return_elements ,
NULL ,
word_complete ,
matches ) ;
return matches . GetSize ( ) ;
2010-09-15 14:56:39 +08:00
}
2012-06-09 05:56:10 +08:00
protected :
virtual bool
2012-08-23 01:17:09 +08:00
DoExecute ( Args & args , CommandReturnObject & result )
2010-09-15 14:56:39 +08:00
{
2012-08-23 01:17:09 +08:00
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
2012-06-09 05:56:10 +08:00
2012-08-23 01:17:09 +08:00
const size_t argc = args . GetArgumentCount ( ) ;
if ( argc > 0 )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
for ( size_t i = 0 ; i < argc ; + + i )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
const char * property_path = args . GetArgumentAtIndex ( i ) ;
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
Error error ( m_interpreter . GetDebugger ( ) . DumpPropertyValue ( & m_exe_ctx , result . GetOutputStream ( ) , property_path , OptionValue : : eDumpGroupValue ) ) ;
2012-08-23 01:17:09 +08:00
if ( error . Success ( ) )
{
result . GetOutputStream ( ) . EOL ( ) ;
}
else
{
result . AppendError ( error . AsCString ( ) ) ;
result . SetStatus ( eReturnStatusFailed ) ;
}
2012-06-09 05:56:10 +08:00
}
}
else
{
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
m_interpreter . GetDebugger ( ) . DumpAllPropertyValues ( & m_exe_ctx , result . GetOutputStream ( ) , OptionValue : : eDumpGroupValue ) ;
2012-06-09 05:56:10 +08:00
}
2010-06-09 00:52:24 +08:00
2012-06-09 05:56:10 +08:00
return result . Succeeded ( ) ;
2010-06-09 00:52:24 +08:00
}
2012-06-09 05:56:10 +08:00
} ;
2010-09-15 14:56:39 +08:00
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
// CommandObjectSettingsList -- List settable variables
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
class CommandObjectSettingsList : public CommandObjectParsed
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
public :
CommandObjectSettingsList ( CommandInterpreter & interpreter ) :
CommandObjectParsed ( interpreter ,
" settings list " ,
" List and describe all the internal debugger settings variables that are available to the user to 'set' or 'show', or describe a particular variable or set of variables (by specifying the variable name or a common prefix). " ,
NULL )
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
CommandArgumentEntry arg ;
CommandArgumentData var_name_arg ;
CommandArgumentData prefix_name_arg ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Define the first variant of this arg.
var_name_arg . arg_type = eArgTypeSettingVariableName ;
var_name_arg . arg_repetition = eArgRepeatOptional ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Define the second variant of this arg.
prefix_name_arg . arg_type = eArgTypeSettingPrefix ;
prefix_name_arg . arg_repetition = eArgRepeatOptional ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
arg . push_back ( var_name_arg ) ;
arg . push_back ( prefix_name_arg ) ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg ) ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
virtual
~ CommandObjectSettingsList ( ) { }
virtual int
HandleArgumentCompletion ( Args & input ,
int & cursor_index ,
int & cursor_char_position ,
OptionElementVector & opt_element_vector ,
int match_start_point ,
int max_return_elements ,
bool & word_complete ,
StringList & matches )
{
2012-08-23 01:17:09 +08:00
std : : string completion_str ( input . GetArgumentAtIndex ( cursor_index ) , cursor_char_position ) ;
2010-09-04 08:03:46 +08:00
2010-09-18 09:14:36 +08:00
CommandCompletions : : InvokeCommonCompletionCallbacks ( m_interpreter ,
2010-09-04 08:03:46 +08:00
CommandCompletions : : eSettingsNameCompletion ,
completion_str . c_str ( ) ,
match_start_point ,
max_return_elements ,
NULL ,
word_complete ,
matches ) ;
2012-06-09 05:56:10 +08:00
return matches . GetSize ( ) ;
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
protected :
virtual bool
2012-08-23 01:17:09 +08:00
DoExecute ( Args & args , CommandReturnObject & result )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
result . SetStatus ( eReturnStatusSuccessFinishResult ) ;
2010-09-04 08:03:46 +08:00
2012-08-23 01:17:09 +08:00
const bool will_modify = false ;
const size_t argc = args . GetArgumentCount ( ) ;
if ( argc > 0 )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
const bool dump_qualified_name = true ;
2010-09-04 08:03:46 +08:00
2012-08-23 01:17:09 +08:00
for ( size_t i = 0 ; i < argc ; + + i )
{
const char * property_path = args . GetArgumentAtIndex ( i ) ;
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
const Property * property = m_interpreter . GetDebugger ( ) . GetValueProperties ( ) - > GetPropertyAtPath ( & m_exe_ctx , will_modify , property_path ) ;
2012-08-23 01:17:09 +08:00
if ( property )
{
property - > DumpDescription ( m_interpreter , result . GetOutputStream ( ) , 0 , dump_qualified_name ) ;
}
else
{
result . AppendErrorWithFormat ( " invalid property path '%s' " , property_path ) ;
result . SetStatus ( eReturnStatusFailed ) ;
}
}
2012-06-09 05:56:10 +08:00
}
else
{
2012-08-23 01:17:09 +08:00
m_interpreter . GetDebugger ( ) . DumpAllDescriptions ( m_interpreter , result . GetOutputStream ( ) ) ;
2012-06-09 05:56:10 +08:00
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
return result . Succeeded ( ) ;
}
} ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
//-------------------------------------------------------------------------
// CommandObjectSettingsRemove
//-------------------------------------------------------------------------
2010-09-04 08:03:46 +08:00
2012-08-23 01:17:09 +08:00
class CommandObjectSettingsRemove : public CommandObjectRaw
2012-06-09 05:56:10 +08:00
{
public :
CommandObjectSettingsRemove ( CommandInterpreter & interpreter ) :
2012-08-23 01:17:09 +08:00
CommandObjectRaw ( interpreter ,
" settings remove " ,
" Remove the specified element from an array or dictionary settings variable. " ,
NULL )
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
CommandArgumentEntry arg1 ;
CommandArgumentEntry arg2 ;
CommandArgumentData var_name_arg ;
CommandArgumentData index_arg ;
CommandArgumentData key_arg ;
// Define the first (and only) variant of this arg.
var_name_arg . arg_type = eArgTypeSettingVariableName ;
var_name_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg1 . push_back ( var_name_arg ) ;
// Define the first variant of this arg.
index_arg . arg_type = eArgTypeSettingIndex ;
index_arg . arg_repetition = eArgRepeatPlain ;
// Define the second variant of this arg.
key_arg . arg_type = eArgTypeSettingKey ;
key_arg . arg_repetition = eArgRepeatPlain ;
// Push both variants into this arg
arg2 . push_back ( index_arg ) ;
arg2 . push_back ( key_arg ) ;
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg1 ) ;
m_arguments . push_back ( arg2 ) ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
virtual
~ CommandObjectSettingsRemove ( ) { }
virtual int
HandleArgumentCompletion ( Args & input ,
int & cursor_index ,
int & cursor_char_position ,
OptionElementVector & opt_element_vector ,
int match_start_point ,
int max_return_elements ,
bool & word_complete ,
StringList & matches )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
std : : string completion_str ( input . GetArgumentAtIndex ( cursor_index ) , cursor_char_position ) ;
2012-06-09 05:56:10 +08:00
// Attempting to complete variable name
if ( cursor_index < 2 )
CommandCompletions : : InvokeCommonCompletionCallbacks ( m_interpreter ,
CommandCompletions : : eSettingsNameCompletion ,
completion_str . c_str ( ) ,
match_start_point ,
max_return_elements ,
NULL ,
word_complete ,
matches ) ;
return matches . GetSize ( ) ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
protected :
virtual bool
2012-08-23 01:17:09 +08:00
DoExecute ( const char * command , CommandReturnObject & result )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
result . SetStatus ( eReturnStatusSuccessFinishNoResult ) ;
Args cmd_args ( command ) ;
// Process possible options.
if ( ! ParseOptions ( cmd_args , result ) )
return false ;
const size_t argc = cmd_args . GetArgumentCount ( ) ;
if ( argc = = 0 )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
result . AppendError ( " 'settings set' takes an array or dictionary item, or an array followed by one or more indexes, or a dictionary followed by one or more key names to remove " ) ;
2012-06-09 05:56:10 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2012-08-23 01:17:09 +08:00
const char * var_name = cmd_args . GetArgumentAtIndex ( 0 ) ;
2012-06-09 05:56:10 +08:00
if ( ( var_name = = NULL ) | | ( var_name [ 0 ] = = ' \0 ' ) )
{
2012-08-23 01:17:09 +08:00
result . AppendError ( " 'settings set' command requires a valid variable name " ) ;
2012-06-09 05:56:10 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2012-08-23 01:17:09 +08:00
// Split the raw command into var_name and value pair.
llvm : : StringRef raw_str ( command ) ;
2013-03-06 07:52:49 +08:00
std : : string var_value_string = raw_str . split ( var_name ) . second . str ( ) ;
const char * var_value_cstr = Args : : StripSpaces ( var_value_string , true , true , false ) ;
2012-08-23 01:17:09 +08:00
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
Error error ( m_interpreter . GetDebugger ( ) . SetPropertyValue ( & m_exe_ctx ,
2012-08-23 01:17:09 +08:00
eVarSetOperationRemove ,
var_name ,
2013-03-06 07:52:49 +08:00
var_value_cstr ) ) ;
2012-08-23 01:17:09 +08:00
if ( error . Fail ( ) )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
result . AppendError ( error . AsCString ( ) ) ;
2012-06-09 05:56:10 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2012-08-23 01:17:09 +08:00
2012-06-09 05:56:10 +08:00
return result . Succeeded ( ) ;
}
} ;
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
// CommandObjectSettingsReplace
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
class CommandObjectSettingsReplace : public CommandObjectRaw
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
public :
CommandObjectSettingsReplace ( CommandInterpreter & interpreter ) :
CommandObjectRaw ( interpreter ,
" settings replace " ,
" Replace the specified element from an internal debugger settings array or dictionary variable with the specified new value. " ,
NULL )
{
CommandArgumentEntry arg1 ;
CommandArgumentEntry arg2 ;
CommandArgumentEntry arg3 ;
CommandArgumentData var_name_arg ;
CommandArgumentData index_arg ;
CommandArgumentData key_arg ;
CommandArgumentData value_arg ;
// Define the first (and only) variant of this arg.
var_name_arg . arg_type = eArgTypeSettingVariableName ;
var_name_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg1 . push_back ( var_name_arg ) ;
// Define the first (variant of this arg.
index_arg . arg_type = eArgTypeSettingIndex ;
index_arg . arg_repetition = eArgRepeatPlain ;
// Define the second (variant of this arg.
key_arg . arg_type = eArgTypeSettingKey ;
key_arg . arg_repetition = eArgRepeatPlain ;
// Put both variants into this arg
arg2 . push_back ( index_arg ) ;
arg2 . push_back ( key_arg ) ;
// Define the first (and only) variant of this arg.
value_arg . arg_type = eArgTypeValue ;
value_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg3 . push_back ( value_arg ) ;
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg1 ) ;
m_arguments . push_back ( arg2 ) ;
m_arguments . push_back ( arg3 ) ;
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
virtual
~ CommandObjectSettingsReplace ( ) { }
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
virtual bool
WantsCompletion ( ) { return true ; }
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
virtual int
HandleArgumentCompletion ( Args & input ,
int & cursor_index ,
int & cursor_char_position ,
OptionElementVector & opt_element_vector ,
int match_start_point ,
int max_return_elements ,
bool & word_complete ,
StringList & matches )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
std : : string completion_str ( input . GetArgumentAtIndex ( cursor_index ) , cursor_char_position ) ;
2012-06-09 05:56:10 +08:00
// Attempting to complete variable name
if ( cursor_index < 2 )
CommandCompletions : : InvokeCommonCompletionCallbacks ( m_interpreter ,
CommandCompletions : : eSettingsNameCompletion ,
completion_str . c_str ( ) ,
match_start_point ,
max_return_elements ,
NULL ,
word_complete ,
matches ) ;
return matches . GetSize ( ) ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
protected :
virtual bool
DoExecute ( const char * command , CommandReturnObject & result )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
result . SetStatus ( eReturnStatusSuccessFinishNoResult ) ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
Args cmd_args ( command ) ;
const char * var_name = cmd_args . GetArgumentAtIndex ( 0 ) ;
if ( ( var_name = = NULL ) | | ( var_name [ 0 ] = = ' \0 ' ) )
{
result . AppendError ( " 'settings replace' command requires a valid variable name; No value supplied " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Split the raw command into var_name, index_value, and value triple.
llvm : : StringRef raw_str ( command ) ;
2013-03-06 07:52:49 +08:00
std : : string var_value_string = raw_str . split ( var_name ) . second . str ( ) ;
const char * var_value_cstr = Args : : StripSpaces ( var_value_string , true , true , false ) ;
2010-09-04 08:03:46 +08:00
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
Error error ( m_interpreter . GetDebugger ( ) . SetPropertyValue ( & m_exe_ctx ,
2012-08-23 01:17:09 +08:00
eVarSetOperationReplace ,
var_name ,
2013-03-06 07:52:49 +08:00
var_value_cstr ) ) ;
2012-08-23 01:17:09 +08:00
if ( error . Fail ( ) )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
result . AppendError ( error . AsCString ( ) ) ;
2012-06-09 05:56:10 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2012-08-23 01:17:09 +08:00
return false ;
2012-06-09 05:56:10 +08:00
}
else
{
2012-08-23 01:17:09 +08:00
result . SetStatus ( eReturnStatusSuccessFinishNoResult ) ;
2012-06-09 05:56:10 +08:00
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
return result . Succeeded ( ) ;
}
} ;
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
// CommandObjectSettingsInsertBefore
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
class CommandObjectSettingsInsertBefore : public CommandObjectRaw
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
public :
CommandObjectSettingsInsertBefore ( CommandInterpreter & interpreter ) :
CommandObjectRaw ( interpreter ,
" settings insert-before " ,
" Insert value(s) into an internal debugger settings array variable, immediately before the specified element. " ,
NULL )
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
CommandArgumentEntry arg1 ;
CommandArgumentEntry arg2 ;
CommandArgumentEntry arg3 ;
CommandArgumentData var_name_arg ;
CommandArgumentData index_arg ;
CommandArgumentData value_arg ;
// Define the first (and only) variant of this arg.
var_name_arg . arg_type = eArgTypeSettingVariableName ;
var_name_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg1 . push_back ( var_name_arg ) ;
// Define the first (variant of this arg.
index_arg . arg_type = eArgTypeSettingIndex ;
index_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg2 . push_back ( index_arg ) ;
// Define the first (and only) variant of this arg.
value_arg . arg_type = eArgTypeValue ;
value_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg3 . push_back ( value_arg ) ;
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg1 ) ;
m_arguments . push_back ( arg2 ) ;
m_arguments . push_back ( arg3 ) ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
virtual
~ CommandObjectSettingsInsertBefore ( ) { }
// Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
virtual bool
WantsCompletion ( ) { return true ; }
virtual int
HandleArgumentCompletion ( Args & input ,
int & cursor_index ,
int & cursor_char_position ,
OptionElementVector & opt_element_vector ,
int match_start_point ,
int max_return_elements ,
bool & word_complete ,
StringList & matches )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
std : : string completion_str ( input . GetArgumentAtIndex ( cursor_index ) , cursor_char_position ) ;
2012-06-09 05:56:10 +08:00
// Attempting to complete variable name
if ( cursor_index < 2 )
CommandCompletions : : InvokeCommonCompletionCallbacks ( m_interpreter ,
CommandCompletions : : eSettingsNameCompletion ,
completion_str . c_str ( ) ,
match_start_point ,
max_return_elements ,
NULL ,
word_complete ,
matches ) ;
return matches . GetSize ( ) ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
protected :
virtual bool
DoExecute ( const char * command , CommandReturnObject & result )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
result . SetStatus ( eReturnStatusSuccessFinishNoResult ) ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
Args cmd_args ( command ) ;
2012-08-23 01:17:09 +08:00
const size_t argc = cmd_args . GetArgumentCount ( ) ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
if ( argc < 3 )
{
result . AppendError ( " 'settings insert-before' takes more arguments " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
const char * var_name = cmd_args . GetArgumentAtIndex ( 0 ) ;
if ( ( var_name = = NULL ) | | ( var_name [ 0 ] = = ' \0 ' ) )
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
result . AppendError ( " 'settings insert-before' command requires a valid variable name; No value supplied " ) ;
2010-09-04 08:03:46 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2012-06-09 05:56:10 +08:00
return false ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
// Split the raw command into var_name, index_value, and value triple.
llvm : : StringRef raw_str ( command ) ;
2013-03-06 07:52:49 +08:00
std : : string var_value_string = raw_str . split ( var_name ) . second . str ( ) ;
const char * var_value_cstr = Args : : StripSpaces ( var_value_string , true , true , false ) ;
2010-09-04 08:03:46 +08:00
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
Error error ( m_interpreter . GetDebugger ( ) . SetPropertyValue ( & m_exe_ctx ,
2012-08-23 01:17:09 +08:00
eVarSetOperationInsertBefore ,
var_name ,
2013-03-06 07:52:49 +08:00
var_value_cstr ) ) ;
2012-08-23 01:17:09 +08:00
if ( error . Fail ( ) )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
result . AppendError ( error . AsCString ( ) ) ;
2012-06-09 05:56:10 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2012-08-23 01:17:09 +08:00
return false ;
2012-06-09 05:56:10 +08:00
}
return result . Succeeded ( ) ;
}
} ;
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
// CommandObjectSettingInsertAfter
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
class CommandObjectSettingsInsertAfter : public CommandObjectRaw
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
public :
CommandObjectSettingsInsertAfter ( CommandInterpreter & interpreter ) :
CommandObjectRaw ( interpreter ,
" settings insert-after " ,
" Insert value(s) into an internal debugger settings array variable, immediately after the specified element. " ,
NULL )
{
CommandArgumentEntry arg1 ;
CommandArgumentEntry arg2 ;
CommandArgumentEntry arg3 ;
CommandArgumentData var_name_arg ;
CommandArgumentData index_arg ;
CommandArgumentData value_arg ;
// Define the first (and only) variant of this arg.
var_name_arg . arg_type = eArgTypeSettingVariableName ;
var_name_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg1 . push_back ( var_name_arg ) ;
// Define the first (variant of this arg.
index_arg . arg_type = eArgTypeSettingIndex ;
index_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg2 . push_back ( index_arg ) ;
// Define the first (and only) variant of this arg.
value_arg . arg_type = eArgTypeValue ;
value_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg3 . push_back ( value_arg ) ;
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg1 ) ;
m_arguments . push_back ( arg2 ) ;
m_arguments . push_back ( arg3 ) ;
}
virtual
~ CommandObjectSettingsInsertAfter ( ) { }
// Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
virtual bool
WantsCompletion ( ) { return true ; }
virtual int
HandleArgumentCompletion ( Args & input ,
int & cursor_index ,
int & cursor_char_position ,
OptionElementVector & opt_element_vector ,
int match_start_point ,
int max_return_elements ,
bool & word_complete ,
StringList & matches )
{
2012-08-23 01:17:09 +08:00
std : : string completion_str ( input . GetArgumentAtIndex ( cursor_index ) , cursor_char_position ) ;
2012-06-09 05:56:10 +08:00
// Attempting to complete variable name
if ( cursor_index < 2 )
CommandCompletions : : InvokeCommonCompletionCallbacks ( m_interpreter ,
CommandCompletions : : eSettingsNameCompletion ,
completion_str . c_str ( ) ,
match_start_point ,
max_return_elements ,
NULL ,
word_complete ,
matches ) ;
return matches . GetSize ( ) ;
}
protected :
virtual bool
DoExecute ( const char * command , CommandReturnObject & result )
{
2012-08-23 01:17:09 +08:00
result . SetStatus ( eReturnStatusSuccessFinishNoResult ) ;
2010-10-05 06:28:36 +08:00
2012-06-09 05:56:10 +08:00
Args cmd_args ( command ) ;
2012-08-23 01:17:09 +08:00
const size_t argc = cmd_args . GetArgumentCount ( ) ;
2010-10-05 06:28:36 +08:00
2012-06-09 05:56:10 +08:00
if ( argc < 3 )
{
result . AppendError ( " 'settings insert-after' takes more arguments " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2010-10-05 06:28:36 +08:00
2012-06-09 05:56:10 +08:00
const char * var_name = cmd_args . GetArgumentAtIndex ( 0 ) ;
if ( ( var_name = = NULL ) | | ( var_name [ 0 ] = = ' \0 ' ) )
{
result . AppendError ( " 'settings insert-after' command requires a valid variable name; No value supplied " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2010-10-05 06:28:36 +08:00
2012-06-09 05:56:10 +08:00
// Split the raw command into var_name, index_value, and value triple.
llvm : : StringRef raw_str ( command ) ;
2013-03-06 07:52:49 +08:00
std : : string var_value_string = raw_str . split ( var_name ) . second . str ( ) ;
const char * var_value_cstr = Args : : StripSpaces ( var_value_string , true , true , false ) ;
2010-09-04 08:03:46 +08:00
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
Error error ( m_interpreter . GetDebugger ( ) . SetPropertyValue ( & m_exe_ctx ,
2012-08-23 01:17:09 +08:00
eVarSetOperationInsertAfter ,
var_name ,
2013-03-06 07:52:49 +08:00
var_value_cstr ) ) ;
2012-08-23 01:17:09 +08:00
if ( error . Fail ( ) )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
result . AppendError ( error . AsCString ( ) ) ;
2012-06-09 05:56:10 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2012-08-23 01:17:09 +08:00
return false ;
2012-06-09 05:56:10 +08:00
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
return result . Succeeded ( ) ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
} ;
//-------------------------------------------------------------------------
// CommandObjectSettingsAppend
//-------------------------------------------------------------------------
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
class CommandObjectSettingsAppend : public CommandObjectRaw
{
public :
CommandObjectSettingsAppend ( CommandInterpreter & interpreter ) :
CommandObjectRaw ( interpreter ,
" settings append " ,
" Append a new value to the end of an internal debugger settings array, dictionary or string variable. " ,
NULL )
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
CommandArgumentEntry arg1 ;
CommandArgumentEntry arg2 ;
CommandArgumentData var_name_arg ;
CommandArgumentData value_arg ;
// Define the first (and only) variant of this arg.
var_name_arg . arg_type = eArgTypeSettingVariableName ;
var_name_arg . arg_repetition = eArgRepeatPlain ;
// There is only one variant this argument could be; put it into the argument entry.
arg1 . push_back ( var_name_arg ) ;
// Define the first (and only) variant of this arg.
value_arg . arg_type = eArgTypeValue ;
value_arg . arg_repetition = eArgRepeatPlain ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// There is only one variant this argument could be; put it into the argument entry.
arg2 . push_back ( value_arg ) ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg1 ) ;
m_arguments . push_back ( arg2 ) ;
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
virtual
~ CommandObjectSettingsAppend ( ) { }
// Overrides base class's behavior where WantsCompletion = !WantsRawCommandString.
virtual bool
WantsCompletion ( ) { return true ; }
virtual int
HandleArgumentCompletion ( Args & input ,
int & cursor_index ,
int & cursor_char_position ,
OptionElementVector & opt_element_vector ,
int match_start_point ,
int max_return_elements ,
bool & word_complete ,
StringList & matches )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
std : : string completion_str ( input . GetArgumentAtIndex ( cursor_index ) , cursor_char_position ) ;
2012-06-09 05:56:10 +08:00
// Attempting to complete variable name
if ( cursor_index < 2 )
CommandCompletions : : InvokeCommonCompletionCallbacks ( m_interpreter ,
CommandCompletions : : eSettingsNameCompletion ,
completion_str . c_str ( ) ,
match_start_point ,
max_return_elements ,
NULL ,
word_complete ,
matches ) ;
return matches . GetSize ( ) ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
protected :
virtual bool
DoExecute ( const char * command , CommandReturnObject & result )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
result . SetStatus ( eReturnStatusSuccessFinishNoResult ) ;
2012-06-09 05:56:10 +08:00
Args cmd_args ( command ) ;
2012-08-23 01:17:09 +08:00
const size_t argc = cmd_args . GetArgumentCount ( ) ;
2012-06-09 05:56:10 +08:00
if ( argc < 2 )
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
result . AppendError ( " 'settings append' takes more arguments " ) ;
2010-09-04 08:03:46 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2012-06-09 05:56:10 +08:00
return false ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
const char * var_name = cmd_args . GetArgumentAtIndex ( 0 ) ;
if ( ( var_name = = NULL ) | | ( var_name [ 0 ] = = ' \0 ' ) )
{
result . AppendError ( " 'settings append' command requires a valid variable name; No value supplied " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Do not perform cmd_args.Shift() since StringRef is manipulating the
// raw character string later on.
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Split the raw command into var_name and value pair.
llvm : : StringRef raw_str ( command ) ;
2013-03-06 07:52:49 +08:00
std : : string var_value_string = raw_str . split ( var_name ) . second . str ( ) ;
const char * var_value_cstr = Args : : StripSpaces ( var_value_string , true , true , false ) ;
2010-09-04 08:03:46 +08:00
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
Error error ( m_interpreter . GetDebugger ( ) . SetPropertyValue ( & m_exe_ctx ,
2012-08-23 01:17:09 +08:00
eVarSetOperationAppend ,
var_name ,
2013-03-06 07:52:49 +08:00
var_value_cstr ) ) ;
2012-08-23 01:17:09 +08:00
if ( error . Fail ( ) )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
result . AppendError ( error . AsCString ( ) ) ;
2012-06-09 05:56:10 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2012-08-23 01:17:09 +08:00
return false ;
2012-06-09 05:56:10 +08:00
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
return result . Succeeded ( ) ;
}
} ;
2010-09-04 08:03:46 +08:00
//-------------------------------------------------------------------------
// CommandObjectSettingsClear
//-------------------------------------------------------------------------
2012-06-09 05:56:10 +08:00
class CommandObjectSettingsClear : public CommandObjectParsed
2010-09-04 08:03:46 +08:00
{
2012-06-09 05:56:10 +08:00
public :
CommandObjectSettingsClear ( CommandInterpreter & interpreter ) :
CommandObjectParsed ( interpreter ,
" settings clear " ,
" Erase all the contents of an internal debugger settings variables; this is only valid for variables with clearable types, i.e. strings, arrays or dictionaries. " ,
NULL )
{
CommandArgumentEntry arg ;
CommandArgumentData var_name_arg ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Define the first (and only) variant of this arg.
var_name_arg . arg_type = eArgTypeSettingVariableName ;
var_name_arg . arg_repetition = eArgRepeatPlain ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// There is only one variant this argument could be; put it into the argument entry.
arg . push_back ( var_name_arg ) ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
// Push the data for the first argument into the m_arguments vector.
m_arguments . push_back ( arg ) ;
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
virtual
~ CommandObjectSettingsClear ( ) { }
virtual int
HandleArgumentCompletion ( Args & input ,
int & cursor_index ,
int & cursor_char_position ,
OptionElementVector & opt_element_vector ,
int match_start_point ,
int max_return_elements ,
bool & word_complete ,
StringList & matches )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
std : : string completion_str ( input . GetArgumentAtIndex ( cursor_index ) , cursor_char_position ) ;
2012-06-09 05:56:10 +08:00
// Attempting to complete variable name
if ( cursor_index < 2 )
CommandCompletions : : InvokeCommonCompletionCallbacks ( m_interpreter ,
CommandCompletions : : eSettingsNameCompletion ,
completion_str . c_str ( ) ,
match_start_point ,
max_return_elements ,
NULL ,
word_complete ,
matches ) ;
return matches . GetSize ( ) ;
2010-09-04 08:03:46 +08:00
}
2012-06-09 05:56:10 +08:00
protected :
virtual bool
DoExecute ( Args & command , CommandReturnObject & result )
2010-09-04 08:03:46 +08:00
{
2012-08-23 01:17:09 +08:00
result . SetStatus ( eReturnStatusSuccessFinishNoResult ) ;
const size_t argc = command . GetArgumentCount ( ) ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
if ( argc ! = 1 )
{
2014-07-02 05:22:11 +08:00
result . AppendError ( " 'settings clear' takes exactly one argument " ) ;
2012-06-09 05:56:10 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
const char * var_name = command . GetArgumentAtIndex ( 0 ) ;
if ( ( var_name = = NULL ) | | ( var_name [ 0 ] = = ' \0 ' ) )
{
result . AppendError ( " 'settings clear' command requires a valid variable name; No value supplied " ) ;
result . SetStatus ( eReturnStatusFailed ) ;
return false ;
}
2012-08-23 01:17:09 +08:00
Expanded the flags that can be set for a command object in lldb_private::CommandObject. This list of available flags are:
enum
{
//----------------------------------------------------------------------
// eFlagRequiresTarget
//
// Ensures a valid target is contained in m_exe_ctx prior to executing
// the command. If a target doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidTargetDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidTargetDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresTarget = (1u << 0),
//----------------------------------------------------------------------
// eFlagRequiresProcess
//
// Ensures a valid process is contained in m_exe_ctx prior to executing
// the command. If a process doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidProcessDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidProcessDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresProcess = (1u << 1),
//----------------------------------------------------------------------
// eFlagRequiresThread
//
// Ensures a valid thread is contained in m_exe_ctx prior to executing
// the command. If a thread doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidThreadDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidThreadDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresThread = (1u << 2),
//----------------------------------------------------------------------
// eFlagRequiresFrame
//
// Ensures a valid frame is contained in m_exe_ctx prior to executing
// the command. If a frame doesn't exist or is invalid, the command
// will fail and CommandObject::GetInvalidFrameDescription() will be
// returned as the error. CommandObject subclasses can override the
// virtual function for GetInvalidFrameDescription() to provide custom
// strings when needed.
//----------------------------------------------------------------------
eFlagRequiresFrame = (1u << 3),
//----------------------------------------------------------------------
// eFlagRequiresRegContext
//
// Ensures a valid register context (from the selected frame if there
// is a frame in m_exe_ctx, or from the selected thread from m_exe_ctx)
// is availble from m_exe_ctx prior to executing the command. If a
// target doesn't exist or is invalid, the command will fail and
// CommandObject::GetInvalidRegContextDescription() will be returned as
// the error. CommandObject subclasses can override the virtual function
// for GetInvalidRegContextDescription() to provide custom strings when
// needed.
//----------------------------------------------------------------------
eFlagRequiresRegContext = (1u << 4),
//----------------------------------------------------------------------
// eFlagTryTargetAPILock
//
// Attempts to acquire the target lock if a target is selected in the
// command interpreter. If the command object fails to acquire the API
// lock, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagTryTargetAPILock = (1u << 5),
//----------------------------------------------------------------------
// eFlagProcessMustBeLaunched
//
// Verifies that there is a launched process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBeLaunched = (1u << 6),
//----------------------------------------------------------------------
// eFlagProcessMustBePaused
//
// Verifies that there is a paused process in m_exe_ctx, if there
// isn't, the command will fail with an appropriate error message.
//----------------------------------------------------------------------
eFlagProcessMustBePaused = (1u << 7)
};
Now each command object contains a "ExecutionContext m_exe_ctx;" member variable that gets initialized prior to running the command. The validity of the target objects in m_exe_ctx are checked to ensure that any target/process/thread/frame/reg context that are required are valid prior to executing the command. Each command object also contains a Mutex::Locker m_api_locker which gets used if eFlagTryTargetAPILock is set. This centralizes a lot of checking code that was previously and inconsistently implemented across many commands.
llvm-svn: 171990
2013-01-10 03:44:40 +08:00
Error error ( m_interpreter . GetDebugger ( ) . SetPropertyValue ( & m_exe_ctx ,
2012-08-23 01:17:09 +08:00
eVarSetOperationClear ,
var_name ,
NULL ) ) ;
if ( error . Fail ( ) )
2012-06-09 05:56:10 +08:00
{
2012-08-23 01:17:09 +08:00
result . AppendError ( error . AsCString ( ) ) ;
2012-06-09 05:56:10 +08:00
result . SetStatus ( eReturnStatusFailed ) ;
2012-08-23 01:17:09 +08:00
return false ;
2012-06-09 05:56:10 +08:00
}
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
return result . Succeeded ( ) ;
}
} ;
2010-09-04 08:03:46 +08:00
2012-06-09 05:56:10 +08:00
//-------------------------------------------------------------------------
// CommandObjectMultiwordSettings
//-------------------------------------------------------------------------
CommandObjectMultiwordSettings : : CommandObjectMultiwordSettings ( CommandInterpreter & interpreter ) :
CommandObjectMultiword ( interpreter ,
" settings " ,
" A set of commands for manipulating internal settable debugger variables. " ,
" settings <command> [<command-options>] " )
{
LoadSubCommand ( " set " , CommandObjectSP ( new CommandObjectSettingsSet ( interpreter ) ) ) ;
LoadSubCommand ( " show " , CommandObjectSP ( new CommandObjectSettingsShow ( interpreter ) ) ) ;
LoadSubCommand ( " list " , CommandObjectSP ( new CommandObjectSettingsList ( interpreter ) ) ) ;
LoadSubCommand ( " remove " , CommandObjectSP ( new CommandObjectSettingsRemove ( interpreter ) ) ) ;
LoadSubCommand ( " replace " , CommandObjectSP ( new CommandObjectSettingsReplace ( interpreter ) ) ) ;
LoadSubCommand ( " insert-before " , CommandObjectSP ( new CommandObjectSettingsInsertBefore ( interpreter ) ) ) ;
LoadSubCommand ( " insert-after " , CommandObjectSP ( new CommandObjectSettingsInsertAfter ( interpreter ) ) ) ;
LoadSubCommand ( " append " , CommandObjectSP ( new CommandObjectSettingsAppend ( interpreter ) ) ) ;
LoadSubCommand ( " clear " , CommandObjectSP ( new CommandObjectSettingsClear ( interpreter ) ) ) ;
}
CommandObjectMultiwordSettings : : ~ CommandObjectMultiwordSettings ( )
{
2010-09-04 08:03:46 +08:00
}