Skip to content

Large watchpoint use watchpointresources #8096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions lldb/include/lldb/Breakpoint/WatchpointAlgorithms.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
//===-- WatchpointAlgorithms.h ----------------------------------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//

#ifndef LLDB_BREAKPOINT_WATCHPOINTALGORITHMS_H
#define LLDB_BREAKPOINT_WATCHPOINTALGORITHMS_H

#include "lldb/Breakpoint/WatchpointResource.h"
#include "lldb/Utility/ArchSpec.h"
#include "lldb/lldb-public.h"

#include <vector>

namespace lldb_private {

class WatchpointAlgorithms {

public:
/// Convert a user's watchpoint request into an array of memory
/// regions that can be watched by one hardware watchpoint register
/// on the current target.
///
/// \param[in] addr
/// The start address specified by the user.
///
/// \param[in] size
/// The number of bytes the user wants to watch.
///
/// \param[in] read
/// True if we are watching for read accesses.
///
/// \param[in] write
/// True if we are watching for write accesses.
/// \a read and \a write may both be true.
/// There is no "modify" style for WatchpointResources -
/// WatchpointResources are akin to the hardware watchpoint
/// registers which are either in terms of read or write.
/// "modify" distinction is done at the Watchpoint layer, where
/// we check the actual range of bytes the user requested.
///
/// \param[in] supported_features
/// The bit flags in this parameter are set depending on which
/// WatchpointHardwareFeature enum values the current target supports.
/// The eWatchpointHardwareFeatureUnknown bit may be set if we
/// don't have specific information about what the remote stub
/// can support, and a reasonablec default will be used.
///
/// \param[in] arch
/// The ArchSpec of the current Target.
///
/// \return
/// A vector of WatchpointResourceSP's, one per hardware watchpoint
/// register needed. We may return more WatchpointResources than the
/// target can watch at once; if all resources cannot be set, the
/// watchpoint cannot be set.
static std::vector<lldb::WatchpointResourceSP> AtomizeWatchpointRequest(
lldb::addr_t addr, size_t size, bool read, bool write,
lldb::WatchpointHardwareFeature supported_features, ArchSpec &arch);

struct Region {
lldb::addr_t addr;
size_t size;
};

protected:
/// Convert a user's watchpoint request into an array of addr+size that
/// can be watched with power-of-2 style hardware watchpoints.
///
/// This is the default algorithm if we have no further information;
/// most watchpoint implementations can be assumed to be able to watch up
/// to pointer-size regions of memory in power-of-2 sizes and alingments.
///
/// \param[in] user_addr
/// The user's start address.
///
/// \param[in] user_size
/// The user's specified byte length.
///
/// \param[in] min_byte_size
/// The minimum byte size supported on this target.
/// In most cases, this will be 1. AArch64 MASK watchpoints can
/// watch a minimum of 8 bytes (although Byte Address Select watchpoints
/// can watch 1 to pointer-size bytes in a pointer-size aligned granule).
///
/// \param[in] max_byte_size
/// The maximum byte size supported for one watchpoint on this target.
///
/// \param[in] address_byte_size
/// The address byte size on this target.
static std::vector<Region> PowerOf2Watchpoints(lldb::addr_t user_addr,
size_t user_size,
size_t min_byte_size,
size_t max_byte_size,
uint32_t address_byte_size);
};

} // namespace lldb_private

#endif // LLDB_BREAKPOINT_WATCHPOINTALGORITHMS_H
8 changes: 0 additions & 8 deletions lldb/include/lldb/Breakpoint/WatchpointResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,6 @@ class WatchpointResource
/// A copy of the Watchpoints which own this resource.
WatchpointCollection CopyConstituentsList();

// The ID of the WatchpointResource is set by the WatchpointResourceList
// when the Resource has been set in the inferior and is being added
// to the List, in an attempt to match the hardware watchpoint register
// ordering. If a Process can correctly identify the hardware watchpoint
// register index when it has created the Resource, it may initialize it
// before it is inserted in the WatchpointResourceList.
void SetID(lldb::wp_resource_id_t);

lldb::wp_resource_id_t GetID() const;

bool Contains(lldb::addr_t addr);
Expand Down
145 changes: 0 additions & 145 deletions lldb/include/lldb/Breakpoint/WatchpointResourceList.h

This file was deleted.

26 changes: 26 additions & 0 deletions lldb/include/lldb/lldb-enumerations.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,32 @@ enum WatchpointWriteType {
eWatchpointWriteTypeOnModify
};

