Skip to content

Commit

Permalink
proc: prefer addresses when setting a breakpoint (go-delve#3193)
Browse files Browse the repository at this point in the history
If a breakpoint has both a list of addresses and an expression prefer
the list of addresses, otherwise it is impossible to set breakpoint
with expressions that depend on the current scope, like 'break +0'
which sets a breakpoint on the current line.
  • Loading branch information
aarzilli authored Nov 16, 2022
1 parent 18ebd91 commit d15c86e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/proc/target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ func enableBreakpointOnTarget(p *Target, lbp *LogicalBreakpoint) error {
addrs, err = FindFileLocation(p, lbp.Set.File, lbp.Set.Line)
case lbp.Set.FunctionName != "":
addrs, err = FindFunctionLocation(p, lbp.Set.FunctionName, lbp.Set.Line)
case lbp.Set.Expr != nil:
addrs = lbp.Set.Expr(p)
case len(lbp.Set.PidAddrs) > 0:
for _, pidAddr := range lbp.Set.PidAddrs {
if pidAddr.Pid == p.Pid() {
addrs = append(addrs, pidAddr.Addr)
}
}
case lbp.Set.Expr != nil:
addrs = lbp.Set.Expr(p)
default:
return fmt.Errorf("breakpoint %d can not be enabled", lbp.LogicalID)
}
Expand Down
14 changes: 14 additions & 0 deletions pkg/terminal/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1342,3 +1342,17 @@ func TestDisassPosCmd(t *testing.T) {
}
})
}

func TestCreateBreakpointByLocExpr(t *testing.T) {
withTestTerminal("math", t, func(term *FakeTerminal) {
out := term.MustExec("break main.main")
position1 := strings.Split(out, " set at ")[1]
term.MustExec("continue")
term.MustExec("clear 1")
out = term.MustExec("break +0")
position2 := strings.Split(out, " set at ")[1]
if position1 != position2 {
t.Fatalf("mismatched positions %q and %q\n", position1, position2)
}
})
}

0 comments on commit d15c86e

Please sign in to comment.