Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Interpreter Debug Hooks #73

Merged
merged 14 commits into from
Nov 11, 2021
86 changes: 86 additions & 0 deletions bscript/interpreter/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package interpreter

// Debugger implement to enable debugging.
// If enabled, copies of state are provided to each of the functions on
// call.
//
// Each function is called during its stage of a threads lifecycle.
// A high level overview of this lifecycle is:
//
// BeforeExecute
// for step
// BeforeStep
// BeforeExecuteOpcode
// for each stack push
// BeforeStackPush
// AfterStackPush
// end for
// for each stack pop
// BeforeStackPop
// AfterStackPop
// end for
// AfterExecuteOpcode
// if end of script
// BeforeScriptChange
// AfterScriptChange
// end if
// if bip16 and end of final script
// BeforeStackPush
// AfterStackPush
// end if
// AfterStep
// end for
// AfterExecute
// if success
// AfterSuccess
// end if
// if error
// AfterError
// end if
type Debugger interface {
BeforeExecute(*State)
AfterExecute(*State)
BeforeStep(*State)
AfterStep(*State)
BeforeExecuteOpcode(*State)
AfterExecuteOpcode(*State)
BeforeScriptChange(*State)
AfterScriptChange(*State)
AfterSuccess(*State)
AfterError(*State, error)

BeforeStackPush(*State, []byte)
AfterStackPush(*State, []byte)
BeforeStackPop(*State)
AfterStackPop(*State, []byte)
}

type nopDebugger struct{}

func (n *nopDebugger) BeforeExecute(*State) {}

func (n *nopDebugger) AfterExecute(*State) {}

func (n *nopDebugger) BeforeStep(*State) {}

func (n *nopDebugger) AfterStep(*State) {}

func (n *nopDebugger) BeforeExecuteOpcode(*State) {}

func (n *nopDebugger) AfterExecuteOpcode(*State) {}

func (n *nopDebugger) BeforeScriptChange(*State) {}

func (n *nopDebugger) AfterScriptChange(*State) {}

func (n *nopDebugger) BeforeStackPush(*State, []byte) {}

func (n *nopDebugger) AfterStackPush(*State, []byte) {}

func (n *nopDebugger) BeforeStackPop(*State) {}

func (n *nopDebugger) AfterStackPop(*State, []byte) {}

func (n *nopDebugger) AfterSuccess(*State) {}

func (n *nopDebugger) AfterError(*State, error) {}
Loading