Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debugger: inline clearBreakpoint, createLogicalBreakpoint #3389

Merged
merged 1 commit into from
May 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 29 additions & 43 deletions service/debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,42 +732,7 @@ func (d *Debugger) CreateBreakpoint(requestedBp *api.Breakpoint, locExpr string,
return locs[0].PCs
}
}
createdBp, err := createLogicalBreakpoint(d, requestedBp, &setbp, suspended)

if err != nil {
return nil, err
}
d.log.Infof("created breakpoint: %#v", createdBp)
return createdBp, nil
}

func (d *Debugger) convertBreakpoint(lbp *proc.LogicalBreakpoint) *api.Breakpoint {
abp := api.ConvertLogicalBreakpoint(lbp)
bps := []*proc.Breakpoint{}
pids := []int{}
t := proc.ValidTargets{Group: d.target}
for t.Next() {
for _, bp := range t.Breakpoints().M {
if bp.LogicalID() == lbp.LogicalID {
bps = append(bps, bp)
pids = append(pids, t.Pid())
}
}
}
api.ConvertPhysicalBreakpoints(abp, pids, bps)
return abp
}

func (d *Debugger) ConvertThreadBreakpoint(thread proc.Thread) *api.Breakpoint {
if b := thread.Breakpoint(); b.Active && b.Breakpoint.Logical != nil {
return d.convertBreakpoint(b.Breakpoint.Logical)
}
return nil
}

// createLogicalBreakpoint creates one physical breakpoint for each address
// in addrs and associates all of them with the same logical breakpoint.
func createLogicalBreakpoint(d *Debugger, requestedBp *api.Breakpoint, setbp *proc.SetBreakpoint, suspended bool) (*api.Breakpoint, error) {
id := requestedBp.ID

if id <= 0 {
Expand All @@ -780,12 +745,12 @@ func createLogicalBreakpoint(d *Debugger, requestedBp *api.Breakpoint, setbp *pr
lbp := &proc.LogicalBreakpoint{LogicalID: id, HitCount: make(map[int64]uint64), Enabled: true}
d.target.LogicalBreakpoints[id] = lbp

err := copyLogicalBreakpointInfo(lbp, requestedBp)
err = copyLogicalBreakpointInfo(lbp, requestedBp)
if err != nil {
return nil, err
}

lbp.Set = *setbp
lbp.Set = setbp

if lbp.Set.Expr != nil {
addrs := lbp.Set.Expr(d.Target())
Expand All @@ -809,7 +774,33 @@ func createLogicalBreakpoint(d *Debugger, requestedBp *api.Breakpoint, setbp *pr
}
}

return d.convertBreakpoint(lbp), nil
createdBp := d.convertBreakpoint(lbp)
d.log.Infof("created breakpoint: %#v", createdBp)
return createdBp, nil
}

func (d *Debugger) convertBreakpoint(lbp *proc.LogicalBreakpoint) *api.Breakpoint {
abp := api.ConvertLogicalBreakpoint(lbp)
bps := []*proc.Breakpoint{}
pids := []int{}
t := proc.ValidTargets{Group: d.target}
for t.Next() {
for _, bp := range t.Breakpoints().M {
if bp.LogicalID() == lbp.LogicalID {
bps = append(bps, bp)
pids = append(pids, t.Pid())
}
}
}
api.ConvertPhysicalBreakpoints(abp, pids, bps)
return abp
}

func (d *Debugger) ConvertThreadBreakpoint(thread proc.Thread) *api.Breakpoint {
if b := thread.Breakpoint(); b.Active && b.Breakpoint.Logical != nil {
return d.convertBreakpoint(b.Breakpoint.Logical)
}
return nil
}

func (d *Debugger) CreateEBPFTracepoint(fnName string) error {
Expand Down Expand Up @@ -970,11 +961,6 @@ func parseHitCondition(hitCond string) (token.Token, int, error) {
func (d *Debugger) ClearBreakpoint(requestedBp *api.Breakpoint) (*api.Breakpoint, error) {
d.targetMutex.Lock()
defer d.targetMutex.Unlock()
return d.clearBreakpoint(requestedBp)
}

// clearBreakpoint clears a breakpoint, we can consume this function to avoid locking a goroutine
func (d *Debugger) clearBreakpoint(requestedBp *api.Breakpoint) (*api.Breakpoint, error) {
if requestedBp.ID <= 0 {
if len(d.target.Targets()) != 1 {
return nil, ErrNotImplementedWithMultitarget
Expand Down