Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Randolph Chung <randolph@tausq.org>
To: Andrew Cagney <cagney@gnu.org>
Cc: gdb-patches@sources.redhat.com
Subject: Re: [patch/RFA] multiarch INSTRUCTION_NULLIFIED
Date: Fri, 03 Dec 2004 21:40:00 -0000	[thread overview]
Message-ID: <20041203201903.GI6359@tausq.org> (raw)
In-Reply-To: <41B0ABC7.4020806@gnu.org>

> Anyway, more relevant, and as daniel asked, can it be done in assember? 
>  A starting point for that might be the gdb.asm test case which uses 
> assembly source code.

ok, how about this. it's in asm and it only tests the relevant edge
cases...

2004-12-03  Randolph Chung  <tausq@debian.org>

testsuite/
	* gdb.arch/pa-nullify.exp: New file.
	* gdb.arch/pa-nullify.s: New file.

--- /dev/null	2004-08-25 14:59:25.000000000 -0700
+++ pa-nullify.s	2004-12-02 08:40:46.342945888 -0800
@@ -0,0 +1,59 @@
+	.LEVEL 1.1
+	.text
+	.align 4
+.globl foo
+	.type	foo, @function
+foo:
+	.PROC
+	.CALLINFO FRAME=64,NO_CALLS,SAVE_SP,ENTRY_GR=3
+	.ENTRY
+	copy %r3,%r1
+	copy %r30,%r3
+	stwm %r1,64(%r30)
+	stw %r26,-36(%r3)
+	ldw -36(%r3),%r19
+	copy %r19,%r28
+	ldo 64(%r3),%r30
+	ldwm -64(%r30),%r3
+	bv,n %r0(%r2)
+	.EXIT
+	.PROCEND
+
+.globl bar
+	.type	bar, @function
+bar:
+	.PROC
+	.CALLINFO FRAME=64,NO_CALLS,SAVE_SP,ENTRY_GR=3
+	.ENTRY
+	copy %r3,%r1
+	copy %r30,%r3
+	stwm %r1,64(%r30)
+	ldo 64(%r3),%r30
+	ldwm -64(%r30),%r3
+	bv,n %r0(%r2)
+	.EXIT
+	.PROCEND
+
+.globl main
+	.type	main, @function
+main:
+	.PROC
+	.CALLINFO FRAME=64,CALLS,SAVE_RP,SAVE_SP,ENTRY_GR=3
+	.ENTRY
+	stw %r2,-20(%r30)
+	copy %r3,%r1
+	copy %r30,%r3
+	stwm %r1,64(%r30)
+	stw %r26,-36(%r3)
+	stw %r25,-40(%r3)
+	ldw -36(%r3),%r26
+	bl foo,%r2
+	nop
+	copy %r28,%r19
+	copy %r19,%r28
+	ldw -20(%r3),%r2
+	ldo 64(%r3),%r30
+	ldwm -64(%r30),%r3
+	bv,n %r0(%r2)
+	.EXIT
+	.PROCEND
--- /dev/null	2004-08-25 14:59:25.000000000 -0700
+++ pa-nullify.exp	2004-12-03 12:16:52.044063224 -0800
@@ -0,0 +1,151 @@
+# Copyright 2004 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 2 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  
+#
+# This file is part of the gdb testsuite.
+
+if $tracelevel {
+    strace $tracelevel
+}
+
+set prms_id 0
+set bug_id 0
+
+# Test handling of nullified instructions for the pa target.
+
+if ![istarget "hppa*-*-*"] then {
+    verbose "Skipping hppa nullification tests."
+    return
+}
+
+set testfile "pa-nullify"
+set srcfile ${testfile}.s
+set binfile ${objdir}/${subdir}/${testfile}
+set gcorefile ${objdir}/${subdir}/${testfile}.gcore
+
+if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {}] != "" } {
+    unsupported "Testcase compile failed."
+    return -1
+}
+
+gdb_exit
+gdb_start
+gdb_reinitialize_dir $srcdir/$subdir
+gdb_load ${binfile}
+
+# In the first test, we do a "step" on a function whose last instruction 
+# contains a branch-with-nullify.  The instruction in the delay slot belongs
+# to the next function.  We verify that when we step off the first function
+# that we end up back at the caller and not at the second instruction.
+
+gdb_breakpoint foo
+gdb_test "run" ".*Breakpoint 1, .* in foo.*" "Breakpoint at foo"
+
+set test "stepi till main"
+gdb_test_multiple "stepi" "${test}" {
+  -re ".*in foo.*$gdb_prompt $" {
+    send_gdb "stepi\n"
+    exp_continue -continue_timer
+  }
+  -re ".*in bar.*$gdb_prompt $" {
+    fail "stepped into bar"
+  }
+  -re ".*in main.*$gdb_prompt $" {
+    pass "stepped into main"
+  }
+}
+
+# In the second test, we verify that we can get a proper backtrace 
+# even when we are in a nullified instruction that belongs to the next function.
+# We also verify that when stepping over a branch-with-nullify insn that we 
+# stay on the same insn for two steps.
+
+proc get_addr_of_sym { sym } {
+  set addr 0
+  global gdb_prompt
+  global hex
+
+  send_gdb "print $sym\n"
+  gdb_test_multiple "print $sym" "Get address of $sym" {
+    -re ".*($hex) <$sym>.*$gdb_prompt $" {
+      set addr $expect_out(1,string)
+      pass "got address of $sym = $addr"
+    }
+  }
+
+  return $addr
+}
+
+if { ! [ runto_main ] } then { gdb_suppress_tests; }
+
+set foo [get_addr_of_sym "foo"]
+set bar [get_addr_of_sym "bar"]
+set foo_last [expr $bar - 4]
+
+gdb_breakpoint "*$foo_last"
+
+gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*"
+gdb_test "backtrace" ".*in foo.*in main.*" "Backtrace from last insn in foo"
+gdb_test "stepi" ".*in foo.*" "stepi to nullified instruction stays in foo"
+gdb_test "backtrace" ".*in foo.*in main.*" "Backtrace from nullified insn"
+gdb_test "stepi" ".*in main.*" "stepi to main"
+
+# In the third test, we verify that backtraces from nullified instructions
+# work even in coredumps
+
+proc gen_core { test } {
+  global gcorefile
+  global gdb_prompt
+  set gcore_works 0
+  set escapedfilename [string_to_regexp $gcorefile]
+
+  gdb_test_multiple "gcore $gcorefile" "gcore" {
+    -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" {
+      pass "$test: gcore"
+      set gcore_works 1
+    }
+    -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
+      unsupported "gcore"
+    }
+  }
+
+  return $gcore_works
+}
+
+proc test_core_bt { test } {
+  global gcorefile
+
+  gdb_test "core $gcorefile" "Core was generated by.*" \
+    "$test: load core file" "A program is being debugged already.*" "y"
+
+  gdb_test "backtrace" ".*in foo.*in main.*" "$test: backtrace in gcore"
+}
+
+set test "core at last insn in foo"
+if { ! [ runto_main ] } then { gdb_suppress_tests; }
+gdb_breakpoint "*$foo_last"
+gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*"
+if [gen_core $test] {
+  test_core_bt $test
+}
+
+set test "core at nullified insn"
+if { ! [ runto_main ] } then { gdb_suppress_tests; }
+gdb_breakpoint "*$foo_last"
+gdb_test "continue" "Breakpoint \[0-9\]*,.* in foo.*"
+gdb_test "stepi" ".*in foo.*"
+if [gen_core $test] {
+  test_core_bt $test
+}


  parent reply	other threads:[~2004-12-03 20:19 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-18  0:02 Randolph Chung
2004-11-18 14:26 ` Andrew Cagney
2004-11-18 16:21   ` Randolph Chung
2004-11-18 16:56     ` Mark Kettenis
2004-11-19  9:25       ` Orjan Friberg
2004-11-23 17:50       ` Randolph Chung
2004-11-23 19:33         ` Mark Kettenis
2004-11-28 17:26         ` Andrew Cagney
2004-11-28 18:41           ` Randolph Chung
2004-11-28 19:55             ` Andrew Cagney
2004-11-29  3:30               ` Randolph Chung
2004-11-29 15:12                 ` Andrew Cagney
2004-11-30  6:56                   ` Randolph Chung
2004-11-30 14:51                     ` Andrew Cagney
2004-11-30 16:44                       ` Randolph Chung
2004-11-30 16:59                         ` Andrew Cagney
2004-11-30 17:38                           ` Randolph Chung
2004-12-01 21:29                             ` Andrew Cagney
2004-12-01 22:33                               ` Randolph Chung
2004-12-01 23:32                                 ` Andrew Cagney
2004-12-02  5:24                                   ` Randolph Chung
2004-12-02 14:27                                     ` Daniel Jacobowitz
2004-12-03 18:11                                     ` Andrew Cagney
2004-12-03 18:15                                       ` Randolph Chung
2004-12-03 18:57                                         ` Daniel Jacobowitz
2004-12-03 19:57                                           ` Randolph Chung
2004-12-03 21:40                                       ` Randolph Chung [this message]
2004-12-03 21:58                                         ` Andrew Cagney
2004-12-03 22:52                                           ` Daniel Jacobowitz
2004-12-04  0:00                                           ` Randolph Chung
2004-12-04  0:55                                           ` Randolph Chung
2004-12-04 11:27                                             ` Mark Kettenis
2004-12-01  6:19                   ` Randolph Chung
2004-12-01 17:11                     ` Daniel Jacobowitz
2004-12-01 17:17                       ` Randolph Chung
2004-12-01 17:19                         ` Daniel Jacobowitz
2004-12-01 17:25                           ` Randolph Chung
2004-12-01 17:28                             ` Daniel Jacobowitz
2004-12-01 17:30                               ` Randolph Chung
2004-12-01 17:35                               ` Randolph Chung
2004-12-01 18:14                                 ` Randolph Chung
2004-12-01 21:25                       ` Andrew Cagney
2004-12-01 13:32 Paul Schlie
2004-12-01 16:25 Randolph Chung

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20041203201903.GI6359@tausq.org \
    --to=randolph@tausq.org \
    --cc=cagney@gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox