2011-09-10 07:25:26 +08:00
//===-- OptionGroupWatchpoint.cpp -------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
# include "lldb/Interpreter/OptionGroupWatchpoint.h"
// C Includes
// C++ Includes
// Other libraries and framework includes
// Project includes
# include "lldb/lldb-enumerations.h"
# include "lldb/Interpreter/Args.h"
2011-09-10 08:48:33 +08:00
# include "lldb/Utility/Utils.h"
2011-09-10 07:25:26 +08:00
using namespace lldb ;
using namespace lldb_private ;
2011-09-13 07:38:44 +08:00
static OptionEnumValueElement g_watch_type [ ] =
2011-09-10 07:25:26 +08:00
{
{ OptionGroupWatchpoint : : eWatchRead , " read " , " Watch for read " } ,
{ OptionGroupWatchpoint : : eWatchWrite , " write " , " Watch for write " } ,
{ OptionGroupWatchpoint : : eWatchReadWrite , " read_write " , " Watch for read/write " } ,
2014-04-20 08:31:37 +08:00
{ 0 , nullptr , nullptr }
2011-09-10 07:25:26 +08:00
} ;
2011-09-30 09:08:48 +08:00
static OptionEnumValueElement g_watch_size [ ] =
{
{ 1 , " 1 " , " Watch for byte size of 1 " } ,
{ 2 , " 2 " , " Watch for byte size of 2 " } ,
{ 4 , " 4 " , " Watch for byte size of 4 " } ,
{ 8 , " 8 " , " Watch for byte size of 8 " } ,
2014-04-20 08:31:37 +08:00
{ 0 , nullptr , nullptr }
2011-09-30 09:08:48 +08:00
} ;
2011-09-10 07:25:26 +08:00
static OptionDefinition
g_option_table [ ] =
{
2014-07-10 00:31:49 +08:00
{ LLDB_OPT_SET_1 , false , " watch " , ' w ' , OptionParser : : eRequiredArgument , nullptr , g_watch_type , 0 , eArgTypeWatchType , " Specify the type of watching to perform. " } ,
{ LLDB_OPT_SET_1 , false , " xsize " , ' x ' , OptionParser : : eRequiredArgument , nullptr , g_watch_size , 0 , eArgTypeByteSize , " Number of bytes to use to watch a region. " }
2011-09-10 07:25:26 +08:00
} ;
2012-06-05 04:08:23 +08:00
bool
OptionGroupWatchpoint : : IsWatchSizeSupported ( uint32_t watch_size )
{
for ( uint32_t i = 0 ; i < llvm : : array_lengthof ( g_watch_size ) ; + + i )
{
if ( g_watch_size [ i ] . value = = 0 )
break ;
if ( watch_size = = g_watch_size [ i ] . value )
return true ;
}
return false ;
}
2011-09-10 07:25:26 +08:00
OptionGroupWatchpoint : : OptionGroupWatchpoint ( ) :
OptionGroup ( )
{
}
OptionGroupWatchpoint : : ~ OptionGroupWatchpoint ( )
{
}
Error
OptionGroupWatchpoint : : SetOptionValue ( CommandInterpreter & interpreter ,
uint32_t option_idx ,
const char * option_arg )
{
Error error ;
2012-12-04 08:32:51 +08:00
const int short_option = g_option_table [ option_idx ] . short_option ;
2011-09-10 07:25:26 +08:00
switch ( short_option )
{
2011-10-08 02:58:12 +08:00
case ' w ' :
2013-06-19 05:52:48 +08:00
{
WatchType tmp_watch_type ;
tmp_watch_type = ( WatchType ) Args : : StringToOptionEnum ( option_arg , g_option_table [ option_idx ] . enum_values , 0 , error ) ;
2011-10-08 02:58:12 +08:00
if ( error . Success ( ) )
2013-06-19 05:52:48 +08:00
{
watch_type = tmp_watch_type ;
2012-02-09 06:37:48 +08:00
watch_type_specified = true ;
2013-06-19 05:52:48 +08:00
}
2011-09-10 07:25:26 +08:00
break ;
2013-06-19 05:52:48 +08:00
}
2011-10-08 02:58:12 +08:00
case ' x ' :
2013-07-26 07:12:53 +08:00
watch_size = ( uint32_t ) Args : : StringToOptionEnum ( option_arg , g_option_table [ option_idx ] . enum_values , 0 , error ) ;
2011-09-30 09:08:48 +08:00
break ;
2011-10-08 02:58:12 +08:00
2011-09-10 07:25:26 +08:00
default :
2011-10-26 08:56:27 +08:00
error . SetErrorStringWithFormat ( " unrecognized short option '%c' " , short_option ) ;
2011-09-10 07:25:26 +08:00
break ;
}
return error ;
}
void
OptionGroupWatchpoint : : OptionParsingStarting ( CommandInterpreter & interpreter )
{
2012-02-09 06:37:48 +08:00
watch_type_specified = false ;
2011-10-08 02:58:12 +08:00
watch_type = eWatchInvalid ;
watch_size = 0 ;
2011-09-10 07:25:26 +08:00
}
const OptionDefinition *
OptionGroupWatchpoint : : GetDefinitions ( )
{
return g_option_table ;
}
uint32_t
OptionGroupWatchpoint : : GetNumDefinitions ( )
{
2012-05-16 07:21:36 +08:00
return llvm : : array_lengthof ( g_option_table ) ;
2011-09-10 07:25:26 +08:00
}