Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pkg/errors): correct stacktraces for inlined functions #901

Merged
merged 3 commits into from
Jun 22, 2023

Conversation

thehowl
Copy link
Member

@thehowl thehowl commented Jun 15, 2023

bugs found after hunting down other bugs in #859...

see before vs after stacktrace, make _test.gnolang.stdlibs on a function which calls panic() in gno code

OLD
Stack Trace:
    0  /home/howl/oc/gno/tm2/pkg/errors/errors.go:14
    1  /home/howl/oc/gno/gnovm/pkg/gnolang/preprocess.go:2851
    2  /usr/lib/go/src/runtime/panic.go:884
    3  /home/howl/oc/gno/tm2/pkg/errors/errors.go:86
    4  /usr/lib/go/src/runtime/panic.go:884
    5  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:1567
    6  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:1037
    7  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:1037
    8  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:727
    9  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:505
   10  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:499
   11  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:517
   12  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:226
   13  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:248
   14  /home/howl/oc/gno/gnovm/tests/imports.go:108
   15  /home/howl/oc/gno/gnovm/pkg/gnolang/store.go:162
   16  /home/howl/oc/gno/gnovm/pkg/gnolang/preprocess.go:2967
   17  /home/howl/oc/gno/gnovm/pkg/gnolang/preprocess.go:2871
   18  /home/howl/oc/gno/gnovm/pkg/gnolang/preprocess.go:2859

NEW
Stack Trace:
    0  /home/howl/oc/gno/tm2/pkg/errors/errors.go:14
    1  /home/howl/oc/gno/gnovm/pkg/gnolang/preprocess.go:2851
    2  /usr/lib/go/src/runtime/panic.go:884
    3  /home/howl/oc/gno/gnovm/pkg/gnolang/preprocess.go:2854
    4  /usr/lib/go/src/runtime/panic.go:884
    5  /home/howl/oc/gno/gnovm/pkg/gnolang/uverse.go:911
    6  /home/howl/oc/gno/gnovm/pkg/gnolang/op_call.go:162
    7  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:1037
    8  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:736
    9  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:504
   10  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:498
   11  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:498
   12  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:518
   13  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:391
   14  /home/howl/oc/gno/gnovm/pkg/gnolang/machine.go:248
   15  /home/howl/oc/gno/gnovm/tests/imports.go:108
   16  /home/howl/oc/gno/gnovm/pkg/gnolang/store.go:162
   17  /home/howl/oc/gno/gnovm/pkg/gnolang/preprocess.go:2967
   18  /home/howl/oc/gno/gnovm/pkg/gnolang/preprocess.go:2870
   19  /home/howl/oc/gno/gnovm/pkg/gnolang/preprocess.go:2859

Note that the new stacktrace adds the call to uverse.go and op_call.go, absent in the old one. This helps make sense of the stacktrace, which otherwise jumps to places that don't make sense in context. Ie.

machine.go:1037
// func (m *Machine) Run() {
			m.doOpCallNativeBody()

OLD
machine.go:1567
// func (m *Machine) LastBlock() *Block {
	return m.Blocks[len(m.Blocks)-1]

NEW
op_call.go:162
// func (m *Machine) doOpCallNativeBody() {
	m.LastFrame().Func.nativeBody(m)
uverse.go:911
//	defNative("panic", ...
			panic(xv.Sprint(m))

The changes respect what godoc says about using runtime.Callers:

To translate these PCs into symbolic information such as function names
and line numbers, use CallersFrames. CallersFrames accounts for inlined
functions and adjusts the return program counters into call program
counters. Iterating over the returned slice of PCs directly is discouraged,
as is using FuncForPC on any of the returned PCs, since these cannot account
for inlining or return program counter adjustment.

@github-actions github-actions bot added the 📦 🌐 tendermint v2 Issues or PRs tm2 related label Jun 15, 2023
tm2/pkg/errors/errors.go Outdated Show resolved Hide resolved
@thehowl thehowl merged commit 7b269a5 into gnolang:master Jun 22, 2023
Doozers pushed a commit to Doozers/gno that referenced this pull request Aug 31, 2023
* fix(pkg/errors): correct stacktraces for inlined functions

* refactor

---------

Co-authored-by: Manfred Touron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🌐 tendermint v2 Issues or PRs tm2 related
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants