MCPcopy Index your code
hub / github.com/maruel/panicparse / nameArguments

Function nameArguments

stack/stack.go:804–860  ·  view source on GitHub ↗

Private stuff. nameArguments is a post-processing step where Args are 'named' with numbers.

(goroutines []*Goroutine)

Source from the content-addressed store, hash-verified

802
803// nameArguments is a post-processing step where Args are 'named' with numbers.
804func nameArguments(goroutines []*Goroutine) {
805 // Set a name for any pointer occurring more than once.
806 type object struct {
807 args []*Arg
808 inPrimary bool
809 }
810 objects := map[uint64]object{}
811 // Enumerate all the arguments.
812 primary := true
813 visit := func(arg *Arg) {
814 if arg.IsPtr {
815 objects[arg.Value] = object{
816 args: append(objects[arg.Value].args, arg),
817 inPrimary: objects[arg.Value].inPrimary || primary,
818 }
819 }
820 }
821 for i, g := range goroutines {
822 primary = i == 0
823 for _, c := range g.Stack.Calls {
824 c.Args.walk(visit)
825 }
826 // CreatedBy.Args is never set.
827 }
828 order := make(uint64Slice, 0, len(objects)/2)
829 for k, obj := range objects {
830 if len(obj.args) > 1 && obj.inPrimary {
831 order = append(order, k)
832 }
833 }
834 sort.Sort(order)
835 nextID := 1
836 for _, k := range order {
837 for _, arg := range objects[k].args {
838 arg.Name = fmt.Sprintf("#%d", nextID)
839 }
840 nextID++
841 }
842
843 // Now do the rest. This is done so the output is deterministic.
844 order = make(uint64Slice, 0, len(objects))
845 for k := range objects {
846 order = append(order, k)
847 }
848 sort.Sort(order)
849 for _, k := range order {
850 // Process the remaining pointers, they were not referenced by primary
851 // thread so will have higher IDs.
852 if objects[k].inPrimary {
853 continue
854 }
855 for _, arg := range objects[k].args {
856 arg.Name = fmt.Sprintf("#%d", nextID)
857 }
858 nextID++
859 }
860}
861

Callers 1

ScanSnapshotFunction · 0.85

Calls 1

walkMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…