diff --git a/cmd/dlv/cmds/commands.go b/cmd/dlv/cmds/commands.go index 83ad7bcf..e94e6a31 100644 --- a/cmd/dlv/cmds/commands.go +++ b/cmd/dlv/cmds/commands.go @@ -404,7 +404,7 @@ func coreCmd(cmd *cobra.Command, args []string) { func connectCmd(cmd *cobra.Command, args []string) { addr := args[0] if addr == "" { - fmt.Fprintf(os.Stderr, "An empty address was provided. You must provide an address as the first argument.\n") + fmt.Fprint(os.Stderr, "An empty address was provided. You must provide an address as the first argument.\n") os.Exit(1) } os.Exit(connect(addr, conf)) @@ -419,8 +419,7 @@ func splitArgs(cmd *cobra.Command, args []string) ([]string, []string) { func connect(addr string, conf *config.Config) int { // Create and start a terminal - attach to running instance - var client service.Client - client = rpc2.NewClient(addr) + client := rpc2.NewClient(addr) term := terminal.New(client, conf) status, err := term.Run() if err != nil { @@ -447,7 +446,7 @@ func execute(attachPid int, processArgs []string, conf *config.Config, coreFile defer listener.Close() if Headless && (InitFile != "") { - fmt.Fprintf(os.Stderr, "Warning: init file ignored\n") + fmt.Fprint(os.Stderr, "Warning: init file ignored\n") } var server interface { @@ -498,7 +497,7 @@ func execute(attachPid int, processArgs []string, conf *config.Config, coreFile if Headless { // Print listener address fmt.Printf("API server listening at: %s\n", listener.Addr()) - ch := make(chan os.Signal) + ch := make(chan os.Signal, 1) signal.Notify(ch, syscall.SIGINT) select { case <-ch: @@ -507,8 +506,7 @@ func execute(attachPid int, processArgs []string, conf *config.Config, coreFile err = server.Stop(true) } else { // Create and start a terminal - var client service.Client - client = rpc2.NewClient(listener.Addr().String()) + client := rpc2.NewClient(listener.Addr().String()) term := terminal.New(client, conf) term.InitFile = InitFile status, err = term.Run() diff --git a/pkg/config/config.go b/pkg/config/config.go index 3abb4857..b2ef3164 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -7,7 +7,7 @@ import ( "os/user" "path" - yaml "gopkg.in/yaml.v2" + "gopkg.in/yaml.v2" ) const ( diff --git a/pkg/dwarf/frame/entries.go b/pkg/dwarf/frame/entries.go index caca2ce2..92c9caf3 100644 --- a/pkg/dwarf/frame/entries.go +++ b/pkg/dwarf/frame/entries.go @@ -32,10 +32,7 @@ type FrameDescriptionEntry struct { // Returns whether or not the given address is within the // bounds of this frame. func (fde *FrameDescriptionEntry) Cover(addr uint64) bool { - if (addr - fde.begin) < fde.end { - return true - } - return false + return (addr - fde.begin) < fde.end } // Address of first location for this frame. diff --git a/pkg/proc/disasm_amd64.go b/pkg/proc/disasm_amd64.go index 2f9dbada..cafe33a9 100644 --- a/pkg/proc/disasm_amd64.go +++ b/pkg/proc/disasm_amd64.go @@ -33,7 +33,6 @@ func patchPCRel(pc uint64, inst *x86asm.Inst) { inst.Args[i] = x86asm.Imm(int64(pc) + int64(rel) + int64(inst.Len)) } } - return } func (inst *AsmInstruction) Text(flavour AssemblyFlavour) string { diff --git a/pkg/proc/gdbserial/gdbserver.go b/pkg/proc/gdbserial/gdbserver.go index 4df8f19d..c5294105 100644 --- a/pkg/proc/gdbserial/gdbserver.go +++ b/pkg/proc/gdbserial/gdbserver.go @@ -739,11 +739,7 @@ func (p *Process) Restart(pos string) error { p.conn.setBreakpoint(addr) } - if err := p.setCurrentBreakpoints(); err != nil { - return err - } - - return nil + return p.setCurrentBreakpoints() } func (p *Process) When() (string, error) { @@ -1274,7 +1270,7 @@ func (t *Thread) reloadGAtPC() error { // around by clearing and re-setting the breakpoint in a specific sequence // with the memory writes. // Additionally all breakpoints in [pc, pc+len(movinstr)] need to be removed - for addr, _ := range t.p.breakpoints { + for addr := range t.p.breakpoints { if addr >= pc && addr <= pc+uint64(len(movinstr)) { err := t.p.conn.clearBreakpoint(addr) if err != nil { diff --git a/pkg/proc/gdbserial/gdbserver_conn.go b/pkg/proc/gdbserial/gdbserver_conn.go index 955cfe0a..601de1f3 100644 --- a/pkg/proc/gdbserial/gdbserver_conn.go +++ b/pkg/proc/gdbserial/gdbserver_conn.go @@ -50,7 +50,6 @@ const ( ) var ErrTooManyAttempts = errors.New("too many transmit attempts") -var ErrNoTargetDescrption = errors.New("target description not supported") // GdbProtocolError is an error response (Exx) of Gdb Remote Serial Protocol // or an "unsupported command" response (empty packet). @@ -526,7 +525,7 @@ func (conn *gdbConn) resume(sig uint8, tu *threadUpdater) (string, uint8, error) if conn.direction == proc.Forward { conn.outbuf.Reset() if sig == 0 { - fmt.Fprintf(&conn.outbuf, "$vCont;c") + fmt.Fprint(&conn.outbuf, "$vCont;c") } else { fmt.Fprintf(&conn.outbuf, "$vCont;C%02x", sig) } @@ -535,7 +534,7 @@ func (conn *gdbConn) resume(sig uint8, tu *threadUpdater) (string, uint8, error) return "", 0, err } conn.outbuf.Reset() - fmt.Fprintf(&conn.outbuf, "$bc") + fmt.Fprint(&conn.outbuf, "$bc") } if err := conn.send(conn.outbuf.Bytes()); err != nil { return "", 0, err @@ -561,7 +560,7 @@ func (conn *gdbConn) step(threadID string, tu *threadUpdater) (string, uint8, er return "", 0, err } conn.outbuf.Reset() - fmt.Fprintf(&conn.outbuf, "$bs") + fmt.Fprint(&conn.outbuf, "$bs") } if err := conn.send(conn.outbuf.Bytes()); err != nil { return "", 0, err @@ -698,7 +697,7 @@ func (conn *gdbConn) queryProcessInfo(pid int) (map[string]string, error) { if pid != 0 { fmt.Fprintf(&conn.outbuf, "$qProcessInfoPID:%d", pid) } else { - fmt.Fprintf(&conn.outbuf, "$qProcessInfo") + fmt.Fprint(&conn.outbuf, "$qProcessInfo") } resp, err := conn.exec(conn.outbuf.Bytes(), "process info for pid") if err != nil { @@ -886,9 +885,9 @@ func (conn *gdbConn) threadStopInfo(threadID string) (sig uint8, reason string, // restart executes a 'vRun' command. func (conn *gdbConn) restart(pos string) error { conn.outbuf.Reset() - fmt.Fprintf(&conn.outbuf, "$vRun;") + fmt.Fprint(&conn.outbuf, "$vRun;") if pos != "" { - fmt.Fprintf(&conn.outbuf, ";") + fmt.Fprint(&conn.outbuf, ";") writeAsciiBytes(&conn.outbuf, []byte(pos)) } _, err := conn.exec(conn.outbuf.Bytes(), "restart") @@ -901,9 +900,9 @@ func (conn *gdbConn) qRRCmd(args ...string) (string, error) { panic("must specify at least one argument for qRRCmd") } conn.outbuf.Reset() - fmt.Fprintf(&conn.outbuf, "$qRRCmd") + fmt.Fprint(&conn.outbuf, "$qRRCmd") for _, arg := range args { - fmt.Fprintf(&conn.outbuf, ":") + fmt.Fprint(&conn.outbuf, ":") writeAsciiBytes(&conn.outbuf, []byte(arg)) } resp, err := conn.exec(conn.outbuf.Bytes(), "qRRCmd") diff --git a/pkg/proc/go_version.go b/pkg/proc/go_version.go index 6410a887..448edeee 100644 --- a/pkg/proc/go_version.go +++ b/pkg/proc/go_version.go @@ -78,7 +78,7 @@ func ParseVersionString(ver string) (GoVersion, bool) { r.Major, err1 = strconv.Atoi(v[0]) r.Minor, err2 = strconv.Atoi(v[1]) r.Rev, err3 = strconv.Atoi(v[2]) - r.Proposal = v[3]; + r.Proposal = v[3] if err1 != nil || err2 != nil || err3 != nil || r.Proposal == "" { return GoVersion{}, false } diff --git a/pkg/proc/native/threads.go b/pkg/proc/native/threads.go index 70723323..c1694724 100644 --- a/pkg/proc/native/threads.go +++ b/pkg/proc/native/threads.go @@ -169,7 +169,7 @@ func (thread *Thread) clearBreakpointState() { } func (th *Thread) Breakpoint() (*proc.Breakpoint, bool, error) { - return th.CurrentBreakpoint, (th.CurrentBreakpoint != nil && th.BreakpointConditionMet), th.BreakpointConditionError + return th.CurrentBreakpoint, th.CurrentBreakpoint != nil && th.BreakpointConditionMet, th.BreakpointConditionError } func (th *Thread) ThreadID() int { diff --git a/pkg/proc/proc.go b/pkg/proc/proc.go index ddfa196f..99480574 100644 --- a/pkg/proc/proc.go +++ b/pkg/proc/proc.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "go/ast" - "go/constant" "go/token" "path/filepath" "strconv" @@ -397,6 +396,9 @@ func GoroutinesInfo(dbp Process) ([]*G, error) { } faddr := make([]byte, dbp.BinInfo().Arch.PtrSize()) _, err = dbp.CurrentThread().ReadMemory(faddr, uintptr(allgentryaddr)) + if err != nil { + return nil, err + } allgptr := binary.LittleEndian.Uint64(faddr) for i := uint64(0); i < allglen; i++ { @@ -429,24 +431,6 @@ func GoroutinesInfo(dbp Process) ([]*G, error) { return allg, nil } -func GetGoVersion(p Process) (GoVersion, error) { - scope := &EvalScope{0, 0, p.CurrentThread(), nil, p.BinInfo(), 0} - vv, err := scope.packageVarAddr("runtime.buildVersion") - if err != nil { - return GoVersion{}, fmt.Errorf("could not determine version number: %v", err) - } - vv.loadValue(LoadConfig{true, 0, 64, 0, 0}) - if vv.Unreadable != nil { - return GoVersion{}, fmt.Errorf("unreadable version number: %v\n", vv.Unreadable) - } - - ver, ok := ParseVersionString(constant.StringVal(vv.Value)) - if !ok { - return GoVersion{}, fmt.Errorf("could not parse version number: %v\n", vv.Value) - } - return ver, nil -} - // FindGoroutine returns a G struct representing the goroutine // specified by `gid`. func FindGoroutine(dbp Process, gid int) (*G, error) { diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index fbc36571..b2c0b806 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -208,7 +208,7 @@ func setFileBreakpoint(p proc.Process, t *testing.T, fixture protest.Fixture, li } func TestHalt(t *testing.T) { - stopChan := make(chan interface{}) + stopChan := make(chan interface{}, 1) withTestProcess("loopprog", t, func(p proc.Process, fixture protest.Fixture) { _, err := setFunctionBreakpoint(p, "main.loop") assertNoError(err, t, "SetBreakpoint") @@ -219,18 +219,20 @@ func TestHalt(t *testing.T) { assertNoError(err, t, "Registers") } } - resumeChan := make(chan struct{}) + resumeChan := make(chan struct{}, 1) go func() { <-resumeChan time.Sleep(100 * time.Millisecond) - if err := p.RequestManualStop(); err != nil { - t.Fatal(err) - } - stopChan <- nil + stopChan <- p.RequestManualStop() }() p.ResumeNotify(resumeChan) assertNoError(proc.Continue(p), t, "Continue") - <-stopChan + retVal := <-stopChan + + if err, ok := retVal.(error); ok && err != nil { + t.Fatal() + } + // Loop through threads and make sure they are all // actually stopped, err will not be nil if the process // is still running. @@ -870,7 +872,11 @@ func stackMatch(stack []loc, locations []proc.Stackframe, skipRuntime bool) bool func TestStacktraceGoroutine(t *testing.T) { mainStack := []loc{{13, "main.stacktraceme"}, {26, "main.main"}} - agoroutineStacks := [][]loc{[]loc{{8, "main.agoroutine"}}, []loc{{9, "main.agoroutine"}}, []loc{{10, "main.agoroutine"}}} + agoroutineStacks := [][]loc{ + {{8, "main.agoroutine"}}, + {{9, "main.agoroutine"}}, + {{10, "main.agoroutine"}}, + } protest.AllowRecording(t) withTestProcess("goroutinestackprog", t, func(p proc.Process, fixture protest.Fixture) { @@ -940,7 +946,7 @@ func TestKill(t *testing.T) { if err := p.Kill(); err != nil { t.Fatal(err) } - if p.Exited() != true { + if !p.Exited() { t.Fatal("expected process to have exited") } if runtime.GOOS == "linux" { @@ -954,7 +960,7 @@ func TestKill(t *testing.T) { if err := p.Detach(true); err != nil { t.Fatal(err) } - if p.Exited() != true { + if !p.Exited() { t.Fatal("expected process to have exited") } if runtime.GOOS == "linux" { @@ -1789,6 +1795,9 @@ func TestIssue332_Part2(t *testing.T) { pcAfterPrologue, err := proc.FindFunctionLocation(p, "main.changeMe", true, -1) assertNoError(err, t, "FindFunctionLocation()") pcEntry, err := proc.FindFunctionLocation(p, "main.changeMe", false, 0) + if err != nil { + t.Fatalf("got error while finding function location: %v", err) + } if pcAfterPrologue == pcEntry { t.Fatalf("main.changeMe and main.changeMe:0 are the same (%x)", pcAfterPrologue) } @@ -1891,7 +1900,7 @@ func TestCmdLineArgs(t *testing.T) { t.Fatalf("Process did not exit: %v", err) } else { if exit.Status != 0 { - t.Fatalf("process exited with invalid status", exit.Status) + t.Fatalf("process exited with invalid status %d", exit.Status) } } } @@ -2364,7 +2373,7 @@ func TestStepConcurrentPtr(t *testing.T) { if oldk, ok := kvals[gid]; ok { if oldk >= k { - t.Fatalf("Goroutine %d did not make progress?") + t.Fatalf("Goroutine %d did not make progress?", gid) } } kvals[gid] = k @@ -2752,7 +2761,7 @@ func TestStacktraceWithBarriers(t *testing.T) { } if !found { - t.Log("Truncated stacktrace for %d\n", goid) + t.Logf("Truncated stacktrace for %d\n", goid) } } }) @@ -2824,7 +2833,7 @@ func TestAttachDetach(t *testing.T) { assertNoError(err, t, "Page request after detach") bs, err := ioutil.ReadAll(resp.Body) assertNoError(err, t, "Reading /nobp page") - if out := string(bs); strings.Index(out, "hello, world!") < 0 { + if out := string(bs); !strings.Contains(out, "hello, world!") { t.Fatalf("/nobp page does not contain \"hello, world!\": %q", out) } diff --git a/pkg/proc/proc_unix_test.go b/pkg/proc/proc_unix_test.go index 14ef04ad..ae3a3b9d 100644 --- a/pkg/proc/proc_unix_test.go +++ b/pkg/proc/proc_unix_test.go @@ -3,6 +3,7 @@ package proc_test import ( + "fmt" "runtime" "syscall" "testing" @@ -12,6 +13,15 @@ import ( protest "github.com/derekparker/delve/pkg/proc/test" ) +type errIssue419 struct { + pid int + err error +} + +func (npe errIssue419) Error() string { + return fmt.Sprintf("Pid is zero or negative: %d", npe.pid) +} + func TestIssue419(t *testing.T) { if testBackend == "lldb" && runtime.GOOS == "darwin" { // debugserver bug? @@ -20,29 +30,43 @@ func TestIssue419(t *testing.T) { if testBackend == "rr" { return } + + errChan := make(chan error, 2) + // SIGINT directed at the inferior should be passed along not swallowed by delve withTestProcess("issue419", t, func(p proc.Process, fixture protest.Fixture) { + defer close(errChan) _, err := setFunctionBreakpoint(p, "main.main") assertNoError(err, t, "SetBreakpoint()") assertNoError(proc.Continue(p), t, "Continue()") - resumeChan := make(chan struct{}) + resumeChan := make(chan struct{}, 1) go func() { time.Sleep(500 * time.Millisecond) <-resumeChan if p.Pid() <= 0 { // if we don't stop the inferior the test will never finish p.RequestManualStop() - p.Kill() - t.Fatalf("Pid is zero or negative: %d", p.Pid()) + err := p.Kill() + errChan <- errIssue419{pid: p.Pid(), err: err} return } err := syscall.Kill(p.Pid(), syscall.SIGINT) - assertNoError(err, t, "syscall.Kill") + errChan <- errIssue419{pid: p.Pid(), err: err} }() p.ResumeNotify(resumeChan) - err = proc.Continue(p) + errChan <- proc.Continue(p) + }) + + for i :=0; i<2; i++ { + err := <-errChan + + if v, ok := err.(errIssue419); ok { + assertNoError(v.err, t, "syscall.Kill") + continue + } + if _, exited := err.(proc.ProcessExitedError); !exited { t.Fatalf("Unexpected error after Continue(): %v\n", err) } - }) + } } diff --git a/pkg/proc/variables.go b/pkg/proc/variables.go index 6101bcfc..fc506cd7 100644 --- a/pkg/proc/variables.go +++ b/pkg/proc/variables.go @@ -481,7 +481,7 @@ func (g *G) UserCurrent() Location { frame := it.Frame() if frame.Call.Fn != nil { name := frame.Call.Fn.Name - if (strings.Index(name, ".") >= 0) && (!strings.HasPrefix(name, "runtime.") || isExportedRuntime(name)) { + if strings.Contains(name, ".") && (!strings.HasPrefix(name, "runtime.") || isExportedRuntime(name)) { return frame.Call } } @@ -712,7 +712,7 @@ func (v *Variable) structMember(memberName string) (*Variable, error) { return nil, err } embeddedVar.Name = structVar.Name - embeddedField, err := embeddedVar.structMember(memberName) + embeddedField, _ := embeddedVar.structMember(memberName) if embeddedField != nil { return embeddedField, nil } @@ -1016,8 +1016,6 @@ func (v *Variable) loadSliceInfo(t *dwarf.SliceType) { if t, ok := v.fieldType.(*dwarf.PtrType); ok { v.stride = t.ByteSize } - - return } func (v *Variable) loadArrayValues(recurseLevel int, cfg LoadConfig) { @@ -1652,7 +1650,6 @@ func (v *Variable) loadInterface(recurseLevel int, loadData bool, cfg LoadConfig } else { v.Children[0].OnlyAddr = true } - return } // Fetches all variables of a specific type in the current function scope diff --git a/pkg/terminal/command_test.go b/pkg/terminal/command_test.go index 47ccaa82..786d4c95 100644 --- a/pkg/terminal/command_test.go +++ b/pkg/terminal/command_test.go @@ -369,7 +369,7 @@ func TestOnPrefix(t *testing.T) { for { outstr, err := term.Exec("continue") if err != nil { - if strings.Index(err.Error(), "exited") < 0 { + if !strings.Contains(err.Error(), "exited") { t.Fatalf("Unexpected error executing 'continue': %v", err) } break @@ -422,7 +422,7 @@ func TestOnPrefixLocals(t *testing.T) { for { outstr, err := term.Exec("continue") if err != nil { - if strings.Index(err.Error(), "exited") < 0 { + if !strings.Contains(err.Error(), "exited") { t.Fatalf("Unexpected error executing 'continue': %v", err) } break @@ -476,7 +476,7 @@ func TestIssue387(t *testing.T) { breakpointHitCount += countOccourences(outstr, "issue387.go:8") t.Log(outstr) if err != nil { - if strings.Index(err.Error(), "exited") < 0 { + if !strings.Contains(err.Error(), "exited") { t.Fatalf("Unexpected error executing 'continue': %v", err) } break @@ -509,7 +509,7 @@ func listIsAt(t *testing.T, term *FakeTerminal, listcmd string, cur, start, end t.Logf("%q: %q", listcmd, outstr) - if strings.Index(lines[0], fmt.Sprintf(":%d", cur)) < 0 { + if !strings.Contains(lines[0], fmt.Sprintf(":%d", cur)) { t.Fatalf("Could not find current line number in first output line: %q", lines[0]) } diff --git a/pkg/terminal/disasmprint.go b/pkg/terminal/disasmprint.go index 7c273749..2915410a 100644 --- a/pkg/terminal/disasmprint.go +++ b/pkg/terminal/disasmprint.go @@ -3,10 +3,11 @@ package terminal import ( "bufio" "fmt" - "github.com/derekparker/delve/service/api" "io" "path/filepath" "text/tabwriter" + + "github.com/derekparker/delve/service/api" ) func DisasmPrint(dv api.AsmInstructions, out io.Writer) { diff --git a/pkg/terminal/docgen.go b/pkg/terminal/docgen.go index a9632d9b..ad99e0b2 100644 --- a/pkg/terminal/docgen.go +++ b/pkg/terminal/docgen.go @@ -27,10 +27,10 @@ func replaceDocPath(s string) string { } func (commands *Commands) WriteMarkdown(w io.Writer) { - fmt.Fprintf(w, "# Commands\n\n") + fmt.Fprint(w, "# Commands\n\n") - fmt.Fprintf(w, "Command | Description\n") - fmt.Fprintf(w, "--------|------------\n") + fmt.Fprint(w, "Command | Description\n") + fmt.Fprint(w, "--------|------------\n") for _, cmd := range commands.cmds { h := cmd.helpMsg if idx := strings.Index(h, "\n"); idx >= 0 { @@ -38,17 +38,17 @@ func (commands *Commands) WriteMarkdown(w io.Writer) { } fmt.Fprintf(w, "[%s](#%s) | %s\n", cmd.aliases[0], cmd.aliases[0], h) } - fmt.Fprintf(w, "\n") + fmt.Fprint(w, "\n") for _, cmd := range commands.cmds { fmt.Fprintf(w, "## %s\n%s\n\n", cmd.aliases[0], replaceDocPath(cmd.helpMsg)) if len(cmd.aliases) > 1 { - fmt.Fprintf(w, "Aliases:") + fmt.Fprint(w, "Aliases:") for _, alias := range cmd.aliases[1:] { fmt.Fprintf(w, " %s", alias) } - fmt.Fprintf(w, "\n") + fmt.Fprint(w, "\n") } - fmt.Fprintf(w, "\n") + fmt.Fprint(w, "\n") } } diff --git a/service/api/conversions.go b/service/api/conversions.go index 4e1905e1..1b2132e7 100644 --- a/service/api/conversions.go +++ b/service/api/conversions.go @@ -276,5 +276,5 @@ func ConvertRegisters(in []proc.Register) (out []Register) { } func ConvertCheckpoint(in proc.Checkpoint) (out Checkpoint) { - return Checkpoint{ID: in.ID, When: in.When, Where: in.Where} + return Checkpoint(in) } diff --git a/service/api/prettyprint.go b/service/api/prettyprint.go index 7c53c1bc..1dd56d1b 100644 --- a/service/api/prettyprint.go +++ b/service/api/prettyprint.go @@ -38,7 +38,7 @@ func (v *Variable) writeTo(buf io.Writer, top, newlines, includeType bool, inden if includeType && v.Type != "void" { fmt.Fprintf(buf, "%s nil", v.Type) } else { - fmt.Fprintf(buf, "nil") + fmt.Fprint(buf, "nil") } return } @@ -50,11 +50,11 @@ func (v *Variable) writeTo(buf io.Writer, top, newlines, includeType bool, inden v.writeArrayTo(buf, newlines, includeType, indent) case reflect.Ptr: if v.Type == "" { - fmt.Fprintf(buf, "nil") + fmt.Fprint(buf, "nil") } else if v.Children[0].OnlyAddr && v.Children[0].Addr != 0 { fmt.Fprintf(buf, "(%s)(0x%x)", v.Type, v.Children[0].Addr) } else { - fmt.Fprintf(buf, "*") + fmt.Fprint(buf, "*") v.Children[0].writeTo(buf, false, newlines, includeType, indent) } case reflect.UnsafePointer: @@ -78,7 +78,7 @@ func (v *Variable) writeTo(buf io.Writer, top, newlines, includeType bool, inden if v.Children[0].Kind == reflect.Invalid { fmt.Fprintf(buf, "%s ", v.Type) if v.Children[0].Addr == 0 { - fmt.Fprintf(buf, "nil") + fmt.Fprint(buf, "nil") return } } else { @@ -88,9 +88,9 @@ func (v *Variable) writeTo(buf io.Writer, top, newlines, includeType bool, inden data := v.Children[0] if data.Kind == reflect.Ptr { if len(data.Children) == 0 { - fmt.Fprintf(buf, "...") + fmt.Fprint(buf, "...") } else if data.Children[0].Addr == 0 { - fmt.Fprintf(buf, "nil") + fmt.Fprint(buf, "nil") } else if data.Children[0].OnlyAddr { fmt.Fprintf(buf, "0x%x", v.Children[0].Addr) } else { @@ -103,7 +103,7 @@ func (v *Variable) writeTo(buf io.Writer, top, newlines, includeType bool, inden v.writeMapTo(buf, newlines, includeType, indent) case reflect.Func: if v.Value == "" { - fmt.Fprintf(buf, "nil") + fmt.Fprint(buf, "nil") } else { fmt.Fprintf(buf, "%s", v.Value) } @@ -152,7 +152,7 @@ func (v *Variable) writeStructTo(buf io.Writer, newlines, includeType bool, inde nl := v.shouldNewlineStruct(newlines) - fmt.Fprintf(buf, "{") + fmt.Fprint(buf, "{") for i := range v.Children { if nl { @@ -161,9 +161,9 @@ func (v *Variable) writeStructTo(buf io.Writer, newlines, includeType bool, inde fmt.Fprintf(buf, "%s: ", v.Children[i].Name) v.Children[i].writeTo(buf, false, nl, true, indent+indentString) if i != len(v.Children)-1 || nl { - fmt.Fprintf(buf, ",") + fmt.Fprint(buf, ",") if !nl { - fmt.Fprintf(buf, " ") + fmt.Fprint(buf, " ") } } } @@ -172,12 +172,12 @@ func (v *Variable) writeStructTo(buf io.Writer, newlines, includeType bool, inde if nl { fmt.Fprintf(buf, "\n%s%s", indent, indentString) } else { - fmt.Fprintf(buf, ",") + fmt.Fprint(buf, ",") } fmt.Fprintf(buf, "...+%d more", int(v.Len)-len(v.Children)) } - fmt.Fprintf(buf, "}") + fmt.Fprint(buf, "}") } func (v *Variable) writeMapTo(buf io.Writer, newlines, includeType bool, indent string) { @@ -187,7 +187,7 @@ func (v *Variable) writeMapTo(buf io.Writer, newlines, includeType bool, indent nl := newlines && (len(v.Children) > 0) - fmt.Fprintf(buf, "[") + fmt.Fprint(buf, "[") for i := 0; i < len(v.Children); i += 2 { key := &v.Children[i] @@ -198,10 +198,10 @@ func (v *Variable) writeMapTo(buf io.Writer, newlines, includeType bool, indent } key.writeTo(buf, false, false, false, indent+indentString) - fmt.Fprintf(buf, ": ") + fmt.Fprint(buf, ": ") value.writeTo(buf, false, nl, false, indent+indentString) if i != len(v.Children)-1 || nl { - fmt.Fprintf(buf, ", ") + fmt.Fprint(buf, ", ") } } @@ -210,18 +210,18 @@ func (v *Variable) writeMapTo(buf io.Writer, newlines, includeType bool, indent if nl { fmt.Fprintf(buf, "\n%s%s", indent, indentString) } else { - fmt.Fprintf(buf, ",") + fmt.Fprint(buf, ",") } fmt.Fprintf(buf, "...+%d more", int(v.Len)-(len(v.Children)/2)) } else { - fmt.Fprintf(buf, "...") + fmt.Fprint(buf, "...") } } if nl { fmt.Fprintf(buf, "\n%s", indent) } - fmt.Fprintf(buf, "]") + fmt.Fprint(buf, "]") } func (v *Variable) shouldNewlineArray(newlines bool) bool { @@ -290,7 +290,7 @@ func (v *Variable) shouldNewlineStruct(newlines bool) bool { func (v *Variable) writeSliceOrArrayTo(buf io.Writer, newlines bool, indent string) { nl := v.shouldNewlineArray(newlines) - fmt.Fprintf(buf, "[") + fmt.Fprint(buf, "[") for i := range v.Children { if nl { @@ -298,7 +298,7 @@ func (v *Variable) writeSliceOrArrayTo(buf io.Writer, newlines bool, indent stri } v.Children[i].writeTo(buf, false, nl, false, indent+indentString) if i != len(v.Children)-1 || nl { - fmt.Fprintf(buf, ",") + fmt.Fprint(buf, ",") } } @@ -307,11 +307,11 @@ func (v *Variable) writeSliceOrArrayTo(buf io.Writer, newlines bool, indent stri if nl { fmt.Fprintf(buf, "\n%s%s", indent, indentString) } else { - fmt.Fprintf(buf, ",") + fmt.Fprint(buf, ",") } fmt.Fprintf(buf, "...+%d more", int(v.Len)-len(v.Children)) } else { - fmt.Fprintf(buf, "...") + fmt.Fprint(buf, "...") } } @@ -319,5 +319,5 @@ func (v *Variable) writeSliceOrArrayTo(buf io.Writer, newlines bool, indent stri fmt.Fprintf(buf, "\n%s", indent) } - fmt.Fprintf(buf, "]") + fmt.Fprint(buf, "]") } diff --git a/service/debugger/debugger_linux.go b/service/debugger/debugger_linux.go index 1d567c08..8da64ec1 100644 --- a/service/debugger/debugger_linux.go +++ b/service/debugger/debugger_linux.go @@ -2,10 +2,11 @@ package debugger import ( "fmt" - sys "golang.org/x/sys/unix" "io/ioutil" "os" "syscall" + + sys "golang.org/x/sys/unix" ) func attachErrorMessage(pid int, err error) error { diff --git a/service/debugger/locations.go b/service/debugger/locations.go index 15316b63..3f6016a1 100644 --- a/service/debugger/locations.go +++ b/service/debugger/locations.go @@ -178,7 +178,7 @@ func parseFuncLocationSpec(in string) *FuncLocationSpec { r := stripReceiverDecoration(v[0]) if r != v[0] { spec.ReceiverName = r - } else if strings.Index(r, "/") >= 0 { + } else if strings.Contains(r, "/") { spec.PackageName = r } else { spec.PackageOrReceiverName = r @@ -198,7 +198,7 @@ func parseFuncLocationSpec(in string) *FuncLocationSpec { spec.AbsolutePackage = true } - if strings.Index(spec.BaseName, "/") >= 0 || strings.Index(spec.ReceiverName, "/") >= 0 { + if strings.Contains(spec.BaseName, "/") || strings.Contains(spec.ReceiverName, "/") { return nil } diff --git a/service/rpc1/client.go b/service/rpc1/client.go index 43c76c49..8a9c68fd 100644 --- a/service/rpc1/client.go +++ b/service/rpc1/client.go @@ -15,7 +15,6 @@ import ( // Client is a RPC service.Client. type RPCClient struct { addr string - processPid int client *rpc.Client haltMu sync.Mutex haltReq bool @@ -303,10 +302,6 @@ func (c *RPCClient) DisassemblePC(scope api.EvalScope, pc uint64, flavour api.As return r, err } -func (c *RPCClient) url(path string) string { - return fmt.Sprintf("http://%s%s", c.addr, path) -} - func (c *RPCClient) call(method string, args, reply interface{}) error { return c.client.Call("RPCServer."+method, args, reply) } diff --git a/service/rpc2/client.go b/service/rpc2/client.go index eb31cfd6..54cfdda5 100644 --- a/service/rpc2/client.go +++ b/service/rpc2/client.go @@ -14,7 +14,6 @@ import ( // Client is a RPC service.Client. type RPCClient struct { addr string - processPid int client *rpc.Client } @@ -349,10 +348,6 @@ func (c *RPCClient) ClearCheckpoint(id int) error { return err } -func (c *RPCClient) url(path string) string { - return fmt.Sprintf("http://%s%s", c.addr, path) -} - func (c *RPCClient) call(method string, args, reply interface{}) error { return c.client.Call("RPCServer."+method, args, reply) } diff --git a/service/rpc2/server.go b/service/rpc2/server.go index 35c3ebc9..ada1788d 100644 --- a/service/rpc2/server.go +++ b/service/rpc2/server.go @@ -109,7 +109,6 @@ func (s *RPCServer) Command(command api.DebuggerCommand, cb service.RPCCallback) var out CommandOut out.State = *st cb.Return(out, nil) - return } type GetBreakpointIn struct { diff --git a/service/rpccommon/server.go b/service/rpccommon/server.go index b89948e0..5caf12d9 100644 --- a/service/rpccommon/server.go +++ b/service/rpccommon/server.go @@ -244,7 +244,6 @@ func suitableMethods(rcvr interface{}, methods map[string]*methodType) { } methods[sname+"."+mname] = &methodType{method: method, ArgType: argType, ReplyType: replyType, Synchronous: synchronous, Rcvr: rcvrv} } - return } func (s *ServerImpl) serveJSONCodec(conn io.ReadWriteCloser) { diff --git a/service/test/common_test.go b/service/test/common_test.go index 6168363b..0e0a6f2b 100644 --- a/service/test/common_test.go +++ b/service/test/common_test.go @@ -26,7 +26,7 @@ func assertError(err error, t *testing.T, s string) { t.Fatalf("failed assertion at %s:%d: %s (no error)\n", fname, line, s) } - if strings.Index(err.Error(), "Internal debugger error") >= 0 { + if strings.Contains(err.Error(), "Internal debugger error") { _, file, line, _ := runtime.Caller(1) fname := filepath.Base(file) t.Fatalf("failed assertion at %s:%d: %s internal debugger error: %v\n", fname, line, s, err) diff --git a/service/test/integration1_test.go b/service/test/integration1_test.go index 6f0e2c97..82f93660 100644 --- a/service/test/integration1_test.go +++ b/service/test/integration1_test.go @@ -172,7 +172,7 @@ func Test1ClientServer_exit(t *testing.T) { if !state.Exited { t.Fatalf("Expected exit after continue: %v", state) } - state, err = c.GetState() + _, err = c.GetState() if err == nil { t.Fatal("Expected error on querying state from exited process") } @@ -699,6 +699,9 @@ func Test1ClientServer_SetVariable(t *testing.T) { assertNoError(c.SetVariable(api.EvalScope{-1, 0}, "a2", "8"), t, "SetVariable()") a2, err := c.EvalVariable(api.EvalScope{-1, 0}, "a2") + if err != nil { + t.Fatalf("Could not evaluate variable: %v", err) + } t.Logf("a2: %v", a2) @@ -737,7 +740,7 @@ func Test1ClientServer_FullStacktrace(t *testing.T) { if arg.Name != "i" { continue } - t.Logf("frame %d, variable i is %v\n", arg) + t.Logf("frame %d, variable i is %v\n", i, arg) argn, err := strconv.Atoi(arg.Value) if err == nil { found[argn] = true diff --git a/service/test/integration2_test.go b/service/test/integration2_test.go index fe9b6067..1eddd758 100644 --- a/service/test/integration2_test.go +++ b/service/test/integration2_test.go @@ -196,7 +196,7 @@ func TestClientServer_exit(t *testing.T) { if !state.Exited { t.Fatalf("Expected exit after continue: %v", state) } - state, err = c.GetState() + _, err = c.GetState() if err == nil { t.Fatal("Expected error on querying state from exited process") } @@ -762,6 +762,9 @@ func TestClientServer_SetVariable(t *testing.T) { assertNoError(c.SetVariable(api.EvalScope{-1, 0}, "a2", "8"), t, "SetVariable()") a2, err := c.EvalVariable(api.EvalScope{-1, 0}, "a2", normalLoadConfig) + if err != nil { + t.Fatalf("Could not evaluate variable: %v", err) + } t.Logf("a2: %v", a2) diff --git a/service/test/variables_test.go b/service/test/variables_test.go index 5e9a897c..65993b70 100644 --- a/service/test/variables_test.go +++ b/service/test/variables_test.go @@ -83,6 +83,10 @@ func evalVariable(p proc.Process, symbol string, cfg proc.LoadConfig) (*proc.Var scope, err = proc.GoroutineScope(p.CurrentThread()) } + if err != nil { + return nil, err + } + return scope.EvalVariable(symbol, cfg) } @@ -100,8 +104,6 @@ func setVariable(p proc.Process, symbol, value string) error { return scope.SetVariable(symbol, value) } -const varTestBreakpointLineNumber = 59 - func withTestProcess(name string, t *testing.T, fn func(p proc.Process, fixture protest.Fixture)) { fixture := protest.BuildFixture(name) var p proc.Process