blob: 4f9f2c19a6a858ec3306f0e8c5483f3a04469910 [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
23static OptionEnumValueElement g_watch_mode[] =
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// if you add any options here, remember to update the counters in OptionGroupWatchpoint::GetNumDefinitions()
32static OptionDefinition
33g_option_table[] =
34{
35 { LLDB_OPT_SET_1, false, "watch", 'w', required_argument, g_watch_mode, 0, eArgTypeWatchMode, "Determine how to watch a memory location (read, write, or read/write)."}
36};
37
38
39OptionGroupWatchpoint::OptionGroupWatchpoint () :
40 OptionGroup()
41{
42}
43
44OptionGroupWatchpoint::~OptionGroupWatchpoint ()
45{
46}
47
48Error
49OptionGroupWatchpoint::SetOptionValue (CommandInterpreter &interpreter,
50 uint32_t option_idx,
51 const char *option_arg)
52{
53 Error error;
54 char short_option = (char) g_option_table[option_idx].short_option;
55 switch (short_option)
56 {
57 case 'w': {
Johnny Chen58dba3c2011-09-09 23:25:26 +000058 OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values;
59 watch_mode = (WatchMode) Args::StringToOptionEnum(option_arg, enum_values, 0, &watch_variable);
Johnny Chen3066b252011-09-12 19:12:06 +000060 if (!watch_variable)
61 error.SetErrorStringWithFormat("Invalid option arg for '-w': '%s'.\n", option_arg);
Johnny Chen58dba3c2011-09-09 23:25:26 +000062 break;
63 }
64 default:
65 error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option);
66 break;
67 }
68
69 return error;
70}
71
72void
73OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter)
74{
75 watch_variable = false;
Johnny Chen439d0332011-09-10 06:22:46 +000076 watch_mode = eWatchInvalid;
Johnny Chen58dba3c2011-09-09 23:25:26 +000077}
78
79
80const OptionDefinition*
81OptionGroupWatchpoint::GetDefinitions ()
82{
83 return g_option_table;
84}
85
86uint32_t
87OptionGroupWatchpoint::GetNumDefinitions ()
88{
Johnny Chen4003f572011-09-10 00:48:33 +000089 return arraysize(g_option_table);
Johnny Chen58dba3c2011-09-09 23:25:26 +000090}