Line data Source code
1 : /* $OpenBSD: db_trap.c,v 1.28 2017/01/09 17:58:44 mpi Exp $ */
2 : /* $NetBSD: db_trap.c,v 1.9 1996/02/05 01:57:18 christos Exp $ */
3 :
4 : /*
5 : * Mach Operating System
6 : * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University
7 : * All Rights Reserved.
8 : *
9 : * Permission to use, copy, modify and distribute this software and its
10 : * documentation is hereby granted, provided that both the copyright
11 : * notice and this permission notice appear in all copies of the
12 : * software, derivative works or modified versions, and any portions
13 : * thereof, and that both notices appear in supporting documentation.
14 : *
15 : * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 : * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17 : * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 : *
19 : * Carnegie Mellon requests users of this software to return to
20 : *
21 : * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 : * School of Computer Science
23 : * Carnegie Mellon University
24 : * Pittsburgh PA 15213-3890
25 : *
26 : * any improvements or extensions that they make and grant Carnegie Mellon
27 : * the rights to redistribute these changes.
28 : *
29 : * Author: David B. Golub, Carnegie Mellon University
30 : * Date: 7/90
31 : */
32 :
33 : /*
34 : * Trap entry point to kernel debugger.
35 : */
36 : #include <sys/param.h>
37 : #include <sys/systm.h>
38 :
39 : #include <machine/db_machdep.h>
40 :
41 : #include <ddb/db_run.h>
42 : #include <ddb/db_command.h>
43 : #include <ddb/db_output.h>
44 : #include <ddb/db_sym.h>
45 : #include <ddb/db_extern.h>
46 : #include <ddb/db_interface.h>
47 : #include <ddb/db_var.h>
48 :
49 : void
50 0 : db_trap(int type, int code)
51 : {
52 0 : boolean_t bkpt;
53 : boolean_t watchpt;
54 :
55 0 : db_is_active = 1;
56 0 : bkpt = IS_BREAKPOINT_TRAP(type, code);
57 0 : watchpt = IS_WATCHPOINT_TRAP(type, code);
58 :
59 0 : if (db_stop_at_pc(&ddb_regs, &bkpt)) {
60 0 : if (db_inst_count) {
61 0 : db_printf("After %d instructions\n", db_inst_count);
62 0 : }
63 0 : if (bkpt)
64 0 : db_printf("Breakpoint at\t");
65 0 : else if (watchpt)
66 0 : db_printf("Watchpoint at\t");
67 : else
68 0 : db_printf("Stopped at\t");
69 0 : db_dot = PC_REGS(&ddb_regs);
70 0 : db_print_loc_and_inst(db_dot);
71 :
72 0 : if (panicstr != NULL) {
73 : static int ddb_msg_shown;
74 :
75 0 : if (! ddb_msg_shown) {
76 : /* show on-proc threads */
77 0 : db_show_all_procs(0, 0, 0, "o");
78 0 : }
79 : /* then the backtrace */
80 0 : db_stack_trace_print(db_dot, 0, 14 /* arbitrary */, "",
81 : db_printf);
82 :
83 0 : if (db_print_position() != 0)
84 0 : db_printf("\n");
85 0 : if (! ddb_msg_shown) {
86 0 : db_printf(
87 : "https://www.openbsd.org/ddb.html describes the minimum info required in bug\n"
88 : "reports. Insufficient info makes it difficult to find and fix bugs.\n");
89 0 : ddb_msg_shown = 1;
90 0 : }
91 : }
92 :
93 0 : db_command_loop();
94 0 : }
95 :
96 0 : db_restart_at_pc(&ddb_regs, watchpt);
97 0 : db_is_active = 0;
98 0 : }
|