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/Interpreter/Args.h" 17 #include "lldb/Utility/Utils.h" 18 #include "lldb/lldb-enumerations.h" 19 20 using namespace lldb; 21 using namespace lldb_private; 22 23 static OptionEnumValueElement g_watch_type[] = { 24 {OptionGroupWatchpoint::eWatchRead, "read", "Watch for read"}, 25 {OptionGroupWatchpoint::eWatchWrite, "write", "Watch for write"}, 26 {OptionGroupWatchpoint::eWatchReadWrite, "read_write", 27 "Watch for read/write"}, 28 {0, nullptr, nullptr}}; 29 30 static OptionEnumValueElement g_watch_size[] = { 31 {1, "1", "Watch for byte size of 1"}, 32 {2, "2", "Watch for byte size of 2"}, 33 {4, "4", "Watch for byte size of 4"}, 34 {8, "8", "Watch for byte size of 8"}, 35 {0, nullptr, nullptr}}; 36 37 static OptionDefinition g_option_table[] = { 38 {LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument, 39 nullptr, g_watch_type, 0, eArgTypeWatchType, 40 "Specify the type of watching to perform."}, 41 {LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument, 42 nullptr, g_watch_size, 0, eArgTypeByteSize, 43 "Number of bytes to use to watch a region."}}; 44 45 bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) { 46 for (uint32_t i = 0; i < llvm::array_lengthof(g_watch_size); ++i) { 47 if (g_watch_size[i].value == 0) 48 break; 49 if (watch_size == g_watch_size[i].value) 50 return true; 51 } 52 return false; 53 } 54 55 OptionGroupWatchpoint::OptionGroupWatchpoint() : OptionGroup() {} 56 57 OptionGroupWatchpoint::~OptionGroupWatchpoint() {} 58 59 Error OptionGroupWatchpoint::SetOptionValue( 60 uint32_t option_idx, llvm::StringRef option_arg, 61 ExecutionContext *execution_context) { 62 Error error; 63 const int short_option = g_option_table[option_idx].short_option; 64 switch (short_option) { 65 case 'w': { 66 WatchType tmp_watch_type; 67 tmp_watch_type = (WatchType)Args::StringToOptionEnum( 68 option_arg, g_option_table[option_idx].enum_values, 0, error); 69 if (error.Success()) { 70 watch_type = tmp_watch_type; 71 watch_type_specified = true; 72 } 73 break; 74 } 75 case 's': 76 watch_size = (uint32_t)Args::StringToOptionEnum( 77 option_arg, g_option_table[option_idx].enum_values, 0, error); 78 break; 79 80 default: 81 error.SetErrorStringWithFormat("unrecognized short option '%c'", 82 short_option); 83 break; 84 } 85 86 return error; 87 } 88 89 void OptionGroupWatchpoint::OptionParsingStarting( 90 ExecutionContext *execution_context) { 91 watch_type_specified = false; 92 watch_type = eWatchInvalid; 93 watch_size = 0; 94 } 95 96 llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() { 97 return llvm::makeArrayRef(g_option_table); 98 } 99