当前位置: 首页>>代码示例>>Golang>>正文


Golang debug.SetPanicOnFault函数代码示例

本文整理汇总了Golang中runtime/debug.SetPanicOnFault函数的典型用法代码示例。如果您正苦于以下问题:Golang SetPanicOnFault函数的具体用法?Golang SetPanicOnFault怎么用?Golang SetPanicOnFault使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SetPanicOnFault函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: write

// write copies the argument buffer to memory starting at address p.
// Its boolean return tells whether it succeeded. If it fails, no bytes were copied.
func write(p uintptr, buf []byte) (ok bool) {
	defer catchFault(&ok)
	defer debug.SetPanicOnFault(debug.SetPanicOnFault(true))
	for i := range buf {
		*(*byte)(unsafe.Pointer(p)) = buf[i]
		p++
	}
	return true
}
开发者ID:rdterner,项目名称:debug,代码行数:11,代码来源:probe.go

示例2: TestSetPanicOnFault

func TestSetPanicOnFault(t *testing.T) {
	old := debug.SetPanicOnFault(true)
	defer debug.SetPanicOnFault(old)

	nfault := 0
	for _, addr := range faultAddrs {
		testSetPanicOnFault(t, uintptr(addr), &nfault)
	}
	if nfault == 0 {
		t.Fatalf("none of the addresses faulted")
	}
}
开发者ID:danny8002,项目名称:go,代码行数:12,代码来源:runtime_test.go

示例3: validWrite

// validWrite reports whether a write of the specified size can be done at address p.
// TODO: It does this by actually doing a write and seeing if it succeeds. Do better.
func validWrite(p uintptr, size int) (ok bool) {
	// Check for negative size and for (p + size) overflow.
	if size < 0 || uint64(^uintptr(0)-p) < uint64(size) {
		return false
	}
	defer catchFault(&ok)
	defer debug.SetPanicOnFault(debug.SetPanicOnFault(true))
	ep := p + uintptr(size)
	for p < ep {
		*(*byte)(unsafe.Pointer(p)) = *(*byte)(unsafe.Pointer(p))
		p++
	}
	return true
}
开发者ID:rdterner,项目名称:debug,代码行数:16,代码来源:probe.go

示例4: TestSetPanicOnFault

func TestSetPanicOnFault(t *testing.T) {
	// This currently results in a fault in the signal trampoline on
	// dragonfly/386 - see issue 7421.
	if GOOS == "dragonfly" && GOARCH == "386" {
		t.Skip("skipping test on dragonfly/386")
	}

	old := debug.SetPanicOnFault(true)
	defer debug.SetPanicOnFault(old)

	for _, addr := range faultAddrs {
		testSetPanicOnFault(t, uintptr(addr))
	}
}
开发者ID:h8liu,项目名称:golang,代码行数:14,代码来源:runtime_test.go

示例5: TestSetPanicOnFault

func TestSetPanicOnFault(t *testing.T) {
	old := debug.SetPanicOnFault(true)
	defer debug.SetPanicOnFault(old)

	defer func() {
		if err := recover(); err == nil {
			t.Fatalf("did not find error in recover")
		}
	}()

	var p *int
	p = (*int)(unsafe.Pointer(^uintptr(0)))
	println(*p)
	t.Fatalf("still here - should have faulted")
}
开发者ID:TomHoenderdos,项目名称:go-sunos,代码行数:15,代码来源:runtime_test.go

示例6: main

