Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.91k stars 542 forks source link

debugger T, and Carp::carp don't trace arg of $1 #4128

Closed p5pRT closed 20 years ago

p5pRT commented 23 years ago

Migrated from rt.perl.org#7170 (status was 'resolved')

Searchable as RT7170$

p5pRT commented 23 years ago

From dcd@tc.fluke.com

when I pass $1 to a subroutine\, the subroutine can access the value of the variable\, but the debugger T command and Carp​::carp display the argument as undef.

use Carp; sub t { carp "t(@​_)\n"; } t("abc"); $_="1234567"; m/^..(...)..$/; t($1);

t(abc)   main​::t('abc') called at c line 4 t(345)   main​::t('undef') called at c line 7

Perl Info ``` Flags: category=core severity=high Site configuration information for perl v5.7.1: Configured by dcd at Mon Jun 18 12:14:49 PDT 2001. Summary of my perl5 (revision 5.0 version 7 subversion 17) configuration: Platform: osname=linux, osvers=2.4.6-pre3, archname=i686-linux uname='linux dd 2.4.6-pre3 #1 wed jun 13 23:08:03 pdt 2001 i686 ' config_args='-Dinstallusrbinperl -Uversiononly -Dusedevel -Doptimize=-O3 -g -de -Dcf_email=dcd@tc.fluke.com' hint=recommended, useposix=true, d_sigaction=define usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef useperlio=define d_sfio=undef uselargefiles=define usesocks=undef use64bitint=undef use64bitall=undef uselongdouble=undef Compiler: cc='cc', ccflags ='-Wall -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O3 -g', cppflags='-Wall -DDEBUGGING -fno-strict-aliasing -I/usr/local/include' ccversion='', gccversion='egcs-2.91.66.1 19990314/Linux (egcs-1.1.2 release)', 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=4 alignbytes=4, usemymalloc=n, prototype=define Linker and Libraries: ld='cc', ldflags =' -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib libs=-lgdbm -ldbm -ldb -ldl -lm -lc perllibs=-ldl -lm -lc libc=/lib/libc.so.5.4.44, so=so, useshrplib=false, libperl=libperl.a Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic' cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib' Locally applied patches: DEVEL10688 @INC for perl v5.7.1: /usr/local/lib/perl5/5.7.1/i686-linux /usr/local/lib/perl5/5.7.1 /usr/local/lib/perl5/site_perl/5.7.1/i686-linux /usr/local/lib/perl5/site_perl/5.7.1 /usr/local/lib/perl5/site_perl/5.6.1/i686-linux /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl . Environment for perl v5.7.1: HOME=/home/dcd LANG (unset) LANGUAGE (unset) LD_LIBRARY_PATH (unset) LOGDIR (unset) PATH=/home/dcd/bin:/sbin:/usr/local/bin:/bin:/usr/bin:/usr/X11/bin:/usr/games:/usr/local/samba:/home/hobbes/tools/scripts:/home/hobbes/tools/linux:/usr0/hobbes/tools/scripts:/usr0/dcd/bin:/apps/general/bin:/usr/public PERL_BADLANG (unset) SHELL=/bin/bash ```
p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

This seems to be a very old bug - perl5.002 has it.

Patch for Carp attached. Also mends another obscure bug - you must never localise @​DB​::args; it discombobulates caller(). And a small redundancy removed and several questions answered.

The debugger case will take a little longer to fix. Exactly the same issue\, but *much* messier code.

Summary of my perl5 (revision 5.0 version 7 subversion 17) configuration​:   ^^ Eh? What version of Perl is that?

Mike Guy

