OptionGroupWatchpoint.cpp revision 1e0e73a403ffbbeafa7a98e958909b56be929cf0
1//===-- OptionGroupWatchpoint.cpp -------------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#include "lldb/Interpreter/OptionGroupWatchpoint.h" 11 12// C Includes 13// C++ Includes 14// Other libraries and framework includes 15// Project includes 16#include "lldb/lldb-enumerations.h" 17#include "lldb/Interpreter/Args.h" 18#include "lldb/Utility/Utils.h" 19 20using namespace lldb; 21using namespace lldb_private; 22 23static OptionEnumValueElement g_watch_type[] = 24{ 25 { OptionGroupWatchpoint::eWatchRead, "read", "Watch for read"}, 26 { OptionGroupWatchpoint::eWatchWrite, "write", "Watch for write"}, 27 { OptionGroupWatchpoint::eWatchReadWrite, "read_write", "Watch for read/write"}, 28 { 0, NULL, NULL } 29}; 30 31static OptionEnumValueElement g_watch_size[] = 32{ 33 { 1, "1", "Watch for byte size of 1"}, 34 { 2, "2", "Watch for byte size of 2"}, 35 { 4, "4", "Watch for byte size of 4"}, 36 { 8, "8", "Watch for byte size of 8"}, 37 { 0, NULL, NULL } 38}; 39 40static OptionDefinition 41g_option_table[] = 42{ 43 { LLDB_OPT_SET_1, false, "watch", 'w', required_argument, g_watch_type, 0, eArgTypeWatchType, "Specify the type of watching to perform."}, 44 { LLDB_OPT_SET_1, false, "xsize", 'x', required_argument, g_watch_size, 0, eArgTypeByteSize, "Number of bytes to use to watch a region."} 45}; 46 47 48bool 49OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) 50{ 51 for (uint32_t i = 0; i < llvm::array_lengthof(g_watch_size); ++i) 52 { 53 if (g_watch_size[i].value == 0) 54 break; 55 if (watch_size == g_watch_size[i].value) 56 return true; 57 } 58 return false; 59} 60 61OptionGroupWatchpoint::OptionGroupWatchpoint () : 62 OptionGroup() 63{ 64} 65 66OptionGroupWatchpoint::~OptionGroupWatchpoint () 67{ 68} 69 70Error 71OptionGroupWatchpoint::SetOptionValue (CommandInterpreter &interpreter, 72 uint32_t option_idx, 73 const char *option_arg) 74{ 75 Error error; 76 char short_option = (char) g_option_table[option_idx].short_option; 77 switch (short_option) 78 { 79 case 'w': 80 watch_type = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error); 81 if (error.Success()) 82 watch_type_specified = true; 83 break; 84 85 case 'x': 86 watch_size = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error); 87 break; 88 89 default: 90 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); 91 break; 92 } 93 94 return error; 95} 96 97void 98OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter) 99{ 100 watch_type_specified = false; 101 watch_type = eWatchInvalid; 102 watch_size = 0; 103} 104 105 106const OptionDefinition* 107OptionGroupWatchpoint::GetDefinitions () 108{ 109 return g_option_table; 110} 111 112uint32_t 113OptionGroupWatchpoint::GetNumDefinitions () 114{ 115 return llvm::array_lengthof(g_option_table); 116} 117