develooper Front page | perl.perl6.internals | Postings from April 2001

PDD for debugger

Thread Next
From:
Dave Storrs
Date:
April 26, 2001 16:34
Subject:
PDD for debugger
Message ID:
Pine.BSF.4.21.0104261633540.22100-100000@megazone23.bigpanda.com
=head1 The Perl6 Debugger

=head2 Perl-level Debugging

=head3 Existing Functionality

The following is a list of the functionality in the existing Perl5
debugger; this functionality should, of course, be maintained for
backwards compatibility.

=over 4

=item T               

Stack trace.

=item s [expr]        

Single step [in expr].

=item n [expr]        

Next, steps over subroutine calls [in expr].

=item <CR>            

Repeat last n or s command.

=item r               

Return from current subroutine.

=item c [line|sub]    

Continue; optionally inserts a one-time-only breakpoint at the
specified position.

=item l min+incr      

List incr+1 lines starting at min.

=item l min-max       

List lines min through max.

=item l line          

List single line.

=item l subname       

List first window of lines from subroutine.

=item l C<$var>

List first window of lines from subroutine referenced by C<$var>.

=item l               

List next window of lines.

=item -               

List previous window of lines.

=item w [line]        

List window around line.

=item .               

Return to the executed line.

=item f filename      

Switch to viewing filename. File must be already loaded.  Filename may
be either the full name of the file, or a regular expression matching
the full file name: f /home/me/foo.pl and f oo\. may access the same
file.  Evals (with saved bodies) are considered to be filenames: f
(eval 7) and f eval 7\b access the body of the 7th eval (in the order
of execution).

=item /pattern/       

Search forwards for pattern; final / is optional.

=item ?pattern?       

Search backwards for pattern; final ? is optional.

=item L               

List all breakpoints and actions.

=item S [[!]pattern]  

List subroutine names [not] matching pattern.

=item t               

Toggle trace mode.

=item t expr          

Trace through execution of expr.

=item b [line] [condition]

Set breakpoint; line defaults to the current execution line; condition
breaks if it evaluates to true, defaults to '1'.

=item b subname [condition]

Set breakpoint at first line of subroutine.

=item b C<$var>

Set breakpoint at first line of subroutine referenced by C<$var>.

=item b load filename 

Set breakpoint on `require'ing the given file.

=item b postpone subname [condition]
        
Set breakpoint at first line of subroutine after it is compiled.

=item b compile subname

Stop after the subroutine is compiled.

=item d [line]        

Delete the breakpoint for line.

=item D               

Delete all breakpoints.

=item a [line] command
        
Set an action to be done before the line is executed; line defaults to
the current execution line.  Sequence is: check for
breakpoint/watchpoint, print line if necessary, do action, prompt user
if necessary, execute line.

=item a [line]        

Delete the action for line.

=item A               

Delete all actions.

=item W expr          

Add a global watch-expression.

=item W               

Delete all watch-expressions.

=item V [pkg [vars]]  

List some (default all) variables in package (default current). Use
~pattern and !pattern for positive and negative regexps.

=item X [vars]        

Same as "V currentpackage [vars]".

=item x expr          

Evals expression in array context, dumps the result.

=item m expr          

Evals expression in array context, prints methods callable on the
first element of the result.

=item m class         

Prints methods callable via the given class.
 
=item < ?             

List Perl commands to run before each prompt.

=item < expr          

Define Perl command to run before each prompt.

=item << expr         

Add to the list of Perl commands to run before each prompt.

=item > ?             

List Perl commands to run after each prompt.

=item > expr          

Define Perl command to run after each prompt.

=item >> expr         

Add to the list of Perl commands to run after each prompt.

=item { db_command    

Define debugger command to run before each prompt.

=item { ?             

List debugger commands to run before each prompt.

=item < expr          

Define Perl command to run before each prompt.

=item {{ db_command   

Add to the list of debugger commands to run before each prompt.

=item ! number        

Redo a previous command (default previous command).

=item ! -number       

Redo number'th-to-last command.

=item ! pattern       

Redo last command that started with pattern. See 'O recallCommand' too.

=item !! cmd          

Run cmd in a subprocess (reads from DB::IN, writes to DB::OUT) See 'O
shellBang' too.

=item H -number       

Display last number commands (default all).

=item p expr          

Same as "print {DB::OUT} expr" in current package.

=item |dbcmd          

Run debugger command, piping DB::OUT to current pager.

=item ||dbcmd         

Same as |dbcmd but DB::OUT is temporarilly select()ed as well.

=item = [alias value] 

Define a command alias, or list current aliases.

=item command         

Execute as a perl statement in current package.

=item v               

Show versions of loaded modules.

=item R               

Pure-man-restart of debugger, some of debugger state and command-line
options may be lost.  Currently the following setting are preserved:
history, breakpoints and actions, debugger Options and the following
command-line options: -w, -I, -e.
 
=item q or ^D         

Quit. Set C<$DB::finished> = 0 to debug global destruction.

=item h [db_command]  

Get help [on a specific debugger command], enter |h to page.

=item h h             

Summary of debugger commands.

=item man manpage     

Runs the external doc viewer man command on the named Perl manpage, or
on man itself if omitted. Set C<$DB::doccmd> to change viewer.

=item O [opt] ...     

Set boolean option to true

=item O [opt?]        

Query options

=item O [opt=val] [opt="val"] ... 

Set options.  Use quotes in spaces in value.

=over 4

=item   recallCommand

ShellBang chars used to recall command or spawn shell;

=item   pager               

Program for output of "|cmd";

=item   tkRunning           

Run Tk while prompting (with ReadLine);

=item     signalLevel, warnLevel, dieLevel 

Level of verbosity;

=item     inhibit_exit        

Allows stepping off the end of the script.

=item     ImmediateStop       

Debugger should stop as early as possible.

=item     RemotePort          

Remote hostname:port for remote debugging

=back

The following options affect what happens with V, X, and x commands:

=over 4

=item     arrayDepth, hashDepth  

Print only first N elements ('' for all);

=item     compactDump, veryCompact  

Change style of array and hash dump.

=item     globPrint           

Whether to print contents of globs;

=item     DumpDBFiles         

Dump arrays holding debugged files;

=item     DumpPackages        

Dump symbol tables of packages;

=item     DumpReused          

Dump contents of "reused" addresses;

=item     quote, HighBit, undefPrint  

Change style of string dump;

=item     bareStringify       

Do not print the overload-stringified value;

=back

Other options include:

=over 4

=item     PrintRet            

Affects printing of return value after r command,

=item     frame               

Affects printing messages on entry and exit from subroutines.

=item     AutoTrace           

Affects printing messages on every possible breaking point.

=item     maxTraceLen         

Gives maximal length of evals/args listed in stack trace.

=item     ornaments           

Affects screen appearance of the command line.

=back

During startup options are initialized from C<$ENV{PERLDB_OPTS}>.

You can put additional initialization options TTY, noTTY, ReadLine,
NonStop, and RemotePort there (or use `R' after you set them).

