P
Pat Deegan
Greetings,
I originally posted this to 'comp.lang.perl' which, apparently, doesn't
exist... brilliant...
I've been having issues while debugging programs. The problems only
appear when using the '-d' switch and I get the impression it has to do
with UTF8 and regex matching but I don't know how to deal with it.
One particular example is a program which uses the DBI to connect to a
database, which will run fine normally but will hang during the call to
DBI->connect() when running under the debugger.
In order to demonstrate the problem, I inserted a couple of bread crumbs
in the DBI.pm file, in the connect() method (at the <=== comments):
1) Just after the DSN is set (around line 460):
$dsn ||= $ENV{DBI_DSN} || $ENV{DBI_DBNAME} || '' unless $old_driver;
print STDERR "DSN: $dsn\n"; # <=== output DSN as passed to connect()
2) Just after the "dbi:driver" prefix is extracted from the DSN (near line
470):
# extract dbi:driver prefix from $dsn into $1
$dsn =~ s/^dbi\w*?)(?:\((.*?)\))?://i
or '' =~ /()/; # ensure $1 etc are empty if match
fails
print STDERR "DSN: $dsn\nDriver: '$1'\n"; # <=== output modified DSN
# and extracted driver
Running the program therefore outputs some info on the dsn and driver to
stderr. A normal program run outputs:
$ perl ./myapp.pl
DSN: dbi:mysql:database=mydb;host=localhost
DSN: database=mydb;host=localhost
Driver: 'mysql'
The problem appears when calling the program with -d. Here the program is
loaded in the debugger and simply 'c'ontinued.
$ perl -d ./myapp.pl
Loading DB routines from perl5db.pl version 1.19 Editor support
available.
Enter h or `h h' for help, or `man perldebug' for more help.
main:./myapp.pl:2): my $numTrials = shift || "1";
DB<1> c
DSN: dbi:mysql:database=mydb;host=localhost
DSN: dbi:mysql:database=mydb;host=localhost
Driver: ''
This is where the program hangs. It seems the (same) dsn did NOT match
the regex this time--the DSN is unchanged and the driver variable is
empty. Hitting ctrl-C will abort the loop and land me somewhere in a
UTF8-related sub, like:
utf8::SWASHGET(/usr/lib/perl5/5.8.0/utf8_heavy.pl:308): 308:
for ($key = $min; $key <= $max; $key++) {
And all this only happens with 'perl -d'. I tried tweaking a few
environment variables, like LANG and SUPPORTED, setting them as
$ export LANG=en_US
$ export SUPPORTED=en_US:en
in a vain attempt to avoid UTF-8 altogether. This had no effect.
Does anyone know how to resolve or work around this problem?
Thanks in advance for any assistance.
In case it's relevant, here's the output of 'perl -V' on this Red Hat
Linux 9 (Shrike) system:
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
Platform:
osname=linux, osvers=2.4.20-2.48smp, archname=i386-linux-thread-multi
uname='linux stripples.devel.redhat.com 2.4.20-2.48smp #1 smp thu feb
13 11:44:55 est 2003 i686 i686 i386 gnulinux ' config_args='-des
-Doptimize=-O2 -march=i386 -mcpu=i686 -g -Dmyhostname=localhost
-Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc.
-Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux
-Dvendorprefix=/usr -Dsiteprefix=/usr
-Dotherlibdirs=/usr/lib/perl5/5.8.0 -Duseshrplib -Dusethreads
-Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db
-Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio
-Dinstallusrbinperl -Ubincompat5005 -Uversiononly
-Dpager=/usr/bin/less -isr' hint=recommended, useposix=true,
d_sigaction=define usethreads=define use5005threads=undef
useithreads=define usemultiplicity=define useperlio=define
d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef
use64bitall=undef uselongdouble=undef usemymalloc=n,
bincompat5005=undef
Compiler:
cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DDEBUGGING -fno-strict-aliasing -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
optimize='-O2 -march=i386 -mcpu=i686 -g', cppflags='-D_REENTRANT
-D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing
-I/usr/local/include -I/usr/include/gdbm' ccversion='',
gccversion='3.2.2 20030213 (Red Hat Linux 8.0 3.2.2-1)',
gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8,
byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8,
Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib
/usr/lib
libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
libc=/lib/libc-2.3.1.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.3.1'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic
-Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: DEBUGGING MULTIPLICITY USE_ITHREADS
USE_LARGE_FILES PERL_IMPLICIT_CONTEXT Locally applied patches:
MAINT18379
Built under linux
Compiled at Feb 18 2003 22:19:53
@INC:
/usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.0
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.0
/usr/lib/perl5/vendor_perl
/usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0
I originally posted this to 'comp.lang.perl' which, apparently, doesn't
exist... brilliant...
I've been having issues while debugging programs. The problems only
appear when using the '-d' switch and I get the impression it has to do
with UTF8 and regex matching but I don't know how to deal with it.
One particular example is a program which uses the DBI to connect to a
database, which will run fine normally but will hang during the call to
DBI->connect() when running under the debugger.
In order to demonstrate the problem, I inserted a couple of bread crumbs
in the DBI.pm file, in the connect() method (at the <=== comments):
1) Just after the DSN is set (around line 460):
$dsn ||= $ENV{DBI_DSN} || $ENV{DBI_DBNAME} || '' unless $old_driver;
print STDERR "DSN: $dsn\n"; # <=== output DSN as passed to connect()
2) Just after the "dbi:driver" prefix is extracted from the DSN (near line
470):
# extract dbi:driver prefix from $dsn into $1
$dsn =~ s/^dbi\w*?)(?:\((.*?)\))?://i
or '' =~ /()/; # ensure $1 etc are empty if match
fails
print STDERR "DSN: $dsn\nDriver: '$1'\n"; # <=== output modified DSN
# and extracted driver
Running the program therefore outputs some info on the dsn and driver to
stderr. A normal program run outputs:
$ perl ./myapp.pl
DSN: dbi:mysql:database=mydb;host=localhost
DSN: database=mydb;host=localhost
Driver: 'mysql'
The problem appears when calling the program with -d. Here the program is
loaded in the debugger and simply 'c'ontinued.
$ perl -d ./myapp.pl
Loading DB routines from perl5db.pl version 1.19 Editor support
available.
Enter h or `h h' for help, or `man perldebug' for more help.
main:./myapp.pl:2): my $numTrials = shift || "1";
DB<1> c
DSN: dbi:mysql:database=mydb;host=localhost
DSN: dbi:mysql:database=mydb;host=localhost
Driver: ''
This is where the program hangs. It seems the (same) dsn did NOT match
the regex this time--the DSN is unchanged and the driver variable is
empty. Hitting ctrl-C will abort the loop and land me somewhere in a
UTF8-related sub, like:
utf8::SWASHGET(/usr/lib/perl5/5.8.0/utf8_heavy.pl:308): 308:
for ($key = $min; $key <= $max; $key++) {
And all this only happens with 'perl -d'. I tried tweaking a few
environment variables, like LANG and SUPPORTED, setting them as
$ export LANG=en_US
$ export SUPPORTED=en_US:en
in a vain attempt to avoid UTF-8 altogether. This had no effect.
Does anyone know how to resolve or work around this problem?
Thanks in advance for any assistance.
In case it's relevant, here's the output of 'perl -V' on this Red Hat
Linux 9 (Shrike) system:
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
Platform:
osname=linux, osvers=2.4.20-2.48smp, archname=i386-linux-thread-multi
uname='linux stripples.devel.redhat.com 2.4.20-2.48smp #1 smp thu feb
13 11:44:55 est 2003 i686 i686 i386 gnulinux ' config_args='-des
-Doptimize=-O2 -march=i386 -mcpu=i686 -g -Dmyhostname=localhost
-Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc.
-Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux
-Dvendorprefix=/usr -Dsiteprefix=/usr
-Dotherlibdirs=/usr/lib/perl5/5.8.0 -Duseshrplib -Dusethreads
-Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db
-Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio
-Dinstallusrbinperl -Ubincompat5005 -Uversiononly
-Dpager=/usr/bin/less -isr' hint=recommended, useposix=true,
d_sigaction=define usethreads=define use5005threads=undef
useithreads=define usemultiplicity=define useperlio=define
d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef
use64bitall=undef uselongdouble=undef usemymalloc=n,
bincompat5005=undef
Compiler:
cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS
-DDEBUGGING -fno-strict-aliasing -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
optimize='-O2 -march=i386 -mcpu=i686 -g', cppflags='-D_REENTRANT
-D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing
-I/usr/local/include -I/usr/include/gdbm' ccversion='',
gccversion='3.2.2 20030213 (Red Hat Linux 8.0 3.2.2-1)',
gccosandvers='' intsize=4, longsize=4, ptrsize=4, doublesize=8,
byteorder=1234 d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=12 ivtype='long', ivsize=4, nvtype='double', nvsize=8,
Off_t='off_t', lseeksize=8 alignbytes=4, prototype=define
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib
/usr/lib
libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
perllibs=-lnsl -ldl -lm -lpthread -lc -lcrypt -lutil
libc=/lib/libc-2.3.1.so, so=so, useshrplib=true, libperl=libperl.so
gnulibc_version='2.3.1'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic
-Wl,-rpath,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Characteristics of this binary (from libperl):
Compile-time options: DEBUGGING MULTIPLICITY USE_ITHREADS
USE_LARGE_FILES PERL_IMPLICIT_CONTEXT Locally applied patches:
MAINT18379
Built under linux
Compiled at Feb 18 2003 22:19:53
@INC:
/usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.0
/usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.0
/usr/lib/perl5/vendor_perl
/usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0