From 04c4b019f7557344910ade621f68e2695eabe2e5 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Tue, 20 Jun 2017 19:39:33 +0200 Subject: [PATCH] api: add FrameOffset to Stackframe (#864) Other debuggers can be instructed to decorate the stacktrace with the value of SP. Our SP equivalent is the frame offset, since we can add it to the Stackframe structure without incurring into added costs we should, so that frontends can use it if they want. --- CHANGELOG.md | 6 ++++++ pkg/terminal/command_test.go | 2 +- service/api/types.go | 5 +++-- service/debugger/debugger.go | 5 ++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f85d2838..b3118390 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ This project adheres to Semantic Versioning. All changes mention the author, unless contributed by me (@derekparker). +## [RELEASE TO BE DEFINED] DATE TO BE DEFINED + +### Added + +- Add FrameOffset field to api.Stackframe (@aarzilli) + ## [1.0.0-rc.2] DATE TO BE DEFINED ### Added diff --git a/pkg/terminal/command_test.go b/pkg/terminal/command_test.go index e22a3893..47ccaa82 100644 --- a/pkg/terminal/command_test.go +++ b/pkg/terminal/command_test.go @@ -216,7 +216,7 @@ func TestExecuteFile(t *testing.T) { func TestIssue354(t *testing.T) { printStack([]api.Stackframe{}, "") - printStack([]api.Stackframe{{api.Location{PC: 0, File: "irrelevant.go", Line: 10, Function: nil}, nil, nil}}, "") + printStack([]api.Stackframe{{api.Location{PC: 0, File: "irrelevant.go", Line: 10, Function: nil}, nil, nil, 0}}, "") } func TestIssue411(t *testing.T) { diff --git a/service/api/types.go b/service/api/types.go index aed385b1..489b3309 100644 --- a/service/api/types.go +++ b/service/api/types.go @@ -118,8 +118,9 @@ type Location struct { type Stackframe struct { Location - Locals []Variable - Arguments []Variable + Locals []Variable + Arguments []Variable + FrameOffset int64 } func (frame *Stackframe) Var(name string) *Variable { diff --git a/service/debugger/debugger.go b/service/debugger/debugger.go index 931f6e73..e88a7f0c 100644 --- a/service/debugger/debugger.go +++ b/service/debugger/debugger.go @@ -853,7 +853,10 @@ func (d *Debugger) Stacktrace(goroutineID, depth int, cfg *proc.LoadConfig) ([]a func (d *Debugger) convertStacktrace(rawlocs []proc.Stackframe, cfg *proc.LoadConfig) ([]api.Stackframe, error) { locations := make([]api.Stackframe, 0, len(rawlocs)) for i := range rawlocs { - frame := api.Stackframe{Location: api.ConvertLocation(rawlocs[i].Call)} + frame := api.Stackframe{ + Location: api.ConvertLocation(rawlocs[i].Call), + FrameOffset: rawlocs[i].CFA - int64(rawlocs[i].StackHi), + } if cfg != nil && rawlocs[i].Current.Fn != nil { var err error scope := proc.FrameToScope(d.target, rawlocs[i])