
Areas that need improving: * Code cleanup * Promote breakpoints back out of thread context * Fix potential bug in "Next" implementation, when thread contexts switch
52 lines
1023 B
Go
52 lines
1023 B
Go
package helper
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
"syscall"
|
|
"testing"
|
|
|
|
"github.com/derekparker/delve/proctl"
|
|
)
|
|
|
|
type testfunc func(p *proctl.DebuggedProcess)
|
|
|
|
func GetRegisters(p *proctl.DebuggedProcess, t *testing.T) *syscall.PtraceRegs {
|
|
regs, err := p.Registers()
|
|
if err != nil {
|
|
t.Fatal("Registers():", err)
|
|
}
|
|
|
|
return regs
|
|
}
|
|
|
|
func WithTestProcess(name string, t *testing.T, fn testfunc) {
|
|
runtime.LockOSThread()
|
|
base, err := CompileTestProg(name)
|
|
if err != nil {
|
|
t.Fatalf("Could not compile %s due to %s", name, err)
|
|
}
|
|
defer os.Remove("./" + base)
|
|
|
|
p, err := proctl.AttachBinary("./" + base)
|
|
if err != nil {
|
|
t.Fatal("NewDebugProcess():", err)
|
|
}
|
|
|
|
defer p.Process.Kill()
|
|
|
|
fn(p)
|
|
}
|
|
|
|
func CompileTestProg(source string) (string, error) {
|
|
base := filepath.Base(source)
|
|
return base, exec.Command("go", "build", "-gcflags=-N -l", "-o", base, source+".go").Run()
|
|
}
|
|
|
|
func startTestProcess(name string) (*exec.Cmd, error) {
|
|
cmd := exec.Command("./" + name)
|
|
return cmd, cmd.Start()
|
|
}
|