terminal/command: Stack no long takes goroutine id
Default numeric argument now simply represents the depth. If you would like to see the stack trace of another goroutine, use `goroutine <id> bt`.
This commit is contained in:
parent
784505813d
commit
2407005444
@ -75,7 +75,7 @@ func DebugCommands(client service.Client) *Commands {
|
|||||||
{aliases: []string{"regs"}, cmdFn: regs, helpMsg: "Print contents of CPU registers."},
|
{aliases: []string{"regs"}, cmdFn: regs, helpMsg: "Print contents of CPU registers."},
|
||||||
{aliases: []string{"exit", "quit", "q"}, cmdFn: exitCommand, helpMsg: "Exit the debugger."},
|
{aliases: []string{"exit", "quit", "q"}, cmdFn: exitCommand, helpMsg: "Exit the debugger."},
|
||||||
{aliases: []string{"list", "ls"}, cmdFn: listCommand, helpMsg: "list <linespec>. Show source around current point or provided linespec."},
|
{aliases: []string{"list", "ls"}, cmdFn: listCommand, helpMsg: "list <linespec>. Show source around current point or provided linespec."},
|
||||||
{aliases: []string{"stack", "bt"}, cmdFn: stackCommand, helpMsg: "stack [-<depth>] [-full] [<goroutine id>]. Prints stack."},
|
{aliases: []string{"stack", "bt"}, cmdFn: stackCommand, helpMsg: "stack [<depth>] [-full]. Prints stack."},
|
||||||
{aliases: []string{"frame"}, cmdFn: frame, helpMsg: "Sets current stack frame (0 is the top of the stack)"},
|
{aliases: []string{"frame"}, cmdFn: frame, helpMsg: "Sets current stack frame (0 is the top of the stack)"},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,6 +323,17 @@ func scopePrefix(client service.Client, cmdname string, pargs ...string) error {
|
|||||||
}
|
}
|
||||||
loc := locs[frame]
|
loc := locs[frame]
|
||||||
return printfile(loc.File, loc.Line, true)
|
return printfile(loc.File, loc.Line, true)
|
||||||
|
case "stack", "bt":
|
||||||
|
depth, full, err := parseStackArgs(fullargs[i+1:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
stack, err := client.Stacktrace(scope.GoroutineID, depth, full)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
printStack(stack, "")
|
||||||
|
return nil
|
||||||
case "locals":
|
case "locals":
|
||||||
return callFilterSortAndOutput(locals, fullargs[i+1:])
|
return callFilterSortAndOutput(locals, fullargs[i+1:])
|
||||||
case "args":
|
case "args":
|
||||||
@ -624,30 +635,14 @@ func filterSortAndOutput(fn filteringFunc) cmdfunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stackCommand(client service.Client, args ...string) error {
|
func stackCommand(client service.Client, args ...string) error {
|
||||||
var err error
|
var (
|
||||||
|
err error
|
||||||
goroutineid := -1
|
goroutineid = -1
|
||||||
depth := 10
|
)
|
||||||
full := false
|
depth, full, err := parseStackArgs(args)
|
||||||
|
if err != nil {
|
||||||
for i := range args {
|
return err
|
||||||
if args[i] == "-full" {
|
|
||||||
full = true
|
|
||||||
} else if args[i][0] == '-' {
|
|
||||||
n, err := strconv.Atoi(args[i][1:])
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("unknown option: %s", args[i])
|
|
||||||
}
|
|
||||||
depth = n
|
|
||||||
} else {
|
|
||||||
n, err := strconv.Atoi(args[i])
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("goroutine id must be a number")
|
|
||||||
}
|
|
||||||
goroutineid = n
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stack, err := client.Stacktrace(goroutineid, depth, full)
|
stack, err := client.Stacktrace(goroutineid, depth, full)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -656,6 +651,25 @@ func stackCommand(client service.Client, args ...string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseStackArgs(args []string) (int, bool, error) {
|
||||||
|
var (
|
||||||
|
depth = 10
|
||||||
|
full = false
|
||||||
|
)
|
||||||
|
for i := range args {
|
||||||
|
if args[i] == "-full" {
|
||||||
|
full = true
|
||||||
|
} else {
|
||||||
|
n, err := strconv.Atoi(args[i])
|
||||||
|
if err != nil {
|
||||||
|
return 0, false, fmt.Errorf("depth must be a number")
|
||||||
|
}
|
||||||
|
depth = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return depth, full, nil
|
||||||
|
}
|
||||||
|
|
||||||
func listCommand(client service.Client, args ...string) error {
|
func listCommand(client service.Client, args ...string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
state, err := client.GetState()
|
state, err := client.GetState()
|
||||||
|
Loading…
Reference in New Issue
Block a user