/// The hardware and native stub capabilities for a given target,
/// for translating a user's watchpoint request into hardware
/// capable watchpoint resources.
FLAGS_ENUM(WatchpointHardwareFeature){
/// lldb will fall back to a default that assumes the target
/// can watch up to pointer-size power-of-2 regions, aligned to
/// power-of-2.
eWatchpointHardwareFeatureUnknown = (1u << 0),

/// Intel systems can watch 1, 2, 4, or 8 bytes (in 64-bit targets),
/// aligned naturally.
eWatchpointHardwareX86 = (1u << 1),

/// ARM systems with Byte Address Select watchpoints
/// can watch any consecutive series of bytes up to the
/// size of a pointer (4 or 8 bytes), at a pointer-size
/// alignment.
eWatchpointHardwareArmBAS = (1u << 2),

/// ARM systems with MASK watchpoints can watch any power-of-2
/// sized region from 8 bytes to 2 gigabytes, aligned to that
/// same power-of-2 alignment.
eWatchpointHardwareArmMASK = (1u << 3),
};
LLDB_MARK_AS_BITMASK_ENUM(WatchpointHardwareFeature)

/// Programming language type.
///
/// These enumerations use the same language enumerations as the DWARF
Expand Down
7 changes: 6 additions & 1 deletion lldb/packages/Python/lldbsuite/test/concurrent_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ def do_thread_actions(

# Initialize the (single) watchpoint on the global variable (g_watchme)
if num_watchpoint_threads + num_delay_watchpoint_threads > 0:
self.runCmd("watchpoint set variable g_watchme")
# The concurrent tests have multiple threads modifying a variable
# with the same value. The default "modify" style watchpoint will
# only report this as 1 hit for all threads, because they all wrote
# the same value. The testsuite needs "write" style watchpoints to
# get the correct number of hits reported.
self.runCmd("watchpoint set variable -w write g_watchme")
for w in self.inferior_target.watchpoint_iter():
self.thread_watchpoint = w
self.assertTrue(
Expand Down
2 changes: 1 addition & 1 deletion lldb/source/Breakpoint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ add_lldb_library(lldbBreakpoint NO_PLUGIN_DEPENDENCIES
StoppointSite.cpp
StopPointSiteList.cpp
Watchpoint.cpp
WatchpointAlgorithms.cpp
WatchpointList.cpp
WatchpointOptions.cpp
WatchpointResource.cpp
WatchpointResourceList.cpp

LINK_LIBS
lldbCore
Expand Down
28 changes: 24 additions & 4 deletions lldb/source/Breakpoint/Watchpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ Watchpoint::Watchpoint(Target &target, lldb::addr_t addr, uint32_t size,
LLDB_LOG_ERROR(GetLog(LLDBLog::Watchpoints), std::move(err),
"Failed to set type: {0}");
} else {
if (auto ts = *type_system_or_err)
m_type =
ts->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 8 * size);
else
if (auto ts = *type_system_or_err) {
if (size <= target.GetArchitecture().GetAddressByteSize()) {
m_type =
ts->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 8 * size);
} else {
CompilerType clang_uint8_type =
ts->GetBuiltinTypeForEncodingAndBitSize(eEncodingUint, 8);
m_type = clang_uint8_type.GetArrayType(size);
}
} else
LLDB_LOG_ERROR(GetLog(LLDBLog::Watchpoints), std::move(err),
"Failed to set type: Typesystem is no longer live: {0}");
}
Expand Down Expand Up @@ -352,6 +358,20 @@ void Watchpoint::DumpWithLevel(Stream *s,
s->Printf("\n declare @ '%s'", m_decl_str.c_str());
if (!m_watch_spec_str.empty())
s->Printf("\n watchpoint spec = '%s'", m_watch_spec_str.c_str());
if (IsEnabled()) {
if (ProcessSP process_sp = m_target.GetProcessSP()) {
auto &resourcelist = process_sp->GetWatchpointResourceList();
size_t idx = 0;
s->Printf("\n watchpoint resources:");
for (WatchpointResourceSP &wpres : resourcelist.Sites()) {
if (wpres->ConstituentsContains(this)) {
s->Printf("\n #%zu: ", idx);
wpres->Dump(s);
}
idx++;
}
}
}

// Dump the snapshots we have taken.
DumpSnapshots(s, " ");
Expand Down
Loading