Inline Patch ```diff --- ./lib/Carp/Heavy.pm.orig Tue Jun 19 00:34:31 2001 +++ ./lib/Carp/Heavy.pm Sun Jun 24 15:14:01 2001 @@ -28,8 +28,7 @@ my $sub_name = Carp::get_subname(\%call_info); if ($call_info{has_args}) { - # Reuse the @args array to avoid warnings. :-) - local @args = map {Carp::format_arg($_)} @args; + my @args = map {Carp::format_arg($_)} @args; if ($MaxArgNums and @args > $MaxArgNums) { # More than we want to show? $#args = $MaxArgNums; push @args, '...'; @@ -120,7 +119,7 @@ sub longmess_heavy { - return @_ if ref($_[0]); # WHAT IS THIS FOR??? + return @_ if ref($_[0]); # don't break references as exceptions my $i = long_error_loc(); return ret_backtrace($i, @_); } @@ -139,19 +138,19 @@ $tid_msg = " thread $tid" if $tid; } - if ($err =~ /\n$/) { + { if ($err =~ /\n$/) { # extra block to localise $1 etc $mess = $err; } else { my %i = caller_info($i); $mess = "$err at $i{file} line $i{line}$tid_msg\n"; - } + }} while (my %i = caller_info(++$i)) { $mess .= "\t$i{sub_name} called at $i{file} line $i{line}$tid_msg\n"; } - return $mess || $err; + return $mess; } sub ret_summary { @@ -190,7 +189,7 @@ sub shortmess_heavy { return longmess_heavy(@_) if $Verbose; - return @_ if ref($_[0]); # WHAT IS THIS FOR??? + return @_ if ref($_[0]); # don't break references as exceptions my $i = short_error_loc(); if ($i) { ret_summary($i, @_); End of patch ```
p5pRT commented 23 years ago

From @jhi

Very early version of bleadperl? :-)

That's what perl -V gives you . I once fixed myconfig but apparently not that (though I must check how the thing works with 5.8.0...)

kosh​:/tmp/jhi/perl ; ./myconfig Summary of my perl5 (revision 5.0 version 7 subversion 1 patchlevel 10824) configuration​:   Platform​: ...

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

From​: Jarkko Hietaniemi \jhi@​iki\.fi

On Sun\, Jun 24\, 2001 at 03​:28​:39PM +0100\, Mike Guy wrote​:

David Dyck \dcd@​tc\.fluke\.com wrote

Summary of my perl5 (revision 5.0 version 7 subversion 17) configuration​: ^^ Eh? What version of Perl is that?

Very early version of bleadperl? :-)

That's what perl -V gives you . I once fixed myconfig but apparently not that (though I must check how the thing works with 5.8.0...)

kosh​:/tmp/jhi/perl ; ./myconfig Summary of my perl5 (revision 5.0 version 7 subversion 1 patchlevel 10824) configuration​: Platform​:

here's what my myconfig prints dd​:perl-current$ ./myconfig Summary of my perl5 (revision 5.0 version 7 subversion 1 patchlevel 10742) configuration​: ...

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

Good idea.

Ocassionally I've had a need to use longmess() directly\, but haven't been able to put it in production code as it's undocumented\, and could theoretically disappear.

In fact\, they are already used\, by CGI​::Carp\, ExtUtils​::MakeMaker and perl5db.pl in the core\, and no doubt in various CPAN modules as well. So they're unlikely to disappear.

I found your suggested patch slightly eccentric\, in documenting them under "BUGS". :-) I attach my suggestion.

Mike Guy

Inline Patch ```diff --- ./lib/Carp.pm.orig Sat Jun 2 18:10:02 2001 +++ ./lib/Carp.pm Mon Jun 25 11:07:05 2001 @@ -21,6 +21,9 @@ use Carp qw(cluck); cluck "This is how we got here!"; + print FH Carp::shortmess("This will have caller's details added"); + print FH Carp::longmess("This will have stack backtrace added"); + =head1 DESCRIPTION The Carp routines are useful in your own modules because @@ -30,6 +33,11 @@ will report the error as occurring where Foo() was called, not where carp() was called. +The routine shortmess() can be used to generate the string that +carp/croak would have produced. The routine longmess() can be +used to generate the backtrace that cluck/confess would have +produced. + =head2 Forcing a Stack Trace As a debugging aid, you can force Carp to treat a croak as a confess @@ -75,7 +83,7 @@ require Exporter; @ISA = ('Exporter'); @EXPORT = qw(confess croak carp); -@EXPORT_OK = qw(cluck verbose); +@EXPORT_OK = qw(cluck verbose longmess shortmess); @EXPORT_FAIL = qw(verbose); # hook to enable verbose mode End of patch ```
p5pRT commented 23 years ago

