mirror of
https://github.com/go-delve/delve.git
synced 2025-10-28 04:35:19 +08:00
proc: refactor common code in WriteBreakpoint (#2300)
Moves common backend code in WriteBreakpoint to proc.(*Target).SetBreakpoint.
This commit is contained in:
committed by
GitHub
parent
f5d5a681d0
commit
c40774d3d4
@ -263,10 +263,7 @@ func (t *Target) SetBreakpoint(addr uint64, kind BreakpointKind, cond ast.Expr)
|
||||
return bp, nil
|
||||
}
|
||||
|
||||
f, l, fn, originalData, err := t.proc.WriteBreakpoint(addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, l, fn := t.BinInfo().PCToLine(uint64(addr))
|
||||
|
||||
fnName := ""
|
||||
if fn != nil {
|
||||
@ -279,10 +276,14 @@ func (t *Target) SetBreakpoint(addr uint64, kind BreakpointKind, cond ast.Expr)
|
||||
Line: l,
|
||||
Addr: addr,
|
||||
Kind: kind,
|
||||
OriginalData: originalData,
|
||||
HitCount: map[int]uint64{},
|
||||
}
|
||||
|
||||
err := t.proc.WriteBreakpoint(newBreakpoint)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if kind != UserBreakpoint {
|
||||
bpmap.internalBreakpointIDCounter++
|
||||
newBreakpoint.LogicalID = bpmap.internalBreakpointIDCounter
|
||||
|
||||
@ -231,8 +231,8 @@ func (p *process) EntryPoint() (uint64, error) {
|
||||
|
||||
// WriteBreakpoint is a noop function since you
|
||||
// cannot write breakpoints into core files.
|
||||
func (p *process) WriteBreakpoint(addr uint64) (file string, line int, fn *proc.Function, originalData []byte, err error) {
|
||||
return "", 0, nil, nil, errors.New("cannot write a breakpoint to a core file")
|
||||
func (p *process) WriteBreakpoint(*proc.Breakpoint) error {
|
||||
return errors.New("cannot write a breakpoint to a core file")
|
||||
}
|
||||
|
||||
// Recorded returns whether this is a live or recorded process. Always returns true for core files.
|
||||
|
||||
@ -1171,14 +1171,8 @@ func (p *gdbProcess) FindBreakpoint(pc uint64) (*proc.Breakpoint, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
func (p *gdbProcess) WriteBreakpoint(addr uint64) (string, int, *proc.Function, []byte, error) {
|
||||
f, l, fn := p.bi.PCToLine(uint64(addr))
|
||||
|
||||
if err := p.conn.setBreakpoint(addr); err != nil {
|
||||
return "", 0, nil, nil, err
|
||||
}
|
||||
|
||||
return f, l, fn, nil, nil
|
||||
func (p *gdbProcess) WriteBreakpoint(bp *proc.Breakpoint) error {
|
||||
return p.conn.setBreakpoint(bp.Addr)
|
||||
}
|
||||
|
||||
func (p *gdbProcess) EraseBreakpoint(bp *proc.Breakpoint) error {
|
||||
|
||||
@ -33,7 +33,7 @@ type ProcessInternal interface {
|
||||
Detach(bool) error
|
||||
ContinueOnce() (trapthread Thread, stopReason StopReason, err error)
|
||||
|
||||
WriteBreakpoint(addr uint64) (file string, line int, fn *Function, originalData []byte, err error)
|
||||
WriteBreakpoint(*Breakpoint) error
|
||||
EraseBreakpoint(*Breakpoint) error
|
||||
}
|
||||
|
||||
|
||||
@ -203,19 +203,13 @@ func (dbp *nativeProcess) CheckAndClearManualStopRequest() bool {
|
||||
return msr
|
||||
}
|
||||
|
||||
func (dbp *nativeProcess) WriteBreakpoint(addr uint64) (string, int, *proc.Function, []byte, error) {
|
||||
f, l, fn := dbp.bi.PCToLine(uint64(addr))
|
||||
|
||||
originalData := make([]byte, dbp.bi.Arch.BreakpointSize())
|
||||
_, err := dbp.memthread.ReadMemory(originalData, addr)
|
||||
func (dbp *nativeProcess) WriteBreakpoint(bp *proc.Breakpoint) error {
|
||||
bp.OriginalData = make([]byte, dbp.bi.Arch.BreakpointSize())
|
||||
_, err := dbp.memthread.ReadMemory(bp.OriginalData, bp.Addr)
|
||||
if err != nil {
|
||||
return "", 0, nil, nil, err
|
||||
return err
|
||||
}
|
||||
if err := dbp.writeSoftwareBreakpoint(dbp.memthread, addr); err != nil {
|
||||
return "", 0, nil, nil, err
|
||||
}
|
||||
|
||||
return f, l, fn, originalData, nil
|
||||
return dbp.writeSoftwareBreakpoint(dbp.memthread, bp.Addr)
|
||||
}
|
||||
|
||||
func (dbp *nativeProcess) EraseBreakpoint(bp *proc.Breakpoint) error {
|
||||
|
||||
Reference in New Issue
Block a user