From patchwork Tue Jun 3 11:53:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 1262 Received: (qmail 9166 invoked by alias); 3 Jun 2014 11:53:19 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 9157 invoked by uid 89); 3 Jun 2014 11:53:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Jun 2014 11:53:17 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s53BrEel022202 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 3 Jun 2014 07:53:14 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s53BrCPp013146; Tue, 3 Jun 2014 07:53:13 -0400 Message-ID: <538DB728.7080702@redhat.com> Date: Tue, 03 Jun 2014 12:53:12 +0100 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: Joel Brobecker CC: gdb-patches@sourceware.org Subject: [pushed] PR breakpoints/17000: user breakpoint not inserted if software-single-step at same location - another test References: <1401394280-14999-1-git-send-email-brobecker@adacore.com> <5387BFF0.6010208@redhat.com> <20140530122253.GC4289@adacore.com> <53887ED5.5050603@redhat.com> <20140530132659.GD4289@adacore.com> <20140530193549.GF4289@adacore.com> <538D05CC.8050608@redhat.com> <538D85A9.5010004@redhat.com> In-Reply-To: <538D85A9.5010004@redhat.com> On 06/03/2014 09:22 AM, Pedro Alves wrote: > On 06/03/2014 12:16 AM, Pedro Alves wrote: > >> Let me know what you think, and feel free to push if it >> looks OK. Tested on all combinations of >> native|gdbserver X hardware-|software- stepping. At least, >> I think I did. If not this exact version, some other minor >> variation. :-) > > Bah, I woke up realizing that the version I posted forgets to > clone the shadow buffer! Let me fix that and repost... > I managed to come up with a test that exposed this. Basically, it does: (gdb) disassemble test Dump of assembler code for function test: 0x0000000000400766 <+0>: push %rbp 0x0000000000400767 <+1>: mov %rsp,%rbp => 0x000000000040076a <+4>: nop 0x000000000040076b <+5>: nop 0x000000000040076c <+6>: pop %rbp 0x000000000040076d <+7>: retq End of assembler dump. (gdb) si& (gdb) del $bpnum (gdb) disassemble test Dump of assembler code for function test: 0x0000000000400766 <+0>: push %rbp 0x0000000000400767 <+1>: mov %rsp,%rbp 0x000000000040076a <+4>: nop => 0x000000000040076b <+5>: int3 0x000000000040076c <+6>: pop %rbp 0x000000000040076d <+7>: retq End of assembler dump. And note the bogus "int3" in the second disassemble output. The test actually fails in a different way currently against gdbserver: (gdb) PASS: gdb.base/sss-bp-on-user-bp-2.exp: define stepi_del_break stepi_del_break Cannot execute this command while the target is running. (gdb) FAIL: gdb.base/sss-bp-on-user-bp-2.exp: stepi_del_break The error is because GDB tried to remove the breakpoint from memory while the thread was running, and we can't talk to the server in the all-stop RSP until we get a stop reply, but in any case, GDB shouldn't even be attempting to remove the breakpoint, exactly because there was a sss breakpoint at the same address. I've added a kfail, and pushed it. 8<-------------- PR breakpoints/17000: user breakpoint not inserted if software-single-step at same location - test GDB gets confused when removing a software single-step breakpoint that is at the same address as another breakpoint. Add another kfailed test. gdb/testsuite/ 2014-06-03 Pedro Alves PR breakpoints/17000 * gdb.base/sss-bp-on-user-bp-2.c: New file. * gdb.base/sss-bp-on-user-bp-2.exp: New file. --- gdb/testsuite/ChangeLog | 6 ++ gdb/testsuite/gdb.base/sss-bp-on-user-bp-2.c | 29 +++++++ gdb/testsuite/gdb.base/sss-bp-on-user-bp-2.exp | 109 +++++++++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 gdb/testsuite/gdb.base/sss-bp-on-user-bp-2.c create mode 100644 gdb/testsuite/gdb.base/sss-bp-on-user-bp-2.exp diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 9ded6eb..644f5ac 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2014-06-03 Pedro Alves + + PR breakpoints/17000 + * gdb.base/sss-bp-on-user-bp-2.c: New file. + * gdb.base/sss-bp-on-user-bp-2.exp: New file. + 2014-06-02 Doug Evans * gdb.guile/scm-parameter.exp: New file. diff --git a/gdb/testsuite/gdb.base/sss-bp-on-user-bp-2.c b/gdb/testsuite/gdb.base/sss-bp-on-user-bp-2.c new file mode 100644 index 0000000..c3c26fe --- /dev/null +++ b/gdb/testsuite/gdb.base/sss-bp-on-user-bp-2.c @@ -0,0 +1,29 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2014 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +static void +test (void) +{ + label: asm (" nop"); label2: asm (" nop"); /* must be a single line */ +} + +int +main (void) +{ + test (); + return 0; +} diff --git a/gdb/testsuite/gdb.base/sss-bp-on-user-bp-2.exp b/gdb/testsuite/gdb.base/sss-bp-on-user-bp-2.exp new file mode 100644 index 0000000..a129bb7 --- /dev/null +++ b/gdb/testsuite/gdb.base/sss-bp-on-user-bp-2.exp @@ -0,0 +1,109 @@ +# Copyright (C) 2014 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test that GDB doesn't get confused in the following scenario +# (PR breakpoints/17000). Say, we have this program: +# +# => 0xff000001 INSN1 +# 0xff000002 INSN2 +# +# The PC currently points at INSN1. +# +# 1 - User sets a breakpoint at 0xff000002 (INSN2). +# +# 2 - User steps. On software single-step archs, this sets a software +# single-step breakpoint at 0xff000002 (INSN2) too. +# +# 3 - User deletes breakpoint (INSN2) before the single-step finishes. +# +# 4 - The single-step finishes, and GDB removes the single-step +# breakpoint. + +standard_testfile + +if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} { + return -1 +} + +if ![runto_main] { + fail "Can't run to main" + return 0 +} + +set line_re "\[^\r\n\]*" + +gdb_test "b test:label" "Breakpoint .*" +gdb_continue_to_breakpoint "run past setup" +delete_breakpoints + +# So we can precisely control breakpoint insertion order. +gdb_test_no_output "set breakpoint always-inserted on" + +# Capture disassembly output. PREFIX is used as test prefix. The +# current instruction indicator (=>) is stripped away. +proc disassemble { prefix } { + with_test_prefix "$prefix" { + set output [capture_command_output "disassemble test" ""] + return [string map {"=>" " "} $output] + } +} + +# Issue a stepi and immediately delete the user breakpoint that is set +# at the same address as the software single-step breakpoint. Do this +# in a user defined command, so that the stepi's trap doesn't have a +# chance to be handled before further input is processed. We then +# compare before/after disassembly. GDB should be able to handle +# deleting the user breakpoint before deleting the single-step +# breakpoint. E.g., we shouldn't see breakpoint instructions in the +# disassembly. + +set disasm_before [disassemble "before"] + +gdb_test "b test:label2" ".*" "set breakpoint where si will land" + +set test "define stepi_del_break" +gdb_test_multiple $test $test { + -re "Type commands for definition of \"stepi_del_break\".\r\nEnd with a line saying just \"end\".\r\n>$" { + gdb_test "si&\ndel \$bpnum\nend" "" $test + } +} + +set command "stepi_del_break" +set test $command +setup_kfail "breakpoints/17000" "*-*-*" +gdb_test_multiple $command $test { + -re "^$command\r\n$gdb_prompt " { + # Note no end anchor, because "si&" finishes and prints the + # current frame/line after the prompt is printed. + pass $test + } +} + +# Now consume the output of the finished "si&". +set test "si& finished" +gdb_test_multiple "" $test { + -re "must be a single line \\\*/\r\n" { + pass $test + } +} + +set disasm_after [disassemble "after"] + +set test "before/after disassembly matches" +if ![string compare $disasm_before $disasm_after] { + pass $test +} else { + fail $test +}