godebug
godebug copied to clipboard
Preserve line numbers with compiler directives
It's possible to annotate lines so that they are treated as different line numbers in stack traces (panics, ...) and logs (test output, ...)
https://golang.org/cmd/gc/
In some cases it will also be possible to preserve the original line number by putting new statements on the same line, e.g.
godebug.Line(ctx, example_in_go_scope, 6); x := mul(1, 2)
vs
godebug.Line(ctx, example_in_go_scope, 6)
//line example-in.go:6
x := mul(1,2)
Given the two snippets above, I think the second one looks better. It is also probably simpler to implement than to implement a mix of line comments and multiple statements on the same line. But it's worth noting the first one as an option.