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

Changeset 257ceb1 in mainline


Ignore:
Timestamp:
2010-07-16T09:06:56Z (10 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
63bdde6
Parents:
f77e591
Message:

Introduce the stack trace context which is passed to the individual stack
tracing hooks and which can carry some additional information.

Location:
kernel/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/stacktrace.h

    rf77e591 r257ceb1  
    4242
    4343typedef struct {
    44         bool (* frame_pointer_validate)(uintptr_t);
    45         bool (* frame_pointer_prev)(uintptr_t, uintptr_t *);
    46         bool (* return_address_get)(uintptr_t, uintptr_t *);
     44        uintptr_t fp;
     45        uintptr_t pc;
     46        struct istate *istate;
     47} stack_trace_context_t;
     48
     49typedef struct {
     50        bool (* stack_trace_context_validate)(stack_trace_context_t *);
     51        bool (* frame_pointer_prev)(stack_trace_context_t *, uintptr_t *);
     52        bool (* return_address_get)(stack_trace_context_t *, uintptr_t *);
    4753        bool (* symbol_resolve)(uintptr_t, const char **, uintptr_t *);
    4854} stack_trace_ops_t;
     
    5359extern void stack_trace(void);
    5460extern void stack_trace_istate(struct istate *);
    55 extern void stack_trace_fp_pc(stack_trace_ops_t *, uintptr_t, uintptr_t);
     61extern void stack_trace_ctx(stack_trace_ops_t *, stack_trace_context_t *);
    5662
    5763/*
     
    6167extern uintptr_t program_counter_get(void);
    6268
    63 extern bool kernel_frame_pointer_validate(uintptr_t);
    64 extern bool kernel_frame_pointer_prev(uintptr_t, uintptr_t *);
    65 extern bool kernel_return_address_get(uintptr_t, uintptr_t *);
     69extern bool kernel_stack_trace_context_validate(stack_trace_context_t *);
     70extern bool kernel_frame_pointer_prev(stack_trace_context_t *, uintptr_t *);
     71extern bool kernel_return_address_get(stack_trace_context_t *, uintptr_t *);
    6672
    67 extern bool uspace_frame_pointer_validate(uintptr_t);
    68 extern bool uspace_frame_pointer_prev(uintptr_t, uintptr_t *);
    69 extern bool uspace_return_address_get(uintptr_t, uintptr_t *);
     73extern bool uspace_stack_trace_context_validate(stack_trace_context_t *);
     74extern bool uspace_frame_pointer_prev(stack_trace_context_t *, uintptr_t *);
     75extern bool uspace_return_address_get(stack_trace_context_t *, uintptr_t *);
    7076
    7177#endif
  • kernel/generic/src/debug/stacktrace.c

    rf77e591 r257ceb1  
    2727 */
    2828
    29 /** @addtogroup genericdebug 
     29/** @addtogroup genericdebug
    3030 * @{
    3131 */
     
    4242
    4343void
    44 stack_trace_fp_pc(stack_trace_ops_t *ops, uintptr_t fp, uintptr_t pc)
     44stack_trace_ctx(stack_trace_ops_t *ops, stack_trace_context_t *ctx)
    4545{
    4646        int cnt = 0;
    4747        const char *symbol;
    4848        uintptr_t offset;
     49        uintptr_t fp;
     50        uintptr_t pc;
    4951       
    50         while (cnt++ < STACK_FRAMES_MAX && ops->frame_pointer_validate(fp)) {
     52        while (cnt++ < STACK_FRAMES_MAX &&
     53            ops->stack_trace_context_validate(ctx)) {
    5154                if (ops->symbol_resolve &&
    52                     ops->symbol_resolve(pc, &symbol, &offset)) {
     55                    ops->symbol_resolve(ctx->pc, &symbol, &offset)) {
    5356                        if (offset)
    54                                 printf("%p: %s+%" PRIp "()\n", fp, symbol, offset);
     57                                printf("%p: %s+%" PRIp "()\n",
     58                                    ctx->fp, symbol, offset);
    5559                        else
    56                                 printf("%p: %s()\n", fp, symbol);
     60                                printf("%p: %s()\n",
     61                                    ctx->fp, symbol);
    5762                } else {
    58                         printf("%p: %p()\n", fp, pc);
     63                        printf("%p: %p()\n", ctx->fp, ctx->pc);
    5964                }
    60                 if (!ops->return_address_get(fp, &pc))
     65                if (!ops->return_address_get(ctx, &pc))
    6166                        break;
    62                 if (!ops->frame_pointer_prev(fp, &fp))
     67                if (!ops->frame_pointer_prev(ctx, &fp))
    6368                        break;
     69                ctx->fp = fp;
     70                ctx->pc = pc;
    6471        }
    6572}
     
    6774void stack_trace(void)
    6875{
    69         stack_trace_fp_pc(&kst_ops, frame_pointer_get(), program_counter_get());
     76        stack_trace_context_t ctx = {
     77                .fp = frame_pointer_get(),
     78                .pc = program_counter_get(),
     79                .istate = NULL
     80        };
     81
     82        stack_trace_ctx(&kst_ops, &ctx);
    7083
    7184        /*
     
    7891void stack_trace_istate(istate_t *istate)
    7992{
     93        stack_trace_context_t ctx = {
     94                .fp = istate_get_fp(istate),
     95                .pc = istate_get_pc(istate),
     96                .istate = istate
     97        };
     98       
    8099        if (istate_from_uspace(istate))
    81                 stack_trace_fp_pc(&ust_ops, istate_get_fp(istate),
    82                     istate_get_pc(istate));
     100                stack_trace_ctx(&ust_ops, &ctx);
    83101        else
    84                 stack_trace_fp_pc(&kst_ops, istate_get_fp(istate),
    85                     istate_get_pc(istate));
     102                stack_trace_ctx(&kst_ops, &ctx);
    86103}
    87104
    88 static bool kernel_symbol_resolve(uintptr_t addr, const char **sp, uintptr_t *op)
     105static bool
     106kernel_symbol_resolve(uintptr_t addr, const char **sp, uintptr_t *op)
    89107{
    90108        return (symtab_name_lookup(addr, sp, op) == 0);
     
    92110
    93111stack_trace_ops_t kst_ops = {
    94         .frame_pointer_validate = kernel_frame_pointer_validate,
     112        .stack_trace_context_validate = kernel_stack_trace_context_validate,
    95113        .frame_pointer_prev = kernel_frame_pointer_prev,
    96114        .return_address_get = kernel_return_address_get,
     
    99117
    100118stack_trace_ops_t ust_ops = {
    101         .frame_pointer_validate = uspace_frame_pointer_validate,
     119        .stack_trace_context_validate = uspace_stack_trace_context_validate,
    102120        .frame_pointer_prev = uspace_frame_pointer_prev,
    103121        .return_address_get = uspace_return_address_get,
Note: See TracChangeset for help on using the changeset viewer.