2011-09-10 07:25:26 +08:00
|
|
|
//===-- OptionGroupWatchpoint.cpp -------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/OptionGroupWatchpoint.h"
|
|
|
|
|
|
|
|
// C Includes
|
|
|
|
// C++ Includes
|
|
|
|
// Other libraries and framework includes
|
|
|
|
// Project includes
|
|
|
|
#include "lldb/Interpreter/Args.h"
|
2011-09-10 08:48:33 +08:00
|
|
|
#include "lldb/Utility/Utils.h"
|
2016-09-07 04:57:50 +08:00
|
|
|
#include "lldb/lldb-enumerations.h"
|
2011-09-10 07:25:26 +08:00
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
static OptionEnumValueElement g_watch_type[] = {
|
|
|
|
{OptionGroupWatchpoint::eWatchRead, "read", "Watch for read"},
|
|
|
|
{OptionGroupWatchpoint::eWatchWrite, "write", "Watch for write"},
|
|
|
|
{OptionGroupWatchpoint::eWatchReadWrite, "read_write",
|
|
|
|
"Watch for read/write"},
|
|
|
|
{0, nullptr, nullptr}};
|
|
|
|
|
|
|
|
static OptionEnumValueElement g_watch_size[] = {
|
|
|
|
{1, "1", "Watch for byte size of 1"},
|
|
|
|
{2, "2", "Watch for byte size of 2"},
|
|
|
|
{4, "4", "Watch for byte size of 4"},
|
|
|
|
{8, "8", "Watch for byte size of 8"},
|
|
|
|
{0, nullptr, nullptr}};
|
|
|
|
|
|
|
|
static OptionDefinition g_option_table[] = {
|
|
|
|
{LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument,
|
|
|
|
nullptr, g_watch_type, 0, eArgTypeWatchType,
|
|
|
|
"Specify the type of watching to perform."},
|
|
|
|
{LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument,
|
|
|
|
nullptr, g_watch_size, 0, eArgTypeByteSize,
|
|
|
|
"Number of bytes to use to watch a region."}};
|
|
|
|
|
|
|
|
bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) {
|
|
|
|
for (uint32_t i = 0; i < llvm::array_lengthof(g_watch_size); ++i) {
|
|
|
|
if (g_watch_size[i].value == 0)
|
|
|
|
break;
|
|
|
|
if (watch_size == g_watch_size[i].value)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2012-06-05 04:08:23 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
OptionGroupWatchpoint::OptionGroupWatchpoint() : OptionGroup() {}
|
|
|
|
|
|
|
|
OptionGroupWatchpoint::~OptionGroupWatchpoint() {}
|
|
|
|
|
|
|
|
Error OptionGroupWatchpoint::SetOptionValue(
|
2016-09-24 01:48:13 +08:00
|
|
|
uint32_t option_idx, llvm::StringRef option_arg,
|
2016-09-07 04:57:50 +08:00
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
Error error;
|
|
|
|
const int short_option = g_option_table[option_idx].short_option;
|
|
|
|
switch (short_option) {
|
|
|
|
case 'w': {
|
|
|
|
WatchType tmp_watch_type;
|
|
|
|
tmp_watch_type = (WatchType)Args::StringToOptionEnum(
|
|
|
|
option_arg, g_option_table[option_idx].enum_values, 0, error);
|
|
|
|
if (error.Success()) {
|
|
|
|
watch_type = tmp_watch_type;
|
|
|
|
watch_type_specified = true;
|
2011-09-10 07:25:26 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 's':
|
|
|
|
watch_size = (uint32_t)Args::StringToOptionEnum(
|
|
|
|
option_arg, g_option_table[option_idx].enum_values, 0, error);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error.SetErrorStringWithFormat("unrecognized short option '%c'",
|
|
|
|
short_option);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return error;
|
2011-09-10 07:25:26 +08:00
|
|
|
}
|
|
|
|
|
2016-09-07 04:57:50 +08:00
|
|
|
void OptionGroupWatchpoint::OptionParsingStarting(
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
watch_type_specified = false;
|
|
|
|
watch_type = eWatchInvalid;
|
|
|
|
watch_size = 0;
|
2011-09-10 07:25:26 +08:00
|
|
|
}
|
|
|
|
|
Convert option tables to ArrayRefs.
This change is very mechanical. All it does is change the
signature of `Options::GetDefinitions()` and `OptionGroup::
GetDefinitions()` to return an `ArrayRef<OptionDefinition>`
instead of a `const OptionDefinition *`. In the case of the
former, it deletes the sentinel entry from every table, and
in the case of the latter, it removes the `GetNumDefinitions()`
method from the interface. These are no longer necessary as
`ArrayRef` carries its own length.
In the former case, iteration was done by using a sentinel
entry, so there was no knowledge of length. Because of this
the individual option tables were allowed to be defined below
the corresponding class (after all, only a pointer was needed).
Now, however, the length must be known at compile time to
construct the `ArrayRef`, and as a result it is necessary to
move every option table before its corresponding class. This
results in this CL looking very big, but in terms of substance
there is not much here.
Differential revision: https://reviews.llvm.org/D24834
llvm-svn: 282188
2016-09-23 04:22:55 +08:00
|
|
|
llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
|
2016-09-23 05:06:13 +08:00
|
|
|
return llvm::makeArrayRef(g_option_table);
|
2011-09-10 07:25:26 +08:00
|
|
|
}
|