1 //===-- OptionGroupWatchpoint.cpp -------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/Interpreter/OptionGroupWatchpoint.h"
14 // Other libraries and framework includes
16 #include "lldb/Host/OptionParser.h"
17 #include "lldb/Interpreter/Args.h"
18 #include "lldb/lldb-enumerations.h"
21 using namespace lldb_private;
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}};
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}};
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."}};
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)
49 if (watch_size == g_watch_size[i].value)
55 OptionGroupWatchpoint::OptionGroupWatchpoint() : OptionGroup() {}
57 OptionGroupWatchpoint::~OptionGroupWatchpoint() {}
60 OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx,
61 llvm::StringRef option_arg,
62 ExecutionContext *execution_context) {
64 const int short_option = g_option_table[option_idx].short_option;
65 switch (short_option) {
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;
77 watch_size = (uint32_t)Args::StringToOptionEnum(
78 option_arg, g_option_table[option_idx].enum_values, 0, error);
82 error.SetErrorStringWithFormat("unrecognized short option '%c'",
90 void OptionGroupWatchpoint::OptionParsingStarting(
91 ExecutionContext *execution_context) {
92 watch_type_specified = false;
93 watch_type = eWatchInvalid;
97 llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
98 return llvm::makeArrayRef(g_option_table);