1 //===-- 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"
18 #include "lldb/Utility/Utils.h"
19 
20 using namespace lldb;
21 using namespace lldb_private;
22 
23 static OptionEnumValueElement g_watch_type[] =
24 {
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 
31 static 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 
40 static OptionDefinition
41 g_option_table[] =
42 {
43     { LLDB_OPT_SET_1, false, "watch", 'w', required_argument, g_watch_type, 0, eArgTypeWatchType, "Determine how to watch a variable; or, with -x option, its pointee."},
44     { LLDB_OPT_SET_1, false, "xsize", 'x', required_argument, g_watch_size, 0, eArgTypeByteSize, "Number of bytes to use to watch the pointee."}
45 };
46 
47 
48 OptionGroupWatchpoint::OptionGroupWatchpoint () :
49     OptionGroup()
50 {
51 }
52 
53 OptionGroupWatchpoint::~OptionGroupWatchpoint ()
54 {
55 }
56 
57 Error
58 OptionGroupWatchpoint::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     {
66         case 'w':
67             watch_type = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
68             if (error.Success())
69                 watch_variable = true;
70             break;
71 
72         case 'x':
73             watch_size = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error);
74             break;
75 
76         default:
77             error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option);
78             break;
79     }
80 
81     return error;
82 }
83 
84 void
85 OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter)
86 {
87     watch_variable = false;
88     watch_type = eWatchInvalid;
89     watch_size = 0;
90 }
91 
92 
93 const OptionDefinition*
94 OptionGroupWatchpoint::GetDefinitions ()
95 {
96     return g_option_table;
97 }
98 
99 uint32_t
100 OptionGroupWatchpoint::GetNumDefinitions ()
101 {
102     return arraysize(g_option_table);
103 }
104