blob: 469a2162ead6e2a9095e9ae8b8cb8c9b47746f98 [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
48OptionGroupWatchpoint::OptionGroupWatchpoint () :
49 OptionGroup()
50{
51}
52
53OptionGroupWatchpoint::~OptionGroupWatchpoint ()
54{
55}
56
57Error
58OptionGroupWatchpoint::SetOptionValue (CommandInterpreter &interpreter,
59 uint32_t option_idx,
60 const char *option_arg)
61{
62 Error error;
63 char short_option = (char) g_option_table[option_idx].short_option;
64 switch (short_option)
65 {
Greg Clayton61aca5d2011-10-07 18:58:12 +000066 case 'w':
67 watch_type = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
68 if (error.Success())
Johnny Chen42404d22012-02-08 22:37:48 +000069 watch_type_specified = true;
Johnny Chen58dba3c2011-09-09 23:25:26 +000070 break;
Greg Clayton61aca5d2011-10-07 18:58:12 +000071
72 case 'x':
73 watch_size = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
Johnny Chen1b452522011-09-30 01:08:48 +000074 break;
Greg Clayton61aca5d2011-10-07 18:58:12 +000075
Johnny Chen58dba3c2011-09-09 23:25:26 +000076 default:
Greg Clayton9c236732011-10-26 00:56:27 +000077 error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
Johnny Chen58dba3c2011-09-09 23:25:26 +000078 break;
79 }
80
81 return error;
82}
83
84void
85OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter)
86{
Johnny Chen42404d22012-02-08 22:37:48 +000087 watch_type_specified = false;
Greg Clayton61aca5d2011-10-07 18:58:12 +000088 watch_type = eWatchInvalid;
89 watch_size = 0;
Johnny Chen58dba3c2011-09-09 23:25:26 +000090}
91
92
93const OptionDefinition*
94OptionGroupWatchpoint::GetDefinitions ()
95{
96 return g_option_table;
97}
98
99uint32_t
100OptionGroupWatchpoint::GetNumDefinitions ()
101{
Johnny Chen4003f572011-09-10 00:48:33 +0000102 return arraysize(g_option_table);
Johnny Chen58dba3c2011-09-09 23:25:26 +0000103}