blob: 076d010ae7ec723c1393301f41ffdcd00cc96d87 [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 +000040// if you add any options here, remember to update the counters in OptionGroupWatchpoint::GetNumDefinitions()
41static OptionDefinition
42g_option_table[] =
43{
Johnny Chen1b452522011-09-30 01:08:48 +000044 { LLDB_OPT_SET_1, false, "watch", 'w', required_argument, g_watch_type, 0, eArgTypeWatchType, "Determine how to watch a variable (read, write, or read/write)."},
45 { LLDB_OPT_SET_1, false, "xsize", 'x', required_argument, g_watch_size, 0, eArgTypeByteSize, "Number of bytes to use to watch a location (1, 2, 4, or 8)."}
Johnny Chen58dba3c2011-09-09 23:25:26 +000046};
47
48
49OptionGroupWatchpoint::OptionGroupWatchpoint () :
50 OptionGroup()
51{
52}
53
54OptionGroupWatchpoint::~OptionGroupWatchpoint ()
55{
56}
57
58Error
59OptionGroupWatchpoint::SetOptionValue (CommandInterpreter &interpreter,
60 uint32_t option_idx,
61 const char *option_arg)
62{
63 Error error;
64 char short_option = (char) g_option_table[option_idx].short_option;
65 switch (short_option)
66 {
67 case 'w': {
Johnny Chen58dba3c2011-09-09 23:25:26 +000068 OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values;
Johnny Chen34bbf852011-09-12 23:38:44 +000069 watch_type = (WatchType) Args::StringToOptionEnum(option_arg, enum_values, 0, &watch_variable);
Johnny Chen3066b252011-09-12 19:12:06 +000070 if (!watch_variable)
71 error.SetErrorStringWithFormat("Invalid option arg for '-w': '%s'.\n", option_arg);
Johnny Chen58dba3c2011-09-09 23:25:26 +000072 break;
73 }
Johnny Chen1b452522011-09-30 01:08:48 +000074 case 'x': {
75 bool success = false;
76 OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values;
77 watch_size = (WatchType) Args::StringToOptionEnum(option_arg, enum_values, 0, &success);
78 if (!success)
79 error.SetErrorStringWithFormat("Invalid option arg for '-x': '%s'.\n", option_arg);
80 break;
81 }
Johnny Chen58dba3c2011-09-09 23:25:26 +000082 default:
83 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
84 break;
85 }
86
87 return error;
88}
89
90void
91OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter)
92{
93 watch_variable = false;
Johnny Chen34bbf852011-09-12 23:38:44 +000094 watch_type = eWatchInvalid;
Johnny Chen1b452522011-09-30 01:08:48 +000095 watch_size = 0;
Johnny Chen58dba3c2011-09-09 23:25:26 +000096}
97
98
99const OptionDefinition*
100OptionGroupWatchpoint::GetDefinitions ()
101{
102 return g_option_table;
103}
104
105uint32_t
106OptionGroupWatchpoint::GetNumDefinitions ()
107{
Johnny Chen4003f572011-09-10 00:48:33 +0000108 return arraysize(g_option_table);
Johnny Chen58dba3c2011-09-09 23:25:26 +0000109}