Changeset 4548 for trunk/compiler

Show
Ignore:
Timestamp:
10/30/08 10:26:29 (2 months ago)
Author:
pmoura
Message:

Updated the Logtalk built-in debugger to print goal invocation numbers when tracing.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4543 r4548  
    120120:- dynamic('$lgt_dbg_spying_'/4).               % '$lgt_dbg_spying_'(Sender, This, Self, Goal) 
    121121:- dynamic('$lgt_dbg_leashing_'/1).             % '$lgt_dbg_leashing_'(Port) 
     122:- dynamic('$lgt_dbg_invocation_number_'/1).    % '$lgt_dbg_invocation_number_'(N) 
    122123 
    123124 
     
    279280    catch('$lgt_tr_msg'(Pred, Obj, Call, user), Error, '$lgt_runtime_error_handler'(error(Error, Obj::Pred, user))), 
    280281    (   '$lgt_dbg_debugging_', '$lgt_debugging_'(Obj) -> 
     282        '$lgt_dbg_reset_invocation_number', 
    281283        '$lgt_ctx_ctx'(Ctx, _, user, user, Obj, '$lgt_bio_user_0_', [], _), 
    282284        '$lgt_ctx_dbg_ctx'(Ctx, DbgCtx), 
     
    292294        catch('$lgt_tr_body'(Obj<<Pred, TPred, DPred, Ctx), Error, '$lgt_runtime_error_handler'(error(Error, Obj<<Pred, user))), 
    293295        (   '$lgt_dbg_debugging_', '$lgt_debugging_'(Obj) -> 
     296            '$lgt_dbg_reset_invocation_number', 
    294297            catch(DPred, Error, '$lgt_runtime_error_handler'(Error)) 
    295298        ;   catch(TPred, Error, '$lgt_runtime_error_handler'(Error)) 
     
    35983601    '$lgt_dbg_nospyall', 
    35993602    '$lgt_dbg_leash'(full), 
    3600     '$lgt_dbg_nodebug'. 
     3603    '$lgt_dbg_nodebug', 
     3604    '$lgt_dbg_reset_invocation_number'. 
    36013605 
    36023606 
     
    36063610    ;   assertz('$lgt_dbg_debugging_'), 
    36073611        retractall('$lgt_dbg_tracing_'), 
     3612        '$lgt_dbg_reset_invocation_number', 
    36083613        write('Debugger switched on: showing spy points for all objects compiled in debug mode.'), nl 
    36093614    ). 
     
    36443649        retractall('$lgt_dbg_debugging_'), 
    36453650        assertz('$lgt_dbg_debugging_'), 
     3651        '$lgt_dbg_reset_invocation_number', 
    36463652        write('Debugger switched on: tracing everything for all objects compiled in debug mode.'), nl 
    36473653    ). 
     
    38643870'$lgt_dbg_fact'(Fact, N, DbgCtx) :- 
    38653871    (   '$lgt_dbg_debugging_', \+ '$lgt_dbg_skipping_' -> 
    3866         '$lgt_dbg_port'(fact(N), Fact, _, DbgCtx, Action), 
     3872        '$lgt_dbg_port'(fact(N), _, Fact, _, DbgCtx, Action), 
    38673873        call(Action) 
    38683874    ;   true 
     
    38723878'$lgt_dbg_head'(Head, N, DbgCtx) :- 
    38733879    (   '$lgt_dbg_debugging_', \+ '$lgt_dbg_skipping_' -> 
    3874         '$lgt_dbg_port'(rule(N), Head, _, DbgCtx, Action), 
     3880        '$lgt_dbg_port'(rule(N), _, Head, _, DbgCtx, Action), 
    38753881        call(Action) 
    38763882    ;   true 
     
    38793885 
    38803886'$lgt_dbg_goal'(Goal, TGoal, DbgCtx) :- 
     3887    '$lgt_dbg_inc_invocation_number'(N), 
    38813888    (   '$lgt_dbg_debugging_', \+ '$lgt_dbg_skipping_' -> 
    3882         (   '$lgt_dbg_port'(call, Goal, _, DbgCtx, CAction), 
     3889        (   '$lgt_dbg_port'(call, N, Goal, _, DbgCtx, CAction), 
    38833890            (   CAction == ignore -> 
    38843891                true 
    38853892            ;   call(CAction), 
    3886                 catch(TGoal, Error, '$lgt_dbg_exception'(Goal, Error, DbgCtx)), 
    3887                 (   '$lgt_dbg_port'(exit, Goal, _, DbgCtx, EAction), 
     3893                catch(TGoal, Error, '$lgt_dbg_exception'(N, Goal, Error, DbgCtx)), 
     3894                (   '$lgt_dbg_port'(exit, N, Goal, _, DbgCtx, EAction), 
    38883895                    call(EAction) 
    3889                 ;   '$lgt_dbg_port'(redo, Goal, _, DbgCtx, RAction), 
     3896                ;   '$lgt_dbg_port'(redo, N, Goal, _, DbgCtx, RAction), 
    38903897                    RAction == ignore 
    38913898                ) 
    38923899            ;   retractall('$lgt_dbg_skipping_'), 
    3893                 '$lgt_dbg_port'(fail, Goal, _, DbgCtx, _), 
     3900                '$lgt_dbg_port'(fail, N, Goal, _, DbgCtx, _), 
    38943901                fail 
    38953902            ) 
     
    39003907 
    39013908 
    3902 '$lgt_dbg_exception'(_, logtalk_debugger_aborted, _) :- 
     3909'$lgt_dbg_exception'(_, _, logtalk_debugger_aborted, _) :- 
    39033910    throw(logtalk_debugger_aborted). 
    39043911 
    3905 '$lgt_dbg_exception'(Goal, Error, DbgCtx) :- 
    3906     '$lgt_dbg_port'(exception, Goal, Error, DbgCtx, TAction), 
     3912'$lgt_dbg_exception'(N, Goal, Error, DbgCtx) :- 
     3913    '$lgt_dbg_port'(exception, N, Goal, Error, DbgCtx, TAction), 
    39073914    (   TAction == fail -> 
    39083915        fail 
     
    39113918 
    39123919 
    3913 '$lgt_dbg_port'(Port, Goal, Error, DbgCtx, Action) :- 
     3920'$lgt_dbg_port'(Port, N, Goal, Error, DbgCtx, Action) :- 
    39143921    '$lgt_dbg_debugging_', 
    39153922    !, 
    39163923    (   '$lgt_dbg_leashing'(Port, Goal, DbgCtx, Code) -> 
    39173924        repeat, 
    3918             write(Code), '$lgt_dbg_write_port_name'(Port), writeq(Goal), write(' ? '), 
     3925            write(Code), '$lgt_dbg_write_port_name'(Port), '$lgt_dbg_write_invocation_number'(Port, N), writeq(Goal), write(' ? '), 
    39193926            catch('$lgt_read_single_char'(Option), _, fail), 
    39203927        '$lgt_dbg_valid_port_option'(Option, Port, Code), 
     
    39223929        ! 
    39233930    ;   (   '$lgt_dbg_tracing_' -> 
    3924             write(' '), '$lgt_dbg_write_port_name'(Port), writeq(Goal), nl 
     3931            write(' '), '$lgt_dbg_write_port_name'(Port), '$lgt_dbg_write_invocation_number'(Port, N), writeq(Goal), nl 
    39253932        ;   true 
    39263933        ), 
     
    39283935    ). 
    39293936 
    3930 '$lgt_dbg_port'(_, _, _, _, true). 
     3937'$lgt_dbg_port'(_, _, _, _, _, true). 
     3938 
     3939 
     3940'$lgt_dbg_write_invocation_number'(fact(_), _) :- !. 
     3941'$lgt_dbg_write_invocation_number'(rule(_), _) :- !. 
     3942'$lgt_dbg_write_invocation_number'(_, N) :- 
     3943    write('('), write(N), write(') '). 
    39313944 
    39323945 
    39333946'$lgt_dbg_write_port_name'(fact(N)) :- 
    39343947    (   N =:= 0 -> 
    3935         write('   Fact: ') 
    3936     ;   write('   Fact('), write(N), write('): ') 
     3948        write(' Fact: ') 
     3949    ;   write(' Fact #'), write(N), write(': ') 
    39373950    ). 
    39383951'$lgt_dbg_write_port_name'(rule(N)) :- 
    39393952    (   N =:= 0 -> 
    3940         write('   Rule: ') 
    3941     ;   write('   Rule('), write(N), write('): ') 
     3953        write(' Rule: ') 
     3954    ;   write(' Rule #'), write(N), write(': ') 
    39423955    ). 
    39433956'$lgt_dbg_write_port_name'(call) :- 
    3944     write('   Call: '). 
     3957    write(' Call: '). 
    39453958'$lgt_dbg_write_port_name'(exit) :- 
    3946     write('   Exit: '). 
     3959    write(' Exit: '). 
    39473960'$lgt_dbg_write_port_name'(redo) :- 
    3948     write('   Redo: '). 
     3961    write(' Redo: '). 
    39493962'$lgt_dbg_write_port_name'(fail) :- 
    3950     write('   Fail: '). 
     3963    write(' Fail: '). 
    39513964'$lgt_dbg_write_port_name'(exception) :- 
    3952     write('   Exception: '). 
     3965    write(' Exception: '). 
    39533966 
    39543967 
     
    40364049    functor(Goal, Functor, Arity), 
    40374050    functor(CGoal, Functor, Arity), 
    4038     write('    Enter a context spy point term formatted as (Sender, This, Self, Goal): '), 
     4051    write('  Enter a context spy point term formatted as (Sender, This, Self, Goal): '), 
    40394052    read(Spypoint), 
    40404053    Spypoint = (Sender, This, Self, CGoal), 
     
    40464059 
    40474060'$lgt_dbg_do_port_option'(@, _, _, _, _, _) :- 
    4048     write('    ?- '), 
     4061    write('  ?- '), 
    40494062    read(Goal), 
    40504063    call(Goal) -> 
     
    40564069        break, 
    40574070        '$lgt_dbg_resume'(Tracing) 
    4058     ;   write('    break no supportd by the back-end Prolog compiler.'), nl 
     4071    ;   write('  break no supportd by the back-end Prolog compiler.'), nl 
    40594072    ), 
    40604073    fail. 
     
    40684081 
    40694082'$lgt_dbg_do_port_option'(d, _, Goal, _, _, _) :- 
    4070     write('    Current goal: '), write_term(Goal, [ignore_ops(true)]), nl, 
     4083    write('  Current goal: '), write_term(Goal, [ignore_ops(true)]), nl, 
    40714084    fail. 
    40724085 
    40734086'$lgt_dbg_do_port_option'(x, _, _, _, DbgCtx, _) :- 
    40744087    '$lgt_dbg_ctx'(DbgCtx, Sender, This, Self), 
    4075     write('    Sender: '), writeq(Sender), nl, 
    4076     write('    This:   '), writeq(This), nl, 
    4077     write('    Self:   '), writeq(Self), nl, 
     4088    write('  Sender: '), writeq(Sender), nl, 
     4089    write('  This:   '), writeq(This), nl, 
     4090    write('  Self:   '), writeq(Self), nl, 
    40784091    fail. 
    40794092 
    40804093'$lgt_dbg_do_port_option'(e, _, _, Error, _, _) :- 
    4081     write('    Exception term: '), writeq(Error), nl, 
     4094    write('  Exception term: '), writeq(Error), nl, 
    40824095    fail. 
    40834096 
    40844097'$lgt_dbg_do_port_option'(h, _, _, _, _, _) :- 
    4085     write('    Available options are:'), nl, 
    4086     write('        c - creep (go on; you may use also the spacebar, return, or enter keys)'), nl, 
    4087     write('        l - leap (continues execution until the next spy point is found)'), nl, 
    4088     write('        s - skip (skips debugging for the current goal; only meaningful at call and redo ports)'), nl, 
    4089     write('        i - ignore (ignores goal, assumes that it succeeded; only valid at call and redo ports)'), nl, 
    4090     write('        f - fail (forces backtracking; may also be used to convert an exception into a failure)'), nl, 
    4091     write('        n - nodebug (turns off debugging)'), nl, 
    4092     write('        ! - command (reads and executes a query)'), nl, 
    4093     write('        @ - command (reads and executes a query)'), nl, 
    4094     write('        b - break (suspends execution and starts new interpreter; type end_of_file to terminate)'), nl, 
    4095     write('        a - abort (returns to top level interpreter)'), nl, 
    4096     write('        q - quit (quits Logtalk)'), nl, 
    4097     write('        d - display (writes current goal without using operator notation)'), nl, 
    4098     write('        x - context (prints execution context)'), nl, 
    4099     write('        e - exception (prints exception term thrown by current goal)'), nl, 
    4100     write('        = - debugging (prints debugging information)'), nl, 
    4101     write('        * - add (adds a context spy point for current goal)'), nl, 
    4102     write('        + - add (adds a predicate spy point for current goal)'), nl, 
    4103     write('        - - remove (removes a predicate spy point for current goal)'), nl, 
    4104     write('        h - help (prints this list of options)'), nl, 
    4105     write('        ? - help (prints this list of options)'), nl, 
     4098    write('  Available options are:'), nl, 
     4099    write('      c - creep (go on; you may use also the spacebar, return, or enter keys)'), nl, 
     4100    write('      l - leap (continues execution until the next spy point is found)'), nl, 
     4101    write('      s - skip (skips debugging for the current goal; only meaningful at call and redo ports)'), nl, 
     4102    write('      i - ignore (ignores goal, assumes that it succeeded; only valid at call and redo ports)'), nl, 
     4103    write('      f - fail (forces backtracking; may also be used to convert an exception into a failure)'), nl, 
     4104    write('      n - nodebug (turns off debugging)'), nl, 
     4105    write('      ! - command (reads and executes a query)'), nl, 
     4106    write('      @ - command (reads and executes a query)'), nl, 
     4107    write('      b - break (suspends execution and starts new interpreter; type end_of_file to terminate)'), nl, 
     4108    write('      a - abort (returns to top level interpreter)'), nl, 
     4109    write('      q - quit (quits Logtalk)'), nl, 
     4110    write('      d - display (writes current goal without using operator notation)'), nl, 
     4111    write('      x - context (prints execution context)'), nl, 
     4112    write('      e - exception (prints exception term thrown by current goal)'), nl, 
     4113    write('      = - debugging (prints debugging information)'), nl, 
     4114    write('      * - add (adds a context spy point for current goal)'), nl, 
     4115    write('      + - add (adds a predicate spy point for current goal)'), nl, 
     4116    write('      - - remove (removes a predicate spy point for current goal)'), nl, 
     4117    write('      h - help (prints this list of options)'), nl, 
     4118    write('      ? - help (prints this list of options)'), nl, 
    41064119    fail. 
    41074120 
    41084121'$lgt_dbg_do_port_option'(?, Port, Goal, Error, DbgCtx, Action) :- 
    41094122    '$lgt_dbg_do_port_option'(h, Port, Goal, Error, DbgCtx, Action). 
     4123 
     4124 
     4125 
     4126'$lgt_dbg_inc_invocation_number'(New) :- 
     4127    retract('$lgt_dbg_invocation_number_'(Old)) -> 
     4128    New is Old + 1, 
     4129    asserta('$lgt_dbg_invocation_number_'(New)). 
     4130 
     4131 
     4132'$lgt_dbg_reset_invocation_number' :- 
     4133    retractall('$lgt_dbg_invocation_number_'(_)), 
     4134    asserta('$lgt_dbg_invocation_number_'(0)). 
    41104135 
    41114136