nikolaus has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to debug and/or profile perl code called from C++ using eval_pv and eval_sv. Both the perl debugger and profiler seem to completely ignore whatever I eval. I have no problems profiling/debugging the things I do in perl_run. In brief:
interpreter = perl_alloc( ); perl_construct(interpreter); perl_parse(interpreter, xs_init, argc, argv, NULL); perl_run(interpreter); // Install signal handlers et al. eval_pv(my_code); // doesn't get profiled, can't debug perl_destruct(interpreter); perl_free(interpreter);

Replies are listed 'Best First'.
Re: Profiling Embedded Perl
by BrowserUk (Patriarch) on Jan 07, 2004 at 04:49 UTC

    Whether this is helpful or not you'll have to tell me, but every use of eval_pv() a quick grep turned up, it had 2 parameters not 1.

    eval_pv Tells Perl to eval the given string and return an SV* result. NOTE: the perl_ form of this function is deprecated. SV* eval_pv(const char* p, I32 croak_on_error)

    HTH.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!

      Thanks, but what I wrote was very pseudo code. I'm not having any trouble eval'ing perl code, just profiling it.

      -nik

        Okay. T'was just something that stood out.

        Just another thought, but would it be easier to profile the code your eval'ing, from a standard perl script rather via embedded perl?


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
        Hooray!

Re: Profiling Embedded Perl
by nikolaus (Novice) on Jan 07, 2004 at 17:19 UTC
    I think I figured out how to make it work, but I don't really understand why.

    If I move the code I was running using -e on the command line into an eval_pv, then just eval "1" on the command line, and do all my eval_pv's before calling perl_run, things seem to work.

    E.g.:

    interpreter = perl_alloc( ); perl_construct(interpreter); perl_parse(interpreter, xs_init, argc, argv, NULL); eval_pv(install_sig_handlers, 0); eval_pv(my_code, 0); // profiling, debugging etc. work perl_run(interpreter); perl_destruct(interpreter); perl_free(interpreter);