From 77c955365f4d32745f6598f47c05833feef1ba8f Mon Sep 17 00:00:00 2001 From: aarzilli Date: Mon, 4 Dec 2017 11:05:05 +0100 Subject: [PATCH] proc: handle DW_TAG_subprogram with a nochildren abbrev On macOS, externally linked programs will have an abbrev for DW_TAG_subprogram without the haschildren flag set. We should handle this case instead of expecting all DW_TAG_subprogram entries to have list of children. Fixes #1034 --- pkg/dwarf/reader/variables.go | 2 +- pkg/proc/proc_test.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/dwarf/reader/variables.go b/pkg/dwarf/reader/variables.go index 78705842..8c6852b7 100644 --- a/pkg/dwarf/reader/variables.go +++ b/pkg/dwarf/reader/variables.go @@ -55,7 +55,7 @@ func (vrdr *VariableReader) Next() bool { } } - if recur { + if recur && vrdr.entry.Children { vrdr.depth++ } else { if vrdr.depth == 0 { diff --git a/pkg/proc/proc_test.go b/pkg/proc/proc_test.go index 0213ac42..6d4a1f5e 100644 --- a/pkg/proc/proc_test.go +++ b/pkg/proc/proc_test.go @@ -3337,3 +3337,21 @@ func TestSystemstackStacktrace(t *testing.T) { } }) } + +func TestIssue1034(t *testing.T) { + // The external linker on macOS produces an abbrev for DW_TAG_subprogram + // without the "has children" flag, we should support this. + withTestProcess("cgostacktest/", t, func(p proc.Process, fixture protest.Fixture) { + _, err := setFunctionBreakpoint(p, "main.main") + assertNoError(err, t, "setFunctionBreakpoint()") + assertNoError(proc.Continue(p), t, "Continue()") + frames, err := p.SelectedGoroutine().Stacktrace(10) + assertNoError(err, t, "Stacktrace") + scope := proc.FrameToScope(p, frames[2]) + args, _ := scope.FunctionArguments(normalLoadConfig) + assertNoError(err, t, "FunctionArguments()") + if len(args) > 0 { + t.Fatalf("wrong number of arguments for frame %v (%d)", frames[2], len(args)) + } + }) +} -- GitLab