Skip to content

Commit

Permalink
BROKEN BROKEN BROKEN DO NOT MERGE TESTING ONLY
Browse files Browse the repository at this point in the history
disable a bunch of necessary stuff to benchmark conditional breakpoints

also ugly hack to run all of proc.Continue code inside the ptrace thread

golang/go#21827
  • Loading branch information
aarzilli committed Jan 30, 2020
1 parent b0c14f4 commit 056a602
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pkg/proc/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,7 @@ func (p *Process) FindThread(threadID int) (proc.Thread, bool) {
func (p *Process) InternalSetCurrentThread(th proc.Thread) {
p.currentThread = th.(*Thread)
}

func (p *Process) MagicThreadExec(fn func()) {
fn()
}
Binary file added pkg/proc/cpu.trace
Binary file not shown.
4 changes: 4 additions & 0 deletions pkg/proc/gdbserial/gdbserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ func (p *Process) InternalSetCurrentThread(th proc.Thread) {
p.currentThread = th.(*Thread)
}

func (p *Process) MagicThreadExec(fn func()) {
fn()
}

const (
interruptSignal = 0x2
breakpointSignal = 0x5
Expand Down
1 change: 1 addition & 0 deletions pkg/proc/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type Process interface {
ProcessManipulation
BreakpointManipulation
RecordingManipulation
MagicThreadExec(func())
}

// RecordingManipulation is an interface for manipulating process recordings.
Expand Down
15 changes: 14 additions & 1 deletion pkg/proc/native/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Process struct {
resumeChan chan<- struct{}
ptraceChan chan func()
ptraceDoneChan chan interface{}
insidePtrace bool
childProcess bool // this process was launched, not attached to
manualStopRequested bool

Expand Down Expand Up @@ -309,12 +310,20 @@ func (dbp *Process) handlePtraceFuncs() {
runtime.LockOSThread()

for fn := range dbp.ptraceChan {
dbp.insidePtrace = true
fn()
dbp.ptraceDoneChan <- nil
dbp.insidePtrace = false
if !dbp.exited {
dbp.ptraceDoneChan <- nil
}
}
}

func (dbp *Process) execPtraceFunc(fn func()) {
if dbp.insidePtrace {
fn()
return
}
dbp.ptraceChan <- fn
<-dbp.ptraceDoneChan
}
Expand All @@ -330,3 +339,7 @@ func (dbp *Process) writeSoftwareBreakpoint(thread *Thread, addr uint64) error {
_, err := thread.WriteMemory(uintptr(addr), dbp.bi.Arch.BreakpointInstruction())
return err
}

func (dbp *Process) MagicThreadExec(fn func()) {
dbp.execPtraceFunc(fn)
}
1 change: 1 addition & 0 deletions pkg/proc/native/registers_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func registers(thread *Thread, floatingPoint bool) (proc.Registers, error) {
return nil, err
}
r := &linutil.AMD64Registers{&regs, nil, nil}
floatingPoint = false
if floatingPoint {
var fpregset linutil.AMD64Xstate
r.Fpregs, fpregset, err = thread.fpRegisters()
Expand Down
17 changes: 15 additions & 2 deletions pkg/proc/proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ func Next(dbp *Target) (err error) {
// process. It will continue until it hits a breakpoint
// or is otherwise stopped.
func Continue(dbp *Target) error {
var err error
dbp.MagicThreadExec(func() {
err = continueInternal(dbp)
})
return err
}

func continueInternal(dbp *Target) error {
if _, err := dbp.Valid(); err != nil {
return err
}
Expand Down Expand Up @@ -303,6 +311,11 @@ func pickCurrentThread(dbp *Target, trapthread Thread, threads []Thread) error {
return dbp.SwitchThread(th.ThreadID())
}
}
if bp := trapthread.Breakpoint(); bp.Breakpoint != nil && !bp.Active {
dbp.InternalSetCurrentThread(trapthread)
dbp.selectedGoroutine = nil
return nil
}
return dbp.SwitchThread(trapthread.ThreadID())
}

Expand Down Expand Up @@ -716,7 +729,7 @@ func FrameToScope(bi *BinaryInfo, thread MemoryReadWriter, g *G, frames ...Stack
// Creates a cacheMem that will preload the entire stack frame the first
// time any local variable is read.
// Remember that the stack grows downward in memory.
minaddr := frames[0].Regs.SP()
/*minaddr := frames[0].Regs.SP()
var maxaddr uint64
if len(frames) > 1 && frames[0].SystemStack == frames[1].SystemStack {
maxaddr = uint64(frames[1].Regs.CFA)
Expand All @@ -725,7 +738,7 @@ func FrameToScope(bi *BinaryInfo, thread MemoryReadWriter, g *G, frames ...Stack
}
if maxaddr > minaddr && maxaddr-minaddr < maxFramePrefetchSize {
thread = cacheMemory(thread, uintptr(minaddr), int(maxaddr-minaddr))
}
}*/

s := &EvalScope{Location: frames[0].Call, Regs: frames[0].Regs, Mem: thread, g: g, BinInfo: bi, frameOffset: frames[0].FrameOffset()}
s.PC = frames[0].lastpc
Expand Down
3 changes: 2 additions & 1 deletion pkg/proc/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ func (frame *Stackframe) FramePointerOffset() int64 {
// ThreadStacktrace returns the stack trace for thread.
// Note the locations in the array are return addresses not call addresses.
func ThreadStacktrace(thread Thread, depth int) ([]Stackframe, error) {
g, _ := GetG(thread)
//g, _ := GetG(thread)
var g *G = nil
if g == nil {
regs, err := thread.Registers(true)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/proc/threads.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,18 +530,18 @@ func ThreadScope(thread Thread) (*EvalScope, error) {

// GoroutineScope returns an EvalScope for the goroutine running on this thread.
func GoroutineScope(thread Thread) (*EvalScope, error) {
locations, err := ThreadStacktrace(thread, 1)
locations, err := ThreadStacktrace(thread, 0)
if err != nil {
return nil, err
}
if len(locations) < 1 {
return nil, errors.New("could not decode first frame")
}
g, err := GetG(thread)
/*g, err := GetG(thread)
if err != nil {
return nil, err
}
return FrameToScope(thread.BinInfo(), thread, g, locations...), nil
}*/
return FrameToScope(thread.BinInfo(), thread, nil, locations...), nil
}

// onNextGoroutine returns true if this thread is on the goroutine requested by the current 'next' command
Expand Down

0 comments on commit 056a602

Please sign in to comment.