From 31d7f2af1a899c77b2416bf2df06d4e04dc10848 Mon Sep 17 00:00:00 2001 From: xiezhengyao Date: Wed, 10 Jul 2024 13:41:19 +0800 Subject: [PATCH] fix: ci lint --- README.md | 5 ++++- pkg/proc/eval.go | 13 ------------- pkg/proc/objects.go | 4 +--- pkg/proc/unsafe.go | 19 ++++++------------- pkg/proc/variables.go | 22 ---------------------- 5 files changed, 11 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 6eb89da..5c7c55f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Goref [![WebSite](https://img.shields.io/website?up_message=cloudwego&url=https%3A%2F%2Fwww.cloudwego.io%2F)](https://www.cloudwego.io/) -[![License](https://img.shields.io/github/license/cloudwego/goref)](https://github.com/cloudwego/goref/blob/main/LICENSE) +[![License](https://img.shields.io/github/license/cloudwego/goref)](https://github.com/cloudwego/goref/blob/main/LICENSE-APACHE) Goref is a Go heap object reference analysis tool based on delve. It can display the space and object count distribution of Go memory references, which is helpful for efficiently locating memory leak issues or viewing persistent heap objects to optimize GC overhead. @@ -35,6 +35,9 @@ $ grf core ${execfile} ${corefile} successfully output to `grf.out` ``` +> Supported go version for executable file: go1.17 ~ go1.22.
+> Supported go version to compile the command tool: go1.21 ~ go1.22. + ## Credit Thanks to [Delve](https://github.com/go-delve/delve) for providing powerful golang debugger. \ No newline at end of file diff --git a/pkg/proc/eval.go b/pkg/proc/eval.go index 98f4a3d..7c20a81 100644 --- a/pkg/proc/eval.go +++ b/pkg/proc/eval.go @@ -37,19 +37,6 @@ const ( const fakeAddressUnresolv = 0xbeed000000000000 -type localsFlags uint8 - -const ( - // If localsTrustArgOrder is set function arguments that don't have an - // address will have one assigned by looking at their position in the argument - // list. - localsTrustArgOrder localsFlags = 1 << iota - - // If localsNoDeclLineCheck the declaration line isn't checked at - // all to determine if the variable is in scope. - localsNoDeclLineCheck -) - type myEvalScope struct { EvalScope diff --git a/pkg/proc/objects.go b/pkg/proc/objects.go index d038e36..ad2748a 100644 --- a/pkg/proc/objects.go +++ b/pkg/proc/objects.go @@ -360,9 +360,7 @@ func (s *ObjRefScope) specialStructTypes(st *godwarf.StructType) *godwarf.Struct // v *sync.readOnly nst := *st nst.Field = make([]*godwarf.StructField, len(st.Field)) - for j := range st.Field { - nst.Field[j] = st.Field[j] - } + copy(nst.Field, st.Field) nf := *nst.Field[2] nf.Type = nst.Field[0].Type.(*godwarf.ArrayType).Type nst.Field[2] = &nf diff --git a/pkg/proc/unsafe.go b/pkg/proc/unsafe.go index 4b6bfa0..0522994 100644 --- a/pkg/proc/unsafe.go +++ b/pkg/proc/unsafe.go @@ -16,7 +16,6 @@ package proc import ( "debug/dwarf" - "reflect" "unsafe" _ "unsafe" @@ -106,18 +105,12 @@ func readVarEntry(entry *godwarf.Tree, image *Image) (name string, typ godwarf.T //go:linkname newVariable github.com/go-delve/delve/pkg/proc.newVariable func newVariable(name string, addr uint64, dwarfType godwarf.Type, bi *BinaryInfo, mem MemoryReadWriter) *Variable -func uint64s2str(us []uint64) (s string) { - p := unsafe.Pointer((*reflect.SliceHeader)(unsafe.Pointer(&us)).Data) - hdr := (*reflect.StringHeader)(unsafe.Pointer(&s)) - hdr.Data = uintptr(p) - hdr.Len = len(us) * 8 - return +func uint64s2str(us []uint64) string { + p := unsafe.Pointer(unsafe.SliceData(us)) + return unsafe.String((*byte)(p), len(us)*8) } -func str2uint64s(s string) (us []uint64) { - p := unsafe.Pointer((*reflect.StringHeader)(unsafe.Pointer(&s)).Data) - hdr := (*reflect.SliceHeader)(unsafe.Pointer(&us)) - hdr.Data = uintptr(p) - hdr.Len, hdr.Cap = len(s)/8, len(s)/8 - return +func str2uint64s(s string) []uint64 { + p := unsafe.Pointer(unsafe.StringData(s)) + return unsafe.Slice((*uint64)(p), len(s)/8) } diff --git a/pkg/proc/variables.go b/pkg/proc/variables.go index 113b656..04d84c9 100644 --- a/pkg/proc/variables.go +++ b/pkg/proc/variables.go @@ -20,7 +20,6 @@ import ( "errors" "fmt" "reflect" - "strconv" "github.com/go-delve/delve/pkg/dwarf/godwarf" "github.com/go-delve/delve/pkg/goversion" @@ -595,24 +594,3 @@ func resolveTypedef(typ godwarf.Type) godwarf.Type { } } } - -func filterVariables(vars []*Variable, pred func(v *Variable) bool) []*Variable { - r := make([]*Variable, 0, len(vars)) - for i := range vars { - if pred(vars[i]) { - r = append(r, vars[i]) - } - } - return r -} - -func logPtrSize(ptrSize int) int { - switch ptrSize { - case 8: - return 3 - case 4: - return 2 - default: - panic("invalid ptrSize: " + strconv.Itoa(ptrSize)) - } -}