* module/system/repl/error-handling.scm (call-with-error-handling): If
the given index is false, assume this was an ephemeral trap, and don't
print a welcome message or reference the trap by index.
* 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/program.scm (source:line-for-user): New exported
procedure, returns a 1-indexed line, suitable for presentation to a
user.
(write-program): Use source:line-for-user when making fallback names.
* module/system/vm/coverage.scm (coverage-data->lcov):
* module/language/assembly/disassemble.scm (source->string):
* module/system/repl/debug.scm (print-frame): Use source:line-for-user.
* libguile/frames.h:
* libguile/frames.c (scm_frame_stack_pointer): New function.
* module/system/repl/debug.scm (print-registers): New function, prints
out registers.
* module/system/repl/command.scm (registers): New debugging
meta-command.
(inspect): Not a stack-command, a normal meta-command.
* libguile/vm.h (scm_c_vm_run): Make internal.
* libguile/vm.c (vm_default_engine): New static global variable.
(make_vm): Set vp->engine based on
(scm_vm_apply): Remove in favor of call-with-vm.
(scm_thread_vm, scm_set_thread_vm_x): Remove these, as they did not
have a well-defined meaning, and were dangerous to call on other
threads.
(scm_the_vm): Reinstate previous definition.
(symbol_to_vm_engine, vm_engine_to_symbol)
(vm_has_pending_computation): New helpers.
(scm_vm_engine, scm_set_vm_engine_x, scm_c_set_vm_engine_x): New
accessors for VM engines.
(scm_c_set_default_vm_engine_x, scm_set_default_vm_engine_x): New
setters for the default VM engine.
(scm_call_with_vm): New function, applies a procedure to arguments in
a context in which a given VM is current.
* libguile/eval.c (eval, scm_apply): VM dispatch goes through
scm_call_with_vm.
* test-suite/tests/control.test ("the-vm"):
* module/system/vm/coverage.scm (with-code-coverage): Use call-with-vm.
* module/system/vm/vm.scm: Update exports.
* test-suite/vm/run-vm-tests.scm (run-vm-program):
* test-suite/tests/compiler.test ("current-reader"): Just rely on the
result of make-program being an applicable.
* test-suite/tests/eval.test ("stack overflow"): Add a note that this
test does not test what it should.
* module/system/vm/coverage.scm (with-code-coverage): Switch current
thread to VM, using `set-thread-vm!'.
* test-suite/tests/coverage.test ("procedure-execution-count")["called
from C"]: New test.
* 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/xref.scm (*closure-sources-db*): New global, like
*sources-db* but for nested procedures. It's a separate map because
these procs need to be treated differently in trap handlers -- you
match on the bytecode, not on the program object.
(add-source, forget-source): Take the db as an argument (the normal db
or the closures db).
(add-sources, forget-sources): Record sources for nested procedures to
in *closures-db*.
(untaint-sources, ensure-sources-db): Adapt for new closures db.
(lookup-source-procedures): Factored out.
(source-closures): New exported procedure, returns closures at the
given source location.
* module/system/vm/trap-state.scm (add-trap-at-source-location!): New
proc.
* module/system/repl/command.scm (break-at-source): New repl
meta-command. Doesn't work as well as it could now because it doesn't
know about nested functions, but that's coming.
* module/system/vm/trap-state.scm (list-traps): Just return the integers
identifying the traps; people can use trap-name to get the names.
* module/system/repl/command.scm (traps): Adapt.
* module/system/vm/trace.scm (print-application, print-return): Add a
prefix before the printout.
(trace-calls-to-procedure, trace-calls-in-procedure): Add prefix
keyword args.
* module/system/vm/trap-state.scm (add-trace-at-procedure-call!): Give a
useful prefix for tracepoint printouts.
* module/system/vm/trace.scm (print-return, print-application)
(frame-return-values): Factored out of other things.
(trace-calls-to-procedure): New proc, installs a trap tracing only
calls to the given proc.
(trace-calls-in-procedure): Refactor a bit.
* module/system/vm/trap-state.scm (add-trace-at-procedure-call!): New
proc.
* module/system/repl/command.scm (tracepoint): New command, installs a
tracepoint on a procedure.
* module/system/vm/trap-state.scm (with-default-trap-handler): Don't
enable traps if we are setting a handler of #f.
* module/system/repl/error-handling.scm (call-with-error-handling): Add
#:trap-handler arg.
* module/system/repl/repl.scm (run-repl): Only have traps enabled while
running the thunk. Otherwise we trace on procedures called as part of
the repl.
* 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/repl/command.scm (profile, trace, inspect)
(pretty-print): Use repl-prepare-eval-thunk instead of the lower-level
compile and make-program.
* 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/trap-state.scm: New file, tracks a VM-specific set of
traps.
* module/Makefile.am: Add trap-state.scm.
* module/system/repl/error-handling.scm: While in a with-error-handling
block, bind a default trap handler that invokes a recursive prompt.
* module/system/repl/command.scm: Add a `break' repl meta-command.
* 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.
* libguile/vm-i-system.c (call_cc, tail_call_cc): Call the new
RESTORE_CONTINUATION_HOOK when a continuation is restored.
(prompt): Call the new ABORT_CONTINUATION_HOOK when entering the abort
handler's continuation.
* libguile/vm-engine.h (ABORT_CONTINUATION_HOOK)
(RESTORE_CONTINUATION_HOOK):
* libguile/vm.h (SCM_VM_ABORT_CONTINUATION_HOOK)
(SCM_VM_RESTORE_CONTINUATION_HOOK):
* libguile/vm.c: (scm_vm_abort_continuation_hook): New hook, called when
entering an abort handler.
(scm_vm_restore_continuation_hook): New hook, called after returning
to a continuation.
* module/system/vm/vm.scm: Add hooks to export list.
* libguile/vm.h (SCM_VM_PUSH_CONTINUATION_HOOK)
(SCM_VM_POP_CONTINUATION_HOOK): New hooks, to replace
enter/exit/return.
(SCM_VM_BOOT_HOOK, SCM_VM_HALT_HOOK, SCM_VM_BREAK_HOOK): Remove these
useless hooks.
* libguile/vm.c (scm_vm_push_continuation_hook)
(scm_vm_pop_continuation_hook): New accessors.
* libguile/vm-i-system.c: Remove boot, halt, break, enter, exit, and
return hooks. Also remove the break instruction. Instead now when we
push a new continuation onto the stack we call PUSH_CONTINUATION_HOOK,
and when we pop via a return we call POP_CONTINUATION_HOOK. APPLY_HOOK
is now decoupled from continuation pushes and pops.
* libguile/vm-engine.h:
* libguile/vm-engine.c: Adapt for hooks.
* module/system/vm/trace.scm (vm-trace): Adapt for hooks. Also revive
the #:instructions? #t mode.
* module/system/vm/vm.scm: Adapt exports for new set of hooks.
* libguile/foreign.c (make_cif): New procedure, with code formerly in
`scm_make_foreign_function'.
(scm_make_foreign_function): Use it.
(invoke_closure, scm_procedure_to_pointer)[FFI_CLOSURES]: New
functions.
* libguile/foreign.h (scm_procedure_to_pointer): New declaration.
* module/system/foreign.scm: Export `procedure->pointer' when available.
* test-suite/standalone/test-ffi (f-callback-1, f-callback-2): New
procedures and related tests.
* test-suite/standalone/test-ffi-lib.c (test_ffi_callback_1,
test_ffi_callback_2): New functions.
* test-suite/tests/foreign.test ("procedure->pointer"): New test prefix.
* doc/ref/api-foreign.texi (Dynamic FFI): Document `procedure->pointer'.
* module/system/repl/error-handling.scm: use the error string to
construct the <debug> instance.
* module/system/repl/command.scm: new debug command `error-message'
that extracts the new <debug> field, available to stack commands as
`message'.
* doc/ref/scheme-using.texi: documentation for new command.
* module/system/repl/debug.scm: <debug> stores the error string in a
new field.
* libguile/foreign.c (scm_string_to_pointer, scm_pointer_to_string): New
functions.
* libguile/foreign.h (scm_string_to_pointer, scm_pointer_to_string): New
declarations.
* module/system/foreign.scm: Export `string->pointer' and
`pointer->string'.
* test-suite/tests/foreign.test ("pointer<->string"): New test prefix.
* doc/ref/api-foreign.texi (Void Pointers and Byte Access): Add
`string->pointer' and `pointer->string'.