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 OptionDefinition g_option_table
[] = {
43 {LLDB_OPT_SET_1
, false, "watch", 'w', OptionParser::eRequiredArgument
,
44 nullptr, OptionEnumValues(g_watch_type
), 0, eArgTypeWatchType
,
45 "Specify the type of watching to perform."},
46 {LLDB_OPT_SET_1
, false, "size", 's', OptionParser::eRequiredArgument
,
47 nullptr, {}, 0, eArgTypeByteSize
,
48 "Number of bytes to use to watch a region."},
53 OptionParser::eRequiredArgument
,
58 "Language of expression to run"}};
61 OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx
,
62 llvm::StringRef option_arg
,
63 ExecutionContext
*execution_context
) {
65 const int short_option
= g_option_table
[option_idx
].short_option
;
66 switch (short_option
) {
68 language_type
= Language::GetLanguageTypeFromString(option_arg
);
69 if (language_type
== eLanguageTypeUnknown
) {
71 sstr
.Printf("Unknown language type: '%s' for expression. List of "
72 "supported languages:\n",
73 option_arg
.str().c_str());
74 Language::PrintSupportedLanguagesForExpressions(sstr
, " ", "\n");
75 error
= Status(sstr
.GetString().str());
80 WatchType tmp_watch_type
;
81 tmp_watch_type
= (WatchType
)OptionArgParser::ToOptionEnum(
82 option_arg
, g_option_table
[option_idx
].enum_values
, 0, error
);
83 if (error
.Success()) {
84 watch_type
= tmp_watch_type
;
85 watch_type_specified
= true;
90 error
= watch_size
.SetValueFromString(option_arg
);
91 if (watch_size
.GetCurrentValue() == 0)
92 error
= Status::FromErrorStringWithFormat(
93 "invalid --size option value '%s'", option_arg
.str().c_str());
97 llvm_unreachable("Unimplemented option");
103 void OptionGroupWatchpoint::OptionParsingStarting(
104 ExecutionContext
*execution_context
) {
105 watch_type_specified
= false;
106 watch_type
= eWatchInvalid
;
108 language_type
= eLanguageTypeUnknown
;
111 llvm::ArrayRef
<OptionDefinition
> OptionGroupWatchpoint::GetDefinitions() {
112 return llvm::ArrayRef(g_option_table
);