Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jim Blandy <jimb@zwingli.cygnus.com>
To: Daniel Jacobowitz <drow@mvista.com>
Cc: gdb-patches@sources.redhat.com
Subject: Re: RFA: MI tests: tolerate prototypes
Date: Tue, 05 Feb 2002 15:54:00 -0000	[thread overview]
Message-ID: <npsn8fpjor.fsf@zwingli.cygnus.com> (raw)
In-Reply-To: <20020203180133.C26302@nevyn.them.org>


Daniel Jacobowitz <drow@mvista.com> writes:
> On Sun, Feb 03, 2002 at 04:06:09PM -0500, Jim Blandy wrote:
> > 
> > Sun Feb  3 12:56:38 2002  Jim Blandy  <jimb@seadog.cygnus.com>
> > 
> > 	* mi-var-child.exp ("get children of struct_declarations", "get
> > 	children of struct_declarations.s2.u2.u1s2", "get children of
> > 	weird"): Tolerate argument types when they appear in function
> > 	types.  (Dwarf 2 includes prototype info; STABS does not.)
> > 	* mi0-var-child.exp: Same.
> 
> Just out of curiousity... does the stabs information really not contain
> this data, or are we just not recovering it?  Could you give an
> example?

It really doesn't contain it.  Check out the test program below.  Here
are the stabs for `prototyped_func' and `non_prototyped_func':

        .stabs  "prototyped_func:F(0,1)",36,0,3,prototyped_func
        .stabs  "f:p(0,14)",160,0,2,8
        .stabs  "s:p(0,1)",160,0,2,12
        .stabs  "s:(0,8)",128,0,2,-2
        .stabs  "",36,0,0,.Lscope0-prototyped_func

        .stabs  "non_prototyped_func:F(0,1)",36,0,11,non_prototyped_func
        .stabs  "f:p(0,15)",160,0,9,8
        .stabs  "s:p(0,1)",160,0,10,16
        .stabs  "f:(0,14)",128,0,9,-8
        .stabs  "s:(0,8)",128,0,10,-10
        .stabs  "",36,0,0,.Lscope1-non_prototyped_func

Notice that the types given in the functions' stabs are identical ---
`function returning int' --- even though one has type "prototyped
function returning int" and the other has type "non-prototyped
function returning int".

If you look at the stabs for the two function pointer variables, you
can see the problem even more easily:

        .stabs  "prototyped_fptr:G(0,23)=*(0,24)=f(0,1)",32,0,15,0
        .stabs  "non_prototyped_fptr:G(0,23)",32,0,16,0

The type info here for these functions is identical, even though you
couldn't even pass the `f' argument to (*prototyped_fptr) correctly
given this info.  (You'd pass a double, while it expects a float.)

It just so happens that almost every ABI tolerates smaller ints being
extended to full ints, so the problems aren't so bad there.  But
you'll still have problems passing ints to prototyped functions
expecting `long long' arguments, on machines where `long long' is
larger than `int'; you won't know that you need to promote them.

I was thinking that you could use the presence of the double stabs to
at least infer that a function was declared *without* a prototyped,
even if you couldn't use it to reliably detect those declared *with*
prototypes.  But look at the stabs for prototyped_func; it duplicates
the entry for 's', even though it's a prototyped function, and the
"passed-as" and "used-as" types are the same.

Anyway, there's a standard syntax for prototyped function types
defined in the STABS manual.  GDB even reads it.  If GCC would just
emit it, things would be better.


$ cat proto.c
int
prototyped_func (float f, short s)
{
  return f + s;
}

int
non_prototyped_func (f, s)
     float f;
     short s;
{
  return f + s;
}

int (*prototyped_fptr) (float f, short s);
int (*non_prototyped_fptr) (float f, short s);

int
baz (int i)
{
  return i;
}


int qux (i)
     int i;
{
  return i;
}
$ gcc -save-temps -g -c proto.c
$ cat proto.s
        .file   "proto.i"
        .stabs  "/home/jimb/gnupro/play/",100,0,0,.Ltext0
        .stabs  "proto.i",100,0,0,.Ltext0
        .text
.Ltext0:
        .stabs  "gcc2_compiled.",60,0,0,0
        .stabs  "int:t(0,1)=r(0,1);-2147483648;2147483647;",128,0,0,0
        .stabs  "char:t(0,2)=r(0,2);0;127;",128,0,0,0
        .stabs  "long int:t(0,3)=r(0,3);-2147483648;2147483647;",128,0,0,0
        .stabs  "unsigned int:t(0,4)=r(0,4);000000000000000000000000;000000000000037777777777;",128,0,0,0
        .stabs  "long unsigned int:t(0,5)=r(0,5);000000000000000000000000;000000000000037777777777;",128,0,0,0
        .stabs  "long long int:t(0,6)=@s64;r(0,6);001000000000000000000000;000777777777777777777777;",128,0,0,0
        .stabs  "long long unsigned int:t(0,7)=@s64;r(0,7);000000000000000000000000;001777777777777777777777;",128,0,0,0
        .stabs  "short int:t(0,8)=@s16;r(0,8);-32768;32767;",128,0,0,0
        .stabs  "short unsigned int:t(0,9)=@s16;r(0,9);0;65535;",128,0,0,0
        .stabs  "signed char:t(0,10)=@s8;r(0,10);-128;127;",128,0,0,0
        .stabs  "unsigned char:t(0,11)=@s8;r(0,11);0;255;",128,0,0,0
        .stabs  "__int128_t:t(0,12)=@s128;r(0,12);000000000000000000000000;0377777777777777777777777777777777;",128,0,0,0
        .stabs  "__uint128_t:t(0,13)=@s128;r(0,13);000000000000000000000000;0377777777777777777777777777777777;",128,0,0,0
        .stabs  "float:t(0,14)=r(0,1);4;0;",128,0,0,0
        .stabs  "double:t(0,15)=r(0,1);8;0;",128,0,0,0
        .stabs  "long double:t(0,16)=r(0,1);12;0;",128,0,0,0
        .stabs  "complex int:t(0,17)=s8real:(0,1),0,32;imag:(0,1),32,32;;",128,0,0,0
        .stabs  "complex float:t(0,18)=r(0,18);8;0;",128,0,0,0
        .stabs  "complex double:t(0,19)=r(0,19);16;0;",128,0,0,0
        .stabs  "complex long double:t(0,20)=r(0,20);24;0;",128,0,0,0
        .stabs  "__builtin_va_list:t(0,21)=*(0,2)",128,0,0,0
        .stabs  "_Bool:t(0,22)=@s8;-16;",128,0,0,0
        .align 2
        .stabs  "prototyped_func:F(0,1)",36,0,3,prototyped_func
        .stabs  "f:p(0,14)",160,0,2,8
        .stabs  "s:p(0,1)",160,0,2,12
.globl prototyped_func
        .type   prototyped_func,@function
prototyped_func:
        .stabs  "proto.c",132,0,0,.Ltext1
.Ltext1:
        .stabn 68,0,3,.LM1-prototyped_func
.LM1:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $12, %esp
        movl    12(%ebp), %eax
        movw    %ax, -2(%ebp)
        .stabn 68,0,4,.LM2-prototyped_func
.LM2:
        filds   -2(%ebp)
        fadds   8(%ebp)
        fnstcw  -4(%ebp)
        movl    -4(%ebp), %eax
        orw     $3072, %ax
        movw    %ax, -6(%ebp)
        fldcw   -6(%ebp)
        fistpl  -12(%ebp)
        fldcw   -4(%ebp)
        movl    -12(%ebp), %eax
        .stabn 68,0,5,.LM3-prototyped_func
.LM3:
        leave
        ret
.Lfe1:
        .size   prototyped_func,.Lfe1-prototyped_func
        .stabs  "s:(0,8)",128,0,2,-2
.Lscope0:
        .stabs  "",36,0,0,.Lscope0-prototyped_func
        .align 2
        .stabs  "non_prototyped_func:F(0,1)",36,0,11,non_prototyped_func
        .stabs  "f:p(0,15)",160,0,9,8
        .stabs  "s:p(0,1)",160,0,10,16
.globl non_prototyped_func
        .type   non_prototyped_func,@function
non_prototyped_func:
        .stabn 68,0,11,.LM4-non_prototyped_func
.LM4:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $20, %esp
        fldl    8(%ebp)
        movl    16(%ebp), %edx
        fstps   -4(%ebp)
        movl    -4(%ebp), %eax
        movl    %eax, -8(%ebp)
        movw    %dx, -10(%ebp)
        .stabn 68,0,12,.LM5-non_prototyped_func
.LM5:
        filds   -10(%ebp)
        fadds   -8(%ebp)
        fnstcw  -12(%ebp)
        movl    -12(%ebp), %eax
        orw     $3072, %ax
        movw    %ax, -14(%ebp)
        fldcw   -14(%ebp)
        fistpl  -20(%ebp)
        fldcw   -12(%ebp)
        movl    -20(%ebp), %eax
        .stabn 68,0,13,.LM6-non_prototyped_func
.LM6:
        leave
        ret
.Lfe2:
        .size   non_prototyped_func,.Lfe2-non_prototyped_func
        .stabs  "f:(0,14)",128,0,9,-8
        .stabs  "s:(0,8)",128,0,10,-10
.Lscope1:
        .stabs  "",36,0,0,.Lscope1-non_prototyped_func
        .align 2
        .stabs  "baz:F(0,1)",36,0,20,baz
        .stabs  "i:p(0,1)",160,0,19,8
.globl baz
        .type   baz,@function
baz:
        .stabn 68,0,20,.LM7-baz
.LM7:
        pushl   %ebp
        movl    %esp, %ebp
        .stabn 68,0,21,.LM8-baz
.LM8:
        movl    8(%ebp), %eax
        .stabn 68,0,22,.LM9-baz
.LM9:
        popl    %ebp
        ret
.Lfe3:
        .size   baz,.Lfe3-baz
.Lscope2:
        .stabs  "",36,0,0,.Lscope2-baz
        .align 2
        .stabs  "qux:F(0,1)",36,0,27,qux
        .stabs  "i:p(0,1)",160,0,26,8
.globl qux
        .type   qux,@function
qux:
        .stabn 68,0,27,.LM10-qux
.LM10:
        pushl   %ebp
        movl    %esp, %ebp
        .stabn 68,0,28,.LM11-qux
.LM11:
        movl    8(%ebp), %eax
        .stabn 68,0,29,.LM12-qux
.LM12:
        popl    %ebp
        ret
.Lfe4:
        .size   qux,.Lfe4-qux
.Lscope3:
        .stabs  "",36,0,0,.Lscope3-qux
        .comm   prototyped_fptr,4,4
        .comm   non_prototyped_fptr,4,4
        .stabs  "prototyped_fptr:G(0,23)=*(0,24)=f(0,1)",32,0,15,0
        .stabs  "non_prototyped_fptr:G(0,23)",32,0,16,0
        .text
        .stabs "",100,0,0,.Letext
.Letext:
        .ident  "GCC: (GNU) 3.1-gnupro-02r1"
$ 


  reply	other threads:[~2002-02-05 23:54 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-03 13:04 Jim Blandy
2002-02-03 15:01 ` Daniel Jacobowitz
2002-02-05 15:54   ` Jim Blandy [this message]
2002-02-05 17:21     ` Daniel Jacobowitz
2002-02-05 20:30       ` Jim Blandy
2002-02-05 21:48         ` Daniel Jacobowitz
2002-02-06 10:48           ` Jim Blandy
2002-02-06 16:14             ` Andrew Cagney
2002-02-06 16:24               ` Daniel Jacobowitz
2002-02-07 11:01               ` Jim Blandy
2002-02-07 12:27                 ` Daniel Jacobowitz
2002-02-08 10:03                   ` Jim Blandy
2002-02-08  5:16       ` function pointer stabs (was Re: RFA: MI tests: tolerate prototypes) Jason Merrill
2002-02-08  7:44         ` Daniel Jacobowitz
2002-02-08 11:37           ` Jim Blandy
2002-02-08 14:51           ` Jim Blandy
2002-02-09 12:15             ` Jim Blandy
2002-02-09 14:13               ` Daniel Jacobowitz
2002-02-03 16:29 ` RFA: MI tests: tolerate prototypes Andrew Cagney

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=npsn8fpjor.fsf@zwingli.cygnus.com \
    --to=jimb@zwingli.cygnus.com \
    --cc=drow@mvista.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