[Q] how to debug perl compiled with -g flag?

K

kj

I know how to debug C programs, but I could use some advice on how
to debug perl (as a C program, that is, not by using perl -d, so
that I can go into subs coded in C). Does anyone know of a tutorial
showing how one does this?

Thanks!

kj
 
T

Tassilo v. Parseval

Also sprach kj:
I know how to debug C programs, but I could use some advice on how
to debug perl (as a C program, that is, not by using perl -d, so
that I can go into subs coded in C). Does anyone know of a tutorial
showing how one does this?

You debug it the same way as any other C program:

ethan@ethan:~$ gdb Projects/installed-perls/perl/pAfY0xH/perl-5.8.0@22901/bin/perl
GNU gdb 5.3
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) set args -e 'sub DESTROY { 1 for my @alarms } \
$server->{foo} = bless []; \
delete $server->{foo} for $server->{foo}, undef; \
'
(gdb) run
Starting program:
/home/ethan/Projects/installed-perls/perl/pAfY0xH/perl-5.8.0@22901/bin/perl
-e 'sub DESTROY { 1 for my @alarms } $server->{foo} = bless []; delete
$server->{foo} for $server->{foo}, undef;'

Program received signal SIGSEGV, Segmentation fault.
0x400f7755 in chunk_alloc () from /lib/libc.so.6
(gdb) bt
#0 0x400f7755 in chunk_alloc () from /lib/libc.so.6
#1 0x400f75ce in malloc () from /lib/libc.so.6
#2 0x080ba5fe in Perl_safesysmalloc (size=1008) at util.c:67
#3 0x080dbbf7 in S_more_sv () at sv.c:322
#4 0x080e61c6 in Perl_newSV (len=0) at sv.c:5293
#5 0x080ce03c in Perl_newAV () at av.c:355
#6 0x080a3c46 in Perl_pad_push (padlist=0x8197eb0, depth=9359, has_args=1) at pad.c:1565
#7 0x080da6b3 in Perl_pp_entersub () at pp_hot.c:2688
#8 0x08063ee1 in S_call_body (myop=0xbf800300, is_eval=0) at perl.c:2158
#9 0x08063b61 in Perl_call_sv (sv=0x8197ea4, flags=150) at perl.c:2079
#10 0x080e74a7 in Perl_sv_clear (sv=0x818a0c0) at sv.c:5880
#11 0x080e7e42 in Perl_sv_free2 (sv=0x818a0c0) at sv.c:6148
#12 0x080e79f4 in Perl_sv_clear (sv=0x8197e50) at sv.c:5978
#13 0x080e7e42 in Perl_sv_free2 (sv=0x8197e50) at sv.c:6148
#14 0x08108452 in Perl_leave_scope (base=168452) at scope.c:750
#15 0x0810641c in Perl_pop_scope () at scope.c:137
#16 0x08111277 in Perl_pp_leaveloop () at pp_ctl.c:1871
#17 0x080ba0fa in Perl_runops_debug () at dump.c:1564
#18 0x08063ef6 in S_call_body (myop=0xbf800680, is_eval=0) at perl.c:2161
#19 0x08063b61 in Perl_call_sv (sv=0x8197ea4, flags=150) at perl.c:2079
[...]
---Type <return> to continue, or q <return> to quit---q
Quit
(gdb) break Perl_call_sv
Breakpoint 1 at 0x806356c: file perl.c, line 1990.
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
[...]
Breakpoint 1, Perl_call_sv (sv=0x8197ea4, flags=150) at perl.c:1990

1990 dSP;
(gdb) call Perl_sv_dump(sv)
SV = PVCV(0x8195ad0) at 0x8197ea4
REFCNT = 2
FLAGS = ()
IV = 0
NV = 0
COMP_STASH = 0x8189fe8 "main"
START = 0x818dea0 ===> 0
ROOT = 0x818df80
XSUB = 0x0
XSUBANY = 0
GVGV::GV = 0x8197ed4 "main" :: "DESTROY"
FILE = "-e"
DEPTH = 0
FLAGS = 0x0
OUTSIDE_SEQ = 0
PADLIST = 0x8197eb0
OUTSIDE = 0x818a1ec (MAIN)
(gdb) n
1994 volatile I32 retval = 0;
(gdb) etc...

So you fire up the debugger on the perl executables. After that you set
the execution arguments. For 'gdb' this is done with 'set args'. You
pass it any parameters that perl usually receives such as

(gdb) set args -MCGI=:all -e 'print header("text/html")'

or for running a script in a file

(gdb) set args script.pl

And then you can do the usual debugging stuff, like setting break
points, executing code in the current context, looking at nice
backtracks etc.

Tassilo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top