public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* gdb unable to print fn argument correctly
@ 2005-07-21 20:06 Manoj Iyer
  2005-07-21 20:10 ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Manoj Iyer @ 2005-07-21 20:06 UTC (permalink / raw)
  To: gdb


I have an test program which has a function of the nature 'void fn(double
c){}', which is compiled as a PwerPC 64bit application. When I set a
breakpoint and stop on this function, GDB is not printing the arguments
passed to this function correctly.

I did some initial debugging, the dwarf information and dissassembly of
the function looks good to me. But I am not able to pin point who is
corrupting the stack. I believe gdb is just printing what is avaiable in
the stack to output.

Any pointers to help me identify the culprit deeply appreciated.


============= test.c ========================

#include <stdio.h>

void fn1(int a) {}
void fn2(long b){}
void fn3(double c){}

int
main()
{
    fn1(1234);
    fn2(123456789L);
    fn3(1234.4567);
    return 0;
}
============= end test.c ======================

============= GDB output ======================
(gdb) br main
Breakpoint 1 at 0x10000574: file /tmp/test1.c, line 10.
(gdb) br fn3
Breakpoint 2 at 0x10000544: file /tmp/test1.c, line 5.
(gdb) r
Starting program: /tmp/test.gdb

Breakpoint 1, main () at /tmp/test1.c:10
10          fn1(1234);
(gdb) c
Continuing.

Breakpoint 2, 0x0000000010000544 in fn3 (c=6.0995758190771502e-316)
    at /tmp/test1.c:5
5       void fn3(double c){}
(gdb)

================= end gdb output ==========================

When I change this testcase, change function fn3 to have something
meaningful in the body, gdb prints the arguments correctly.

=================== modified test.c ======================
#include <stdio.h>

void fn1(int a) {}
void fn2(long b){}
void fn3(double c){printf("hello world %lf\n", c);}

int
main()
{
    fn1(1234);
    fn2(123456789L);
    fn3(1234.4567);
    return 0;
}

================= end of test.c ==========================

================= output from gdb =======================
(gdb) br main
Breakpoint 1 at 0x100004c0: file test.c, line 9.
(gdb) br fn3
Breakpoint 2 at 0x10000488: file test.c, line 5.
(gdb) r
Starting program: /tmp/test

Breakpoint 1, main () at test.c:9
warning: Source file is more recent than executable.

9           fn1(1234);
(gdb) c
Continuing.

Breakpoint 2, fn3 (c=1234.4567) at test.c:5
5       void fn3(double c){printf("hello world %lf\n", c);}
(gdb)

================== end of output from gdb ===================

=================== DWARF info for fn3() ===================
 <1><2bf>: Abbrev Number: 4 (DW_TAG_subprogram)
     DW_AT_sibling     : <2e3>
     DW_AT_external    : 1
     DW_AT_name        : fn3
     DW_AT_decl_file   : 1
     DW_AT_decl_line   : 5
     DW_AT_prototyped  : 1
     DW_AT_low_pc      : 0x10000448 268436552
     DW_AT_high_pc     : 0x10000468 268436584
     DW_AT_frame_base  : 1 byte block: 6f       (DW_OP_reg31)
 <2><2d6>: Abbrev Number: 5 (DW_TAG_formal_parameter)
     DW_AT_name        : c
     DW_AT_decl_file   : 1
     DW_AT_decl_line   : 5
     DW_AT_type        : <2e3>
     DW_AT_location    : 2 byte block: 91 8     (DW_OP_fbreg: 8)
 <1><2e3>: Abbrev Number: 3 (DW_TAG_base_type)
     DW_AT_name        : double
     DW_AT_byte_size   : 8
     DW_AT_encoding    : 4      (float)
=================================================================

==== Disassembly of void fn3(double c){} =======================
fn3()
[5]     10000448:   94 21 ff e0   stwu       r1, -32(r1)
        1000044c:   93 e1 00 1c   stw        r31, 28(r1)
        10000450:   7c 3f 0b 78   mr         r31, r1
        10000454:   d8 3f 00 08   stfd       fr1, 8(r31)
        10000458:   81 61 00 00   lwz        r11, 0(r1)
        1000045c:   83 eb ff fc   lwz        r31, -4(r11)
        10000460:   7d 61 5b 78   mr         r1, r11
        10000464:   4e 80 00 20   blr
