-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[lldb] Add 'modify' type watchpoints, make it default #66308
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
Changes from all commits
1efbce9
6648995
f8da42f
19d2f06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
%feature("docstring", | ||
"A container for options to use when creating watchpoints." | ||
) lldb::SBWatchpointOptions; | ||
|
||
%feature("docstring", "Sets whether the watchpoint should stop on read accesses." | ||
) lldb::SBWatchpointOptions::SetWatchpointTypeRead; | ||
%feature("docstring", "Gets whether the watchpoint should stop on read accesses." | ||
) lldb::SBWatchpointOptions::GetWatchpointTypeRead; | ||
%feature("docstring", "Sets whether the watchpoint should stop on write accesses. eWatchpointWriteTypeOnModify is the most commonly useful mode, where lldb will stop when the watched value has changed. eWatchpointWriteTypeAlways will stop on any write to the watched region, even if it's the value is the same." | ||
) lldb::SBWatchpointOptions::SetWatchpointTypeWrite; | ||
%feature("docstring", "Gets whether the watchpoint should stop on write accesses, returning WatchpointWriteType to indicate the type of write watching that is enabled, or eWatchpointWriteTypeDisabled." | ||
) lldb::SBWatchpointOptions::GetWatchpointTypeWrite; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//===-- SBWatchpointOptions.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_API_SBWATCHPOINTOPTIONS_H | ||
#define LLDB_API_SBWATCHPOINTOPTIONS_H | ||
|
||
#include "lldb/API/SBDefines.h" | ||
|
||
class WatchpointOptionsImpl; | ||
|
||
namespace lldb { | ||
|
||
class LLDB_API SBWatchpointOptions { | ||
public: | ||
SBWatchpointOptions(); | ||
|
||
SBWatchpointOptions(const lldb::SBWatchpointOptions &rhs); | ||
|
||
~SBWatchpointOptions(); | ||
|
||
const SBWatchpointOptions &operator=(const lldb::SBWatchpointOptions &rhs); | ||
|
||
/// Stop when the watched memory region is read. | ||
void SetWatchpointTypeRead(bool read); | ||
bool GetWatchpointTypeRead() const; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add header doc here to explain that write mode will stop on any write even if the value doesn't change |
||
/// Stop when the watched memory region is written to/modified | ||
void SetWatchpointTypeWrite(lldb::WatchpointWriteType write_type); | ||
lldb::WatchpointWriteType GetWatchpointTypeWrite() const; | ||
|
||
private: | ||
// This auto_pointer is made in the constructor and is always valid. | ||
mutable std::unique_ptr<WatchpointOptionsImpl> m_opaque_up; | ||
}; | ||
|
||
} // namespace lldb | ||
|
||
#endif // LLDB_API_SBWATCHPOINTOPTIONS_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//===-- SBWatchpointOptions.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/API/SBWatchpointOptions.h" | ||
#include "lldb/Breakpoint/Watchpoint.h" | ||
#include "lldb/Utility/Instrumentation.h" | ||
|
||
#include "Utils.h" | ||
|
||
using namespace lldb; | ||
using namespace lldb_private; | ||
|
||
class WatchpointOptionsImpl { | ||
public: | ||
bool m_read = false; | ||
bool m_write = false; | ||
bool m_modify = false; | ||
}; | ||
Comment on lines
+18
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be moved to Watchpoint.h and then used in our internal API as well if you like that idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I originally wrote that little class in Watchpoint.h and then I moved it into the SBWatchpointOptions because I wasn't using it anywhere else. tbh I thought the class for the three bools was overkill right now but I agree that there's long-term value in making the SB API cleanly extensible. But for the lldb_private API, I'm less worried about using three bools for now. If it does become more than that, an Options class would be a thing to adopt. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we can do anything internally, so it doesn't really matter what we do inside as we can always change it at any point as long as the public API is solid. |
||
|
||
|
||
SBWatchpointOptions::SBWatchpointOptions() | ||
: m_opaque_up(new WatchpointOptionsImpl()) { | ||
LLDB_INSTRUMENT_VA(this); | ||
} | ||
|
||
SBWatchpointOptions::SBWatchpointOptions(const SBWatchpointOptions &rhs) { | ||
LLDB_INSTRUMENT_VA(this, rhs); | ||
|
||
m_opaque_up = clone(rhs.m_opaque_up); | ||
} | ||
|
||
const SBWatchpointOptions & | ||
SBWatchpointOptions::operator=(const SBWatchpointOptions &rhs) { | ||
LLDB_INSTRUMENT_VA(this, rhs); | ||
|
||
if (this != &rhs) | ||
m_opaque_up = clone(rhs.m_opaque_up); | ||
return *this; | ||
} | ||
|
||
SBWatchpointOptions::~SBWatchpointOptions() = default; | ||
|
||
void SBWatchpointOptions::SetWatchpointTypeRead(bool read) { | ||
m_opaque_up->m_read = read; | ||
} | ||
bool SBWatchpointOptions::GetWatchpointTypeRead() const { | ||
return m_opaque_up->m_read; | ||
} | ||
|
||
void SBWatchpointOptions::SetWatchpointTypeWrite( | ||
WatchpointWriteType write_type) { | ||
if (write_type == eWatchpointWriteTypeOnModify) { | ||
m_opaque_up->m_write = false; | ||
m_opaque_up->m_modify = true; | ||
} else if (write_type == eWatchpointWriteTypeAlways) { | ||
m_opaque_up->m_write = true; | ||
m_opaque_up->m_modify = false; | ||
} else | ||
m_opaque_up->m_write = m_opaque_up->m_modify = false; | ||
} | ||
|
||
WatchpointWriteType SBWatchpointOptions::GetWatchpointTypeWrite() const { | ||
if (m_opaque_up->m_modify) | ||
return eWatchpointWriteTypeOnModify; | ||
if (m_opaque_up->m_write) | ||
return eWatchpointWriteTypeAlways; | ||
return eWatchpointWriteTypeDisabled; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a header doc explaining this will stop any time memory is read from. Might want to mention if this works along with "modify" at all to only stop when reading a value and that value has changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can do read+modify, actually. I fixed a subtle bug in this latest commit in Watchpoint::WatchedValueReportable() where we know that a watched memory region may have been accessed. If it's read+modify, we don't know if it's been read from, or written to (value mutating or not). Unless we emulate the instruction that was executed, it could be a read, or a write with the same value, or it could be an access near the watched region which triggered the stop. (this latter happening with large watchpoint support where watching a 24 byte region may actually need to watch 32 bytes, or on an AArch64 processor in streaming SVE mode when a write is near the watched region)
Effectively, if a watchpoint is read+modify, it will behave the same as read+write -- we will have to stop on every access to that memory region (or near that memory region, for the above reasons).
I only came to understand this behavior this afternoon while debugging a testsuite failure, I need to do a fuller once-over of my changes to see if there are other updates I need to make.