Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

The perl debugger and an embedded interpreter

by aufflick (Deacon)
on Jun 06, 2012 at 11:39 UTC ( #974699=perlquestion: print w/replies, xml ) Need Help??

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

So you have a perl interpreter embedded in your C program (actually it's a Mac Cocoa program, but that's probably not relevant).

You want to debug the perl modules running inside your app because it seems to behave differently (and incorrectly) to on the "outside", so you pass -d as an argument to perl_parse.

When I try that I get the perl debugger intro text printing out, but the code never actually stops and I never get a debugger prompt. I tried locally and with the RemotePort option to connect via tcp with the same result - debugger welcome text every time, but it never stops to listen.

Any ideas?

Update: Dear future me: the solution was as simple as adding a perl_run(). It's not strictly required normally since I run code via call_perl() etc. but since the perl debugger is simple code in that gets executed at require time, it was never actually getting executed.

Replies are listed 'Best First'.
Re: The perl debugger and an embedded interpreter (Mac Cocoa)
by Anonymous Monk on Jun 06, 2012 at 11:50 UTC
      It's inherited code, so I don't know it inside out yet but grep tells me that caller() is used in some logging modules.

      Not sure what the problem would be, but I commented out all instances of caller() but no change to my symptoms - what are you thinking might be happening?

      I'm using the Apple supplied perl/libperl 5.10.1 in Lion (which is not the default perl - that's 5.12).

Re: The perl debugger and an embedded interpreter
by xiaoyafeng (Deacon) on Jun 06, 2012 at 15:42 UTC

    I pass -d to a embedding interpreter, and it works fine (on windows).

    So maybe posting your code would help.

    And please note in debug mode, perl will load some XS modules background, so you should comply a xs_init file with your code.

    I am trying to improve my English skills, if you see a mistake please feel free to reply or /msg me a correction

      Pasting the code in helped me realise the problem - no perl_run()! It's not strictly required normally since I run code via call_perl() etc. but since the perl debugger is simple code in that gets executed at require time, it was never actually getting executed.

      The welcome message threw me off - I guess that must get printed in a BEGIN {} block.

      Yes I have an xs_init (that I know works, because I can load XS modules). Here is my relevant embedding code:

      static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ int argc = 1; char * argv[] = { "myPerlInterp", "-w" }; PERL_SYS_INIT3(&argc, (char ***)&argv, (char ***)NULL); }); ... [(NSMutableDictionary *)envDict setObject:@"TTY=/dev/ttys001 L +ineInfo=/dev/ttys003 ReadLine=1" forKey:@"PERLDB_OPTS"]; my_perl_env = calloc(sizeof(char *), [envDict count] + 1); int i=0; for (NSString * var in [envDict allKeys]) { //TODO: unsure if this is going to propogate any non-ascii + paths correctly NSString * entry = [NSString stringWithFormat:@"%@=%@", va +r, [envDict objectForKey:var]]; const char * val = [entry UTF8String]; char * val_copy = calloc(sizeof(char), strlen(val) + 1); strncpy(val_copy, val, strlen(val)); my_perl_env[i++] = val_copy; } my_perl_queue = dispatch_queue_create([label cStringUsingEncod +ing:NSASCIIStringEncoding], DISPATCH_QUEUE_SERIAL); dispatch_sync(my_perl_queue, ^{ //char * embedding[] = { "", "-w", "-e", "0" }; char * embedding[] = { "", "-w", "-d", "-e", "0" }; int embedding_count = sizeof(embedding) / sizeof(char *); my_perl = perl_alloc(); PL_perl_destruct_level = 1; perl_construct(my_perl); perl_parse(my_perl, xs_init, embedding_count, embedding, m +y_perl_env); // not sure why the perl_parse env isn't used to setup @IN +C - even giving it to PERL_SYS_INIT3 doesn't work eval_pv("use Env qw(@PERL5LIB); push @INC, @PERL5LIB;", TR +UE); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; }); }
      If you're not familiar with blocks and grand central dispatch, just imagine the code in the ^{ ... } bits are running on a background thread. The envDict is an NSDictionary containing how I want the environment to be setup.

      As I said this generally works, and in the above incantation, /dev/ttys01 gets this output:

      Marks-MacBook-Air:~ aufflick$ sleep 1000000 Loading DB routines from version 1.32 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help.
      And then the code continues to run with no interactive prompt (just typing stuff leaves it in the buffer - stdin never seems to be read). The same happens just running at the console without the PERL5DB_OPTS or using the RemotePort/nc method.

      I'm trying to figure out how to set a breakpoint in advance to see if that manages to enter the debugger. perldebguts talks about %{"::_<current_file"} but I can't seem to figure it out.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://974699]
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2023-10-04 19:31 GMT
Find Nodes?
    Voting Booth?

    No recent polls found