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