=back

=for html
<P><HR><P>

=head3 Suggested New Functionality

The following are suggestions for new functionality.  I have not
attempted to assign particular keyboard commands to them, because that
is an interface and naming issue.

=over 4

=item A default pager.

The Perl debugger does not currently include a default pager for long
output; this is a nontrivial problem for systems (such as Win32/DOS)
where there B<is> no default pager.  Specifically, it means that the
user may have no easy way to read all of the help that the "h" command
provides.  I'm not suggesting anything fancy here; no searching or
going backwards, just the ability to break the input into blocks of 20
lines at a time...and maybe a variable that sets exactly how large the
blocks should be.

=item Dump all lexical variables in the current scope.

It would also be nice if references would include mention of the name
and type of the variable to which they refer.  Truly spiffy would be
if closures visible in the current scope could dump the variables over
which they close.

=item Trace execution on a per-statement basis.

This one came from Dan and to be honest, I'm not exactly sure what he
intended by it--Dan, how is this different from 't' or 't expr'?

=item Dump the opcodes being executed for a particular statement.

This is basically tracing at the Perl assembly level.  Ideally, it
should display a line (or small group of lines) of source code, and
then the op codes that it (they) produced.  See next entry for why you
want this.

=item Ability to edit and recompile your code on the fly.

There would need to be limits on this; it's a bit much to expect that
you, for example, add a global pragma without needing to do a full
recompile.  There should not be any reason that you couldn't make
minor changes however (e.g., changing what constant is assigned to a
variable, or changing an '&&' to an '||').

=item Specify which line should be executed next.

It should be possible to, for example, jump back to the beginning of
the current subroutine and rerun it.  This doesn't guarantee that
things will work properly--if you choose to jump to the top of the
current subroutine but you've thrown away your @_, you're probably
hosed.

=item Show memory stats.

This would include things like "For this statement, X variables were
created and Y bytes of memory were freed."

=item Profiling.

For a given program run, the profile should be able to display the
following (whether it displays all of these stats every time or only
the ones you select is an interface issue): 

=over 4

=item *

wall-clock seconds, 

=item *

CPU seconds, 

=item *

number of CPU seconds spent on disk I/O,

=item *

number of CPU seconds spent on memory management,

=item *

number of CPU seconds spent in each function,

=item *

minimum, average, and maximum amount of memory used after the
beginning of execution, and

=item *

minimum, average, and maximum number of filehandles simultaneously
open during execution.

=back

