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 |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 16 | #include "lldb/Interpreter/Args.h" |
Johnny Chen | 7c575b3 | 2011-09-10 00:48:33 +0000 | [diff] [blame] | 17 | #include "lldb/Utility/Utils.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 18 | #include "lldb/lldb-enumerations.h" |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace lldb; |
| 21 | using namespace lldb_private; |
| 22 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 23 | static OptionEnumValueElement g_watch_type[] = { |
| 24 | {OptionGroupWatchpoint::eWatchRead, "read", "Watch for read"}, |
| 25 | {OptionGroupWatchpoint::eWatchWrite, "write", "Watch for write"}, |
| 26 | {OptionGroupWatchpoint::eWatchReadWrite, "read_write", |
| 27 | "Watch for read/write"}, |
| 28 | {0, nullptr, nullptr}}; |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 29 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 30 | static OptionEnumValueElement g_watch_size[] = { |
| 31 | {1, "1", "Watch for byte size of 1"}, |
| 32 | {2, "2", "Watch for byte size of 2"}, |
| 33 | {4, "4", "Watch for byte size of 4"}, |
| 34 | {8, "8", "Watch for byte size of 8"}, |
| 35 | {0, nullptr, nullptr}}; |
Johnny Chen | b62a3be | 2011-09-30 01:08:48 +0000 | [diff] [blame] | 36 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 37 | static OptionDefinition g_option_table[] = { |
| 38 | {LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument, |
| 39 | nullptr, g_watch_type, 0, eArgTypeWatchType, |
| 40 | "Specify the type of watching to perform."}, |
| 41 | {LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument, |
| 42 | nullptr, g_watch_size, 0, eArgTypeByteSize, |
| 43 | "Number of bytes to use to watch a region."}}; |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 44 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 45 | bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) { |
| 46 | for (uint32_t i = 0; i < llvm::array_lengthof(g_watch_size); ++i) { |
| 47 | if (g_watch_size[i].value == 0) |
| 48 | break; |
| 49 | if (watch_size == g_watch_size[i].value) |
| 50 | return true; |
| 51 | } |
| 52 | return false; |
| 53 | } |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 54 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | OptionGroupWatchpoint::OptionGroupWatchpoint() : OptionGroup() {} |
| 56 | |
| 57 | OptionGroupWatchpoint::~OptionGroupWatchpoint() {} |
| 58 | |
| 59 | Error OptionGroupWatchpoint::SetOptionValue( |
Zachary Turner | 8cef4b0 | 2016-09-23 17:48:13 +0000 | [diff] [blame] | 60 | uint32_t option_idx, llvm::StringRef option_arg, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 61 | ExecutionContext *execution_context) { |
| 62 | Error error; |
| 63 | const int short_option = g_option_table[option_idx].short_option; |
| 64 | switch (short_option) { |
| 65 | case 'w': { |
| 66 | WatchType tmp_watch_type; |
| 67 | tmp_watch_type = (WatchType)Args::StringToOptionEnum( |
| 68 | option_arg, g_option_table[option_idx].enum_values, 0, error); |
| 69 | if (error.Success()) { |
| 70 | watch_type = tmp_watch_type; |
| 71 | watch_type_specified = true; |
Johnny Chen | 3cb41e8 | 2012-06-04 20:08:23 +0000 | [diff] [blame] | 72 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 73 | break; |
| 74 | } |
| 75 | case 's': |
| 76 | watch_size = (uint32_t)Args::StringToOptionEnum( |
| 77 | option_arg, g_option_table[option_idx].enum_values, 0, error); |
| 78 | break; |
| 79 | |
| 80 | default: |
| 81 | error.SetErrorStringWithFormat("unrecognized short option '%c'", |
| 82 | short_option); |
| 83 | break; |
| 84 | } |
| 85 | |
| 86 | return error; |
Johnny Chen | 3cb41e8 | 2012-06-04 20:08:23 +0000 | [diff] [blame] | 87 | } |
| 88 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 89 | void OptionGroupWatchpoint::OptionParsingStarting( |
| 90 | ExecutionContext *execution_context) { |
| 91 | watch_type_specified = false; |
| 92 | watch_type = eWatchInvalid; |
| 93 | watch_size = 0; |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Zachary Turner | 1f0f5b5 | 2016-09-22 20:22:55 +0000 | [diff] [blame] | 96 | llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() { |
Zachary Turner | 7060243 | 2016-09-22 21:06:13 +0000 | [diff] [blame] | 97 | return llvm::makeArrayRef(g_option_table); |
Johnny Chen | b1d7529 | 2011-09-09 23:25:26 +0000 | [diff] [blame] | 98 | } |