From 2407005444d4dd73d7e731adb3f8316fd2b84032 Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Sat, 19 Sep 2015 23:41:26 -0500 Subject: [PATCH] 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 bt`. --- terminal/command.go | 62 +++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/terminal/command.go b/terminal/command.go index b18de250..f14a4909 100644 --- a/terminal/command.go +++ b/terminal/command.go @@ -75,7 +75,7 @@ func DebugCommands(client service.Client) *Commands { {aliases: []string{"regs"}, cmdFn: regs, helpMsg: "Print contents of CPU registers."}, {aliases: []string{"exit", "quit", "q"}, cmdFn: exitCommand, helpMsg: "Exit the debugger."}, {aliases: []string{"list", "ls"}, cmdFn: listCommand, helpMsg: "list . Show source around current point or provided linespec."}, - {aliases: []string{"stack", "bt"}, cmdFn: stackCommand, helpMsg: "stack [-] [-full] []. Prints stack."}, + {aliases: []string{"stack", "bt"}, cmdFn: stackCommand, helpMsg: "stack [] [-full]. Prints 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] 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": return callFilterSortAndOutput(locals, fullargs[i+1:]) case "args": @@ -624,30 +635,14 @@ func filterSortAndOutput(fn filteringFunc) cmdfunc { } func stackCommand(client service.Client, args ...string) error { - var err error - - goroutineid := -1 - depth := 10 - full := false - - for i := range args { - 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 - } + var ( + err error + goroutineid = -1 + ) + depth, full, err := parseStackArgs(args) + if err != nil { + return err } - stack, err := client.Stacktrace(goroutineid, depth, full) if err != nil { return err @@ -656,6 +651,25 @@ func stackCommand(client service.Client, args ...string) error { 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 { if len(args) == 0 { state, err := client.GetState()