blob: e352a0e705e3dad073fd6911f0b8166b2361cca9 [file] [log] [blame]
Johnny Chen58dba3c2011-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 Chen4003f572011-09-10 00:48:33 +000018#include "lldb/Utility/Utils.h"
Johnny Chen58dba3c2011-09-09 23:25:26 +000019
20using namespace lldb;
21using namespace lldb_private;
22
Johnny Chen34bbf852011-09-12 23:38:44 +000023static OptionEnumValueElement g_watch_type[] =
Johnny Chen58dba3c2011-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"},
28 { 0, NULL, NULL }
29};
30
Johnny Chen1b452522011-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"},
37 { 0, NULL, NULL }
38};
39
Johnny Chen58dba3c2011-09-09 23:25:26 +000040static OptionDefinition
41g_option_table[] =
42{
Johnny Chen6183fcc2012-02-08 01:13:31 +000043 { LLDB_OPT_SET_1, false, "watch", 'w', required_argument, g_watch_type, 0, eArgTypeWatchType, "Specify the type of watching to perform."},
44 { LLDB_OPT_SET_1, false, "xsize", 'x', required_argument, g_watch_size, 0, eArgTypeByteSize, "Number of bytes to use to watch a region."}
Johnny Chen58dba3c2011-09-09 23:25:26 +000045};
46
47
Johnny Chen1e0e73a2012-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 Chen58dba3c2011-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 Clayton6475c422012-12-04 00:32:51 +000076 const int short_option = g_option_table[option_idx].short_option;
Johnny Chen58dba3c2011-09-09 23:25:26 +000077 switch (short_option)
78 {
Greg Clayton61aca5d2011-10-07 18:58:12 +000079 case 'w':
80 watch_type = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
81 if (error.Success())
Johnny Chen42404d22012-02-08 22:37:48 +000082 watch_type_specified = true;
Johnny Chen58dba3c2011-09-09 23:25:26 +000083 break;
Greg Clayton61aca5d2011-10-07 18:58:12 +000084
85 case 'x':
86 watch_size = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
Johnny Chen1b452522011-09-30 01:08:48 +000087 break;
Greg Clayton61aca5d2011-10-07 18:58:12 +000088
Johnny Chen58dba3c2011-09-09 23:25:26 +000089 default:
Greg Clayton9c236732011-10-26 00:56:27 +000090 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
Johnny Chen58dba3c2011-09-09 23:25:26 +000091 break;
92 }
93
94 return error;
95}
96
97void
98OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter)
99{
Johnny Chen42404d22012-02-08 22:37:48 +0000100 watch_type_specified = false;
Greg Clayton61aca5d2011-10-07 18:58:12 +0000101 watch_type = eWatchInvalid;
102 watch_size = 0;
Johnny Chen58dba3c2011-09-09 23:25:26 +0000103}
104
105
106const OptionDefinition*
107OptionGroupWatchpoint::GetDefinitions ()
108{
109 return g_option_table;
110}
111
112uint32_t
113OptionGroupWatchpoint::GetNumDefinitions ()
114{
Johnny Chen08af5982012-05-15 23:21:36 +0000115 return llvm::array_lengthof(g_option_table);
Johnny Chen58dba3c2011-09-09 23:25:26 +0000116}