From @jhi

Thanks\, applied. (And the earlier version retracted.)

p5pRT commented 23 years ago

From @schwern

Can we think of a better name than longmess/shortmess? backtrace/??? Or perhaps something more in line with the whole carp/croak/cluck feel.

p5pRT commented 23 years ago

From @jhi

Note that whatever we do\, the old names must stay before other modules already use those names.

Or perhaps something more in line with the whole carp/croak/cluck feel.

yodle/yelp? :-)

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

cry\, cuss\, curse\, caterwaul\, complain(t)

mutter(ed)\, moan(ed)

whimper\, whine

language is such a fun thing. :>

p5pRT commented 23 years ago

From @schwern

I like it! (Well\, yodel) Patch follows plus a rewrite of Carp.t plus I removed all the uses of longmess and shortmess I could find.

PS The original Carp.t is a perfect example of a Far Too Clever test.

PPS This is a good example of using Test​::More

--- lib/CGI/Carp.pm 2001/06/26 05​:40​:22 1.1 +++ lib/CGI/Carp.pm 2001/06/26 05​:42​:24 @​@​ -293\,10 +293\,10 @​@​ # The mod_perl package Apache​::Registry loads CGI programs by calling # eval. These evals don't count when looking at the stack backtrace. sub _longmess { - my $message = Carp​::longmess(); + my $message = Carp​::yodel();   my $mod_perl = exists $ENV{MOD_PERL};   $message =~ s\,eval[^\n]+Apache/Registry\.pm.*\,\,s if $mod_perl; - return $message;
+ return $message; }

