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

Randolph Chung wrote:
>>PPS: A gdb.arch/ addition to tickle the basic edge case would be a 
>>helpful way of capturing this knowledge.
> 
> 
> how about this... my first gdb testcase, so hopefully i didn't do
> anything too wrong :)
> 
> 74 PASSes, 3 FAILs with the old code (assuming the instruction_nullified
> logic is removed). 77 PASSes with my previous patch.
> 
> randolph
> 
> 
> 2004-12-01  Randolph Chung  <tausq@debian.org>
> 
> 	* gdb.arch/pa-nullify.exp: New file.
> 	* gdb.arch/pa-nullify.c: New file.

> +send_gdb "print foo\n"
> +gdb_expect {
> +  -re ".* = {int \\(int\\)} ($hex) <foo>.*$gdb_prompt $" {
> +    set baddr $expect_out(1,string)
> +    verbose "Breakpoint address at $baddr"
> +    pass "print foo = $baddr"
> +  }
> +  default {
> +    fail "print foo"
> +    gdb_suppress_tests
> +  } timeout {
> +    fail "cannot get address of foo (timed out)."
> +    gdb_suppress_tests
> +  }
> +}

I'd use gdb_test_multiple: it's more robust and handles more cases when 
things go wrong; and we're trying to eliminate the old style (yes, there 
is no marker to warn you of this, sigh).  It should be a drop-in 
replacement and easy to fix.

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.

Andrew

> +gdb_breakpoint "*$baddr"
> +
> +gdb_test "display /i \$pc" "1: x/i +\\\$pc.*" "display /i \$pc"
> +gdb_test "continue" ".*Breakpoint \[0-9\], foo \\(x=1\\) at .*pa-nullify.c:23.*" "break at first insn of foo"
> +
> +set done 0
> +set iter 0
> +while { $done == 0 && $iter < 20 } {
> +  send_gdb "backtrace\n"
> +  gdb_expect {
> +    -re ".*foo \\(x=.*\\).* main \\(.*\\).*$gdb_prompt $" {
> +      pass "backtrace from foo"
> +    }
> +    -re "$gdb_prompt $" {
> +      fail "backtrace from foo"
> +      gdb_suppress_tests
> +    } 
> +    timeout {
> +      fail "(timeout) backtrace from foo"
> +      gdb_suppress_tests
> +    }
> +  }
> +
> +  send_gdb "stepi\n"
> +  gdb_expect {
> +     -re ".*: x/i +\\\$pc.*:\[ \t\]+(.*)\r.*$gdb_prompt $" {
> +       set insn $expect_out(1,string)
> +       pass "x/i \$pc = $insn"
> +     } timeout {
> +       fail "(timeout) x/i \$pc"
> +       gdb_suppress_tests
> +       break
> +     }
> +  }
> +
> +  incr iter
> +
> +  if { $insn == "bv,n r0(rp)" } {
> +    pass "found bv,n insn"
> +    set done 1
> +  }
> +}
> +
> +send_gdb "stepi\n"
> +gdb_expect {
> +  -re ".*bv,n r0\\(rp\\)\r.*$gdb_prompt $" {
> +    pass "restep on nullified instruction"
> +  } 
> +  -re ".*bar.*\r.*x/i.*bar.*\r.*$gdb_prompt $" {
> +    fail "step on nullification instruction ended in next function"
> +  }
> +  timeout {
> +    fail "(timeout) restep on nullified instruction"
> +  } 
> +}
> +incr iter
> +
> +# Lastly, we do a single step through each instruction and generate a core file.
> +# Then, load the core file and verify that we can get a proper backtrace.
> +
> +if ![isnative] then {
> +  verbose "skipping core file tests on non-native configuration"
> +  return
> +}
> +
> +send_gdb "undisplay 1\n"
> +
> +proc do_core_test { count } {
> +  global gcorefile
> +  global gdb_prompt
> +  global hex
> +
> +  if { ! [ runto_main ] } then { gdb_suppress_tests; }
> +
> +  set baddr "0"
> +  send_gdb "print foo\n"
> +  gdb_expect {
> +    -re ".* = {int \\(int\\)} ($hex) <foo>.*$gdb_prompt $" {
> +      set baddr $expect_out(1,string)
> +      verbose "Breakpoint address at $baddr"
> +      pass "print foo = $baddr #$count"
> +    }
> +    default {
> +      fail "print foo #$count"
> +      gdb_suppress_tests
> +    } 
> +    timeout {
> +      fail "cannot get address of foo (timed out). #$count"
> +      gdb_suppress_tests
> +    }
> +  }
> +  gdb_breakpoint "*$baddr"
> +
> +  gdb_test "continue" ".*Breakpoint \[0-9\]*, foo \\(x=1\\) at .*pa-nullify.c:23.*" "break at first insn of foo #$count"
> +
> +  gdb_test "si $count" 
> +
> +  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 "gcore #$count"
> +	set gcore_works 1
> +    }
> +    -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" {
> +	unsupported "gcore"
> +    }
> +  }
> +
> +  if { $gcore_works } {
> +    gdb_test "core $gcorefile" "Core was generated by.*" \
> +      "load core file #$count" "A program is being debugged already.*" "y"
> +
> +    send_gdb "backtrace\n"
> +    gdb_expect {
> +      -re ".*foo \\(x=.*\\).* main \\(.*\\).*$gdb_prompt $" {
> +        pass "backtrace from foo #$count"
> +      }
> +      -re "$gdb_prompt $" {
> +        fail "backtrace from foo #$count"
> +        gdb_suppress_tests
> +      } 
> +      timeout {
> +        fail "(timeout) backtrace from foo in gcore #$count"
> +        gdb_suppress_tests
> +      }
> +    }
> +  }
> +}
> +
> +for { set i 1 } { $i <= $iter } {incr i} {
> +  do_core_test $i
> +}
> --- /dev/null	2004-08-25 14:59:25.000000000 -0700
> +++ pa-nullify.c	2004-12-01 21:19:51.324347136 -0800
> @@ -0,0 +1,30 @@
> +/* PA nullification test program.
> +
> +   Copyright 2004 Free Software Foundation, Inc.
> +
> +   This file is part of GDB.
> +
> +   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.  */
> +
> +int foo(int x)
> +{ return x; }
> +
> +void bar(void) { }
> +
> +int main(int argc, char **argv)
> +{
> +	return foo(argc);
> +}
> 


  parent reply	other threads:[~2004-12-03 18:11 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 [this message]
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
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=41B0ABC7.4020806@gnu.org \
    --to=cagney@gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    --cc=randolph@tausq.org \
    /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