/*
 * $Id: /mirror/trunk/src/ops/debug.ops 32253 2008-10-28T20:44:01.227920Z julianalbo  $
 * Copyright (C) 2002-2008, The Perl Foundation.
 */

/*
** debug.ops
*/

VERSION = PARROT_VERSION;

=head1 NAME

debug.ops

=cut

=head1 DESCRIPTION

Parrot debugger

=cut

=head1 HISTORY

Initial version by Daniel Grunblatt on 2002.5.19

=cut

###############################################################################

=head2 Parrot debug operations

=over 4

=cut

########################################

=item B<debug_init>()

Init the Parrot debugger, must be called before any other debug op.

=cut

op debug_init() :base_debug {
    Parrot_debugger_init(interp);
}

########################################

=item B<debug_load>(inconst STR)

Load a Parrot source file for the current program.

=cut

op debug_load(inconst STR) :base_debug {
    Parrot_debugger_load(interp, $1);
}

########################################

=item B<debug_break>()

Break execution and drop into the debugger.
If we are already into the debugger and is the first time we are
called set a breakpoint.

When you re run/continue the program begin debugged it will pay
no attention to the debug ops.

RT #42377: clone the interpreter to allow people to play into the
debugger and then continue the normal execution of the program.

=cut

op debug_break() :base_debug {
    Parrot_debugger_break(interp, cur_opcode);
}

########################################

=item B<debug_print>()

Print all the Parrot registers at once.

=cut

op debug_print() :base_debug {
    if (!interp->pdb) {
        opcode_t *handler = Parrot_ex_throw_from_op_args(interp, expr NEXT(),
            EXCEPTION_INVALID_OPERATION,
            "Initialize debugger with debug_init before using debug_print");
        goto ADDRESS(handler);
    }

    if (!(interp->pdb->state & PDB_BREAK)) {
        PDB_print(interp, "I");
        PDB_print(interp, "N");
        PDB_print(interp, "S");
        PDB_print(interp, "P");
    }
}

=item B<backtrace>()

Print a backtrace.

=cut

op backtrace() :base_debug {
    PDB_backtrace(interp);
}

#######################################

=item B<getline>(out INT)

Get the current line number.

=cut

inline op getline(out INT) {
  Parrot_Context_info info;
  Parrot_Context_get_info(interp, CONTEXT(interp), &info);
  $1 = info.line;
}

=item B<getfile>(out STR)

Get the name of the current file.

=cut

inline op getfile(out STR) {
  Parrot_Context_info info;
  Parrot_Context_get_info(interp, CONTEXT(interp), &info);
  $1 = info.file;
}

=back

=cut

/*
 * Local variables:
 *   c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
