Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cmd/stackwhere/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ func (psl *programStackList) runListProgram(cmd *cobra.Command, args []string) e

w := cmd.OutOrStdout()
for _, slots := range usage {
if !*psl.flagCallStack {
slots = slices.CompactFunc(slices.Clone(slots), func(a, b slotUsage) bool {
return a.displayEqual(b)
})
}

if _, err := fmt.Fprintf(w, "R10-%d:\n", slots[0].Offset); err != nil {
return err
}
Expand Down Expand Up @@ -215,6 +221,10 @@ type slotUsage struct {
Callstack []callStackEntry `json:"callstack,omitempty"`
}

func (s slotUsage) displayEqual(other slotUsage) bool {
return s.Name == other.Name && s.ByteSize == other.ByteSize && s.FileLineCol == other.FileLineCol
}

type callStackEntry struct {
Name string `json:"name"`
FileLineCol string `json:"file_line_col"`
Expand Down
26 changes: 26 additions & 0 deletions cmd/stackwhere/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,32 @@ func TestListProgramWritesToConfiguredOutput(t *testing.T) {
if !strings.Contains(got, "32 - a @") {
t.Fatalf("expected stack slot details in configured writer, got %q", got)
}
if strings.Count(got, "16 - two_inlined_a @ /src/basic.c:81") != 1 {
t.Fatalf("expected duplicate inline rows to be suppressed in default output, got %q", got)
}
if strings.Count(got, "16 - two_inlined_b @ /src/basic.c:75") != 1 {
t.Fatalf("expected duplicate inline rows to be suppressed in default output, got %q", got)
}
}

func TestListProgramCallStackPreservesDistinctInlineCallSites(t *testing.T) {
cmd := root()
cmd.SetArgs([]string{"list", "../../testdata/basic.o", "cil_entry", "--call-stack"})

var stdout bytes.Buffer
cmd.SetOut(&stdout)

if err := cmd.Execute(); err != nil {
t.Fatalf("list command failed: %v", err)
}

got := stdout.String()
if strings.Count(got, "16 - two_inlined_a @ /src/basic.c:81") != 2 {
t.Fatalf("expected both inline call sites in call-stack output, got %q", got)
}
if !strings.Contains(got, "inlined_a @ /src/basic.c:93:9") || !strings.Contains(got, "inlined_a @ /src/basic.c:103:9") {
t.Fatalf("expected both inline call stacks in output, got %q", got)
}
}

func TestSortedProgramStackUsageOrdersEqualUsageByName(t *testing.T) {
Expand Down