Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 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" |
Johnny Chen | 4003f57 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/Utils.h" |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
Johnny Chen | 34bbf85 | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 23 | static OptionEnumValueElement g_watch_type[] = |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 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 | |
Johnny Chen | 1b45252 | 2011-09-30 01:08:48 +0000 | [diff] [blame] | 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 | |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 40 | static OptionDefinition |
| 41 | g_option_table[] = |
| 42 | { |
Johnny Chen | 6183fcc | 2012-02-08 01:13:31 +0000 | [diff] [blame] | 43 | { 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 Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | |
Johnny Chen | 1e0e73a | 2012-06-04 20:08:23 +0000 | [diff] [blame] | 48 | bool |
| 49 | OptionGroupWatchpoint::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 Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 61 | OptionGroupWatchpoint::OptionGroupWatchpoint () : |
| 62 | OptionGroup() |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | OptionGroupWatchpoint::~OptionGroupWatchpoint () |
| 67 | { |
| 68 | } |
| 69 | |
| 70 | Error |
| 71 | OptionGroupWatchpoint::SetOptionValue (CommandInterpreter &interpreter, |
| 72 | uint32_t option_idx, |
| 73 | const char *option_arg) |
| 74 | { |
| 75 | Error error; |
Greg Clayton | 6475c42 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 76 | const int short_option = g_option_table[option_idx].short_option; |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 77 | switch (short_option) |
| 78 | { |
Greg Clayton | 61aca5d | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 79 | case 'w': |
| 80 | watch_type = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error); |
| 81 | if (error.Success()) |
Johnny Chen | 42404d2 | 2012-02-08 22:37:48 +0000 | [diff] [blame] | 82 | watch_type_specified = true; |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 83 | break; |
Greg Clayton | 61aca5d | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 84 | |
| 85 | case 'x': |
| 86 | watch_size = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error); |
Johnny Chen | 1b45252 | 2011-09-30 01:08:48 +0000 | [diff] [blame] | 87 | break; |
Greg Clayton | 61aca5d | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 88 | |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 89 | default: |
Greg Clayton | 9c23673 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 90 | error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 91 | break; |
| 92 | } |
| 93 | |
| 94 | return error; |
| 95 | } |
| 96 | |
| 97 | void |
| 98 | OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter) |
| 99 | { |
Johnny Chen | 42404d2 | 2012-02-08 22:37:48 +0000 | [diff] [blame] | 100 | watch_type_specified = false; |
Greg Clayton | 61aca5d | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 101 | watch_type = eWatchInvalid; |
| 102 | watch_size = 0; |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
| 106 | const OptionDefinition* |
| 107 | OptionGroupWatchpoint::GetDefinitions () |
| 108 | { |
| 109 | return g_option_table; |
| 110 | } |
| 111 | |
| 112 | uint32_t |
| 113 | OptionGroupWatchpoint::GetNumDefinitions () |
| 114 | { |
Johnny Chen | 08af598 | 2012-05-15 23:21:36 +0000 | [diff] [blame] | 115 | return llvm::array_lengthof(g_option_table); |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 116 | } |