develooper Front page | perl.perl5.porters | Postings from July 2005

[perl #6947] Perl5.6 debugger does not follow # source line references from cpp

From:
Michael G Schwern via RT
Date:
July 14, 2005 19:52
Subject:
[perl #6947] Perl5.6 debugger does not follow # source line references from cpp
Message ID:
rt-3.0.11-6947-117412.19.4003352738772@perl.org
> [rwk@americom.com - Sat May 05 21:48:58 2001]:
> 
> . I run my perl scripts through cpp (for various reasons).  I can't
>    use
> the -P option because I use libraries and such which all need to be
>    run
> through cpp.
> 
> . The output from cpp contains # lines of the form (for example):
> 
> # 1 "/src/5.5longdistance/public_html/page.pc"
> # 1 "/src/5.5longdistance/include/ld.h" 1
> # 1 "/src/nbn/include/display.h" 1
> # 1 "/src/nbn/include/class.h" 1
> BEGIN {push(@INC, '/src/nbn/widgets', '/src/nbn/comm',
>    '/virtuals/americom/lib')}
> use Object;
> # 3 "/src/nbn/include/display.h" 2
> # 1 "/src/5.5longdistance/include/ld.h" 2
> # 1 "/src/5.5longdistance/public_html/page.pc" 2
> use Display;
> unlink '/tmp/Errors';
> #send errors to /tmp/Errors if not running in the debugger
> $inDebugger = $INC{'/home/rwk/.perldb'};
> if (!$inDebugger) {
>     open(STDERR, '> /tmp/Errors');
>     open(STDOUT, '| /usr/bin/tee --append /tmp/html') if -e
>    '/tmp/DumpHtml';
> } else {
>     open(STDERR, ">&STDOUT");
> }
> FORM::Execute();
> END {
>     if (!$inDebugger && ! -z '/tmp/Errors') {
> 	#in case they occured before heading was printed
> 	print "Content-type: text/html\n\n";
> 	print "<PRE>\n";
> 	my(@errors) = `cat /tmp/Errors`;
> 	print @errors;
>     }
> }
> 
> . When running the above in the perl debugger under perl5.004_04, it
> correctly visits the source file and line specified by the # source
> lines in the file.  This make debugging easy, particularly within
> emacs.
> 
> . Under perl5.6, it fails to do this and simply visits the file with
>    the
> # source lines, rather than the file they refer to.
> 
> Can anyone tell me if there is a fix or work-arround for this problem?

You are correct in that Perl prior to 5.6 honored these comments and
that 5.6 and after do not.

$ cat ~/tmp/foo
#!/usr/bin/perl -w                                                     
     
                                                                     
# 1 "/usr/include/ndbm.h"                         
warn "Foo"; 
 
0 ~/tmp$ perl5.4.5 ~/tmp/test
Foo at /usr/include/ndbm.h line 1.
0 ~/tmp$ perl5.5.4 ~/tmp/test
Foo at /usr/include/ndbm.h line 1.
0 ~/tmp$ perl5.6.2 ~/tmp/test
Foo at /Users/schwern/tmp/test line 4.
0 ~/tmp$ perl5.8.6 ~/tmp/test
Foo at /Users/schwern/tmp/test line 4.

However it was never documented that it would do so.  It appears to have
been a quirk in the processing of "#line" directives, which are
documented at the end of perlsyn, that "line" was optional.  I think it
was this change which clarified the behavior to avoid picking up
random comments as line directives.
http://public.activestate.com/cgi-bin/perlbrowse?patch=5108

-    if (strnEQ(s, "line ", 5)) {
-	s += 5;
-	sawline = 1;
-    }
+    if (strnEQ(s, "line", 4))
+	s += 4;
+    else
+	return;

Before it would continue processing a comment as a possible #line
directive even if it did not see "line".  After it would stop if it did
not see "line".

The work around is to use the documented "#line 4 filename" comments as
documented in perlsyn.  Sorry if cpp does not output these.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About