LLDB  mainline
OptionGroupWatchpoint.cpp
Go to the documentation of this file.
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 
10 
11 #include "lldb/Host/OptionParser.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 
51 
52 Status
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':
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 
84  ExecutionContext *execution_context) {
85  watch_type_specified = false;
87  watch_size = 0;
88 }
89 
90 llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
91  return llvm::makeArrayRef(g_option_table);
92 }
static constexpr OptionEnumValueElement g_watch_size[]
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
static constexpr OptionDefinition g_option_table[]
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
void OptionParsingStarting(ExecutionContext *execution_context) override
static constexpr OptionEnumValueElement g_watch_type[]
static int64_t ToOptionEnum(llvm::StringRef s, const OptionEnumValues &enum_values, int32_t fail_value, Status &error)
bool Success() const
Test for success condition.
Definition: Status.cpp:287
llvm::ArrayRef< OptionDefinition > GetDefinitions() override
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_value, ExecutionContext *execution_context) override
Definition: SBAddress.h:15
int SetErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Set the current error string to a formatted error string.
Definition: Status.cpp:255
#define LLDB_OPT_SET_1
Definition: lldb-defines.h:111
An error handling class.
Definition: Status.h:44