Esempio n. 1
0
func InfoScopeSubcmd(args []string) {
	fr := gub.CurFrame()
	scope := fr.Scope()
	if scope == nil {
		gub.Errmsg("No scope recorded here")
		return
	}
	count := 0
	if len(args) == 3 {
		var err error
		count, err = gub.GetInt(args[2],
			"count", 0, gub.MAXSTACKSHOW)
		if err != nil {
			return
		}
	}

	typescope := scope.Scope
	for i := 0; i < count; i++ {
		typescope = typescope.Parent()
		if typescope == nil {
			gub.Errmsg("There are only %d nested scopes", i)
			return
		}
		scope = fr.Fn().Pkg.TypeScope2Scope[typescope]
		if scope == nil {
			gub.Errmsg("No parent scope; There are only %d nested scopes", i)
			return
		}
	}
	gub.Section("scope number %d", scope.ScopeId())
	gub.Msg("%s", typescope)
}
Esempio n. 2
0
// InfoBreakpointSubcmd implements the debugger command:
//   info breakpoint
//
// This command shows status of user-settable breakpoints. If no
// breakpoint numbers are given, the show all breakpoints. Otherwise
// only those breakpoints listed are shown and the order given.
//
// The "Disp" column contains one of "keep", "del", the disposition of
// the breakpoint after it gets hit.
//
// The "enb" column indicates whether the breakpoint is enabled.
//
// The "Where" column indicates where the breakpoint is located.
// Status of user-settable breakpoints.
func InfoBreakpointSubcmd(args []string) {
	if gub.IsBreakpointEmpty() {
		gub.Msg("No breakpoints set")
		return
	}
	bpLen := len(gub.Breakpoints)
	if bpLen-gub.BrkptsDeleted == 0 {
		gub.Msg("No breakpoints.")
	}
	if len(args) > 2 {
		headerShown := false
		for _, num := range args[2:] {
			if bpNum, err := gub.GetInt(num,
				"breakpoint number", 0, bpLen-1); err == nil {
				if bp := gub.BreakpointFindById(bpNum); bp != nil {
					if !headerShown {
						gub.Section("Num Type          Disp Enb Where")
						headerShown = true
					}
					gub.Bpprint(*bp)
				} else {
					gub.Errmsg("Breakpoint %d not found.", bpNum)
				}
			}
		}
	} else {
		gub.Section("Num Type          Disp Enb Where")
		for _, bp := range gub.Breakpoints {
			if bp.Deleted {
				continue
			}
			gub.Bpprint(*bp)
		}
	}
}
Esempio n. 3
0
func DownCommand(args []string) {
	count := 1
	if len(args) == 2 {
		var err error
		count, err = gub.GetInt(args[1],
			"count", -gub.MAXSTACKSHOW, gub.MAXSTACKSHOW)
		if err != nil {
			return
		}
	}
	gub.AdjustFrame(-count, false)
}
Esempio n. 4
0
func BacktraceCommand(args []string) {
	count := gub.MAXSTACKSHOW
	var err error
	if len(args) > 1 {
		count, err = gub.GetInt(args[1], "maximum count",
			0, gub.MAXSTACKSHOW)
		if err != nil {
			return
		}
	}
	gub.PrintStack(gub.TopFrame(), count)
}
Esempio n. 5
0
func JumpCommand(args []string) {
	fr := gub.CurFrame()
	b := gub.CurBlock()
	ic, err := gub.GetInt(args[1],
		"instruction number", 0, len(b.Instrs)-1)
	if err != nil {
		return
	}
	// compensate for interpreter loop which does ic++ at end of loop body
	fr.SetPC(ic - 1)
	gub.InCmdLoop = false
}
Esempio n. 6
0
// shows stack of all goroutines
func GoroutinesCommand(args []string) {
	goTops := interp.GetInterpreter().GoTops()
	var goNum int
	var err error
	if len(args) > 1 {
		goNum, err = gub.GetInt(args[1],
			"goroutine number", 0, len(goTops)-1)
		if err != nil {
			return
		}
		gub.PrintGoroutine(goNum, goTops)
		return
	}
	for goNum := range goTops {
		gub.PrintGoroutine(goNum, goTops)
	}
}
Esempio n. 7
0
func DisassembleCommand(args []string) {
	fr := gub.CurFrame()
	myfn := fr.Fn()
	if len(args) > 1 {
		what := args[1]
		if what == "." {
			if block := gub.CurBlock(); block != nil {
				gub.DisasmBlock(myfn, block.Index, fr.PC())
			} else {
				gub.Errmsg("Can't get block info here")
			}
			return
		} else if what != "+" {
			if fn, err := gub.FuncLookup(what); err == nil && fn != nil {
				myfn = fn
			} else {
				bnum, err := gub.GetInt(args[1],
					"block number of function name", 0, len(myfn.Blocks)-1)
				if err == nil {
					lastBlock := len(myfn.Blocks) - 1
					if bnum <= lastBlock {
						b := myfn.Blocks[bnum]
						if len(args) == 3 {
							ic, err := gub.GetUInt(args[2],
								"instruction number", 0, uint64(len(b.Instrs)-1))
							if err == nil {
								gub.DisasmInst(myfn, bnum, ic)
							}
						} else {
							gub.DisasmBlock(myfn, bnum, -1)
						}
					} else {
						gub.Errmsg("Block number should be between 0 and %d; got %d",
							lastBlock, bnum)
					}
				}
				return
			}
		}
	} else {
		gub.DisasmCurrentInst()
		return
	}
	myfn.WriteTo(os.Stderr)
}
Esempio n. 8
0
// DeleteCommand implements the debugger command:
//    delete [bpnum1 ... ]
// which deletes some breakpoints by breakpoint number
//
// See also "breakpoint", "info break", "enable", and "disable".
func DeleteCommand(args []string) {
	for i := 1; i < len(args); i++ {
		msg := fmt.Sprintf("breakpoint number for argument %d", i)
		bpnum, err := gub.GetInt(args[i], msg, 0, len(gub.Breakpoints)-1)
		if err != nil {
			continue
		}
		if gub.BreakpointExists(bpnum) {
			if gub.BreakpointDelete(bpnum) {
				gub.Msg(" Deleted breakpoint %d", bpnum)
			} else {
				gub.Errmsg("Trouble deleting breakpoint %d", bpnum)
			}
		} else {
			gub.Errmsg("Breakpoint %d doesn't exist", bpnum)
		}
	}
}