Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "Plugins/Process/FreeBSDRemote/NativeRegisterContextFreeBSD.h"
#include "Plugins/Process/Utility/RegisterContext_x86.h"
#include "Plugins/Process/Utility/NativeRegisterContextWatchpoint_x86.h"
#include "Plugins/Process/Utility/lldb-x86-register-enums.h"

#define LLDB_INVALID_XSAVE_OFFSET UINT32_MAX
Expand All @@ -30,7 +31,8 @@ namespace process_freebsd {
class NativeProcessFreeBSD;

class NativeRegisterContextFreeBSD_x86_64
: public NativeRegisterContextFreeBSD {
: public NativeRegisterContextFreeBSD,
public NativeRegisterContextWatchpoint_x86 {
public:
NativeRegisterContextFreeBSD_x86_64(const ArchSpec &target_arch,
NativeThreadProtocol &native_thread);
Expand All @@ -48,33 +50,6 @@ class NativeRegisterContextFreeBSD_x86_64

Status WriteAllRegisterValues(const lldb::DataBufferSP &data_sp) override;

Status IsWatchpointHit(uint32_t wp_index, bool &is_hit) override;

Status GetWatchpointHitIndex(uint32_t &wp_index,
lldb::addr_t trap_addr) override;

Status IsWatchpointVacant(uint32_t wp_index, bool &is_vacant) override;

bool ClearHardwareWatchpoint(uint32_t wp_index) override;

Status ClearWatchpointHit(uint32_t wp_index) override;

Status ClearAllHardwareWatchpoints() override;

Status SetHardwareWatchpointWithIndex(lldb::addr_t addr, size_t size,
uint32_t watch_flags,
uint32_t wp_index);

uint32_t SetHardwareWatchpoint(lldb::addr_t addr, size_t size,
uint32_t watch_flags) override;

lldb::addr_t GetWatchpointAddress(uint32_t wp_index) override;

uint32_t NumSupportedHardwareWatchpoints() override;

Status
CopyHardwareWatchpointsFrom(NativeRegisterContextFreeBSD &source) override;

private:
// Private member types.
enum { GPRegSet, FPRegSet, XSaveRegSet, DBRegSet };
Expand Down
52 changes: 42 additions & 10 deletions lldb/source/Plugins/Process/FreeBSDRemote/NativeThreadFreeBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@ void NativeThreadFreeBSD::SetStoppedByExec() {
}

void NativeThreadFreeBSD::SetStoppedByWatchpoint(uint32_t wp_index) {
lldbassert(wp_index != LLDB_INVALID_INDEX32 && "wp_index cannot be invalid");

std::ostringstream ostr;
ostr << GetRegisterContext().GetWatchpointAddress(wp_index) << " ";
ostr << wp_index;

ostr << " " << GetRegisterContext().GetWatchpointHitAddress(wp_index);

SetStopped();
m_stop_description = ostr.str();
m_stop_info.reason = StopReason::eStopReasonWatchpoint;
m_stop_info.details.signal.signo = SIGTRAP;
}

void NativeThreadFreeBSD::SetStoppedWithNoReason() {
Expand Down Expand Up @@ -176,36 +187,57 @@ NativeRegisterContextFreeBSD &NativeThreadFreeBSD::GetRegisterContext() {

Status NativeThreadFreeBSD::SetWatchpoint(lldb::addr_t addr, size_t size,
uint32_t watch_flags, bool hardware) {
return Status("not implemented");
assert(m_state == eStateStopped);
if (!hardware)
return Status("not implemented");
Status error = RemoveWatchpoint(addr);
if (error.Fail())
return error;
uint32_t wp_index =
GetRegisterContext().SetHardwareWatchpoint(addr, size, watch_flags);
if (wp_index == LLDB_INVALID_INDEX32)
return Status("Setting hardware watchpoint failed.");
m_watchpoint_index_map.insert({addr, wp_index});
return Status();
}

Status NativeThreadFreeBSD::RemoveWatchpoint(lldb::addr_t addr) {
auto wp = m_watchpoint_index_map.find(addr);
if (wp == m_watchpoint_index_map.end())
return Status();
return Status("not implemented");
uint32_t wp_index = wp->second;
m_watchpoint_index_map.erase(wp);
if (GetRegisterContext().ClearHardwareWatchpoint(wp_index))
return Status();
return Status("Clearing hardware watchpoint failed.");
}

Status NativeThreadFreeBSD::SetHardwareBreakpoint(lldb::addr_t addr,
size_t size) {
if (m_state == eStateLaunching)
return Status();

assert(m_state == eStateStopped);
Status error = RemoveHardwareBreakpoint(addr);
if (error.Fail())
return error;

return Status("not implemented");
uint32_t bp_index = GetRegisterContext().SetHardwareBreakpoint(addr, size);

if (bp_index == LLDB_INVALID_INDEX32)
return Status("Setting hardware breakpoint failed.");

m_hw_break_index_map.insert({addr, bp_index});
return Status();
}

Status NativeThreadFreeBSD::RemoveHardwareBreakpoint(lldb::addr_t addr) {
auto bp = m_hw_break_index_map.find(addr);
if (bp == m_hw_break_index_map.end())
return Status();

return Status("not implemented");
}
uint32_t bp_index = bp->second;
if (GetRegisterContext().ClearHardwareBreakpoint(bp_index)) {
m_hw_break_index_map.erase(bp);
return Status();
}

Status NativeThreadFreeBSD::CopyWatchpointsFrom(NativeThreadFreeBSD &source) {
return Status("not implemented");
return Status("Clearing hardware breakpoint failed.");
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def setUp(self):
self.exe_name = self.testMethodName
self.d = {'CXX_SOURCES': self.source, 'EXE': self.exe_name}

@skipIfFreeBSD # timing out on buildbot
def test_watchpoint_command(self):
"""Test 'watchpoint command'."""
self.build(dictionary=self.d)
Expand Down Expand Up @@ -95,7 +94,6 @@ def test_watchpoint_command(self):
self.expect("frame variable --show-globals cookie",
substrs=['(int32_t)', 'cookie = 777'])

@skipIfFreeBSD # timing out on buildbot
@skipIfReproducer
def test_continue_in_watchpoint_command(self):
"""Test continue in a watchpoint command."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentBreakpointDelayBreakpointOneSignal(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@expectedFailureNetBSD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentBreakpointOneDelayBreakpointThreads(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
def test(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class ConcurrentBreakpointsDelayedBreakpointOneWatchpoint(

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentCrashWithBreak(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
def test(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentCrashWithSignal(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
def test(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentCrashWithWatchpoint(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentCrashWithWatchpointBreakpointSignal(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentDelaySignalBreak(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
def test(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentDelaySignalWatch(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentDelayWatchBreak(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentDelayedCrashWithBreakpointSignal(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
def test(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentDelayedCrashWithBreakpointWatchpoint(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentNWatchNBreak(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentSignalBreak(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
def test(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentSignalDelayBreak(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@expectedFailureNetBSD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentSignalDelayWatch(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@expectedFailureNetBSD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentSignalNWatchNBreak(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@expectedFailureNetBSD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentSignalWatch(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentSignalWatchBreak(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@expectedFailureNetBSD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentTwoBreakpointThreads(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
def test(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentTwoBreakpointsOneDelaySignal(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@expectedFailureNetBSD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentTwoBreakpointsOneSignal(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@expectedFailureNetBSD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentTwoBreakpointsOneWatchpoint(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentTwoWatchpointThreads(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentTwoWatchpointsOneBreakpoint(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentTwoWatchpointsOneDelayBreakpoint(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentTwoWatchpointsOneSignal(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@expectedFailureNetBSD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentWatchBreak(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentWatchBreakDelay(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentWatchpointDelayWatchpointOneBreakpoint(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ConcurrentWatchpointWithDelayWatchpointThreads(ConcurrentEventsBase):

mydir = ConcurrentEventsBase.compute_mydir(__file__)

@skipIfFreeBSD # timing out on buildbot
# Atomic sequences are not supported yet for MIPS in LLDB.
@skipIf(triple='^mips')
@add_test_categories(["watchpoint"])
Expand Down
5 changes: 5 additions & 0 deletions lldb/test/API/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,8 @@ def delete_module_cache(path):

# testFormat: The test format to use to interpret tests.
config.test_format = lldbtest.LLDBTest(dotest_cmd)

# Propagate FREEBSD_REMOTE_PLUGIN
if 'FREEBSD_REMOTE_PLUGIN' in os.environ:
config.environment['FREEBSD_REMOTE_PLUGIN'] = os.environ[
'FREEBSD_REMOTE_PLUGIN']