From bb48ad52d3f1e97d019d79162ac386a19a3a6f6a Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Tue, 28 Apr 2015 09:01:28 -0500 Subject: [PATCH] Move generic register structs/funcs to own file --- proctl/registers.go | 31 +++++++++++++++++++++++++++++++ proctl/threads.go | 28 ---------------------------- 2 files changed, 31 insertions(+), 28 deletions(-) create mode 100644 proctl/registers.go diff --git a/proctl/registers.go b/proctl/registers.go new file mode 100644 index 00000000..ab9f2700 --- /dev/null +++ b/proctl/registers.go @@ -0,0 +1,31 @@ +package proctl + +import "fmt" + +// An interface for a generic register type. The +// interface encapsulates the generic values / actions +// we need independant of arch. The concrete register types +// will be different depending on OS/Arch. +type Registers interface { + PC() uint64 + SP() uint64 + SetPC(*ThreadContext, uint64) error +} + +// Obtains register values from the debugged process. +func (thread *ThreadContext) Registers() (Registers, error) { + regs, err := registers(thread) + if err != nil { + return nil, fmt.Errorf("could not get registers: %s", err) + } + return regs, nil +} + +// Returns the current PC for this thread. +func (thread *ThreadContext) PC() (uint64, error) { + regs, err := thread.Registers() + if err != nil { + return 0, err + } + return regs.PC(), nil +} diff --git a/proctl/threads.go b/proctl/threads.go index 1e9a0f6c..b5c4ebb4 100644 --- a/proctl/threads.go +++ b/proctl/threads.go @@ -23,34 +23,6 @@ type ThreadContext struct { os *OSSpecificDetails } -// An interface for a generic register type. The -// interface encapsulates the generic values / actions -// we need independant of arch. The concrete register types -// will be different depending on OS/Arch. -type Registers interface { - PC() uint64 - SP() uint64 - SetPC(*ThreadContext, uint64) error -} - -// Obtains register values from the debugged process. -func (thread *ThreadContext) Registers() (Registers, error) { - regs, err := registers(thread) - if err != nil { - return nil, fmt.Errorf("could not get registers: %s", err) - } - return regs, nil -} - -// Returns the current PC for this thread. -func (thread *ThreadContext) PC() (uint64, error) { - regs, err := thread.Registers() - if err != nil { - return 0, err - } - return regs.PC(), nil -} - // Continue the execution of this thread. This method takes // software breakpoints into consideration and ensures that // we step over any breakpoints. It will restore the instruction,