direct-io.hg

view xen/include/asm-x86/debugger.h @ 3786:87ebc14decdb

bitkeeper revision 1.1178 (420c87ccD2VdHFZVGUqHR4Zd2yI1mg)

After a fatal trap, we want to debug whatever caused the trap rather than the trap
handler. Fix things up accordingly.

Also add some documentation while I'm here.

Signed-off-by: sos22@cl.cam.ac.uk.
author sos22@douglas.cl.cam.ac.uk
date Fri Feb 11 10:24:12 2005 +0000 (2005-02-11)
parents c37c674174f7
children dbf3fa962906
line source
1 /******************************************************************************
2 * asm/debugger.h
3 *
4 * Generic hooks into arch-dependent Xen.
5 *
6 * Each debugger should define two functions here:
7 *
8 * 1. debugger_trap_entry():
9 * Called at start of any synchronous fault or trap, before any other work
10 * is done. The idea is that if your debugger deliberately caused the trap
11 * (e.g. to implement breakpoints or data watchpoints) then you can take
12 * appropriate action and return a non-zero value to cause early exit from
13 * the trap function.
14 *
15 * 2. debugger_trap_fatal():
16 * Called when Xen is about to give up and crash. Typically you will use this
17 * hook to drop into a debug session. It can also be used to hook off
18 * deliberately caused traps (which you then handle and return non-zero)
19 * but really these should be hooked off 'debugger_trap_entry'.
20 *
21 * 3. debugger_trap_immediate():
22 * Called if we want to drop into a debugger now. This is essentially the
23 * same as debugger_trap_fatal, except that we use the current register state
24 * rather than the state which was in effect when we took the trap.
25 * Essentially, if we're dying because of an unhandled exception, we call
26 * debugger_trap_fatal; if we're dying because of a panic() we call
27 * debugger_trap_immediate().
28 */
30 #ifndef __X86_DEBUGGER_H__
31 #define __X86_DEBUGGER_H__
33 #include <asm/processor.h>
35 /* The main trap handlers use these helper macros which include early bail. */
36 #define DEBUGGER_trap_entry(_v, _r) \
37 if ( debugger_trap_entry(_v, _r) ) return EXCRET_fault_fixed;
38 #define DEBUGGER_trap_fatal(_v, _r) \
39 if ( debugger_trap_fatal(_v, _r) ) return EXCRET_fault_fixed;
41 #ifdef XEN_DEBUGGER
43 #include <asm/pdb.h>
45 static inline int debugger_trap_entry(
46 unsigned int vector, struct xen_regs *regs)
47 {
48 int ret = 0;
50 switch ( vector )
51 {
52 case TRAP_debug:
53 if ( pdb_initialized )
54 {
55 pdb_handle_debug_trap(regs, regs->error_code);
56 ret = 1; /* early exit */
57 }
58 break;
60 case TRAP_int3:
61 if ( pdb_initialized && (pdb_handle_exception(vector, regs) == 0) )
62 ret = 1; /* early exit */
63 break;
65 case TRAP_gp_fault:
66 if ( (VM86_MODE(regs) || !RING_0(regs)) &&
67 ((regs->error_code & 3) == 2) &&
68 pdb_initialized && (pdb_ctx.system_call != 0) )
69 {
70 unsigned long cr3 = read_cr3();
71 if ( cr3 == pdb_ctx.ptbr )
72 pdb_linux_syscall_enter_bkpt(
73 regs, regs->error_code,
74 current->thread.traps + (regs->error_code>>3));
75 }
76 break;
77 }
79 return ret;
80 }
82 static inline int debugger_trap_fatal(
83 unsigned int vector, struct xen_regs *regs)
84 {
85 int ret = 0;
87 switch ( vector )
88 {
89 case TRAP_page_fault:
90 if ( pdb_page_fault_possible )
91 {
92 pdb_page_fault = 1;
93 /* make eax & edx valid to complete the instruction */
94 regs->eax = (long)&pdb_page_fault_scratch;
95 regs->edx = (long)&pdb_page_fault_scratch;
96 ret = 1; /* exit - do not crash! */
97 }
98 break;
99 }
101 return ret;
102 }
104 #define debugger_trap_immediate() ()
106 #elif defined(CRASH_DEBUG)
108 extern void cdb_trap(void);
109 extern void __trap_to_cdb(struct xen_regs *);
110 #define debugger_trap_entry(_v, _r) (0)
111 #define debugger_trap_fatal(_v, _r) (__trap_to_cdb(_r), 0)
112 #define debugger_trap_immediate() (cdb_trap())
114 #elif 0
116 extern int kdb_trap(int, int, struct xen_regs *);
118 static inline int debugger_trap_entry(
119 unsigned int vector, struct xen_regs *regs)
120 {
121 return 0;
122 }
124 static inline int debugger_trap_fatal(
125 unsigned int vector, struct xen_regs *regs)
126 {
127 return kdb_trap(vector, 0, regs);
128 }
130 #else
132 #define debugger_trap_entry(_v, _r) (0)
133 #define debugger_trap_fatal(_v, _r) (0)
134 #define debugger_trap_immediate()
136 #endif
138 #endif /* __X86_DEBUGGER_H__ */