]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionGroupWatchpoint.cpp
Merge lldb trunk r366426, resolve conflicts, and update FREEBSD-Xlist.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / OptionGroupWatchpoint.cpp
1 //===-- OptionGroupWatchpoint.cpp -------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "lldb/Interpreter/OptionGroupWatchpoint.h"
10
11 #include "lldb/Host/OptionParser.h"
12 #include "lldb/Interpreter/OptionArgParser.h"
13 #include "lldb/lldb-enumerations.h"
14
15 using namespace lldb;
16 using namespace lldb_private;
17
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"} };
23
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"} };
29
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."}};
37
38 bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) {
39   for (const auto& size : g_watch_size) {
40     if (0  == size.value)
41       break;
42     if (watch_size == size.value)
43       return true;
44   }
45   return false;
46 }
47
48 OptionGroupWatchpoint::OptionGroupWatchpoint() : OptionGroup() {}
49
50 OptionGroupWatchpoint::~OptionGroupWatchpoint() {}
51
52 Status
53 OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx,
54                                       llvm::StringRef option_arg,
55                                       ExecutionContext *execution_context) {
56   Status error;
57   const int short_option = g_option_table[option_idx].short_option;
58   switch (short_option) {
59   case 'w': {
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;
66     }
67     break;
68   }
69   case 's':
70     watch_size = (uint32_t)OptionArgParser::ToOptionEnum(
71         option_arg, g_option_table[option_idx].enum_values, 0, error);
72     break;
73
74   default:
75     error.SetErrorStringWithFormat("unrecognized short option '%c'",
76                                    short_option);
77     break;
78   }
79
80   return error;
81 }
82
83 void OptionGroupWatchpoint::OptionParsingStarting(
84     ExecutionContext *execution_context) {
85   watch_type_specified = false;
86   watch_type = eWatchInvalid;
87   watch_size = 0;
88 }
89
90 llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
91   return llvm::makeArrayRef(g_option_table);
92 }