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.0/sys/powerpc/powerpc/db_trace.c 139825 2005-01-07 02:29:27Z imp $ */
    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 
   36 #include <vm/vm.h>
   37 #include <vm/pmap.h>
   38 #include <vm/vm_extern.h>
   39 
   40 #include <machine/db_machdep.h>
   41 #include <machine/pcb.h>
   42 #include <machine/spr.h>
   43 #include <machine/trap.h>
   44 
   45 #include <ddb/ddb.h>
   46 #include <ddb/db_access.h>
   47 #include <ddb/db_sym.h>
   48 #include <ddb/db_variables.h>
   49 
   50 static db_varfcn_t db_frame;
   51 
   52 #define DB_OFFSET(x)    (db_expr_t *)offsetof(struct trapframe, x)
   53 
   54 struct db_variable db_regs[] = {
   55         { "r0",  DB_OFFSET(fixreg[0]),  db_frame },
   56         { "r1",  DB_OFFSET(fixreg[1]),  db_frame },
   57         { "r2",  DB_OFFSET(fixreg[2]),  db_frame },
   58         { "r3",  DB_OFFSET(fixreg[3]),  db_frame },
   59         { "r4",  DB_OFFSET(fixreg[4]),  db_frame },
   60         { "r5",  DB_OFFSET(fixreg[5]),  db_frame },
   61         { "r6",  DB_OFFSET(fixreg[6]),  db_frame },
   62         { "r7",  DB_OFFSET(fixreg[7]),  db_frame },
   63         { "r8",  DB_OFFSET(fixreg[8]),  db_frame },
   64         { "r9",  DB_OFFSET(fixreg[9]),  db_frame },
   65         { "r10", DB_OFFSET(fixreg[10]), db_frame },
   66         { "r11", DB_OFFSET(fixreg[11]), db_frame },
   67         { "r12", DB_OFFSET(fixreg[12]), db_frame },
   68         { "r13", DB_OFFSET(fixreg[13]), db_frame },
   69         { "r14", DB_OFFSET(fixreg[14]), db_frame },
   70         { "r15", DB_OFFSET(fixreg[15]), db_frame },
   71         { "r16", DB_OFFSET(fixreg[16]), db_frame },
   72         { "r17", DB_OFFSET(fixreg[17]), db_frame },
   73         { "r18", DB_OFFSET(fixreg[18]), db_frame },
   74         { "r19", DB_OFFSET(fixreg[19]), db_frame },
   75         { "r20", DB_OFFSET(fixreg[20]), db_frame },
   76         { "r21", DB_OFFSET(fixreg[21]), db_frame },
   77         { "r22", DB_OFFSET(fixreg[22]), db_frame },
   78         { "r23", DB_OFFSET(fixreg[23]), db_frame },
   79         { "r24", DB_OFFSET(fixreg[24]), db_frame },
   80         { "r25", DB_OFFSET(fixreg[25]), db_frame },
   81         { "r26", DB_OFFSET(fixreg[26]), db_frame },
   82         { "r27", DB_OFFSET(fixreg[27]), db_frame },
   83         { "r28", DB_OFFSET(fixreg[28]), db_frame },
   84         { "r29", DB_OFFSET(fixreg[29]), db_frame },
   85         { "r30", DB_OFFSET(fixreg[30]), db_frame },
   86         { "r31", DB_OFFSET(fixreg[31]), db_frame },
   87         { "srr0", DB_OFFSET(srr0),      db_frame },
   88         { "srr1", DB_OFFSET(srr1),      db_frame },
   89         { "lr",  DB_OFFSET(lr),         db_frame },
   90         { "ctr", DB_OFFSET(ctr),        db_frame },
   91         { "cr",  DB_OFFSET(cr),         db_frame },
   92         { "xer", DB_OFFSET(xer),        db_frame },
   93         { "dar", DB_OFFSET(dar),        db_frame },
   94         { "dsisr", DB_OFFSET(dsisr),    db_frame },
   95 };
   96 struct db_variable *db_eregs = db_regs + sizeof (db_regs)/sizeof (db_regs[0]);
   97 
   98 extern int trapexit[];
   99 extern int end[];
  100 
  101 /*
  102  * register variable handling
  103  */
  104 static int
  105 db_frame(struct db_variable *vp, db_expr_t *valuep, int op)
  106 {
  107         uint32_t *reg;
  108 
  109         if (kdb_frame == NULL)
  110                 return (0);
  111         reg = (uint32_t*)((uintptr_t)kdb_frame + (uintptr_t)vp->valuep);
  112         if (op == DB_VAR_GET)
  113                 *valuep = *reg;
  114         else
  115                 *reg = *valuep;
  116         return (1);
  117 }
  118 
  119 
  120 /*
  121  *      Frame tracing.
  122  */
  123 static int
  124 db_backtrace(struct thread *td, db_addr_t fp, int count)
  125 {
  126         db_addr_t stackframe, lr, *args;
  127         db_expr_t diff;
  128         c_db_sym_t sym;
  129         const char *symname;
  130         boolean_t kernel_only = TRUE;
  131         boolean_t full = FALSE;
  132         int quit;
  133 
  134 #if 0
  135         {
  136                 register char *cp = modif;
  137                 register char c;
  138 
  139                 while ((c = *cp++) != 0) {
  140                         if (c == 't')
  141                                 trace_thread = TRUE;
  142                         if (c == 'u')
  143                                 kernel_only = FALSE;
  144                         if (c == 'f')
  145                                 full = TRUE;
  146                 }
  147         }
  148 #endif
  149 
  150         stackframe = fp;
  151 
  152         quit = 0;
  153         db_setup_paging(db_simple_pager, &quit, db_lines_per_page);
  154         while (!quit) {
  155                 if (stackframe < PAGE_SIZE)
  156                         break;
  157 
  158                 /*
  159                  * Locate the next frame by grabbing the backchain ptr
  160                  * from frame[0]
  161                  */
  162                 stackframe = *(db_addr_t *)stackframe;
  163 
  164         next_frame:
  165                 /* The saved arg values start at frame[2] */
  166                 args = (db_addr_t *)(stackframe + 8);
  167 
  168                 if (stackframe < PAGE_SIZE)
  169                         break;
  170 
  171                 if (count-- == 0)
  172                         break;
  173 
  174                 /*
  175                  * Extract link register from frame and subtract
  176                  * 4 to convert into calling address (as opposed to
  177                  * return address)
  178                  */
  179                 lr = *(db_addr_t *)(stackframe + 4) - 4;
  180                 if ((lr & 3) || (lr < 0x100)) {
  181                         db_printf("saved LR(0x%x) is invalid.", lr);
  182                         break;
  183                 }
  184 
  185                 db_printf("0x%08x: ", stackframe);
  186 
  187                 /*
  188                  * The trap code labels the return address from the
  189                  * call to C code as 'trapexit'. Use this to determine
  190                  * if the callframe has to traverse a saved trap context
  191                  */
  192                 if (lr + 4 == (db_addr_t) &trapexit) {
  193                         const char *trapstr;
  194                         struct trapframe *tf = (struct trapframe *)
  195                                 (stackframe+8);
  196                         db_printf("%s ", tf->srr1 & PSL_PR ? "user" : "kernel");
  197                         switch (tf->exc) {
  198                         case EXC_DSI:
  199                                 db_printf("DSI %s trap @ %#x by ",
  200                                     tf->dsisr & DSISR_STORE ? "write" : "read",
  201                                     tf->dar);
  202                                 goto print_trap;
  203                         case EXC_ALI:
  204                                 db_printf("ALI trap @ %#x (DSISR %#x) ",
  205                                           tf->dar, tf->dsisr);
  206                                 goto print_trap;
  207                         case EXC_ISI: trapstr = "ISI"; break;
  208                         case EXC_PGM: trapstr = "PGM"; break;
  209                         case EXC_SC: trapstr = "SC"; break;
  210                         case EXC_EXI: trapstr = "EXI"; break;
  211                         case EXC_MCHK: trapstr = "MCHK"; break;
  212                         case EXC_VEC: trapstr = "VEC"; break;
  213                         case EXC_FPU: trapstr = "FPU"; break;
  214                         case EXC_FPA: trapstr = "FPA"; break;
  215                         case EXC_DECR: trapstr = "DECR"; break;
  216                         case EXC_BPT: trapstr = "BPT"; break;
  217                         case EXC_TRC: trapstr = "TRC"; break;
  218                         case EXC_RUNMODETRC: trapstr = "RUNMODETRC"; break;
  219                         case EXC_PERF: trapstr = "PERF"; break;
  220                         case EXC_SMI: trapstr = "SMI"; break;
  221                         case EXC_RST: trapstr = "RST"; break;
  222                         default: trapstr = NULL; break;
  223                         }
  224                         if (trapstr != NULL) {
  225                                 db_printf("%s trap by ", trapstr);
  226                         } else {
  227                                 db_printf("trap %#x by ", tf->exc);
  228                         }
  229 
  230                    print_trap:
  231                         lr = (db_addr_t) tf->srr0;
  232                         diff = 0;
  233                         symname = NULL;
  234                         sym = db_search_symbol(lr, DB_STGY_ANY, &diff);
  235                         db_symbol_values(sym, &symname, 0);
  236                         if (symname == NULL || !strcmp(symname, "end")) {
  237                                 db_printf("%#x: srr1=%#x\n", lr, tf->srr1);
  238                         } else {
  239                                 db_printf("%s+%#x: srr1=%#x\n", symname, diff,
  240                                     tf->srr1);
  241                         }
  242                         db_printf("%-10s  r1=%#x cr=%#x xer=%#x ctr=%#x",
  243                             "", tf->fixreg[1], tf->cr, tf->xer, tf->ctr);
  244                         if (tf->exc == EXC_DSI)
  245                                 db_printf(" dsisr=%#x", tf->dsisr);
  246                         db_printf("\n");
  247                         stackframe = (db_addr_t) tf->fixreg[1];
  248                         if (kernel_only && (tf->srr1 & PSL_PR))
  249                                 break;
  250                         goto next_frame;
  251                 }
  252 
  253                 diff = 0;
  254                 symname = NULL;
  255                 sym = db_search_symbol(lr, DB_STGY_ANY, &diff);
  256                 db_symbol_values(sym, &symname, 0);
  257                 if (symname == NULL || !strcmp(symname, "end"))
  258                         db_printf("at %x", lr);
  259                 else
  260                         db_printf("at %s+%#x", symname, diff);
  261                 if (full)
  262                         /* Print all the args stored in that stackframe. */
  263                         db_printf("(%x, %x, %x, %x, %x, %x, %x, %x)",
  264                                 args[0], args[1], args[2], args[3],
  265                                 args[4], args[5], args[6], args[7]);
  266                 db_printf("\n");
  267         }
  268 
  269         return (0);
  270 }
  271 
  272 void
  273 db_trace_self(void)
  274 {
  275         db_addr_t addr;
  276 
  277         addr = (db_addr_t)__builtin_frame_address(1);
  278         db_backtrace(curthread, addr, -1);
  279 }
  280 
  281 int
  282 db_trace_thread(struct thread *td, int count)
  283 {
  284         struct pcb *ctx;
  285 
  286         ctx = kdb_thr_ctx(td);
  287         return (db_backtrace(td, (db_addr_t)ctx->pcb_sp, count));
  288 }
  289 

Cache object: 8c2f155c8b4b7bb72b8e94438db67f28


[ 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.