1 //===-- OptionGroupWatchpoint.cpp -------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionGroupWatchpoint.h"
11 #include "lldb/Host/OptionParser.h"
12 #include "lldb/Interpreter/OptionArgParser.h"
13 #include "lldb/lldb-enumerations.h"
16 using namespace lldb_private;
18 static constexpr OptionEnumValueElement g_watch_type[] = {
19 {OptionGroupWatchpoint::eWatchRead, "read", "Watch for read"},
20 {OptionGroupWatchpoint::eWatchWrite, "write", "Watch for write"},
21 {OptionGroupWatchpoint::eWatchReadWrite, "read_write",
22 "Watch for read/write"} };
24 static constexpr OptionEnumValueElement g_watch_size[] = {
25 {1, "1", "Watch for byte size of 1"},
26 {2, "2", "Watch for byte size of 2"},
27 {4, "4", "Watch for byte size of 4"},
28 {8, "8", "Watch for byte size of 8"} };
30 static constexpr OptionDefinition g_option_table[] = {
31 {LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument,
32 nullptr, OptionEnumValues(g_watch_type), 0, eArgTypeWatchType,
33 "Specify the type of watching to perform."},
34 {LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument,
35 nullptr, OptionEnumValues(g_watch_size), 0, eArgTypeByteSize,
36 "Number of bytes to use to watch a region."}};
38 bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) {
39 for (const auto& size : g_watch_size) {
42 if (watch_size == size.value)
48 OptionGroupWatchpoint::OptionGroupWatchpoint() : OptionGroup() {}
50 OptionGroupWatchpoint::~OptionGroupWatchpoint() {}
53 OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx,
54 llvm::StringRef option_arg,
55 ExecutionContext *execution_context) {
57 const int short_option = g_option_table[option_idx].short_option;
58 switch (short_option) {
60 WatchType tmp_watch_type;
61 tmp_watch_type = (WatchType)OptionArgParser::ToOptionEnum(
62 option_arg, g_option_table[option_idx].enum_values, 0, error);
63 if (error.Success()) {
64 watch_type = tmp_watch_type;
65 watch_type_specified = true;
70 watch_size = (uint32_t)OptionArgParser::ToOptionEnum(
71 option_arg, g_option_table[option_idx].enum_values, 0, error);
75 error.SetErrorStringWithFormat("unrecognized short option '%c'",
83 void OptionGroupWatchpoint::OptionParsingStarting(
84 ExecutionContext *execution_context) {
85 watch_type_specified = false;
86 watch_type = eWatchInvalid;
90 llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
91 return llvm::makeArrayRef(g_option_table);