mirror of
https://github.com/go-delve/delve.git
synced 2025-10-29 01:27:16 +08:00
@ -59,6 +59,7 @@ func DebugCommands(client service.Client) *Commands {
|
||||
{aliases: []string{"print", "p"}, cmdFn: printVar, helpMsg: "Evaluate a variable."},
|
||||
{aliases: []string{"info"}, cmdFn: info, helpMsg: "Subcommands: args, funcs, locals, sources, vars, or regs."},
|
||||
{aliases: []string{"exit"}, cmdFn: nullCommand, helpMsg: "Exit the debugger."},
|
||||
{aliases: []string{"stack"}, cmdFn: stackCommand, helpMsg: "stack [<depth> [<goroutine id>]]. Prints stack."},
|
||||
}
|
||||
|
||||
return c
|
||||
@ -189,7 +190,7 @@ func goroutines(client service.Client, args ...string) error {
|
||||
if g.Function != nil {
|
||||
fname = g.Function.Name
|
||||
}
|
||||
fmt.Printf("Goroutine %d - %s:%d %s\n", g.ID, g.File, g.Line, fname)
|
||||
fmt.Printf("Goroutine %d - %s:%d %s (%#v)\n", g.ID, g.File, g.Line, fname, g.PC)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -399,7 +400,7 @@ func info(client service.Client, args ...string) error {
|
||||
data = filterVariables(vars, filter)
|
||||
|
||||
default:
|
||||
return fmt.Errorf("unsupported info type, must be args, funcs, locals, sources, or vars")
|
||||
return fmt.Errorf("unsupported info type, must be args, funcs, locals, sources or vars")
|
||||
}
|
||||
|
||||
// sort and output data
|
||||
@ -411,6 +412,45 @@ func info(client service.Client, args ...string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func stackCommand(client service.Client, args ...string) error {
|
||||
var err error
|
||||
|
||||
goroutineid := -1
|
||||
depth := 10
|
||||
|
||||
switch len(args) {
|
||||
case 0:
|
||||
// nothing to do
|
||||
case 2:
|
||||
goroutineid, err = strconv.Atoi(args[1])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Wrong argument: expected integer")
|
||||
}
|
||||
fallthrough
|
||||
case 1:
|
||||
depth, err = strconv.Atoi(args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("Wrong argument: expected integer")
|
||||
}
|
||||
|
||||
default:
|
||||
return fmt.Errorf("Wrong number of arguments to stack")
|
||||
}
|
||||
|
||||
stack, err := client.Stacktrace(goroutineid, depth)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := range stack {
|
||||
name := "(nil)"
|
||||
if stack[i].Function != nil {
|
||||
name = stack[i].Function.Name
|
||||
}
|
||||
fmt.Printf("%d. %s\n\t%s:%d (%#v)\n", i, name, stack[i].File, stack[i].Line, stack[i].PC)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func printcontext(state *api.DebuggerState) error {
|
||||
if state.CurrentThread == nil {
|
||||
fmt.Println("No current thread available")
|
||||
|
||||
Reference in New Issue
Block a user