2011-07-07 12:38:25 +08:00
//===-- OptionGroupVariable.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"
2011-07-07 12:38:25 +08:00
# include "lldb/Interpreter/OptionGroupVariable.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
2012-12-12 06:42:19 +08:00
# include "lldb/Core/DataVisualization.h"
# include "lldb/Core/Error.h"
2011-07-07 12:38:25 +08:00
# include "lldb/Target/Target.h"
# include "lldb/Interpreter/CommandInterpreter.h"
2011-09-10 09:19:01 +08:00
# include "lldb/Utility/Utils.h"
2011-07-07 12:38:25 +08:00
using namespace lldb ;
using namespace lldb_private ;
2011-07-12 08:18:11 +08:00
// if you add any options here, remember to update the counters in OptionGroupVariable::GetNumDefinitions()
2011-07-07 12:38:25 +08:00
static OptionDefinition
g_option_table [ ] =
{
2012-12-04 08:32:51 +08:00
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " no-args " , ' a ' , no_argument , NULL , 0 , eArgTypeNone , " Omit function arguments. " } ,
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " no-locals " , ' l ' , no_argument , NULL , 0 , eArgTypeNone , " Omit local variables. " } ,
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " show-globals " , ' g ' , no_argument , NULL , 0 , eArgTypeNone , " Show the current frame source file global and static variables. " } ,
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " show-declaration " , ' c ' , no_argument , NULL , 0 , eArgTypeNone , " Show variable declaration information (source file and line where the variable was declared). " } ,
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " regex " , ' r ' , no_argument , NULL , 0 , eArgTypeRegularExpression , " The <variable-name> argument for name lookups are regular expressions. " } ,
{ LLDB_OPT_SET_1 | LLDB_OPT_SET_2 , false , " scope " , ' s ' , no_argument , NULL , 0 , eArgTypeNone , " Show variable scope (argument, local, global, static). " } ,
{ LLDB_OPT_SET_1 , false , " summary " , ' y ' , required_argument , NULL , 0 , eArgTypeName , " Specify the summary that the variable output should use. " } ,
{ LLDB_OPT_SET_2 , false , " summary-string " , ' z ' , required_argument , NULL , 0 , eArgTypeName , " Specify a summary string to use to format the variable output. " } ,
2011-07-07 12:38:25 +08:00
} ;
2013-01-18 04:24:11 +08:00
static Error
ValidateNamedSummary ( const char * str , void * )
{
if ( ! str | | ! str [ 0 ] )
return Error ( " must specify a valid named summary " ) ;
TypeSummaryImplSP summary_sp ;
if ( DataVisualization : : NamedSummaryFormats : : GetSummaryFormat ( ConstString ( str ) , summary_sp ) = = false )
return Error ( " must specify a valid named summary " ) ;
return Error ( ) ;
}
static Error
ValidateSummaryString ( const char * str , void * )
{
if ( ! str | | ! str [ 0 ] )
return Error ( " must specify a non-empty summary string " ) ;
return Error ( ) ;
}
2011-07-07 12:38:25 +08:00
OptionGroupVariable : : OptionGroupVariable ( bool show_frame_options ) :
OptionGroup ( ) ,
2012-12-12 06:42:19 +08:00
include_frame_options ( show_frame_options ) ,
2013-01-18 04:24:11 +08:00
summary ( ValidateNamedSummary ) ,
summary_string ( ValidateSummaryString )
2011-07-07 12:38:25 +08:00
{
}
OptionGroupVariable : : ~ OptionGroupVariable ( )
{
}
Error
OptionGroupVariable : : SetOptionValue ( CommandInterpreter & interpreter ,
uint32_t option_idx ,
const char * option_arg )
{
Error error ;
if ( ! include_frame_options )
option_idx + = 3 ;
2012-12-04 08:32:51 +08:00
const int short_option = g_option_table [ option_idx ] . short_option ;
2011-07-07 12:38:25 +08:00
switch ( short_option )
{
case ' r ' : use_regex = true ; break ;
case ' a ' : show_args = false ; break ;
case ' l ' : show_locals = false ; break ;
case ' g ' : show_globals = true ; break ;
case ' c ' : show_decl = true ; break ;
case ' s ' :
show_scope = true ;
break ;
2011-07-12 08:18:11 +08:00
case ' y ' :
2012-12-12 06:42:19 +08:00
error = summary . SetCurrentValue ( option_arg ) ;
2012-08-10 06:02:51 +08:00
break ;
case ' z ' :
2012-12-12 06:42:19 +08:00
error = summary_string . SetCurrentValue ( option_arg ) ;
2011-07-12 08:18:11 +08:00
break ;
2011-07-07 12:38:25 +08:00
default :
2011-10-26 08:56:27 +08:00
error . SetErrorStringWithFormat ( " unrecognized short option '%c' " , short_option ) ;
2011-07-07 12:38:25 +08:00
break ;
}
return error ;
}
void
OptionGroupVariable : : OptionParsingStarting ( CommandInterpreter & interpreter )
{
show_args = true ; // Frame option only
show_locals = true ; // Frame option only
show_globals = false ; // Frame option only
show_decl = false ;
use_regex = false ;
show_scope = false ;
2012-08-10 06:02:51 +08:00
summary . Clear ( ) ;
summary_string . Clear ( ) ;
2011-07-07 12:38:25 +08:00
}
2011-09-10 09:19:01 +08:00
# define NUM_FRAME_OPTS 3
2011-07-07 12:38:25 +08:00
const OptionDefinition *
OptionGroupVariable : : GetDefinitions ( )
{
// Show the "--no-args", "--no-locals" and "--show-globals"
// options if we are showing frame specific options
if ( include_frame_options )
return g_option_table ;
// Skip the "--no-args", "--no-locals" and "--show-globals"
// options if we are not showing frame specific options (globals only)
2011-09-10 09:19:01 +08:00
return & g_option_table [ NUM_FRAME_OPTS ] ;
2011-07-07 12:38:25 +08:00
}
uint32_t
OptionGroupVariable : : GetNumDefinitions ( )
{
2011-09-10 09:19:01 +08:00
// Count the "--no-args", "--no-locals" and "--show-globals"
// options if we are showing frame specific options.
2011-07-07 12:38:25 +08:00
if ( include_frame_options )
2012-05-16 07:21:36 +08:00
return llvm : : array_lengthof ( g_option_table ) ;
2011-07-07 12:38:25 +08:00
else
2012-05-16 07:21:36 +08:00
return llvm : : array_lengthof ( g_option_table ) - NUM_FRAME_OPTS ;
2011-07-07 12:38:25 +08:00
}