From 081d2e58c6a9b616b5fc3f19b4ce3850d0f398d8 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Thu, 21 Sep 2023 01:35:48 +0200 Subject: [PATCH] interp: print LLVM instruction in traceback The old traceback would look like this: # internal/godebug /usr/local/go/src/internal/godebug/godebug.go:101:11: interp: test call <2> 0 <3> 0 traceback: /usr/local/go/src/internal/godebug/godebug.go:101:11: call <2> 0 <3> 0 /usr/local/go/src/internal/godebug: call <1> 0 With this patch, it looks like this: # io/fs /usr/local/go/src/io/fs/fs.go:144:45: interp: test %0 = load %runtime._interface, ptr @"internal/oserror.ErrInvalid", align 8, !dbg !316 traceback: /usr/local/go/src/io/fs/fs.go:144:45: %0 = load %runtime._interface, ptr @"internal/oserror.ErrInvalid", align 8, !dbg !316 /usr/local/go/src/io/fs/fs.go:137:28: %0 = call %runtime._interface @"io/fs.errInvalid"(ptr undef), !dbg !317 For developers (like me) who are familiar with LLVM, this is probably easier to read. For users, I'm not sure: the instructions have quite a lot of distracting fluff in them. But at least it contains the function names that are called (which are not currently present in the old traceback). ...that said, having the LLVM instructions in a bug report is probably going to be easier for people who are familar with LLVM. --- go.mod | 2 +- go.sum | 4 ++-- interp/errors.go | 4 ++-- interp/interpreter.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 9af3402bad..48049c88ef 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( golang.org/x/sys v0.11.0 golang.org/x/tools v0.12.0 gopkg.in/yaml.v2 v2.4.0 - tinygo.org/x/go-llvm v0.0.0-20230918183930-9edb6403d0bc + tinygo.org/x/go-llvm v0.0.0-20230920233244-32ed56c6be9c ) require ( diff --git a/go.sum b/go.sum index 587efdf2ac..b895ee1d8c 100644 --- a/go.sum +++ b/go.sum @@ -65,5 +65,5 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -tinygo.org/x/go-llvm v0.0.0-20230918183930-9edb6403d0bc h1:IVX1dqCX3c88P7iEMBtz1xCAM4UIqCMgbqHdSefBaWE= -tinygo.org/x/go-llvm v0.0.0-20230918183930-9edb6403d0bc/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= +tinygo.org/x/go-llvm v0.0.0-20230920233244-32ed56c6be9c h1:rS8mAFqf0CfxPCbtfsI3bWL4jkb0TBYA1wx7tY1nu28= +tinygo.org/x/go-llvm v0.0.0-20230920233244-32ed56c6be9c/go.mod h1:GFbusT2VTA4I+l4j80b17KFK+6whv69Wtny5U+T8RR0= diff --git a/interp/errors.go b/interp/errors.go index 7aad39fb8f..551a18d481 100644 --- a/interp/errors.go +++ b/interp/errors.go @@ -60,10 +60,10 @@ func (r *runner) errorAt(inst instruction, err error) *Error { pos := getPosition(inst.llvmInst) return &Error{ ImportPath: r.pkgName, - Inst: inst.String(), + Inst: inst.llvmInst.String(), Pos: pos, Err: err, - Traceback: []ErrorLine{{pos, inst.String()}}, + Traceback: []ErrorLine{{pos, inst.llvmInst.String()}}, } } diff --git a/interp/interpreter.go b/interp/interpreter.go index dcea0044a9..3150aca93b 100644 --- a/interp/interpreter.go +++ b/interp/interpreter.go @@ -543,7 +543,7 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent // how this function got called. callErr.Traceback = append(callErr.Traceback, ErrorLine{ Pos: getPosition(inst.llvmInst), - Inst: inst.String(), + Inst: inst.llvmInst.String(), }) return nil, mem, callErr }