db_trap.c revision 1.5
1/*	$NetBSD: db_trap.c,v 1.5 1994/06/29 06:31:22 cgd 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
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 <ddb/db_command.h>
39#include <ddb/db_break.h>
40
41#include <setjmp.h>
42
43extern void		db_restart_at_pc();
44extern boolean_t	db_stop_at_pc();
45
46extern int		db_inst_count;
47extern int		db_load_count;
48extern int		db_store_count;
49
50extern jmp_buf		*db_recover;
51
52db_trap(type, code)
53	int	type, code;
54{
55	boolean_t	bkpt;
56	boolean_t	watchpt;
57	jmp_buf		db_jmpbuf;
58	jmp_buf		*savejmp = db_recover;
59
60	bkpt = IS_BREAKPOINT_TRAP(type, code);
61	watchpt = IS_WATCHPOINT_TRAP(type, code);
62
63	if (db_stop_at_pc(&bkpt)) {
64	    if (db_inst_count) {
65		db_printf("After %d instructions (%d loads, %d stores),\n",
66			  db_inst_count, db_load_count, db_store_count);
67	    }
68	    if (bkpt)
69		db_printf("Breakpoint at\t");
70	    else if (watchpt)
71		db_printf("Watchpoint at\t");
72	    else
73		db_printf("Stopped at\t");
74	    db_dot = PC_REGS(DDB_REGS);
75	    if (!setjmp(*(db_recover = &db_jmpbuf)))
76		db_print_loc_and_inst(db_dot);
77
78	    db_command_loop();
79	}
80
81	db_restart_at_pc(watchpt);
82}
83