From 611a3eb2eb5c586b75d11f77581adb206d3208bc Mon Sep 17 00:00:00 2001 From: xiezhengyao Date: Wed, 10 Jul 2024 14:52:42 +0800 Subject: [PATCH] fix: ci lint --- .github/ISSUE_TEMPLATE/bug_report.md | 4 +-- CONTRIBUTING.md | 10 +++---- pkg/proc/eval.go | 24 ++++++++-------- pkg/proc/heap.go | 13 ++++----- pkg/proc/mem.go | 6 ++-- pkg/proc/objects.go | 42 +++++++++++++--------------- pkg/proc/protobuf.go | 32 ++++++++++----------- pkg/proc/region.go | 13 +++------ pkg/proc/unsafe.go | 30 ++++++++++---------- pkg/proc/variables.go | 32 ++++++++++----------- 10 files changed, 99 insertions(+), 107 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 9b7368d..ba00d9a 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -27,9 +27,9 @@ A clear and concise description of what you expected to happen. If applicable, add screenshots to help explain your problem. -**Kitex version:** +**Goref version:** -Please provide the version of Kitex you are using. +Please provide the version of goref you are using. **Environment:** diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e60a59e..d37a2c1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,7 +8,7 @@ We use [git-flow](https://nvie.com/posts/a-successful-git-branching-model/) as o ## Bugs ### 1. How to Find Known Issues -We are using [Github Issues](https://github.com/cloudwego/kitex/issues) for our public bugs. We keep a close eye on this and try to make it clear when we have an internal fix in progress. Before filing a new task, try to make sure your problem doesn’t already exist. +We are using [Github Issues](https://github.com/cloudwego/goref/issues) for our public bugs. We keep a close eye on this and try to make it clear when we have an internal fix in progress. Before filing a new task, try to make sure your problem doesn’t already exist. ### 2. Reporting New Issues Providing a reduced test code is a recommended way for reporting issues. Then can placed in: @@ -23,12 +23,12 @@ Please do not report the safe disclosure of bugs to public issues. Contact us by ## Submit a Pull Request Before you submit your Pull Request (PR) consider the following guidelines: -1. Search [GitHub](https://github.com/cloudwego/kitex/pulls) for an open or closed PR that relates to your submission. You don't want to duplicate existing efforts. +1. Search [GitHub](https://github.com/cloudwego/goref/pulls) for an open or closed PR that relates to your submission. You don't want to duplicate existing efforts. 2. Be sure that an issue describes the problem you're fixing, or documents the design for the feature you'd like to add. Discussing the design upfront helps to ensure that we're ready to accept your work. -3. [Fork](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) the cloudwego/kitex repo. +3. [Fork](https://docs.github.com/en/github/getting-started-with-github/fork-a-repo) the cloudwego/goref repo. 4. In your forked repository, make your changes in a new git branch: ``` - git checkout -b my-fix-branch develop + git checkout -b my-fix-branch main ``` 5. Create your patch, including appropriate test cases. 6. Follow our [Style Guides](#code-style-guides). @@ -38,7 +38,7 @@ Before you submit your Pull Request (PR) consider the following guidelines: ``` git push origin my-fix-branch ``` -9. In GitHub, send a pull request to `kitex:develop` +9. In GitHub, send a pull request to `goref:main` ## Contribution Prerequisites - Our development environment keeps up with [Go Official](https://golang.org/project/). diff --git a/pkg/proc/eval.go b/pkg/proc/eval.go index 7c20a81..5a3d35a 100644 --- a/pkg/proc/eval.go +++ b/pkg/proc/eval.go @@ -27,7 +27,7 @@ import ( "github.com/go-delve/delve/pkg/dwarf/reader" "github.com/go-delve/delve/pkg/goversion" "github.com/go-delve/delve/pkg/logflags" - . "github.com/go-delve/delve/pkg/proc" + "github.com/go-delve/delve/pkg/proc" ) const ( @@ -38,15 +38,15 @@ const ( const fakeAddressUnresolv = 0xbeed000000000000 type myEvalScope struct { - EvalScope + proc.EvalScope dictAddr uint64 // dictionary address for instantiated generic functions - enclosingRangeScopes []*EvalScope - rangeFrames []Stackframe + // enclosingRangeScopes []*proc.EvalScope + // rangeFrames []proc.Stackframe } -func (scope *myEvalScope) Locals(mds []ModuleData) ([]*ReferenceVariable, error) { +func (scope *myEvalScope) Locals(mds []proc.ModuleData) ([]*ReferenceVariable, error) { // var scopes [][]*Variable vars0, err := scope.simpleLocals(mds) if err != nil { @@ -102,7 +102,7 @@ func (scope *myEvalScope) Locals(mds []ModuleData) ([]*ReferenceVariable, error) */ } -func (scope *myEvalScope) simpleLocals(mds []ModuleData) ([]*ReferenceVariable, error) { +func (scope *myEvalScope) simpleLocals(mds []proc.ModuleData) ([]*ReferenceVariable, error) { if scope.Fn == nil { return nil, errors.New("unable to find function context") } @@ -181,7 +181,7 @@ func (scope *myEvalScope) simpleLocals(mds []ModuleData) ([]*ReferenceVariable, // Extracts the name and type of a variable from a dwarf entry // then executes the instructions given in the DW_AT_location attribute to grab the variable's address -func extractVarInfoFromEntry(bi *BinaryInfo, image *Image, regs op.DwarfRegisters, mem MemoryReadWriter, entry *godwarf.Tree, dictAddr uint64, mds []ModuleData) (*ReferenceVariable, error) { +func extractVarInfoFromEntry(bi *proc.BinaryInfo, image *proc.Image, regs op.DwarfRegisters, mem proc.MemoryReadWriter, entry *godwarf.Tree, dictAddr uint64, mds []proc.ModuleData) (*ReferenceVariable, error) { if entry.Tag != dwarf.TagFormalParameter && entry.Tag != dwarf.TagVariable { return nil, fmt.Errorf("invalid entry tag, only supports FormalParameter and Variable, got %s", entry.Tag.String()) } @@ -197,10 +197,10 @@ func extractVarInfoFromEntry(bi *BinaryInfo, image *Image, regs op.DwarfRegister logflags.DebuggerLogger().Errorf("could not resolve parametric type of %s: %v", n, err) } - addr, pieces, _, err := bi.Location(entry, dwarf.AttrLocation, regs.PC(), regs, mem) + addr, pieces, _, _ := bi.Location(entry, dwarf.AttrLocation, regs.PC(), regs, mem) uaddr := uint64(addr) if pieces != nil { - cmem, _ := CreateCompositeMemory(mem, bi.Arch, regs, pieces, t.Common().ByteSize) + cmem, _ := proc.CreateCompositeMemory(mem, bi.Arch, regs, pieces, t.Common().ByteSize) if cmem != nil { uaddr = fakeAddressUnresolv mem = cmem @@ -213,7 +213,7 @@ func extractVarInfoFromEntry(bi *BinaryInfo, image *Image, regs op.DwarfRegister // resolveParametricType returns the real type of t if t is a parametric // type, by reading the correct dictionary entry. -func resolveParametricType(bi *BinaryInfo, mem MemoryReadWriter, t godwarf.Type, dictAddr uint64, mds []ModuleData) (godwarf.Type, error) { +func resolveParametricType(bi *proc.BinaryInfo, mem proc.MemoryReadWriter, t godwarf.Type, dictAddr uint64, mds []proc.ModuleData) (godwarf.Type, error) { ptyp, _ := t.(*godwarf.ParametricType) if ptyp == nil { return t, nil @@ -231,7 +231,7 @@ func resolveParametricType(bi *BinaryInfo, mem MemoryReadWriter, t godwarf.Type, } _type := newVariable("", rtypeAddr, runtimeType, bi, mem) - typ, _, err := RuntimeTypeToDIE(_type, 0, mds) + typ, _, err := proc.RuntimeTypeToDIE(_type, 0, mds) if err != nil { return ptyp.TypedefType.Type, err } @@ -239,7 +239,7 @@ func resolveParametricType(bi *BinaryInfo, mem MemoryReadWriter, t godwarf.Type, return typ, nil } -func runtimeTypeTypename(bi *BinaryInfo) string { +func runtimeTypeTypename(bi *proc.BinaryInfo) string { if goversion.ProducerAfterOrEqual(bi.Producer(), 1, 21) { return "internal/abi.Type" } diff --git a/pkg/proc/heap.go b/pkg/proc/heap.go index 9b4e67f..f8f5c16 100644 --- a/pkg/proc/heap.go +++ b/pkg/proc/heap.go @@ -21,7 +21,7 @@ import ( "math/bits" "github.com/go-delve/delve/pkg/logflags" - . "github.com/go-delve/delve/pkg/proc" + "github.com/go-delve/delve/pkg/proc" ) type spanInfo struct { @@ -118,11 +118,11 @@ type HeapScope struct { finalizers []finalizer - mds []ModuleData + mds []proc.ModuleData - mem MemoryReadWriter - bi *BinaryInfo - scope *EvalScope + mem proc.MemoryReadWriter + bi *proc.BinaryInfo + scope *proc.EvalScope finalMarks []finalMarkParam } @@ -379,7 +379,7 @@ func (s *HeapScope) readOneBitBitmap(bitmap *region, min Address) { } // TODO: use bitmapMask to speed up memory lookup. -const bitmapMask uint64 = 0xf0f0f0f0f0f0f0f0 +// const bitmapMask uint64 = 0xf0f0f0f0f0f0f0f0 // Read a multi-bit bitmap (Go 1.11-1.20), recording the heap pointers. func (s *HeapScope) readMultiBitBitmap(bitmap *region, min Address) { @@ -480,7 +480,6 @@ func (hb *heapBits) resetGCMask(addr Address) { // TODO: check gc mask offset := addr.Sub(hb.sp.base) hb.sp.ptrMask[offset/8/64] &= ^(1 << (offset / 8 % 64)) - return } // nextPtr returns next ptr address starts from 'addr', returns 0 if not found. diff --git a/pkg/proc/mem.go b/pkg/proc/mem.go index 03953eb..0769f6c 100644 --- a/pkg/proc/mem.go +++ b/pkg/proc/mem.go @@ -16,7 +16,7 @@ package proc import ( - . "github.com/go-delve/delve/pkg/proc" + "github.com/go-delve/delve/pkg/proc" ) const cacheEnabled = true @@ -25,7 +25,7 @@ type memCache struct { loaded bool cacheAddr uint64 cache []byte - mem MemoryReadWriter + mem proc.MemoryReadWriter } func (m *memCache) contains(addr uint64, size int) bool { @@ -57,7 +57,7 @@ func (m *memCache) WriteMemory(addr uint64, data []byte) (written int, err error return m.mem.WriteMemory(addr, data) } -func cacheMemory(mem MemoryReadWriter, addr uint64, size int) MemoryReadWriter { +func cacheMemory(mem proc.MemoryReadWriter, addr uint64, size int) proc.MemoryReadWriter { if !cacheEnabled { return mem } diff --git a/pkg/proc/objects.go b/pkg/proc/objects.go index ad2748a..8850cfd 100644 --- a/pkg/proc/objects.go +++ b/pkg/proc/objects.go @@ -21,10 +21,9 @@ import ( "regexp" "strconv" - "github.com/go-delve/delve/pkg/logflags" - . "github.com/go-delve/delve/pkg/proc" - "github.com/go-delve/delve/pkg/dwarf/godwarf" + "github.com/go-delve/delve/pkg/logflags" + "github.com/go-delve/delve/pkg/proc" ) const maxRefDepth = 256 @@ -38,7 +37,7 @@ type ObjRefScope struct { g *stack } -func (s *ObjRefScope) findObject(addr Address, typ godwarf.Type, mem MemoryReadWriter) (v *ReferenceVariable) { +func (s *ObjRefScope) findObject(addr Address, typ godwarf.Type, mem proc.MemoryReadWriter) (v *ReferenceVariable) { sp, base := s.findSpanAndBase(addr) if sp == nil { // not in heap @@ -79,7 +78,7 @@ func (s *ObjRefScope) findObject(addr Address, typ godwarf.Type, mem MemoryReadW return } -func (s *HeapScope) markObject(addr Address, mem MemoryReadWriter) (size, count int64) { +func (s *HeapScope) markObject(addr Address, mem proc.MemoryReadWriter) (size, count int64) { sp, base := s.findSpanAndBase(addr) if sp == nil { return // not found @@ -166,7 +165,7 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) { if err != nil { return } - if y := s.findObject(Address(ptrval), resolveTypedef(typ.Type), DereferenceMemory(x.mem)); y != nil { + if y := s.findObject(Address(ptrval), resolveTypedef(typ.Type), proc.DereferenceMemory(x.mem)); y != nil { s.findRef(y, idx) // flatten reference x.size += y.size @@ -177,7 +176,7 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) { if err != nil { return } - if y := s.findObject(Address(ptrval), resolveTypedef(typ.Type.(*godwarf.PtrType).Type), DereferenceMemory(x.mem)); y != nil { + if y := s.findObject(Address(ptrval), resolveTypedef(typ.Type.(*godwarf.PtrType).Type), proc.DereferenceMemory(x.mem)); y != nil { x.size += y.size x.count += y.count @@ -208,7 +207,7 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) { if err != nil { return } - if y := s.findObject(Address(ptrval), resolveTypedef(typ.Type.(*godwarf.PtrType).Type), DereferenceMemory(x.mem)); y != nil { + if y := s.findObject(Address(ptrval), resolveTypedef(typ.Type.(*godwarf.PtrType).Type), proc.DereferenceMemory(x.mem)); y != nil { it, err := s.toMapIterator(y) if err != nil { logflags.DebuggerLogger().Errorf("toMapIterator failed: %v", err) @@ -232,7 +231,7 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) { if err != nil { return } - if y := s.findObject(Address(strAddr), fakeArrayType(uint64(strLen), &godwarf.UintType{BasicType: godwarf.BasicType{CommonType: godwarf.CommonType{ByteSize: 1, Name: "byte", ReflectKind: reflect.Uint8}, BitSize: 8, BitOffset: 0}}), DereferenceMemory(x.mem)); y != nil { + if y := s.findObject(Address(strAddr), fakeArrayType(uint64(strLen), &godwarf.UintType{BasicType: godwarf.BasicType{CommonType: godwarf.CommonType{ByteSize: 1, Name: "byte", ReflectKind: reflect.Uint8}, BitSize: 8, BitOffset: 0}}), proc.DereferenceMemory(x.mem)); y != nil { s.findRef(y, idx) x.size += y.size x.count += y.count @@ -251,7 +250,7 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) { cap_, _ = readUintRaw(x.mem, uint64(int64(x.Addr)+f.ByteOffset), f.Type.Size()) } } - if y := s.findObject(Address(base), fakeArrayType(cap_, typ.ElemType), DereferenceMemory(x.mem)); y != nil { + if y := s.findObject(Address(base), fakeArrayType(cap_, typ.ElemType), proc.DereferenceMemory(x.mem)); y != nil { s.findRef(y, idx) x.size += y.size x.count += y.count @@ -267,7 +266,7 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) { } var ityp godwarf.Type if _type != nil { - rtyp, kind, err := RuntimeTypeToDIE(_type, uint64(data.Addr), s.mds) + rtyp, kind, err := proc.RuntimeTypeToDIE(_type, uint64(data.Addr), s.mds) if err == nil { if kind&kindDirectIface == 0 { if _, isptr := resolveTypedef(rtyp).(*godwarf.PtrType); !isptr { @@ -282,7 +281,7 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) { if ityp == nil { ityp = new(godwarf.VoidType) } - if y := s.findObject(Address(ptrval), ityp, DereferenceMemory(x.mem)); y != nil { + if y := s.findObject(Address(ptrval), ityp, proc.DereferenceMemory(x.mem)); y != nil { s.findRef(y, idx) x.size += y.size x.count += y.count @@ -324,7 +323,7 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) { return } var cst godwarf.Type - funcAddr, err := readUintRaw(DereferenceMemory(x.mem), closureAddr, int64(s.bi.Arch.PtrSize())) + funcAddr, err := readUintRaw(proc.DereferenceMemory(x.mem), closureAddr, int64(s.bi.Arch.PtrSize())) if err == nil && funcAddr != 0 { if fn := s.bi.PCToFunc(funcAddr); fn != nil { // cst := extra(fn, s.bi).closureStructType @@ -336,7 +335,7 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) { if cst == nil { cst = new(godwarf.VoidType) } - if closure := s.findObject(Address(closureAddr), cst, DereferenceMemory(x.mem)); closure != nil { + if closure := s.findObject(Address(closureAddr), cst, proc.DereferenceMemory(x.mem)); closure != nil { s.findRef(closure, idx) x.size += closure.size x.count += closure.count @@ -349,7 +348,6 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) { } default: } - return } var atomicPointerRegex = regexp.MustCompile(`^sync/atomic\.Pointer\[.*\]$`) @@ -379,12 +377,12 @@ func isPrimitiveType(typ godwarf.Type) bool { return false } -var loadSingleValue = LoadConfig{} +var loadSingleValue = proc.LoadConfig{} // ObjectReference scanning goroutine stack and global vars to search all heap objects they reference, // and outputs the reference relationship to the filename with pprof format. -func ObjectReference(t *Target, filename string) error { - scope, err := ThreadScope(t, t.CurrentThread()) +func ObjectReference(t *proc.Target, filename string) error { + scope, err := proc.ThreadScope(t, t.CurrentThread()) if err != nil { return err } @@ -405,7 +403,7 @@ func ObjectReference(t *Target, filename string) error { pb: newProfileBuilder(f), } - mds, err := LoadModuleData(t.BinInfo(), t.Memory()) + mds, err := proc.LoadModuleData(t.BinInfo(), t.Memory()) if err != nil { return err } @@ -422,7 +420,7 @@ func ObjectReference(t *Target, filename string) error { // Local variables threadID := t.CurrentThread().ThreadID() - grs, _, _ := GoroutinesInfo(t, 0, 0) + grs, _, _ := proc.GoroutinesInfo(t, 0, 0) for _, gr := range grs { s.g = &stack{} lo, hi := getStack(gr) @@ -430,10 +428,10 @@ func ObjectReference(t *Target, filename string) error { if gr.Thread != nil { threadID = gr.Thread.ThreadID() } - sf, _ := GoroutineStacktrace(t, gr, 1024, 0) + sf, _ := proc.GoroutineStacktrace(t, gr, 1024, 0) if len(sf) > 0 { for i := range sf { - ms := myEvalScope{EvalScope: *FrameToScope(t, t.Memory(), gr, threadID, sf[i:]...)} + ms := myEvalScope{EvalScope: *proc.FrameToScope(t, t.Memory(), gr, threadID, sf[i:]...)} locals, err := ms.Locals(mds) if err != nil { logflags.DebuggerLogger().Errorf("local variables err: %v", err) diff --git a/pkg/proc/protobuf.go b/pkg/proc/protobuf.go index 78f802f..e329d60 100644 --- a/pkg/proc/protobuf.go +++ b/pkg/proc/protobuf.go @@ -36,7 +36,7 @@ func (b *protobuf) length(tag int, len int) { func (b *protobuf) uint64(tag int, x uint64) { // append varint to b.data - b.varint(uint64(tag)<<3 | 0) + b.varint(uint64(tag) << 3) b.varint(x) } @@ -110,12 +110,12 @@ func (b *protobuf) strings(tag int, x []string) { } } -func (b *protobuf) stringOpt(tag int, x string) { - if x == "" { - return - } - b.string(tag, x) -} +//func (b *protobuf) stringOpt(tag int, x string) { +// if x == "" { +// return +// } +// b.string(tag, x) +//} func (b *protobuf) bool(tag int, x bool) { if x { @@ -125,12 +125,12 @@ func (b *protobuf) bool(tag int, x bool) { } } -func (b *protobuf) boolOpt(tag int, x bool) { - if !x { - return - } - b.bool(tag, x) -} +//func (b *protobuf) boolOpt(tag int, x bool) { +// if !x { +// return +// } +// b.bool(tag, x) +//} type msgOffset int @@ -177,9 +177,9 @@ const ( tagSample_Label = 3 // repeated Label // message Label - tagLabel_Key = 1 // int64 (string table index) - tagLabel_Str = 2 // int64 (string table index) - tagLabel_Num = 3 // int64 + // tagLabel_Key = 1 // int64 (string table index) + // tagLabel_Str = 2 // int64 (string table index) + // tagLabel_Num = 3 // int64 // message Mapping tagMapping_ID = 1 // uint64 diff --git a/pkg/proc/region.go b/pkg/proc/region.go index e66a66f..ae2d0d3 100644 --- a/pkg/proc/region.go +++ b/pkg/proc/region.go @@ -11,10 +11,10 @@ package proc import ( "github.com/go-delve/delve/pkg/dwarf/godwarf" - . "github.com/go-delve/delve/pkg/proc" + "github.com/go-delve/delve/pkg/proc" ) -func toRegion(v *Variable, bi *BinaryInfo) *region { +func toRegion(v *proc.Variable, bi *proc.BinaryInfo) *region { return ®ion{ mem: getVariableMem(v), bi: bi, @@ -28,17 +28,12 @@ func toRegion(v *Variable, bi *BinaryInfo) *region { // Note that it is the type of the thing in the region, // not the type of the reference to the region. type region struct { - mem MemoryReadWriter - bi *BinaryInfo + mem proc.MemoryReadWriter + bi *proc.BinaryInfo a Address typ godwarf.Type } -func (r *region) clone() *region { - nr := *r - return &nr -} - // Address returns the address that a region of pointer type points to. func (r *region) Address() Address { switch t := r.typ.(type) { diff --git a/pkg/proc/unsafe.go b/pkg/proc/unsafe.go index 0522994..b51cbeb 100644 --- a/pkg/proc/unsafe.go +++ b/pkg/proc/unsafe.go @@ -20,7 +20,7 @@ import ( _ "unsafe" "github.com/go-delve/delve/pkg/dwarf/godwarf" - . "github.com/go-delve/delve/pkg/proc" + "github.com/go-delve/delve/pkg/proc" "github.com/modern-go/reflect2" ) @@ -38,32 +38,32 @@ var ( ) func init() { - vt := reflect2.TypeOf(Variable{}).(reflect2.StructType) + vt := reflect2.TypeOf(proc.Variable{}).(reflect2.StructType) memField = vt.FieldByName("mem") - gt := reflect2.TypeOf(G{}).(reflect2.StructType) + gt := reflect2.TypeOf(proc.G{}).(reflect2.StructType) stackField = gt.FieldByName("stack") - st := reflect2.TypeOf(stackField.Get(&G{})).(reflect2.PtrType).Elem().(reflect2.StructType) + st := reflect2.TypeOf(stackField.Get(&proc.G{})).(reflect2.PtrType).Elem().(reflect2.StructType) stackLoField = st.FieldByName("lo") stackHiField = st.FieldByName("hi") - ft := reflect2.TypeOf(Function{}).(reflect2.StructType) + ft := reflect2.TypeOf(proc.Function{}).(reflect2.StructType) offsetField = ft.FieldByName("offset") } -func getVariableMem(v *Variable) MemoryReadWriter { - return *memField.Get(v).(*MemoryReadWriter) +func getVariableMem(v *proc.Variable) proc.MemoryReadWriter { + return *memField.Get(v).(*proc.MemoryReadWriter) } -func getStack(g *G) (lo, hi uint64) { +func getStack(g *proc.G) (lo, hi uint64) { stack := stackField.Get(g) lo = *stackLoField.Get(stack).(*uint64) hi = *stackHiField.Get(stack).(*uint64) return } -func getFunctionOffset(f *Function) (offset dwarf.Offset) { +func getFunctionOffset(f *proc.Function) (offset dwarf.Offset) { return *offsetField.Get(f).(*dwarf.Offset) } @@ -88,22 +88,22 @@ func extra(f *Function, bi *BinaryInfo) (e *functionExtra) */ //go:linkname image github.com/go-delve/delve/pkg/proc.(*EvalScope).image -func image(scope *EvalScope) *Image +func image(scope *proc.EvalScope) *proc.Image //go:linkname getDwarfTree github.com/go-delve/delve/pkg/proc.(*Image).getDwarfTree -func getDwarfTree(image *Image, off dwarf.Offset) (*godwarf.Tree, error) +func getDwarfTree(image *proc.Image, off dwarf.Offset) (*godwarf.Tree, error) //go:linkname findType github.com/go-delve/delve/pkg/proc.(*BinaryInfo).findType -func findType(bi *BinaryInfo, name string) (godwarf.Type, error) +func findType(bi *proc.BinaryInfo, name string) (godwarf.Type, error) //go:linkname rangeParentName github.com/go-delve/delve/pkg/proc.(*Function).rangeParentName -func rangeParentName(fn *Function) string +func rangeParentName(fn *proc.Function) string //go:linkname readVarEntry github.com/go-delve/delve/pkg/proc.readVarEntry -func readVarEntry(entry *godwarf.Tree, image *Image) (name string, typ godwarf.Type, err error) +func readVarEntry(entry *godwarf.Tree, image *proc.Image) (name string, typ godwarf.Type, err error) //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 newVariable(name string, addr uint64, dwarfType godwarf.Type, bi *proc.BinaryInfo, mem proc.MemoryReadWriter) *proc.Variable func uint64s2str(us []uint64) string { p := unsafe.Pointer(unsafe.SliceData(us)) diff --git a/pkg/proc/variables.go b/pkg/proc/variables.go index 04d84c9..0cbca4e 100644 --- a/pkg/proc/variables.go +++ b/pkg/proc/variables.go @@ -24,7 +24,7 @@ import ( "github.com/go-delve/delve/pkg/dwarf/godwarf" "github.com/go-delve/delve/pkg/goversion" "github.com/go-delve/delve/pkg/logflags" - . "github.com/go-delve/delve/pkg/proc" + "github.com/go-delve/delve/pkg/proc" ) const ( @@ -55,7 +55,7 @@ type ReferenceVariable struct { Addr Address Name string RealType godwarf.Type - mem MemoryReadWriter + mem proc.MemoryReadWriter // heap bits for this object // hb.base equals to Addr, hb.end equals to min(Addr.Add(RealType.Size), heapBase.Add(elemSize)) @@ -67,11 +67,11 @@ type ReferenceVariable struct { count int64 } -func newReferenceVariable(addr Address, name string, typ godwarf.Type, mem MemoryReadWriter, hb *heapBits) *ReferenceVariable { +func newReferenceVariable(addr Address, name string, typ godwarf.Type, mem proc.MemoryReadWriter, hb *heapBits) *ReferenceVariable { return &ReferenceVariable{Addr: addr, Name: name, RealType: typ, mem: mem, hb: hb} } -func newReferenceVariableWithSizeAndCount(addr Address, name string, typ godwarf.Type, mem MemoryReadWriter, hb *heapBits, size, count int64) *ReferenceVariable { +func newReferenceVariableWithSizeAndCount(addr Address, name string, typ godwarf.Type, mem proc.MemoryReadWriter, hb *heapBits, size, count int64) *ReferenceVariable { rv := newReferenceVariable(addr, name, typ, mem, hb) rv.size, rv.count = size, count return rv @@ -92,7 +92,7 @@ func (v *ReferenceVariable) isValid(addr Address) bool { } type mapIterator struct { - bi *BinaryInfo + bi *proc.BinaryInfo numbuckets uint64 oldmask uint64 buckets *ReferenceVariable @@ -148,9 +148,9 @@ func (s *ObjRefScope) toMapIterator(hmap *ReferenceVariable) (it *mapIterator, e if err != nil { return } - buckets := s.findObject(Address(ptr), resolveTypedef(f.Type.(*godwarf.PtrType).Type), DereferenceMemory(hmap.mem)) + buckets := s.findObject(Address(ptr), resolveTypedef(f.Type.(*godwarf.PtrType).Type), proc.DereferenceMemory(hmap.mem)) if buckets == nil { - buckets = newReferenceVariable(Address(ptr), "", resolveTypedef(f.Type.(*godwarf.PtrType).Type), DereferenceMemory(hmap.mem), nil) + buckets = newReferenceVariable(Address(ptr), "", resolveTypedef(f.Type.(*godwarf.PtrType).Type), proc.DereferenceMemory(hmap.mem), nil) } buckets.Name = "buckets" it.buckets = buckets @@ -162,9 +162,9 @@ func (s *ObjRefScope) toMapIterator(hmap *ReferenceVariable) (it *mapIterator, e if err != nil { return } - oldbuckets := s.findObject(Address(ptr), resolveTypedef(f.Type.(*godwarf.PtrType).Type), DereferenceMemory(hmap.mem)) + oldbuckets := s.findObject(Address(ptr), resolveTypedef(f.Type.(*godwarf.PtrType).Type), proc.DereferenceMemory(hmap.mem)) if oldbuckets == nil { - oldbuckets = newReferenceVariable(Address(ptr), "", resolveTypedef(f.Type.(*godwarf.PtrType).Type), DereferenceMemory(hmap.mem), nil) + oldbuckets = newReferenceVariable(Address(ptr), "", resolveTypedef(f.Type.(*godwarf.PtrType).Type), proc.DereferenceMemory(hmap.mem), nil) } oldbuckets.Name = "oldbuckets" it.oldbuckets = oldbuckets @@ -272,7 +272,7 @@ func (s *ObjRefScope) nextBucket(it *mapIterator) bool { logflags.DebuggerLogger().Errorf("could not load overflow variable: %v", err) return false } - if it.overflow = s.findObject(Address(ptr), field.RealType.(*godwarf.PtrType).Type, DereferenceMemory(it.b.mem)); it.overflow != nil { + if it.overflow = s.findObject(Address(ptr), field.RealType.(*godwarf.PtrType).Type, proc.DereferenceMemory(it.b.mem)); it.overflow != nil { it.count += it.overflow.count it.size += it.overflow.size } @@ -384,7 +384,7 @@ func (it *mapIterator) mapEvacuated(b *ReferenceVariable) bool { return true } -func (s *ObjRefScope) readInterface(v *ReferenceVariable) (_type *Variable, data *ReferenceVariable, isnil bool) { +func (s *ObjRefScope) readInterface(v *ReferenceVariable) (_type *proc.Variable, data *ReferenceVariable, isnil bool) { // An interface variable is implemented either by a runtime.iface // struct or a runtime.eface struct. The difference being that empty // interfaces (i.e. "interface {}") are represented by runtime.eface @@ -418,7 +418,7 @@ func (s *ObjRefScope) readInterface(v *ReferenceVariable) (_type *Variable, data continue } // +rtype *itab|*internal/abi.ITab - tab := newReferenceVariable(Address(ptr), "", resolveTypedef(f.Type.(*godwarf.PtrType).Type), DereferenceMemory(v.mem), nil) + tab := newReferenceVariable(Address(ptr), "", resolveTypedef(f.Type.(*godwarf.PtrType).Type), proc.DereferenceMemory(v.mem), nil) isnil = tab.Addr == 0 if !isnil { for _, tf := range tab.RealType.(*godwarf.StructType).Field { @@ -461,7 +461,7 @@ type finalizePtrType struct { godwarf.Type } -func readIntRaw(mem MemoryReadWriter, addr uint64, size int64) (int64, error) { +func readIntRaw(mem proc.MemoryReadWriter, addr uint64, size int64) (int64, error) { var n int64 val := make([]byte, int(size)) @@ -484,7 +484,7 @@ func readIntRaw(mem MemoryReadWriter, addr uint64, size int64) (int64, error) { return n, nil } -func readUintRaw(mem MemoryReadWriter, addr uint64, size int64) (uint64, error) { +func readUintRaw(mem proc.MemoryReadWriter, addr uint64, size int64) (uint64, error) { var n uint64 val := make([]byte, int(size)) @@ -507,7 +507,7 @@ func readUintRaw(mem MemoryReadWriter, addr uint64, size int64) (uint64, error) return n, nil } -func readUint64Array(mem MemoryReadWriter, addr uint64, res []uint64) (err error) { +func readUint64Array(mem proc.MemoryReadWriter, addr uint64, res []uint64) (err error) { val := make([]byte, len(res)*8) _, err = mem.ReadMemory(val, addr) if err != nil { @@ -570,7 +570,7 @@ func fakeArrayType(n uint64, fieldType godwarf.Type) godwarf.Type { } } -func pointerTo(typ godwarf.Type, arch *Arch) godwarf.Type { +func pointerTo(typ godwarf.Type, arch *proc.Arch) godwarf.Type { return &godwarf.PtrType{ CommonType: godwarf.CommonType{ ByteSize: int64(arch.PtrSize()),