Solved

How to debug into sub functions in Perl?

Posted on 2011-03-24
3
478 Views
Last Modified: 2012-05-11
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
Comment
Question by:Tolgar
3 Comments
 
LVL 8

Expert Comment

by:point_pleasant
ID: 35210385
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
 

Author Comment

by:Tolgar
ID: 35210568
Well, I already use s but it still does not go into the subroutine. Why is that?

Thanks,
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 35211636
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now