blob: f4d8df1e6ba79a275f02fcebd43221abc60c4f90 [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
16#include "lldb/lldb-enumerations.h"
17#include "lldb/Interpreter/Args.h"
Johnny Chen7c575b32011-09-10 00:48:33 +000018#include "lldb/Utility/Utils.h"
Johnny Chenb1d75292011-09-09 23:25:26 +000019
20using namespace lldb;
21using namespace lldb_private;
22
Johnny Chen887062a2011-09-12 23:38:44 +000023static OptionEnumValueElement g_watch_type[] =
Johnny Chenb1d75292011-09-09 23:25:26 +000024{
25 { OptionGroupWatchpoint::eWatchRead, "read", "Watch for read"},
26 { OptionGroupWatchpoint::eWatchWrite, "write", "Watch for write"},
27 { OptionGroupWatchpoint::eWatchReadWrite, "read_write", "Watch for read/write"},
Ed Masted78c9572014-04-20 00:31:37 +000028 { 0, nullptr, nullptr }
Johnny Chenb1d75292011-09-09 23:25:26 +000029};
30
Johnny Chenb62a3be2011-09-30 01:08:48 +000031static OptionEnumValueElement g_watch_size[] =
32{
33 { 1, "1", "Watch for byte size of 1"},
34 { 2, "2", "Watch for byte size of 2"},
35 { 4, "4", "Watch for byte size of 4"},
36 { 8, "8", "Watch for byte size of 8"},
Ed Masted78c9572014-04-20 00:31:37 +000037 { 0, nullptr, nullptr }
Johnny Chenb62a3be2011-09-30 01:08:48 +000038};
39
Johnny Chenb1d75292011-09-09 23:25:26 +000040static OptionDefinition
41g_option_table[] =
42{
Zachary Turnerd37221d2014-07-09 16:31:49 +000043 { LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument, nullptr, g_watch_type, 0, eArgTypeWatchType, "Specify the type of watching to perform."},
44 { LLDB_OPT_SET_1, false, "xsize", 'x', OptionParser::eRequiredArgument, nullptr, g_watch_size, 0, eArgTypeByteSize, "Number of bytes to use to watch a region."}
Johnny Chenb1d75292011-09-09 23:25:26 +000045};
46
47
Johnny Chen3cb41e82012-06-04 20:08:23 +000048bool
49OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size)
50{
51 for (uint32_t i = 0; i < llvm::array_lengthof(g_watch_size); ++i)
52 {
53 if (g_watch_size[i].value == 0)
54 break;
55 if (watch_size == g_watch_size[i].value)
56 return true;
57 }
58 return false;
59}
60
Johnny Chenb1d75292011-09-09 23:25:26 +000061OptionGroupWatchpoint::OptionGroupWatchpoint () :
62 OptionGroup()
63{
64}
65
66OptionGroupWatchpoint::~OptionGroupWatchpoint ()
67{
68}
69
70Error
71OptionGroupWatchpoint::SetOptionValue (CommandInterpreter &interpreter,
72 uint32_t option_idx,
73 const char *option_arg)
74{
75 Error error;
Greg Clayton3bcdfc02012-12-04 00:32:51 +000076 const int short_option = g_option_table[option_idx].short_option;
Johnny Chenb1d75292011-09-09 23:25:26 +000077 switch (short_option)
78 {
Greg Claytoncf0e4f02011-10-07 18:58:12 +000079 case 'w':
Jim Inghamc6462312013-06-18 21:52:48 +000080 {
81 WatchType tmp_watch_type;
82 tmp_watch_type = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
Greg Claytoncf0e4f02011-10-07 18:58:12 +000083 if (error.Success())
Jim Inghamc6462312013-06-18 21:52:48 +000084 {
85 watch_type = tmp_watch_type;
Johnny Chen2ffa7542012-02-08 22:37:48 +000086 watch_type_specified = true;
Jim Inghamc6462312013-06-18 21:52:48 +000087 }
Johnny Chenb1d75292011-09-09 23:25:26 +000088 break;
Jim Inghamc6462312013-06-18 21:52:48 +000089 }
Greg Claytoncf0e4f02011-10-07 18:58:12 +000090 case 'x':
Sean Callanan4d682d22013-07-25 23:12:53 +000091 watch_size = (uint32_t) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
Johnny Chenb62a3be2011-09-30 01:08:48 +000092 break;
Greg Claytoncf0e4f02011-10-07 18:58:12 +000093
Johnny Chenb1d75292011-09-09 23:25:26 +000094 default:
Greg Clayton86edbf42011-10-26 00:56:27 +000095 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
Johnny Chenb1d75292011-09-09 23:25:26 +000096 break;
97 }
98
99 return error;
100}
101
102void
103OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter)
104{
Johnny Chen2ffa7542012-02-08 22:37:48 +0000105 watch_type_specified = false;
Greg Claytoncf0e4f02011-10-07 18:58:12 +0000106 watch_type = eWatchInvalid;
107 watch_size = 0;
Johnny Chenb1d75292011-09-09 23:25:26 +0000108}
109
110
111const OptionDefinition*
112OptionGroupWatchpoint::GetDefinitions ()
113{
114 return g_option_table;
115}
116
117uint32_t
118OptionGroupWatchpoint::GetNumDefinitions ()
119{
Johnny Chen6ebc8c452012-05-15 23:21:36 +0000120 return llvm::array_lengthof(g_option_table);
Johnny Chenb1d75292011-09-09 23:25:26 +0000121}