LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 #include "runtime.h" | 5 #include "runtime.h" |
6 #include "defs_GOOS_GOARCH.h" | 6 #include "defs_GOOS_GOARCH.h" |
7 #include "os_GOOS.h" | 7 #include "os_GOOS.h" |
8 | 8 |
9 void | 9 void |
10 runtime·dumpregs(Context *r) | 10 runtime·dumpregs(Context *r) |
11 { | 11 { |
12 runtime·printf("eax %x\n", r->Eax); | 12 runtime·printf("eax %x\n", r->Eax); |
13 runtime·printf("ebx %x\n", r->Ebx); | 13 runtime·printf("ebx %x\n", r->Ebx); |
14 runtime·printf("ecx %x\n", r->Ecx); | 14 runtime·printf("ecx %x\n", r->Ecx); |
15 runtime·printf("edx %x\n", r->Edx); | 15 runtime·printf("edx %x\n", r->Edx); |
16 runtime·printf("edi %x\n", r->Edi); | 16 runtime·printf("edi %x\n", r->Edi); |
17 runtime·printf("esi %x\n", r->Esi); | 17 runtime·printf("esi %x\n", r->Esi); |
18 runtime·printf("ebp %x\n", r->Ebp); | 18 runtime·printf("ebp %x\n", r->Ebp); |
19 runtime·printf("esp %x\n", r->Esp); | 19 runtime·printf("esp %x\n", r->Esp); |
20 runtime·printf("eip %x\n", r->Eip); | 20 runtime·printf("eip %x\n", r->Eip); |
21 runtime·printf("eflags %x\n", r->EFlags); | 21 runtime·printf("eflags %x\n", r->EFlags); |
22 runtime·printf("cs %x\n", r->SegCs); | 22 runtime·printf("cs %x\n", r->SegCs); |
23 runtime·printf("fs %x\n", r->SegFs); | 23 runtime·printf("fs %x\n", r->SegFs); |
24 runtime·printf("gs %x\n", r->SegGs); | 24 runtime·printf("gs %x\n", r->SegGs); |
25 } | 25 } |
26 | 26 |
| 27 #define DBG_PRINTEXCEPTION_C 0x40010006 |
| 28 |
27 // Called by sigtramp from Windows VEH handler. | 29 // Called by sigtramp from Windows VEH handler. |
28 // Return value signals whether the exception has been handled (-1) | 30 // Return value signals whether the exception has been handled (-1) |
29 // or should be made available to other handlers in the chain (0). | 31 // or should be made available to other handlers in the chain (0). |
30 uint32 | 32 uint32 |
31 runtime·sighandler(ExceptionRecord *info, Context *r, G *gp) | 33 runtime·sighandler(ExceptionRecord *info, Context *r, G *gp) |
32 { | 34 { |
33 bool crash; | 35 bool crash; |
34 uintptr *sp; | 36 uintptr *sp; |
35 | 37 |
36 // It is unclear whether this is needed, unclear whether it | |
37 // would work, and unclear how to test it. Leave out for now. | |
38 // This only handles breakpoint instructions written in the | |
39 // assembly sources, not breakpoints set by a debugger. | |
40 /* | |
41 switch(info->ExceptionCode) { | 38 switch(info->ExceptionCode) { |
| 39 case DBG_PRINTEXCEPTION_C: |
| 40 // This exception is intended to be caught by debuggers. |
| 41 // There is a not-very-informational message like |
| 42 // "Invalid parameter passed to C runtime function" |
| 43 // sitting at info->ExceptionInformation[0] (a wchar_t*), |
| 44 // with length info->ExceptionInformation[1]. |
| 45 // The default behavior is to ignore this exception, |
| 46 // but somehow returning 0 here (meaning keep going) |
| 47 // makes the program crash instead. Maybe Windows has no |
| 48 // other handler registered? In any event, ignore it. |
| 49 return -1; |
| 50 |
42 case EXCEPTION_BREAKPOINT: | 51 case EXCEPTION_BREAKPOINT: |
43 » » r->Eip--;» // because 8l generates 2 bytes for INT3 | 52 » » // It is unclear whether this is needed, unclear whether it |
44 » » return 0; | 53 » » // would work, and unclear how to test it. Leave out for now. |
| 54 » » // This only handles breakpoint instructions written in the |
| 55 » » // assembly sources, not breakpoints set by a debugger, and |
| 56 » » // there are very few of the former. |
| 57 » » // |
| 58 » » // r->Eip--;» // because 8l generates 2 bytes for INT3 |
| 59 » » // return 0; |
| 60 » » break; |
45 } | 61 } |
46 */ | |
47 | 62 |
48 if(gp != nil && runtime·issigpanic(info->ExceptionCode)) { | 63 if(gp != nil && runtime·issigpanic(info->ExceptionCode)) { |
49 // Make it look like a call to the signal func. | 64 // Make it look like a call to the signal func. |
50 // Have to pass arguments out of band since | 65 // Have to pass arguments out of band since |
51 // augmenting the stack frame would break | 66 // augmenting the stack frame would break |
52 // the unwinding code. | 67 // the unwinding code. |
53 gp->sig = info->ExceptionCode; | 68 gp->sig = info->ExceptionCode; |
54 gp->sigcode0 = info->ExceptionInformation[0]; | 69 gp->sigcode0 = info->ExceptionInformation[0]; |
55 gp->sigcode1 = info->ExceptionInformation[1]; | 70 gp->sigcode1 = info->ExceptionInformation[1]; |
56 gp->sigpc = r->Eip; | 71 gp->sigpc = r->Eip; |
(...skipping 10 matching lines...) Expand all Loading... |
67 r->Esp = (uintptr)sp; | 82 r->Esp = (uintptr)sp; |
68 } | 83 } |
69 r->Eip = (uintptr)runtime·sigpanic; | 84 r->Eip = (uintptr)runtime·sigpanic; |
70 return -1; | 85 return -1; |
71 } | 86 } |
72 | 87 |
73 if(runtime·panicking) // traceback already printed | 88 if(runtime·panicking) // traceback already printed |
74 runtime·exit(2); | 89 runtime·exit(2); |
75 runtime·panicking = 1; | 90 runtime·panicking = 1; |
76 | 91 |
77 » runtime·printf("Exception %x %p %p\n", info->ExceptionCode, | 92 » runtime·printf("Exception %x %p %p %p\n", info->ExceptionCode, |
78 » » info->ExceptionInformation[0], info->ExceptionInformation[1]); | 93 » » info->ExceptionInformation[0], info->ExceptionInformation[1], r-
>Eip); |
79 | 94 |
80 runtime·printf("PC=%x\n", r->Eip); | 95 runtime·printf("PC=%x\n", r->Eip); |
81 if(m->lockedg != nil && m->ncgo > 0 && gp == m->g0) { | 96 if(m->lockedg != nil && m->ncgo > 0 && gp == m->g0) { |
82 runtime·printf("signal arrived during cgo execution\n"); | 97 runtime·printf("signal arrived during cgo execution\n"); |
83 gp = m->lockedg; | 98 gp = m->lockedg; |
84 } | 99 } |
85 runtime·printf("\n"); | 100 runtime·printf("\n"); |
86 | 101 |
87 if(runtime·gotraceback(&crash)){ | 102 if(runtime·gotraceback(&crash)){ |
88 runtime·traceback(r->Eip, r->Esp, 0, gp); | 103 runtime·traceback(r->Eip, r->Esp, 0, gp); |
(...skipping 18 matching lines...) Expand all Loading... |
107 runtime·sigdisable(uint32 sig) | 122 runtime·sigdisable(uint32 sig) |
108 { | 123 { |
109 USED(sig); | 124 USED(sig); |
110 } | 125 } |
111 | 126 |
112 void | 127 void |
113 runtime·dosigprof(Context *r, G *gp, M *mp) | 128 runtime·dosigprof(Context *r, G *gp, M *mp) |
114 { | 129 { |
115 runtime·sigprof((uint8*)r->Eip, (uint8*)r->Esp, nil, gp, mp); | 130 runtime·sigprof((uint8*)r->Eip, (uint8*)r->Esp, nil, gp, mp); |
116 } | 131 } |
LEFT | RIGHT |