Path: blob/main/contrib/llvm-project/lldb/source/Interpreter/OptionGroupWatchpoint.cpp
39587 views
//===-- OptionGroupWatchpoint.cpp -----------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "lldb/Interpreter/OptionGroupWatchpoint.h"910#include "lldb/Host/OptionParser.h"11#include "lldb/Interpreter/OptionArgParser.h"12#include "lldb/Target/Language.h"13#include "lldb/lldb-enumerations.h"1415using namespace lldb;16using namespace lldb_private;1718static constexpr OptionEnumValueElement g_watch_type[] = {19{20OptionGroupWatchpoint::eWatchRead,21"read",22"Watch for read",23},24{25OptionGroupWatchpoint::eWatchWrite,26"write",27"Watch for write",28},29{30OptionGroupWatchpoint::eWatchModify,31"modify",32"Watch for modifications",33},34{35OptionGroupWatchpoint::eWatchReadWrite,36"read_write",37"Watch for read/write",38},39};4041static constexpr OptionDefinition g_option_table[] = {42{LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument,43nullptr, OptionEnumValues(g_watch_type), 0, eArgTypeWatchType,44"Specify the type of watching to perform."},45{LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument,46nullptr, {}, 0, eArgTypeByteSize,47"Number of bytes to use to watch a region."},48{LLDB_OPT_SET_2,49false,50"language",51'l',52OptionParser::eRequiredArgument,53nullptr,54{},550,56eArgTypeLanguage,57"Language of expression to run"}};5859Status60OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx,61llvm::StringRef option_arg,62ExecutionContext *execution_context) {63Status error;64const int short_option = g_option_table[option_idx].short_option;65switch (short_option) {66case 'l': {67language_type = Language::GetLanguageTypeFromString(option_arg);68if (language_type == eLanguageTypeUnknown) {69StreamString sstr;70sstr.Printf("Unknown language type: '%s' for expression. List of "71"supported languages:\n",72option_arg.str().c_str());73Language::PrintSupportedLanguagesForExpressions(sstr, " ", "\n");74error.SetErrorString(sstr.GetString());75}76break;77}78case 'w': {79WatchType tmp_watch_type;80tmp_watch_type = (WatchType)OptionArgParser::ToOptionEnum(81option_arg, g_option_table[option_idx].enum_values, 0, error);82if (error.Success()) {83watch_type = tmp_watch_type;84watch_type_specified = true;85}86break;87}88case 's':89error = watch_size.SetValueFromString(option_arg);90if (watch_size.GetCurrentValue() == 0)91error.SetErrorStringWithFormat("invalid --size option value '%s'",92option_arg.str().c_str());93break;9495default:96llvm_unreachable("Unimplemented option");97}9899return error;100}101102void OptionGroupWatchpoint::OptionParsingStarting(103ExecutionContext *execution_context) {104watch_type_specified = false;105watch_type = eWatchInvalid;106watch_size.Clear();107language_type = eLanguageTypeUnknown;108}109110llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {111return llvm::ArrayRef(g_option_table);112}113114115