]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Interpreter/OptionGroupWatchpoint.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Interpreter / OptionGroupWatchpoint.cpp
1 //===-- OptionGroupWatchpoint.cpp -------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "lldb/Interpreter/OptionGroupWatchpoint.h"
11
12 #include "lldb/Host/OptionParser.h"
13 #include "lldb/Interpreter/OptionArgParser.h"
14 #include "lldb/lldb-enumerations.h"
15
16 using namespace lldb;
17 using namespace lldb_private;
18
19 static constexpr OptionEnumValueElement g_watch_type[] = {
20     {OptionGroupWatchpoint::eWatchRead, "read", "Watch for read"},
21     {OptionGroupWatchpoint::eWatchWrite, "write", "Watch for write"},
22     {OptionGroupWatchpoint::eWatchReadWrite, "read_write",
23      "Watch for read/write"} };
24
25 static constexpr OptionEnumValueElement g_watch_size[] = {
26     {1, "1", "Watch for byte size of 1"},
27     {2, "2", "Watch for byte size of 2"},
28     {4, "4", "Watch for byte size of 4"},
29     {8, "8", "Watch for byte size of 8"} };
30
31 static constexpr OptionDefinition g_option_table[] = {
32     {LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument,
33      nullptr, OptionEnumValues(g_watch_type), 0, eArgTypeWatchType,
34      "Specify the type of watching to perform."},
35     {LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument,
36      nullptr, OptionEnumValues(g_watch_size), 0, eArgTypeByteSize,
37      "Number of bytes to use to watch a region."}};
38
39 bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) {
40   for (const auto& size : g_watch_size) {
41     if (0  == size.value)
42       break;
43     if (watch_size == size.value)
44       return true;
45   }
46   return false;
47 }
48
49 OptionGroupWatchpoint::OptionGroupWatchpoint() : OptionGroup() {}
50
51 OptionGroupWatchpoint::~OptionGroupWatchpoint() {}
52
53 Status
54 OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx,
55                                       llvm::StringRef option_arg,
56                                       ExecutionContext *execution_context) {
57   Status error;
58   const int short_option = g_option_table[option_idx].short_option;
59   switch (short_option) {
60   case 'w': {
61     WatchType tmp_watch_type;
62     tmp_watch_type = (WatchType)OptionArgParser::ToOptionEnum(
63         option_arg, g_option_table[option_idx].enum_values, 0, error);
64     if (error.Success()) {
65       watch_type = tmp_watch_type;
66       watch_type_specified = true;
67     }
68     break;
69   }
70   case 's':
71     watch_size = (uint32_t)OptionArgParser::ToOptionEnum(
72         option_arg, g_option_table[option_idx].enum_values, 0, error);
73     break;
74
75   default:
76     error.SetErrorStringWithFormat("unrecognized short option '%c'",
77                                    short_option);
78     break;
79   }
80
81   return error;
82 }
83
84 void OptionGroupWatchpoint::OptionParsingStarting(
85     ExecutionContext *execution_context) {
86   watch_type_specified = false;
87   watch_type = eWatchInvalid;
88   watch_size = 0;
89 }
90
91 llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
92   return llvm::makeArrayRef(g_option_table);
93 }