mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
vm: refactor stack dump commands
This commit is contained in:
parent
6da458365d
commit
3b04b6d238
2 changed files with 24 additions and 11 deletions
|
@ -301,7 +301,17 @@ func handleBreak(c *ishell.Context) {
|
|||
|
||||
func handleXStack(c *ishell.Context) {
|
||||
v := getVMFromContext(c)
|
||||
c.Println(v.Stack(c.Cmd.Name))
|
||||
var stackDump string
|
||||
switch c.Cmd.Name {
|
||||
case "estack":
|
||||
stackDump = v.DumpEStack()
|
||||
case "istack":
|
||||
stackDump = v.DumpIStack()
|
||||
default:
|
||||
c.Err(errors.New("unknown stack"))
|
||||
return
|
||||
}
|
||||
c.Println(stackDump)
|
||||
}
|
||||
|
||||
func handleSlots(c *ishell.Context) {
|
||||
|
@ -470,7 +480,7 @@ func runVMWithHandling(c *ishell.Context, v *vm.VM) {
|
|||
case v.HasFailed():
|
||||
message = "" // the error will be printed on return
|
||||
case v.HasHalted():
|
||||
message = v.Stack("estack")
|
||||
message = v.DumpEStack()
|
||||
case v.AtBreakpoint():
|
||||
ctx := v.Context()
|
||||
if ctx.NextIP() < ctx.LenInstr() {
|
||||
|
|
21
pkg/vm/vm.go
21
pkg/vm/vm.go
|
@ -334,15 +334,18 @@ func (v *VM) PopResult() interface{} {
|
|||
return v.estack.Pop().Value()
|
||||
}
|
||||
|
||||
// Stack returns json formatted representation of the given stack.
|
||||
func (v *VM) Stack(n string) string {
|
||||
var s *Stack
|
||||
if n == "istack" {
|
||||
s = &v.istack
|
||||
}
|
||||
if n == "estack" {
|
||||
s = v.estack
|
||||
}
|
||||
// DumpIStack returns json formatted representation of the invocation stack.
|
||||
func (v *VM) DumpIStack() string {
|
||||
return dumpStack(&v.istack)
|
||||
}
|
||||
|
||||
// DumpEStack returns json formatted representation of the execution stack.
|
||||
func (v *VM) DumpEStack() string {
|
||||
return dumpStack(v.estack)
|
||||
}
|
||||
|
||||
// dumpStack returns json formatted representation of the given stack.
|
||||
func dumpStack(s *Stack) string {
|
||||
b, _ := json.MarshalIndent(s, "", " ")
|
||||
return string(b)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue