This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RFA: MI tests: tolerate prototypes



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"
$ 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]