2020-01-24 08:23:27 +01:00
|
|
|
//===-- OptionGroupWatchpoint.cpp -----------------------------------------===//
|
2011-09-09 23:25:26 +00:00
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-09-09 23:25:26 +00:00
|
|
|
//
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
#include "lldb/Interpreter/OptionGroupWatchpoint.h"
|
|
|
|
|
|
2017-03-22 23:33:16 +00:00
|
|
|
#include "lldb/Host/OptionParser.h"
|
2018-04-10 09:03:59 +00:00
|
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
2011-09-09 23:25:26 +00:00
|
|
|
#include "lldb/lldb-enumerations.h"
|
|
|
|
|
|
|
|
|
|
using namespace lldb;
|
|
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
2018-09-26 18:50:19 +00:00
|
|
|
static constexpr OptionEnumValueElement g_watch_type[] = {
|
2019-08-02 00:18:44 +00:00
|
|
|
{
|
|
|
|
|
OptionGroupWatchpoint::eWatchRead,
|
|
|
|
|
"read",
|
|
|
|
|
"Watch for read",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
OptionGroupWatchpoint::eWatchWrite,
|
|
|
|
|
"write",
|
|
|
|
|
"Watch for write",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
OptionGroupWatchpoint::eWatchReadWrite,
|
|
|
|
|
"read_write",
|
|
|
|
|
"Watch for read/write",
|
|
|
|
|
},
|
|
|
|
|
};
|
2011-09-09 23:25:26 +00:00
|
|
|
|
2018-09-26 18:50:19 +00:00
|
|
|
static constexpr OptionEnumValueElement g_watch_size[] = {
|
2019-08-02 00:18:44 +00:00
|
|
|
{
|
|
|
|
|
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",
|
|
|
|
|
},
|
|
|
|
|
};
|
2011-09-30 01:08:48 +00:00
|
|
|
|
2018-09-26 18:50:19 +00:00
|
|
|
static constexpr OptionDefinition g_option_table[] = {
|
2014-07-09 16:31:49 +00:00
|
|
|
{LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument,
|
2018-09-26 18:50:19 +00:00
|
|
|
nullptr, OptionEnumValues(g_watch_type), 0, eArgTypeWatchType,
|
2014-07-09 16:31:49 +00:00
|
|
|
"Specify the type of watching to perform."},
|
2015-03-26 00:42:27 +00:00
|
|
|
{LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument,
|
2018-09-26 18:50:19 +00:00
|
|
|
nullptr, OptionEnumValues(g_watch_size), 0, eArgTypeByteSize,
|
2015-03-26 00:42:27 +00:00
|
|
|
"Number of bytes to use to watch a region."}};
|
2011-09-09 23:25:26 +00:00
|
|
|
|
2012-06-04 20:08:23 +00:00
|
|
|
bool OptionGroupWatchpoint::IsWatchSizeSupported(uint32_t watch_size) {
|
2018-09-26 18:50:19 +00:00
|
|
|
for (const auto& size : g_watch_size) {
|
|
|
|
|
if (0 == size.value)
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
2018-09-26 18:50:19 +00:00
|
|
|
if (watch_size == size.value)
|
2012-06-04 20:08:23 +00:00
|
|
|
return true;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2012-06-04 20:08:23 +00:00
|
|
|
return false;
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
2011-09-09 23:25:26 +00:00
|
|
|
|
2012-06-04 20:08:23 +00:00
|
|
|
OptionGroupWatchpoint::OptionGroupWatchpoint() : OptionGroup() {}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2012-06-04 20:08:23 +00:00
|
|
|
OptionGroupWatchpoint::~OptionGroupWatchpoint() {}
|
2016-09-06 20:57:50 +00:00
|
|
|
|
2017-05-12 04:51:55 +00:00
|
|
|
Status
|
|
|
|
|
OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx,
|
|
|
|
|
llvm::StringRef option_arg,
|
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
|
Status error;
|
2012-06-04 20:08:23 +00:00
|
|
|
const int short_option = g_option_table[option_idx].short_option;
|
|
|
|
|
switch (short_option) {
|
2011-10-07 18:58:12 +00:00
|
|
|
case 'w': {
|
2013-06-18 21:52:48 +00:00
|
|
|
WatchType tmp_watch_type;
|
2018-04-10 09:03:59 +00:00
|
|
|
tmp_watch_type = (WatchType)OptionArgParser::ToOptionEnum(
|
2012-06-04 20:08:23 +00:00
|
|
|
option_arg, g_option_table[option_idx].enum_values, 0, error);
|
|
|
|
|
if (error.Success()) {
|
|
|
|
|
watch_type = tmp_watch_type;
|
|
|
|
|
watch_type_specified = true;
|
|
|
|
|
}
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
}
|
2012-06-04 20:08:23 +00:00
|
|
|
case 's':
|
2018-04-10 09:03:59 +00:00
|
|
|
watch_size = (uint32_t)OptionArgParser::ToOptionEnum(
|
2012-06-04 20:08:23 +00:00
|
|
|
option_arg, g_option_table[option_idx].enum_values, 0, error);
|
2016-09-06 20:57:50 +00:00
|
|
|
break;
|
|
|
|
|
|
2012-06-04 20:08:23 +00:00
|
|
|
default:
|
2019-08-22 08:08:05 +00:00
|
|
|
llvm_unreachable("Unimplemented option");
|
2016-09-06 20:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
2012-06-04 20:08:23 +00:00
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-09 23:25:26 +00:00
|
|
|
void OptionGroupWatchpoint::OptionParsingStarting(
|
|
|
|
|
ExecutionContext *execution_context) {
|
|
|
|
|
watch_type_specified = false;
|
2011-10-07 18:58:12 +00:00
|
|
|
watch_type = eWatchInvalid;
|
|
|
|
|
watch_size = 0;
|
2011-09-09 23:25:26 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-22 20:22:55 +00:00
|
|
|
llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
|
2016-09-22 21:06:13 +00:00
|
|
|
return llvm::makeArrayRef(g_option_table);
|
2011-09-09 23:25:26 +00:00
|
|
|
}
|