* module/system/vm/assembler.scm (pack-arity-flags):
(write-arity-headers): Add a flag to indicate that an arity is part of
a case-lambda, so that we can use binary search to find arities.
* module/system/vm/debug.scm (is-in-case-lambda?)
(arity-is-in-case-lambda?, find-first-arity): Use binary search.
* 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.
* module/ice-9/session.scm (procedure-arguments): Add an rtl-program?
case.
* module/system/vm/debug.scm (arity-arguments-alist): Use the order that
session.test expects.
* test-suite/tests/session.test ("procedure-arguments"): Adapt tests
with keywords for the new starting-with-the-procedure numbering of
locals.
* libguile/gsubr.h:
* libguile/gsubr.c (scm_i_primitive_call_ip):
* libguile/programs.c (scm_primitive_call_ip): Adapt to return an
absolute address.
* module/system/vm/assembler.scm (write-arity-headers): Adapt to write
byte addresses (relative to the text base).
* module/system/vm/debug.scm (arity-low-pc, arity-high-pc): Return
absolute addresses, instead of word offsets relative to the text
base.
(find-first-arity): Adapt for absolute addresses.
* module/system/vm/program.scm (program-arguments-alist): Adapt for
arity-low-pc / arity-high-pc absolute addresses.
* libguile/frames.c (scm_frame_source): Instead of assuming that
scm_frame_procedure is correct, use the IP to get the source.
(scm_frame_instruction_pointer): Return an absolute value instead of
assuming that slot 0 is correct. (It isn't, when preparing for a tail
call.)
* libguile/programs.h:
* libguile/programs.c (scm_find_source_for_addr): New internal helper.
* module/system/repl/debug.scm (print-registers): Readably print
absolute instruction pointers.
* module/system/vm/coverage.scm: Complete rewrite to use absolute IP's.
We can't assume that frame-procedure is cheap if it is correct, or
correct if it is cheap. Anyway using the address is better anyway.
(coverage-data->lcov): Disable per-function info temporarily.
(loaded-modules, module-procedures, closest-source-line)
(closed-over-procedures): Remove these. Instead of going from
procedures to source info, now we go from ELF image to source info.
* module/system/vm/debug.scm (debug-context-length): New interface.
* module/system/vm/program.scm (source-for-addr): New internal helper.
* module/system/vm/objcode.scm:
* libguile/objcodes.c (scm_all_mapped_elf_images): New proc.
* module/system/vm/debug.scm (fold-all-debug-contexts):
(fold-source-locations): New public interfaces.
* module/system/vm/assembler.scm (link-docstrs): Write pc offsets as
byte addresses. Works better with native code.
* module/system/vm/debug.scm (find-program-docstring): Fix the linear
search. How embarassing!
* libguile/frames.c (scm_frame_source, scm_frame_instruction_pointer):
Fix to work with RTL programs.
* module/system/vm/debug.scm (find-debug-context): Allow for the
possibility of there being no ELF image.
(find-program-debug-info, find-program-arities)
(program-minimum-arity, find-program-docstring)
(find-program-properties, find-source-for-addr)
(find-program-die, find-program-sources): Don't bail if we couldn't
get the debug context.
* module/system/vm/frame.scm (frame-next-source)
(frame-call-representation): Allow RTL programs.
* module/system/vm/program.scm (program-arguments-alist): Placeholder
implementation for RTL programs.
(program-arguments-alists): Don't bail if we couldn't get the
arities.
* module/system/vm/debug.scm (find-program-sources): If there is no
source location before the low-pc of the procedure we're grovelling
for, we were skipping the source loc info. Fix that.
* module/system/vm/program.scm (write-program): Get source info for
anonymous RTL functions.
(program-sources, program-sources-pre-retire): Provide program
counters relative to the beginning of the procedure.
* module/system/vm/debug.scm (<source>, source-pre-pc)
(source-post-pc, source-file, source-line, source-column)
(source-line-for-user): New data type for source location
information.
(find-source-for-addr, find-program-sources): New procedures to get
source location information for a particular address.
* module/scripts/disassemble.scm (disassemble): Update to work with
RTl (and only RTL, as that's the future).
* module/system/vm/debug.scm (for-each-elf-symbol): New public
interface.
(debug-context-from-image): New helper.
(find-debug-context): Use the helper.
* module/system/vm/disassembler.scm (disassemble-image): New public
interface.
* libguile/programs.c (parse_arity): Lookup rtl-program-minimum-arity
from (system vm debug).
* module/system/vm/debug.scm (find-first-arity): Fix the linear search.
Whoops!
* module/system/vm/assembler.scm (link-procprops, link-objects): Arrange
to write procedure property links out to a separate section.
* libguile/procprop.c (scm_procedure_properties):
* libguile/programs.h:
* libguile/programs.c (scm_i_rtl_program_properties):
* module/system/vm/debug.scm (find-program-properties): Wire up
procedure-properties for RTL procedures. Yeah! Fistpumps! :)
* module/system/vm/debug.scm (find-program-debug-info): Return #f if the
string is "", as it is if we don't have a name. Perhaps
elf-symbol-name should return #f in that case...
* test-suite/tests/rtl.test: Add some tests.
* libguile/procprop.h:
* libguile/procprop.c (scm_procedure_documentation): Move here from
procs.c, and to make the logic more similar to that of procedure-name,
which allows RTL programs to dispatch to rtl-program-documentation.
* libguile/programs.c (scm_i_rtl_program_documentation):
* libguile/programs.h:
* module/system/vm/program.scm (rtl-program-documentation): New
plumbing.
* module/system/vm/debug.scm (find-program-docstring): New interface to
grovel ELF for a docstring.
* libguile/procprop.c (scm_i_procedure_arity): Allow RTL programs to
dispatch to scm_i_program_arity.
* libguile/programs.c (scm_i_program_print): Refactor reference to
write-program.
(scm_i_rtl_program_minimum_arity): New procedure, dispatches to
Scheme.
(scm_i_program_arity): Dispatch to scm_i_rtl_program_minimum_arity if
appropriate.
* module/system/vm/debug.scm (program-minimum-arity): New export.
* module/system/vm/program.scm (rtl-program-minimum-arity): New internal
function.
(program-arguments-alists): New helper, implemented also for RTL
procedures.
(write-program): Refactor a bit, and call program-arguments-alists.
* test-suite/tests/rtl.test ("simply procedure arity"): Add tests that
arities make it all the way to cold ELF and back to warm Guile.
* module/system/vm/debug.scm (<arity>): New object, for reading
arities. Unlike <arity> in the assembler, this one only holds on to a
couple of pointers, and doesn't even load in argument names. Unlike
the arity lists in (system vm program), it can load in names. Very
early days but it does seem to work.
(find-program-arities, arity-arguments-alist): New higher-level
interfaces.
* module/Makefile.am:
* module/system/vm/debug.scm: New module.
* module/system/vm/elf.scm (elf-section-by-name): New helper.
(elf-symbol-table-len): New helper.
* test-suite/tests/rtl.test: Add test for finding debug info.
* module/system/repl/repl.scm (prompting-meta-read): Use
call-with-error-handling.
* module/system/vm/debug.scm (call-with-error-handling): Add case for
#:on-error 'pass. Have the catch handler return the unspecified value.
* module/system/repl/repl.scm (prompting-meta-read): Catch and print
read errors here, returning unspecified in that case.
(start-repl): Don't enable the debugger while reading expressions.
Adapt with-backtrace to with-error-handling.
* module/system/vm/debug.scm (run-debugger, debugger-repl): No need to
take a stack, the frames vector is sufficient.
(call-with-error-handling, with-error-handling): New public utilities.
Notably they do not poke the-last-stack.
* module/system/vm/debug.scm (frame->module): Actually bind frame-local
variables to values in the new anonymous module. Setting settable vars
should work too :)
* module/system/repl/common.scm (*repl-level*): New public fluid.
(repl-prompt): If *repl-level* is a positive integer, add it to the
prompt.
* module/system/repl/repl.scm (start-repl): The `lang' argument is now
optional, and defaults to (current-language). New kwargs level and
welcome; level defaults to 0, or 1+ the existing level, and the
welcome is a boolean, true if level is 0. Parameterize *repl-level*
during the dynamic extent of this repl. Also, parameterize
the-last-stack to #f for the duration of this repl.
* module/system/vm/debug.scm (frame->module, debugger-repl): Stubs of a
recursive repl implementation. The idea is to be a repl in the lexical
context of the error; but it would be nice to be able to operate in
the module of the proc too, for example to export bindings. Hmm.
* module/system/vm/debug.scm (*debug-input-port*):
(*debug-output-port*): New public fluids.
(run-debugger): Add some kwargs for input and output ports, defaulting
to the debug input and output ports.
(debug-pre-unwind-handler): Print to debug output port.
(debug): Untabify.
* module/ice-9/boot-9.scm (top-repl): Map (debug) at the repl to (system
vm debug).
* module/system/vm/debug.scm (run-debugger, debugger-repl): Don't take
the index as an arg, for now anyway.
(debug): New wrapper.
* libguile/stacks.c (scm_sys_stacks): New global variable, moved here
from boot-9.scm.
(scm_init_stacks): Define scm_sys_stacks to %stacks.
(stack_depth): Remove narrowing by frame pointer.
(find_prompt): New helper.
(narrow_stack): Clean up a bit, and allow narrowing by prompt tag.
(scm_make_stack): Update docs, and use scm_stack_id to get the stack
id.
(scm_stack_id): The current stack id may be fetched as the cdar of
%stacks.
(stack_id_with_fp): Remove helper.
* module/ice-9/boot-9.scm (%start-stack): Fix indentation.
(%stacks): Remove definition, it's in stacks.c now.
(default-pre-unwind-handler): Narrow by another frame.
(save-stack): Remove special handling for certain stack ids, as it is
often possible that the function isn't on the stack -- in the
interpreter, or after a tail call. Better to narrow by prompt ids.
* module/system/vm/debug.scm (print-frames): Change to operate on a
vector of frames.
(run-debugger): Change to receive a vector of frames. The debugger
also has the full stack, so it can re-narrow (or widen) to get the
whole stack, if the user wants.
(stack->vector): New helper.
(debug-pre-unwind-handler): Narrow by more frames, and to the most
recent start-stack invocation. Adapt to run-debugger change.
* module/system/vm/debug.scm (debug-pre-unwind-handler): Narrow two
frames instead of stack-reffing past one. The second frame is
necessary, now that make-stack itself is on the stack.
* module/system/vm/debug.scm (print-frames): Clean up a bit, reverting
part of the previous change. (The problem was that in the else branch
of the conditional, it didn't consume an arg.)
In the future I would like to preserve the clean look of the
backtraces. It's easier to read that way.
* module/system/vm/debug.scm (location-string): New procedure.
(print-frames): Use it. This fixes cases where LINE is #f and makes a
distinction between FILE = stdin and FILE is unknown.
* module/system/vm/debug.scm (debugger-repl): Remove the `bindings'
command, it is superseded by `locals'.
Update the TODO.
(debug-pre-unwind-handler): Remove scary "beta" warning. Already being
able to bt #:width 1000 #:full? #t is quite useful...
* module/system/vm/debug.scm (print-locals): Factor out to a function.
(collect-frames, print-frames): Implement the guts of `backtrace' in
Scheme.
(debugger-repl): Add #:width and #:full? options to `backtrace'.
Backtrace uses the backtrace code implemented in scheme.
* libguile/frames.c (scm_init_frames): No need to bootstrap the VM here,
it should be already bootstrapped by init.c.
(scm_bootstrap_frames): No need to register an extension, as
scm_init_frames is called by init.c.
* module/system/vm/frame.scm: Don't load the scm_init_frames extension,
as the primitives from frames.c are loaded by Guile's init.
(frame-bindings): Change to return bindings, as can be accessed by the
binding: accessors from program.scm.
(frame-lookup-binding): Revive and make this one work with current
code.
(frame-binding-set!):
(frame-binding-ref): Use the new frame-lookup-binding. Perhaps these
should handle boxing and unboxing, though.
(frame-source): New accessor, returns a source object.
(frame-call-representation): Change to return a full list, as
truncated-print can truncate for us.
(frame-environment, frame-object-binding, frame-object-name): Update
not to take an address, as the address is part of the frame.
(frame-variable-exists?, frame-variable-ref, frame-variable-set!)
(frame-local-variables, frame-program-name, print-frame)
(print-frame-chain-as-backtrace, frame-file, frame-line-number)
(make-frame-chain, bootstrap-frame?, frame-number, frame-address):
Remove these outdated functions.
* module/system/vm/debug.scm (debugger-repl): Use
frame-call-representation, and ~@y.
(locals): New command, prints local variables in a frame.