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"
12 #include "lldb/Host/OptionParser.h"
13 #include "lldb/Interpreter/OptionArgParser.h"
14 #include "lldb/lldb-enumerations.h"
17 using namespace lldb_private;
19 static constexpr OptionEnumValueElement g_watch_type[] = {
20 {OptionGroupWatchpoint::eWatchRead, "read", "Watch for read"},
21 {OptionGroupWatchpoint::eWatchWrite, "write", "Watch for write"},
22 {OptionGroupWatchpoint::eWatchReadWrite, "read_write",
23 "Watch for read/write"} };
25 static constexpr OptionEnumValueElement g_watch_size[] = {
26 {1, "1", "Watch for byte size of 1"},
27 {2, "2", "Watch for byte size of 2"},
28 {4, "4", "Watch for byte size of 4"},
29 {8, "8", "Watch for byte size of 8"} };
31 static constexpr OptionDefinition g_option_table[] = {
32 {LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument,
33 nullptr, OptionEnumValues(g_watch_type), 0, eArgTypeWatchType,
34 "Specify the type of watching to perform."},
35 {LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument,
36 nullptr, OptionEnumValues(g_watch_size), 0, eArgTypeByteSize,
37 "Number of bytes to use to watch a region."}};
39 bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) {
40 for (const auto& size : g_watch_size) {
43 if (watch_size == size.value)
49 OptionGroupWatchpoint::OptionGroupWatchpoint() : OptionGroup() {}
51 OptionGroupWatchpoint::~OptionGroupWatchpoint() {}
54 OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx,
55 llvm::StringRef option_arg,
56 ExecutionContext *execution_context) {
58 const int short_option = g_option_table[option_idx].short_option;
59 switch (short_option) {
61 WatchType tmp_watch_type;
62 tmp_watch_type = (WatchType)OptionArgParser::ToOptionEnum(
63 option_arg, g_option_table[option_idx].enum_values, 0, error);
64 if (error.Success()) {
65 watch_type = tmp_watch_type;
66 watch_type_specified = true;
71 watch_size = (uint32_t)OptionArgParser::ToOptionEnum(
72 option_arg, g_option_table[option_idx].enum_values, 0, error);
76 error.SetErrorStringWithFormat("unrecognized short option '%c'",
84 void OptionGroupWatchpoint::OptionParsingStarting(
85 ExecutionContext *execution_context) {
86 watch_type_specified = false;
87 watch_type = eWatchInvalid;
91 llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
92 return llvm::makeArrayRef(g_option_table);