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

Cache object: ce90deb0dc46a7ea8343b575de09fb3f


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