Johnny Chen | b1d7529 | 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 | 7c575b3 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 18 | #include "lldb/Utility/Utils.h" |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
Johnny Chen | 887062a | 2011-09-12 23:38:44 +0000 | [diff] [blame] | 23 | static OptionEnumValueElement g_watch_type[] = |
Johnny Chen | b1d7529 | 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"}, |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 28 | { 0, nullptr, nullptr } |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 29 | }; |
| 30 | |
Johnny Chen | b62a3be | 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"}, |
Ed Maste | d78c957 | 2014-04-20 00:31:37 +0000 | [diff] [blame] | 37 | { 0, nullptr, nullptr } |
Johnny Chen | b62a3be | 2011-09-30 01:08:48 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 40 | static OptionDefinition |
| 41 | g_option_table[] = |
| 42 | { |
Zachary Turner | d37221d | 2014-07-09 16:31:49 +0000 | [diff] [blame] | 43 | { LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument, nullptr, g_watch_type, 0, eArgTypeWatchType, "Specify the type of watching to perform."}, |
| 44 | { LLDB_OPT_SET_1, false, "xsize", 'x', OptionParser::eRequiredArgument, nullptr, g_watch_size, 0, eArgTypeByteSize, "Number of bytes to use to watch a region."} |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | |
Johnny Chen | 3cb41e8 | 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 | b1d7529 | 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 | 3bcdfc0 | 2012-12-04 00:32:51 +0000 | [diff] [blame] | 76 | const int short_option = g_option_table[option_idx].short_option; |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 77 | switch (short_option) |
| 78 | { |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 79 | case 'w': |
Jim Ingham | c646231 | 2013-06-18 21:52:48 +0000 | [diff] [blame] | 80 | { |
| 81 | WatchType tmp_watch_type; |
| 82 | tmp_watch_type = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error); |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 83 | if (error.Success()) |
Jim Ingham | c646231 | 2013-06-18 21:52:48 +0000 | [diff] [blame] | 84 | { |
| 85 | watch_type = tmp_watch_type; |
Johnny Chen | 2ffa754 | 2012-02-08 22:37:48 +0000 | [diff] [blame] | 86 | watch_type_specified = true; |
Jim Ingham | c646231 | 2013-06-18 21:52:48 +0000 | [diff] [blame] | 87 | } |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 88 | break; |
Jim Ingham | c646231 | 2013-06-18 21:52:48 +0000 | [diff] [blame] | 89 | } |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 90 | case 'x': |
Sean Callanan | 4d682d2 | 2013-07-25 23:12:53 +0000 | [diff] [blame] | 91 | watch_size = (uint32_t) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error); |
Johnny Chen | b62a3be | 2011-09-30 01:08:48 +0000 | [diff] [blame] | 92 | break; |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 93 | |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 94 | default: |
Greg Clayton | 86edbf4 | 2011-10-26 00:56:27 +0000 | [diff] [blame] | 95 | error.SetErrorStringWithFormat("unrecognized short option '%c'", short_option); |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 96 | break; |
| 97 | } |
| 98 | |
| 99 | return error; |
| 100 | } |
| 101 | |
| 102 | void |
| 103 | OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter) |
| 104 | { |
Johnny Chen | 2ffa754 | 2012-02-08 22:37:48 +0000 | [diff] [blame] | 105 | watch_type_specified = false; |
Greg Clayton | cf0e4f0 | 2011-10-07 18:58:12 +0000 | [diff] [blame] | 106 | watch_type = eWatchInvalid; |
| 107 | watch_size = 0; |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | |
| 111 | const OptionDefinition* |
| 112 | OptionGroupWatchpoint::GetDefinitions () |
| 113 | { |
| 114 | return g_option_table; |
| 115 | } |
| 116 | |
| 117 | uint32_t |
| 118 | OptionGroupWatchpoint::GetNumDefinitions () |
| 119 | { |
Johnny Chen | 6ebc8c45 | 2012-05-15 23:21:36 +0000 | [diff] [blame] | 120 | return llvm::array_lengthof(g_option_table); |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 121 | } |