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 fc6b72523f)
124 lines
4.5 KiB
C++
124 lines
4.5 KiB
C++
//===-- ProcessWindows.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 liblldb_Plugins_Process_Windows_Common_ProcessWindows_H_
|
|
#define liblldb_Plugins_Process_Windows_Common_ProcessWindows_H_
|
|
|
|
#include "lldb/Target/Process.h"
|
|
#include "lldb/Utility/Status.h"
|
|
#include "lldb/lldb-forward.h"
|
|
|
|
#include "Plugins/DynamicLoader/Windows-DYLD/DynamicLoaderWindowsDYLD.h"
|
|
#include "ProcessDebugger.h"
|
|
|
|
namespace lldb_private {
|
|
|
|
class HostProcess;
|
|
|
|
class ProcessWindows : public Process, public ProcessDebugger {
|
|
public:
|
|
// Static functions.
|
|
static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
|
|
lldb::ListenerSP listener_sp,
|
|
const FileSpec *,
|
|
bool can_connect);
|
|
|
|
static void Initialize();
|
|
|
|
static void Terminate();
|
|
|
|
static llvm::StringRef GetPluginNameStatic() { return "windows"; }
|
|
|
|
static llvm::StringRef GetPluginDescriptionStatic();
|
|
|
|
~ProcessWindows();
|
|
|
|
size_t GetSTDOUT(char *buf, size_t buf_size, Status &error) override;
|
|
size_t GetSTDERR(char *buf, size_t buf_size, Status &error) override;
|
|
size_t PutSTDIN(const char *buf, size_t buf_size, Status &error) override;
|
|
|
|
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
|
|
|
|
Status EnableBreakpointSite(BreakpointSite *bp_site) override;
|
|
Status DisableBreakpointSite(BreakpointSite *bp_site) override;
|
|
|
|
Status DoDetach(bool keep_stopped) override;
|
|
Status DoLaunch(Module *exe_module, ProcessLaunchInfo &launch_info) override;
|
|
Status DoAttachToProcessWithID(
|
|
lldb::pid_t pid,
|
|
const lldb_private::ProcessAttachInfo &attach_info) override;
|
|
Status DoResume() override;
|
|
Status DoDestroy() override;
|
|
Status DoHalt(bool &caused_stop) override;
|
|
|
|
void DidLaunch() override;
|
|
void DidAttach(lldb_private::ArchSpec &arch_spec) override;
|
|
|
|
void RefreshStateAfterStop() override;
|
|
|
|
bool CanDebug(lldb::TargetSP target_sp,
|
|
bool plugin_specified_by_name) override;
|
|
bool DestroyRequiresHalt() override { return false; }
|
|
bool DoUpdateThreadList(ThreadList &old_thread_list,
|
|
ThreadList &new_thread_list) override;
|
|
bool IsAlive() override;
|
|
|
|
ArchSpec GetSystemArchitecture() override;
|
|
|
|
size_t DoReadMemory(lldb::addr_t vm_addr, void *buf, size_t size,
|
|
Status &error) override;
|
|
size_t DoWriteMemory(lldb::addr_t vm_addr, const void *buf, size_t size,
|
|
Status &error) override;
|
|
lldb::addr_t DoAllocateMemory(size_t size, uint32_t permissions,
|
|
Status &error) override;
|
|
Status DoDeallocateMemory(lldb::addr_t ptr) override;
|
|
|
|
lldb::addr_t GetImageInfoAddress() override;
|
|
|
|
DynamicLoaderWindowsDYLD *GetDynamicLoader() override;
|
|
|
|
// IDebugDelegate overrides.
|
|
void OnExitProcess(uint32_t exit_code) override;
|
|
void OnDebuggerConnected(lldb::addr_t image_base) override;
|
|
ExceptionResult OnDebugException(bool first_chance,
|
|
const ExceptionRecord &record) override;
|
|
void OnCreateThread(const HostThread &thread) override;
|
|
void OnExitThread(lldb::tid_t thread_id, uint32_t exit_code) override;
|
|
void OnLoadDll(const ModuleSpec &module_spec,
|
|
lldb::addr_t module_addr) override;
|
|
void OnUnloadDll(lldb::addr_t module_addr) override;
|
|
void OnDebugString(const std::string &string) override;
|
|
void OnDebuggerError(const Status &error, uint32_t type) override;
|
|
|
|
std::optional<uint32_t> GetWatchpointSlotCount() override;
|
|
Status EnableWatchpoint(lldb::WatchpointSP wp_sp,
|
|
bool notify = true) override;
|
|
Status DisableWatchpoint(lldb::WatchpointSP wp_sp,
|
|
bool notify = true) override;
|
|
|
|
protected:
|
|
ProcessWindows(lldb::TargetSP target_sp, lldb::ListenerSP listener_sp);
|
|
|
|
Status DoGetMemoryRegionInfo(lldb::addr_t vm_addr,
|
|
MemoryRegionInfo &info) override;
|
|
|
|
private:
|
|
struct WatchpointInfo {
|
|
uint32_t slot_id;
|
|
lldb::addr_t address;
|
|
uint32_t size;
|
|
bool read;
|
|
bool write;
|
|
};
|
|
std::map<lldb::break_id_t, WatchpointInfo> m_watchpoints;
|
|
std::vector<lldb::break_id_t> m_watchpoint_ids;
|
|
};
|
|
} // namespace lldb_private
|
|
|
|
#endif // liblldb_Plugins_Process_Windows_Common_ProcessWindows_H_
|