LibDebug: Disable and cleanup DebugSession breakpoints on destruction

Breakpoints need to be disabled before we detach from the debugee.

I noticed this while looking into the fact that if you continue
executing a program in sdb (/bin/ls) where you had previously
set a breakpoint, it would crash on sdb exit once the debugee died
with an assert on HashMap destruction where we were iterating
while clearing is set. This change also happens to fix this assert.
This commit is contained in:
Brian Gianforcaro 2020-08-01 15:44:50 -07:00 committed by Andreas Kling
parent 81187c4ead
commit 1f7c61b15f
Notes: sideshowbarker 2024-07-19 04:22:34 +09:00

View file

@ -38,6 +38,11 @@ DebugSession::DebugSession(int pid)
DebugSession::~DebugSession() DebugSession::~DebugSession()
{ {
for (const auto& bp : m_breakpoints) {
disable_breakpoint(bp.key);
}
m_breakpoints.clear();
if (!m_is_debugee_dead) { if (!m_is_debugee_dead) {
if (ptrace(PT_DETACH, m_debugee_pid, 0, 0) < 0) { if (ptrace(PT_DETACH, m_debugee_pid, 0, 0) < 0) {
perror("PT_DETACH"); perror("PT_DETACH");