Skip to content

Commit 08c4a67

Browse files
committed
[lldb] Move breakpoint hit reset code to Target::CleanupProcess
This ensures it is run regardless of the method we use to initiate the session (previous version did not handle connects), and it is the same place that is used for resetting watchpoints. Differential Revision: https://reviews.llvm.org/D134882
1 parent 8d1de7b commit 08c4a67

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

lldb/source/Target/Process.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2761,18 +2761,15 @@ ListenerSP ProcessAttachInfo::GetListenerForProcess(Debugger &debugger) {
27612761
}
27622762

27632763
Status Process::WillLaunch(Module *module) {
2764-
GetTarget().ResetBreakpointHitCounts();
27652764
return DoWillLaunch(module);
27662765
}
27672766

27682767
Status Process::WillAttachToProcessWithID(lldb::pid_t pid) {
2769-
GetTarget().ResetBreakpointHitCounts();
27702768
return DoWillAttachToProcessWithID(pid);
27712769
}
27722770

27732771
Status Process::WillAttachToProcessWithName(const char *process_name,
27742772
bool wait_for_launch) {
2775-
GetTarget().ResetBreakpointHitCounts();
27762773
return DoWillAttachToProcessWithName(process_name, wait_for_launch);
27772774
}
27782775

lldb/source/Target/Target.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ void Target::CleanupProcess() {
177177
// clean up needs some help from the process.
178178
m_breakpoint_list.ClearAllBreakpointSites();
179179
m_internal_breakpoint_list.ClearAllBreakpointSites();
180+
ResetBreakpointHitCounts();
180181
// Disable watchpoints just on the debugger side.
181182
std::unique_lock<std::recursive_mutex> lock;
182183
this->GetWatchpointList().GetListMutex(lock);

lldb/test/API/functionalities/gdb_remote_client/TestProcessConnect.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,57 @@ def test_process_connect_async(self):
6363
self.dbg.GetSelectedTarget().GetProcess().Kill()
6464
lldbutil.expect_state_changes(self, self.dbg.GetListener(),
6565
self.process(), [lldb.eStateExited])
66+
def test_breakpoint_count(self):
67+
"""
68+
Test that breakpoint count gets reset for each new connection.
69+
"""
70+
class MyResponder(MockGDBServerResponder):
71+
72+
def __init__(self):
73+
super().__init__()
74+
self.continued = False
75+
76+
def qfThreadInfo(self):
77+
return "m47"
78+
79+
def qsThreadInfo(self):
80+
return "l"
81+
82+
def setBreakpoint(self, packet):
83+
return "OK"
84+
85+
def readRegister(self, reg):
86+
# Pretend we're at the breakpoint after we've been resumed.
87+
return "3412000000000000" if self.continued else "4747000000000000"
88+
89+
def cont(self):
90+
self.continued = True
91+
return "T05thread=47;reason:breakpoint"
92+
93+
# Connect to the first process and set our breakpoint.
94+
self.server.responder = MyResponder()
95+
target = self.createTarget("a.yaml")
96+
process = self.connect(target)
97+
98+
bkpt = target.BreakpointCreateByAddress(0x1234)
99+
self.assertTrue(bkpt.IsValid())
100+
self.assertEqual(bkpt.GetNumLocations(), 1)
101+
102+
# "continue" the process. It should hit our breakpoint.
103+
process.Continue()
104+
self.assertState(process.GetState(), lldb.eStateStopped)
105+
self.assertEqual(bkpt.GetHitCount(), 1)
106+
107+
# Now kill it. The breakpoint should still show a hit count of one.
108+
process.Kill()
109+
self.server.stop()
110+
self.assertEqual(bkpt.GetHitCount(), 1)
111+
112+
# Start over, and reconnect.
113+
self.server = MockGDBServer(self.server_socket_class())
114+
self.server.start()
115+
116+
process = self.connect(target)
117+
118+
# The hit count should be reset.
119+
self.assertEqual(bkpt.GetHitCount(), 0)

0 commit comments

Comments
 (0)