Skip to content

Commit

Permalink
fix: ci lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantxie committed Jul 10, 2024
1 parent 1b9d89f commit 611a3eb
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 107 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

Expand Down
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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).
Expand All @@ -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/).
Expand Down
24 changes: 12 additions & 12 deletions pkg/proc/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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 {
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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())
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -231,15 +231,15 @@ 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
}

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"
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/proc/heap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions pkg/proc/mem.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package proc

import (
. "github.com/go-delve/delve/pkg/proc"
"github.com/go-delve/delve/pkg/proc"
)

const cacheEnabled = true
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
42 changes: 20 additions & 22 deletions pkg/proc/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -349,7 +348,6 @@ func (s *ObjRefScope) findRef(x *ReferenceVariable, idx *pprofIndex) {
}
default:
}
return
}

var atomicPointerRegex = regexp.MustCompile(`^sync/atomic\.Pointer\[.*\]$`)
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -422,18 +420,18 @@ 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)
s.g.init(Address(lo), Address(hi))
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)
Expand Down
Loading

0 comments on commit 611a3eb

Please sign in to comment.