whatcanGOwrong

This commit is contained in:
2024-09-19 21:38:24 -04:00
commit d0ae4d841d
17908 changed files with 4096831 additions and 0 deletions
@@ -0,0 +1,9 @@
package main
import "fmt"
func asmFunc(*int) int
func main() {
fmt.Printf("%d\n", asmFunc(nil))
}
@@ -0,0 +1,7 @@
#include "textflag.h"
TEXT ·asmFunc(SB),0,$0-16
MOVL arg+0(FP), AX
MOVL (AX), AX
MOVL AX, ret+4(FP)
RET
@@ -0,0 +1,7 @@
#include "textflag.h"
TEXT ·asmFunc(SB),0,$0-16
MOVQ arg+0(FP), AX
MOVQ (AX), AX
MOVQ AX, ret+8(FP)
RET
@@ -0,0 +1,7 @@
#include "textflag.h"
TEXT ·asmFunc(SB),0,$0-16
MOVD arg+0(FP), R5
MOVD (R5), R5
MOVD R5, ret+8(FP)
RET
@@ -0,0 +1,7 @@
#include "textflag.h"
TEXT ·asmFunc(SB),0,$0-16
MOVD arg+0(FP), R5
MOVD (R5), R5
MOVD R5, ret+8(FP)
RET
@@ -0,0 +1,19 @@
package main
import (
"fmt"
"os"
)
func g() {
}
func main() {
g()
a := os.Args[1] == "1"
if a {
fmt.Printf("true branch %v\n", a)
} else {
fmt.Printf("false branch %v\n", a)
}
}
@@ -0,0 +1,96 @@
/* The Computer Language Benchmarks Game
* http://benchmarksgame.alioth.debian.org/
*
* based on Go program by The Go Authors.
* based on C program by Kevin Carson
* flag.Arg hack by Isaac Gouy
* modified by Jamil Djadala to use goroutines
* modified by Chai Shushan
*
*/
package main
import (
"flag"
"fmt"
"runtime"
"strconv"
"sync"
)
var minDepth = 4
var n = 20
func main() {
runtime.GOMAXPROCS(runtime.NumCPU() * 2)
flag.Parse()
if flag.NArg() > 0 {
n, _ = strconv.Atoi(flag.Arg(0))
}
maxDepth := n
if minDepth+2 > n {
maxDepth = minDepth + 2
}
stretchDepth := maxDepth + 1
check_l := bottomUpTree(0, stretchDepth).ItemCheck()
fmt.Printf("stretch tree of depth %d\t check: %d\n", stretchDepth, check_l)
longLivedTree := bottomUpTree(0, maxDepth)
result_trees := make([]int, maxDepth+1)
result_check := make([]int, maxDepth+1)
var wg sync.WaitGroup
for depth_l := minDepth; depth_l <= maxDepth; depth_l += 2 {
wg.Add(1)
go func(depth int) {
iterations := 1 << uint(maxDepth-depth+minDepth)
check := 0
for i := 1; i <= iterations; i++ {
check += bottomUpTree(i, depth).ItemCheck()
check += bottomUpTree(-i, depth).ItemCheck()
}
result_trees[depth] = iterations * 2
result_check[depth] = check
wg.Done()
}(depth_l)
}
wg.Wait()
for depth := minDepth; depth <= maxDepth; depth += 2 {
fmt.Printf("%d\t trees of depth %d\t check: %d\n",
result_trees[depth], depth, result_check[depth],
)
}
fmt.Printf("long lived tree of depth %d\t check: %d\n",
maxDepth, longLivedTree.ItemCheck(),
)
}
func bottomUpTree(item, depth int) *Node {
if depth <= 0 {
return &Node{item, nil, nil}
}
return &Node{item,
bottomUpTree(2*item-1, depth-1),
bottomUpTree(2*item, depth-1),
}
}
type Node struct {
item int
left, right *Node
}
func (self *Node) ItemCheck() int {
if self.left == nil {
return self.item
}
return self.item + self.left.ItemCheck() - self.right.ItemCheck()
}
@@ -0,0 +1,28 @@
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func demo(id int, wait *sync.WaitGroup) {
for i := 0; i < 100; i++ {
sleep := rand.Intn(10) + 1
fmt.Printf("id: %d step: %d sleeping %d\n", id, i, sleep)
time.Sleep(time.Duration(sleep) * time.Millisecond)
}
wait.Done()
}
func main() {
wait := new(sync.WaitGroup)
wait.Add(1)
wait.Add(1)
go demo(1, wait)
go demo(2, wait)
wait.Wait()
}
@@ -0,0 +1,8 @@
# comment line
trace main.main
break main.sayhi
#
# comment line
#
@@ -0,0 +1,11 @@
package main
func main() {
i := 0
for {
i++
if i > 10 {
break
}
}
}
@@ -0,0 +1,5 @@
#include "textflag.h"
TEXT ·asmBrk(SB),0,$0-0
BYTE $0xcc
RET
@@ -0,0 +1,7 @@
package main
func asmBrk()
func main() {
asmBrk()
}
@@ -0,0 +1,14 @@
package main
import "fmt"
// To be set via
// go build -ldflags '-X main.Hello=World'
var Hello string
func main() {
if len(Hello) < 1 {
panic("global main.Hello not set via build flags")
}
fmt.Printf("Hello %s!\n", Hello)
}
@@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println("hello world!")
}
@@ -0,0 +1,15 @@
package main
import (
"os"
"testing"
)
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
func TestCurrentDirectory(t *testing.T) {
wd, _ := os.Getwd()
t.Logf("current directory: %s", wd)
}
@@ -0,0 +1,28 @@
package main
import "fmt"
func callme(i int) {
fmt.Println("got:", i)
}
const nBytes = 10
var zeroarr [nBytes]byte
func callme2() {
for i := 0; i < nBytes; i++ {
zeroarr[i] = '0'
}
fmt.Println("callme2")
}
func callme3() {
callme2()
}
func main() {
for i := 0; i < 5; i++ {
callme(i)
}
callme3()
}
@@ -0,0 +1,15 @@
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
fmt.Printf("read %q\n", s.Text())
}
os.Stdout.Close()
}
@@ -0,0 +1,14 @@
package main
/*
int a(int v) {
return 0xff + v;
}
*/
import "C"
import "fmt"
func main() {
fmt.Println("aaa")
print(C.a(11))
}
@@ -0,0 +1,17 @@
package main
// #cgo CFLAGS: -g -Wall -O0
/*
void sigsegv(int x) {
int *p = NULL;
*p = x;
}
void testfn(int x) {
sigsegv(x);
}
*/
import "C"
func main() {
C.testfn(C.int(10))
}
@@ -0,0 +1,35 @@
#include <stdio.h>
#include "_cgo_export.h"
#ifdef __amd64__
#define BREAKPOINT asm("int3;")
#elif __i386__
#define BREAKPOINT asm("int3;")
#elif __PPC64__
#define BREAKPOINT asm("tw 31,0,0;")
#elif __aarch64__
#ifdef WIN32
#define BREAKPOINT asm("brk 0xF000;")
#else
#define BREAKPOINT asm("brk 0;")
#endif
#endif
void helloworld_pt2(int x) {
BREAKPOINT;
helloWorld(x+1);
}
void helloworld(int x) {
helloworld_pt2(x+1);
}
void helloworld_pt4(int x) {
BREAKPOINT;
helloWorld2(x+1);
}
void helloworld_pt3(int x) {
helloworld_pt4(x+1);
}
@@ -0,0 +1,7 @@
#ifndef __HELLO_H__
#define __HELLO_H__
void helloworld(int);
void helloworld_pt3(int);
#endif
@@ -0,0 +1,30 @@
package main
// #include "hello.h"
import "C"
import (
"fmt"
"runtime"
)
func main() {
runtime.Breakpoint()
C.helloworld(2)
}
//export helloWorld
func helloWorld(x C.int) {
helloWorldS(x)
}
func helloWorldS(x C.int) {
runtime.Breakpoint()
C.helloworld_pt3(x - 1)
}
//export helloWorld2
func helloWorld2(x C.int) {
runtime.Breakpoint()
fmt.Printf("hello world %d\n", x)
}
@@ -0,0 +1,15 @@
package main
/*
#include <stdio.h>
char* foo(void) { return "hello, world!"; }
*/
import "C"
import "fmt"
import "runtime"
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
fmt.Println(C.GoString(C.foo()))
}
@@ -0,0 +1,26 @@
package main
import (
"runtime"
"time"
)
func main() {
blockingchan1 := make(chan int)
blockingchan2 := make(chan int)
go sendToChan("one", blockingchan1)
go sendToChan("two", blockingchan1)
go recvFromChan(blockingchan2)
time.Sleep(time.Second)
runtime.Breakpoint()
}
func sendToChan(name string, ch chan<- int) {
ch <- 1
}
func recvFromChan(ch <-chan int) {
<-ch
}
@@ -0,0 +1,10 @@
package main
import (
"net/http"
"net/url"
)
func main() {
http.DefaultClient.Do(&http.Request{URL: &url.URL{}})
}
@@ -0,0 +1,25 @@
package main
import (
"fmt"
"runtime"
)
func makeAcc(scale int) func(x int) int {
a := 0
return func(x int) int {
a += x * scale
return a
}
}
func main() {
acc := makeAcc(3)
runtime.Breakpoint()
fmt.Println(acc(1))
runtime.Breakpoint()
fmt.Println(acc(2))
runtime.Breakpoint()
fmt.Println(acc(6))
runtime.Breakpoint()
}
@@ -0,0 +1,17 @@
package main
import "fmt"
func callme() {
for i := 0; i < 10; i++ {
callme2()
}
}
func callme2() {
fmt.Println("called again!!")
}
func main() {
callme()
}
@@ -0,0 +1,25 @@
package main
import (
"sync"
"time"
)
func main() {
var wg sync.WaitGroup
wg.Add(2)
for i := 0; i < 2; i++ {
go func() {
j := 0
for {
j++
if j > 10 {
break
}
}
wg.Done()
}()
time.Sleep(time.Second)
}
wg.Wait()
}
@@ -0,0 +1,38 @@
package main
import (
"fmt"
"github.com/go-delve/delve/_fixtures/internal/dir0/pkg"
"runtime"
)
type ConstType uint8
const (
constZero ConstType = iota
constOne
constTwo
constThree
)
type BitFieldType uint8
const (
bitZero BitFieldType = 1 << iota
bitOne
bitTwo
bitThree
bitFour
)
func main() {
a := constTwo
b := constThree
c := bitZero | bitOne
d := BitFieldType(33)
e := ConstType(10)
f := BitFieldType(0)
runtime.Breakpoint()
pkg.SomeVar.AnotherMethod(2)
fmt.Println(a, b, c, d, e, f, pkg.SomeConst)
}
@@ -0,0 +1,19 @@
package main
import (
"fmt"
"time"
)
func sleepytime() {
time.Sleep(time.Millisecond)
}
func sayhi() {
fmt.Println("Hello, World!")
}
func main() {
sleepytime()
sayhi()
}
@@ -0,0 +1,8 @@
package main
func main() {
s := ""
t := "test"
panic("panic!!!")
println(s, t)
}
@@ -0,0 +1,9 @@
def main():
for f in functions().Funcs:
v = f.split('.')
if len(v) != 2:
continue
if v[0] != "main":
continue
if v[1][0] >= 'a' and v[1][0] <= 'z':
create_breakpoint({ "FunctionName": f, "Line": -1 }) # see documentation of RPCServer.CreateBreakpoint
@@ -0,0 +1,29 @@
package main
import (
"math/rand"
"sync"
"time"
)
var globalvar1 int
func demo(id int, wait *sync.WaitGroup) {
for i := 0; i < 100; i++ {
sleep := rand.Intn(10) + 1
globalvar1 = globalvar1 + 1
time.Sleep(time.Duration(sleep) * time.Millisecond)
}
wait.Done()
}
func main() {
wait := new(sync.WaitGroup)
wait.Add(1)
wait.Add(1)
go demo(1, wait)
go demo(2, wait)
wait.Wait()
}
@@ -0,0 +1,48 @@
package main
import (
"fmt"
"runtime"
"sync"
"time"
)
var globalvar1 = 0
var globalvar2 = 0
func main() { // Position 0
runtime.LockOSThread()
globalvar2 = 1
fmt.Printf("%d %d\n", globalvar1, globalvar2)
globalvar2 = globalvar1 + 1
globalvar1 = globalvar2 + 1
fmt.Printf("%d %d\n", globalvar1, globalvar2) // Position 1
globalvar2 = globalvar2 + 1 // Position 2
globalvar2 = globalvar1 + globalvar2 // Position 3
fmt.Printf("%d %d\n", globalvar1, globalvar2)
globalvar1 = globalvar2 + 1
fmt.Printf("%d %d\n", globalvar1, globalvar2)
done := make(chan struct{}) // Position 4
var wg sync.WaitGroup
for i := 0; i < 20; i++ {
wg.Add(1)
go waitfunc(i, &wg)
}
wg.Wait()
go f(done)
<-done
}
func f(done chan struct{}) {
runtime.LockOSThread()
globalvar1 = globalvar2 + 2
close(done) // Position 5
}
func waitfunc(i int, wg *sync.WaitGroup) {
runtime.LockOSThread()
wg.Done()
time.Sleep(50 * time.Second)
}
@@ -0,0 +1,25 @@
package main
import (
"fmt"
//
)
func f() {
w := 0
g(1000, &w) // Position 0
}
func g(cnt int, p *int) {
if cnt == 0 {
*p = 10
return // Position 1
}
g(cnt-1, p)
}
func main() {
f()
fmt.Printf("done\n") // Position 2
}
@@ -0,0 +1,19 @@
package main
import (
"fmt"
)
func main() {
a := 0
a++
b := 0
f1(a, b)
}
func f1(
a int,
b int,
) {
fmt.Printf("%d %d\n", a, b)
}
@@ -0,0 +1,29 @@
package main
var n = 0
func sampleFunction() {
n++
}
func callAndDeferReturn() {
defer sampleFunction()
sampleFunction()
n++
}
func callAndPanic2() {
defer sampleFunction()
sampleFunction()
panic("panicking")
}
func callAndPanic() {
defer recover()
callAndPanic2()
}
func main() {
callAndDeferReturn()
callAndPanic()
}
@@ -0,0 +1,32 @@
package main
import "runtime"
func f1() {
}
func f2(a int8, b int32) {
}
func f3() {
}
func call1() {
defer f2(1, -1)
defer f1()
call2()
}
func call2() {
defer f3()
defer f2(42, 61)
call3()
}
func call3() {
runtime.Breakpoint()
}
func main() {
call1()
}
@@ -0,0 +1,15 @@
package main
import (
"fmt"
"github.com/go-delve/delve/_fixtures/internal/dir.io"
"github.com/go-delve/delve/_fixtures/internal/dir.io/io.io"
"runtime"
)
func main() {
var iface interface{} = &dirio.SomeType{}
var iface2 interface{} = &ioio.SomeOtherType{}
runtime.Breakpoint()
fmt.Println(iface, iface2)
}
@@ -0,0 +1,26 @@
package main
import (
"fmt"
"runtime"
"strconv"
)
type Rectangle struct{}
func (r *Rectangle) Height() int {
h, _ := strconv.ParseInt("7", 10, 0)
return int(h)
}
func (r *Rectangle) Width() int {
return 6
}
func (r *Rectangle) Area() int { return r.Height() * r.Width() }
func main() {
var r Rectangle
runtime.Breakpoint()
fmt.Println(r.Area())
}
@@ -0,0 +1,14 @@
package main
// #include <stdio.h>
// void fortytwo()
// {
// fprintf(stdin, "42");
// }
import "C"
import "runtime"
func main() {
C.fortytwo()
runtime.Breakpoint()
}
@@ -0,0 +1,14 @@
package main
import "fmt"
func callme(i int) int {
if i == 0 {
return 100
}
return callme(i - 1)
}
func main() {
fmt.Println(callme(10))
}
@@ -0,0 +1,22 @@
package main
import (
"fmt"
"time"
)
func main() {
i := int64(0)
for i = 0; i < 5; i++ {
tracedFunction(i)
}
for i = 5; i < 10; i++ {
tracedFunction(i)
time.Sleep(time.Second)
}
}
//go:noinline
func tracedFunction(x int64) {
fmt.Println(x)
}
@@ -0,0 +1,23 @@
package main
import (
"fmt"
"time"
)
func main() {
str := "abcdefghijklmnopqrstuvqxyz"
i := int64(0)
for i = 0; i < 5; i++ {
tracedFunction(i, i%5 == 0, str[i])
}
for i = 5; i < 10; i++ {
tracedFunction(i, i%5 == 0, str[i])
time.Sleep(time.Millisecond)
}
}
//go:noinline
func tracedFunction(x int64, b bool, r byte) {
fmt.Println(x, b, r)
}
@@ -0,0 +1,2 @@
def command_echo_expr(a, b, c):
print("a", a, "b", b, "c", c)
@@ -0,0 +1,25 @@
package main
import (
"fmt"
"unsafe"
)
func main() {
l := int(51)
bs := make([]byte, l)
for i := 0; i < l; i++ {
bs[i] = byte(i + int(10))
}
bsp := (*byte)(unsafe.Pointer(&bs[0]))
bspUintptr := uintptr(unsafe.Pointer(bsp))
fmt.Printf("%#x\n", bspUintptr)
_ = *bsp
bs[0] = 255
_ = *bsp
}
@@ -0,0 +1 @@
exit
@@ -0,0 +1,6 @@
package main
func main() {
var f func()
go f()
}
@@ -0,0 +1,17 @@
def command_find_array(arr, pred):
"""Calls pred for each element of the array or slice 'arr' returns the index of the first element for which pred returns true.
find_arr <arr>, <pred>
Example use:
find_arr "s2", lambda x: x.A == 5
"""
arrv = eval(None, arr).Variable
for i in range(0, arrv.Len):
v = arrv.Value[i]
if pred(v):
print("found", i)
return
print("not found")
@@ -0,0 +1,258 @@
package main
import (
"fmt"
"os"
"runtime"
"strings"
)
var call = "this is a variable named `call`"
func callstacktrace() (stacktrace string) {
for skip := 0; ; skip++ {
pc, file, line, ok := runtime.Caller(skip)
if !ok {
break
}
fn := runtime.FuncForPC(pc)
stacktrace += fmt.Sprintf("in %s at %s:%d\n", fn.Name(), file, line)
}
return stacktrace
}
func call0(a, b int) {
fmt.Printf("call0: first: %d second: %d\n", a, b)
}
func call1(a, b int) int {
fmt.Printf("first: %d second: %d\n", a, b)
return a + b
}
func call2(a, b int) (int, int) {
fmt.Printf("call2: first: %d second: %d\n", a, b)
return a, b
}
func callexit() {
fmt.Printf("about to exit\n")
os.Exit(0)
}
func callpanic() {
fmt.Printf("about to panic\n")
panic("callpanic panicked")
}
func callbreak() {
fmt.Printf("about to break")
runtime.Breakpoint()
}
func stringsJoin(v []string, sep string) string {
// This is needed because strings.Join is in an optimized package and
// because of a bug in the compiler arguments of optimized functions don't
// have a location.
return strings.Join(v, sep)
}
type astruct struct {
X int
}
type a2struct struct {
Y int
}
func (a astruct) VRcvr(x int) string {
return fmt.Sprintf("%d + %d = %d", x, a.X, x+a.X)
}
func (pa *astruct) PRcvr(x int) string {
return fmt.Sprintf("%d - %d = %d", x, pa.X, x-pa.X)
}
type PRcvrable interface {
PRcvr(int) string
}
type VRcvrable interface {
VRcvr(int) string
}
var zero = 0
func makeclos(pa *astruct) func(int) string {
i := 0
return func(x int) string {
i++
return fmt.Sprintf("%d + %d + %d = %d", i, pa.X, x, i+pa.X+x)
}
}
var ga astruct
var globalPA2 *a2struct
func escapeArg(pa2 *a2struct) {
globalPA2 = pa2
}
func square(x int) int {
return x * x
}
func intcallpanic(a int) int {
if a == 0 {
panic("panic requested")
}
return a
}
func onetwothree(n int) []int {
return []int{n + 1, n + 2, n + 3}
}
func curriedAdd(n int) func(int) int {
return func(m int) int {
return n + m
}
}
func getAStruct(n int) astruct {
return astruct{X: n}
}
func getAStructPtr(n int) *astruct {
return &astruct{X: n}
}
func getVRcvrableFromAStruct(n int) VRcvrable {
return astruct{X: n}
}
func getPRcvrableFromAStructPtr(n int) PRcvrable {
return &astruct{X: n}
}
func getVRcvrableFromAStructPtr(n int) VRcvrable {
return &astruct{X: n}
}
func noreturncall(n int) {
return
}
type Base struct {
y int
}
type Derived struct {
x int
Base
}
func (b *Base) Method() int {
return b.y
}
type X int
func (_ X) CallMe() {
println("foo")
}
type X2 int
func (_ X2) CallMe(i int) int {
return i * i
}
func regabistacktest(s1, s2, s3, s4, s5 string, n uint8) (string, string, string, string, string, uint8) {
return s1 + s2, s2 + s3, s3 + s4, s4 + s5, s5 + s1, 2 * n
}
func regabistacktest2(n1, n2, n3, n4, n5, n6, n7, n8, n9, n10 int) (int, int, int, int, int, int, int, int, int, int) {
return n1 + n2, n2 + n3, n3 + n4, n4 + n5, n5 + n6, n6 + n7, n7 + n8, n8 + n9, n9 + n10, n10 + n1
}
func regabistacktest3(sargs [10]string, n uint8) (r [10]string, m uint8) {
for i := range sargs {
r[i] = sargs[i] + sargs[(i+1)%len(sargs)]
}
m = n * 3
return
}
func floatsum(a, b float64) float64 {
return a + b
}
type Issue2698 struct {
a uint32
b uint8
c uint8
d uintptr
}
func (i Issue2698) String() string {
return fmt.Sprintf("%d %d %d %d", i.a, i.b, i.c, i.d)
}
type Issue3364 struct {
a int
b uint32
}
func (i Issue3364) String() string {
return fmt.Sprintf("%d %d", i.a, i.b)
}
func main() {
one, two := 1, 2
intslice := []int{1, 2, 3}
stringslice := []string{"one", "two", "three"}
comma := ","
a := astruct{X: 3}
pa := &astruct{X: 6}
a2 := a2struct{Y: 7}
var pa2 *astruct
var str string = "old string value"
longstrs := []string{"very long string 0123456789a0123456789b0123456789c0123456789d0123456789e0123456789f0123456789g012345678h90123456789i0123456789j0123456789"}
rast3 := [10]string{"one", "two", "three", "four", "five", "six", "seven", "height", "nine", "ten"}
var vable_a VRcvrable = a
var vable_pa VRcvrable = pa
var pable_pa PRcvrable = pa
var x X = 2
var x2 X2 = 2
issue2698 := Issue2698{
a: 1,
b: 2,
c: 3,
d: 4,
}
issue3364 := Issue3364{
a: 1,
b: 2,
}
fn2clos := makeclos(pa)
fn2glob := call1
fn2valmeth := pa.VRcvr
fn2ptrmeth := pa.PRcvr
var fn2nil func()
d := &Derived{3, Base{4}}
var ref strings.Builder
fmt.Fprintf(&ref, "blah")
runtime.Breakpoint() // breakpoint here
call1(one, two)
fn2clos(2)
strings.LastIndexByte(stringslice[1], 'w')
d.Method()
d.Base.Method()
x.CallMe()
fmt.Println(one, two, zero, call, call0, call2, callexit, callpanic, callbreak, callstacktrace, stringsJoin, intslice, stringslice, comma, a.VRcvr, a.PRcvr, pa, vable_a, vable_pa, pable_pa, fn2clos, fn2glob, fn2valmeth, fn2ptrmeth, fn2nil, ga, escapeArg, a2, square, intcallpanic, onetwothree, curriedAdd, getAStruct, getAStructPtr, getVRcvrableFromAStruct, getPRcvrableFromAStructPtr, getVRcvrableFromAStructPtr, pa2, noreturncall, str, d, x, x2.CallMe(5), longstrs, regabistacktest, regabistacktest2, issue2698.String(), issue3364.String(), regabistacktest3, rast3, floatsum, ref)
}
@@ -0,0 +1,31 @@
package main
import (
"os"
"runtime"
)
func fputestsetup(f64a, f64b, f64c, f64d float64, f32a, f32b, f32c, f32d float32, avx2, avx512, dobreak bool)
func getCPUID70() (ebx, ecx uint32)
func main() {
var f64a float64 = 1.1
var f64b float64 = 1.2
var f64c float64 = 1.3
var f64d float64 = 1.4
var f32a float32 = 1.5
var f32b float32 = 1.6
var f32c float32 = 1.7
var f32d float32 = 1.8
ebx, _ := getCPUID70()
avx2 := ebx&(1<<5) != 0
avx512 := ebx&(1<<16) != 0
fputestsetup(f64a, f64b, f64c, f64d, f32a, f32b, f32c, f32d, avx2, avx512, len(os.Args) < 2 || os.Args[1] != "panic")
if len(os.Args) < 2 || os.Args[1] != "panic" {
runtime.Breakpoint()
} else {
panic("boom!")
}
}
@@ -0,0 +1,85 @@
TEXT ·fputestsetup(SB),$0-50
// setup x87 stack
FMOVD f64a+0(FP), F0
FMOVD f64b+8(FP), F0
FMOVD f64c+16(FP), F0
FMOVD f64d+24(FP), F0
FMOVF f32a+32(FP), F0
FMOVF f32b+36(FP), F0
FMOVF f32c+40(FP), F0
FMOVF f32d+44(FP), F0
// setup SSE registers
// XMM0 = { f64b, f64a } = { 1.2, 1.1 }
MOVLPS f64a+0(FP), X0
MOVHPS f64b+8(FP), X0
// XMM1 = { f64d, f64c } = { 1.4, 1.3 }
MOVLPS f64c+16(FP), X1
MOVHPS f64d+24(FP), X1
// XMM2 = { f32d, f32c, f32b, f32a } = { 1.8, 1.7, 1.6, 1.5 }
MOVQ f32a+32(FP), AX
MOVQ AX, X2
MOVQ f32c+40(FP), AX
MOVQ AX, X3
PUNPCKLQDQ X3, X2
// XMM3 = { f64a, f64b } = { 1.1, 1.2 }
MOVLPS f64b+8(FP), X3
MOVHPS f64a+0(FP), X3
// XMM4 = { f64c, f64d } = { 1.3, 1.4 }
MOVLPS f64d+24(FP), X4
MOVHPS f64c+16(FP), X4
// XMM5 = { f32b, f32a, f32d, f32c } = { 1.6, 1.5, 1.8, 1.7 }
MOVQ f32c+40(FP), AX
MOVQ AX, X5
MOVQ f32a+32(FP), AX
MOVQ AX, X6
PUNPCKLQDQ X6, X5
// XMM6 = XMM0 + XMM1 = { f64b+f64d, f64a+f64c } = { 2.6, 2.4 }
MOVAPS X0,X6
ADDPD X1, X6
// XMM7 = XMM0 + XMM3 = { f64b+f64a, f64a+f64b } = { 2.3, 2.3 }
MOVAPS X0, X7
ADDPD X3, X7
// XMM8 = XMM2 + XMM5 = { f32d+f32b, f32c+f32a, f32b+f32d, f32a+f32c } = { 3.4, 3.2, 3.4, 3.2 }
MOVAPS X2, X8
ADDPS X5, X8
MOVAPS X1, X9
MOVAPS X2, X10
MOVQ $42, AX
CMPB avx2+48(FP), $0x0
JE done
//copy XMM1 to both halves of YMM11
VPERMQ $0x44, Y1, Y11
CMPB avx512+49(FP), $0x0
JE done
//copy YMM11 to both halves of ZMM12
VSHUFF64X2 $0x44, Z11, Z11, Z12
done:
CMPB dobreak+50(FP), $0x0
JE return
BYTE $0xcc // INT 3
return:
RET
TEXT ·getCPUID70(SB),$0
MOVQ $7, AX
MOVQ $0, CX
CPUID
MOVD BX, ret+0(FP)
MOVD CX, ret+4(FP)
RET
@@ -0,0 +1,12 @@
package main
import "fmt"
func testfn[T any](arg T) {
fmt.Println(arg)
}
func main() {
testfn[uint16](1)
testfn[float64](2.1)
}
@@ -0,0 +1,25 @@
package main
import "fmt"
type Blah[T any] struct {
x T
}
func (b *Blah[T]) F(y T) {
b.x = y
}
type BlahInt interface {
F(int)
}
func callf(b BlahInt) {
b.F(2)
fmt.Println(b)
}
func main() {
b := &Blah[int]{10}
callf(b)
}
@@ -0,0 +1,23 @@
package main
import (
"context"
"runtime"
"runtime/pprof"
)
func main() {
ctx := context.Background()
labels := pprof.Labels("k1", "v1", "k2", "v2")
runtime.Breakpoint()
pprof.Do(ctx, labels, f)
}
var dummy int
func f(ctx context.Context) {
a := dummy
runtime.Breakpoint()
dummy++
dummy = a
}
@@ -0,0 +1,9 @@
def command_goroutine_start_line(args):
"prints the line of source code that started each currently running goroutine"
gs = goroutines().Goroutines
for g in gs:
line = read_file(g.StartLoc.File).splitlines()[g.StartLoc.Line-1].strip()
print(g.ID, "\t", g.StartLoc.File + ":" + str(g.StartLoc.Line), "\t", line)
def main():
dlv_command("config alias goroutine_start_line gsl")
@@ -0,0 +1,26 @@
package main
import "runtime"
const N = 10
func agoroutine(started chan<- struct{}, done chan<- struct{}, i int) {
started <- struct{}{}
done <- struct{}{}
}
func main() {
done := make(chan struct{})
started := make(chan struct{})
for i := 0; i < N; i++ {
runtime.Breakpoint()
go agoroutine(started, done, i)
}
for i := 0; i < N; i++ {
<-started
}
runtime.Gosched()
for i := 0; i < N; i++ {
<-done
}
}
@@ -0,0 +1,75 @@
package main
import (
"context"
"runtime"
"runtime/pprof"
"sync"
"time"
)
func sleepyfunc(wg *sync.WaitGroup, lbl string) {
defer wg.Done()
pprof.SetGoroutineLabels(pprof.WithLabels(context.Background(), pprof.Labels("name", lbl)))
time.Sleep(10 * 60 * time.Second)
}
func gopoint1(wg *sync.WaitGroup, lbl string, f func(*sync.WaitGroup, string)) {
go f(wg, lbl)
}
func gopoint2(wg *sync.WaitGroup, lbl string, f func(*sync.WaitGroup, string)) {
go f(wg, lbl)
}
func gopoint3(wg *sync.WaitGroup, lbl string, f func(*sync.WaitGroup, string)) {
go f(wg, lbl)
}
func gopoint4(wg *sync.WaitGroup, lbl string, f func(*sync.WaitGroup, string)) {
go f(wg, lbl)
}
func gopoint5(wg *sync.WaitGroup, lbl string, f func(*sync.WaitGroup, string)) {
go f(wg, lbl)
}
func startpoint1(wg *sync.WaitGroup, lbl string) {
sleepyfunc(wg, lbl)
}
func startpoint2(wg *sync.WaitGroup, lbl string) {
sleepyfunc(wg, lbl)
}
func startpoint3(wg *sync.WaitGroup, lbl string) {
sleepyfunc(wg, lbl)
}
func startpoint4(wg *sync.WaitGroup, lbl string) {
sleepyfunc(wg, lbl)
}
func startpoint5(wg *sync.WaitGroup, lbl string) {
sleepyfunc(wg, lbl)
}
func main() {
var wg sync.WaitGroup
for _, lbl := range []string{"one", "two", "three", "four", "five"} {
for _, f := range []func(*sync.WaitGroup, string){startpoint1, startpoint2, startpoint3, startpoint4, startpoint5} {
for i := 0; i < 1000; i++ {
wg.Add(5)
gopoint1(&wg, lbl, f)
gopoint2(&wg, lbl, f)
gopoint3(&wg, lbl, f)
gopoint4(&wg, lbl, f)
gopoint5(&wg, lbl, f)
}
}
}
time.Sleep(2 * time.Second)
runtime.Breakpoint()
wg.Wait()
}
@@ -0,0 +1,32 @@
package main
import (
"fmt"
"sync"
)
func callme(i int, s string) int {
fmt.Println(s)
return i * i
}
func dostuff(wg *sync.WaitGroup, lbl string) {
defer wg.Done()
var j int
for i := 0; i < 10; i++ {
j += callme(i, lbl)
}
println(lbl, j)
}
func main() {
var wg sync.WaitGroup
for _, lbl := range []string{"one", "two", "three", "four", "five"} {
for i := 0; i < 10; i++ {
wg.Add(1)
go dostuff(&wg, lbl)
}
}
wg.Wait()
}
@@ -0,0 +1,47 @@
package main
import "runtime"
const N = 10
func agoroutine(started chan<- struct{}, done chan<- struct{}, i int) {
started <- struct{}{}
done <- struct{}{}
}
var dummy int
func stacktraceme() {
dummy++
return
}
func main() {
done := make(chan struct{})
started := make(chan struct{})
for i := 0; i < N; i++ {
go agoroutine(started, done, i)
}
for i := 0; i < N; i++ {
<-started
}
runtime.Gosched()
stacktraceme()
for i := 0; i < N; i++ {
<-done
}
n := 0
func1(n + 1)
}
func func1(n int) {
func2(n + 1)
}
func func2(n int) {
func3(n + 1)
}
func func3(n int) {
stacktraceme()
}
@@ -0,0 +1,30 @@
package main
import (
"fmt"
"math/rand"
"runtime"
"sync"
"time"
)
func demo(id int, wait *sync.WaitGroup) {
for i := 0; i < 100; i++ {
sleep := rand.Intn(10) + 1
runtime.Breakpoint()
fmt.Printf("id: %d step: %d sleeping %d\n", id, i, sleep)
time.Sleep(time.Duration(sleep) * time.Millisecond)
}
wait.Done()
}
func main() {
wait := new(sync.WaitGroup)
wait.Add(1)
wait.Add(1)
go demo(1, wait)
go demo(2, wait)
wait.Wait()
}
@@ -0,0 +1,13 @@
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "hello world")
})
http.ListenAndServe(":0", nil)
}
@@ -0,0 +1,31 @@
package main
import "fmt"
type A struct {
a int
}
type B struct {
*A
}
type Iface interface {
PtrReceiver() string
NonPtrReceiver() string
}
func (*A) PtrReceiver() string {
return "blah"
}
func (A) NonPtrReceiver() string {
return "blah"
}
func main() {
var iface Iface = &B{&A{1}}
s := iface.PtrReceiver()
s = iface.NonPtrReceiver()
fmt.Printf("%s\n", s)
}
@@ -0,0 +1,18 @@
package main
import "fmt"
// Increment Natural number y
func Increment(y uint) uint {
if y == 0 {
return 1
}
if y%2 == 1 {
return (2 * Increment(y/2))
}
return y + 1
}
func main() {
fmt.Printf("%d\n", Increment(3))
}
@@ -0,0 +1,15 @@
package main
import "fmt"
func callme(i int) int {
return i * i
}
func main() {
j := 0
j += callme(2)
fmt.Println(j)
fmt.Println(j + 1)
fmt.Println(j + 2)
}
@@ -0,0 +1,18 @@
package main
import (
"fmt"
"time"
)
func sayhi() {
fmt.Println("hi")
}
func main() {
time.Sleep(1 * time.Second)
for i := 0; i < 3; i++ {
sayhi()
time.Sleep(1 * time.Second)
}
}
@@ -0,0 +1,11 @@
package dirio
type SomeType struct {
X int
}
var A string = "something"
func SomeFunction() {
println("hello world")
}
@@ -0,0 +1,5 @@
package ioio
type SomeOtherType struct {
Y int
}
@@ -0,0 +1,21 @@
package pkg
var A = 0
type SomeType struct {
X float64
}
func (s *SomeType) AMethod(x int) int {
return x + 3
}
func (s *SomeType) AnotherMethod(x int) int {
return x + 4
}
var SomeVar SomeType
const (
SomeConst int = 2
)
@@ -0,0 +1,5 @@
package realname
type SomeType struct {
A bool
}
@@ -0,0 +1,8 @@
package pkg
var A = 1
type SomeType struct {
X int
Y int
}
@@ -0,0 +1,9 @@
package pluginsupport
type Something interface {
Callback(int) int
}
type SomethingElse interface {
Callback2(int, int) float64
}
@@ -0,0 +1,28 @@
package main
import (
"fmt"
)
func fibonacci(n int, c chan int) {
x, y := 0, 1
for i := 0; i < n; i++ {
c <- x
x, y = y, x+y
}
close(c)
}
func main() {
a := struct { // set breakpoint here
A string
B int
}{A: "demo", B: 10}
fmt.Printf("%#v\n", a)
c := make(chan int, 10)
go fibonacci(cap(c), c)
for i := range c {
fmt.Println(i)
}
}
@@ -0,0 +1,20 @@
package main
import (
"os"
"sync"
)
var wg sync.WaitGroup
func f(from string) {
defer wg.Done()
return
}
func main() {
wg.Add(1)
go f("goroutine")
wg.Wait()
os.Exit(2)
}
@@ -0,0 +1,10 @@
package main
import "fmt"
func main() {
for i := 0; i < 4; i++ {
equalsTwo := i == 2
fmt.Printf("i: %d -> equalsTwo: %t \n", i, equalsTwo) // :8
}
}
@@ -0,0 +1,12 @@
package main
import "fmt"
func main() {
i := getNum()
fmt.Println(i)
}
func getNum() int {
return 0
}
@@ -0,0 +1,16 @@
package main
import "runtime"
type s struct {
i int64
}
func main() {
i := 1
p := &i
s := s{i: 1}
_ = s
runtime.Breakpoint()
println(i, p)
}
@@ -0,0 +1,14 @@
package main
import "time"
func main() {
for i := 0; i < 5; i++ {
go func() {
time.Sleep(11 * time.Millisecond)
}()
}
x := 255
println(x) //break
}
@@ -0,0 +1,37 @@
package main
import (
"fmt"
"runtime"
)
type W struct {
x int
y int
}
func main() {
testMaps()
}
func testMaps() {
m := make(map[string]W)
m["t"] = W{}
m["s"] = W{}
m["r"] = W{}
m["v"] = W{}
mm := map[string]W{
"r": {},
"s": {},
"t": {},
"v": {},
}
delete(mm, "s")
delete(m, "t")
runtime.Breakpoint()
fmt.Println(m, mm)
}
@@ -0,0 +1,16 @@
package main
import (
"fmt"
"time"
)
func main() {
sum := int64(0)
start := time.Now()
for value := int64(0); value < 10000; value++ {
sum += value
}
elapsed := time.Since(start)
fmt.Printf("Sum: %d\nTook %s\n", sum, elapsed)
}
@@ -0,0 +1,14 @@
package main
func main() {
a := x()
println(a) //break here
}
func x() string {
return `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui
officia deserunt mollit anim id est laborum.`
}
@@ -0,0 +1,20 @@
package main
import (
"runtime"
)
/*
typedef struct Qst Q1;
typedef const Q1 Q;
struct Qst {
Q *q;
};
const Q1 globalq;
*/
import "C"
func main() {
runtime.Breakpoint()
}
@@ -0,0 +1,21 @@
package main
var strings = []string{
"one",
"two",
"three",
"four",
"projects/my-gcp-project-id-string/locations/us-central1/queues/my-task-queue-name",
"five",
"six",
}
func f(s string) {
// ...
}
func main() {
for _, s := range strings {
f(s)
}
}
@@ -0,0 +1,19 @@
package main
import (
"fmt"
)
var g int = 0
func compromised(n int64)
//go:nosplit
func skipped() {
g++
}
func main() {
compromised(1)
fmt.Printf("%d\n", g)
}
@@ -0,0 +1,12 @@
#include "textflag.h"
TEXT ·compromised(SB),NOSPLIT,$0-8
CMPQ n+0(FP), $0
JNZ notzero
RET
notzero:
MOVQ $0, AX
MOVQ $1, AX
CALL main·skipped(SB)
RET
@@ -0,0 +1,14 @@
package main
import (
"fmt"
"regexp"
"runtime"
)
func main() {
r := regexp.MustCompile("ab")
runtime.Breakpoint()
out := r.MatchString("blah")
fmt.Printf("%v\n", out)
}
@@ -0,0 +1,23 @@
package main
import (
"fmt"
"runtime"
"unsafe"
)
func main() {
l := int(51)
bs := make([]byte, l)
for i := 0; i < l; i++ {
bs[i] = byte(i + int(10))
}
p := uintptr(unsafe.Pointer(&bs))
fmt.Println(p)
bs[0] = 254
runtime.KeepAlive(bs)
}
@@ -0,0 +1,22 @@
package main
import (
"fmt"
"time"
)
func A() {
fmt.Printf("hello delve\n")
}
func main() {
count := 0
for {
A()
time.Sleep(time.Millisecond * time.Duration(100))
if count >= 30 {
break
}
count++
}
}
@@ -0,0 +1,10 @@
package main
func main() {
f(nil) //break
println("ok")
}
func f(x *int) {
println(*x)
}
@@ -0,0 +1,18 @@
package main
import (
"runtime"
)
var i int
type T struct{}
func (t T) m() { stop() }
func stop() {
runtime.Breakpoint()
i++
}
func main() { T{}.m() }
@@ -0,0 +1,35 @@
package main
import (
"fmt"
"runtime"
"sync"
)
func coroutine(i int, start, finish *sync.WaitGroup) {
defer finish.Done()
j := i * 2
if i == 99 {
runtime.Breakpoint()
start.Done()
} else {
start.Wait()
}
fmt.Println("hello ", i, j)
fmt.Println("goodbye", i, j)
}
func main() {
i := 0
var start, finish sync.WaitGroup
start.Add(1)
for ; i < 100; i++ {
finish.Add(1)
go coroutine(i, &start, &finish)
}
finish.Wait()
println(i)
}
@@ -0,0 +1,10 @@
package main
import (
"time"
)
func main() {
time.Sleep(time.Hour)
println("ok")
}
@@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println("test dlv")
}
@@ -0,0 +1,57 @@
Note:
-----
cfile-linux-amd64.syso was generated from the C source file that appears below.
Build with Clang version 10:
$ clang-10 -O -gdwarf-5 -c cfile.c -o cfile.syso
The DWARF of interest is for the function "qtop". Triggering the bug
requires that the source file in question appears as the first item
in the DWARF line table file section, e.g.
$ llvm-dwarfdump-10 --debug-line cfile.syso
....
standard_opcode_lengths[DW_LNS_set_epilogue_begin] = 0
standard_opcode_lengths[DW_LNS_set_isa] = 1
include_directories[ 0] = "/ssd2/go1/src/tmp/dlvbug"
file_names[ 0]:
name: "cfile.c"
dir_index: 0
md5_checksum: ...
// ------------------------begin source code for cfile.c----------------
#include <stdlib.h>
#include <string.h>
int glob = 99;
inline int qleaf(int lx, int ly, int *lv)
{
lv[lx&3] += 3;
return lv[ly&3];
}
int qmid(int mx, int my, int *lv, int *mv)
{
mv[mx&3] += qleaf(mx, my, lv);
return mv[my&3];
}
int qtop(int mx, int my)
{
int mv[64], lv[66], n = (mx < 64 ? 64 : mx);
memset(&mv[0], 9, sizeof(mv));
memset(&lv[0], 11, sizeof(mv));
return qmid(mx, my, lv, mv) + qleaf(mx, my, lv);
}
void Cfunc(int x) {
glob += qtop(x, 43);
}
@@ -0,0 +1,5 @@
#include "textflag.h"
TEXT ·cfunc(SB),$0
JMP Cfunc(SB)
@@ -0,0 +1,7 @@
package main
func cfunc()
func main() {
cfunc()
}
@@ -0,0 +1,16 @@
package main
import "fmt"
func typicalFunction() (res int) {
defer func() {
res = 2
return
}()
res = 10
return // setup breakpoint here
}
func main() {
fmt.Println(typicalFunction())
}

Some files were not shown because too many files have changed in this diff Show More