The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/powerpc/powerpc/db_trace.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $FreeBSD: releng/6.4/sys/powerpc/powerpc/db_trace.c 156647 2006-03-13 03:07:01Z jeff $ */
    2 /*      $NetBSD: db_trace.c,v 1.20 2002/05/13 20:30:09 matt Exp $       */
    3 /*      $OpenBSD: db_trace.c,v 1.3 1997/03/21 02:10:48 niklas Exp $     */
    4 
    5 /*-
    6  * Mach Operating System
    7  * Copyright (c) 1992 Carnegie Mellon University
    8  * All Rights Reserved.
    9  *
   10  * Permission to use, copy, modify and distribute this software and its
   11  * documentation is hereby granted, provided that both the copyright
   12  * notice and this permission notice appear in all copies of the
   13  * software, derivative works or modified versions, and any portions
   14  * thereof, and that both notices appear in supporting documentation.
   15  *
   16  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   17  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   18  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   19  *
   20  * Carnegie Mellon requests users of this software to return to
   21  *
   22  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   23  *  School of Computer Science
   24  *  Carnegie Mellon University
   25  *  Pittsburgh PA 15213-3890
   26  *
   27  * any improvements or extensions that they make and grant Carnegie Mellon
   28  * the rights to redistribute these changes.
   29  */
   30 
   31 #include <sys/param.h>
   32 #include <sys/systm.h>
   33 #include <sys/kdb.h>
   34 #include <sys/proc.h>
   35 #include <sys/stack.h>
   36 
   37 #include <vm/vm.h>
   38 #include <vm/pmap.h>
   39 #include <vm/vm_extern.h>
   40 
   41 #include <machine/db_machdep.h>
   42 #include <machine/pcb.h>
   43 #include <machine/spr.h>
   44 #include <machine/trap.h>
   45 
   46 #include <ddb/ddb.h>
   47 #include <ddb/db_access.h>
   48 #include <ddb/db_sym.h>
   49 #include <ddb/db_variables.h>
   50 
   51 static db_varfcn_t db_frame;
   52 
   53 #define DB_OFFSET(x)    (db_expr_t *)offsetof(struct trapframe, x)
   54 
   55 struct db_variable db_regs[] = {
   56         { "r0",  DB_OFFSET(fixreg[0]),  db_frame },
   57         { "r1",  DB_OFFSET(fixreg[1]),  db_frame },
   58         { "r2",  DB_OFFSET(fixreg[2]),  db_frame },
   59         { "r3",  DB_OFFSET(fixreg[3]),  db_frame },
   60         { "r4",  DB_OFFSET(fixreg[4]),  db_frame },
   61         { "r5",  DB_OFFSET(fixreg[5]),  db_frame },
   62         { "r6",  DB_OFFSET(fixreg[6]),  db_frame },
   63         { "r7",  DB_OFFSET(fixreg[7]),  db_frame },
   64         { "r8",  DB_OFFSET(fixreg[8]),  db_frame },
   65         { "r9",  DB_OFFSET(fixreg[9]),  db_frame },
   66         { "r10", DB_OFFSET(fixreg[10]), db_frame },
   67         { "r11", DB_OFFSET(fixreg[11]), db_frame },
   68         { "r12", DB_OFFSET(fixreg[12]), db_frame },
   69         { "r13", DB_OFFSET(fixreg[13]), db_frame },
   70         { "r14", DB_OFFSET(fixreg[14]), db_frame },
   71         { "r15", DB_OFFSET(fixreg[15]), db_frame },
   72         { "r16", DB_OFFSET(fixreg[16]), db_frame },
   73         { "r17", DB_OFFSET(fixreg[17]), db_frame },
   74         { "r18", DB_OFFSET(fixreg[18]), db_frame },
   75         { "r19", DB_OFFSET(fixreg[19]), db_frame },
   76         { "r20", DB_OFFSET(fixreg[20]), db_frame },
   77         { "r21", DB_OFFSET(fixreg[21]), db_frame },
   78         { "r22", DB_OFFSET(fixreg[22]), db_frame },
   79         { "r23", DB_OFFSET(fixreg[23]), db_frame },
   80         { "r24", DB_OFFSET(fixreg[24]), db_frame },
   81         { "r25", DB_OFFSET(fixreg[25]), db_frame },
   82         { "r26", DB_OFFSET(fixreg[26]), db_frame },
   83         { "r27", DB_OFFSET(fixreg[27]), db_frame },
   84         { "r28", DB_OFFSET(fixreg[28]), db_frame },
   85         { "r29", DB_OFFSET(fixreg[29]), db_frame },
   86         { "r30", DB_OFFSET(fixreg[30]), db_frame },
   87         { "r31", DB_OFFSET(fixreg[31]), db_frame },
   88         { "srr0", DB_OFFSET(srr0),      db_frame },
   89         { "srr1", DB_OFFSET(srr1),      db_frame },
   90         { "lr",  DB_OFFSET(lr),         db_frame },
   91         { "ctr", DB_OFFSET(ctr),        db_frame },
   92         { "cr",  DB_OFFSET(cr),         db_frame },
   93         { "xer", DB_OFFSET(xer),        db_frame },
   94         { "dar", DB_OFFSET(dar),        db_frame },
   95         { "dsisr", DB_OFFSET(dsisr),    db_frame },
   96 };
   97 struct db_variable *db_eregs = db_regs + sizeof (db_regs)/sizeof (db_regs[0]);
   98 
   99 extern int trapexit[];
  100 extern int end[];
  101 
  102 /*
  103  * register variable handling
  104  */
  105 static int
  106 db_frame(struct db_variable *vp, db_expr_t *valuep, int op)
  107 {
  108         uint32_t *reg;
  109 
  110         if (kdb_frame == NULL)
  111                 return (0);
  112         reg = (uint32_t*)((uintptr_t)kdb_frame + (uintptr_t)vp->valuep);
  113         if (op == DB_VAR_GET)
  114                 *valuep = *reg;
  115         else
  116                 *reg = *valuep;
  117         return (1);
  118 }
  119 
  120 
  121 /*
  122  *      Frame tracing.
  123  */
  124 static int
  125 db_backtrace(struct thread *td, db_addr_t fp, int count)
  126 {
  127         db_addr_t stackframe, lr, *args;
  128         db_expr_t diff;
  129         c_db_sym_t sym;
  130         const char *symname;
  131         boolean_t kernel_only = TRUE;
  132         boolean_t full = FALSE;
  133         int quit;
  134 
  135 #if 0
  136         {
  137                 register char *cp = modif;
  138                 register char c;
  139 
  140                 while ((c = *cp++) != 0) {
  141                         if (c == 't')
  142                                 trace_thread = TRUE;
  143                         if (c == 'u')
  144                                 kernel_only = FALSE;
  145                         if (c == 'f')
  146                                 full = TRUE;
  147                 }
  148         }
  149 #endif
  150 
  151         stackframe = fp;
  152 
  153         quit = 0;
  154         db_setup_paging(db_simple_pager, &quit, db_lines_per_page);
  155         while (!quit) {
  156                 if (stackframe < PAGE_SIZE)
  157                         break;
  158 
  159                 /*
  160                  * Locate the next frame by grabbing the backchain ptr
  161                  * from frame[0]
  162                  */
  163                 stackframe = *(db_addr_t *)stackframe;
  164 
  165         next_frame:
  166                 /* The saved arg values start at frame[2] */
  167                 args = (db_addr_t *)(stackframe + 8);
  168 
  169                 if (stackframe < PAGE_SIZE)
  170                         break;
  171 
  172                 if (count-- == 0)
  173                         break;
  174 
  175                 /*
  176                  * Extract link register from frame and subtract
  177                  * 4 to convert into calling address (as opposed to
  178                  * return address)
  179                  */
  180                 lr = *(db_addr_t *)(stackframe + 4) - 4;
  181                 if ((lr & 3) || (lr < 0x100)) {
  182                         db_printf("saved LR(0x%x) is invalid.", lr);
  183                         break;
  184                 }
  185 
  186                 db_printf("0x%08x: ", stackframe);
  187 
  188                 /*
  189                  * The trap code labels the return address from the
  190                  * call to C code as 'trapexit'. Use this to determine
  191                  * if the callframe has to traverse a saved trap context
  192                  */
  193                 if (lr + 4 == (db_addr_t) &trapexit) {
  194                         const char *trapstr;
  195                         struct trapframe *tf = (struct trapframe *)
  196                                 (stackframe+8);
  197                         db_printf("%s ", tf->srr1 & PSL_PR ? "user" : "kernel");
  198                         switch (tf->exc) {
  199                         case EXC_DSI:
  200                                 db_printf("DSI %s trap @ %#x by ",
  201                                     tf->dsisr & DSISR_STORE ? "write" : "read",
  202                                     tf->dar);
  203                                 goto print_trap;
  204                         case EXC_ALI:
  205                                 db_printf("ALI trap @ %#x (DSISR %#x) ",
  206                                           tf->dar, tf->dsisr);
  207                                 goto print_trap;
  208                         case EXC_ISI: trapstr = "ISI"; break;
  209                         case EXC_PGM: trapstr = "PGM"; break;
  210                         case EXC_SC: trapstr = "SC"; break;
  211                         case EXC_EXI: trapstr = "EXI"; break;
  212                         case EXC_MCHK: trapstr = "MCHK"; break;
  213                         case EXC_VEC: trapstr = "VEC"; break;
  214                         case EXC_FPU: trapstr = "FPU"; break;
  215                         case EXC_FPA: trapstr = "FPA"; break;
  216                         case EXC_DECR: trapstr = "DECR"; break;
  217                         case EXC_BPT: trapstr = "BPT"; break;
  218                         case EXC_TRC: trapstr = "TRC"; break;
  219                         case EXC_RUNMODETRC: trapstr = "RUNMODETRC"; break;
  220                         case EXC_PERF: trapstr = "PERF"; break;
  221                         case EXC_SMI: trapstr = "SMI"; break;
  222                         case EXC_RST: trapstr = "RST"; break;
  223                         default: trapstr = NULL; break;
  224                         }
  225                         if (trapstr != NULL) {
  226                                 db_printf("%s trap by ", trapstr);
  227                         } else {
  228                                 db_printf("trap %#x by ", tf->exc);
  229                         }
  230 
  231                    print_trap:
  232                         lr = (db_addr_t) tf->srr0;
  233                         diff = 0;
  234                         symname = NULL;
  235                         sym = db_search_symbol(lr, DB_STGY_ANY, &diff);
  236                         db_symbol_values(sym, &symname, 0);
  237                         if (symname == NULL || !strcmp(symname, "end")) {
  238                                 db_printf("%#x: srr1=%#x\n", lr, tf->srr1);
  239                         } else {
  240                                 db_printf("%s+%#x: srr1=%#x\n", symname, diff,
  241                                     tf->srr1);
  242                         }
  243                         db_printf("%-10s  r1=%#x cr=%#x xer=%#x ctr=%#x",
  244                             "", tf->fixreg[1], tf->cr, tf->xer, tf->ctr);
  245                         if (tf->exc == EXC_DSI)
  246                                 db_printf(" dsisr=%#x", tf->dsisr);
  247                         db_printf("\n");
  248                         stackframe = (db_addr_t) tf->fixreg[1];
  249                         if (kernel_only && (tf->srr1 & PSL_PR))
  250                                 break;
  251                         goto next_frame;
  252                 }
  253 
  254                 diff = 0;
  255                 symname = NULL;
  256                 sym = db_search_symbol(lr, DB_STGY_ANY, &diff);
  257                 db_symbol_values(sym, &symname, 0);
  258                 if (symname == NULL || !strcmp(symname, "end"))
  259                         db_printf("at %x", lr);
  260                 else
  261                         db_printf("at %s+%#x", symname, diff);
  262                 if (full)
  263                         /* Print all the args stored in that stackframe. */
  264                         db_printf("(%x, %x, %x, %x, %x, %x, %x, %x)",
  265                                 args[0], args[1], args[2], args[3],
  266                                 args[4], args[5], args[6], args[7]);
  267                 db_printf("\n");
  268         }
  269 
  270         return (0);
  271 }
  272 
  273 void
  274 db_trace_self(void)
  275 {
  276         db_addr_t addr;
  277 
  278         addr = (db_addr_t)__builtin_frame_address(1);
  279         db_backtrace(curthread, addr, -1);
  280 }
  281 
  282 int
  283 db_trace_thread(struct thread *td, int count)
  284 {
  285         struct pcb *ctx;
  286 
  287         ctx = kdb_thr_ctx(td);
  288         return (db_backtrace(td, (db_addr_t)ctx->pcb_sp, count));
  289 }
  290 
  291 void
  292 stack_save(struct stack *st)
  293 {
  294         vm_offset_t callpc;
  295         db_addr_t stackframe;
  296 
  297         stack_zero(st);
  298         stackframe = (db_addr_t)__builtin_frame_address(1);
  299         if (stackframe < PAGE_SIZE)
  300                 return;
  301         while (1) {
  302                 stackframe = *(db_addr_t *)stackframe;
  303                 if (stackframe < PAGE_SIZE)
  304                         break;
  305                 callpc = *(vm_offset_t *)(stackframe + 4) - 4;
  306                 if ((callpc & 3) || (callpc < 0x100))
  307                         break;
  308                 if (stack_put(st, callpc) == -1)
  309                         break;
  310         }
  311 }
  312 

Cache object: ff265434a6713c10eb9b8133cad39087


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.