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.
As far as I can see, there is no other way to get the current stack, at least not in a form that can be used arbitrarily instead of just printed to an output port. (There is
sexp_exception_stack_trace
of course, but I assume that's just for exceptions).For concreteness, my use case is roughly this: I have procedures exported to Scheme, that can be called to create objects at the C/C++ level. I would like to inspect the stack at the time of creation, i.e. within the call to the exported procedure, in order to get the location in the source where the object is created, for use in diagnostic messages to the user. If there is some existing way of doing this, please let me know.
Since we're on the matter, I notice that stack traces (obtained via the function exported in this PR, or via
sexp_exception_stack_trace
) seem to be incomplete. Consider for instance a foreign procedure defined asand exported via
If I call it from a file named, say
test.scm
, containing:Then the stack trace I get from the thrown exception looks like:
If I change the call to, say
(foo 42)
, and get the stack trace viasexp_get_stack_trace
from within the Cfoo
function, I get the same trace. In any case, no stack frame with location withintest.scm
appears.If I wrap
foo
in another function as inI now get a more complete stack trace:
But this seems to work only when the call is wrapped in another call (as in
display
here). Am I doing something wrong? If not, is there some way of getting a complete strack trace consistently? (If work is required on the Chibi-Scheme side, I could try to help out, given some pointers.)