mirror of
https://github.com/go-delve/delve.git
synced 2025-10-27 20:23:41 +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
|
return bp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
f, l, fn, originalData, err := t.proc.WriteBreakpoint(addr)
|
f, l, fn := t.BinInfo().PCToLine(uint64(addr))
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
fnName := ""
|
fnName := ""
|
||||||
if fn != nil {
|
if fn != nil {
|
||||||
@ -279,10 +276,14 @@ func (t *Target) SetBreakpoint(addr uint64, kind BreakpointKind, cond ast.Expr)
|
|||||||
Line: l,
|
Line: l,
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Kind: kind,
|
Kind: kind,
|
||||||
OriginalData: originalData,
|
|
||||||
HitCount: map[int]uint64{},
|
HitCount: map[int]uint64{},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err := t.proc.WriteBreakpoint(newBreakpoint)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if kind != UserBreakpoint {
|
if kind != UserBreakpoint {
|
||||||
bpmap.internalBreakpointIDCounter++
|
bpmap.internalBreakpointIDCounter++
|
||||||
newBreakpoint.LogicalID = bpmap.internalBreakpointIDCounter
|
newBreakpoint.LogicalID = bpmap.internalBreakpointIDCounter
|
||||||
|
|||||||
@ -231,8 +231,8 @@ func (p *process) EntryPoint() (uint64, error) {
|
|||||||
|
|
||||||
// WriteBreakpoint is a noop function since you
|
// WriteBreakpoint is a noop function since you
|
||||||
// cannot write breakpoints into core files.
|
// cannot write breakpoints into core files.
|
||||||
func (p *process) WriteBreakpoint(addr uint64) (file string, line int, fn *proc.Function, originalData []byte, err error) {
|
func (p *process) WriteBreakpoint(*proc.Breakpoint) error {
|
||||||
return "", 0, nil, nil, errors.New("cannot write a breakpoint to a core file")
|
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.
|
// 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
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *gdbProcess) WriteBreakpoint(addr uint64) (string, int, *proc.Function, []byte, error) {
|
func (p *gdbProcess) WriteBreakpoint(bp *proc.Breakpoint) error {
|
||||||
f, l, fn := p.bi.PCToLine(uint64(addr))
|
return p.conn.setBreakpoint(bp.Addr)
|
||||||
|
|
||||||
if err := p.conn.setBreakpoint(addr); err != nil {
|
|
||||||
return "", 0, nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return f, l, fn, nil, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *gdbProcess) EraseBreakpoint(bp *proc.Breakpoint) error {
|
func (p *gdbProcess) EraseBreakpoint(bp *proc.Breakpoint) error {
|
||||||
|
|||||||
@ -33,7 +33,7 @@ type ProcessInternal interface {
|
|||||||
Detach(bool) error
|
Detach(bool) error
|
||||||
ContinueOnce() (trapthread Thread, stopReason StopReason, err 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
|
EraseBreakpoint(*Breakpoint) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -203,19 +203,13 @@ func (dbp *nativeProcess) CheckAndClearManualStopRequest() bool {
|
|||||||
return msr
|
return msr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dbp *nativeProcess) WriteBreakpoint(addr uint64) (string, int, *proc.Function, []byte, error) {
|
func (dbp *nativeProcess) WriteBreakpoint(bp *proc.Breakpoint) error {
|
||||||
f, l, fn := dbp.bi.PCToLine(uint64(addr))
|
bp.OriginalData = make([]byte, dbp.bi.Arch.BreakpointSize())
|
||||||
|
_, err := dbp.memthread.ReadMemory(bp.OriginalData, bp.Addr)
|
||||||
originalData := make([]byte, dbp.bi.Arch.BreakpointSize())
|
|
||||||
_, err := dbp.memthread.ReadMemory(originalData, addr)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, nil, nil, err
|
return err
|
||||||
}
|
}
|
||||||
if err := dbp.writeSoftwareBreakpoint(dbp.memthread, addr); err != nil {
|
return dbp.writeSoftwareBreakpoint(dbp.memthread, bp.Addr)
|
||||||
return "", 0, nil, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return f, l, fn, originalData, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dbp *nativeProcess) EraseBreakpoint(bp *proc.Breakpoint) error {
|
func (dbp *nativeProcess) EraseBreakpoint(bp *proc.Breakpoint) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user