delve/dwarf/frame/table_test.go
Derek Parker 3b2b17938b Improve support for goroutine context switching
Remove any assumption that a wait syscall on a thread id after a
continue will return. Any time we continue a thread, wait for activity
from any thread, because the scheduler may well have switched contexts
on us due to syscall entrace, channel op, etc...

There are several more things to be done here including:

* Potential tracking of goroutine id as we jump around to thread
  contexts.
* Potential of selectively choosing threads to operate on based on the
  internal M data structures, ensuring that our M has an active G.

This commit partially fixes #23 and #24, however there are still some
random hangs that happen and need to be ironed out.
2014-11-24 17:57:52 -06:00

65 lines
1.2 KiB
Go

package frame_test
import (
"encoding/binary"
"path/filepath"
"syscall"
"testing"
"github.com/derekparker/delve/helper"
"github.com/derekparker/delve/proctl"
)
func TestFindReturnAddress(t *testing.T) {
var testfile, _ = filepath.Abs("../../_fixtures/testnextprog")
helper.WithTestProcess(testfile, t, func(p *proctl.DebuggedProcess) {
var (
fdes = p.FrameEntries
gsd = p.GoSymTable
)
testsourcefile := testfile + ".go"
start, _, err := gsd.LineToPC(testsourcefile, 24)
if err != nil {
t.Fatal(err)
}
_, err = p.Break(uintptr(start))
if err != nil {
t.Fatal(err)
}
err = p.Continue()
if err != nil {
t.Fatal(err)
}
regs, err := p.Registers()
if err != nil {
t.Fatal(err)
}
fde, err := fdes.FDEForPC(start)
if err != nil {
t.Fatal(err)
}
ret := fde.ReturnAddressOffset(start)
if err != nil {
t.Fatal(err)
}
addr := uint64(int64(regs.Rsp) + ret)
data := make([]byte, 8)
syscall.PtracePeekText(p.Pid, uintptr(addr), data)
addr = binary.LittleEndian.Uint64(data)
expected := uint64(0x400f03)
if addr != expected {
t.Fatalf("return address not found correctly, expected %#v got %#v", expected, addr)
}
})
}