1 //===-- OptionGroupWatchpoint.cpp -----------------------------------------===//
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/Target/Language.h"
14 #include "lldb/lldb-enumerations.h"
17 using namespace lldb_private
;
19 static constexpr OptionEnumValueElement g_watch_type
[] = {
21 OptionGroupWatchpoint::eWatchRead
,
26 OptionGroupWatchpoint::eWatchWrite
,
31 OptionGroupWatchpoint::eWatchModify
,
33 "Watch for modifications",
36 OptionGroupWatchpoint::eWatchReadWrite
,
38 "Watch for read/write",
42 static constexpr OptionEnumValueElement g_watch_size
[] = {
46 "Watch for byte size of 1",
51 "Watch for byte size of 2",
56 "Watch for byte size of 4",
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."},
76 OptionParser::eRequiredArgument
,
81 "Language of expression to run"}};
83 bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size
) {
84 for (const auto& size
: g_watch_size
) {
87 if (watch_size
== size
.value
)
94 OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx
,
95 llvm::StringRef option_arg
,
96 ExecutionContext
*execution_context
) {
98 const int short_option
= g_option_table
[option_idx
].short_option
;
99 switch (short_option
) {
101 language_type
= Language::GetLanguageTypeFromString(option_arg
);
102 if (language_type
== eLanguageTypeUnknown
) {
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());
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;
123 watch_size
= (uint32_t)OptionArgParser::ToOptionEnum(
124 option_arg
, g_option_table
[option_idx
].enum_values
, 0, error
);
128 llvm_unreachable("Unimplemented option");
134 void OptionGroupWatchpoint::OptionParsingStarting(
135 ExecutionContext
*execution_context
) {
136 watch_type_specified
= false;
137 watch_type
= eWatchInvalid
;
139 language_type
= eLanguageTypeUnknown
;
142 llvm::ArrayRef
<OptionDefinition
> OptionGroupWatchpoint::GetDefinitions() {
143 return llvm::ArrayRef(g_option_table
);