db_trap.c revision 1.17
1/*	$NetBSD: db_trap.c,v 1.17 2000/12/20 15:42:37 jhawk 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@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#include <sys/param.h>
36#include <sys/proc.h>
37
38#include <machine/db_machdep.h>
39
40#include <ddb/db_run.h>
41#include <ddb/db_command.h>
42#include <ddb/db_break.h>
43#include <ddb/db_output.h>
44#include <ddb/db_sym.h>
45#include <ddb/db_extern.h>
46
47/*
48 * db_trap_callback can be hooked by MD port code to handle special
49 * cases such as disabling hardware watchdogs while in DDB.
50 */
51void (*db_trap_callback)(int);
52
53void
54db_trap(type, code)
55	int	type, code;
56{
57	boolean_t	bkpt;
58	boolean_t	watchpt;
59
60	bkpt = IS_BREAKPOINT_TRAP(type, code);
61	watchpt = IS_WATCHPOINT_TRAP(type, code);
62
63	if (db_trap_callback) db_trap_callback(1);
64
65	if (db_stop_at_pc(DDB_REGS, &bkpt)) {
66	    if (db_inst_count) {
67		db_printf("After %d instructions (%d loads, %d stores),\n",
68			  db_inst_count, db_load_count, db_store_count);
69	    }
70	    if (curproc != NULL) {
71		if (bkpt)
72			db_printf("Breakpoint");
73		else if (watchpt)
74			db_printf("Watchpoint");
75		else
76			db_printf("Stopped");
77		db_printf(" in pid %d (%s) at\t", curproc->p_pid,
78		    curproc->p_comm);
79	    } else if (bkpt)
80		db_printf("Breakpoint at\t");
81	    else if (watchpt)
82		db_printf("Watchpoint at\t");
83	    else
84		db_printf("Stopped at\t");
85	    db_dot = PC_REGS(DDB_REGS);
86	    db_print_loc_and_inst(db_dot);
87
88	    db_command_loop();
89	}
90
91	db_restart_at_pc(DDB_REGS, watchpt);
92
93	if (db_trap_callback) db_trap_callback(0);
94}
95