Perl Monk, Perl Meditation | |
PerlMonks |
Re: Is there any way of determining the current line number of a child process while it is running?by hv (Prior) |
on May 02, 2003 at 04:47 UTC ( [id://254901]=note: print w/replies, xml ) | Need Help?? |
Getting a bit uglier, here's a hack that takes a rather different approach: it uses 'gdb' to attach to the process with the given pid, and queries perl's internal structures. Use with caution. :)
A brief explanation: PL_curcop is a variable used in perl to hold details about the current execution state, including the last seen line number and a reference to the glob for the file the code came from. Note that occasionally PL_curcop may be null, in which case this'll just print "unknown". Also, when the execution is inside code evalled from a string, it'll show something like: .. which may not be supremely useful if your code spends a lot of time in such things. I should stress that this is a quick hack - doing it properly would at the very least involve using a safer approach for temporary files. I'm also not sure how recent a version of gdb is required for this, though it works ok for me with "GNU gdb 5.0rh-5 Red Hat Linux 7.1". Hope it helps, Hugo
In Section
Seekers of Perl Wisdom
|
|