mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 14:56:10 +00:00

This patch is rearranging code a bit to add WatchpointResources to Process. A WatchpointResource is meant to represent a hardware watchpoint register in the inferior process. It has an address, a size, a type, and a list of Watchpoints that are using this WatchpointResource. This current patch doesn't add any of the features of WatchpointResources that make them interesting -- a user asking to watch a 24 byte object could watch this with three 8 byte WatchpointResources. Or a Watchpoint on 1 byte at 0x1002 and a second watchpoint on 1 byte at 0x1003, these must both be served by a single WatchpointResource on that doubleword at 0x1000 on a 64-bit target, if two hardware watchpoint registers were used to track these separately, one of them may not be hit. Or if you have one Watchpoint on a variable with a condition set, and another Watchpoint on that same variable with a command defined or different condition, or ignorecount, both of those Watchpoints need to evaluate their criteria/commands when their WatchpointResource has been hit. There's a bit of code movement to rearrange things in the direction I'll need for implementing this feature, so I want to start with reviewing & landing this mostly NFC patch and we can focus on the algorithmic choices about how WatchpointResources are shared and handled as they're triggeed, separately. This patch also stops printing "Watchpoint <n> hit: old value: <x>, new vlaue: <y>" for Read watchpoints. I could make an argument for print "Watchpoint <n> hit: current value <x>" but the current output doesn't make any sense, and the user can print the value if they are particularly interested. Read watchpoints are used primarily to understand what code is reading a variable. This patch adds more fallbacks for how to print the objects being watched if we have types, instead of assuming they are all integral values, so a struct will print its elements. As large watchpoints are added, we'll be doing a lot more of those. To track the WatchpointSP in the WatchpointResources, I changed the internal API which took a WatchpointSP and devolved it to a Watchpoint*, which meant touching several different Process files. I removed the watchpoint code in ProcessKDP which only reported that watchpoints aren't supported, the base class does that already. I haven't yet changed how we receive a watchpoint to identify the WatchpointResource responsible for the trigger, and identify all Watchpoints that are using this Resource to evaluate their conditions etc. This is the same work that a BreakpointSite needs to do when it has been tiggered, where multiple Breakpoints may be at the same address. There is not yet any printing of the Resources that a Watchpoint is implemented in terms of ("watchpoint list", or SBWatchpoint::GetDescription). "watchpoint set var" and "watchpoint set expression" take a size argument which was previously 1, 2, 4, or 8 (an enum). I've changed this to an unsigned int. Most hardware implementations can only watch 1, 2, 4, 8 byte ranges, but with Resources we'll allow a user to ask for different sized watchpoints and set them in hardware-expressble terms soon. I've annotated areas where I know there is work still needed with LWP_TODO that I'll be working on once this is landed. I've tested this on aarch64 macOS, aarch64 Linux, and Intel macOS. https://discourse.llvm.org/t/rfc-large-watchpoint-support-in-lldb/72116 (cherry picked from commit fc6b72523f3d73b921690a713e97a433c96066c6)
114 lines
3.4 KiB
C++
114 lines
3.4 KiB
C++
//===-- OptionGroupWatchpoint.cpp -----------------------------------------===//
|
|
//
|
|
// 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "lldb/Interpreter/OptionGroupWatchpoint.h"
|
|
|
|
#include "lldb/Host/OptionParser.h"
|
|
#include "lldb/Interpreter/OptionArgParser.h"
|
|
#include "lldb/Target/Language.h"
|
|
#include "lldb/lldb-enumerations.h"
|
|
|
|
using namespace lldb;
|
|
using namespace lldb_private;
|
|
|
|
static constexpr OptionEnumValueElement g_watch_type[] = {
|
|
{
|
|
OptionGroupWatchpoint::eWatchRead,
|
|
"read",
|
|
"Watch for read",
|
|
},
|
|
{
|
|
OptionGroupWatchpoint::eWatchWrite,
|
|
"write",
|
|
"Watch for write",
|
|
},
|
|
{
|
|
OptionGroupWatchpoint::eWatchModify,
|
|
"modify",
|
|
"Watch for modifications",
|
|
},
|
|
{
|
|
OptionGroupWatchpoint::eWatchReadWrite,
|
|
"read_write",
|
|
"Watch for read/write",
|
|
},
|
|
};
|
|
|
|
static constexpr OptionDefinition g_option_table[] = {
|
|
{LLDB_OPT_SET_1, false, "watch", 'w', OptionParser::eRequiredArgument,
|
|
nullptr, OptionEnumValues(g_watch_type), 0, eArgTypeWatchType,
|
|
"Specify the type of watching to perform."},
|
|
{LLDB_OPT_SET_1, false, "size", 's', OptionParser::eRequiredArgument,
|
|
nullptr, {}, 0, eArgTypeByteSize,
|
|
"Number of bytes to use to watch a region."},
|
|
{LLDB_OPT_SET_2,
|
|
false,
|
|
"language",
|
|
'l',
|
|
OptionParser::eRequiredArgument,
|
|
nullptr,
|
|
{},
|
|
0,
|
|
eArgTypeLanguage,
|
|
"Language of expression to run"}};
|
|
|
|
Status
|
|
OptionGroupWatchpoint::SetOptionValue(uint32_t option_idx,
|
|
llvm::StringRef option_arg,
|
|
ExecutionContext *execution_context) {
|
|
Status error;
|
|
const int short_option = g_option_table[option_idx].short_option;
|
|
switch (short_option) {
|
|
case 'l': {
|
|
language_type = Language::GetLanguageTypeFromString(option_arg);
|
|
if (language_type == eLanguageTypeUnknown) {
|
|
StreamString sstr;
|
|
sstr.Printf("Unknown language type: '%s' for expression. List of "
|
|
"supported languages:\n",
|
|
option_arg.str().c_str());
|
|
Language::PrintSupportedLanguagesForExpressions(sstr, " ", "\n");
|
|
error.SetErrorString(sstr.GetString());
|
|
}
|
|
break;
|
|
}
|
|
case 'w': {
|
|
WatchType tmp_watch_type;
|
|
tmp_watch_type = (WatchType)OptionArgParser::ToOptionEnum(
|
|
option_arg, g_option_table[option_idx].enum_values, 0, error);
|
|
if (error.Success()) {
|
|
watch_type = tmp_watch_type;
|
|
watch_type_specified = true;
|
|
}
|
|
break;
|
|
}
|
|
case 's':
|
|
error = watch_size.SetValueFromString(option_arg);
|
|
if (watch_size.GetCurrentValue() == 0)
|
|
error.SetErrorStringWithFormat("invalid --size option value '%s'",
|
|
option_arg.str().c_str());
|
|
break;
|
|
|
|
default:
|
|
llvm_unreachable("Unimplemented option");
|
|
}
|
|
|
|
return error;
|
|
}
|
|
|
|
void OptionGroupWatchpoint::OptionParsingStarting(
|
|
ExecutionContext *execution_context) {
|
|
watch_type_specified = false;
|
|
watch_type = eWatchInvalid;
|
|
watch_size.Clear();
|
|
language_type = eLanguageTypeUnknown;
|
|
}
|
|
|
|
llvm::ArrayRef<OptionDefinition> OptionGroupWatchpoint::GetDefinitions() {
|
|
return llvm::ArrayRef(g_option_table);
|
|
}
|