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

Allow changing source paths presented in stack traces #1976

Conversation

jhogberg
Copy link
Contributor

@jhogberg jhogberg commented Oct 5, 2018

When pre-processing a file, epp will automatically insert -file() attributes to let the compiler know what file an expression belongs to. This information is then used in error reports and stack traces.

The current behavior is that the pre-processor will always use the path as passed to erlc for these attributes, so the only way to prevent leaking information about the build environment is to invoke erlc in the folder the source file resides in.

This PR aims to remedy that. When the +source flag is given the pre-processor will use that instead of the actual file path for these attributes. It also fixes a related bug in the +deterministic flag.

https://bugs.erlang.org/browse/ERL-706

Note that this does *not* affect -include()'d files or the -file()
directive.
The source file path as given to `erlc` was included in an implicit
file attribute inserted by epp, even when the +source flag was
set to something else which was a bit surprising. It was also
included when +deterministic was specified, breaking the flag's
promise.

This commit forwards the +source flag to epp so it inserts the
right information, and if +deterministic is given it will be shaved
to just the base name of the file, guaranteeing the same result
regardless of how the input is reached.
@jhogberg jhogberg changed the base branch from master to maint October 5, 2018 11:06
@ferd
Copy link
Contributor

ferd commented Oct 5, 2018

Nice. And that implicit file attribute is what is used when generating stacktraces as well?

@jhogberg
Copy link
Contributor Author

jhogberg commented Oct 5, 2018

Yep!

Before:

$ erlc '+{source,"gurka.erl"}' foo.erl
$ erl
Erlang/OTP 21 [RELEASE CANDIDATE 1] [erts-9.3.1] [source-f8de655] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [hipe]

Eshell V9.3.1  (abort with ^G)
1> foo:crash().
** exception error: no match of right hand side value 2
     in function  foo:crash/0 (foo.erl, line 4)

After:

$ erlc '+{source,"gurka.erl"}' foo.erl
$ erl
Erlang/OTP 21 [erts-10.1] [source-3a34f37] [64-bit] [smp:24:24] [ds:24:24:10] [async-threads:1] [hipe]

Eshell V10.1  (abort with ^G)
1> foo:crash().
** exception error: no match of right hand side value 2
     in function  foo:crash/0 (gurka.erl, line 4)

@jhogberg jhogberg self-assigned this Oct 5, 2018
@jhogberg jhogberg added team:VM Assigned to OTP team VM fix labels Oct 5, 2018
@ferd
Copy link
Contributor

ferd commented Oct 5, 2018

Nice, that sounds like exactly the kind of thing we needed for rebar3 then :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants