blob: cda934bd3943f37efabc536e9e116a3a20974687 [file] [log] [blame]
Johnny Chenb1d75292011-09-09 23:25:26 +00001//===-- 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// C Includes
13// C++ Includes
14// Other libraries and framework includes
15// Project includes
Johnny Chenb1d75292011-09-09 23:25:26 +000016#include "lldb/Interpreter/Args.h"
Johnny Chen7c575b32011-09-10 00:48:33 +000017#include "lldb/Utility/Utils.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000018#include "lldb/lldb-enumerations.h"
Johnny Chenb1d75292011-09-09 23:25:26 +000019
20using namespace lldb;
21using namespace lldb_private;
22
Kate Stoneb9c1b512016-09-06 20:57:50 +000023static OptionEnumValueElement g_watch_type[] = {
24 {OptionGroupWatchpoint::eWatchRead, "read", "Watch for read"},
25 {OptionGroupWatchpoint::eWatchWrite, "write", "Watch for write"},
26 {OptionGroupWatchpoint::eWatchReadWrite, "read_write",
27 "Watch for read/write"},
28 {0, nullptr, nullptr}};
Johnny Chenb1d75292011-09-09 23:25:26 +000029
Kate Stoneb9c1b512016-09-06 20:57:50 +000030static OptionEnumValueElement g_watch_size[] = {
31 {1, "1", "Watch for byte size of 1"},
32 {2, "2", "Watch for byte size of 2"},
33 {4, "4", "Watch for byte size of 4"},
34 {8, "8", "Watch for byte size of 8"},
35 {0, nullptr, nullptr}};
Johnny Chenb62a3be2011-09-30 01:08:48 +000036
Kate Stoneb9c1b512016-09-06 20:57:50 +000037static OptionDefinition g_option_table[] = {
38 {LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument,
39 nullptr, g_watch_type, 0, eArgTypeWatchType,
40 "Specify the type of watching to perform."},
41 {LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument,
42 nullptr, g_watch_size, 0, eArgTypeByteSize,
43 "Number of bytes to use to watch a region."}};
Johnny Chenb1d75292011-09-09 23:25:26 +000044
Kate Stoneb9c1b512016-09-06 20:57:50 +000045bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) {
46 for (uint32_t i = 0; i < llvm::array_lengthof(g_watch_size); ++i) {
47 if (g_watch_size[i].value == 0)
48 break;
49 if (watch_size == g_watch_size[i].value)
50 return true;
51 }
52 return false;
53}
Johnny Chenb1d75292011-09-09 23:25:26 +000054
Kate Stoneb9c1b512016-09-06 20:57:50 +000055OptionGroupWatchpoint::OptionGroupWatchpoint() : OptionGroup() {}
56
57OptionGroupWatchpoint::~OptionGroupWatchpoint() {}
58
59Error OptionGroupWatchpoint::SetOptionValue(
Zachary Turner8cef4b02016-09-23 17:48:13 +000060 uint32_t option_idx, llvm::StringRef option_arg,
Kate Stoneb9c1b512016-09-06 20:57:50 +000061 ExecutionContext *execution_context) {
62 Error error;
63 const int short_option = g_option_table[option_idx].short_option;
64 switch (short_option) {
65 case 'w': {
66 WatchType tmp_watch_type;
67 tmp_watch_type = (WatchType)Args::StringToOptionEnum(
68 option_arg, g_option_table[option_idx].enum_values, 0, error);
69 if (error.Success()) {
70 watch_type = tmp_watch_type;
71 watch_type_specified = true;
Johnny Chen3cb41e82012-06-04 20:08:23 +000072 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000073 break;
74 }
75 case 's':
76 watch_size = (uint32_t)Args::StringToOptionEnum(
77 option_arg, g_option_table[option_idx].enum_values, 0, error);
78 break;
79
80 default:
81 error.SetErrorStringWithFormat("unrecognized short option '%c'",
82 short_option);
83 break;
84 }
85
86 return error;
Johnny Chen3cb41e82012-06-04 20:08:23 +000087}
88
Kate Stoneb9c1b512016-09-06 20:57:50 +000089void OptionGroupWatchpoint::OptionParsingStarting(
90 ExecutionContext *execution_context) {
91 watch_type_specified = false;
92 watch_type = eWatchInvalid;
93 watch_size = 0;
Johnny Chenb1d75292011-09-09 23:25:26 +000094}
95
Zachary Turner1f0f5b52016-09-22 20:22:55 +000096llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
Zachary Turner70602432016-09-22 21:06:13 +000097 return llvm::makeArrayRef(g_option_table);
Johnny Chenb1d75292011-09-09 23:25:26 +000098}