Breakpoint on a builtin?

G

Guest

Is there a way in the perl debugger to set a breakpoint on a builtin
function?

I currently have a script that is deleting a file, and I want to know why
it has decided to delete the file. I'd like to set a breakpoint on the
'unlink' function, so I can catch the caller, and do the whole debugging
thing. However, when I try this, I get:

DB<1> b unlink
Subroutine main::unlink not found.

Do the builtin functions reside in a special namespace that will allow me
to, e.g., 'b special::unlink', or some such? Or is there some other,
special notation that I can use?

Thanks,
Keith
 
G

Guest

: Do the builtin functions reside in a special namespace that will allow me
: to, e.g., 'b special::unlink', or some such? Or is there some other,
: special notation that I can use?

iirc Perl doesn't have unlink and related functions itself but uses
system calls for those; in this case it is understandable that there
is no stepping into this part of code.

I suggest you run your script under strace, like

$ strace -o strace.dump myperl-script-with-bizarre-unlink-in-it.pl

and analyze the log in strace.dump which is definitely informative.

Oliver.
 
A

Anno Siegel

Keith NoSpam Arner said:
Is there a way in the perl debugger to set a breakpoint on a builtin
function?

I currently have a script that is deleting a file, and I want to know why
it has decided to delete the file. I'd like to set a breakpoint on the
'unlink' function, so I can catch the caller, and do the whole debugging
thing. However, when I try this, I get:

DB<1> b unlink
Subroutine main::unlink not found.

Do the builtin functions reside in a special namespace that will allow me
to, e.g., 'b special::unlink', or some such? Or is there some other,
special notation that I can use?

You could override (documented in perlsub) the unlink function and set
a breakpoint on that. This should do (untested, I'm stalwartly
ignoring the debugger):

# double braces indicate an un-indented block
{{
package CORE::GLOBAL;
use subs 'unlink';
sub unlink { CORE::unlink( @_) }
}}

unlink 'xyz';

Anno
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
Anno Siegel
# double braces indicate an un-indented block
{{
package CORE::GLOBAL;
use subs 'unlink';
sub unlink { CORE::unlink( @_) }
}}

Not enough. One needs to special-case the 0-arguments case. [See
Fatal for how to auto-implement this.]

Hope this helps,
Ilya
 
A

Anno Siegel

Ilya Zakharevich said:
[A complimentary Cc of this posting was sent to
Anno Siegel
# double braces indicate an un-indented block
{{
package CORE::GLOBAL;
use subs 'unlink';
sub unlink { CORE::unlink( @_) }
}}

Not enough. One needs to special-case the 0-arguments case. [See
Fatal for how to auto-implement this.]

Oh, CORE::unlink() doesn't unlink $_. Whoda thunk. Well,

sub unlink { CORE::unlink( @_ ? @_ : $_) }

then. Or am I still missing something?

Anno
 
G

Guest

You could override (documented in perlsub) the unlink function and set
a breakpoint on that. This should do (untested, I'm stalwartly
ignoring the debugger):

Hhmm... no dice. I can correctly override the builtin (that is, it will
execute the function that I override with), but when I set a breakpoint on
my function, the debugger does not hit it:


[0]karner@bayberry 8:48am:485 > perl -d

Loading DB routines from perl5db.pl version 1.0402
Emacs support available.

Enter h or `h h' for help.

package CORE::GLOBAL;
use subs 'unlink';
sub unlink { print "not unlinking $_[0]\n"};

package main;
print "hello\n";
unlink "foo";

main::(-:5): print "hello\n";
DB<1> b CORE::GLOBAL::unlink
DB<2> c
hello
not unlinking foo
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<2>
 
B

Brian McCauley

Ilya said:
[A complimentary Cc of this posting was sent to
Anno Siegel
# double braces indicate an un-indented block
{{
package CORE::GLOBAL;
use subs 'unlink';
sub unlink { CORE::unlink( @_) }
}}


Not enough. One needs to special-case the 0-arguments case. [See
Fatal for how to auto-implement this.]

I've had a look at Fatal version 1.03 in Perl 5.8.5 and I can't see how
Fatal destinguishes no arguments ( e.g. unlink() ) from an empty list (
unlink( my @empty_list = ()))

What an I missing?
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
Brian McCauley
Not enough. One needs to special-case the 0-arguments case. [See
Fatal for how to auto-implement this.]
I've had a look at Fatal version 1.03 in Perl 5.8.5 and I can't see how
Fatal destinguishes no arguments ( e.g. unlink() ) from an empty list (
unlink( my @empty_list = ()))
What an I missing?

That I did not realize there is a difference. THE VERDICT: functions
which take a list, AND default to $_ are not overridable (via
importing, or via CORE::GLOBAL)... Do not see how to get this info
via caller() either...

Bad luck for Perl programmers, they may need to switch to a different
language;
Ilya
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
Keith Arner nospam
Hhmm... no dice. I can correctly override the builtin (that is, it will
execute the function that I override with), but when I set a breakpoint on
my function, the debugger does not hit it:

I can't set a breakpoint in CORE::GLOBAL::* here. But setting it in
foo works with this:

perl -dwle 'sub foo {warn qq((@_))} BEGIN {*CORE::GLOBAL::unlink = \&foo} $_= "bar"; unlink or die'

Hope this helps,
Ilya
 

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

No members online now.

Forum statistics

Threads
473,797
Messages
2,569,647
Members
45,380
Latest member
LatonyaEde

Latest Threads

Top