2011-09-09 23:25:26 +00: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 00:48:33 +00:00
# include "lldb/Utility/Utils.h"
2011-09-09 23:25:26 +00:00
using namespace lldb ;
using namespace lldb_private ;
2011-09-12 23:38:44 +00:00
static OptionEnumValueElement g_watch_type [ ] =
2011-09-09 23:25:26 +00:00
{
{ OptionGroupWatchpoint : : eWatchRead , " read " , " Watch for read " } ,
{ OptionGroupWatchpoint : : eWatchWrite , " write " , " Watch for write " } ,
{ OptionGroupWatchpoint : : eWatchReadWrite , " read_write " , " Watch for read/write " } ,
2014-04-20 00:31:37 +00:00
{ 0 , nullptr , nullptr }
2011-09-09 23:25:26 +00:00
} ;
2011-09-30 01:08:48 +00: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 00:31:37 +00:00
{ 0 , nullptr , nullptr }
2011-09-30 01:08:48 +00:00
} ;
2011-09-09 23:25:26 +00:00
static OptionDefinition
g_option_table [ ] =
{
2014-07-09 16:31:49 +00: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-09 23:25:26 +00:00
} ;
2012-06-04 20:08:23 +00: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-09 23:25:26 +00:00
OptionGroupWatchpoint : : OptionGroupWatchpoint ( ) :
OptionGroup ( )
{
}
OptionGroupWatchpoint : : ~ OptionGroupWatchpoint ( )
{
}
Error
OptionGroupWatchpoint : : SetOptionValue ( CommandInterpreter & interpreter ,
uint32_t option_idx ,
const char * option_arg )
{
Error error ;
2012-12-04 00:32:51 +00:00
const int short_option = g_option_table [ option_idx ] . short_option ;
2011-09-09 23:25:26 +00:00
switch ( short_option )
{
2011-10-07 18:58:12 +00:00
case ' w ' :
2013-06-18 21:52:48 +00:00
{
WatchType tmp_watch_type ;
tmp_watch_type = ( WatchType ) Args : : StringToOptionEnum ( option_arg , g_option_table [ option_idx ] . enum_values , 0 , error ) ;
2011-10-07 18:58:12 +00:00
if ( error . Success ( ) )
2013-06-18 21:52:48 +00:00
{
watch_type = tmp_watch_type ;
2012-02-08 22:37:48 +00:00
watch_type_specified = true ;
2013-06-18 21:52:48 +00:00
}
2011-09-09 23:25:26 +00:00
break ;
2013-06-18 21:52:48 +00:00
}
2011-10-07 18:58:12 +00:00
case ' x ' :
2013-07-25 23:12:53 +00:00
watch_size = ( uint32_t ) Args : : StringToOptionEnum ( option_arg , g_option_table [ option_idx ] . enum_values , 0 , error ) ;
2011-09-30 01:08:48 +00:00
break ;
2011-10-07 18:58:12 +00:00
2011-09-09 23:25:26 +00:00
default :
2011-10-26 00:56:27 +00:00
error . SetErrorStringWithFormat ( " unrecognized short option '%c' " , short_option ) ;
2011-09-09 23:25:26 +00:00
break ;
}
return error ;
}
void
OptionGroupWatchpoint : : OptionParsingStarting ( CommandInterpreter & interpreter )
{
2012-02-08 22:37:48 +00:00
watch_type_specified = false ;
2011-10-07 18:58:12 +00:00
watch_type = eWatchInvalid ;
watch_size = 0 ;
2011-09-09 23:25:26 +00:00
}
const OptionDefinition *
OptionGroupWatchpoint : : GetDefinitions ( )
{
return g_option_table ;
}
uint32_t
OptionGroupWatchpoint : : GetNumDefinitions ( )
{
2012-05-15 23:21:36 +00:00
return llvm : : array_lengthof ( g_option_table ) ;
2011-09-09 23:25:26 +00:00
}