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 | // if you add any options here, remember to update the counters in OptionGroupWatchpoint::GetNumDefinitions() |
| 41 | static OptionDefinition |
| 42 | g_option_table[] = |
| 43 | { |
Johnny Chen | 1b45252 | 2011-09-30 01:08:48 +0000 | [diff] [blame] | 44 | { 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 Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | |
| 49 | OptionGroupWatchpoint::OptionGroupWatchpoint () : |
| 50 | OptionGroup() |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | OptionGroupWatchpoint::~OptionGroupWatchpoint () |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | Error |
| 59 | OptionGroupWatchpoint::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 | { |
Greg Clayton | 61aca5d | 2011-10-07 18:58:12 +0000 | [diff] [blame^] | 67 | case 'w': |
| 68 | watch_type = (WatchType) Args::StringToOptionEnum(option_arg, g_option_table[option_idx].enum_values, 0, error); |
| 69 | if (error.Success()) |
| 70 | watch_variable = true; |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 71 | break; |
Greg Clayton | 61aca5d | 2011-10-07 18:58:12 +0000 | [diff] [blame^] | 72 | |
| 73 | case 'x': |
| 74 | 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] | 75 | break; |
Greg Clayton | 61aca5d | 2011-10-07 18:58:12 +0000 | [diff] [blame^] | 76 | |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 77 | default: |
| 78 | error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); |
| 79 | break; |
| 80 | } |
| 81 | |
| 82 | return error; |
| 83 | } |
| 84 | |
| 85 | void |
| 86 | OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter) |
| 87 | { |
| 88 | watch_variable = false; |
Greg Clayton | 61aca5d | 2011-10-07 18:58:12 +0000 | [diff] [blame^] | 89 | watch_type = eWatchInvalid; |
| 90 | watch_size = 0; |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | |
| 94 | const OptionDefinition* |
| 95 | OptionGroupWatchpoint::GetDefinitions () |
| 96 | { |
| 97 | return g_option_table; |
| 98 | } |
| 99 | |
| 100 | uint32_t |
| 101 | OptionGroupWatchpoint::GetNumDefinitions () |
| 102 | { |
Johnny Chen | 4003f57 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 103 | return arraysize(g_option_table); |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 104 | } |