Add custom location marks to exception backtraces #931
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
In 023b7c1,
current_locwas explicitly added back to the "About to crash" error. ActuallyMessages.erroralready usescurrent_nodeunless specified otherwise. That's why in #533 I removed the explicit location specification.But that error didn't have a location (from a node) because there is no current node at that point. Some
current_locis always present, so it seems like that works on the "About to crash" error, but it actually doesn't.Even when an exception is raised in a transfer function, using
current_locfor "About to crash" just gives it the last global variable definition location! That is because it is set by the simulated global initializer transfer functions:analyzer/src/framework/control.ml
Lines 276 to 280 in 4828e7b
But unlike actual transfer functions, this forgets to unset the current location after calling
Spec.assignand thus the last global initializer location simply leaks to the rest.Therefore,
current_locfor "About to crash" is plain incorrect and even misleading.Solution
This PR proposes a solution to the above problem by allowing raised exceptions to be marked with some custom data.
Arbitrary custom data can be added and a printer for it registered (just like exceptions themselves). An exception handler can then add such custom mark to the exception as it is reraised.
In this particular case, this is done in
FromSpec, where we managecurrent_locduring actual transfer function evaluation.Uncaught exception printing is extended to also print all the marks added to the exception. The marks actually stack, so you don't just get the innermost
current_locfor where the exception occurred, but the entire stack ofcurrent_locs, which is analogous to the entire stack of OCaml transfer function calls.In case
-vis not used, the first mark is also added to the "About to crash" error.