diff --git a/Documentation/cli/README.md b/Documentation/cli/README.md index d68963971530e74346e629a75d106c0e4180a219..9ebcebf8f8503ced08fa8456ba632491109a7387 100644 --- a/Documentation/cli/README.md +++ b/Documentation/cli/README.md @@ -39,6 +39,7 @@ Command | Description [trace](#trace) | Set tracepoint. [types](#types) | Print list of types [vars](#vars) | Print package variables. +[whatis](#whatis) | Prints type of an expression. ## args Print function arguments. @@ -320,3 +321,9 @@ Print package variables. If regex is specified only package variables with a name matching it will be returned. If -v is specified more information about each package variable will be shown. +## whatis +Prints type of an expression. + + whatis . + + diff --git a/pkg/terminal/command.go b/pkg/terminal/command.go index 31383599f64e5377b99ebe499f473473dc8a97f9..04ca46eb28695d39441b39851120402ba60c2109 100644 --- a/pkg/terminal/command.go +++ b/pkg/terminal/command.go @@ -11,6 +11,7 @@ import ( "io" "math" "os" + "reflect" "regexp" "sort" "strconv" @@ -141,6 +142,9 @@ Called with more arguments it will execute a command on the specified goroutine. [goroutine ] [frame ] print See $GOPATH/src/github.com/derekparker/delve/Documentation/cli/expr.md for a description of supported expressions.`}, + {aliases: []string{"whatis"}, allowedPrefixes: scopePrefix, cmdFn: whatisCommand, helpMsg: `Prints type of an expression. + + whatis .`}, {aliases: []string{"set"}, allowedPrefixes: scopePrefix, cmdFn: setVar, helpMsg: `Changes the value of a variable. [goroutine ] [frame ] set = @@ -911,6 +915,26 @@ func printVar(t *Term, ctx callContext, args string) error { return nil } +func whatisCommand(t *Term, ctx callContext, args string) error { + if len(args) == 0 { + return fmt.Errorf("not enough arguments") + } + val, err := t.client.EvalVariable(ctx.Scope, args, ShortLoadConfig) + if err != nil { + return err + } + if val.Type != "" { + fmt.Println(val.Type) + } + if val.RealType != val.Type { + fmt.Printf("Real type: %s\n", val.RealType) + } + if val.Kind == reflect.Interface && len(val.Children) > 0 { + fmt.Printf("Concrete type: %s\n", val.Children[0].Type) + } + return nil +} + func setVar(t *Term, ctx callContext, args string) error { // HACK: in go '=' is not an operator, we detect the error and try to recover from it by splitting the input string _, err := parser.ParseExpr(args) @@ -1194,7 +1218,6 @@ func disassCommand(t *Term, ctx callContext, args string) error { return disasmErr } - fmt.Printf("printing\n") DisasmPrint(disasm, os.Stdout) return nil