Example #1
0
// 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())
}
Example #2
0
func JumpCommand(args []string) {
	fr := gub.CurFrame()
	b := gub.CurBlock()
	ic, err := gub.GetInt(args[1],
		"instruction number", 0, len(b.Instrs)-1)
	if err != nil {
		return
	}
	// compensate for interpreter loop which does ic++ at end of loop body
	fr.SetPC(ic - 1)
	gub.InCmdLoop = false
}
Example #3
0
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)
	}
}
Example #4
0
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())
		}
	}
}
Example #5
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)
}