Q re guts: where to put breakpoints?

K

kj

This is a question for those familiar with the Perl internals.

I'd like to debug some Perl code that invokes functions written in
C. I have versions of Perl and the relevant modules that have been
compiled with the appropriate debugging flags, so that, in principle
I could run perl under a C debugger (in my case gdb). The only
obstacle is that I have no idea of where to set breakpoints. More
specifically, I need a strategy for setting a conditional breakpoint
in Perl's internals roughly corresponding to setting a perldb
breakpoint at a particular line in a Perl script.

E.g. suppose I have a Perl script foo.pl whose lines 100 through
102 are

100 my $x = 1;
101 my $y = function_implemented_in_C($x, $y);
102 my $z = $x + $y;

If I were running this script under perldb, I could set a breakpoint
at line 101 (b 101), but I would not be able to step into the
function call at that line, because this function is not written
in Perl; hitting s at this point would put me on line 102, just as
if I had hit n. So I have to run this under gdb instead, and I
need a way to tell gdb to stop at the same stage in the running of
the C program as the one arrived at upon hitting the breakpoint at
line 101 when running foo.pl under perldb.

Any pointers on how I can do this this would be much appreciated.

Thanks!

kj
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
kj
obstacle is that I have no idea of where to set breakpoints. More
specifically, I need a strategy for setting a conditional breakpoint
in Perl's internals roughly corresponding to setting a perldb
breakpoint at a particular line in a Perl script.

In such situations I go the way of least resistance: I use some OPCODE
which is not used anywhere else in the program, and has no
side-effects; just modify the line in question to call the opcode, as in:

kill 0, $$;

then set the breakpoint at Perl_pp_kill().
If I were running this script under perldb, I could set a breakpoint
at line 101 (b 101), but I would not be able to step into the
function call at that line, because this function is not written
in Perl; hitting s at this point would put me on line 102, just as
if I had hit n. So I have to run this under gdb instead, and I
need a way to tell gdb to stop at the same stage in the running of
the C program as the one arrived at upon hitting the breakpoint at
line 101 when running foo.pl under perldb.

Run perldb under gdb; when stopped at line 101 in perldb, switch to
gdb, and enable the C breakpoint where you want it.

Another strategy is to set gdb breakpoint on 1127th time you hit a C
statement (by `ignore' command; you can find the count using the
`info breakpoints' command (sp?) from deeper in the stack). [This is
applicable, if you want to stop at the caller (or a caller of a
caller...) of your C function; right?].

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,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top