OptionGroupWatchpoint.cpp revision 34bbf85e60949752de9c8272a70d59383e523cc5
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 31// if you add any options here, remember to update the counters in OptionGroupWatchpoint::GetNumDefinitions() 32static OptionDefinition 33g_option_table[] = 34{ 35 { LLDB_OPT_SET_1, false, "watch", 'w', required_argument, g_watch_type, 0, eArgTypeWatchType, "Determine how to watch a memory location (read, write, or read/write)."} 36}; 37 38 39OptionGroupWatchpoint::OptionGroupWatchpoint () : 40 OptionGroup() 41{ 42} 43 44OptionGroupWatchpoint::~OptionGroupWatchpoint () 45{ 46} 47 48Error 49OptionGroupWatchpoint::SetOptionValue (CommandInterpreter &interpreter, 50 uint32_t option_idx, 51 const char *option_arg) 52{ 53 Error error; 54 char short_option = (char) g_option_table[option_idx].short_option; 55 switch (short_option) 56 { 57 case 'w': { 58 OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; 59 watch_type = (WatchType) Args::StringToOptionEnum(option_arg, enum_values, 0, &watch_variable); 60 if (!watch_variable) 61 error.SetErrorStringWithFormat("Invalid option arg for '-w': '%s'.\n", option_arg); 62 break; 63 } 64 default: 65 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); 66 break; 67 } 68 69 return error; 70} 71 72void 73OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter) 74{ 75 watch_variable = false; 76 watch_type = eWatchInvalid; 77} 78 79 80const OptionDefinition* 81OptionGroupWatchpoint::GetDefinitions () 82{ 83 return g_option_table; 84} 85 86uint32_t 87OptionGroupWatchpoint::GetNumDefinitions () 88{ 89 return arraysize(g_option_table); 90} 91