==================================================================

Thanks
-----
manjo
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+ Cogito ergo sum                                                          +
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gdb unable to print fn argument correctly
  2005-07-21 20:06 gdb unable to print fn argument correctly Manoj Iyer
@ 2005-07-21 20:10 ` Daniel Jacobowitz
  2005-07-21 22:55   ` Manoj Iyer
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2005-07-21 20:10 UTC (permalink / raw)
  To: Manoj Iyer; +Cc: gdb

On Thu, Jul 21, 2005 at 02:40:23PM -0500, Manoj Iyer wrote:
> 
> I have an test program which has a function of the nature 'void fn(double
> c){}', which is compiled as a PwerPC 64bit application. When I set a
> breakpoint and stop on this function, GDB is not printing the arguments
> passed to this function correctly.
> 
> I did some initial debugging, the dwarf information and dissassembly of
> the function looks good to me. But I am not able to pin point who is
> corrupting the stack. I believe gdb is just printing what is avaiable in
> the stack to output.
> 
> Any pointers to help me identify the culprit deeply appreciated.

Check what instruction ($pc) GDB has stopped on.  The debug info is
valid only at or after 0x10000458.  What does the line table look like?

> ==== Disassembly of void fn3(double c){} =======================
> fn3()
> [5]     10000448:   94 21 ff e0   stwu       r1, -32(r1)
>         1000044c:   93 e1 00 1c   stw        r31, 28(r1)
>         10000450:   7c 3f 0b 78   mr         r31, r1
>         10000454:   d8 3f 00 08   stfd       fr1, 8(r31)
>         10000458:   81 61 00 00   lwz        r11, 0(r1)
>         1000045c:   83 eb ff fc   lwz        r31, -4(r11)
>         10000460:   7d 61 5b 78   mr         r1, r11
>         10000464:   4e 80 00 20   blr
> ==================================================================


-- 
Daniel Jacobowitz
CodeSourcery, LLC

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gdb unable to print fn argument correctly
  2005-07-21 20:10 ` Daniel Jacobowitz
@ 2005-07-21 22:55   ` Manoj Iyer
  2005-07-21 22:59     ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Manoj Iyer @ 2005-07-21 22:55 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb

> Check what instruction ($pc) GDB has stopped on.  The debug info is
> valid only at or after 0x10000458.  What does the line table look like?
>
> > ==== Disassembly of void fn3(double c){} =======================
> > fn3()
> > [5]     10000448:   94 21 ff e0   stwu       r1, -32(r1)
> >         1000044c:   93 e1 00 1c   stw        r31, 28(r1)
> >         10000450:   7c 3f 0b 78   mr         r31, r1
> >         10000454:   d8 3f 00 08   stfd       fr1, 8(r31)
> >         10000458:   81 61 00 00   lwz        r11, 0(r1)
> >         1000045c:   83 eb ff fc   lwz        r31, -4(r11)
> >         10000460:   7d 61 5b 78   mr         r1, r11
> >         10000464:   4e 80 00 20   blr
> > ==================================================================
>

GDB stopped on the instruction at 0x...10000544, which is 10000544:   d8
3f 00 70     stfd    f1,112(r31).

Here is what my line table looks like:

================ line table =================
Compilation Unit Number 6:
        length 58, version 2, prolog length 27
        Minimum instruction length: 4
        Default is statement: 1
        Line base: -5
        Line range: 14
        Opcode base: 10
        Opcode lengths: 0 1 1 1 1 0 0 0 1

        Include Directories:

        File Names Table:
        File Directory    Last Modified        Size  Name
           1     0     Dec 31 18:00:00 1969       0  test1.c

              Line Column   Address  File
              ---- ------   -------  ----
           1     3    0   0x100004e4 test1.c
           2     4    0   0x10000510 test1.c
           3     5    0   0x10000538 test1.c
           4     9    0   0x10000560 test1.c
           5    10    0   0x10000574 test1.c
           6    11    0   0x1000057c test1.c
           7    12    0   0x10000588 test1.c
           8    13    0   0x10000594 test1.c
           9    14    0   0x10000598 test1.c