=item Continue to other modules.

The ability to continue up to a particular line in another module (the
syntax might be something like: c Tie::Hash::116) would be very
convenient.  This can actually be accomplished now by doing f
Tie::Hash and then doing c 116, but that is not particularly
intuitive.

=item Goto caller line in the call stack.

This is actually a simple feature, but it's hard to explain.  Here's
an example; imagine the call stack looks like this:

=over 4

=item *

sub Display_Outputs()       <= current stack frame

=item *

sub Generate_Outputs()

=item *

sub Gather_Inputs()

=back

Issuing this command once would immediately shift the display to the
line in Generate_Outputs() which called the current function
(Display_Outputs()).  Issuing it again would move you one frame
further back in the call stack, to the line in Gather_Inputs() which
called which called Generate_Outputs().  The call stack is not
disturbed in the process; Display_Outputs() is still the current frame
and pressing 'n' or 's' will execute the next statement in that
function.  All this command does is shift what the debugger is
currently displaying.  This is useful when you are trying to follow
the logic of how you got to a particular point

=item Multiline eval capacity.

There was at least one RFC about this, and there were several I<long>
threads about why it was hard, etc.  I think everyone agreed that it
would be a good thing, it's simply a question of whether it's a doable
thing.

=back

The existing debugger is primarily oriented towards functional
programming.  The following suggestions are all oriented towards
the object-oriented style; no one says that you have to use OO, but if
you do, these features might be convenient.

=over 4

=item Built in DataDumper equivalent.

This would allow you to dump out an object, see if it is tied to
anything, what its representation is (hash ref, array ref, etc), what
methods it has, what variables it has, what values those variables
currently contain, etc.  (I realize this could be pretty hairy for
objects that use dynamic loading and runtime modification of C<@ISA>.)

=item Display class hierarchies.

This would obviously only display classes defined in files that are
currently loaded.

=item Method definition location.

This basically allows you to ask 'if I called method Foo() on object
C<$bar>, where is the actual definition of the function that would be
called?'  It would do the standard method lookup, just as it is done
at runtime (e.g., traversing C<@ISA> and C<AUTOLOAD>), save the
location that is currently being displayed, and move the display
to the relevant sub.  It should then be possible to easily return the
display to where it was before you issued this command (perhaps by
issuing this command again with no argument).

=back

=for html
<P><HR><P>

=head2 Internals level stuff

=over 4

=item Memory allocation tracing.

Noting when memory is allocated or reallocated for data. (As well as
for the allocation system itself.)

=item Data type conversion tracing.

Knowing that your program is spending 90% of its time converting "2.0"
into 2.0 might suggest a few easy optimizations.

=item Garbage collection stats

Specifically, it would be good to know:

=over 4

=item *

what memory gets moved from where to where and how big the move is,

=item *

how much memory was reclaimed, and

=item *

which PMCs the garbage collector visits.

=back

=item String handling and Unicode issues.

Specifically, the ability to:

=over 4

=item *

display what encoding the particular string uses,

=item *

display what normalization form the specified Unicode string uses, 

=item *

display the specified Unicode string in its current encoding/normalization
(e.g., "ASCII:{f}{o}{o}", "UTF16:{LATIN SMALL E}{ACCENT ACUTE}" or
"UTF16:{LATIN SMALL E ACCENT ACUTE}", depending), and 

=item *

force the string to a specified encoding/normalization.

=back

=back

=for html
<P><HR><P>

=head2 Implementation

I am going to make the (possibly invalid) assumption that implementing
the Perl5-debugger features will be straightforward, since we already
have the code.  That just leaves the new functionality.

=over 4

=item Default pager

I imagine a very straightforward implementation for this, something like:

=back 

=for html
while (there is data in the buffer) {
    display the next N lines (or however many are left);
    wait for the user to press a key;
}

=for text
while (there is data in the buffer) {
    display the next N lines (or however many are left);
    wait for the user to press a key;
}

=for html
<P><HR WIDTH=10 SIZE=10><P>

I'm afraid I've already taken longer than planned to get to this point, and I want to get this document shipped off tonight, so I'm going to leave the rest of these blank and submit an update tomorrow.  --DKS

=over 4

=item Dump all lexical variables in the current scope.

=item Trace execution on a per-statement basis.

=item Dump the opcodes being executed for a particular statement.

=item Ability to edit and recompile your code on the fly.

=item Specify which line should be executed next.

=item Show memory stats.

=item Profiling.

=item Continue to other modules.

=item Goto caller line in the call stack.

=item Multiline eval capacity.

=item Built in DataDumper equivalent.

=item Display class hierarchies.

=item Method definition location.

=item Memory allocation tracing.

=item Data type conversion tracing.

=item Garbage collection stats

=item String handling and Unicode issues.

=back


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About