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

Changeset c1b979a in mainline


Ignore:
Timestamp:
2014-07-11T23:06:30Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
78192cc7
Parents:
8e4a408
Message:

Taskdump printing of fibril stacktraces.

Location:
uspace
Files:
3 added
14 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskdump/Makefile

    r8e4a408 rc1b979a  
    3333SOURCES = \
    3434        elf_core.c \
     35        fibrildump.c \
    3536        taskdump.c \
    3637        symtab.c
  • uspace/app/taskdump/include/symtab.h

    r8e4a408 rc1b979a  
    5050extern int symtab_load(const char *file_name, symtab_t **symtab);
    5151extern void symtab_delete(symtab_t *st);
    52 extern int symtab_name_to_addr(symtab_t *st, char *name, uintptr_t *addr);
     52extern int symtab_name_to_addr(symtab_t *st, const char *name, uintptr_t *addr);
    5353extern int symtab_addr_to_name(symtab_t *symtab, uintptr_t addr, char **name,
    5454    size_t *offs);
  • uspace/app/taskdump/symtab.c

    r8e4a408 rc1b979a  
    202202 * @return      EOK on success, ENOENT if no such symbol was found.
    203203 */
    204 int symtab_name_to_addr(symtab_t *st, char *name, uintptr_t *addr)
     204int symtab_name_to_addr(symtab_t *st, const char *name, uintptr_t *addr)
    205205{
    206206        size_t i;
  • uspace/app/taskdump/taskdump.c

    r8e4a408 rc1b979a  
    3535#include <async.h>
    3636#include <elf/elf_linux.h>
     37#include <fibrildump.h>
    3738#include <stdio.h>
    3839#include <stdlib.h>
     
    5253#include <elf_core.h>
    5354#include <stacktrace.h>
     55#include <taskdump.h>
    5456
    5557#define LINE_BYTES 16
     
    7678static istate_t reg_state;
    7779
     80static stacktrace_ops_t td_stacktrace_ops = {
     81        .read_uintptr = td_read_uintptr
     82};
     83
    7884int main(int argc, char *argv[])
    7985{
     
    106112        if (rc < 0)
    107113                printf("Failed dumping address space areas.\n");
     114
     115        rc = fibrils_dump(app_symtab, sess);
     116        if (rc < 0)
     117                printf("Failed dumping fibrils.\n");
    108118
    109119        udebug_end(sess);
     
    311321}
    312322
     323int td_stacktrace(uintptr_t fp, uintptr_t pc)
     324{
     325        uintptr_t nfp;
     326        stacktrace_t st;
     327        char *sym_pc;
     328        int rc;
     329
     330        st.op_arg = NULL;
     331        st.ops = &td_stacktrace_ops;
     332
     333        while (stacktrace_fp_valid(&st, fp)) {
     334                sym_pc = fmt_sym_address(pc);
     335                printf("  %p: %s\n", (void *) fp, sym_pc);
     336                free(sym_pc);
     337
     338                rc = stacktrace_ra_get(&st, fp, &pc);
     339                if (rc != EOK)
     340                        return rc;
     341
     342                rc = stacktrace_fp_prev(&st, fp, &nfp);
     343                if (rc != EOK)
     344                        return rc;
     345
     346                fp = nfp;
     347        }
     348
     349        return EOK;
     350}
     351
    313352static int thread_dump(uintptr_t thash)
    314353{
    315354        istate_t istate;
    316         uintptr_t pc, fp, nfp;
    317         stacktrace_t st;
     355        uintptr_t pc, fp;
    318356        char *sym_pc;
    319357        int rc;
     
    336374        free(sym_pc);
    337375
    338         st.op_arg = NULL;
    339         st.read_uintptr = td_read_uintptr;
    340 
    341         while (stacktrace_fp_valid(&st, fp)) {
    342                 sym_pc = fmt_sym_address(pc);
    343                 printf("  %p: %s\n", (void *) fp, sym_pc);
    344                 free(sym_pc);
    345 
    346                 rc = stacktrace_ra_get(&st, fp, &pc);
    347                 if (rc != EOK)
    348                         return rc;
    349 
    350                 rc = stacktrace_fp_prev(&st, fp, &nfp);
    351                 if (rc != EOK)
    352                         return rc;
    353 
    354                 fp = nfp;
    355         }
     376        (void) td_stacktrace(fp, pc);
    356377
    357378        return EOK;
  • uspace/lib/c/arch/amd64/src/stacktrace.c

    r8e4a408 rc1b979a  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/arm32/src/stacktrace.c

    r8e4a408 rc1b979a  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/ia32/src/stacktrace.c

    r8e4a408 rc1b979a  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/ppc32/src/stacktrace.c

    r8e4a408 rc1b979a  
    5151int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
    5252{
    53         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
     53        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, prev);
    5454}
    5555
    5656int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    5757{
    58         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     58        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    5959}
    6060
  • uspace/lib/c/arch/sparc32/src/stacktrace.c

    r8e4a408 rc1b979a  
    5353{
    5454        uintptr_t bprev;
    55         int rc = (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV,
     55        int rc = (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV,
    5656            &bprev);
    5757        if (rc == EOK)
     
    6363int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    6464{
    65         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     65        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    6666}
    6767
  • uspace/lib/c/arch/sparc64/src/stacktrace.c

    r8e4a408 rc1b979a  
    5555        int rc;
    5656
    57         rc = (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, &bprev);
     57        rc = (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_FP_PREV, &bprev);
    5858        if (rc == EOK)
    5959                *prev = bprev + STACK_BIAS;
     
    6363int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
    6464{
    65         return (*st->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
     65        return (*st->ops->read_uintptr)(st->op_arg, fp + FRAME_OFFSET_RA, ra);
    6666}
    6767
  • uspace/lib/c/generic/fibril.c

    r8e4a408 rc1b979a  
    5959static LIST_INITIALIZE(serialized_list);
    6060static LIST_INITIALIZE(manager_list);
     61static LIST_INITIALIZE(fibril_list);
    6162
    6263/** Number of threads that are executing a manager fibril. */
     
    116117       
    117118        fibril->waits_for = NULL;
     119        list_append(&fibril->all_link, &fibril_list);
    118120       
    119121        return fibril;
     
    122124void fibril_teardown(fibril_t *fibril)
    123125{
     126        list_remove(&fibril->all_link);
    124127        tls_free(fibril->tcb);
    125128        free(fibril);
  • uspace/lib/c/generic/stacktrace.c

    r8e4a408 rc1b979a  
    4242static int stacktrace_read_uintptr(void *arg, uintptr_t addr, uintptr_t *data);
    4343
    44 void stacktrace_print_fp_pc(uintptr_t fp, uintptr_t pc)
     44static stacktrace_ops_t basic_ops = {
     45        .read_uintptr = stacktrace_read_uintptr
     46};
     47
     48void stacktrace_print_generic(stacktrace_ops_t *ops, void *arg, uintptr_t fp,
     49    uintptr_t pc)
    4550{
    4651        stacktrace_t st;
    4752        uintptr_t nfp;
     53        int rc;
    4854
    49         st.op_arg = NULL;
    50         st.read_uintptr = stacktrace_read_uintptr;
     55        st.op_arg = arg;
     56        st.ops = ops;
    5157
    5258        while (stacktrace_fp_valid(&st, fp)) {
    5359                printf("%p: %p()\n", (void *) fp, (void *) pc);
    54                 (void) stacktrace_ra_get(&st, fp, &pc);
    55                 (void) stacktrace_fp_prev(&st, fp, &nfp);
     60                rc =  stacktrace_ra_get(&st, fp, &pc);
     61                if (rc != EOK)
     62                        break;
     63                rc = stacktrace_fp_prev(&st, fp, &nfp);
     64                if (rc != EOK)
     65                        break;
    5666                fp = nfp;
    5767        }
     68}
     69
     70void stacktrace_print_fp_pc(uintptr_t fp, uintptr_t pc)
     71{
     72        stacktrace_print_generic(&basic_ops, NULL, fp, pc);
    5873}
    5974
  • uspace/lib/c/include/fibril.h

    r8e4a408 rc1b979a  
    6767typedef struct fibril {
    6868        link_t link;
     69        link_t all_link;
    6970        context_t ctx;
    7071        void *stack;
  • uspace/lib/c/include/stacktrace.h

    r8e4a408 rc1b979a  
    4141
    4242typedef struct {
     43        int (*read_uintptr)(void *, uintptr_t, uintptr_t *);
     44} stacktrace_ops_t;
     45
     46typedef struct {
    4347        void *op_arg;
    44         int (*read_uintptr)(void *, uintptr_t, uintptr_t *);
     48        stacktrace_ops_t *ops;
    4549} stacktrace_t;
    4650
    4751extern void stacktrace_print(void);
    4852extern void stacktrace_print_fp_pc(uintptr_t, uintptr_t);
     53extern void stacktrace_print_generic(stacktrace_ops_t *, void *, uintptr_t,
     54    uintptr_t);
    4955
    5056/*
Note: See TracChangeset for help on using the changeset viewer.