Home | History | Annotate | Line # | Download | only in ddb
db_trap.c revision 1.17.2.2
      1 /*	$NetBSD: db_trap.c,v 1.17.2.2 2001/11/14 19:13:39 nathanw Exp $	*/
      2 
      3 /*
      4  * Mach Operating System
      5  * Copyright (c) 1991,1990 Carnegie Mellon University
      6  * All Rights Reserved.
      7  *
      8  * Permission to use, copy, modify and distribute this software and its
      9  * documentation is hereby granted, provided that both the copyright
     10  * notice and this permission notice appear in all copies of the
     11  * software, derivative works or modified versions, and any portions
     12  * thereof, and that both notices appear in supporting documentation.
     13  *
     14  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     15  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     16  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     17  *
     18  * Carnegie Mellon requests users of this software to return to
     19  *
     20  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     21  *  School of Computer Science
     22  *  Carnegie Mellon University
     23  *  Pittsburgh PA 15213-3890
     24  *
     25  * any improvements or extensions that they make and grant Carnegie the
     26  * rights to redistribute these changes.
     27  *
     28  * 	Author: David B. Golub, Carnegie Mellon University
     29  *	Date:	7/90
     30  */
     31 
     32 /*
     33  * Trap entry point to kernel debugger.
     34  */
     35 
     36 #include <sys/cdefs.h>
     37 __KERNEL_RCSID(0, "$NetBSD: db_trap.c,v 1.17.2.2 2001/11/14 19:13:39 nathanw Exp $");
     38 
     39 #include <sys/param.h>
     40 #include <sys/lwp.h>
     41 #include <sys/proc.h>
     42 
     43 #include <machine/db_machdep.h>
     44 
     45 #include <ddb/db_run.h>
     46 #include <ddb/db_command.h>
     47 #include <ddb/db_break.h>
     48 #include <ddb/db_output.h>
     49 #include <ddb/db_sym.h>
     50 #include <ddb/db_extern.h>
     51 
     52 /*
     53  * db_trap_callback can be hooked by MD port code to handle special
     54  * cases such as disabling hardware watchdogs while in DDB.
     55  */
     56 void (*db_trap_callback)(int);
     57 
     58 void
     59 db_trap(type, code)
     60 	int	type, code;
     61 {
     62 	boolean_t	bkpt;
     63 	boolean_t	watchpt;
     64 
     65 	bkpt = IS_BREAKPOINT_TRAP(type, code);
     66 	watchpt = IS_WATCHPOINT_TRAP(type, code);
     67 
     68 	if (db_trap_callback) db_trap_callback(1);
     69 
     70 	if (db_stop_at_pc(DDB_REGS, &bkpt)) {
     71 	    if (db_inst_count) {
     72 		db_printf("After %d instructions (%d loads, %d stores),\n",
     73 			  db_inst_count, db_load_count, db_store_count);
     74 	    }
     75 	    if (curproc != NULL) {
     76 		if (bkpt)
     77 			db_printf("Breakpoint");
     78 		else if (watchpt)
     79 			db_printf("Watchpoint");
     80 		else
     81 			if (curproc->l_proc == NULL)
     82 				db_printf("Stopped; curproc = %p, curproc->l_proc is NULL at\t", curproc);
     83 			else
     84 				db_printf("Stopped in %s at\t", curproc->l_proc->p_comm);
     85 	    } else if (bkpt)
     86 		db_printf("Breakpoint at\t");
     87 	    else if (watchpt)
     88 		db_printf("Watchpoint at\t");
     89 	    else
     90 		db_printf("Stopped at\t");
     91 	    db_dot = PC_REGS(DDB_REGS);
     92 	    db_print_loc_and_inst(db_dot);
     93 
     94 	    db_command_loop();
     95 	}
     96 
     97 	db_restart_at_pc(DDB_REGS, watchpt);
     98 
     99 	if (db_trap_callback) db_trap_callback(0);
    100 }
    101