ia64/xen-unstable

view xen/include/asm-x86/debugger.h @ 3776:d9449b5a8d64

bitkeeper revision 1.1170.1.1 (420b98f5HLKkq19C9PxLpNFZOD2-mg)

Make it compile in the non-crash_debug case.
author sos22@douglas.cl.cam.ac.uk
date Thu Feb 10 17:25:09 2005 +0000 (2005-02-10)
parents 415d774d6ee7
children c37c674174f7
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 */
22 #ifndef __X86_DEBUGGER_H__
23 #define __X86_DEBUGGER_H__
25 #include <asm/processor.h>
27 /* The main trap handlers use these helper macros which include early bail. */
28 #define DEBUGGER_trap_entry(_v, _r) \
29 if ( debugger_trap_entry(_v, _r) ) return EXCRET_fault_fixed;
30 #define DEBUGGER_trap_fatal(_v, _r) \
31 if ( debugger_trap_fatal(_v, _r) ) return EXCRET_fault_fixed;
33 #ifdef XEN_DEBUGGER
35 #include <asm/pdb.h>
37 static inline int debugger_trap_entry(
38 unsigned int vector, struct xen_regs *regs)
39 {
40 int ret = 0;
42 switch ( vector )
43 {
44 case TRAP_debug:
45 if ( pdb_initialized )
46 {
47 pdb_handle_debug_trap(regs, regs->error_code);
48 ret = 1; /* early exit */
49 }
50 break;
52 case TRAP_int3:
53 if ( pdb_initialized && (pdb_handle_exception(vector, regs) == 0) )
54 ret = 1; /* early exit */
55 break;
57 case TRAP_gp_fault:
58 if ( (VM86_MODE(regs) || !RING_0(regs)) &&
59 ((regs->error_code & 3) == 2) &&
60 pdb_initialized && (pdb_ctx.system_call != 0) )
61 {
62 unsigned long cr3 = read_cr3();
63 if ( cr3 == pdb_ctx.ptbr )
64 pdb_linux_syscall_enter_bkpt(
65 regs, regs->error_code,
66 current->thread.traps + (regs->error_code>>3));
67 }
68 break;
69 }
71 return ret;
72 }
74 static inline int debugger_trap_fatal(
75 unsigned int vector, struct xen_regs *regs)
76 {
77 int ret = 0;
79 switch ( vector )
80 {
81 case TRAP_page_fault:
82 if ( pdb_page_fault_possible )
83 {
84 pdb_page_fault = 1;
85 /* make eax & edx valid to complete the instruction */
86 regs->eax = (long)&pdb_page_fault_scratch;
87 regs->edx = (long)&pdb_page_fault_scratch;
88 ret = 1; /* exit - do not crash! */
89 }
90 break;
91 }
93 return ret;
94 }
96 #define debugger_trap_immediate() ()
98 #elif defined(CRASH_DEBUG)
100 extern void cdb_trap(void);
101 extern void __trap_to_cdb(struct xen_regs *);
102 #define debugger_trap_entry(_v, _r) (0)
103 #define debugger_trap_fatal(_v, _r) (__trap_to_cdb(_r), 0)
104 #define debugger_trap_immediate() (cdb_trap())
106 #elif 0
108 extern int kdb_trap(int, int, struct xen_regs *);
110 static inline int debugger_trap_entry(
111 unsigned int vector, struct xen_regs *regs)
112 {
113 return 0;
114 }
116 static inline int debugger_trap_fatal(
117 unsigned int vector, struct xen_regs *regs)
118 {
119 return kdb_trap(vector, 0, regs);
120 }
122 #else
124 #define debugger_trap_entry(_v, _r) (0)
125 #define debugger_trap_fatal(_v, _r) (0)
126 #define debugger_trap_immediate()
128 #endif
130 #endif /* __X86_DEBUGGER_H__ */