This is the mail archive of the gdb@sourceware.org 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: Custom call frame description


Hi!

On Fri, Jan 22, 2010 at 5:42 PM, Tom Tromey <tromey@redhat.com> wrote:
> One thing you can do is run gcc -S on simple programs and look at the
> resulting assembly. ÂAdding -dA can help clarify things, too.

Oh, thanks. I was looking at -S but it was cryptic without -dA. And I
have some success now.

But I am not sure to what I have to set canonical frame address? To
top address of the call frame or to the bottom? Because otherwise I
use top of the frame (where fp register is pointing) in my compiler
from which I calculate access to different elements of the frame.
While my sp is pointing at the bottom of the frame and I do not really
use it (except in the next function call). Somehow I got a feeling
that I should follow sp with canonical frame address but this is
somehow strange as I am using fp for my frame access. Also I
incrementally lower sp in my function prelude - should I change
canonical frame address for every instruction then? Or should I
immediately offset it for complete frame size?

Stack level 0, frame at 0xbef66c34: << should this point to top or
bottom of the frame?
 pc = 0x876c in _insert (prg.s:74); saved pc 0x8a48
 called by frame at 0xbef66c84 << same here, should this be top or
bottom of the frame?
 source language asm.
 Arglist at 0xbef66c34, args:
 Locals at 0xbef66c34, Previous frame's sp is 0xbef66c34 << this is
not really in sync with called frame address?

Currently I set CFA to sp register in initial commands and then when
in prolog, when I store current sp to fp, I switch CFA to fp register.
But at that moment things break and I get:

Stack level 0, frame at 0xbef66c34:
 pc = 0x8774 in _insert (prg.s:77); saved pc 0x8a48
 called by frame at 0xbef66c34
 source language asm.
 Arglist at 0xbef66c34, args:
 Locals at 0xbef66c34, Previous frame's sp is 0xbef66c34

My prolog looks like:

_insert:
    str fp, [sp, #-8]
    mov fp, sp
.L_insert_fp_defined:
    sub sp, sp, #12
    stmdb sp!, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r12}
    sub sp, sp, #12
    str lr, [fp, #-12]
.L_insert_lr_stored:

My epilog:

    str r12, [fp]
    add sp, sp, #60
    ldmdb sp, {r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r12}
    mov sp, fp
.L_insert_sp_defined:
    ldr fp, [sp, #-8]
    ldr pc, [sp, #-12]
.L_insert_end:

And I have:

.text
.section .debug_frame,"",%progbits
.align 2
.Lframe:
    .4byte .LECIE-.LSCIE @ Length of Common Information Entry
.LSCIE:
    .4byte 0xffffffff @ CIE Identifier Tag
    .byte 0x1 @ CIE Version
    .ascii "^@" @ CIE Augmentation
    .uleb128 0x1 @ CIE Code Alignment Factor
    .sleb128 -1 @ CIE Data Alignment Factor
    .byte 0x10 @ CIE RA Column
    .byte 0x9 @ DW_CFA_register
    .uleb128 0x10
    .uleb128 0xe
    .byte 0xc @ DW_CFA_def_cfa
    .uleb128 0xd
    .uleb128 0x0
.align 2
.LECIE:
.LSFDE_insert:
    .4byte .LEFDE_insert-.LASFDE_insert @ FDE Length
.LASFDE_insert:
    .4byte .Lframe @ FDE CIE offset
    .4byte _insert @ FDE initial location
    .4byte .L_insert_end-_insert @ FDE address range
    .byte 0x4 @ DW_CFA_advance_loc4
    .4byte .L_insert_fp_defined-_insert
    .byte 0xd @ DW_CFA_def_cfa_register
    .uleb128 0xb
    .byte 0x4 @ DW_CFA_advance_loc4
    .4byte .L_insert_lr_stored-.L_insert_fp_defined
    .byte 0x5 @ DW_CFA_offset_extended
    .uleb128 0x10
    .uleb128 12
    .byte 0x4 @ DW_CFA_advance_loc4
    .4byte .L_insert_sp_defined-.L_insert_lr_stored
    .byte 0xd @ DW_CFA_def_cfa_register
    .uleb128 0xd
.align 2
.LEFDE_insert:

How can I specify where are function arguments? And locals?


Mitar


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