[fpc-devel] strange behavior of mips stabs

Fuxin Zhang zhangfx at lemote.com
Sun Jun 10 17:08:46 CEST 2012


After looking into the gcc code, it is really so uncommon:( Lots of pain
to get full support.

gcc-4.4.6/gcc/config/mips/mips.c
  line 7484:
 /* The MIPS debug format wants all automatic variables and arguments
   to be in terms of the virtual frame pointer (stack pointer before
   any adjustment in the function), while the MIPS 3.0 linker wants
   the frame pointer to be the stack pointer after the initial
   adjustment.  So, we do the adjustment here.  The arg pointer (which
   is eliminated) points to the virtual frame pointer, while the frame
   pointer (which may be eliminated) points to the stack pointer after
   the initial adjustments.  */

HOST_WIDE_INT
mips_debugger_offset (rtx addr, HOST_WIDE_INT offset)
{
  rtx offset2 = const0_rtx;
  rtx reg = eliminate_constant_term (addr, &offset2);

  if (offset == 0)
    offset = INTVAL (offset2);

  if (reg == stack_pointer_rtx
      || reg == frame_pointer_rtx
      || reg == hard_frame_pointer_rtx)
    {
      offset -= cfun->machine->frame.total_size; // here it is
      if (reg == hard_frame_pointer_rtx)
        offset += cfun->machine->frame.hard_frame_pointer_offset;
    }


> for a function like this:
>    int i(int b)
> {
>         int i1,i2,i3;
>         return i1 + i2;
> }
>
> in x86, compile with gcc -fno-pic -fomit-frame-pointer -gstabs -O0 -S
> the output is:
> Lscope1:
>         .stabs  "i:F(0,1)",36,0,0,i
>         .stabs  "b:p(0,1)",160,0,0,-20
> .globl i
>         .type   i, @function
> i:
>         .stabn  68,0,10,.LM5-.LFBB2
> .LM5:
> .LFBB2:
> .LFB1:
>         .cfi_startproc
>         movl    %edi, -20(%rsp)
>         .stabn  68,0,12,.LM6-.LFBB2
> .LM6:
>         movl    -8(%rsp), %eax
>         movl    -4(%rsp), %edx
>         leal    (%rdx,%rax), %eax
>         .stabn  68,0,13,.LM7-.LFBB2
> .LM7:
>         ret
>         .cfi_endproc
> .LFE1:
>         .size   i, .-i
>         .stabs  "i1:(0,1)",128,0,0,-4
>         .stabs  "i2:(0,1)",128,0,0,-8
>         .stabs  "i3:(0,1)",128,0,0,-12
>         .stabn  192,0,0,.LFBB2-.LFBB2
>         .stabn  224,0,0,.Lscope2-.LFBB2
>
> Everything works as expect:
>    the offsets for both parameters and locals are negative, no matter in
> stabs directive or in the assembly code. And the offset value in stabs
> equals to the one in the code.
>
> But for mips, mipsel-linux-gcc -fno-pic -fomit-frame-pointer -gstabs -O0
> -S output is:
> scope1:
>         .align  2
>         .stabs  "i:F(0,1)",36,0,0,i
>         .stabs  "b:p(0,1)",160,0,0,24
>         .globl  i
>         .ent    i
>         .type   i, @function
> i:
>         .stabn  68,0,10,$LM5
> $LM5:
> $LFBB2:
>         .set    nomips16
>         .frame  $sp,24,$31              # vars= 16, regs= 0/0, args= 0,
> gp= 8
>         .mask   0x00000000,0
>         .fmask  0x00000000,0
>         .set    noreorder
>         .set    nomacro
>
>         addiu   $sp,$sp,-24
>         .cprestore      0
>         sw      $4,24($sp)
>         .stabn  68,0,12,$LM6
> $LM6:
>         lw      $3,16($sp)
>         lw      $2,12($sp)
>         nop
>         addu    $2,$3,$2
>         .stabn  68,0,13,$LM7
> $LM7:
>         addiu   $sp,$sp,24
>         j       $31
>         nop
>
>         .set    macro
>         .set    reorder
>         .end    i
>         .stabs  "i1:(0,1)",128,0,0,-8
>         .stabs  "i2:(0,1)",128,0,0,-12
>
> The local variable offsets in stabs are negative, but in the code they are
> positive. For my understanding of fpc logic, they should both generated
> from loc.reference.offset or something similiar, they cannot be different.
> If I am not making mistake, we have to special case some code to make
> debugging work.
>
> Am I wrong?
>
> Regards
>
>
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>





More information about the fpc-devel mailing list