From fa62905a7e68f1a566d56c4bafd5820bf7eff515 Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Wed, 14 Jan 2015 17:36:35 -0600 Subject: [PATCH] Remove slight duplication --- proctl/breakpoints_linux_amd64.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/proctl/breakpoints_linux_amd64.go b/proctl/breakpoints_linux_amd64.go index 81a9c089..62b59b17 100644 --- a/proctl/breakpoints_linux_amd64.go +++ b/proctl/breakpoints_linux_amd64.go @@ -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 -- GitLab