sub die { @​@​ -321\,10 +321\,10 @​@​ {   local $^W=0;   eval \<\<EOF; -sub confess { CGI​::Carp​::die Carp​::longmess \@​_; } -sub croak { CGI​::Carp​::die Carp​::shortmess \@​_; } -sub carp { CGI​::Carp​::warn Carp​::shortmess \@​_; } -sub cluck { CGI​::Carp​::warn Carp​::longmess \@​_; } +sub confess { CGI​::Carp​::die Carp​::yodel \@​_; } +sub croak { CGI​::Carp​::die Carp​::yelp \@​_; } +sub carp { CGI​::Carp​::warn Carp​::yodel \@​_; } +sub cluck { CGI​::Carp​::warn Carp​::yelp \@​_; } EOF   ; } --- lib/ExtUtils/MakeMaker.pm 2001/06/26 05​:35​:21 1.1 +++ lib/ExtUtils/MakeMaker.pm 2001/06/26 05​:36​:20 @​@​ -2\,7 +2\,7 @​@​

package ExtUtils​::MakeMaker;

-$VERSION = "5.45"; +$VERSION = "5.46"; $Version_OK = "5.17"; # Makefiles older than $Version_OK will die   # (Will be checked from MakeMaker version 4.13 onwards) ($Revision = substr(q$Revision​: 1.1 $\, 10)) =~ s/\s+$//; @​@​ -381\,7 +381\,7 @​@​   }

  # This is for old Makefiles written pre 5.00\, will go away - if ( Carp​::longmess("") =~ /runsubdirpl/s ){ + if ( Carp​::yodel("") =~ /runsubdirpl/s ){   Carp​::carp("WARNING​: Please rerun 'perl Makefile.PL' to regenerate your Makefiles\n");   }

--- lib/Carp.pm 2001/06/25 17​:56​:19 1.1 +++ lib/Carp.pm 2001/06/26 05​:25​:56 @​@​ -21\,8 +21\,10 @​@​   use Carp qw(cluck);   cluck "This is how we got here!";

- print FH Carp​::shortmess("This will have caller's details added"); - print FH Carp​::longmess("This will have stack backtrace added"); + use Carp qw(yodel yelp); + my $warning = yelp "Its like carp\, but doesn't warn"; + my $trace = yodel "Like cluck\, but returns the stack trace"; +

=head1 DESCRIPTION

@​@​ -33\,8 +35\,8 @​@​ will report the error as occurring where Foo() was called\, not where carp() was called.

-The routine shortmess() can be used to generate the string that -carp/croak would have produced. The routine longmess() can be +The routine yelp() can be used to generate the string that +carp/croak would have produced. The routine yodel() can be used to generate the backtrace that cluck/confess would have produced.

@​@​ -83\,7 +85\,7 @​@​ require Exporter; @​ISA = ('Exporter'); @​EXPORT = qw(confess croak carp); -@​EXPORT_OK = qw(cluck verbose longmess shortmess); +@​EXPORT_OK = qw(cluck verbose yodel yelp); @​EXPORT_FAIL = qw(verbose); # hook to enable verbose mode

@​@​ -121\,6 +123\,12 @​@​   { local $@​; require Carp​::Heavy; } # XXX fix require to not clear $@​?   goto &shortmess_heavy; } + +# long and shortmess must stay around because some things use them. +# Eventually\, yodel/yelp should replace longmess/shortmess and they +# will become the aliases instead of vice-versa. +*yodel = \&longmess; +*yelp = \&shortmess;

# the following four functions call longmess() or shortmess() depending on --- lib/Carp.t 2001/06/26 05​:08​:28 1.1 +++ lib/Carp.t 2001/06/26 05​:33​:24 @​@​ -1\,53 +1\,83 @​@​ BEGIN { - chdir 't' if -d 't'; - @​INC = '../lib'; + chdir 't' if -d 't'; + @​INC = '../lib'; }

-use Carp qw(carp cluck croak confess); +use Test​::More tests => 13;

-print "1..7\n"; +require_ok("Carp");

-print "ok 1\n"; +{ + # Test that Carp exports the right things by default. + package Testing​::Carp;

-$SIG{__WARN__} = sub { - print "ok $1\n" - if $_[0] =~ m!ok (\d+)$! }; + :​:ok( !grep(defined &{$_}\, qw(&carp croak confess cluck yodel yelp))\, + 'namespace is clean' );

-carp "ok 2\n"; -
-$SIG{__WARN__} = sub { - print "ok $1\n" - if $_[0] =~ m!(\d+) at .+\b(?i​:carp\.t) line \d+$! }; + Carp->import;

-carp 3; + :​:ok( !grep(!defined &{$_}\, qw(carp croak confess))\, + 'exported the expected defaults' );

-sub sub_4 { + Carp->import(qw(cluck yodel yelp)); + + :​:ok( !grep(!defined &{$_}\, qw(cluck yodel yelp))\, + 'exported the extras' ); +} + + +use Carp qw(​:DEFAULT cluck yodel yelp); + +my($warning) = ''; +local $SIG{__WARN__} = sub { $warning = $_[0] }; + +carp("ok 2\n"); +is($warning\, "ok 2\n"\, 'carp with newline'); +

-$SIG{__WARN__} = sub { - print "ok $1\n" - if $_[0] =~ m!^(\d+) at .+\b(?i​:carp\.t) line \d+\n\tmain​::sub_4\(\) called at .+\b(?i​:carp\.t) line \d+$! }; +carp(3); +like($warning\, qr!3 at .+\b(?i​:carp\.t) line \d+$!\, 'simple carp');

-cluck 4;

+sub sub_4 { + cluck(4); } +sub_4();

-sub_4; +like($warning\, qr!^(\d+) at .+\b(?i​:carp\.t) line \d+\n\tmain​::sub_4\(\) called at .+\b(?i​:carp\.t) line \d+$!\, 'cluck inside subroutine');

-$SIG{__DIE__} = sub { - print "ok $1\n" - if $_[0] =~ m!^(\d+) at .+\b(?i​:carp\.t) line \d+\n\teval \Q{...}\E called at .+\b(?i​:carp\.t) line \d+$! };

-eval { croak 5 }; +eval { croak(5) }; +like($@​\, qr!^(\d+) at .+\b(?i​:carp\.t) line \d+\n\teval \Q{...}\E called at .+\b(?i​:carp\.t) line \d+$!\, 'simple croak');

-sub sub_6 { - $SIG{__DIE__} = sub { - print "ok $1\n" - if $_[0] =~ m!^(\d+) at .+\b(?i​:carp\.t) line \d+\n\teval \Q{...}\E called at .+\b(?i​:carp\.t) line \d+\n\tmain​::sub_6\(\) called at .+\b(?i​:carp\.t) line \d+$! };

- eval { confess 6 }; + +sub sub_6 { + eval { confess(6) }; }

sub_6;

-print "ok 7\n"; +like($@​\, qr!^(\d+) at .+\b(?i​:carp\.t) line \d+\n\teval \Q{...}\E called at .+\b(?i​:carp\.t) line \d+\n\tmain​::sub_6\(\) called at .+\b(?i​:carp\.t) line \d+$!\, 'confess inside subroutine' ); + + +my $yodel; +sub sub_7 { + eval { + # These must be on the same line for the message to come out + # the same. + $yodel = yodel("foo"); cluck("foo"); confess("foo"); + }; +} +sub_7(); +is($warning\, $@​\, 'cluck/confess output the same thing'); +is($warning\, $yodel\, ' so does yodel'); +

+my $yelp; +eval { + # These must also be on the same line. + $yelp = yelp("bar"); carp("bar"); croak("bar"); +}; +is($warning\, $@​\, 'carp/croak output the same thing'); +is($warning\, $yelp\, ' so does yelp'); --- lib/perl5db.pl 2001/06/26 05​:36​:41 1.1 +++ lib/perl5db.pl 2001/06/26 05​:37​:44 @​@​ -2643\,10 +2643\,10 @​@​   local $doret = -2;   $SIG{'ABRT'} = 'DEFAULT';   kill 'ABRT'\, $$ if $panic++; - if (defined &Carp​::longmess) { + if (defined &Carp​::yodel) {   local $SIG{__WARN__} = '';   local $Carp​::CarpLevel = 2; # mydie + confess - &warn(Carp​::longmess("Signal @​_")); + &warn(Carp​::yodel("Signal @​_"));   }   else {   print $DB​::OUT "Got signal @​_\n"; @​@​ -2662\,10 +2662\,10 @​@​   eval { require Carp } if defined $^S; # If error/warning during compilation\,   # require may be broken.   CORE​::warn(@​_\, "\nCannot print stack trace\, load with -MCarp option to see stack")\, - return unless defined &Carp​::longmess; + return unless defined &Carp​::yodel;   my ($mysingle\,$mytrace) = ($single\,$trace);   $single = 0; $trace = 0; - my $mess = Carp​::longmess(@​_); + my $mess = Carp​::yodel(@​_);   ($single\,$trace) = ($mysingle\,$mytrace);   &warn($mess); } @​@​ -2688\,13 +2688\,13 @​@​   # require may be broken.

  die(@​_\, "\nCannot print stack trace\, load with -MCarp option to see stack") - unless defined &Carp​::longmess; + unless defined &Carp​::yodel;

  # We do not want to debug this chunk (automatic disabling works   # inside DB​::DB\, but not in Carp).   my ($mysingle\,$mytrace) = ($single\,$trace);   $single = 0; $trace = 0; - my $mess = Carp​::longmess(@​_); + my $mess = Carp​::yodel(@​_);   ($single\,$trace) = ($mysingle\,$mytrace);   die $mess; }

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

I liked it too\, but yodel is equally commonly spelt in one of two ways\, which ain't so cool. A whole lot more fun than shortmess/longmess though!

p5pRT commented 23 years ago

From @andk

  > On Mon\, Jun 25\, 2001 at 11​:09​:12PM -0500\, Jarkko Hietaniemi wrote​:

Can we think of a better name than longmess/shortmess? backtrace/???

Note that whatever we do\, the old names must stay before other modules already use those names.

Or perhaps something more in line with the whole carp/croak/cluck feel.

yodle/yelp? :-)

  > I like it! (Well\, yodel) Patch follows plus a rewrite of Carp.t plus I   > removed all the uses of longmess and shortmess I could find.

Your style of naming things is just plain sick​:

AnyLoader does anything but interface to any loader. Ima​::DBI has something to do with DBI\, but nothing with Ima. D​::oh is the only really funny one. But it's from 1999 and getting old. Sex​: I still don't know if it is fun or what. Bone​::Easy? Same here. Semi​::Semicolon? Same here.

And now yodle!

What's the problem you're trying to solve? Is perl not hard and confusing enough?

p5pRT commented 23 years ago

From @vanstyn

I'm not convinced about this - the other functions are verbs related to speaking because they write to stderr. shortmess and longmess don't do this.

Hugo

p5pRT commented 23 years ago

From @jhi

Even though I came up with the y/y pair I tend to agree. Different use\, different names.

Hugo

p5pRT commented 23 years ago

From @schwern

Thank you. :)

Ima​::DBI has something to do with DBI\, but nothing with Ima.

I'm a DBI. GET IT?! Nobody does *grumble*

D​::oh is the only really funny one. But it's from 1999 and getting old.

That's D'oh\, and I blame Pudge.

Sex​: I still don't know if it is fun or what.

They have a pill for that now\, ya know. ;)

Bone​::Easy? Same here.

You know what they say about a fisherman with hot brains.

And now yodle!

I hereby transfer all blame to Jarko Hietaniemi under the Blame Transfer Protocol\, RFC pending.

You forgot uny2k\, loose and UNIVERSAL​::exports. :)

What's the problem you're trying to solve? Is perl not hard and confusing enough?

Oh\, you thought this was about solving problems?! No no no\, its about bad puns and wordplay. :)

--

Michael G. Schwern \schwern@&#8203;pobox\.com http​://www.pobox.com/~schwern/ Perl6 Quality Assurance \perl\-qa@&#8203;perl\.org Kwalitee Is Job One Instant Cross-Platform CGI Programming in Visual Perl 5 with Object Oriented Design in 7 Days Unleashed for Dummies Special Edition with Exclusive Java Chapters for Developers. Year 2000 compliant\, Enterprise edition and ISO9000- certified. A Nutshell Handbook Designed For Windows 95/98/NT with a forward by Larry "Bud" Melman. Interactive Multimedia CDROM included. 3rd revised editon\, covers Perl5.6. Of course\, it will be refered to by its simple acronym​: ICPCGIPiVP5wOODi7DU4DSEwEJC4DY2KCEedISO9000-cNHD4W9598NTLBMIMCDROM3edP5.6

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

[snip various defenses and (possibly inappropriate\, due to lack of proxy) BTP use]

You didn't address Andreas' complaint about Semi​::Semicolons\, so I'll do that for you.

Schwern can blame me for that\, and I\, in turn can blame Ziggy. And possibly the Egyptians or Mesopatamians or someone for inventing beer. Randal was also a bystander - innocent or not\, I'll leave up to the jury...

:-)

dha

p5pRT commented 23 years ago

From @schwern

Okay\, then what's a good term for raising objections in a written forum?

p5pRT commented 23 years ago

From @schwern

I'm the source\, Jarrko is the target\, Andreas (and p5p) the proxy. That's the trouble with relying on these draft protocols.

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

Flame? :-)

  -Rich

p5pRT commented 23 years ago

From [Unknown Contact. See original ticket]

I still think more protocols should be bashed out over drinks\, though...

dha

p5pRT commented 23 years ago

From @schwern

Drinks? Draft protocol? Get it? HA!

Corollary to Godwin's Law​: "As a p5p thread grows longer\, the probability of a bad pun approaches one. Once this occurs\, that thread is over\, and whoever inflicted the pun is beaten to within an inch of his life."