本文整理汇总了Golang中github.com/rocky/ssa-interp/gub.Msg函数的典型用法代码示例。如果您正苦于以下问题:Golang Msg函数的具体用法?Golang Msg怎么用?Golang Msg使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Msg函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ShowOnOff
func ShowOnOff(subcmdName string, on bool) {
if on {
gub.Msg("%s is on.", subcmdName)
} else {
gub.Msg("%s is off.", subcmdName)
}
}
示例2: InfoPackageSubcmd
// InfoPackageCommand implements the command:
// info package [*name* ]
// which show information about a package or lists all packages.
func InfoPackageSubcmd(args []string) {
if len(args) > 2 {
for _, pkg_name := range args[2:len(args)] {
if pkg := gub.Program().PackagesByName[pkg_name]; pkg != nil {
gub.Msg("Package %s: \"%s\"", pkg_name, pkg.Object.Path())
gub.Section("Package members:")
var names []string
for k, _ := range pkg.Members {
names = append(names, k)
}
sort.Strings(names)
opts := columnize.DefaultOptions()
opts.DisplayWidth = gub.Maxwidth
opts.LinePrefix = " "
mems := strings.TrimRight(columnize.Columnize(names, opts),
"\n")
gub.Msg(mems)
} else {
gub.Errmsg("Package %s not imported", pkg_name)
}
}
} else {
pkgNames := []string{}
for pkg := range gub.Program().PackagesByName {
pkgNames = append(pkgNames, pkg)
}
gub.PrintSorted("All imported packages", pkgNames)
}
}
示例3: InfoBreakpointSubcmd
// InfoBreakpointSubcmd implements the debugger command:
// info breakpoint
//
// This command shows status of user-settable breakpoints. If no
// breakpoint numbers are given, the show all breakpoints. Otherwise
// only those breakpoints listed are shown and the order given.
//
// The "Disp" column contains one of "keep", "del", the disposition of
// the breakpoint after it gets hit.
//
// The "enb" column indicates whether the breakpoint is enabled.
//
// The "Where" column indicates where the breakpoint is located.
// Status of user-settable breakpoints.
func InfoBreakpointSubcmd(args []string) {
if gub.IsBreakpointEmpty() {
gub.Msg("No breakpoints set")
return
}
bpLen := len(gub.Breakpoints)
if bpLen-gub.BrkptsDeleted == 0 {
gub.Msg("No breakpoints.")
}
if len(args) > 2 {
headerShown := false
for _, num := range args[2:] {
if bpNum, err := gub.GetInt(num,
"breakpoint number", 0, bpLen-1); err == nil {
if bp := gub.BreakpointFindById(bpNum); bp != nil {
if !headerShown {
gub.Section("Num Type Disp Enb Where")
headerShown = true
}
gub.Bpprint(*bp)
} else {
gub.Errmsg("Breakpoint %d not found.", bpNum)
}
}
}
} else {
gub.Section("Num Type Disp Enb Where")
for _, bp := range gub.Breakpoints {
if bp.Deleted {
continue
}
gub.Bpprint(*bp)
}
}
}
示例4: AliasCommand
func AliasCommand(args []string) {
if len(args) == 1 {
var names []string
for k, _ := range gub.Aliases {
names = append(names, k)
}
gub.Section("All aliases:")
sort.Strings(names)
opts := columnize.DefaultOptions()
opts.DisplayWidth = gub.Maxwidth
opts.LinePrefix = " "
mems := strings.TrimRight(columnize.Columnize(names, opts),
"\n")
gub.Msg(mems)
} else {
cmd := args[1]
if info := gub.Cmds[cmd]; info != nil {
if len(info.Aliases) > 0 {
gub.Msg("Aliases for %s: %s",
cmd, strings.Join(info.Aliases, ", "))
} else {
gub.Msg("No aliases for %s", cmd)
}
} else if realCmd := gub.Aliases[cmd]; realCmd != "" {
gub.Msg("Alias %s is an alias for command %s", cmd, realCmd)
} else {
gub.Errmsg("Can't find command or alias %s", cmd)
}
}
}
示例5: LocalsCommand
// LocalsCommand implements the debugger command:
// locals [*name*]
// which shows local variable info.
//
// See also "globals", "whatis", and "eval".
func LocalsCommand(args []string) {
argc := len(args) - 1
fr := gub.CurFrame()
if argc == 0 {
for i, _ := range fr.Locals() {
gub.PrintLocal(fr, uint(i), false)
}
for reg, v := range fr.Reg2Var {
gub.Msg("reg %s, var %s", reg, v)
}
} else {
varname := args[1]
if gub.PrintIfLocal(fr, varname, false) {
return
}
// FIXME: This really shouldn't be needed.
for i, v := range fr.Locals() {
ssaVal := fr.Fn().Locals[i]
if varname == ssaVal.Name() {
gub.Msg("fixme %s %s: %s",
varname, fr.Fn().Locals[i], interp.ToInspect(v, nil))
break
}
}
}
}
示例6: InfoProgramSubcmd
// InfoProgramSubcmd implements the debugger command:
// info program
// This command prints information about the program including:
// instruction number
// block number
// function number
// stop event
// source-code position
func InfoProgramSubcmd(args []string) {
if gub.TraceEvent == ssa2.PROGRAM_TERMINATION {
gub.Msg("program stop event: %s", ssa2.Event2Name[gub.TraceEvent])
return
}
fr := gub.CurFrame()
pc := fr.PC()
gub.Msg("instruction number: %d", pc)
block := gub.CurBlock()
if block == nil {
gub.Msg("unknown block")
} else {
gub.Msg("basic block: %d", block.Index)
if block.Scope != nil {
gub.Msg("scope: %d", block.Scope.ScopeId())
} else {
gub.Msg("unknown scope")
}
}
gub.Msg("function: %s", fr.FnAndParamString())
gub.Msg("program stop event: %s", ssa2.Event2Name[gub.TraceEvent])
gub.Msg("position: %s", gub.CurFrame().PositionRange())
}
示例7: InfoPCSubcmd
func InfoPCSubcmd(args []string) {
fr := gub.CurFrame()
pc := fr.PC()
fn := fr.FnAndParamString()
if block := gub.CurBlock(); block != nil {
gub.Msg("instruction number: %d of block %d, function %s",
pc, block.Index, fn)
} else if pc == -2 {
gub.Msg("instruction number: %d (at return), function %s", pc, fn)
} else {
gub.Msg("instruction number: %d, function %s", pc, fn)
}
}
示例8: InfoBlockSubcmd
func InfoBlockSubcmd(args []string) {
block := gub.CurBlock()
// if block == nil && gub.Instr.Block() != nil {
// block = gub.Instr.Block()
// }
if block == nil {
gub.Msg("unknown block")
} else {
gub.Msg("basic block: %d", block.Index)
if block.Scope != nil {
gub.Msg("scope: %d", block.Scope.ScopeId())
}
}
}
示例9: FormatCommand
// FormatCommand implements the debugger command: format
//
// format
//
// Formats AST and produces source text for function.
// FIXME: allow one to specify a function or package
func FormatCommand(args []string) {
var syntax ast.Node
var err error
fr := gub.CurFrame()
fn := fr.Fn()
if len(args) > 1 {
name := args[1]
if name != "." {
fn, err = gub.FuncLookup(name)
if err != nil {
gub.Errmsg(err.Error())
return
} else if fn == nil {
gub.Errmsg("function '%s' not found", name)
return
}
}
syntax = fn.Syntax()
} else {
syntax = fn.Syntax()
switch s := (*gub.Instr).(type) {
case *ssa2.Trace:
syntax = s.Syntax()
}
}
// FIXME: Put this as a routine in parent gub and
// use when showing locations
if syntax != nil {
gub.PrintSyntax(syntax, fn.Prog.Fset)
} else {
gub.Msg("Sorry, we don't have an AST for this")
}
}
示例10: AstCommand
// AstCommand implements the debugger command: ast
//
// ast
//
// Prints AST for current function.
func AstCommand(args []string) {
var syntax ast.Node
var err error
fr := gub.CurFrame()
fn := fr.Fn()
if len(args) > 1 {
name := args[1]
fn, err = gub.FuncLookup(name)
if err != nil {
gub.Errmsg(err.Error())
return
} else if fn == nil {
gub.Errmsg("function '%s' not found", name)
return
} else {
syntax = fn.Syntax()
}
} else {
syntax = fn.Syntax()
switch s := (*gub.Instr).(type) {
case *ssa2.Trace:
syntax = s.Syntax()
}
}
if syntax != nil {
ast.Print(fn.Prog.Fset, syntax)
fmt.Println("")
} else {
gub.Msg("Sorry, we don't have an AST for this")
}
}
示例11: ContinueCommand
func ContinueCommand(args []string) {
for fr := gub.TopFrame(); fr != nil; fr = fr.Caller(0) {
interp.SetStepOff(fr)
}
gub.InCmdLoop = false
gub.Msg("Continuing...")
}
示例12: LocationsCommand
func LocationsCommand(args []string) {
fn := gub.CurFrame().Fn()
pkg := fn.Pkg
for _, l := range pkg.Locs() {
gub.Msg("\t%s", ssa2.FmtRange(fn, l.Pos(), l.EndP()))
}
}
示例13: InfoScopeSubcmd
func InfoScopeSubcmd(args []string) {
fr := gub.CurFrame()
scope := fr.Scope()
if scope == nil {
gub.Errmsg("No scope recorded here")
return
}
count := 0
if len(args) == 3 {
var err error
count, err = gub.GetInt(args[2],
"count", 0, gub.MAXSTACKSHOW)
if err != nil {
return
}
}
typescope := scope.Scope
for i := 0; i < count; i++ {
typescope = typescope.Parent()
if typescope == nil {
gub.Errmsg("There are only %d nested scopes", i)
return
}
scope = fr.Fn().Pkg.TypeScope2Scope[typescope]
if scope == nil {
gub.Errmsg("No parent scope; There are only %d nested scopes", i)
return
}
}
gub.Section("scope number %d", scope.ScopeId())
gub.Msg("%s", typescope)
}
示例14: InstructionCommand
func InstructionCommand(args []string) {
fr := gub.CurFrame()
ic := uint64(fr.PC())
if len(args) >= 2 {
new_ic, ok := gub.GetUInt(args[1], "instruction number", 0,
uint64(len(gub.CurFrame().Block().Instrs)))
if ok == nil {
ic = new_ic
} else {
gub.Errmsg("Expecting integer; got %s.", args[1])
return
}
// if len(args) == 3 {
// new_num, ok = strconv.Atoi(args[2])
// if ok != nil {
// gub.Errmsg("Expecting integer; got %s", args[2])
// return
// }
}
gub.DisasmInst(fr.Fn(), fr.Block().Index, ic)
genericInstr := fr.Block().Instrs[ic]
switch instr := genericInstr.(type) {
case *ssa2.ChangeType:
gub.Msg("%s: %s", instr.X.Name(), gub.Deref2Str(fr.Get(instr.X), nil))
case *ssa2.Convert:
gub.Msg("%s: %s", instr.X.Name(), gub.Deref2Str(fr.Get(instr.X), nil))
case *ssa2.MakeInterface:
gub.Msg("%s: %s", instr.X.Name(), gub.Deref2Str(fr.Get(instr.X), nil))
case *ssa2.ChangeInterface:
gub.Msg("%s: %s", instr.X.Name(), gub.Deref2Str(fr.Get(instr.X), nil))
case *ssa2.Range:
gub.Msg("%s: %s", instr.X.Name(), gub.Deref2Str(fr.Get(instr.X), nil))
case *ssa2.UnOp:
gub.Msg("%s: %s", instr.X.Name(), gub.Deref2Str(fr.Get(instr.X), nil))
case *ssa2.Field:
gub.Msg("%s: %s", instr.X.Name(), gub.Deref2Str(fr.Get(instr.X), nil))
case *ssa2.BinOp:
gub.Msg("%s: %s", instr.X.Name(), gub.Deref2Str(fr.Get(instr.X), nil))
gub.Msg("%s: %s", instr.X.Name(), gub.Deref2Str(fr.Get(instr.Y), nil))
case *ssa2.Trace:
default:
gub.Msg("Don't know how to deal with %s yet", instr)
}
}
示例15: GlobalsCommand
// GlobalsCommand implements the debugger command:
// globals [*name*]
// which shows global variable info.
//
// See also "locals", "whatis", and "eval".
func GlobalsCommand(args []string) {
argc := len(args) - 1
if argc == 0 {
for k, v := range gub.CurFrame().I().Globals() {
if v == nil {
fmt.Printf("%s: nil\n")
} else {
// FIXME: figure out why reflect.lookupCache causes
// an panic on a nil pointer or invalid address
if fmt.Sprintf("%s", k) == "reflect.lookupCache" {
continue
}
gub.Msg("%s: %s", k, interp.ToInspect(*v, &k))
}
}
} else {
// This doesn't work and I don't know how to fix it.
for i := 1; i <= argc; i++ {
vv := ssa2.NewConst(exact.MakeString(args[i]),
types.Typ[types.String], token.NoPos, token.NoPos)
// fmt.Println(vv, "vs", interp.ToInspect(vv))
v, ok := gub.CurFrame().I().Globals()[vv]
if ok {
gub.Msg("%s: %s", vv, interp.ToInspect(*v, nil))
}
}
// This is ugly, but I don't know how to turn a string into
// a ssa2.Value.
globals := make(map[string]*interp.Value)
for k, v := range gub.CurFrame().I().Globals() {
globals[fmt.Sprintf("%s", k)] = v
}
for i := 1; i <= argc; i++ {
vv := args[i]
v, ok := globals[vv]
if ok {
gub.Msg("%s: %s", vv, interp.ToInspect(*v, nil))
}
}
}
}