Make it possible to ignore page faults in GDB.
[pintos-anon] / src / misc / bochs-2.2.6-page-fault-segv.patch
1 Index: bochs-2.2.6/cpu/exception.cc
2 diff -u bochs-2.2.6/cpu/exception.cc\~ bochs-2.2.6/cpu/exception.cc
3 --- bochs-2.2.6/cpu/exception.cc~ 2006-09-28 15:51:39.000000000 -0700
4 +++ bochs-2.2.6/cpu/exception.cc 2006-12-08 11:14:33.000000000 -0800
5 @@ -1033,6 +1033,7 @@ void BX_CPU_C::exception(unsigned vector
6      BX_CPU_THIS_PTR curr_exception[0] = exception_type;
7    }
8  
9 +  bx_gdbstub_exception(vector);
10  #if BX_CPU_LEVEL >= 2
11    if (!real_mode()) {
12      BX_CPU_THIS_PTR interrupt(vector, 0, push_error, error_code);
13 Index: bochs-2.2.6/gdbstub.cc
14 diff -u bochs-2.2.6/gdbstub.cc\~ bochs-2.2.6/gdbstub.cc
15 --- bochs-2.2.6/gdbstub.cc~ 2006-09-28 15:51:39.000000000 -0700
16 +++ bochs-2.2.6/gdbstub.cc 2006-12-08 11:12:03.000000000 -0800
17 @@ -26,6 +26,7 @@ static int last_stop_reason = GDBSTUB_ST
18  #define GDBSTUB_EXECUTION_BREAKPOINT    (0xac1)
19  #define GDBSTUB_TRACE                   (0xac2)
20  #define GDBSTUB_USER_BREAK              (0xac3)
21 +#define GDBSTUB_EXCEPTION_0E            (0xac4)
22  
23  static int listen_socket_fd;
24  static int socket_fd;
25 @@ -271,6 +272,12 @@ int bx_gdbstub_check(unsigned int eip)
26     return(GDBSTUB_STOP_NO_REASON);
27  }
28  
29 +void bx_gdbstub_exception(unsigned int nr) 
30 +{
31 +    if (nr == 0x0e)
32 +        last_stop_reason = GDBSTUB_EXCEPTION_0E;
33 +}
34 +
35  static int remove_breakpoint(unsigned int addr, int len)
36  {
37     unsigned int i;
38 @@ -452,6 +459,10 @@ static void debug_loop(void)
39                     {
40                        write_signal(&buf[1], SIGTRAP);
41                     }
42 +                 else if (last_stop_reason == GDBSTUB_EXCEPTION_0E)
43 +                   {
44 +                      write_signal(&buf[1], SIGSEGV);
45 +                   }
46                   else
47                     {
48                        write_signal(&buf[1], 0);
49 @@ -476,10 +487,14 @@ static void debug_loop(void)
50                     {
51                        write_signal(&buf[1], SIGTRAP);
52                     }
53 -                 else
54 +                 else if (last_stop_reason == GDBSTUB_EXCEPTION_0E)
55                     {
56                        write_signal(&buf[1], SIGSEGV);
57                     }
58 +                 else
59 +                   {
60 +                      write_signal(&buf[1], 0);
61 +                   }
62                   put_reply(buf);
63                   break;
64                }
65 Index: bochs-2.2.6/bochs.h
66 diff -u bochs-2.2.6/bochs.h\~ bochs-2.2.6/bochs.h
67 --- bochs-2.2.6/bochs.h~ 2006-09-28 15:51:39.000000000 -0700
68 +++ bochs-2.2.6/bochs.h 2006-12-08 11:14:19.000000000 -0800
69 @@ -375,6 +375,7 @@ BOCHSAPI extern logfunc_t *genlog;
70  // defines for GDB stub
71  void bx_gdbstub_init(int argc, char* argv[]);
72  int bx_gdbstub_check(unsigned int eip);
73 +void bx_gdbstub_exception(unsigned int nr);
74  #define GDBSTUB_STOP_NO_REASON   (0xac0)
75  
76  #if BX_SUPPORT_SMP