Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Cagney <ac131313@cygnus.com>
To: gdb-patches@sources.redhat.com
Subject: [rfa:testsuite} Overhaul sizeof.exp
Date: Tue, 19 Feb 2002 15:17:00 -0000	[thread overview]
Message-ID: <3C72DCF7.5000908@cygnus.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 321 bytes --]

[oops, I posted this but to the wrong address.  Explains why no one saw it]

Hello,

This patch overhauls sizeof.exp adding more ``this could never fail
tests''.  In particular:

	checks char, signed char, unsigned char
	checks stores don't corrupt memory

Ok?  I've checked it in an unsigned char target (PPC).

Andrew


[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 7900 bytes --]

2002-02-16  Andrew Cagney  <ac131313@redhat.com>

	* gdb.base/sizeof.exp (get_valueof): Revise.  Check for signed and
	unsigned char.  Check for correctly sized writes.  Update copyright.

Index: gdb.base/call-ar-st.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/call-ar-st.exp,v
retrieving revision 1.11
diff -p -r1.11 call-ar-st.exp
*** call-ar-st.exp	2002/01/06 14:42:39	1.11
--- call-ar-st.exp	2002/02/17 00:41:08
***************
*** 1,4 ****
! #   Copyright 1998, 1999, 2000, 2001
  #   Free Software Foundation, Inc.
  
  # This program is free software; you can redistribute it and/or modify
--- 1,4 ----
! #   Copyright 1998, 1999, 2000, 2001, 2002
  #   Free Software Foundation, Inc.
  
  # This program is free software; you can redistribute it and/or modify
Index: gdb.base/sizeof.c
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/sizeof.c,v
retrieving revision 1.2
diff -p -r1.2 sizeof.c
*** sizeof.c	2000/08/02 22:13:01	1.2
--- sizeof.c	2002/02/17 00:41:08
***************
*** 1,8 ****
--- 1,90 ----
  #include <stdio.h>
  
+ typedef char padding[16];
+ 
+ struct {
+   padding p1;
+   char v;
+   padding p2;
+ } padding_char;
+ 
+ struct {
+   padding p1;
+   short v;
+   padding p2;
+ } padding_short;
+ 
+ struct {
+   padding p1;
+   int v;
+   padding p2;
+ } padding_int;
+ 
+ struct {
+   padding p1;
+   long v;
+   padding p2;
+ } padding_long;
+ 
+ struct {
+   padding p1;
+   long long v;
+   padding p2;
+ } padding_long_long;
+ 
+ struct {
+   padding p1;
+   float v;
+   padding p2;
+ } padding_float;
+ 
+ struct {
+   padding p1;
+   double v;
+   padding p2;
+ } padding_double;
+ 
+ struct {
+   padding p1;
+   long double v;
+   padding p2;
+ } padding_long_double;
+ 
+ static void
+ fill (void *buf, long sizeof_buf)
+ {
+   char *p = buf;
+   int i;
+   for (i = 0; i < sizeof_buf; i++)
+     p[i] = "The quick brown dingo jumped over the layzy dog."[i];
+ }
+ 
+ void
+ fill_structs (void)
+ {
+   fill (&padding_char.p1, sizeof (padding));
+   fill (&padding_char.p2, sizeof (padding));
+   fill (&padding_short.p1, sizeof (padding));
+   fill (&padding_short.p2, sizeof (padding));
+   fill (&padding_int.p1, sizeof (padding));
+   fill (&padding_int.p2, sizeof (padding));
+   fill (&padding_long.p1, sizeof (padding));
+   fill (&padding_long.p2, sizeof (padding));
+   fill (&padding_long_long.p1, sizeof (padding));
+   fill (&padding_long_long.p2, sizeof (padding));
+   fill (&padding_float.p1, sizeof (padding));
+   fill (&padding_float.p2, sizeof (padding));
+   fill (&padding_double.p1, sizeof (padding));
+   fill (&padding_double.p2, sizeof (padding));
+   fill (&padding_long_double.p1, sizeof (padding));
+   fill (&padding_long_double.p2, sizeof (padding));
+ }
+ 
  int
  main ()
  {
+   fill_structs ();
+ 
    printf ("sizeof (char) == %d\n", sizeof (char));
    printf ("sizeof (short) == %d\n", sizeof (short));
    printf ("sizeof (int) == %d\n", sizeof (int));
*************** main ()
*** 15,19 ****
--- 97,107 ----
    printf ("sizeof (float) == %d\n", sizeof (float));
    printf ("sizeof (double) == %d\n", sizeof (double));
    printf ("sizeof (long double) == %d\n", sizeof (long double));
+ 
+   /* Signed char?  */
+   printf ("valueof ((int) (char) -1) == %d\n", (int) (char) -1);
+   printf ("valueof ((int) (signed char) -1) == %d\n", (int) (signed char) -1);
+   printf ("valueof ((int) (unsigned char) -1) == %d\n", (int) (unsigned char) -1);
+ 
    return 0;
  }
