func breakpoint(client service.Client, args ...string) error { if len(args) != 1 { return fmt.Errorf("argument must be either a function name or <file:line>") } requestedBp := &api.Breakpoint{} tokens := strings.Split(args[0], ":") switch { case len(tokens) == 1: requestedBp.FunctionName = args[0] case len(tokens) == 2: file := tokens[0] line, err := strconv.Atoi(tokens[1]) if err != nil { return err } requestedBp.File = file requestedBp.Line = line default: return fmt.Errorf("invalid line reference") } bp, err := client.CreateBreakpoint(requestedBp) if err != nil { return err } fmt.Printf("Breakpoint %d set at %#v for %s %s:%d\n", bp.ID, bp.Addr, bp.FunctionName, bp.File, bp.Line) return nil }
func setBreakpoint(client service.Client, tracepoint bool, args ...string) error { if len(args) < 1 { return fmt.Errorf("address required, specify either a function name or <file:line>") } requestedBp := &api.Breakpoint{} tokens := strings.Split(args[0], ":") switch { case len(tokens) == 1: requestedBp.FunctionName = args[0] case len(tokens) == 2: file := tokens[0] line, err := strconv.Atoi(tokens[1]) if err != nil { return err } requestedBp.File = file requestedBp.Line = line default: return fmt.Errorf("invalid line reference") } for i := 1; i < len(args); i++ { switch args[i] { case "-stack": i++ n, err := strconv.Atoi(args[i]) if err != nil { return fmt.Errorf("argument of -stack must be a number") } requestedBp.Stacktrace = n case "-goroutine": requestedBp.Goroutine = true default: requestedBp.Variables = append(requestedBp.Variables, args[i]) } } requestedBp.Tracepoint = tracepoint bp, err := client.CreateBreakpoint(requestedBp) if err != nil { return err } thing := "Breakpoint" if tracepoint { thing = "Tracepoint" } fmt.Printf("%s %d set at %#v for %s %s:%d\n", thing, bp.ID, bp.Addr, bp.FunctionName, bp.File, bp.Line) return nil }
func setBreakpoint(client service.Client, tracepoint bool, args ...string) error { if len(args) < 1 { return fmt.Errorf("address required, specify either a function name or <file:line>") } requestedBp := &api.Breakpoint{} for i := 1; i < len(args); i++ { switch args[i] { case "-stack": i++ n, err := strconv.Atoi(args[i]) if err != nil { return fmt.Errorf("argument of -stack must be a number") } requestedBp.Stacktrace = n case "-goroutine": requestedBp.Goroutine = true default: requestedBp.Variables = append(requestedBp.Variables, args[i]) } } requestedBp.Tracepoint = tracepoint locs, err := client.FindLocation(args[0]) if err != nil { return err } thing := "Breakpoint" if tracepoint { thing = "Tracepoint" } for _, loc := range locs { requestedBp.Addr = loc.PC bp, err := client.CreateBreakpoint(requestedBp) if err != nil { return err } fmt.Printf("%s %d set at %#v for %s %s:%d\n", thing, bp.ID, bp.Addr, bp.FunctionName, bp.File, bp.Line) } return nil }