提交 794d5b1e 编写于 作者: D Derek Parker

Revert errors.New change

上级 0358c174
...@@ -4,7 +4,6 @@ package command ...@@ -4,7 +4,6 @@ package command
import ( import (
"bufio" "bufio"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
...@@ -104,7 +103,7 @@ func CommandFunc(fn func() error) cmdfunc { ...@@ -104,7 +103,7 @@ func CommandFunc(fn func() error) cmdfunc {
} }
func noCmdAvailable(p *proctl.DebuggedProcess, args ...string) error { func noCmdAvailable(p *proctl.DebuggedProcess, args ...string) error {
return errors.New("command not available") return fmt.Errorf("command not available")
} }
func nullCommand(p *proctl.DebuggedProcess, args ...string) error { func nullCommand(p *proctl.DebuggedProcess, args ...string) error {
...@@ -141,7 +140,7 @@ func threads(p *proctl.DebuggedProcess, args ...string) error { ...@@ -141,7 +140,7 @@ func threads(p *proctl.DebuggedProcess, args ...string) error {
func thread(p *proctl.DebuggedProcess, args ...string) error { func thread(p *proctl.DebuggedProcess, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return errors.New("you must specify a thread") return fmt.Errorf("you must specify a thread")
} }
oldTid := p.CurrentThread.Id oldTid := p.CurrentThread.Id
tid, err := strconv.Atoi(args[0]) tid, err := strconv.Atoi(args[0])
...@@ -205,7 +204,7 @@ func next(p *proctl.DebuggedProcess, args ...string) error { ...@@ -205,7 +204,7 @@ func next(p *proctl.DebuggedProcess, args ...string) error {
func clear(p *proctl.DebuggedProcess, args ...string) error { func clear(p *proctl.DebuggedProcess, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return errors.New("not enough arguments") return fmt.Errorf("not enough arguments")
} }
bp, err := p.ClearByLocation(args[0]) bp, err := p.ClearByLocation(args[0])
...@@ -251,7 +250,7 @@ func breakpoints(p *proctl.DebuggedProcess, args ...string) error { ...@@ -251,7 +250,7 @@ func breakpoints(p *proctl.DebuggedProcess, args ...string) error {
func breakpoint(p *proctl.DebuggedProcess, args ...string) error { func breakpoint(p *proctl.DebuggedProcess, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return errors.New("not enough arguments") return fmt.Errorf("not enough arguments")
} }
bp, err := p.BreakByLocation(args[0]) bp, err := p.BreakByLocation(args[0])
...@@ -266,7 +265,7 @@ func breakpoint(p *proctl.DebuggedProcess, args ...string) error { ...@@ -266,7 +265,7 @@ func breakpoint(p *proctl.DebuggedProcess, args ...string) error {
func printVar(p *proctl.DebuggedProcess, args ...string) error { func printVar(p *proctl.DebuggedProcess, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return errors.New("not enough arguments") return fmt.Errorf("not enough arguments")
} }
val, err := p.EvalSymbol(args[0]) val, err := p.EvalSymbol(args[0])
...@@ -293,7 +292,7 @@ func filterVariables(vars []*proctl.Variable, filter *regexp.Regexp) []string { ...@@ -293,7 +292,7 @@ func filterVariables(vars []*proctl.Variable, filter *regexp.Regexp) []string {
func info(p *proctl.DebuggedProcess, args ...string) error { func info(p *proctl.DebuggedProcess, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return errors.New("not enough arguments. expected info type [regex].") return fmt.Errorf("not enough arguments. expected info type [regex].")
} }
// Allow for optional regex // Allow for optional regex
...@@ -346,7 +345,7 @@ func info(p *proctl.DebuggedProcess, args ...string) error { ...@@ -346,7 +345,7 @@ func info(p *proctl.DebuggedProcess, args ...string) error {
data = filterVariables(vars, filter) data = filterVariables(vars, filter)
default: default:
return errors.New("unsupported info type, must be args, funcs, locals, sources, or vars") return fmt.Errorf("unsupported info type, must be args, funcs, locals, sources, or vars")
} }
// sort and output data // sort and output data
......
...@@ -2,7 +2,7 @@ package reader ...@@ -2,7 +2,7 @@ package reader
import ( import (
"debug/dwarf" "debug/dwarf"
"errors" "fmt"
) )
type Reader struct { type Reader struct {
...@@ -57,7 +57,7 @@ func (reader *Reader) SeekToFunction(pc uint64) (*dwarf.Entry, error) { ...@@ -57,7 +57,7 @@ func (reader *Reader) SeekToFunction(pc uint64) (*dwarf.Entry, error) {
} }
} }
return nil, errors.New("unable to find function context") return nil, fmt.Errorf("unable to find function context")
} }
// SeekToType moves the reader to the type specified by the entry, // SeekToType moves the reader to the type specified by the entry,
...@@ -66,7 +66,7 @@ func (reader *Reader) SeekToFunction(pc uint64) (*dwarf.Entry, error) { ...@@ -66,7 +66,7 @@ func (reader *Reader) SeekToFunction(pc uint64) (*dwarf.Entry, error) {
func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resolvePointerTypes bool) (*dwarf.Entry, error) { func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resolvePointerTypes bool) (*dwarf.Entry, error) {
offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset) offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset)
if !ok { if !ok {
return nil, errors.New("entry does not have a type attribute") return nil, fmt.Errorf("entry does not have a type attribute")
} }
// Seek to the first type offset // Seek to the first type offset
...@@ -94,7 +94,7 @@ func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resol ...@@ -94,7 +94,7 @@ func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resol
reader.Seek(offset) reader.Seek(offset)
} }
return nil, errors.New("no type entry found") return nil, fmt.Errorf("no type entry found")
} }
// NextScopeVariable moves the reader to the next debug entry that describes a local variable and returns the entry. // NextScopeVariable moves the reader to the next debug entry that describes a local variable and returns the entry.
......
package proctl package proctl
import "errors" import "fmt"
// TODO(darwin) // TODO(darwin)
func setHardwareBreakpoint(reg, tid int, addr uint64) error { func setHardwareBreakpoint(reg, tid int, addr uint64) error {
return errors.New("not implemented on darwin") return fmt.Errorf("not implemented on darwin")
} }
// TODO(darwin) // TODO(darwin)
func clearHardwareBreakpoint(reg, tid int) error { func clearHardwareBreakpoint(reg, tid int) error {
return errors.New("not implemented on darwin") return fmt.Errorf("not implemented on darwin")
} }
...@@ -15,10 +15,7 @@ int offset(int reg) { ...@@ -15,10 +15,7 @@ int offset(int reg) {
*/ */
import "C" import "C"
import ( import "fmt"
"errors"
"fmt"
)
// Sets a hardware breakpoint by setting the contents of the // Sets a hardware breakpoint by setting the contents of the
// debug register `reg` with the address of the instruction // debug register `reg` with the address of the instruction
...@@ -26,7 +23,7 @@ import ( ...@@ -26,7 +23,7 @@ import (
// DR0-DR3. Debug register 7 is the control register. // DR0-DR3. Debug register 7 is the control register.
func setHardwareBreakpoint(reg, tid int, addr uint64) error { func setHardwareBreakpoint(reg, tid int, addr uint64) error {
if reg < 0 || reg > 3 { if reg < 0 || reg > 3 {
return errors.New("invalid debug register value") return fmt.Errorf("invalid debug register value")
} }
var ( var (
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"debug/dwarf" "debug/dwarf"
"debug/gosym" "debug/gosym"
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
...@@ -583,7 +582,7 @@ func (dbp *DebuggedProcess) handleBreakpointOnThread(id int) (*ThreadContext, er ...@@ -583,7 +582,7 @@ func (dbp *DebuggedProcess) handleBreakpointOnThread(id int) (*ThreadContext, er
func (dbp *DebuggedProcess) run(fn func() error) error { func (dbp *DebuggedProcess) run(fn func() error) error {
if dbp.exited { if dbp.exited {
return errors.New("process has already exited") return fmt.Errorf("process has already exited")
} }
dbp.running = true dbp.running = true
dbp.halt = false dbp.halt = false
......
...@@ -6,7 +6,6 @@ import "C" ...@@ -6,7 +6,6 @@ import "C"
import ( import (
"debug/gosym" "debug/gosym"
"debug/macho" "debug/macho"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
...@@ -50,7 +49,7 @@ func Launch(cmd []string) (*DebuggedProcess, error) { ...@@ -50,7 +49,7 @@ func Launch(cmd []string) (*DebuggedProcess, error) {
pid := int(C.fork_exec(C.CString(argv0), &argv, &dbp.os.task, &dbp.os.portSet, &dbp.os.exceptionPort, &dbp.os.notificationPort)) pid := int(C.fork_exec(C.CString(argv0), &argv, &dbp.os.task, &dbp.os.portSet, &dbp.os.exceptionPort, &dbp.os.notificationPort))
if pid <= 0 { if pid <= 0 {
return nil, errors.New("could not fork/exec") return nil, fmt.Errorf("could not fork/exec")
} }
dbp.Pid = pid dbp.Pid = pid
...@@ -70,7 +69,7 @@ func (dbp *DebuggedProcess) requestManualStop() (err error) { ...@@ -70,7 +69,7 @@ func (dbp *DebuggedProcess) requestManualStop() (err error) {
) )
kret := C.raise_exception(task, thread, exceptionPort, C.EXC_BREAKPOINT) kret := C.raise_exception(task, thread, exceptionPort, C.EXC_BREAKPOINT)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return errors.New("could not raise mach exception") return fmt.Errorf("could not raise mach exception")
} }
return nil return nil
} }
...@@ -82,7 +81,7 @@ func (dbp *DebuggedProcess) updateThreadList() error { ...@@ -82,7 +81,7 @@ func (dbp *DebuggedProcess) updateThreadList() error {
count = C.thread_count(C.task_t(dbp.os.task)) count = C.thread_count(C.task_t(dbp.os.task))
) )
if count == -1 { if count == -1 {
return errors.New("could not get thread count") return fmt.Errorf("could not get thread count")
} }
list := make([]uint32, count) list := make([]uint32, count)
...@@ -90,10 +89,10 @@ func (dbp *DebuggedProcess) updateThreadList() error { ...@@ -90,10 +89,10 @@ func (dbp *DebuggedProcess) updateThreadList() error {
// instead of getting count above and passing in a slice // instead of getting count above and passing in a slice
kret = C.get_threads(C.task_t(dbp.os.task), unsafe.Pointer(&list[0])) kret = C.get_threads(C.task_t(dbp.os.task), unsafe.Pointer(&list[0]))
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return errors.New("could not get thread list") return fmt.Errorf("could not get thread list")
} }
if count < 0 { if count < 0 {
return errors.New("could not get thread list") return fmt.Errorf("could not get thread list")
} }
for _, port := range list { for _, port := range list {
...@@ -233,7 +232,7 @@ func (dbp *DebuggedProcess) trapWait(pid int) (*ThreadContext, error) { ...@@ -233,7 +232,7 @@ func (dbp *DebuggedProcess) trapWait(pid int) (*ThreadContext, error) {
} }
return nil, ManualStopError{} return nil, ManualStopError{}
case 0: case 0:
return nil, errors.New("error while waiting for task") return nil, fmt.Errorf("error while waiting for task")
} }
// Since we cannot be notified of new threads on OS X // Since we cannot be notified of new threads on OS X
......
...@@ -2,7 +2,7 @@ package proctl ...@@ -2,7 +2,7 @@ package proctl
// #include "threads_darwin.h" // #include "threads_darwin.h"
import "C" import "C"
import "errors" import "fmt"
type Regs struct { type Regs struct {
pc, sp uint64 pc, sp uint64
...@@ -19,7 +19,7 @@ func (r *Regs) SP() uint64 { ...@@ -19,7 +19,7 @@ func (r *Regs) SP() uint64 {
func (r *Regs) SetPC(thread *ThreadContext, pc uint64) error { func (r *Regs) SetPC(thread *ThreadContext, pc uint64) error {
kret := C.set_pc(thread.os.thread_act, C.uint64_t(pc)) kret := C.set_pc(thread.os.thread_act, C.uint64_t(pc))
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return errors.New("could not set pc") return fmt.Errorf("could not set pc")
} }
return nil return nil
} }
...@@ -28,7 +28,7 @@ func registers(thread *ThreadContext) (Registers, error) { ...@@ -28,7 +28,7 @@ func registers(thread *ThreadContext) (Registers, error) {
var state C.x86_thread_state64_t var state C.x86_thread_state64_t
kret := C.get_registers(C.mach_port_name_t(thread.os.thread_act), &state) kret := C.get_registers(C.mach_port_name_t(thread.os.thread_act), &state)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return nil, errors.New("could not get registers") return nil, fmt.Errorf("could not get registers")
} }
regs := &Regs{pc: uint64(state.__rip), sp: uint64(state.__rsp)} regs := &Regs{pc: uint64(state.__rip), sp: uint64(state.__rsp)}
return regs, nil return regs, nil
......
...@@ -3,7 +3,6 @@ package proctl ...@@ -3,7 +3,6 @@ package proctl
// #include "threads_darwin.h" // #include "threads_darwin.h"
import "C" import "C"
import ( import (
"errors"
"fmt" "fmt"
"unsafe" "unsafe"
) )
...@@ -25,12 +24,12 @@ func (t *ThreadContext) Halt() error { ...@@ -25,12 +24,12 @@ func (t *ThreadContext) Halt() error {
func (t *ThreadContext) singleStep() error { func (t *ThreadContext) singleStep() error {
kret := C.single_step(t.os.thread_act) kret := C.single_step(t.os.thread_act)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return errors.New("could not single step") return fmt.Errorf("could not single step")
} }
t.Process.trapWait(0) t.Process.trapWait(0)
kret = C.clear_trap_flag(t.os.thread_act) kret = C.clear_trap_flag(t.os.thread_act)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return errors.New("could not clear CPU trap flag") return fmt.Errorf("could not clear CPU trap flag")
} }
return nil return nil
} }
...@@ -42,7 +41,7 @@ func (t *ThreadContext) resume() error { ...@@ -42,7 +41,7 @@ func (t *ThreadContext) resume() error {
} }
kret := C.resume_thread(t.os.thread_act) kret := C.resume_thread(t.os.thread_act)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return errors.New("could not continue thread") return fmt.Errorf("could not continue thread")
} }
return nil return nil
} }
...@@ -65,7 +64,7 @@ func writeMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error) ...@@ -65,7 +64,7 @@ func writeMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error)
) )
if ret := C.write_memory(thread.Process.os.task, vm_addr, vm_data, length); ret < 0 { if ret := C.write_memory(thread.Process.os.task, vm_addr, vm_data, length); ret < 0 {
return 0, errors.New("could not write memory") return 0, fmt.Errorf("could not write memory")
} }
return len(data), nil return len(data), nil
} }
...@@ -79,7 +78,7 @@ func readMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error) { ...@@ -79,7 +78,7 @@ func readMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error) {
ret := C.read_memory(thread.Process.os.task, vm_addr, vm_data, length) ret := C.read_memory(thread.Process.os.task, vm_addr, vm_data, length)
if ret < 0 { if ret < 0 {
return 0, errors.New("could not read memory") return 0, fmt.Errorf("could not read memory")
} }
return len(data), nil return len(data), nil
} }
...@@ -87,7 +86,7 @@ func readMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error) { ...@@ -87,7 +86,7 @@ func readMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error) {
func (thread *ThreadContext) saveRegisters() (Registers, error) { func (thread *ThreadContext) saveRegisters() (Registers, error) {
kret := C.get_registers(C.mach_port_name_t(thread.os.thread_act), &thread.os.registers) kret := C.get_registers(C.mach_port_name_t(thread.os.thread_act), &thread.os.registers)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return nil, errors.New("could not save register contents") return nil, fmt.Errorf("could not save register contents")
} }
return &Regs{pc: uint64(thread.os.registers.__rip), sp: uint64(thread.os.registers.__rsp)}, nil return &Regs{pc: uint64(thread.os.registers.__rip), sp: uint64(thread.os.registers.__rsp)}, nil
} }
...@@ -95,7 +94,7 @@ func (thread *ThreadContext) saveRegisters() (Registers, error) { ...@@ -95,7 +94,7 @@ func (thread *ThreadContext) saveRegisters() (Registers, error) {
func (thread *ThreadContext) restoreRegisters() error { func (thread *ThreadContext) restoreRegisters() error {
kret := C.set_registers(C.mach_port_name_t(thread.os.thread_act), &thread.os.registers) kret := C.set_registers(C.mach_port_name_t(thread.os.thread_act), &thread.os.registers)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return errors.New("could not save register contents") return fmt.Errorf("could not save register contents")
} }
return nil return nil
} }
package proctl package proctl
import ( import (
"errors"
"fmt" "fmt"
sys "golang.org/x/sys/unix" sys "golang.org/x/sys/unix"
...@@ -53,7 +52,7 @@ func (t *ThreadContext) blocked() bool { ...@@ -53,7 +52,7 @@ func (t *ThreadContext) blocked() bool {
func (thread *ThreadContext) saveRegisters() (Registers, error) { func (thread *ThreadContext) saveRegisters() (Registers, error) {
if err := sys.PtraceGetRegs(thread.Id, &thread.os.registers); err != nil { if err := sys.PtraceGetRegs(thread.Id, &thread.os.registers); err != nil {
return nil, errors.New("could not save register contents") return nil, fmt.Errorf("could not save register contents")
} }
return &Regs{&thread.os.registers}, nil return &Regs{&thread.os.registers}, nil
} }
......
...@@ -5,7 +5,6 @@ import ( ...@@ -5,7 +5,6 @@ import (
"debug/dwarf" "debug/dwarf"
"debug/gosym" "debug/gosym"
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
...@@ -84,7 +83,7 @@ func (thread *ThreadContext) AllM() ([]*M, error) { ...@@ -84,7 +83,7 @@ func (thread *ThreadContext) AllM() ([]*M, error) {
} }
m := binary.LittleEndian.Uint64(mptr) m := binary.LittleEndian.Uint64(mptr)
if m == 0 { if m == 0 {
return nil, errors.New("allm contains no M pointers") return nil, fmt.Errorf("allm contains no M pointers")
} }
procidInstructions, err := instructionsFor("procid", thread.Process, reader, true) procidInstructions, err := instructionsFor("procid", thread.Process, reader, true)
...@@ -191,7 +190,7 @@ func instructionsForEntry(entry *dwarf.Entry) ([]byte, error) { ...@@ -191,7 +190,7 @@ func instructionsForEntry(entry *dwarf.Entry) ([]byte, error) {
if entry.Tag == dwarf.TagMember { if entry.Tag == dwarf.TagMember {
instructions, ok := entry.Val(dwarf.AttrDataMemberLoc).([]byte) instructions, ok := entry.Val(dwarf.AttrDataMemberLoc).([]byte)
if !ok { if !ok {
return nil, errors.New("member data has no data member location attribute") return nil, fmt.Errorf("member data has no data member location attribute")
} }
// clone slice to prevent stomping on the dwarf data // clone slice to prevent stomping on the dwarf data
return append([]byte{}, instructions...), nil return append([]byte{}, instructions...), nil
...@@ -200,7 +199,7 @@ func instructionsForEntry(entry *dwarf.Entry) ([]byte, error) { ...@@ -200,7 +199,7 @@ func instructionsForEntry(entry *dwarf.Entry) ([]byte, error) {
// non-member // non-member
instructions, ok := entry.Val(dwarf.AttrLocation).([]byte) instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
if !ok { if !ok {
return nil, errors.New("entry has no location attribute") return nil, fmt.Errorf("entry has no location attribute")
} }
// clone slice to prevent stomping on the dwarf data // clone slice to prevent stomping on the dwarf data
...@@ -225,7 +224,7 @@ func parseAllMPtr(dbp *DebuggedProcess, reader *dwarf.Reader) (uint64, error) { ...@@ -225,7 +224,7 @@ func parseAllMPtr(dbp *DebuggedProcess, reader *dwarf.Reader) (uint64, error) {
instructions, ok := entry.Val(dwarf.AttrLocation).([]byte) instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
if !ok { if !ok {
return 0, errors.New("type assertion failed") return 0, fmt.Errorf("type assertion failed")
} }
addr, err := op.ExecuteStackProgram(0, instructions) addr, err := op.ExecuteStackProgram(0, instructions)
if err != nil { if err != nil {
...@@ -321,7 +320,7 @@ func allglenval(dbp *DebuggedProcess, reader *dwarf.Reader) (uint64, error) { ...@@ -321,7 +320,7 @@ func allglenval(dbp *DebuggedProcess, reader *dwarf.Reader) (uint64, error) {
instructions, ok := entry.Val(dwarf.AttrLocation).([]byte) instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
if !ok { if !ok {
return 0, errors.New("type assertion failed") return 0, fmt.Errorf("type assertion failed")
} }
addr, err := op.ExecuteStackProgram(0, instructions) addr, err := op.ExecuteStackProgram(0, instructions)
if err != nil { if err != nil {
...@@ -342,7 +341,7 @@ func addressFor(dbp *DebuggedProcess, name string, reader *dwarf.Reader) (uint64 ...@@ -342,7 +341,7 @@ func addressFor(dbp *DebuggedProcess, name string, reader *dwarf.Reader) (uint64
instructions, ok := entry.Val(dwarf.AttrLocation).([]byte) instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
if !ok { if !ok {
return 0, errors.New("type assertion failed") return 0, fmt.Errorf("type assertion failed")
} }
addr, err := op.ExecuteStackProgram(0, instructions) addr, err := op.ExecuteStackProgram(0, instructions)
if err != nil { if err != nil {
...@@ -359,7 +358,7 @@ func offsetFor(name string, reader *dwarf.Reader, parentinstr []byte) (uint64, e ...@@ -359,7 +358,7 @@ func offsetFor(name string, reader *dwarf.Reader, parentinstr []byte) (uint64, e
} }
instructions, ok := entry.Val(dwarf.AttrDataMemberLoc).([]byte) instructions, ok := entry.Val(dwarf.AttrDataMemberLoc).([]byte)
if !ok { if !ok {
return 0, errors.New("type assertion failed") return 0, fmt.Errorf("type assertion failed")
} }
offset, err := op.ExecuteStackProgram(0, append(parentinstr, instructions...)) offset, err := op.ExecuteStackProgram(0, append(parentinstr, instructions...))
if err != nil { if err != nil {
...@@ -490,7 +489,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read ...@@ -490,7 +489,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read
// Get parent variable name // Get parent variable name
parentName, ok := parentEntry.Val(dwarf.AttrName).(string) parentName, ok := parentEntry.Val(dwarf.AttrName).(string)
if !ok { if !ok {
return nil, errors.New("unable to retrive variable name") return nil, fmt.Errorf("unable to retrive variable name")
} }
// Seek reader to the type information so members can be iterated // Seek reader to the type information so members can be iterated
...@@ -523,7 +522,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read ...@@ -523,7 +522,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read
offset, ok := memberEntry.Val(dwarf.AttrType).(dwarf.Offset) offset, ok := memberEntry.Val(dwarf.AttrType).(dwarf.Offset)
if !ok { if !ok {
return nil, errors.New("type assertion failed") return nil, fmt.Errorf("type assertion failed")
} }
data := thread.Process.dwarf data := thread.Process.dwarf
...@@ -550,7 +549,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read ...@@ -550,7 +549,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read
// Extracts the name, type, and value of a variable from a dwarf entry // Extracts the name, type, and value of a variable from a dwarf entry
func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Variable, error) { func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Variable, error) {
if entry == nil { if entry == nil {
return nil, errors.New("invalid entry") return nil, fmt.Errorf("invalid entry")
} }
if entry.Tag != dwarf.TagFormalParameter && entry.Tag != dwarf.TagVariable { if entry.Tag != dwarf.TagFormalParameter && entry.Tag != dwarf.TagVariable {
...@@ -559,12 +558,12 @@ func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Vari ...@@ -559,12 +558,12 @@ func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Vari
n, ok := entry.Val(dwarf.AttrName).(string) n, ok := entry.Val(dwarf.AttrName).(string)
if !ok { if !ok {
return nil, errors.New("type assertion failed") return nil, fmt.Errorf("type assertion failed")
} }
offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset) offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset)
if !ok { if !ok {
return nil, errors.New("type assertion failed") return nil, fmt.Errorf("type assertion failed")
} }
data := thread.Process.dwarf data := thread.Process.dwarf
...@@ -575,7 +574,7 @@ func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Vari ...@@ -575,7 +574,7 @@ func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Vari
instructions, ok := entry.Val(dwarf.AttrLocation).([]byte) instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
if !ok { if !ok {
return nil, errors.New("type assertion failed") return nil, fmt.Errorf("type assertion failed")
} }
val, err := thread.extractValue(instructions, 0, t, true) val, err := thread.extractValue(instructions, 0, t, true)
...@@ -911,7 +910,7 @@ func (thread *ThreadContext) readFloat(addr uintptr, size int64) (string, error) ...@@ -911,7 +910,7 @@ func (thread *ThreadContext) readFloat(addr uintptr, size int64) (string, error)
return strconv.FormatFloat(n, 'f', -1, int(size)*8), nil return strconv.FormatFloat(n, 'f', -1, int(size)*8), nil
} }
return "", errors.New("could not read float") return "", fmt.Errorf("could not read float")
} }
func (thread *ThreadContext) readBool(addr uintptr) (string, error) { func (thread *ThreadContext) readBool(addr uintptr) (string, error) {
......
package proctl package proctl
import ( import (
"errors" "fmt"
"path/filepath" "path/filepath"
"sort" "sort"
"testing" "testing"
...@@ -56,8 +56,8 @@ func TestVariableEvaluation(t *testing.T) { ...@@ -56,8 +56,8 @@ func TestVariableEvaluation(t *testing.T) {
{"a6.Baz", "8", "int", nil}, {"a6.Baz", "8", "int", nil},
{"a7.Baz", "5", "int", nil}, {"a7.Baz", "5", "int", nil},
{"a8.Baz", "feh", "struct string", nil}, {"a8.Baz", "feh", "struct string", nil},
{"a9.Baz", "nil", "int", errors.New("a9 is nil")}, {"a9.Baz", "nil", "int", fmt.Errorf("a9 is nil")},
{"a9.NonExistent", "nil", "int", errors.New("a9 has no member NonExistent")}, {"a9.NonExistent", "nil", "int", fmt.Errorf("a9 has no member NonExistent")},
{"a8", "main.FooBar2 {Bur: 10, Baz: feh}", "main.FooBar2", nil}, // reread variable after member {"a8", "main.FooBar2 {Bur: 10, Baz: feh}", "main.FooBar2", nil}, // reread variable after member
{"i32", "[2]int32 [1,2]", "[2]int32", nil}, {"i32", "[2]int32 [1,2]", "[2]int32", nil},
{"b1", "true", "bool", nil}, {"b1", "true", "bool", nil},
...@@ -70,7 +70,7 @@ func TestVariableEvaluation(t *testing.T) { ...@@ -70,7 +70,7 @@ func TestVariableEvaluation(t *testing.T) {
{"f", "main.barfoo", "func()", nil}, {"f", "main.barfoo", "func()", nil},
{"ba", "[]int len: 200, cap: 200, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,...+136 more]", "struct []int", nil}, {"ba", "[]int len: 200, cap: 200, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,...+136 more]", "struct []int", nil},
{"ms", "main.Nest {Level: 0, Nest: *main.Nest {Level: 1, Nest: *main.Nest {...}}}", "main.Nest", nil}, {"ms", "main.Nest {Level: 0, Nest: *main.Nest {Level: 1, Nest: *main.Nest {...}}}", "main.Nest", nil},
{"NonExistent", "", "", errors.New("could not find symbol value for NonExistent")}, {"NonExistent", "", "", fmt.Errorf("could not find symbol value for NonExistent")},
} }
withTestProcess(executablePath, t, func(p *DebuggedProcess) { withTestProcess(executablePath, t, func(p *DebuggedProcess) {
......
package debugger package debugger
import ( import (
"errors"
"fmt" "fmt"
"log" "log"
"regexp" "regexp"
...@@ -66,7 +65,7 @@ func New(config *Config) *Debugger { ...@@ -66,7 +65,7 @@ func New(config *Config) *Debugger {
// operation. // operation.
func (d *Debugger) withProcess(f func(*proctl.DebuggedProcess) error) error { func (d *Debugger) withProcess(f func(*proctl.DebuggedProcess) error) error {
if !d.running { if !d.running {
return errors.New("debugger isn't running") return fmt.Errorf("debugger isn't running")
} }
result := make(chan error) result := make(chan error)
...@@ -162,7 +161,7 @@ func (d *Debugger) Run() error { ...@@ -162,7 +161,7 @@ func (d *Debugger) Run() error {
// Detach stops the debugger. // Detach stops the debugger.
func (d *Debugger) Detach(kill bool) error { func (d *Debugger) Detach(kill bool) error {
if !d.running { if !d.running {
return errors.New("debugger isn't running") return fmt.Errorf("debugger isn't running")
} }
d.stop <- stopSignal{KillProcess: kill} d.stop <- stopSignal{KillProcess: kill}
...@@ -206,7 +205,7 @@ func (d *Debugger) CreateBreakPoint(requestedBp *api.BreakPoint) (*api.BreakPoin ...@@ -206,7 +205,7 @@ func (d *Debugger) CreateBreakPoint(requestedBp *api.BreakPoint) (*api.BreakPoin
case len(requestedBp.FunctionName) > 0: case len(requestedBp.FunctionName) > 0:
loc = requestedBp.FunctionName loc = requestedBp.FunctionName
default: default:
return errors.New("no file or function name specified") return fmt.Errorf("no file or function name specified")
} }
bp, breakError := p.BreakByLocation(loc) bp, breakError := p.BreakByLocation(loc)
......
...@@ -4,7 +4,6 @@ package terminal ...@@ -4,7 +4,6 @@ package terminal
import ( import (
"bufio" "bufio"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
...@@ -107,7 +106,7 @@ func CommandFunc(fn func() error) cmdfunc { ...@@ -107,7 +106,7 @@ func CommandFunc(fn func() error) cmdfunc {
} }
func noCmdAvailable(client service.Client, args ...string) error { func noCmdAvailable(client service.Client, args ...string) error {
return errors.New("command not available") return fmt.Errorf("command not available")
} }
func nullCommand(client service.Client, args ...string) error { func nullCommand(client service.Client, args ...string) error {
...@@ -221,7 +220,7 @@ func next(client service.Client, args ...string) error { ...@@ -221,7 +220,7 @@ func next(client service.Client, args ...string) error {
func clear(client service.Client, args ...string) error { func clear(client service.Client, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return errors.New("not enough arguments") return fmt.Errorf("not enough arguments")
} }
id, err := strconv.Atoi(args[0]) id, err := strconv.Atoi(args[0])
...@@ -273,7 +272,7 @@ func breakpoints(client service.Client, args ...string) error { ...@@ -273,7 +272,7 @@ func breakpoints(client service.Client, args ...string) error {
func breakpoint(client service.Client, args ...string) error { func breakpoint(client service.Client, args ...string) error {
if len(args) != 1 { if len(args) != 1 {
return errors.New("argument must be either a function name or <file:line>") return fmt.Errorf("argument must be either a function name or <file:line>")
} }
requestedBp := &api.BreakPoint{} requestedBp := &api.BreakPoint{}
tokens := strings.Split(args[0], ":") tokens := strings.Split(args[0], ":")
...@@ -289,7 +288,7 @@ func breakpoint(client service.Client, args ...string) error { ...@@ -289,7 +288,7 @@ func breakpoint(client service.Client, args ...string) error {
requestedBp.File = file requestedBp.File = file
requestedBp.Line = line requestedBp.Line = line
default: default:
return errors.New("invalid line reference") return fmt.Errorf("invalid line reference")
} }
bp, err := client.CreateBreakPoint(requestedBp) bp, err := client.CreateBreakPoint(requestedBp)
...@@ -303,7 +302,7 @@ func breakpoint(client service.Client, args ...string) error { ...@@ -303,7 +302,7 @@ func breakpoint(client service.Client, args ...string) error {
func printVar(client service.Client, args ...string) error { func printVar(client service.Client, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return errors.New("not enough arguments") return fmt.Errorf("not enough arguments")
} }
val, err := client.EvalSymbol(args[0]) val, err := client.EvalSymbol(args[0])
...@@ -327,7 +326,7 @@ func filterVariables(vars []api.Variable, filter *regexp.Regexp) []string { ...@@ -327,7 +326,7 @@ func filterVariables(vars []api.Variable, filter *regexp.Regexp) []string {
func info(client service.Client, args ...string) error { func info(client service.Client, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return errors.New("not enough arguments. expected info type [regex].") return fmt.Errorf("not enough arguments. expected info type [regex].")
} }
// Allow for optional regex // Allow for optional regex
...@@ -398,7 +397,7 @@ func info(client service.Client, args ...string) error { ...@@ -398,7 +397,7 @@ func info(client service.Client, args ...string) error {
} }
default: default:
return errors.New("unsupported info type, must be args, funcs, locals, sources, or vars") return fmt.Errorf("unsupported info type, must be args, funcs, locals, sources, or vars")
} }
// sort and output data // sort and output data
......
package terminal package terminal
import ( import (
"errors" "fmt"
"testing" "testing"
"github.com/derekparker/delve/service" "github.com/derekparker/delve/service"
...@@ -25,7 +25,7 @@ func TestCommandDefault(t *testing.T) { ...@@ -25,7 +25,7 @@ func TestCommandDefault(t *testing.T) {
func TestCommandReplay(t *testing.T) { func TestCommandReplay(t *testing.T) {
cmds := DebugCommands(nil) cmds := DebugCommands(nil)
cmds.Register("foo", func(client service.Client, args ...string) error { return errors.New("registered command") }, "foo command") cmds.Register("foo", func(client service.Client, args ...string) error { return fmt.Errorf("registered command") }, "foo command")
cmd := cmds.Find("foo") cmd := cmds.Find("foo")
err := cmd(nil) err := cmd(nil)
......
package terminal package terminal
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
...@@ -80,7 +79,7 @@ func (t *Term) Run() (error, int) { ...@@ -80,7 +79,7 @@ func (t *Term) Run() (error, int) {
if err == io.EOF { if err == io.EOF {
err, status = handleExit(t.client, t) err, status = handleExit(t.client, t)
} }
err, status = errors.New("Prompt for input failed.\n"), 1 err, status = fmt.Errorf("Prompt for input failed.\n"), 1
break break
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册