From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28713 invoked by alias); 20 Feb 2002 02:19:09 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 28644 invoked from network); 20 Feb 2002 02:19:06 -0000 Received: from unknown (HELO localhost.redhat.com) (24.112.135.44) by sources.redhat.com with SMTP; 20 Feb 2002 02:19:06 -0000 Received: from cygnus.com (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id BD7EB3D12; Tue, 19 Feb 2002 21:19:05 -0500 (EST) Message-ID: <3C730799.4050201@cygnus.com> Date: Tue, 19 Feb 2002 18:19:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:0.9.8) Gecko/20020210 X-Accept-Language: en-us MIME-Version: 1.0 To: Michael Elizabeth Chastain Cc: gdb-patches@sources.redhat.com Subject: Re: [rfa:testsuite} Overhaul sizeof.exp References: <200202192346.g1JNk6730384@duracef.shout.net> Content-Type: multipart/mixed; boundary="------------000300030605080106010205" X-SW-Source: 2002-02/txt/msg00517.txt.bz2 This is a multi-part message in MIME format. --------------000300030605080106010205 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1901 > A nit: there is an extraneous change to call-ar-st.exp. How did that sneak its way in :-( Ulgh, I updated the copyright on the wrong file (I'll try to blame emacs ...). > Bigger nit: the ChangeLog says that it's about sizeof.exp, but the patch > includes changes to sizeof.c. Will fix. > Here is a log excerpt: > > # target=native, host=i686-pc-linux-gnu%rh-7.2, gdb=HEAD%2002-02-16, gcc=3.0.3, goption=-gstabs+ > print padding_long_double.p1^M > $35 = "The quick brown "^M > (gdb) PASS: gdb.base/sizeof.exp: print padding_long_double.p1 > print/d padding_long_double.v = 4^M > $36 = 2523330444660750855469793280^M > (gdb) FAIL: gdb.base/sizeof.exp: print/d padding_long_double.v = 4 > print padding_long_double.p2^M > $37 = "The quick brown "^M > (gdb) PASS: gdb.base/sizeof.exp: print padding_long_double.p2 > > All 10 gdb.log files have the same constant value for $36. (evil laughter :-) The print/d statement was wrong - it should not include the assignment and instead should look like: (gdb) PASS: gdb.base/sizeof.exp: print padding_double.p2 set padding_long_double.v = 4 (gdb) PASS: gdb.base/sizeof.exp: set padding_long_double.v = 4 print padding_long_double.p1 $35 = "The quick brown " (gdb) PASS: gdb.base/sizeof.exp: print padding_long_double.p1 print/d padding_long_double.v $36 = 4 (gdb) PASS: gdb.base/sizeof.exp: print/d padding_long_double.v print padding_long_double.p2 $37 = "The quick brown " (gdb) PASS: gdb.base/sizeof.exp: print padding_long_double.p2 The attached includes that fixes. Unfortunatly it doesn't address the x86 problem. Looking at printcmd.c:print_scalar_formatted() the function behaves differently when sizeof (host LONGEST) < sizeof (target type) (i.e. x86) :-( I think this a very long standing bug. The problem I guess is what to do short term with this part of the test. sigh, Andrew (updated change attached) --------------000300030605080106010205 Content-Type: text/plain; name="diffs" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="diffs" Content-length: 7424 2002-02-19 Andrew Cagney * gdb.base/sizeof.c (main): Call fill_structs. Print value of signed, unsigned and straight char. (padding_char, padding_short, padding_int, padding_long, padding_long_long, padding_float, padding_double, padding_long_double): New global variables. (fill, fill_structs): New functions. * gdb.base/sizeof.exp: Check for signed and unsigned char. Check for correctly sized writes. Update copyright. (get_valueof): New procedure. (get_sizeof): Call get_valueof. (check_valueof): New procedure. (check_padding): New procedure. Index: gdb.base/sizeof.c =================================================================== RCS file: /cvs/src/src/gdb/testsuite/gdb.base/sizeof.c,v retrieving revision 1.2 diff -u -r1.2 sizeof.c --- sizeof.c 2000/08/02 22:13:01 1.2 +++ sizeof.c 2002/02/20 01:49:56 @@ -1,8 +1,105 @@ #include +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.v, sizeof (padding_char.v)); + fill (&padding_char.p2, sizeof (padding)); + + fill (&padding_short.p1, sizeof (padding)); + fill (&padding_short.v, sizeof (padding_short.v)); + fill (&padding_short.p2, sizeof (padding)); + + fill (&padding_int.p1, sizeof (padding)); + fill (&padding_int.v, sizeof (padding_int.v)); + fill (&padding_int.p2, sizeof (padding)); + + fill (&padding_long.p1, sizeof (padding)); + fill (&padding_long.v, sizeof (padding_long.v)); + fill (&padding_long.p2, sizeof (padding)); + + fill (&padding_long_long.p1, sizeof (padding)); + fill (&padding_long_long.v, sizeof (padding_long_long.v)); + fill (&padding_long_long.p2, sizeof (padding)); + + fill (&padding_float.p1, sizeof (padding)); + fill (&padding_float.v, sizeof (padding_float.v)); + fill (&padding_float.p2, sizeof (padding)); + + fill (&padding_double.p1, sizeof (padding)); + fill (&padding_double.v, sizeof (padding_double.v)); + fill (&padding_double.p2, sizeof (padding)); + + fill (&padding_long_double.p1, sizeof (padding)); + fill (&padding_long_double.v, sizeof (padding_long_double.v)); + 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)); @@ -15,5 +112,11 @@ 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 -u -r1.3 sizeof.exp --- sizeof.exp 2001/03/06 08:21:51 1.3 +++ sizeof.exp 2002/02/20 01:49:56 @@ -1,4 +1,4 @@ -# Copyright 2000 Free Software Foundation, Inc. +# Copyright 2000, 2002 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 @@ -56,22 +56,28 @@ # Query GDB for the size of various types # -proc get_sizeof { type default } { +proc get_valueof { exp default } { global gdb_prompt - send_gdb "print/d sizeof (${type})\n" + send_gdb "print/d ${exp}\n" gdb_expect { - -re "\\$\[0-9\]* = (\[0-9\]*).*$gdb_prompt $" { - set size $expect_out(1,string) - pass "get sizeof ${type} ($size)" + -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 sizeof ${type} (timeout)" + fail "get value of ${exp} (timeout)" } } - return ${size} + 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] @@ -85,7 +91,6 @@ 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 # @@ -97,10 +102,10 @@ return; } - set pat [string_to_regexp ${type}] + set pat [string_to_regexp "sizeof (${type}) == ${size}"] send_gdb "next\n" gdb_expect { - -re "sizeof \\(${pat}\\) == ${size}\[\r\n\].*$gdb_prompt $" { + -re "${pat}\[\r\n\].*$gdb_prompt $" { pass "check sizeof ${type} == ${size}" } -re ".*$gdb_prompt $" { @@ -125,6 +130,59 @@ 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}" + 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 --------------000300030605080106010205--