Breakpoint on a builtin?

Discussion in 'Perl Misc' started by Keith NoSpam Arner, Aug 4, 2004.

  1. 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

    --
    In questions of science, the authority of a thousand is not worth the
    humble reasoning of a single individual.
    -Galileo Galilei
     
    Keith NoSpam Arner, Aug 4, 2004
    #1
    1. Advertising

  2. Keith NoSpam Arner

    Guest Guest

    Keith NoSpam Arner <> wrote:

    : 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.

    --
    Dr. Oliver Corff e-mail: -berlin.de
     
    Guest, Aug 5, 2004
    #2
    1. Advertising

  3. Keith NoSpam Arner

    Anno Siegel Guest

    Keith NoSpam Arner <> wrote in comp.lang.perl.misc:
    >
    > 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
     
    Anno Siegel, Aug 5, 2004
    #3
  4. [A complimentary Cc of this posting was sent to
    Anno Siegel
    <-berlin.de>], who wrote in article <cespo4$5un$-Berlin.DE>:
    > Keith NoSpam Arner <> wrote in comp.lang.perl.misc:
    > # 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
     
    Ilya Zakharevich, Aug 5, 2004
    #4
  5. Keith NoSpam Arner

    Anno Siegel Guest

    Ilya Zakharevich <> wrote in comp.lang.perl.misc:
    > [A complimentary Cc of this posting was sent to
    > Anno Siegel
    > <-berlin.de>], who wrote in article
    > <cespo4$5un$-Berlin.DE>:
    > > Keith NoSpam Arner <> wrote in

    > comp.lang.perl.misc:
    > > # 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
     
    Anno Siegel, Aug 5, 2004
    #5
  6. On 5 Aug 2004, Anno Siegel wrote:

    > Keith NoSpam Arner <> wrote in comp.lang.perl.misc:
    > >
    > > Is there a way in the perl debugger to set a breakpoint on a builtin
    > > function?

    >
    > 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>


    --
    In questions of science, the authority of a thousand is not worth the
    humble reasoning of a single individual.
    -Galileo Galilei
     
    Keith Arner nospam, Aug 6, 2004
    #6
  7. Ilya Zakharevich wrote:

    > [A complimentary Cc of this posting was sent to
    > Anno Siegel
    > <-berlin.de>], who wrote in article <cespo4$5un$-Berlin.DE>:
    >
    >>Keith NoSpam Arner <> wrote in comp.lang.perl.misc:
    >> # 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?
     
    Brian McCauley, Aug 6, 2004
    #7
  8. [A complimentary Cc of this posting was sent to
    Brian McCauley
    <>], who wrote in article <cf0cfc$b0$>:
    > > 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
     
    Ilya Zakharevich, Aug 6, 2004
    #8
  9. [A complimentary Cc of this posting was sent to
    Keith Arner nospam
    <>], who wrote in article <Pine.GSO.4.42.0408060850270.15519-100000@zimbra>:
    > > 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:


    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
     
    Ilya Zakharevich, Aug 6, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    7
    Views:
    2,107
    Mike Treseler
    Jun 29, 2005
  2. Vik

    Breakpoint will not be hit

    Vik, Jul 25, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    517
    William F. Robertson, Jr.
    Jul 25, 2003
  3. Tim Cali

    Breakpoint is ignored

    Tim Cali, Sep 28, 2003, in forum: ASP .Net
    Replies:
    9
    Views:
    2,401
    Tim Cali
    Sep 29, 2003
  4. Mark
    Replies:
    4
    Views:
    385
    Rick Spiewak
    Apr 26, 2004
  5. bdb112
    Replies:
    2
    Views:
    316
    Chris Torek
    Jul 2, 2011
Loading...

Share This Page