• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 523
  • Last Modified:

How to debug into sub functions in Perl?

Hi,
I have subfunction in my code and Perl debugger cannot go into it.

Here is what I do:

perl -d myFile
b linenumber
c
s

Open in new window



It stops at linenumber and when I say step into it it skips. n also does not work.

Here is the beginning of my sub function:

SOME CODE

my (%c, %d);
sub logFunc {
    my ($a, $b) = @_;
    my $S;
    my $file;

SOME OTHER CODE

} #myFunc

SOME MORE CODE

Open in new window



How can I debug this code?
0
Tolgar
Asked:
Tolgar
1 Solution
 
point_pleasantCommented:
n runs until the next statement (the one immediately following this one in the current file) is about to execute. Note that if the current line is a subroutine call, the debugger won't stop until returning from that subroutine. To stop at the first line of the called subroutine, use the s (single-step) command instead. The r command executes until returning from the current subroutine (i.e., until we pop the activation stack).

0
 
TolgarAuthor Commented:
Well, I already use s but it still does not go into the subroutine. Why is that?

Thanks,
0
 
clockwatcherCommented:
This may be a stupid question but are you expecting what you posted to actually step into that function?  

SOME CODE

my (%c, %d);
sub logFunc {
    my ($a, $b) = @_;
    my $S;
    my $file;

SOME OTHER CODE

} #myFunc

Open in new window


If you are, that's your problem right there.  The code that you posted never calls your function so the debugger won't ever actually be in there to step into it.  If you actually call your function, then you'll step into that section of the code.

SOME CODE

my (%c, %d);
sub logFunc {
    my ($a, $b) = @_;
    my $S;
    my $file;

SOME OTHER CODE

} #myFunc

# call your function
my $val = logFunc( 5, 5);

Open in new window

0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now