Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

How to attach a perl debugger to a running perl

by Eyck (Priest)
on Sep 21, 2006 at 14:11 UTC ( #574131=perlquestion: print w/replies, xml ) Need Help??

Eyck has asked for the wisdom of the Perl Monks concerning the following question:

This works:
gdb -p $pid
but gdb is not particularly usefull when debugging perl. (unless I'm missing something).

What I would like, is a way to attach something that can see perl variables, for example, I would like to attach to a process, and look at %sth hash...

Replies are listed 'Best First'.
Re: How to attach a perl debugger to a running perl
by liverpole (Monsignor) on Sep 21, 2006 at 14:58 UTC
    Hi Eyck, If you read the perl 5.9.4 todo list, and specifically this section, you'll see this is something that's been proposed:
    Attach/detach debugger from running program The old perltodo notes "With gdb, you can attach the debugger to a run +ning program if you pass the process ID. It would be good to do this with t +he Perl debugger on a running Perl program, although I'm not sure how it +would be done." ssh and screen do this with named pipes in /tmp. Maybe we ca +n too.

    It's clearly a technique that many would love to have.  As far as I know, though, it hasn't been implemented yet.

      Thanks for the info, I thought I'm just missing something, as such functionality is/would be immensly usefull.
        FWIW: I'm trying...

        As noted in Devel::STrace: strace for Perl scripts (with some seedlings), Devel::STrace et al. provide the seeds to support an attachable debugger. I'm hoping to get one together within a month or so.

        It will also be browser based, and multithread/multiprocess friendly...and (hopefully) collaborative.

        Alas, that doesn't solve your problem today <sigh/>

        If you're willing to roll up your sleeves, you might be able to either hack up Devel::STrace/Devel::RingBuffer to achieve what you need, or maybe wire something together with Devel::ebug.

Re: How to attach a perl debugger to a running perl
by Fletch (Bishop) on Sep 21, 2006 at 15:01 UTC

    Unless it's started with debugging enabled, no I don't think there's a way to get an existing process into the debugger. However having said that you probably could come up with a creative combination of PERLDB_OPTS and a subroutine which you trigger somehow (say sending your process a SIGUSR1) that sets $DB::signal to make it so that you can get it to drop into the debugger on demand rather than from the start. See perldebtut, perldebug, and perldebguts for more hints (and I don't want to hear any complaints about performance if you run everything under the debugger :).

    (And as a parenthetical aside, it'd be cool if there was some way to do something in Perl akin to the Ruby on Rails breakpoint / script/breakpointer setup. That lets you have breakpoint calls in your Rails code and then you run the breakpointer script which attaches to an irb (interactive Ruby; think perl -de 0) session which interacts with the Rails app via DRb calls.)

Re: How to attach a perl debugger to a running perl
by grep (Monsignor) on Sep 21, 2006 at 14:54 UTC
    I don't know of a way to start the debugger after the script is running.

    Use perl -d You can can step through the script and then use x %sth to inspect the vars. You can also use V main to view all vars in the main package.

    take a look at perlrun and perldebug

    Mynd you, mønk bites Kan be pretti nasti...
Re: How to attach a perl debugger to a running perl
by berntsmr (Novice) on Sep 21, 2006 at 19:12 UTC
    I prefer the gui interface provided by perl -d:ptkdb <SCRIPTNAME> You must have the DEVEL/ module installed for this to work. On the other hand, I've used signals to adjust variables inside a script that control the amount of debug information written out. I gave the ability to "kick" the script through debug levels 1-4 and back to off. That worked quite well and would provide you the opportunity to get specific variable dumps at certain points in your code.
Re: How to attach a perl debugger to a running perl
by CountZero (Bishop) on Sep 21, 2006 at 21:06 UTC
    From within Komodo you can set breakpoints, "watch" variables and single step your program.


    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      First you must have error logs file path in your server. With that you can able to trace the error in the file. Or you can just add the following code to see whether that particular function is working or not:
      print "Content-type:text/html\n\n"; print "here";

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://574131]
Approved by Corion
Front-paged by Old_Gray_Bear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2023-01-29 18:01 GMT
Find Nodes?
    Voting Booth?

    No recent polls found