github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/src/pkg/runtime/os_windows_amd64.c (about)

     1  // Copyright 2011 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  #include "runtime.h"
     6  #include "defs_GOOS_GOARCH.h"
     7  #include "os_GOOS.h"
     8  
     9  void
    10  runtime·dumpregs(Context *r)
    11  {
    12  	runtime·printf("rax     %X\n", r->Rax);
    13  	runtime·printf("rbx     %X\n", r->Rbx);
    14  	runtime·printf("rcx     %X\n", r->Rcx);
    15  	runtime·printf("rdx     %X\n", r->Rdx);
    16  	runtime·printf("rdi     %X\n", r->Rdi);
    17  	runtime·printf("rsi     %X\n", r->Rsi);
    18  	runtime·printf("rbp     %X\n", r->Rbp);
    19  	runtime·printf("rsp     %X\n", r->Rsp);
    20  	runtime·printf("r8      %X\n", r->R8 );
    21  	runtime·printf("r9      %X\n", r->R9 );
    22  	runtime·printf("r10     %X\n", r->R10);
    23  	runtime·printf("r11     %X\n", r->R11);
    24  	runtime·printf("r12     %X\n", r->R12);
    25  	runtime·printf("r13     %X\n", r->R13);
    26  	runtime·printf("r14     %X\n", r->R14);
    27  	runtime·printf("r15     %X\n", r->R15);
    28  	runtime·printf("rip     %X\n", r->Rip);
    29  	runtime·printf("rflags  %X\n", r->EFlags);
    30  	runtime·printf("cs      %X\n", (uint64)r->SegCs);
    31  	runtime·printf("fs      %X\n", (uint64)r->SegFs);
    32  	runtime·printf("gs      %X\n", (uint64)r->SegGs);
    33  }
    34  
    35  uint32
    36  runtime·sighandler(ExceptionRecord *info, Context *r, G *gp)
    37  {
    38  	bool crash;
    39  	uintptr *sp;
    40  
    41  	switch(info->ExceptionCode) {
    42  	case EXCEPTION_BREAKPOINT:
    43  		return 1;
    44  	}
    45  
    46  	if(gp != nil && runtime·issigpanic(info->ExceptionCode)) {
    47  		// Make it look like a call to the signal func.
    48  		// Have to pass arguments out of band since
    49  		// augmenting the stack frame would break
    50  		// the unwinding code.
    51  		gp->sig = info->ExceptionCode;
    52  		gp->sigcode0 = info->ExceptionInformation[0];
    53  		gp->sigcode1 = info->ExceptionInformation[1];
    54  		gp->sigpc = r->Rip;
    55  
    56  		// Only push runtime·sigpanic if r->rip != 0.
    57  		// If r->rip == 0, probably panicked because of a
    58  		// call to a nil func.  Not pushing that onto sp will
    59  		// make the trace look like a call to runtime·sigpanic instead.
    60  		// (Otherwise the trace will end at runtime·sigpanic and we
    61  		// won't get to see who faulted.)
    62  		if(r->Rip != 0) {
    63  			sp = (uintptr*)r->Rsp;
    64  			*--sp = r->Rip;
    65  			r->Rsp = (uintptr)sp;
    66  		}
    67  		r->Rip = (uintptr)runtime·sigpanic;
    68  		return 0;
    69  	}
    70  
    71  	if(runtime·panicking)	// traceback already printed
    72  		runtime·exit(2);
    73  	runtime·panicking = 1;
    74  
    75  	runtime·printf("Exception %x %p %p\n", info->ExceptionCode,
    76  		info->ExceptionInformation[0], info->ExceptionInformation[1]);
    77  
    78  	runtime·printf("PC=%X\n", r->Rip);
    79  	if(m->lockedg != nil && m->ncgo > 0 && gp == m->g0) {
    80  		runtime·printf("signal arrived during cgo execution\n");
    81  		gp = m->lockedg;
    82  	}
    83  	runtime·printf("\n");
    84  
    85  	if(runtime·gotraceback(&crash)){
    86  		runtime·traceback((void*)r->Rip, (void*)r->Rsp, 0, gp);
    87  		runtime·tracebackothers(gp);
    88  		runtime·dumpregs(r);
    89  	}
    90  	
    91  	if(crash)
    92  		runtime·crash();
    93  
    94  	runtime·exit(2);
    95  	return 0;
    96  }
    97  
    98  void
    99  runtime·sigenable(uint32 sig)
   100  {
   101  	USED(sig);
   102  }
   103  
   104  void
   105  runtime·sigdisable(uint32 sig)
   106  {
   107  	USED(sig);
   108  }
   109  
   110  void
   111  runtime·dosigprof(Context *r, G *gp)
   112  {
   113  	runtime·sigprof((uint8*)r->Rip, (uint8*)r->Rsp, nil, gp);
   114  }