* module/system/vm/traps.scm (frame-matcher): Always match on a
procedure's code, instead of the value in slot 0. Prevents confusion
with closure-optimized procedures, re-use of slot 0, and untagged
values in slot 0.
(trap-at-procedure-call, trap-in-procedure)
(trap-instructions-in-procedure, trap-at-procedure-ip-in-range)
(trap-at-source-location, trap-in-dynamic-extent)
(trap-calls-in-dynamic-extent, trap-instructions-in-dynamic-extent):
Update to adapt to frame-matcher change and remove #:closure?
argument, effectively changing the default behavior to #:closure? #t.
* doc/ref/api-debug.texi (Low-Level Traps): Update documentation.
* libguile/vm-engine.c (vm_engine): Always invoke the apply hook after
the ip has been reset. Avoids problems in frame-bindings, which
builds its bindings map based on the IP. Invoke push-continuation
before linking the new frame, so that more locals are available to the
frame inspector.
* module/system/vm/traps.scm (trap-in-procedure): No need for a
push-cont handler, as the apply handler will exit the frame.
* module/system/vm/trace.scm (print-return): Remove frame argument.
(trace-calls-to-procedure, trace-calls-in-procedure): Adapt callers.
* module/system/vm/traps.scm (trap-in-procedure, trap-frame-finish):
(trap-calls-to-procedure): Since the pop continuation hook is now
called after the continuation is popped, we need to check the right
frame. Fixes tail-calls in the trace root, and probably other things.
Reported by Jordy Dickinson <jordy.dickinson@gmail.com>.
Fixes <http://bugs.gnu.org/15691>.
* module/system/vm/traps.scm (frame-matcher): Extract procedure when
proc is an applicable struct.
* libguile/vm.h:
* libguile/vm.c:
(scm_vm_apply_hook, scm_vm_push_continuation_hook,
scm_vm_pop_continuation_hook, scm_vm_abort_continuation_hook,
scm_vm_restore_continuation_hook, scm_vm_next_hook,
scm_vm_trace_level, scm_set_vm_trace_level_x, scm_vm_engine,
scm_set_vm_engine_x, scm_c_set_vm_engine_x): The VM argument is now
implicit: the VM for the current thread.
* doc/ref/api-debug.texi (VM Hooks): Try to adapt.
* module/ice-9/command-line.scm:
* module/statprof.scm:
* module/system/vm/coverage.scm:
* module/system/vm/trace.scm:
* module/system/vm/trap-state.scm:
* module/system/vm/traps.scm:
* test-suite/tests/control.test:
* test-suite/tests/eval.test: Adapt users that set hooks or ensure that
we have a debug engine.
* module/system/vm/debug.scm: Export program-debug-info-size.
* module/system/vm/traps.scm (frame-matcher): Remove stack program
case. Use absolute frame-instruction-procedure to match if
match-code?.
(program-last-ip): Use (system vm debug) interfaces.
(program-sources-by-line): Use program-sources, as
program-sources-pre-retire will go away soon. Return absolute
addresses.
* doc/ref/api-debug.texi (VM Hooks): Update documentation.
* libguile/vm.c (vm_dispatch_hook):
* libguile/vm-engine.c: Rework the hook machinery so that they can
receive an arbitrary number of arguments. The return and abort
hooks will pass the values that they return to their continuations.
(vm_engine): Adapt to ABORT_CONTINUATION_HOOK change.
* libguile/vm-i-system.c (return, return/values): Adapt to
POP_CONTINUATION_HOOK change.
* module/system/vm/frame.scm (frame-return-values): Remove. The
pop-continuation-hook will pass the values directly.
* module/system/vm/trace.scm (print-return):
(trace-calls-to-procedure):
(trace-calls-in-procedure): Update to receive return values
directly.
* module/system/vm/traps.scm (trap-in-procedure)
(trap-in-dynamic-extent): Ignore return values.
(trap-frame-finish, trap-calls-in-dynamic-extent)
(trap-calls-to-procedure): Pass return values to the handlers.
* libguile/programs.h:
* libguile/programs.c (scm_program_source): Add an optional arg, the
sources table to traverse. Defaults to the result of
scm_program_sources.
* module/system/vm/program.scm (program-sources-pre-retire): Move
definition here from (system vm traps), and export.
* module/system/vm/traps.scm: Adapt.
* module/system/vm/frame.scm (frame-next-source): New exported binding,
returns the source line corresponding to the next instruction instead
of the previous instruction.
* module/system/vm/traps.scm (trap-matching-instructions): New trap,
just installs a next hook and runs the handler when a predicate
succeeds.
* module/system/vm/trap-state.scm (add-ephemeral-stepping-trap!): New
procedure, uses trap-matching-instructions with an appropriate
predicate to handle step, stepi, next, and nexti repl metacommands.
* module/system/repl/command.scm (step, step-instruction, next)
(next-instruction): New repl debugger commands.
* module/system/vm/traps.scm: Fix a comment.
* module/system/vm/trap-state.scm (<trap-state>): Add next-ephemeral-idx
slot.
(wrapper-at-index): Use eqv? instead of = to avoid type errors in user
inputs.
(next-ephemeral-index!, ephemeral-handler-for-index): New functions,
allocate ephemeral trap ids for functions to be called only once.
(add-trap-at-frame-finish!): New export, traps when a frame finishes.
* module/system/vm/traps.scm (trap-at-procedure-ip-in-range): Rework not
to call the handler when returning to a frame that was already
entered. So now breaking at foo.scm:1234 doesn't break when returning
to that line.
* module/system/vm/traps.scm (trap-in-procedure): If we are
(re-)entering the procedure from a return, call the enter-proc with
the returnee, not the returner.
(in-range?): Tighten up a bit.
(program-sources-before-retire): New helper, like program-sources but
indexed before instructions are retired instead of after.
(program-sources-by-line): Use program-sources-before-retire so that
we can break on instructions by source line *before* those
instructions are executed.
* module/system/vm/trap-state.scm (add-trap-at-source-location!):
* module/system/vm/traps.scm (trap-at-source-location): Rename "line"
argument to "user-line", indicating that the line is one-based instead
of zero-based. Decrement the line before handing off to
source-closures-or-procedures and source->ip-range.
* module/system/vm/traps.scm (frame-matcher): New helper.
(trap-at-procedure-call, trap-in-procedure, trap-in-dynamic-extent)
(trap-calls-in-dynamic-extent, trap-instructions-in-dynamic-extent)
(trap-instructions-in-procedure, trap-at-procedure-ip-in-range): Add
ability to trap on procedures that are closures.
(trap-at-source-location): Check source-closures first, to catch
source locations that are in nested procedures.
* module/system/vm/traps.scm (trap-frame-finish): Use frame-address
instead of frame-dynamic-link.
(trap-calls-to-procedure): New proc, traps on procedure calls and
their corresponding returns.
* module/system/vm/traps.scm (trap-frame-finish)
(trap-in-dynamic-extent, trap-calls-in-dynamic-extent)
(trap-instructions-in-dynamic-extent): New traps, for implementing
tracing, and the `finish' command.
* module/system/vm/trace.scm (trace-calls-in-procedure)
(trace-instructions-in-procedure): New tracing traps.
(vm-trace): Reimplement in terms of the new traps.
* module/system/vm/trap-state.scm (add-trap!): New helper; not used in
this commit, though.
* module/system/vm/traps.scm (new-disabled-trap): Don't manipulate the
VM trace level in the enable and disable handlers. Unfortunately, this
makes traps not work unless you enable hooks, but given that
vm_dispatch_hook has to set trace-level to 0, there needs to be an
object with a broader view of what traps are enabled. That object is
the hook state.
* module/system/vm/trap-state.scm (trap-state->trace-level): New
procedure.
(with-default-trap-handler): Add an optional trap-state argument. Now
makes sure that the vm-trace-level is set appropriately during the
execution of the thunk, allowing for breakpoints from recursive
prompts.
* module/system/vm/traps.scm: New module, implements higher-level traps
based on the VM hooks. Inspired by (ice-9 debugging traps). Instead of
the ice-9's variety, these traps have a procedural interface instead
of a GOOPS interface.
* module/Makefile.am: Add the new module.