Skip to content

Commit

Permalink
*: run go1.19 'go fmt' on everything and fix problems (go-delve#3031)
Browse files Browse the repository at this point in the history
Go 1.19 also formats doc comments according to the new godoc syntax.
Some of our comments, especially unexported symbols did not conform to
the godoc syntax and therefore are mangled by 'go fmt'.

This PR runs 'go fmt' from go1.19 on everything and manually fixes the
problems.

See also:
	https://github.com/golang/proposal/blob/master/design/51082-godocfmt.md
  • Loading branch information
aarzilli authored Jun 17, 2022
1 parent 2827145 commit c412dcd
Show file tree
Hide file tree
Showing 22 changed files with 242 additions and 256 deletions.
1 change: 1 addition & 0 deletions _scripts/gen-cli-docs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package main
Expand Down
1 change: 1 addition & 0 deletions _scripts/gen-usage-docs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

package main
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// SplitQuotedFields is like strings.Fields but ignores spaces inside areas surrounded
// by the specified quote character.
// To specify a single quote use backslash to escape it: '\''
// To specify a single quote use backslash to escape it: \'
func SplitQuotedFields(in string, quote rune) []string {
type stateEnum int
const (
Expand Down
4 changes: 3 additions & 1 deletion pkg/dwarf/godwarf/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@ func max(a, b uint64) uint64 {
}

// fuseRanges fuses rngs2 into rngs1, it's the equivalent of
// normalizeRanges(append(rngs1, rngs2))
//
// normalizeRanges(append(rngs1, rngs2))
//
// but more efficient.
func fuseRanges(rngs1, rngs2 [][2]uint64) [][2]uint64 {
if rangesContains(rngs1, rngs2) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/dwarf/godwarf/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func (t *UnsupportedType) stringIntl(recCheck) string {

func (t *UnsupportedType) String() string { return t.stringIntl(nil) }

// ReadType reads the type at off in the DWARF ``info'' section.
// ReadType reads the type at off in the DWARF info section.
func ReadType(d *dwarf.Data, index int, off dwarf.Offset, typeCache map[dwarf.Offset]Type) (Type, error) {
typ, err := readType(d, "info", d.Reader(), off, typeCache, nil)
if typ != nil {
Expand Down
19 changes: 10 additions & 9 deletions pkg/locspec/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
//
// Location spec examples:
//
// locStr ::= <filename>:<line> | <function>[:<line>] | /<regex>/ | (+|-)<offset> | <line> | *<address>
// * <filename> can be the full path of a file or just a suffix
// * <function> ::= <package>.<receiver type>.<name> | <package>.(*<receiver type>).<name> | <receiver type>.<name> | <package>.<name> | (*<receiver type>).<name> | <name>
// <function> must be unambiguous
// * /<regex>/ will return a location for each function matched by regex
// * +<offset> returns a location for the line that is <offset> lines after the current line
// * -<offset> returns a location for the line that is <offset> lines before the current line
// * <line> returns a location for a line in the current file
// * *<address> returns the location corresponding to the specified address
// locStr ::= <filename>:<line> | <function>[:<line>] | /<regex>/ | (+|-)<offset> | <line> | *<address>
//
// * <filename> can be the full path of a file or just a suffix
// * <function> ::= <package>.<receiver type>.<name> | <package>.(*<receiver type>).<name> | <receiver type>.<name> | <package>.<name> | (*<receiver type>).<name> | <name>
// <function> must be unambiguous
// * /<regex>/ will return a location for each function matched by regex
// * +<offset> returns a location for the line that is <offset> lines after the current line
// * -<offset> returns a location for the line that is <offset> lines before the current line
// * <line> returns a location for a line in the current file
// * *<address> returns the location corresponding to the specified address
package locspec
14 changes: 8 additions & 6 deletions pkg/proc/bininfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1337,7 +1337,7 @@ func loadBinaryInfoElf(bi *BinaryInfo, image *Image, path string, addr uint64, w
return nil
}

// _STT_FUNC is a code object, see /usr/include/elf.h for a full definition.
// _STT_FUNC is a code object, see /usr/include/elf.h for a full definition.
const _STT_FUNC = 2

func (bi *BinaryInfo) loadSymbolName(image *Image, file *elf.File, wg *sync.WaitGroup) {
Expand Down Expand Up @@ -1633,13 +1633,15 @@ func (bi *BinaryInfo) parseDebugFrameMacho(image *Image, exe *macho.File, debugI
bi.parseDebugFrameGeneral(image, debugFrameBytes, "__debug_frame", debugFrameErr, ehFrameBytes, ehFrameAddr, "__eh_frame", frame.DwarfEndian(debugInfoBytes))
}

// macOSDebugFrameBugWorkaround applies a workaround for:
// https://github.com/golang/go/issues/25841
// macOSDebugFrameBugWorkaround applies a workaround for [golang/go#25841]
//
// It finds the Go function with the lowest entry point and the first
// debug_frame FDE, calculates the difference between the start of the
// function and the start of the FDE and sums it to all debug_frame FDEs.
// A number of additional checks are performed to make sure we don't ruin
// executables unaffected by this bug.
//
// [golang/go#25841]: https://github.com/golang/go/issues/25841
func (bi *BinaryInfo) macOSDebugFrameBugWorkaround() {
//TODO: log extensively because of bugs in the field
if bi.GOOS != "darwin" || bi.Arch.Name != "arm64" {
Expand Down Expand Up @@ -1967,9 +1969,9 @@ func (bi *BinaryInfo) loadDebugInfoMaps(image *Image, debugInfoBytes, debugLineB

// LookupGenericFunc returns a map that allows searching for instantiations of generic function by specificying a function name without type parameters.
// For example the key "pkg.(*Receiver).Amethod" will find all instantiations of Amethod:
// - pkg.(*Receiver[.shape.int]).Amethod"
// - pkg.(*Receiver[.shape.*uint8]).Amethod"
// - etc.
// - pkg.(*Receiver[.shape.int]).Amethod
// - pkg.(*Receiver[.shape.*uint8]).Amethod
// - etc.
func (bi *BinaryInfo) LookupGenericFunc() map[string][]*Function {
if bi.lookupGenericFunc == nil {
bi.lookupGenericFunc = make(map[string][]*Function)
Expand Down
10 changes: 6 additions & 4 deletions pkg/proc/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ var ErrNoThreads = errors.New("no threads found in core file")
// 0x0000000000400000 0x000000000044f000 0x0000000000000000
// but then it's partially overwritten with an RW mapping whose data is stored
// in the core file:
// Type Offset VirtAddr PhysAddr
// FileSiz MemSiz Flags Align
// LOAD 0x0000000000004000 0x000000000049a000 0x0000000000000000
// 0x0000000000002000 0x0000000000002000 RW 1000
//
// Type Offset VirtAddr PhysAddr
// FileSiz MemSiz Flags Align
// LOAD 0x0000000000004000 0x000000000049a000 0x0000000000000000
// 0x0000000000002000 0x0000000000002000 RW 1000
//
// This can be represented in a SplicedMemory by adding the original region,
// then putting the RW mapping on top of it.
type splicedMemory struct {
Expand Down
6 changes: 3 additions & 3 deletions pkg/proc/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// the process we are debugging.
//
// proc implements all core functionality including:
// * creating / attaching to a process
// * process manipulation (step, next, continue, halt)
// * methods to explore the memory of the process
//
// - creating / attaching to a process
// - process manipulation (step, next, continue, halt)
// - methods to explore the memory of the process
package proc
22 changes: 11 additions & 11 deletions pkg/proc/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,17 +338,17 @@ func afterLastArgAddr(vars []*Variable) uint64 {
}

// setValue writes the value of srcv to dstv.
// * If srcv is a numerical literal constant and srcv is of a compatible type
// the necessary type conversion is performed.
// * If srcv is nil and dstv is of a nil'able type then dstv is nilled.
// * If srcv is the empty string and dstv is a string then dstv is set to the
// empty string.
// * If dstv is an "interface {}" and srcv is either an interface (possibly
// non-empty) or a pointer shaped type (map, channel, pointer or struct
// containing a single pointer field) the type conversion to "interface {}"
// is performed.
// * If srcv and dstv have the same type and are both addressable then the
// contents of srcv are copied byte-by-byte into dstv
// - If srcv is a numerical literal constant and srcv is of a compatible type
// the necessary type conversion is performed.
// - If srcv is nil and dstv is of a nil'able type then dstv is nilled.
// - If srcv is the empty string and dstv is a string then dstv is set to the
// empty string.
// - If dstv is an "interface {}" and srcv is either an interface (possibly
// non-empty) or a pointer shaped type (map, channel, pointer or struct
// containing a single pointer field) the type conversion to "interface {}"
// is performed.
// - If srcv and dstv have the same type and are both addressable then the
// contents of srcv are copied byte-by-byte into dstv
func (scope *EvalScope) setValue(dstv, srcv *Variable, srcExpr string) error {
srcv.loadValue(loadSingleValue)

Expand Down
62 changes: 2 additions & 60 deletions pkg/proc/gdbserial/rr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package gdbserial

import (
"bufio"
"bytes"
"fmt"
"io"
"io/ioutil"
Expand All @@ -12,8 +11,8 @@ import (
"strconv"
"strings"
"syscall"
"unicode"

"github.com/go-delve/delve/pkg/config"
"github.com/go-delve/delve/pkg/proc"
)

Expand Down Expand Up @@ -248,7 +247,7 @@ func (err *ErrMalformedRRGdbCommand) Error() string {

func rrParseGdbCommand(line string) rrInit {
port := ""
fields := splitQuotedFields(line)
fields := config.SplitQuotedFields(line, '\'')
for i := 0; i < len(fields); i++ {
switch fields[i] {
case "-ex":
Expand Down Expand Up @@ -279,63 +278,6 @@ func rrParseGdbCommand(line string) rrInit {
return rrInit{port: port, exe: exe}
}

// Like strings.Fields but ignores spaces inside areas surrounded
// by single quotes.
// To specify a single quote use backslash to escape it: '\''
func splitQuotedFields(in string) []string {
type stateEnum int
const (
inSpace stateEnum = iota
inField
inQuote
inQuoteEscaped
)
state := inSpace
r := []string{}
var buf bytes.Buffer

for _, ch := range in {
switch state {
case inSpace:
if ch == '\'' {
state = inQuote
} else if !unicode.IsSpace(ch) {
buf.WriteRune(ch)
state = inField
}

case inField:
if ch == '\'' {
state = inQuote
} else if unicode.IsSpace(ch) {
r = append(r, buf.String())
buf.Reset()
} else {
buf.WriteRune(ch)
}

case inQuote:
if ch == '\'' {
state = inField
} else if ch == '\\' {
state = inQuoteEscaped
} else {
buf.WriteRune(ch)
}

case inQuoteEscaped:
buf.WriteRune(ch)
state = inQuote
}
}

if buf.Len() != 0 {
r = append(r, buf.String())
}

return r
}

// RecordAndReplay acts like calling Record and then Replay.
func RecordAndReplay(cmd []string, wd string, quiet bool, debugInfoDirs []string, redirects [3]string) (*proc.Target, string, error) {
tracedir, err := Record(cmd, wd, quiet, redirects)
Expand Down
13 changes: 7 additions & 6 deletions pkg/proc/native/ptrace_linux_386.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ func ptraceGetRegset(tid int) (regset amd64util.AMD64Xstate, err error) {
// ptraceGetTls return the addr of tls by PTRACE_GET_THREAD_AREA for specify thread.
// See http://man7.org/linux/man-pages/man2/ptrace.2.html for detail about PTRACE_GET_THREAD_AREA.
// struct user_desc at https://golang.org/src/runtime/sys_linux_386.s
// type UserDesc struct {
// EntryNumber uint32
// BaseAddr uint32
// Limit uint32
// Flag uint32
// }
//
// type UserDesc struct {
// EntryNumber uint32
// BaseAddr uint32
// Limit uint32
// Flag uint32
// }
func ptraceGetTls(gs int32, tid int) (uint32, error) {
ud := [4]uint32{}

Expand Down
7 changes: 4 additions & 3 deletions pkg/proc/native/threads_linux_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ func (wpstate *watchpointState) set(idx uint8, addr, ctrl uint64) {
// The format of this register set is described by user_hwdebug_state in
// arch/arm64/include/uapi/asm/ptrace.h.
// It consists of one 64bit word containing:
// * 1byte number of watchpoints
// * 1byte debug architecture version (the 4 least significant bits of ID_AA64DFR0_EL1)
// * 6bytes padding
// - 1byte number of watchpoints
// - 1byte debug architecture version (the 4 least significant bits of ID_AA64DFR0_EL1)
// - 6bytes padding
//
// Followed by 2 64bit words for each watchpoint, up to a maximum of 16
// watchpoints. The first word contains the address at which the watchpoint
// is set (DBGWVRn_EL1), the second word is the control register for the
Expand Down
22 changes: 11 additions & 11 deletions pkg/proc/scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,26 @@ func TestScopeWithEscapedVariable(t *testing.T) {
}

// TestScope will:
// - run _fixtures/scopetest.go
// - set a breakpoint on all lines containing a comment
// - continue until the program ends
// - every time a breakpoint is hit it will check that
// scope.FunctionArguments+scope.LocalVariables and scope.EvalExpression
// return what the corresponding comment describes they should return and
// removes the breakpoint.
// - run _fixtures/scopetest.go
// - set a breakpoint on all lines containing a comment
// - continue until the program ends
// - every time a breakpoint is hit it will check that
// scope.FunctionArguments+scope.LocalVariables and scope.EvalExpression
// return what the corresponding comment describes they should return and
// removes the breakpoint.
//
// Each comment is a comma separated list of variable declarations, with
// each variable declaration having the following format:
//
// name type = initialvalue
// name type = initialvalue
//
// the = and the initial value are optional and can only be specified if the
// type is an integer type, float32, float64 or bool.
//
// If multiple variables with the same name are specified:
// 1. LocalVariables+FunctionArguments should return them in the same order and
// every variable except the last one should be marked as shadowed
// 2. EvalExpression should return the last one.
// 1. LocalVariables+FunctionArguments should return them in the same order and
// every variable except the last one should be marked as shadowed
// 2. EvalExpression should return the last one.
func TestScope(t *testing.T) {
if ver, _ := goversion.Parse(runtime.Version()); ver.Major >= 0 && !ver.AfterOrEqual(goversion.GoVersion{Major: 1, Minor: 9, Rev: -1}) {
return
Expand Down
35 changes: 18 additions & 17 deletions pkg/proc/target_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ func conditionErrors(threads []Thread) error {
}

// pick a new dbp.currentThread, with the following priority:
// - a thread with an active stepping breakpoint
// - a thread with an active breakpoint, prioritizing trapthread
// - trapthread
// - a thread with an active stepping breakpoint
// - a thread with an active breakpoint, prioritizing trapthread
// - trapthread
func pickCurrentThread(dbp *Target, trapthread Thread, threads []Thread) error {
for _, th := range threads {
if bp := th.Breakpoint(); bp.Active && bp.Stepping {
Expand Down Expand Up @@ -445,14 +445,14 @@ func (dbp *Target) StepInstruction() (err error) {
// once the CALL is reached.
//
// Regardless of stepInto the following breakpoints will be set:
// - a breakpoint on the first deferred function with NextDeferBreakpoint
// kind, the list of all the addresses to deferreturn calls in this function
// and condition checking that we remain on the same goroutine
// - a breakpoint on each line of the function, with a condition checking
// that we stay on the same stack frame and goroutine.
// - a breakpoint on the return address of the function, with a condition
// checking that we move to the previous stack frame and stay on the same
// goroutine.
// - a breakpoint on the first deferred function with NextDeferBreakpoint
// kind, the list of all the addresses to deferreturn calls in this function
// and condition checking that we remain on the same goroutine
// - a breakpoint on each line of the function, with a condition checking
// that we stay on the same stack frame and goroutine.
// - a breakpoint on the return address of the function, with a condition
// checking that we move to the previous stack frame and stay on the same
// goroutine.
//
// The breakpoint on the return address is *not* set if the current frame is
// an inlined call. For inlined calls topframe.Current.Fn is the function
Expand Down Expand Up @@ -957,12 +957,13 @@ func findCallInstrForRet(p Process, mem MemoryReadWriter, ret uint64, fn *Functi
}

// stepOutReverse sets a breakpoint on the CALL instruction that created the current frame, this is either:
// - the CALL instruction immediately preceding the return address of the
// current frame
// - the return address of the current frame if the current frame was
// created by a runtime.deferreturn run
// - the return address of the runtime.gopanic frame if the current frame
// was created by a panic
// - the CALL instruction immediately preceding the return address of the
// current frame
// - the return address of the current frame if the current frame was
// created by a runtime.deferreturn run
// - the return address of the runtime.gopanic frame if the current frame
// was created by a panic
//
// This function is used to implement reversed StepOut
func stepOutReverse(p *Target, topframe, retframe Stackframe, sameGCond ast.Expr) error {
curthread := p.CurrentThread()
Expand Down
Loading

0 comments on commit c412dcd

Please sign in to comment.