Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / source / Interpreter / OptionGroupWatchpoint.cpp
blobc3708e7a1e80fd2c16491a9e966539f40136219b
1 //===-- OptionGroupWatchpoint.cpp -----------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "lldb/Interpreter/OptionGroupWatchpoint.h"
11 #include "lldb/Host/OptionParser.h"
12 #include "lldb/Interpreter/OptionArgParser.h"
13 #include "lldb/Target/Language.h"
14 #include "lldb/lldb-enumerations.h"
16 using namespace lldb;
17 using namespace lldb_private;
19 static constexpr OptionEnumValueElement g_watch_type[] = {
21 OptionGroupWatchpoint::eWatchRead,
22 "read",
23 "Watch for read",
26 OptionGroupWatchpoint::eWatchWrite,
27 "write",
28 "Watch for write",
31 OptionGroupWatchpoint::eWatchModify,
32 "modify",
33 "Watch for modifications",
36 OptionGroupWatchpoint::eWatchReadWrite,
37 "read_write",
38 "Watch for read/write",
42 static constexpr OptionEnumValueElement g_watch_size[] = {
45 "1",
46 "Watch for byte size of 1",
50 "2",
51 "Watch for byte size of 2",
55 "4",
56 "Watch for byte size of 4",
60 "8",
61 "Watch for byte size of 8",
65 static constexpr OptionDefinition g_option_table[] = {
66 {LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument,
67 nullptr, OptionEnumValues(g_watch_type), 0, eArgTypeWatchType,
68 "Specify the type of watching to perform."},
69 {LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument,
70 nullptr, OptionEnumValues(g_watch_size), 0, eArgTypeByteSize,
71 "Number of bytes to use to watch a region."},
72 {LLDB_OPT_SET_2,
73 false,
74 "language",
75 'l',
76 OptionParser::eRequiredArgument,
77 nullptr,
78 {},
80 eArgTypeLanguage,
81 "Language of expression to run"}};
83 bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) {
84 for (const auto& size : g_watch_size) {
85 if (0 == size.value)
86 break;
87 if (watch_size == size.value)
88 return true;
90 return false;
93 Status
94 OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx,
95 llvm::StringRef option_arg,
96 ExecutionContext *execution_context) {
97 Status error;
98 const int short_option = g_option_table[option_idx].short_option;
99 switch (short_option) {
100 case 'l': {
101 language_type = Language::GetLanguageTypeFromString(option_arg);
102 if (language_type == eLanguageTypeUnknown) {
103 StreamString sstr;
104 sstr.Printf("Unknown language type: '%s' for expression. List of "
105 "supported languages:\n",
106 option_arg.str().c_str());
107 Language::PrintSupportedLanguagesForExpressions(sstr, " ", "\n");
108 error.SetErrorString(sstr.GetString());
110 break;
112 case 'w': {
113 WatchType tmp_watch_type;
114 tmp_watch_type = (WatchType)OptionArgParser::ToOptionEnum(
115 option_arg, g_option_table[option_idx].enum_values, 0, error);
116 if (error.Success()) {
117 watch_type = tmp_watch_type;
118 watch_type_specified = true;
120 break;
122 case 's':
123 watch_size = (uint32_t)OptionArgParser::ToOptionEnum(
124 option_arg, g_option_table[option_idx].enum_values, 0, error);
125 break;
127 default:
128 llvm_unreachable("Unimplemented option");
131 return error;
134 void OptionGroupWatchpoint::OptionParsingStarting(
135 ExecutionContext *execution_context) {
136 watch_type_specified = false;
137 watch_type = eWatchInvalid;
138 watch_size = 0;
139 language_type = eLanguageTypeUnknown;
142 llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
143 return llvm::ArrayRef(g_option_table);