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 | |
| 23 | static 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() |
| 32 | static OptionDefinition |
| 33 | g_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 | |
| 39 | OptionGroupWatchpoint::OptionGroupWatchpoint () : |
| 40 | OptionGroup() |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | OptionGroupWatchpoint::~OptionGroupWatchpoint () |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | Error |
| 49 | OptionGroupWatchpoint::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': { |
| 58 | watch_variable = false; |
| 59 | OptionEnumValueElement *enum_values = g_option_table[option_idx].enum_values; |
| 60 | watch_mode = (WatchMode) Args::StringToOptionEnum(option_arg, enum_values, 0, &watch_variable); |
| 61 | break; |
| 62 | } |
| 63 | default: |
| 64 | error.SetErrorStringWithFormat("Invalid short option character '%c'.\n", short_option); |
| 65 | break; |
| 66 | } |
| 67 | |
| 68 | return error; |
| 69 | } |
| 70 | |
| 71 | void |
| 72 | OptionGroupWatchpoint::OptionParsingStarting (CommandInterpreter &interpreter) |
| 73 | { |
| 74 | watch_variable = false; |
| 75 | watch_mode = eWatchRead; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | const OptionDefinition* |
| 80 | OptionGroupWatchpoint::GetDefinitions () |
| 81 | { |
| 82 | return g_option_table; |
| 83 | } |
| 84 | |
| 85 | uint32_t |
| 86 | OptionGroupWatchpoint::GetNumDefinitions () |
| 87 | { |
Johnny Chen | 4003f57 | 2011-09-10 00:48:33 +0000 | [diff] [blame^] | 88 | return arraysize(g_option_table); |
Johnny Chen | 58dba3c | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 89 | } |