From 1f7c61b15fc33102975cc90f06aca43be1b781f2 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sat, 1 Aug 2020 15:44:50 -0700 Subject: [PATCH] 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. --- Libraries/LibDebug/DebugSession.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Libraries/LibDebug/DebugSession.cpp b/Libraries/LibDebug/DebugSession.cpp index 97d1d8d8f4a..c4dbc414d6b 100644 --- a/Libraries/LibDebug/DebugSession.cpp +++ b/Libraries/LibDebug/DebugSession.cpp @@ -38,6 +38,11 @@ DebugSession::DebugSession(int pid) DebugSession::~DebugSession() { + for (const auto& bp : m_breakpoints) { + disable_breakpoint(bp.key); + } + m_breakpoints.clear(); + if (!m_is_debugee_dead) { if (ptrace(PT_DETACH, m_debugee_pid, 0, 0) < 0) { perror("PT_DETACH");