Changeset e515b21a in mainline


Ignore:
Timestamp:
2010-01-26T21:31:56Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
3698e44
Parents:
80487bc5
Message:

Make stacktrace implementation in C library more generic. Use it in taskdump to print a stack trace of the faulting task.

Location:
uspace
Files:
8 added
1 deleted
13 edited
6 moved

Legend:

Unmodified
Added
Removed
  • uspace/app/taskdump/Makefile

    r80487bc5 re515b21a  
    2929USPACE_PREFIX = ../..
    3030LIBS = $(LIBC_PREFIX)/libc.a
     31EXTRA_CFLAGS = -Iinclude
    3132
    3233OUTPUT = taskdump
  • uspace/app/taskdump/taskdump.c

    r80487bc5 re515b21a  
    4646#include <bool.h>
    4747
     48#include <stacktrace.h>
     49
    4850#define LINE_BYTES 16
    4951
     
    5759static int connect_task(task_id_t task_id);
    5860static int parse_args(int argc, char *argv[]);
    59 static void print_syntax();
     61static void print_syntax(void);
    6062static int threads_dump(void);
    6163static int thread_dump(uintptr_t thash);
     
    6365static int area_dump(as_area_info_t *area);
    6466static void hex_dump(uintptr_t addr, void *buffer, size_t size);
     67static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value);
    6568
    6669int main(int argc, char *argv[])
     
    184187}
    185188
    186 static void print_syntax()
     189static void print_syntax(void)
    187190{
    188191        printf("Syntax: taskdump [-m] -t <task_id>\n");
     
    298301{
    299302        istate_t istate;
    300         uintptr_t pc, fp;
     303        uintptr_t pc, fp, nfp;
     304        stacktrace_t st;
    301305        int rc;
    302306
     
    311315
    312316        printf("Thread 0x%lx crashed at PC 0x%lx. FP 0x%lx\n", thash, pc, fp);
    313         printf("Istate hexdump:\n");
    314         hex_dump(0, &istate, (sizeof(istate_t) + 15) & ~15);
     317
     318        st.op_arg = NULL;
     319        st.read_uintptr = td_read_uintptr;
     320
     321        while (stacktrace_fp_valid(&st, fp)) {
     322                printf("%p: %p()\n", fp, pc);
     323
     324                rc = stacktrace_ra_get(&st, fp, &pc);
     325                if (rc != EOK)
     326                        return rc;
     327
     328                rc = stacktrace_fp_prev(&st, fp, &nfp);
     329                if (rc != EOK)
     330                        return rc;
     331
     332                fp = nfp;
     333        }
    315334
    316335        return EOK;
     
    376395}
    377396
     397static int td_read_uintptr(void *arg, uintptr_t addr, uintptr_t *value)
     398{
     399        uintptr_t data;
     400        int rc;
     401
     402        (void) arg;
     403
     404        rc = udebug_mem_read(phoneid, &data, addr, sizeof(data));
     405        if (rc < 0) {
     406                printf("Warning: udebug_mem_read() failed.\n");
     407                return rc;
     408        }
     409
     410        *value = data;
     411        return EOK;
     412}
     413
    378414/** @}
    379415 */
  • uspace/lib/libc/arch/amd64/Makefile.inc

    r80487bc5 re515b21a  
    3737        arch/$(UARCH)/src/fibril.S \
    3838        arch/$(UARCH)/src/tls.c \
    39         arch/$(UARCH)/src/stacktrace.S
     39        arch/$(UARCH)/src/stacktrace.c \
     40        arch/$(UARCH)/src/stacktrace_asm.S
    4041
    4142GCC_CFLAGS += -fno-omit-frame-pointer
  • uspace/lib/libc/arch/amd64/src/stacktrace_asm.S

    r80487bc5 re515b21a  
    2929.text
    3030
    31 .global frame_pointer_get
    32 .global frame_pointer_prev
    33 .global frame_pointer_validate
    34 .global return_address_get
    35 .global program_counter_get
     31.global stacktrace_prepare
     32.global stacktrace_fp_get
     33.global stacktrace_pc_get
    3634
    37 frame_pointer_get:
     35stacktrace_prepare:
     36        ret
     37
     38stacktrace_fp_get:
    3839        movq %rbp, %rax
    3940        ret
    4041
    41 frame_pointer_prev:
    42         movq (%rdi), %rax
    43         ret
    44 
    45 frame_pointer_validate:
    46         movq %rdi, %rax
    47         ret
    48 
    49 return_address_get:
    50         movq 8(%rdi), %rax
    51         ret
    52 
    53 program_counter_get:
     42stacktrace_pc_get:
    5443        movq (%rsp), %rax
    5544        ret
  • uspace/lib/libc/arch/arm32/Makefile.inc

    r80487bc5 re515b21a  
    3838        arch/$(UARCH)/src/tls.c \
    3939        arch/$(UARCH)/src/eabi.S \
    40         arch/$(UARCH)/src/stacktrace.S
     40        arch/$(UARCH)/src/stacktrace.c \
     41        arch/$(UARCH)/src/stacktrace_asm.S
    4142
    4243GCC_CFLAGS += -ffixed-r9 -mtp=soft -mapcs-frame -fno-omit-frame-pointer
  • uspace/lib/libc/arch/arm32/src/stacktrace_asm.S

    r80487bc5 re515b21a  
    2929.text
    3030
    31 .global frame_pointer_get
    32 .global frame_pointer_prev
    33 .global frame_pointer_validate
    34 .global return_address_get
    35 .global program_counter_get
     31.global stacktrace_prepare
     32.global stacktrace_fp_get
     33.global stacktrace_pc_get
    3634
    37 frame_pointer_get:
     35stacktrace_prepare:
     36        mov pc, lr
     37
     38stacktrace_fp_get:
    3839        mov r0, fp
    3940        mov pc, lr
    4041
    41 frame_pointer_prev:
    42         ldr r0, [r0, #-12]
    43         mov pc, lr
    44 
    45 frame_pointer_validate:
    46         mov pc, lr
    47 
    48 return_address_get:
    49         ldr r0, [r0, #-4]
    50         mov pc, lr
    51 
    52 program_counter_get:
     42stacktrace_pc_get:
    5343        mov r0, lr
    5444        mov pc, lr
    55 
  • uspace/lib/libc/arch/ia32/Makefile.inc

    r80487bc5 re515b21a  
    3838        arch/$(UARCH)/src/tls.c \
    3939        arch/$(UARCH)/src/setjmp.S \
    40         arch/$(UARCH)/src/stacktrace.S
     40        arch/$(UARCH)/src/stacktrace.c \
     41        arch/$(UARCH)/src/stacktrace_asm.S
    4142
    4243GCC_CFLAGS += -march=pentium
  • uspace/lib/libc/arch/ia32/src/stacktrace_asm.S

    r80487bc5 re515b21a  
    2929.text
    3030
    31 .global frame_pointer_get
    32 .global frame_pointer_prev
    33 .global frame_pointer_validate
    34 .global return_address_get
    35 .global program_counter_get
     31.global stacktrace_prepare
     32.global stacktrace_fp_get
     33.global stacktrace_pc_get
    3634
    37 frame_pointer_get:
     35stacktrace_prepare:
     36        ret
     37
     38stacktrace_fp_get:
    3839        movl %ebp, %eax
    3940        ret
    4041
    41 frame_pointer_prev:
    42         movl 4(%esp), %eax
    43         movl (%eax), %eax
    44         ret
    45 
    46 frame_pointer_validate:
    47         movl 4(%esp), %eax
    48         ret
    49 
    50 return_address_get:
    51         movl 4(%esp), %eax
    52         movl 4(%eax), %eax
    53         ret
    54 
    55 program_counter_get:
     42stacktrace_pc_get:
    5643        movl (%esp), %eax
    5744        ret
  • uspace/lib/libc/arch/ia64/Makefile.inc

    r80487bc5 re515b21a  
    3737        arch/$(UARCH)/src/tls.c \
    3838        arch/$(UARCH)/src/ddi.c \
    39         arch/$(UARCH)/src/stacktrace.S
     39        arch/$(UARCH)/src/stacktrace.c \
     40        arch/$(UARCH)/src/stacktrace_asm.S
    4041
    4142GCC_CFLAGS += -fno-unwind-tables
  • uspace/lib/libc/arch/ia64/src/stacktrace_asm.S

    r80487bc5 re515b21a  
    2929.text
    3030
    31 .global frame_pointer_get
    32 .global frame_pointer_prev
    33 .global frame_pointer_validate
    34 .global return_address_get
    35 .global program_counter_get
     31.global stacktrace_prepare
     32.global stacktrace_fp_get
     33.global stacktrace_pc_get
    3634
    37 frame_pointer_get:
    38 frame_pointer_prev:
    39 frame_pointer_validate:
    40 return_address_get:
    41 program_counter_get:
     35stacktrace_prepare:
     36        br.ret.sptk.many b0
     37
     38stacktrace_fp_get:
     39stacktrace_pc_get:
    4240        mov r8 = r0
    4341        br.ret.sptk.many b0
  • uspace/lib/libc/arch/mips32/Makefile.inc

    r80487bc5 re515b21a  
    3636        arch/$(UARCH)/src/fibril.S \
    3737        arch/$(UARCH)/src/tls.c \
    38         arch/$(UARCH)/src/stacktrace.S
     38        arch/$(UARCH)/src/stacktrace.c \
     39        arch/$(UARCH)/src/stacktrace_asm.S
    3940
    4041GCC_CFLAGS += -mips3
  • uspace/lib/libc/arch/mips32/src/stacktrace_asm.S

    r80487bc5 re515b21a  
    3232.set noreorder
    3333
    34 .global frame_pointer_get
    35 .global frame_pointer_prev
    36 .global frame_pointer_validate
    37 .global return_address_get
    38 .global program_counter_get
     34.global stacktrace_prepare
     35.global stacktrace_fp_get
     36.global stacktrace_pc_get
    3937
    40 frame_pointer_get:
    41 frame_pointer_prev:
    42 frame_pointer_validate:
    43 return_address_get:
    44 program_counter_get:
     38stacktrace_prepare:
     39stacktrace_fp_get:
     40stacktrace_pc_get:
    4541        j $ra
    4642        xor $v0, $v0
  • uspace/lib/libc/arch/mips32eb/Makefile.inc

    r80487bc5 re515b21a  
    3636        arch/$(UARCH)/src/fibril.S \
    3737        arch/$(UARCH)/src/tls.c \
    38         arch/$(UARCH)/src/stacktrace.S
     38        arch/$(UARCH)/src/stacktrace.c \
     39        arch/$(UARCH)/src/stacktrace_asm.S
    3940
    4041GCC_CFLAGS += -mips3
  • uspace/lib/libc/arch/ppc32/Makefile.inc

    r80487bc5 re515b21a  
    3636        arch/$(UARCH)/src/fibril.S \
    3737        arch/$(UARCH)/src/tls.c \
    38         arch/$(UARCH)/src/stacktrace.S
     38        arch/$(UARCH)/src/stacktrace.c \
     39        arch/$(UARCH)/src/stacktrace_asm.S
    3940
    4041GCC_CFLAGS += -mcpu=powerpc -msoft-float -m32
  • uspace/lib/libc/arch/ppc32/src/stacktrace_asm.S

    r80487bc5 re515b21a  
    3131#include <libarch/regname.h>
    3232
    33 .global frame_pointer_get
    34 .global frame_pointer_prev
    35 .global frame_pointer_validate
    36 .global return_address_get
    37 .global program_counter_get
     33.global stacktrace_prepare
     34.global stacktrace_fp_get
     35.global stacktrace_pc_get
    3836
    39 frame_pointer_get:
     37stacktrace_prepare:
     38        blr
     39
     40stacktrace_fp_get:
    4041        mr r3, sp
    4142        blr
    4243
    43 frame_pointer_prev:
    44         lwz r3, 0(r3)
    45         blr
    46 
    47 frame_pointer_validate:
    48         blr
    49 
    50 return_address_get:
    51         lwz r3, 4(r3)
    52         blr
    53 
    54 program_counter_get:
     44stacktrace_pc_get:
    5545        mflr r3
    5646        blr
  • uspace/lib/libc/arch/sparc64/Makefile.inc

    r80487bc5 re515b21a  
    3535ARCH_SOURCES += arch/$(UARCH)/src/fibril.S \
    3636        arch/$(UARCH)/src/tls.c \
    37         arch/$(UARCH)/src/stacktrace.S
     37        arch/$(UARCH)/src/stacktrace.c \
     38        arch/$(UARCH)/src/stacktrace_asm.S
    3839
    3940GCC_CFLAGS += -mcpu=ultrasparc -m64
  • uspace/lib/libc/generic/stacktrace.c

    r80487bc5 re515b21a  
    11/*
    22 * Copyright (c) 2009 Jakub Jermar
     3 * Copyright (c) 2010 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    3637#include <stdio.h>
    3738#include <sys/types.h>
     39#include <errno.h>
    3840
    39 void stack_trace_fp_pc(uintptr_t fp, uintptr_t pc)
     41static int stacktrace_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data);
     42
     43void stacktrace_print_fp_pc(uintptr_t fp, uintptr_t pc)
    4044{
    41         while (frame_pointer_validate(fp)) {
     45        stacktrace_t st;
     46        uintptr_t nfp;
     47
     48        st.op_arg = NULL;
     49        st.read_uintptr = stacktrace_read_uintptr;
     50
     51        while (stacktrace_fp_valid(&st, fp)) {
    4252                printf("%p: %p()\n", fp, pc);
    43                 pc = return_address_get(fp);
    44                 fp = frame_pointer_prev(fp);
     53                (void) stacktrace_ra_get(&st, fp, &pc);
     54                (void) stacktrace_fp_prev(&st, fp, &nfp);
     55                fp = nfp;
    4556        }
    4657}
    4758
    48 void stack_trace(void)
     59void stacktrace_print(void)
    4960{
    50         stack_trace_fp_pc(frame_pointer_get(), program_counter_get());
     61        stacktrace_prepare();
     62        stacktrace_print_fp_pc(stacktrace_fp_get(), stacktrace_pc_get());
    5163        /*
    5264         * Prevent the tail call optimization of the previous call by
    5365         * making it a non-tail call.
    5466         */
    55         (void) frame_pointer_get();
     67        (void) stacktrace_fp_get();
     68}
     69
     70static int stacktrace_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data)
     71{
     72        (void) arg;
     73        *data = *((uintptr_t *) addr);
     74        return EOK;
    5675}
    5776
  • uspace/lib/libc/include/stacktrace.h

    r80487bc5 re515b21a  
    11/*
    22 * Copyright (c) 2009 Jakub Jermar
     3 * Copyright (c) 2010 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    3940#include <bool.h>
    4041
    41 extern void stack_trace(void);
    42 extern void stack_trace_fp_pc(uintptr_t, uintptr_t);
     42typedef struct {
     43        void *op_arg;
     44        int (*read_uintptr)(void *, uintptr_t, uintptr_t *);
     45} stacktrace_t;
     46
     47extern void stacktrace_print(void);
     48extern void stacktrace_print_fp_pc(uintptr_t, uintptr_t);
    4349
    4450/*
    4551 * The following interface is to be implemented by each architecture.
    4652 */
    47 extern bool frame_pointer_validate(uintptr_t);
    48 extern uintptr_t frame_pointer_get(void);
    49 extern uintptr_t frame_pointer_prev(uintptr_t);
    50 extern uintptr_t return_address_get(uintptr_t);
    51 extern uintptr_t program_counter_get();
     53extern bool stacktrace_fp_valid(stacktrace_t *, uintptr_t);
     54extern int stacktrace_fp_prev(stacktrace_t *, uintptr_t, uintptr_t *);
     55extern int stacktrace_ra_get(stacktrace_t *, uintptr_t, uintptr_t *);
     56
     57extern void stacktrace_prepare(void);
     58extern uintptr_t stacktrace_fp_get(void);
     59extern uintptr_t stacktrace_pc_get();
    5260
    5361#endif
  • uspace/lib/libc/include/stdlib.h

    r80487bc5 re515b21a  
    4242#define abort() \
    4343        do { \
    44                 stack_trace(); \
     44                stacktrace_print(); \
    4545                _exit(1); \
    4646        } while (0)
Note: See TracChangeset for help on using the changeset viewer.