develooper Front page | perl.perl5.porters | Postings from September 2013

A few Perl gdb debugging tools

Thread Next
From:
wolfsage
Date:
September 26, 2013 15:27
Subject:
A few Perl gdb debugging tools
Message ID:
CAJ0K8bgSi++wFd_xBzSzFyJ21pvVW4+UdmZoMoBCm7EWqx6jsg@mail.gmail.com
Howdy folks,

I've written two debugging tools for use with Perl and gdb that may be
of use to some of you.

They are:

  https://metacpan.org/module/Devel::GDB::Breakpoint
  https://metacpan.org/module/Devel::GDB::Parser::Breakpoint

Devel::GDB::Breakpoint lets you insert easy-to-break-on subs into your
Perl code that will be executed at runtime:

  # prog.pl
  use Devel::GDB::Breakpoint;

  print "before";
  breakpoint 42;
  print "after";

  $ gdb --args perl ./prog.pl
  > b bp if val == 42
  > run

This will break when the op containing breakpoint() gets executed and
the underlying C bp() call is made.

Devel::GDB::Parser::Breakpoint allows similar functionality, but the C
function is executed at parse/lexer time:

  # prog.pl
  use Devel::GDB::Parser::Breakpoint;

  print "before";
  parser_breakpoint 42;
  if ; # syntax error

  $ gdb --args perl ./prog.pl
  > b bp if val == 42
  > run

This will break at the parser_breakpoint line before "if ;" has been
parsed, so you can look around.

Hope these are useful.

If there's a better way to do both of these things (prior art, simpler
tricks with gdb without needing external modules) please share.

Cheers,

-- Matthew Horsfall (alh)

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