1:- module(
    2       da_stack,
    3       [
    4           da_stack_trace/2,
    5           da_stack_frame_at_port/4
    6       ]
    7   ).    8
    9:- use_module(frame).

DAP library module for reasoning about Prolog execution stack

This module contains predicates for retrieving information about the current Prolog stack for debugging purposes.

*/

 da_stack_trace(+FrameId, -StackTrace) is det
StackTrace is unified with a list of describing the current execution stack, starting from FrameId. The stack frame corresponding to FrameId itself is not included in StackTrace.

Each element of StackTrace is a compound term of the form stack_frame(StackFrameId, PredicateIndicator, Alternative, SourceSpan), where:

   33:- det(da_stack_trace/2).   34da_stack_trace(FrameId, StackTrace) :-
   35    da_frame_parent(FrameId, ParentFrameId),
   36    da_frame_parent_pc(FrameId, PC),
   37    da_frame_pc_stack(ParentFrameId, PC, da_stack_frame_info, StackTrace).
   38
   39da_stack_frame_info(FrameId, PC,
   40                    stack_frame(FrameId, pc(PC), PredicateIndicator, Alternative, SourceSpan)) :-
   41    da_frame_predicate_indicator(FrameId, PredicateIndicator),
   42    da_frame_alternative_frame(FrameId, Alternative),
   43    da_frame_pc_source_span(FrameId, PC, SourceSpan).
   44
   45da_stack_frame_at_port(FrameId, Port, ChoicePoint,
   46                       stack_frame(FrameId, port(Port), PredicateIndicator, Alternative, SourceSpan)) :-
   47    da_frame_predicate_indicator(FrameId, PredicateIndicator),
   48    da_alternative(ChoicePoint, Alternative),
   49    da_frame_port_source_span(FrameId, Port, SourceSpan)