================== enf of line table ===========================



================ GDB output ====================================
(gdb) br main
Breakpoint 1 at 0x10000574: file test1.c, line 10.
(gdb) br fn3
Breakpoint 2 at 0x10000544: file test1.c, line 5.
(gdb) r
Starting program: /tmp/test1.gdb

Breakpoint 1, main () at test1.c:10
10          fn1(1234);
(gdb) c
Continuing.

Breakpoint 2, 0x0000000010000544 in fn3 (c=6.0995758190771502e-316)
    at test1.c:5
5       void fn3(double c){}
================================================================

=========== disassembly of fn3 =================================
0000000010000538 <.fn3>:
    10000538:   fb e1 ff f8     std     r31,-8(r1)
    1000053c:   f8 21 ff c1     stdu    r1,-64(r1)
    10000540:   7c 3f 0b 78     mr      r31,r1
    10000544:   d8 3f 00 70     stfd    f1,112(r31)
    10000548:   e8 21 00 00     ld      r1,0(r1)
    1000054c:   eb e1 ff f8     ld      r31,-8(r1)
    10000550:   4e 80 00 20     blr
        ...
    1000055c:   80 01 00 01     lwz     r0,1(r1)
=======================================================

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gdb unable to print fn argument correctly
  2005-07-21 22:55   ` Manoj Iyer
@ 2005-07-21 22:59     ` Daniel Jacobowitz
  2005-07-26 18:44       ` Manoj Iyer
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Jacobowitz @ 2005-07-21 22:59 UTC (permalink / raw)
  To: Manoj Iyer; +Cc: gdb

On Thu, Jul 21, 2005 at 05:29:10PM -0500, Manoj Iyer wrote:
> GDB stopped on the instruction at 0x...10000544, which is 10000544:   d8
> 3f 00 70     stfd    f1,112(r31).

The prologue analyzer must have been invoked.  One way to fix the
problem would be to find out why the prologue analyzer stopped before
this instruction.  Search for skip_prologue.

>               Line Column   Address  File
>               ---- ------   -------  ----
>            1     3    0   0x100004e4 test1.c
>            2     4    0   0x10000510 test1.c
>            3     5    0   0x10000538 test1.c
>            4     9    0   0x10000560 test1.c
>            5    10    0   0x10000574 test1.c
>            6    11    0   0x1000057c test1.c
>            7    12    0   0x10000588 test1.c
>            8    13    0   0x10000594 test1.c
>            9    14    0   0x10000598 test1.c

If this is GCC output, then there ought to be two lines in each
function, the second marking the end of the prologue.  Figure out why
there's only one in each of your small functions.

-- 
Daniel Jacobowitz
CodeSourcery, LLC

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gdb unable to print fn argument correctly
  2005-07-21 22:59     ` Daniel Jacobowitz
@ 2005-07-26 18:44       ` Manoj Iyer
  2005-07-27 18:10         ` Daniel Jacobowitz
  0 siblings, 1 reply; 6+ messages in thread
From: Manoj Iyer @ 2005-07-26 18:44 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: gdb




> On Thu, Jul 21, 2005 at 05:29:10PM -0500, Manoj Iyer wrote:
> > GDB stopped on the instruction at 0x...10000544, which is 10000544:   d8
> > 3f 00 70     stfd    f1,112(r31).
>
> The prologue analyzer must have been invoked.  One way to fix the
> problem would be to find out why the prologue analyzer stopped before
> this instruction.  Search for skip_prologue.
>

Looks like skip_prolog was called consistantly on both working and
non-working cases. Below is the output from GDB...

Also, another question I have is, in utils.c, wrap_here(), where does the
wrap_buffer gets initialized?

  if (wrap_buffer[0])
    {
      *wrap_pointer = '\0';
      fputs_unfiltered (wrap_buffer, gdb_stdout);
    }

prints the arguments to the function among other things, so I am trying to
identify who fills the wrap_buffer with information.


