Skip to content

Commit

Permalink
Propagate SIGTRAP to client during diversion
Browse files Browse the repository at this point in the history
Changes DiversionSession to propagate a SIGTRAP received by the target
process to the client, as a signal, when it was not produced by a
debugger breakpoint, a singlestep operation or a watchpoint.
  • Loading branch information
aarzilli authored and rocallahan committed Nov 21, 2020
1 parent 79ac37a commit 4f99ff0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ set(TESTS_WITH_PROGRAM
daemon_read
dconf_mock
dev_tty
diversion_sigtrap
diversion_syscall
dlopen
early_error
Expand Down
4 changes: 4 additions & 0 deletions src/DiversionSession.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ DiversionSession::DiversionResult DiversionSession::diversion_step(
if (t->stop_sig()) {
LOG(debug) << "Pending signal: " << t->get_siginfo();
result.break_status = diagnose_debugger_trap(t, command);
if (!result.break_status.breakpoint_hit && result.break_status.watchpoints_hit.empty() && !result.break_status.singlestep_complete && (t->stop_sig() == SIGTRAP)) {
result.break_status.signal = unique_ptr<siginfo_t>(new siginfo_t(t->get_siginfo()));
result.break_status.signal->si_signo = t->stop_sig();
}
LOG(debug) << "Diversion break at ip=" << (void*)t->ip().register_value()
<< "; break=" << result.break_status.breakpoint_hit
<< ", watch=" << !result.break_status.watchpoints_hit.empty()
Expand Down
18 changes: 18 additions & 0 deletions src/test/diversion_sigtrap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* -*- Mode: C; tab-width: 8; c-basic-offset: 2; indent-tabs-mode: nil; -*- */

#include "util.h"

static __attribute__((noinline)) void breakpoint(void) {
int break_here = 1;
(void)break_here;
}

static __attribute__((noinline)) int hardware_breakpoint(void) {
asm("int3;");
return 10;
}

int main(void) {
breakpoint();
hardware_breakpoint();
}
11 changes: 11 additions & 0 deletions src/test/diversion_sigtrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from util import *
import re, sys

send_gdb('b breakpoint')
expect_gdb('Breakpoint 1')

send_gdb('c')
expect_gdb('Breakpoint 1')

send_gdb('p hardware_breakpoint()')
expect_gdb('Program received signal SIGTRAP')
3 changes: 3 additions & 0 deletions src/test/diversion_sigtrap.run
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source `dirname $0`/util.sh
record $TESTNAME
debug_test

0 comments on commit 4f99ff0

Please sign in to comment.