Changeset 46c20c8 in mainline for kernel/generic/src/debug


Ignore:
Timestamp:
2010-11-26T20:08:10Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45df59a
Parents:
fb150d78 (diff), ffdd2b9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
kernel/generic/src/debug
Files:
1 added
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/debug/debug.c

    rfb150d78 r46c20c8  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Martin Decky
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 #include <test.h>
    30 #include <arch.h>
    31 #include <atomic.h>
     29/** @addtogroup genericdebug
     30 * @{
     31 */
     32
     33/**
     34 * @file
     35 * @brief Kernel instrumentation functions.
     36 */
     37
     38#ifdef CONFIG_TRACE
     39
     40#include <debug.h>
     41#include <symtab.h>
     42#include <errno.h>
    3243#include <print.h>
    33 #include <proc/thread.h>
    3444
    35 #include <synch/rwlock.h>
    36 
    37 #define READERS  50
    38 #define WRITERS  50
    39 
    40 static rwlock_t rwlock;
    41 
    42 static void writer(void *arg)
     45void __cyg_profile_func_enter(void *fn, void *call_site)
    4346{
    44         TPRINTF("Trying to lock rwlock for writing....\n");
     47        const char *fn_sym = symtab_fmt_name_lookup((uintptr_t) fn);
    4548       
    46         rwlock_write_lock(&rwlock);
    47         rwlock_write_unlock(&rwlock);
     49        const char *call_site_sym;
     50        uintptr_t call_site_off;
    4851       
    49         TPRINTF("Trying to lock rwlock for reading....\n");
    50        
    51         rwlock_read_lock(&rwlock);
    52         rwlock_read_unlock(&rwlock);
     52        if (symtab_name_lookup((uintptr_t) call_site, &call_site_sym,
     53            &call_site_off) == EOK)
     54                printf("%s()+%p->%s()\n", call_site_sym,
     55                    (void *) call_site_off, fn_sym);
     56        else
     57                printf("->%s()\n", fn_sym);
    5358}
    5459
    55 char *test_rwlock2(void)
     60void __cyg_profile_func_exit(void *fn, void *call_site)
    5661{
    57         thread_t *thrd;
     62        const char *fn_sym = symtab_fmt_name_lookup((uintptr_t) fn);
    5863       
    59         rwlock_initialize(&rwlock);
     64        const char *call_site_sym;
     65        uintptr_t call_site_off;
    6066       
    61         rwlock_read_lock(&rwlock);
    62         rwlock_read_lock(&rwlock);
    63         rwlock_read_lock(&rwlock);
    64         rwlock_read_lock(&rwlock);
    65        
    66         thrd = thread_create(writer, NULL, TASK, 0, "writer", false);
    67         if (thrd)
    68                 thread_ready(thrd);
     67        if (symtab_name_lookup((uintptr_t) call_site, &call_site_sym,
     68            &call_site_off) == EOK)
     69                printf("%s()+%p<-%s()\n", call_site_sym,
     70                    (void *) call_site_off, fn_sym);
    6971        else
    70                 return "Could not create thread";
    71        
    72         thread_sleep(1);
    73        
    74         rwlock_read_unlock(&rwlock);
    75         rwlock_read_unlock(&rwlock);
    76         rwlock_read_unlock(&rwlock);
    77         rwlock_read_unlock(&rwlock);
    78        
    79         thread_join(thrd);
    80         thread_detach(thrd);
    81        
    82         return NULL;
     72                printf("<-%s()\n", fn_sym);
    8373}
     74
     75#endif /* CONFIG_TRACE */
     76
     77/** @}
     78 */
  • kernel/generic/src/debug/stacktrace.c

    rfb150d78 r46c20c8  
    2727 */
    2828
    29 /** @addtogroup genericdebug 
     29/** @addtogroup genericdebug
    3030 * @{
    3131 */
     
    3535#include <stacktrace.h>
    3636#include <interrupt.h>
    37 #include <arch/types.h>
     37#include <typedefs.h>
    3838#include <symtab.h>
     39#include <print.h>
    3940
    4041#define STACK_FRAMES_MAX        20
    4142
    42 void
    43 stack_trace_fp_pc(stack_trace_ops_t *ops, uintptr_t fp, uintptr_t pc)
     43void stack_trace_ctx(stack_trace_ops_t *ops, stack_trace_context_t *ctx)
    4444{
    4545        int cnt = 0;
    46         char *symbol;
     46        const char *symbol;
    4747        uintptr_t offset;
    48 
    49         while (cnt++ < STACK_FRAMES_MAX && ops->frame_pointer_validate(fp)) {
     48        uintptr_t fp;
     49        uintptr_t pc;
     50       
     51        while (cnt++ < STACK_FRAMES_MAX &&
     52            ops->stack_trace_context_validate(ctx)) {
    5053                if (ops->symbol_resolve &&
    51                     ops->symbol_resolve(pc, &symbol, &offset)) {
    52                         if (offset)
    53                                 printf("%p: %s+%p()\n", fp, symbol, offset);
     54                    ops->symbol_resolve(ctx->pc, &symbol, &offset)) {
     55                        if (offset)
     56                                printf("%p: %s()+%p\n", (void *) ctx->fp,
     57                                    symbol, (void *) offset);
    5458                        else
    55                                 printf("%p: %s()\n", fp, symbol);
    56                 } else {
    57                         printf("%p: %p()\n", fp, pc);
    58                 }
    59                 if (!ops->return_address_get(fp, &pc))
     59                                printf("%p: %s()\n", (void *) ctx->fp, symbol);
     60                } else
     61                        printf("%p: %p()\n", (void *) ctx->fp, (void *) ctx->pc);
     62               
     63                if (!ops->return_address_get(ctx, &pc))
    6064                        break;
    61                 if (!ops->frame_pointer_prev(fp, &fp))
     65               
     66                if (!ops->frame_pointer_prev(ctx, &fp))
    6267                        break;
     68               
     69                ctx->fp = fp;
     70                ctx->pc = pc;
    6371        }
    6472}
     
    6674void stack_trace(void)
    6775{
    68         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);
    6983
    7084        /*
     
    7791void stack_trace_istate(istate_t *istate)
    7892{
     93        stack_trace_context_t ctx = {
     94                .fp = istate_get_fp(istate),
     95                .pc = istate_get_pc(istate),
     96                .istate = istate
     97        };
     98       
    7999        if (istate_from_uspace(istate))
    80                 stack_trace_fp_pc(&ust_ops, istate_get_fp(istate),
    81                     istate_get_pc(istate));
     100                stack_trace_ctx(&ust_ops, &ctx);
    82101        else
    83                 stack_trace_fp_pc(&kst_ops, istate_get_fp(istate),
    84                     istate_get_pc(istate));
     102                stack_trace_ctx(&kst_ops, &ctx);
    85103}
    86104
    87 static bool kernel_symbol_resolve(uintptr_t addr, char **sp, uintptr_t *op)
     105static bool
     106kernel_symbol_resolve(uintptr_t addr, const char **sp, uintptr_t *op)
    88107{
    89108        return (symtab_name_lookup(addr, sp, op) == 0);
     
    91110
    92111stack_trace_ops_t kst_ops = {
    93         .frame_pointer_validate = kernel_frame_pointer_validate,
     112        .stack_trace_context_validate = kernel_stack_trace_context_validate,
    94113        .frame_pointer_prev = kernel_frame_pointer_prev,
    95114        .return_address_get = kernel_return_address_get,
     
    98117
    99118stack_trace_ops_t ust_ops = {
    100         .frame_pointer_validate = uspace_frame_pointer_validate,
     119        .stack_trace_context_validate = uspace_stack_trace_context_validate,
    101120        .frame_pointer_prev = uspace_frame_pointer_prev,
    102121        .return_address_get = uspace_return_address_get,
  • kernel/generic/src/debug/symtab.c

    rfb150d78 r46c20c8  
    3838#include <symtab.h>
    3939#include <byteorder.h>
    40 #include <string.h>
     40#include <str.h>
    4141#include <print.h>
    42 #include <arch/types.h>
     42#include <typedefs.h>
    4343#include <typedefs.h>
    4444#include <errno.h>
     
    4646/** Get name of a symbol that seems most likely to correspond to address.
    4747 *
    48  * @param addr          Address.
    49  * @param name          Place to store pointer to the symbol name.
    50  * @param offset        Place to store offset from the symbol address.
     48 * @param addr   Address.
     49 * @param name   Place to store pointer to the symbol name.
     50 * @param offset Place to store offset from the symbol address.
    5151 *
    5252 * @return Zero on success or negative error code, ENOENT if not found,
     
    5454 *
    5555 */
    56 int symtab_name_lookup(uintptr_t addr, char **name, uintptr_t *offset)
     56int symtab_name_lookup(uintptr_t addr, const char **name, uintptr_t *offset)
    5757{
    5858#ifdef CONFIG_SYMTAB
     
    8383/** Lookup symbol by address and format for display.
    8484 *
    85  * Returns name of closest corresponding symbol, "Not found" if none exists
    86  * or "N/A" if no symbol information is available.
     85 * Returns name of closest corresponding symbol,
     86 * "unknown" if none exists and "N/A" if no symbol
     87 * information is available.
    8788 *
    8889 * @param addr Address.
     
    9293 *
    9394 */
    94 char *symtab_fmt_name_lookup(uintptr_t addr)
    95 {
    96         char *name;
     95const char *symtab_fmt_name_lookup(uintptr_t addr)
     96{
     97        const char *name;
    9798        int rc = symtab_name_lookup(addr, &name, NULL);
    9899       
     
    101102                return name;
    102103        case ENOENT:
    103                 return "Not found";
     104                return "unknown";
    104105        default:
    105106                return "N/A";
     
    191192                uintptr_t addr = uint64_t_le2host(symbol_table[pos].address_le);
    192193                char *realname = symbol_table[pos].symbol_name;
    193                 printf("%p: %s\n", addr, realname);
     194                printf("%p: %s\n", (void *) addr, realname);
    194195                pos++;
    195196        }
     
    239240                printf("\n");
    240241                pos = 0;
    241                 while ((hint = symtab_search_one(name, &pos))) {
     242                while (symtab_search_one(name, &pos)) {
    242243                        printf("%s\n", symbol_table[pos].symbol_name);
    243244                        pos++;
Note: See TracChangeset for help on using the changeset viewer.