Skip to content

Commit

Permalink
Fix TestStepPtr
Browse files Browse the repository at this point in the history
  • Loading branch information
derekparker committed Nov 22, 2022
1 parent 3c9e7a0 commit 07a6c9b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
13 changes: 12 additions & 1 deletion pkg/proc/ppc64le_disasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proc

import (
"encoding/binary"

"github.com/go-delve/delve/pkg/dwarf/op"
"github.com/go-delve/delve/pkg/dwarf/regnum"
"golang.org/x/arch/ppc64/ppc64asm"
Expand Down Expand Up @@ -61,7 +62,17 @@ func ppc64leAsmDecode(asmInst *AsmInstruction, mem []byte, regs *op.DwarfRegiste

func resolveCallArgPPC64LE(inst *ppc64asm.Inst, instAddr uint64, currentGoroutine bool, regs *op.DwarfRegisters, mem MemoryReadWriter, bininfo *BinaryInfo) *Location {
switch inst.Op {
case ppc64asm.B, ppc64asm.BL, ppc64asm.BLA, ppc64asm.BCL, ppc64asm.BCLA, ppc64asm.BCLR, ppc64asm.BCLRL, ppc64asm.BCCTRL, ppc64asm.BCTARL:
case ppc64asm.BCLRL, ppc64asm.BCLR:
if regs != nil && regs.PC() == instAddr {
pc := regs.Reg(bininfo.Arch.LRRegNum).Uint64Val
file, line, fn := bininfo.PCToLine(pc)
if fn == nil {
return &Location{PC: pc}
}
return &Location{PC: pc, File: file, Line: line, Fn: fn}
}
return nil
case ppc64asm.B, ppc64asm.BL, ppc64asm.BLA, ppc64asm.BCL, ppc64asm.BCLA, ppc64asm.BCCTRL, ppc64asm.BCTARL:
// ok
default:
return nil
Expand Down
24 changes: 16 additions & 8 deletions pkg/proc/target_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (
"fmt"
"go/ast"
"go/token"
"golang.org/x/arch/ppc64/ppc64asm"
"path/filepath"
"runtime"
"strings"

"golang.org/x/arch/ppc64/ppc64asm"

"github.com/go-delve/delve/pkg/astutil"
"github.com/go-delve/delve/pkg/dwarf/reader"
)
Expand Down Expand Up @@ -155,6 +156,7 @@ func (grp *TargetGroup) Continue() error {
// here we either set a breakpoint into the destination of the CALL
// instruction or we determined that the called function is hidden,
// either way we need to resume execution
fmt.Println("stepping into ++++++++")
if err = setStepIntoBreakpoint(dbp, fn, text, sameGoroutineCondition(dbp.SelectedGoroutine())); err != nil {
return err
}
Expand Down Expand Up @@ -648,7 +650,9 @@ func next(dbp *Target, stepInto, inlinedStepOut bool) error {
}

func setStepIntoBreakpoints(dbp *Target, curfn *Function, text []AsmInstruction, topframe Stackframe, sameGCond ast.Expr) error {
fmt.Println("set step into breakpoints")
for _, instr := range text {
fmt.Printf("instr: %v\n", instr.Text(IntelFlavour, dbp.BinInfo()))
if instr.Loc.File != topframe.Current.File || instr.Loc.Line != topframe.Current.Line || !instr.IsCall() {
continue
}
Expand All @@ -658,12 +662,14 @@ func setStepIntoBreakpoints(dbp *Target, curfn *Function, text []AsmInstruction,
return err
}
} else {
fmt.Println("non absolute")
// Non-absolute call instruction, set a StepBreakpoint here
if _, err := allowDuplicateBreakpoint(dbp.SetBreakpoint(0, instr.Loc.PC, StepBreakpoint, sameGCond)); err != nil {
return err
}
}
}
fmt.Println("fin set step into breakpoints")
return nil
}

Expand Down Expand Up @@ -754,19 +760,21 @@ func setStepIntoBreakpoint(dbp *Target, curfn *Function, text []AsmInstruction,

pc := instr.DestLoc.PC
fn := instr.DestLoc.Fn
fmt.Println("PC before: ", pc)
fmt.Printf("instr: %v\n", instr.Text(IntelFlavour, dbp.BinInfo()))
if fn != nil {
fmt.Println("fn before: ", fn.Name)
}

if runtime.GOARCH == "ppc64le" && (instr.Inst.OpcodeEquals(uint64(ppc64asm.BCLRL))) {
if runtime.GOARCH == "ppc64le" && instr.Inst.OpcodeEquals(uint64(ppc64asm.BCLRL)) {
fmt.Println("----- found bclrl instruction")
regs, err := dbp.CurrentThread().Registers()
if err != nil {
return err
}
fmt.Println("LR after: ", pc)
pc = regs.LR()
fn = dbp.BinInfo().PCToFunc(pc)
fmt.Println("LR before: ", pc)
fmt.Println("FN: ", fn)
fmt.Printf("lr: %#x fn: %s\n", regs.LR(), fn.Name)
lr := regs.LR()
fn = dbp.BinInfo().PCToFunc(lr)
fmt.Printf("pc: %#x lr: %#x fn: %s\n", regs.PC(), regs.LR(), fn.Name)
}

// Skip unexported runtime functions
Expand Down

0 comments on commit 07a6c9b

Please sign in to comment.