提交 c2092d16 编写于 作者: A aarzilli 提交者: Derek Parker

terminal: implement whatis command

Implements #596
上级 317ebe1c
...@@ -39,6 +39,7 @@ Command | Description ...@@ -39,6 +39,7 @@ Command | Description
[trace](#trace) | Set tracepoint. [trace](#trace) | Set tracepoint.
[types](#types) | Print list of types [types](#types) | Print list of types
[vars](#vars) | Print package variables. [vars](#vars) | Print package variables.
[whatis](#whatis) | Prints type of an expression.
## args ## args
Print function arguments. Print function arguments.
...@@ -320,3 +321,9 @@ Print package variables. ...@@ -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. 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 <expression>.
...@@ -11,6 +11,7 @@ import ( ...@@ -11,6 +11,7 @@ import (
"io" "io"
"math" "math"
"os" "os"
"reflect"
"regexp" "regexp"
"sort" "sort"
"strconv" "strconv"
...@@ -141,6 +142,9 @@ Called with more arguments it will execute a command on the specified goroutine. ...@@ -141,6 +142,9 @@ Called with more arguments it will execute a command on the specified goroutine.
[goroutine <n>] [frame <m>] print <expression> [goroutine <n>] [frame <m>] print <expression>
See $GOPATH/src/github.com/derekparker/delve/Documentation/cli/expr.md for a description of supported expressions.`}, 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 <expression>.`},
{aliases: []string{"set"}, allowedPrefixes: scopePrefix, cmdFn: setVar, helpMsg: `Changes the value of a variable. {aliases: []string{"set"}, allowedPrefixes: scopePrefix, cmdFn: setVar, helpMsg: `Changes the value of a variable.
[goroutine <n>] [frame <m>] set <variable> = <value> [goroutine <n>] [frame <m>] set <variable> = <value>
...@@ -911,6 +915,26 @@ func printVar(t *Term, ctx callContext, args string) error { ...@@ -911,6 +915,26 @@ func printVar(t *Term, ctx callContext, args string) error {
return nil 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 { 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 // 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) _, err := parser.ParseExpr(args)
...@@ -1194,7 +1218,6 @@ func disassCommand(t *Term, ctx callContext, args string) error { ...@@ -1194,7 +1218,6 @@ func disassCommand(t *Term, ctx callContext, args string) error {
return disasmErr return disasmErr
} }
fmt.Printf("printing\n")
DisasmPrint(disasm, os.Stdout) DisasmPrint(disasm, os.Stdout)
return nil return nil
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册