Remove slight duplication

This commit is contained in:
Derek Parker 2015-01-14 17:36:35 -06:00
parent bcc4943abd
commit fa62905a7e

@ -77,14 +77,7 @@ func (dbp *DebuggedProcess) setBreakpoint(tid int, addr uint64) (*BreakPoint, er
if err != nil {
return nil, fmt.Errorf("could not set hardware breakpoint")
}
dbp.breakpointIDCounter++
dbp.HWBreakPoints[i] = &BreakPoint{
FunctionName: fn.Name,
File: f,
Line: l,
Addr: addr,
ID: dbp.breakpointIDCounter,
}
dbp.HWBreakPoints[i] = dbp.newBreakpoint(fn.Name, f, l, addr, nil)
return dbp.HWBreakPoints[i], nil
}
}
@ -98,15 +91,7 @@ func (dbp *DebuggedProcess) setBreakpoint(tid int, addr uint64) (*BreakPoint, er
if err != nil {
return nil, err
}
dbp.breakpointIDCounter++
dbp.BreakPoints[addr] = &BreakPoint{
FunctionName: fn.Name,
File: f,
Line: l,
Addr: addr,
OriginalData: originalData,
ID: dbp.breakpointIDCounter,
}
dbp.BreakPoints[addr] = dbp.newBreakpoint(fn.Name, f, l, addr, originalData)
return dbp.BreakPoints[addr], nil
}
@ -132,6 +117,18 @@ func (dbp *DebuggedProcess) clearBreakpoint(tid int, addr uint64) (*BreakPoint,
return nil, fmt.Errorf("No breakpoint currently set for %#v", addr)
}
func (dbp *DebuggedProcess) newBreakpoint(fn, f string, l int, addr uint64, data []byte) *BreakPoint {
dbp.breakpointIDCounter++
return &BreakPoint{
FunctionName: fn,
File: f,
Line: l,
Addr: addr,
OriginalData: data,
ID: dbp.breakpointIDCounter,
}
}
// Sets a hardware breakpoint by setting the contents of the
// debug register `reg` with the address of the instruction
// that we want to break at. There are only 4 debug registers