Index: gdb.base/sizeof.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/sizeof.exp,v
retrieving revision 1.3
diff -p -r1.3 sizeof.exp
*** sizeof.exp	2001/03/06 08:21:51	1.3
--- sizeof.exp	2002/02/17 00:41:08
*************** if ![runto_main] then {
*** 56,77 ****
  # Query GDB for the size of various types
  #
  
! proc get_sizeof { type default } {
      global gdb_prompt
!     send_gdb "print/d sizeof (${type})\n"
      gdb_expect {
! 	-re "\\$\[0-9\]* = (\[0-9\]*).*$gdb_prompt $" {
! 	    set size $expect_out(1,string)
! 	    pass "get sizeof ${type} ($size)"
  	}
  	timeout {
  	    set size ${default}
! 	    fail "get sizeof ${type} (timeout)"
  	}
      }
!     return ${size}
  }
  
  set sizeof_char [get_sizeof "char" 1]
  set sizeof_short [get_sizeof "short" 2]
  set sizeof_int [get_sizeof "int" 4]
--- 56,83 ----
  # Query GDB for the size of various types
  #
  
! proc get_valueof { exp default } {
      global gdb_prompt
!     send_gdb "print/d ${exp}\n"
      gdb_expect {
! 	-re "\\$\[0-9\]* = (\[-\]*\[0-9\]*).*$gdb_prompt $" {
! 	    set val $expect_out(1,string)
! 	    pass "get value of ${exp} ($val)"
  	}
  	timeout {
  	    set size ${default}
! 	    fail "get value of ${exp} (timeout)"
  	}
      }
!     return ${val}
! }
! 
! proc get_sizeof { type default } {
!     return [get_valueof "sizeof (${type})" $default]
  }
  
+ gdb_test "next"
+ 
  set sizeof_char [get_sizeof "char" 1]
  set sizeof_short [get_sizeof "short" 2]
  set sizeof_int [get_sizeof "int" 4]
*************** set sizeof_float [get_sizeof "float" 4]
*** 85,91 ****
  set sizeof_double [get_sizeof "double" 8]
  set sizeof_long_double [get_sizeof "long double" 8]
  
- 
  #
  # Compare GDB's idea of types with the running program
  #
--- 91,96 ----
*************** proc check_sizeof { type size } {
*** 97,106 ****
  	return;
      }
  
!     set pat [string_to_regexp ${type}]
      send_gdb "next\n"
      gdb_expect {
! 	-re "sizeof \\(${pat}\\) == ${size}\[\r\n\].*$gdb_prompt $" {
  	    pass "check sizeof ${type} == ${size}"
  	}
  	-re ".*$gdb_prompt $" {
--- 102,111 ----
  	return;
      }
  
!     set pat [string_to_regexp "sizeof (${type}) == ${size}"]
      send_gdb "next\n"
      gdb_expect {
! 	-re "${pat}\[\r\n\].*$gdb_prompt $" {
  	    pass "check sizeof ${type} == ${size}"
  	}
  	-re ".*$gdb_prompt $" {
*************** check_sizeof "float" ${sizeof_float}
*** 125,130 ****
--- 130,188 ----
  check_sizeof "double" ${sizeof_double}
  check_sizeof "long double" ${sizeof_long_double}
  
+ proc check_valueof { exp val } {
+     global gdb_prompt
+ 
+     if [gdb_skip_stdio_test "check valueof $exp == $val"] {
+ 	return;
+     }
+ 
+     set pat [string_to_regexp "valueof (${exp}) == ${val}"]
+     send_gdb "next\n"
+     gdb_expect {
+ 	-re "${pat}\[\r\n\].*$gdb_prompt $" {
+ 	    pass "check valueof ${exp} == ${val}"
+ 	}
+ 	-re ".*$gdb_prompt $" {
+ 	    fail "check valueof ${exp} == ${val}"
+ 	}
+ 	timeout {
+ 	    fail "check valueof ${exp} == ${val} (timeout)"
+ 	}
+     }
+ }
+ 
+ # Check that GDB and the target agree over the sign of a character.
+ 
+ set signof_char [get_valueof "(int) (char) -1" -1]
+ set signof_signed_char [get_valueof "(int) (signed char) -1" -1]
+ set signof_unsigned_char [get_valueof "(int) (unsigned char) -1" -1]
+ 
+ check_valueof "(int) (char) -1" ${signof_char}
+ check_valueof "(int) (signed char) -1" ${signof_signed_char}
+ check_valueof "(int) (unsigned char) -1" ${signof_unsigned_char}
+ 
+ proc check_padding { type val } {
+     global gdb_prompt
+     gdb_test "set padding_${type}.v = ${val}"
+     gdb_test "print padding_${type}.p1" "= \"The quick brown \""
+     gdb_test "print/d padding_${type}.v = ${val}" "= ${val}"
+     gdb_test "print padding_${type}.p2" "\"The quick brown \".*"
+ }
+ 
+ # Check that GDB is managing to store a value in a struct field
+ # without corrupting the fields immediately adjacent to it.
+ 
+ check_padding "char" 1
+ check_padding "short" 2
+ check_padding "int" 4
+ check_padding "long" 4
+ check_padding "long_long" 8
+ 
+ # use multiples of two which can be represented exactly
+ check_padding "float" 1
+ check_padding "double" 2
+ check_padding "long_double" 4
  
  #
  # For reference, dump out the entire architecture

             reply	other threads:[~2002-02-19 23:17 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-19 15:17 Andrew Cagney [this message]
2002-02-19 15:46 Michael Elizabeth Chastain
2002-02-19 18:19 ` Andrew Cagney
2002-02-19 20:43 Michael Elizabeth Chastain
2002-02-21 14:03 ` Jim Blandy
2002-02-19 20:57 Michael Elizabeth Chastain
2002-02-20  6:57 ` Andrew Cagney
2002-02-20  7:21   ` Andrew Cagney
2002-02-20  8:19     ` Fernando Nasser
2002-02-20 17:57       ` Andrew Cagney
2002-02-20  8:16   ` Fernando Nasser
2002-02-20  8:51     ` Daniel Jacobowitz
2002-02-20  9:24       ` Fernando Nasser
2002-02-21 14:04       ` Jim Blandy
2002-02-21 14:23         ` Daniel Jacobowitz
2002-02-20  8:59 Michael Elizabeth Chastain
2002-02-20  9:17 Michael Elizabeth Chastain
2002-02-20  9:42 ` Fernando Nasser
2002-02-20 10:20 ` Andrew Cagney
2002-02-20  9:49 Michael Elizabeth Chastain
2002-02-20 10:06 ` Fernando Nasser
2002-02-20 10:12   ` Daniel Jacobowitz
2002-02-20 10:07 ` Richard Earnshaw
2002-02-20 10:07 ` Daniel Jacobowitz
2002-02-20 10:18   ` Fernando Nasser
2002-02-20 10:24 Michael Elizabeth Chastain
2002-02-20 11:48 ` Fernando Nasser

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=3C72DCF7.5000908@cygnus.com \
    --to=ac131313@cygnus.com \
    --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