Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Connect gdb to a running perl process

by saintmike (Vicar)
on Feb 14, 2005 at 08:32 UTC ( [id://430719]=perlquestion: print w/replies, xml ) Need Help??

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

Esteemed monks,

the gdb debugger can connect to any running process, perl scripts included. So if I know that my script has process id 1234, I can simply call

gdb -p 1234
and boom! I'm connected to the script. But can I also figure out which file and which line the script is currently processing? Typing where shows a stack trace:
(gdb) where #0 0x55000402 in ?? () #1 0x00c75420 in __nanosleep_nocancel () from /lib/tls/libc.so.6 #2 0x00c7526f in sleep () from /lib/tls/libc.so.6 #3 0x080dacea in Perl_pp_sleep () #4 0x080a6044 in Perl_runops_standard () #5 0x0806103e in S_run_body () #6 0x08060e36 in perl_run () #7 0x0805e359 in main ()
Does anyone know enough about perlguts to figure out from here where (file/line) the script is right now?

Replies are listed 'Best First'.
Re: Connect gdb to a running perl process
by Zaxo (Archbishop) on Feb 14, 2005 at 09:55 UTC

    If you compile perl with DEBUGGING, you not only get the use of the -D option, you also get the symbol table and debug info preserved. That is fine fodder for gdb.

    After Compline,
    Zaxo

Re: Connect gdb to a running perl process
by rob_au (Abbot) on Feb 14, 2005 at 09:56 UTC

    This might be a stupid question, but why are you using gdb to debug your Perl script? Why not invoke the Perl debugger? If you do need to debug using gdb, some of the methodology described at http://modperlbook.org/html/ch21_07.html may be of use.

    (By the way, from the where output, I would hazard a guess that your Perl code is executing a sleep statement)

     

    perl -le "print unpack'N', pack'B32', '00000000000000000000001000000000'"

      This might be a stupid question, but why are you using gdb to debug your Perl script? Why not invoke the Perl debugger?

      You can't call the perl debugger on a running perl script, can you? Requirement is to not having to restart the process.

      (By the way, from the where output, I would hazard a guess that your Perl code is executing a sleep statement)

      Right, this was a sample script. I was hoping there was a proven sequence of gdb commands to examine perl's internal data structures revealing the current file and line.

Re: Connect gdb to a running perl process
by rockyb (Scribe) on Apr 12, 2014 at 15:50 UTC

    Josh Jore gives instruction in use.perl.org.

    Subsequently (I think), he turned this into his Perl Module on CPAN App::Stacktrace.

    I recently created a fork of that from Jore's github repository to add the kind of frame in the display — sub, eval, or FORMAT. I would like to include the subroutine name for sub and don't know how to. And that's how I stumbled across this query.

    So sorry if it's a little late.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 13:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found