Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 47246f4 in mainline


Ignore:
Timestamp:
2009-12-30T18:34:15Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
01fda09
Parents:
ee2f1aae
Message:

Pair the stack frame address and the return address in a more meaningful way.
Also do the 'right' thing on sparc64 and recognize the end of the stack trace
by -0x7ff stored in %fp.

Location:
uspace/lib/libc
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/arch/amd64/src/entry.s

    ree2f1aae r47246f4  
    3939__entry:
    4040        #
    41         # Stop stack traces in this function.
     41        # Create the first stack frame.
    4242        #
    43         xorq %rbp, %rbp
     43        pushq $0
     44        mov %rsp, %rbp
    4445       
    4546        # %rdi was deliberately chosen as the first argument is also in %rdi
  • uspace/lib/libc/arch/amd64/src/stacktrace.S

    ree2f1aae r47246f4  
    3333.global frame_pointer_validate
    3434.global return_address_get
     35.global program_counter_get
    3536
    3637frame_pointer_get:
     
    4950        movq 8(%rdi), %rax
    5051        ret
     52
     53program_counter_get:
     54        movq (%rsp), %rax
     55        ret
  • uspace/lib/libc/arch/amd64/src/thread_entry.s

    ree2f1aae r47246f4  
    3636__thread_entry:
    3737        #
    38         # Stop stack traces in this function.
     38        # Create the first stack frame.
    3939        #
    40         xorq %rbp, %rbp
     40        pushq $0
     41        movq %rsp, %rbp
    4142
    4243        #
  • uspace/lib/libc/arch/arm32/src/stacktrace.S

    ree2f1aae r47246f4  
    3333.global frame_pointer_validate
    3434.global return_address_get
     35.global program_counter_get
    3536
    3637frame_pointer_get:
     
    3839frame_pointer_validate:
    3940return_address_get:
     41program_counter_get:
    4042        mov r0, #0
    4143        mov pc, lr
  • uspace/lib/libc/arch/ia32/src/entry.s

    ree2f1aae r47246f4  
    56560:
    5757        #
    58         # Stop stack traces in this function.
     58        # Create the first stack frame.
    5959        #
    60         xorl %ebp, %ebp
     60        pushl $0
     61        movl %esp, %ebp
    6162
    6263        # Pass the PCB pointer to __main as the first argument
  • uspace/lib/libc/arch/ia32/src/stacktrace.S

    ree2f1aae r47246f4  
    3333.global frame_pointer_validate
    3434.global return_address_get
     35.global program_counter_get
    3536
    3637frame_pointer_get:
     
    5152        movl 4(%eax), %eax
    5253        ret
     54
     55program_counter_get:
     56        movl (%esp), %eax
     57        ret
  • uspace/lib/libc/arch/ia32/src/thread_entry.s

    ree2f1aae r47246f4  
    4242
    4343        #
    44         # Stop stack traces in this function.
     44        # Create the first stack frame.
    4545        #
    46         xorl %ebp, %ebp
     46        pushl $0
     47        mov %esp, %ebp
    4748
    4849        #
  • uspace/lib/libc/arch/sparc64/include/fibril.h

    ree2f1aae r47246f4  
    5353                (c)->fp = -STACK_BIAS; \
    5454                (c)->tp = ptls; \
    55                 (c)->i7 = 0; \
    5655        } while (0)
    5756       
  • uspace/lib/libc/arch/sparc64/src/entry.s

    ree2f1aae r47246f4  
    4040__entry:
    4141        #
    42         # Stop stack traces in this function.
     42        # Create the first stack frame.
    4343        #
    44         clr %i7
     44        save %sp, -176, %sp
     45        flushw
     46        add %g0, -0x7ff, %fp
    4547
    4648        # Pass pcb_ptr as the first argument to __main()
    47         mov %o1, %o0
     49        mov %i1, %o0
    4850        sethi %hi(_gp), %l7
    4951        call __main
  • uspace/lib/libc/arch/sparc64/src/stacktrace.S

    ree2f1aae r47246f4  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032
     
    3335.global frame_pointer_validate
    3436.global return_address_get
     37.global program_counter_get
    3538
    3639frame_pointer_get:
    3740        # Add the stack bias to %sp to get the actual address.
    3841        retl
    39         add %sp, 0x7ff, %o0
     42        add %sp, STACK_BIAS, %o0
    4043
    4144frame_pointer_prev:
    42         save %sp, -176, %sp
     45        save %sp, -(STACK_WINDOW_SAVE_AREA_SIZE+STACK_ARG_SAVE_AREA_SIZE), %sp
    4346        # Flush all other windows to memory so that we can read their contents.
    4447        flushw
     
    4649        ldx [%i0 + 14 * 8], %i0
    4750        # Add the stack bias to the %fp read from the window save area.
    48         add %i0, 0x7ff, %i0
     51        add %i0, STACK_BIAS, %i0
    4952        ret
    5053        restore
    5154
    5255frame_pointer_validate:
    53         #
    54         # Fall through - we detect the last frame in the trace by zero %i7.
    55         #
     56        retl
     57        nop
    5658
    5759return_address_get:
    58         save %sp, -176, %sp
     60        save %sp, -(STACK_WINDOW_SAVE_AREA_SIZE+STACK_ARG_SAVE_AREA_SIZE), %sp
    5961        # Flush all other windows to memory so that we can read their contents.
    6062        flushw
     
    6365        ret
    6466        restore
     67
     68program_counter_get:
     69        retl
     70        mov %o7, %o0
     71
  • uspace/lib/libc/arch/sparc64/src/thread_entry.s

    ree2f1aae r47246f4  
    3636__thread_entry:
    3737        #
    38         # Stop stack traces in this function.
     38        # Create the first stack frame.
    3939        #
    40         clr %i7
     40        save %sp, -176, %sp
     41        flushw
     42        add %g0, -0x7ff, %fp
    4143
    4244        sethi %hi(_gp), %l7
  • uspace/lib/libc/generic/stacktrace.c

    ree2f1aae r47246f4  
    3737#include <sys/types.h>
    3838
    39 void stack_trace_fp(uintptr_t fp)
     39void stack_trace_fp_pc(uintptr_t fp, uintptr_t pc)
    4040{
    41         uintptr_t ra;
    42 
     41        printf("Printing stack trace:\n");
     42        printf("=====================\n");
    4343        while (frame_pointer_validate(fp)) {
    44                 ra = return_address_get(fp);
    45                 printf("%p: %p()\n", fp, ra);
     44                printf("%p: %p()\n", fp, pc);
     45                pc = return_address_get(fp);
    4646                fp = frame_pointer_prev(fp);
    4747        }
     48        printf("=====================\n");
    4849}
    4950
    5051void stack_trace(void)
    5152{
    52         stack_trace_fp(frame_pointer_get());
     53        stack_trace_fp_pc(frame_pointer_get(), program_counter_get());
    5354}
    5455
  • uspace/lib/libc/include/stacktrace.h

    ree2f1aae r47246f4  
    4040
    4141extern void stack_trace(void);
    42 extern void stack_trace_fp(uintptr_t);
     42extern void stack_trace_fp_pc(uintptr_t, uintptr_t);
    4343
    4444/*
     
    4949extern uintptr_t frame_pointer_prev(uintptr_t);
    5050extern uintptr_t return_address_get(uintptr_t);
     51extern uintptr_t program_counter_get();
    5152
    5253#endif
Note: See TracChangeset for help on using the changeset viewer.