===================== non-working case ==============
(gdb) br main
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x10000560
Breakpoint 1 at 0x10000574: file /tmp/test1.c, line 10.
(gdb) br fn3
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x10000538
Breakpoint 2 at 0x10000544: file /tmp/test1.c, line 5.
(gdb) r
Starting program: /tmp/test1
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x10000560
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x10000538
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x10000560
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x10000538

Breakpoint 1, main () at /tmp/test1.c:10
10          fn1(1234);
(gdb) c
Continuing.

Breakpoint 2, 0x0000000010000544 in fn3 (c=6.0995758190771502e-316)
    at /tmp/test1.c:5
5       void fn3(double c){}
(gdb) q
The program is running.  Exit anyway? (y or n) y

==============================================================


========== working case ===================
(gdb) br main
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x100004ac
Breakpoint 1 at 0x100004c0: file test.c, line 9.
(gdb) br fn3
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x10000470
Breakpoint 2 at 0x10000488: file test.c, line 5.
(gdb) r
Starting program: /tmp/test
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x100004ac
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x10000470
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x100004ac
rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x10000470

Breakpoint 1, main () at test.c:9
warning: Source file is more recent than executable.
9           fn1(1234);
(gdb) c
Continuing.

Breakpoint 2, fn3 (c=1234.4567) at test.c:5
5       void fn3(double c){printf("hello world %lf\n", c);}
(gdb)

=========================================================




> >               Line Column   Address  File
> >               ---- ------   -------  ----
> >            1     3    0   0x100004e4 test1.c
> >            2     4    0   0x10000510 test1.c
> >            3     5    0   0x10000538 test1.c
> >            4     9    0   0x10000560 test1.c
> >            5    10    0   0x10000574 test1.c
> >            6    11    0   0x1000057c test1.c
> >            7    12    0   0x10000588 test1.c
> >            8    13    0   0x10000594 test1.c
> >            9    14    0   0x10000598 test1.c
>
> If this is GCC output, then there ought to be two lines in each
> function, the second marking the end of the prologue.  Figure out why
> there's only one in each of your small functions.
>
> --
> Daniel Jacobowitz
> CodeSourcery, LLC
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: gdb unable to print fn argument correctly
  2005-07-26 18:44       ` Manoj Iyer
@ 2005-07-27 18:10         ` Daniel Jacobowitz
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Jacobowitz @ 2005-07-27 18:10 UTC (permalink / raw)
  To: Manoj Iyer; +Cc: gdb

On Tue, Jul 26, 2005 at 01:17:01PM -0500, Manoj Iyer wrote:
> 
> 
> 
> > On Thu, Jul 21, 2005 at 05:29:10PM -0500, Manoj Iyer wrote:
> > > GDB stopped on the instruction at 0x...10000544, which is 10000544:   d8
> > > 3f 00 70     stfd    f1,112(r31).
> >
> > The prologue analyzer must have been invoked.  One way to fix the
> > problem would be to find out why the prologue analyzer stopped before
> > this instruction.  Search for skip_prologue.
> >
> 
> Looks like skip_prolog was called consistantly on both working and
> non-working cases. Below is the output from GDB...

> rs6000-tdep.c: rs6000_skip_prologue(): 501 :: pc = 0x10000538

The prologue analyzer thinks the prologue stops rather earlier than it
really does.

> Also, another question I have is, in utils.c, wrap_here(), where does the
> wrap_buffer gets initialized?
> 
>   if (wrap_buffer[0])
>     {
>       *wrap_pointer = '\0';
>       fputs_unfiltered (wrap_buffer, gdb_stdout);
>     }
> 
> prints the arguments to the function among other things, so I am trying to
> identify who fills the wrap_buffer with information.

Grep for wrap_buffer?  fputs_maybe_filtered copies data into
wrap_buffer (via wrap_pointer).


-- 
Daniel Jacobowitz
CodeSourcery, LLC

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-07-27 18:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-07-21 20:06 gdb unable to print fn argument correctly Manoj Iyer
2005-07-21 20:10 ` Daniel Jacobowitz
2005-07-21 22:55   ` Manoj Iyer
2005-07-21 22:59     ` Daniel Jacobowitz
2005-07-26 18:44       ` Manoj Iyer
2005-07-27 18:10         ` Daniel Jacobowitz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).