func main() {
	// Turn the eventual fault into a panic, not a program crash,
	// so that memcopy can recover.
	debug.SetPanicOnFault(true)

	size := syscall.Getpagesize()

	// Map 16 pages of data with a 4-page hole in the middle.
	data, err := syscall.Mmap(-1, 0, 16*size, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANON|syscall.MAP_PRIVATE)
	if err != nil {
		log.Fatalf("mmap: %v", err)
	}

	// Note: Cannot call syscall.Munmap, because Munmap checks
	// that you are unmapping a whole region returned by Mmap.
	// We are trying to unmap just a hole in the middle.
	if _, _, err := syscall.Syscall(syscall.SYS_MUNMAP, uintptr(unsafe.Pointer(&data[8*size])), uintptr(4*size), 0); err != 0 {
		log.Fatalf("munmap: %v", err)
	}

	other := make([]byte, 16*size)

	// Check that memcopy returns the actual amount copied
	// before the fault (8*size - 5, the offset we skip in the argument).
	n, err := memcopy(data[5:], other)
	if err == nil {
		log.Fatal("no error from memcopy across memory hole")
	}
	if n != 8*size-5 {
		log.Fatal("memcopy returned %d, want %d", n, 8*size-5)
	}
}
开发者ID:wheelcomplex,项目名称:go-1,代码行数:32,代码来源:recover4.go

示例7: TestSetPanicOnFault

func TestSetPanicOnFault(t *testing.T) {
	// This currently results in a fault in the signal trampoline on
	// dragonfly/386 - see issue 7421.
	if GOOS == "dragonfly" && GOARCH == "386" {
		t.Skip("skipping test on dragonfly/386")
	}

	old := debug.SetPanicOnFault(true)
	defer debug.SetPanicOnFault(old)

	for _, addr := range faultAddrs {
		if Compiler == "gccgo" && GOARCH == "386" && (addr&0xff000000) != 0 {
			// On gccgo these addresses can be used for
			// the thread stack.
			continue
		}
		testSetPanicOnFault(t, uintptr(addr))
	}
}
开发者ID:mbref,项目名称:gcc-microblaze,代码行数:19,代码来源:runtime_test.go

示例8: TestSetPanicOnFault

func TestSetPanicOnFault(t *testing.T) {
	t.Skip("skipping for llgo due to lack of non-call exception support")

	// This currently results in a fault in the signal trampoline on
	// dragonfly/386 - see issue 7421.
	if GOOS == "dragonfly" && GOARCH == "386" {
		t.Skip("skipping test on dragonfly/386")
	}

	old := debug.SetPanicOnFault(true)
	defer debug.SetPanicOnFault(old)

	nfault := 0
	for _, addr := range faultAddrs {
		testSetPanicOnFault(t, uintptr(addr), &nfault)
	}
	if nfault == 0 {
		t.Fatalf("none of the addresses faulted")
	}
}
开发者ID:glycerine,项目名称:llgo,代码行数:20,代码来源:runtime_test.go

示例9: TestSetPanicOnFault

func TestSetPanicOnFault(t *testing.T) {
	// This currently results in a fault in the signal trampoline on
	// dragonfly/386 - see issue 7421.
	if GOOS == "dragonfly" && GOARCH == "386" {
		t.Skip("skipping test on dragonfly/386")
	}

	old := debug.SetPanicOnFault(true)
	defer debug.SetPanicOnFault(old)

	defer func() {
		if err := recover(); err == nil {
			t.Fatalf("did not find error in recover")
		}
	}()

	var p *int
	p = (*int)(unsafe.Pointer(^uintptr(0)))
	println(*p)
	t.Fatalf("still here - should have faulted")
}
开发者ID:rosrad,项目名称:go-rep,代码行数:21,代码来源:runtime_test.go

示例10: main

func main() {
	debug.SetPanicOnFault(true)
	defer func() {
		if err := recover(); err == nil {
			panic("not panicking")
		}
		pc, _, _, _ := runtime.Caller(10)
		f := runtime.FuncForPC(pc)
		if f == nil || f.Name() != "main.f" {
			if f == nil {
				println("no func for ", unsafe.Pointer(pc))
			} else {
				println("found func:", f.Name())
			}
			panic("cannot find main.f on stack")
		}
	}()
	f(20)
}
开发者ID:wycharry,项目名称:go,代码行数:19,代码来源:issue11656.go


注:本文中的runtime/debug.SetPanicOnFault函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。