]> git.saurik.com Git - apple/xnu.git/blame - osfmk/ddb/db_trap.c
xnu-792.6.61.tar.gz
[apple/xnu.git] / osfmk / ddb / db_trap.c
CommitLineData
1c79356b 1/*
91447636 2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
1c79356b
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
1c79356b 11 *
37839358
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * @OSF_COPYRIGHT@
24 */
25/*
26 * Mach Operating System
27 * Copyright (c) 1991,1990 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50/*
51 */
52/*
53 * Author: David B. Golub, Carnegie Mellon University
54 * Date: 7/90
55 */
56
57/*
58 * Trap entry point to kernel debugger.
59 */
60#include <mach/boolean.h>
61#include <machine/db_machdep.h>
62#include <kern/misc_protos.h>
63#include <ddb/db_access.h>
64#include <ddb/db_break.h>
65#include <ddb/db_command.h>
66#include <ddb/db_examine.h>
67#include <ddb/db_output.h> /* For db_printf() */
68#include <ddb/db_run.h>
69#include <ddb/db_task_thread.h>
70#include <ddb/db_trap.h>
71#include <machine/setjmp.h>
72
73extern jmp_buf_t *db_recover;
74
75extern int db_inst_count;
76extern int db_load_count;
77extern int db_store_count;
78
1c79356b
A
79void
80db_task_trap(
81 int type,
82 int code,
83 boolean_t user_space)
84{
85 jmp_buf_t db_jmpbuf;
86 jmp_buf_t *prev;
87 boolean_t bkpt;
88 boolean_t watchpt;
89 task_t task;
90 task_t task_space;
91
92 task = db_current_task();
91447636 93 task_space = db_target_space(current_thread(), user_space);
1c79356b
A
94 bkpt = IS_BREAKPOINT_TRAP(type, code);
95 watchpt = IS_WATCHPOINT_TRAP(type, code);
96
97 /*
98 * Note: we look up PC values in an address space (task_space),
99 * but print symbols using a (task-specific) symbol table, found
100 * using task.
101 */
102 db_init_default_act();
103 db_check_breakpoint_valid();
104 if (db_stop_at_pc(&bkpt, task, task_space)) {
105 if (db_inst_count) {
106 db_printf("After %d instructions (%d loads, %d stores),\n",
107 db_inst_count, db_load_count, db_store_count);
108 }
109 if (bkpt)
110 db_printf("Breakpoint at ");
111 else if (watchpt)
112 db_printf("Watchpoint at ");
113 else
114 db_printf("Stopped at ");
115 db_dot = PC_REGS(DDB_REGS);
116
117 prev = db_recover;
118 if (_setjmp(db_recover = &db_jmpbuf) == 0) {
119#if defined(__alpha)
120 db_print_loc(db_dot, task_space);
121 db_printf("\n\t");
122 db_print_inst(db_dot, task_space);
123#else /* !defined(__alpha) */
124#if defined(__ppc__)
125 db_print_loc_and_inst(db_dot, task_space);
126#else /* __ppc__ */
127 db_print_loc_and_inst(db_dot, task);
128#endif /* __ppc__ */
129#endif /* defined(__alpha) */
130 } else
91447636 131 db_printf("Trouble printing location %#llX.\n", (unsigned long long)db_dot);
1c79356b
A
132 db_recover = prev;
133
134 db_command_loop();
135 }
136
137 db_restart_at_pc(watchpt, task_space);
138}