Devel::hdb debugger talk

download Devel::hdb debugger talk

If you can't read please download the document

Transcript of Devel::hdb debugger talk

Debugging your Perl programs

Debugging your Perl programs

Methodsprint

Debugging your Perl programs

Methodsprint

warn

Debugging your Perl programs

Methodsprint

warn

die

Debugging your Perl programs

Methodsprint

warn

die

Logging (print to file, Log4Perl, etc)

Debugging your Perl programs

Methodsprint

warn

die

Logging (print to file, Log4Perl, etc)

tie() variables

Debugging your Perl programs

Methodsprint

warn

die

Logging (print to file, Log4Perl, etc)

tie() variables

Data::Dumper, Data::Dump

Debugging your Perl programs

Methodsprint

warn

die

Logging (print to file, Log4Perl, etc)

tie() variables

Data::Dumper, Data::Dump

Hook::LexWrap

Debugging your Perl programs

> perl -d try.plLoading DB routines from perl5db.pl version 1.39_10Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(try2.pl:4):print "hello world\n"; DB _

Debugging your Perl programs

DB hList/search source lines: Control script execution: l [ln|sub] List source code T Stack trace - or . List previous/current line s [expr] Single step [in expr] v [line] View around line n [expr] Next, steps over subs f filename View source in file Repeat last n or s /pattern/ ?patt? Search forw/backw r Return from subroutine M Show module versions c [ln|sub] Continue until positionDebugger controls: L List break/watch/actions o [...] Set debugger options t [n] [expr] Toggle trace [max depth] ][trace expr] ] [cmd] Do pre/post-prompt b [ln|event|sub] [cnd] Set breakpoint ! [N|pat] Redo a previous command B ln|* Delete a/all breakpoints H [-num] Display last num commands a [ln] cmd Do cmd before line = [a val] Define/list an alias A ln|* Delete a/all actions h [db_cmd] Get help on command w expr Add a watch expression h h Complete help page W expr|* Delete a/all watch exprs |[|]db_cmd Send output to pager ![!] syscmd Run cmd in a subprocess q or ^D Quit R Attempt a restartData Examination: expr Execute perl code, also see: s,n,t expr x|m expr Evals expr in list context, dumps the result or lists methods. p expr Print expression (uses script's current package). S [[!]pat] List subroutine names [not] matching pattern V [Pk [Vars]] List Variables in Package. Vars can be ~pattern or !pattern. X [Vars] Same as "V current_package [Vars]". i class inheritance tree. y [n [Vars]] List lexicals in higher scope . Vars same as V. e Display thread id E Display all thread ids.For more help, type h cmd_letter, or run man perldebug for all docs. DB

Debugging your Perl programs

> perl -d:ptkdb try.pl

Debugging your Perl programs

> perl -d:hdb try.plDebugger pid 87264 listening on http://127.0.0.1:8080/debugger-gui

Debugging your Perl programs

> perl -d:hdb try.plHTTP::Server::PSGI (part of Plack)jQueryTwitter BootstrapHandlebarsDevel::Chitin

Demo!

> perl -d:hdb demo_program.plSingle step, over, etc

Watch variables

Breakpoints

Stack

Mouseover variables in other frames

Breakpoints/actions

Fork

Uncaught exceptions

Trace and Follow

> perl -d:hdb=trace:tracefile trace_follow.pl 1

Trace and Follow

> perl -d:hdb=trace:tracefile trace_follow.pl 1Writing execution trace to tracefile...program is runningEverything is working okDoing some more stuff...Exiting> _

Trace and Follow

> perl -d:hdb=trace:tracefile trace_follow.pl 1Writing execution trace to tracefile...program is runningEverything is working okDoing some more stuff...Exiting> perl -d:hdb=follow:tracefile trace_follow.pl 0Debugger pid 87677 listening on http://127.0.0.1:8080/debugger-gui

Devel::Chitin

Extracted debugger-specific code

Object-oriented interface

Multiple debugger modules

Devel::Chitin Basic control

$db->attach();$db->detach();

Devel::Chitin Basic control

$db->attach();$db->detach();$db->step; $db->stepover(); $db->stepout();$db->continue();$db->trace($flag);

Devel::Chitin Info

$bool = $db->is_loaded($filename);$arrayref = $db->file_source($filename);@names = $db->loaded_files();$stack = $db->stack();$loc = $db->current_location();

Devel::Chitin Events

$db->init();$db->notify_stopped($loc);$db->notify_trace($loc);$db->notify_fork_parent($loc, $pid);$db->notify_fork_child($loc);$db->notify_program_terminated($loc);$db->notify_uncaught_exeption($exc);

Simple Debugger Demo

perl -d:SimpleDebugger trace_follow.pl

Simple Debugger Demo

package Devel::SimpleDebugger;

use base qw(Devel::Chitin);Devel::SimpleDebugger->attach();

sub notify_stopped { my($self, $location) = @_; my $file_lines = $self->file_source($location->filename);

printf("Stopped at %s:%d >> %s", $location->filename, $location->line, $file_lines->[ $location->line ]); scalar(); $self->step;}

1;

Simple Profiler Demo

perl -d:SimpleProf trace_follow.pl

Simple Profiler Demo

package Devel::SimpleProf;

use strict;use warnings;use base qw(Devel::Chitin);use Time::HiRes;

Devel::SimpleProf->attach();Devel::SimpleProf->trace(1);

my($last_location, $last_time) = (0, Time::HiRes::time);

sub notify_trace { my $now = Time::HiRes::time(); my($self, $location) = @_;

if ($last_location) { my $diff = $now - $last_time; printf("%s:%d took %0.3f ms\n", $last_location->filename, $last_location->line, ($now - $last_time)*1000); }}

sub notify_trace_resumed { my($self, $location) = @_; $last_location = $location; $last_time = Time::HiRes::time;}

1;

Both at the same time

perl -d:SimpleProf -MDevel::SimpleDebugger trace_follow.pl

Devel::Chitin new stuff

my $perl = $db->next_statement()

Deparses the OpTree at the stopped location back into Perl code

Devel::Chitin new stuff

my $perl = $db->next_statement()

> perl -d:Chitin -MShowNext deparse_demo.pl

Sources

Devel::hdbhttps://metacpan.org/pod/Devel::hdb

https://github.com/brummett/Devel-hdb

Devel::Chitinhttps://metacpan.org/pod/Devel::Chitin

https://github.com/brummett/Devel-Chitin

Demo codehttps://github.com/brummett/Devel-hdb-talk