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/Host/OptionParser.h" 17 #include "lldb/Interpreter/Args.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 Status 60 OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx, 61 llvm::StringRef option_arg, 62 ExecutionContext *execution_context) { 63 Status error; 64 const int short_option = g_option_table[option_idx].short_option; 65 switch (short_option) { 66 case 'w': { 67 WatchType tmp_watch_type; 68 tmp_watch_type = (WatchType)Args::StringToOptionEnum( 69 option_arg, g_option_table[option_idx].enum_values, 0, error); 70 if (error.Success()) { 71 watch_type = tmp_watch_type; 72 watch_type_specified = true; 73 } 74 break; 75 } 76 case 's': 77 watch_size = (uint32_t)Args::StringToOptionEnum( 78 option_arg, g_option_table[option_idx].enum_values, 0, error); 79 break; 80 81 default: 82 error.SetErrorStringWithFormat("unrecognized short option '%c'", 83 short_option); 84 break; 85 } 86 87 return error; 88 } 89 90 void OptionGroupWatchpoint::OptionParsingStarting( 91 ExecutionContext *execution_context) { 92 watch_type_specified = false; 93 watch_type = eWatchInvalid; 94 watch_size = 0; 95 } 96 97 llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() { 98 return llvm::makeArrayRef(g_option_table); 99 } 100