db_trap.c revision 1.17.2.2
11.17.2.2Snathanw/*	$NetBSD: db_trap.c,v 1.17.2.2 2001/11/14 19:13:39 nathanw Exp $	*/
21.5Scgd
31.1Scgd/*
41.1Scgd * Mach Operating System
51.1Scgd * Copyright (c) 1991,1990 Carnegie Mellon University
61.1Scgd * All Rights Reserved.
71.1Scgd *
81.1Scgd * Permission to use, copy, modify and distribute this software and its
91.1Scgd * documentation is hereby granted, provided that both the copyright
101.1Scgd * notice and this permission notice appear in all copies of the
111.1Scgd * software, derivative works or modified versions, and any portions
121.1Scgd * thereof, and that both notices appear in supporting documentation.
131.1Scgd *
141.14Spk * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
151.1Scgd * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
161.1Scgd * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
171.1Scgd *
181.1Scgd * Carnegie Mellon requests users of this software to return to
191.1Scgd *
201.1Scgd *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
211.1Scgd *  School of Computer Science
221.1Scgd *  Carnegie Mellon University
231.1Scgd *  Pittsburgh PA 15213-3890
241.1Scgd *
251.1Scgd * any improvements or extensions that they make and grant Carnegie the
261.1Scgd * rights to redistribute these changes.
271.1Scgd *
281.1Scgd * 	Author: David B. Golub, Carnegie Mellon University
291.1Scgd *	Date:	7/90
301.1Scgd */
311.1Scgd
321.1Scgd/*
331.1Scgd * Trap entry point to kernel debugger.
341.1Scgd */
351.17.2.2Snathanw
361.17.2.2Snathanw#include <sys/cdefs.h>
371.17.2.2Snathanw__KERNEL_RCSID(0, "$NetBSD: db_trap.c,v 1.17.2.2 2001/11/14 19:13:39 nathanw Exp $");
381.17.2.2Snathanw
391.7Smycroft#include <sys/param.h>
401.17.2.1Snathanw#include <sys/lwp.h>
411.7Smycroft#include <sys/proc.h>
421.7Smycroft
431.7Smycroft#include <machine/db_machdep.h>
441.7Smycroft
451.6Smycroft#include <ddb/db_run.h>
461.1Scgd#include <ddb/db_command.h>
471.1Scgd#include <ddb/db_break.h>
481.9Schristos#include <ddb/db_output.h>
491.9Schristos#include <ddb/db_sym.h>
501.9Schristos#include <ddb/db_extern.h>
511.1Scgd
521.16Sjeffs/*
531.16Sjeffs * db_trap_callback can be hooked by MD port code to handle special
541.16Sjeffs * cases such as disabling hardware watchdogs while in DDB.
551.16Sjeffs */
561.15Sjeffsvoid (*db_trap_callback)(int);
571.15Sjeffs
581.9Schristosvoid
591.1Scgddb_trap(type, code)
601.1Scgd	int	type, code;
611.1Scgd{
621.1Scgd	boolean_t	bkpt;
631.1Scgd	boolean_t	watchpt;
641.1Scgd
651.1Scgd	bkpt = IS_BREAKPOINT_TRAP(type, code);
661.1Scgd	watchpt = IS_WATCHPOINT_TRAP(type, code);
671.1Scgd
681.15Sjeffs	if (db_trap_callback) db_trap_callback(1);
691.15Sjeffs
701.6Smycroft	if (db_stop_at_pc(DDB_REGS, &bkpt)) {
711.1Scgd	    if (db_inst_count) {
721.1Scgd		db_printf("After %d instructions (%d loads, %d stores),\n",
731.1Scgd			  db_inst_count, db_load_count, db_store_count);
741.1Scgd	    }
751.11Sross	    if (curproc != NULL) {
761.12Srvb		if (bkpt)
771.17Sjhawk			db_printf("Breakpoint");
781.12Srvb		else if (watchpt)
791.17Sjhawk			db_printf("Watchpoint");
801.12Srvb		else
811.17.2.1Snathanw			if (curproc->l_proc == NULL)
821.17.2.1Snathanw				db_printf("Stopped; curproc = %p, curproc->l_proc is NULL at\t", curproc);
831.17.2.1Snathanw			else
841.17.2.1Snathanw				db_printf("Stopped in %s at\t", curproc->l_proc->p_comm);
851.12Srvb	    } else if (bkpt)
861.1Scgd		db_printf("Breakpoint at\t");
871.1Scgd	    else if (watchpt)
881.1Scgd		db_printf("Watchpoint at\t");
891.1Scgd	    else
901.1Scgd		db_printf("Stopped at\t");
911.1Scgd	    db_dot = PC_REGS(DDB_REGS);
921.8Sgwr	    db_print_loc_and_inst(db_dot);
931.1Scgd
941.1Scgd	    db_command_loop();
951.1Scgd	}
961.1Scgd
971.6Smycroft	db_restart_at_pc(DDB_REGS, watchpt);
981.15Sjeffs
991.15Sjeffs	if (db_trap_callback) db_trap_callback(0);
1001.1Scgd}
101