Example #1
0
func DisassembleCommand(args []string) {
	fr := gub.CurFrame()
	myfn := fr.Fn()
	if len(args) > 1 {
		what := args[1]
		if what == "." {
			if block := gub.CurBlock(); block != nil {
				gub.DisasmBlock(myfn, block.Index, fr.PC())
			} else {
				gub.Errmsg("Can't get block info here")
			}
			return
		} else if what != "+" {
			if fn, err := gub.FuncLookup(what); err == nil && fn != nil {
				myfn = fn
			} else {
				bnum, err := gub.GetInt(args[1],
					"block number of function name", 0, len(myfn.Blocks)-1)
				if err == nil {
					lastBlock := len(myfn.Blocks) - 1
					if bnum <= lastBlock {
						b := myfn.Blocks[bnum]
						if len(args) == 3 {
							ic, err := gub.GetUInt(args[2],
								"instruction number", 0, uint64(len(b.Instrs)-1))
							if err == nil {
								gub.DisasmInst(myfn, bnum, ic)
							}
						} else {
							gub.DisasmBlock(myfn, bnum, -1)
						}
					} else {
						gub.Errmsg("Block number should be between 0 and %d; got %d",
							lastBlock, bnum)
					}
				}
				return
			}
		}
	} else {
		gub.DisasmCurrentInst()
		return
	}
	myfn.WriteTo(os.Stderr)
}
Example #2
0
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)
	}
}