From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2725 invoked by alias); 7 Sep 2009 04:11:01 -0000 Received: (qmail 2709 invoked by uid 22791); 7 Sep 2009 04:10:59 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_31,J_CHICKENPOX_51,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 07 Sep 2009 04:10:49 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n874AlFI003579 for ; Mon, 7 Sep 2009 00:10:47 -0400 Received: from host0.dyn.jankratochvil.net (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n874AgOH021017 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 7 Sep 2009 00:10:46 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id n874AgYI026087 for ; Mon, 7 Sep 2009 06:10:42 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.3/Submit) id n874Ae1x026081 for gdb-patches@sourceware.org; Mon, 7 Sep 2009 06:10:40 +0200 Date: Mon, 07 Sep 2009 04:11:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] [ia64] Fix (#2) shadowing of breakpoints [testcase fixup] Message-ID: <20090907041040.GA25651@host0.dyn.jankratochvil.net> References: <20090905185856.GA16389@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090905185856.GA16389@host0.dyn.jankratochvil.net> User-Agent: Mutt/1.5.19 (2009-01-05) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-09/txt/msg00152.txt.bz2 [ Fixed testcase forgotten former-duplicate test. ] Hi, found my previous fix was incomplete: [patch] ia64: Fix breakpoints memory shadow http://sourceware.org/ml/gdb-patches/2008-10/msg00678.html http://sourceware.org/ml/gdb-patches/2008-11/msg00001.html Hiding of breakpoints in multiple slots of a single bundle could fail with "set breakpoint always-inserted on": original code: 0x4000000000000690 : [MII] st4.rel [r2]=r14 0x4000000000000691 : mov r14=2;; 0x4000000000000692 : nop.i 0x0 displayed code: 0x4000000000000690 : [MII] st4.rel [r2]=r14 0x4000000000000691 : break.i 0xccccc;; 0x4000000000000692 : nop.i 0x0 The insert breakpoints must read the memory in a both shadowed and unshadowed way for the two different use cases there. I think there is no guarantee of order of restoration of shadow_contents so its content must be always fully breakpoint-free. Regression tested on ia64-rhel54-linux-gnu together with the next patch. Patch has no code changes on non-ia64 arches. A bit weird VAL error handling is going to be fixed up in the next patch. Thanks, Jan gdb/ 2009-09-05 Jan Kratochvil Fix ia64 shadowing of breakpoints in multiple slots of a single bundle. * ia64-tdep.c (ia64_memory_insert_breakpoint): New call of make_show_memory_breakpoints_cleanup with parameter 0. Move the reading of SHADOW_CONTENTS to this memory state point of code. gdb/testsuite/ 2009-09-07 Jan Kratochvil * gdb.base/breakpoint-shadow.exp (Second breakpoint placed): Initialize $bpt2address. (Second breakpoint address is valid on ia64) (ia64 breakpoint in the Second breakpoint bundle): New. --- gdb/ia64-tdep.c +++ gdb/ia64-tdep.c @@ -622,13 +622,28 @@ ia64_memory_insert_breakpoint (struct gdbarch *gdbarch, addr &= ~0x0f; + /* Enable the automatic memory restoration from breakpoints while + we read our instruction bundle for the purpose of SHADOW_CONTENTS. + Otherwise, we could possibly store into the shadow parts of the adjacent + placed breakpoints. It is due to our SHADOW_CONTENTS overlapping the real + breakpoint instruction bits region. */ + cleanup = make_show_memory_breakpoints_cleanup (0); + val = target_read_memory (addr, bundle, BUNDLE_LEN); + + /* Slot number 2 may skip at most 2 bytes at the beginning. */ + bp_tgt->shadow_len = BUNDLE_LEN - 2; + + /* Store the whole bundle, except for the initial skipped bytes by the slot + number interpreted as bytes offset in PLACED_ADDRESS. */ + memcpy (bp_tgt->shadow_contents, bundle + slotnum, bp_tgt->shadow_len); + /* Disable the automatic memory restoration from breakpoints while we read our instruction bundle. Otherwise, the general restoration mechanism kicks in and we would possibly remove parts of the adjacent placed breakpoints. It is due to our SHADOW_CONTENTS overlapping the real breakpoint instruction bits region. */ - cleanup = make_show_memory_breakpoints_cleanup (1); - val = target_read_memory (addr, bundle, BUNDLE_LEN); + make_show_memory_breakpoints_cleanup (1); + val |= target_read_memory (addr, bundle, BUNDLE_LEN); /* Check for L type instruction in slot 1, if present then bump up the slot number to the slot 2. */ @@ -636,13 +651,6 @@ ia64_memory_insert_breakpoint (struct gdbarch *gdbarch, if (slotnum == 1 && template_encoding_table[template][slotnum] == L) slotnum = 2; - /* Slot number 2 may skip at most 2 bytes at the beginning. */ - bp_tgt->placed_size = bp_tgt->shadow_len = BUNDLE_LEN - 2; - - /* Store the whole bundle, except for the initial skipped bytes by the slot - number interpreted as bytes offset in PLACED_ADDRESS. */ - memcpy (bp_tgt->shadow_contents, bundle + slotnum, bp_tgt->shadow_len); - /* Breakpoints already present in the code will get deteacted and not get reinserted by bp_loc_is_permanent. Multiple breakpoints at the same location cannot induce the internal error as they are optimized into @@ -654,6 +662,8 @@ ia64_memory_insert_breakpoint (struct gdbarch *gdbarch, paddress (gdbarch, bp_tgt->placed_address)); replace_slotN_contents (bundle, IA64_BREAKPOINT, slotnum); + bp_tgt->placed_size = bp_tgt->shadow_len; + if (val == 0) val = target_write_memory (addr + slotnum, bundle + slotnum, bp_tgt->shadow_len); --- gdb/testsuite/gdb.base/breakpoint-shadow.exp +++ gdb/testsuite/gdb.base/breakpoint-shadow.exp @@ -48,7 +48,26 @@ gdb_test_multiple "disass main" $test { } gdb_test "b [gdb_get_line_number "break-first"]" "Breakpoint \[0-9\] at .*" "First breakpoint placed" -gdb_test "b [gdb_get_line_number "break-second"]" "Breakpoint \[0-9\] at .*" "Second breakpoint placed" +set test "Second breakpoint placed" +gdb_test_multiple "b [gdb_get_line_number "break-second"]" $test { + -re "Breakpoint \[0-9\] at (0x\[0-9a-f\]*):.*" { + pass $test + set bpt2address $expect_out(1,string) + } +} + +if [istarget "ia64-*-*"] then { + # Unoptimized code should not use the 3rd slot for the first instruction of + # a source line. + set test "Second breakpoint address is valid on ia64" + if [string match "*\[01\]" $bpt2address] { + pass $test + + gdb_test "b *($bpt2address + 1)" "Breakpoint \[0-9\] at .*" "ia64 breakpoint in the Second breakpoint bundle" + } else { + unresolved $test + } +} set test "disassembly with breakpoints" gdb_test_multiple "disass main" $test {