Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

[Solved] Best method of call tracing, without writing code?

by Hercynium (Hermit)
on Oct 05, 2007 at 16:36 UTC ( [id://642956]=perlquestion: print w/replies, xml ) Need Help??

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

I thought this was too simplistic a question for SoPW, but the CB was pretty well engaged in an interesting discussion that I decided trying to interrupt further would be rude :)

I have an existing code-base, and I want to begin writing a test suite for one of the modules. I've decided that the best way to start would be to determine exactly what data is being passed into each subroutine and what is getting returned.

So, for example, I want to be able to specify that all method and subroutine calls in module Foo::Bar get logged, complete with a dump of the passed arguments and the returned data. This has to be done without modifying any existing code. (Adding a single 'use' at the top of the main script is acceptable, though)

I found Debug::Trace which looks like it will do the job, and the author looks like someone who knows his stuff (He also wrote the venerable Getopt::Long!) but I wonder if there is a better, more fitting solution to which the wisdom of the Monks can illuminate.

Update: Down the rabbit hole we go... I've now tried Debug::Trace, Devel::TraceCalls, and Devel::TraceMethods, and none worked... BUT I have an idea why.

The module that *uses* the module whose methods I want to trace is loaded dynamically, at run-time through a mechanism I created with an eval. In other words, the methods that call the methods I want to analyze are in a module that isn't used until run-time, and therefore the module containing the methods I want to analyze is not loaded until run-time. Ick...

It's a bit complicated to describe - the code is on CPAN as TL1ng. (please don't take this as a plug for my module... it's still young and fragile.)


Update 2: Eureka! Since I am testing, I already know which module will be loaded at run-time... so I can pre-load it and now Debug::Trace works!
perl -MTL1ng::Base -MDebug::Trace=TL1ng::Parser::parse_string,:indent\ +(2\),:nomaxdepth,:nouseqq test_simple_auto.pl

Of course, it would still be nice to get some more feedback on other better/best/interesting debugging techniques of similar ilk!

Ikegami - Even though I figured it out before you posted, Thank you!

Replies are listed 'Best First'.
Re: Best method of call tracing, without writing code?
by ikegami (Patriarch) on Oct 05, 2007 at 18:10 UTC

    The module that *uses* the module whose methods I want to trace is loaded dynamically, at run-time through a mechanism I created with an eval.

    So load it earlier when debugging.

    perl -MTL1ng::Parser -MDebug::Trace=TL1ng::Parser::parse_string test_s +imple_auto.pl
Re: Best method of call tracing, without writing code?
by dragonchild (Archbishop) on Oct 05, 2007 at 16:57 UTC
    What are you looking for that Debug::Trace doesn't do for you?

    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
      Really, I'm just looking for the current best practice.

      As a update, I've just tried Debug::Trace as it is documented and I'm getting no output...
      perl -MDebug::Trace=TL1ng::Parser::parse_string test_simple_auto.pl
      TL1ng::Parser::parse_string() is called as a method on a TL1ng::Parser object from inside various methods in TL1ng::Base.

      I can't figure out what I'm missing :(
Re: [Solved] Best method of call tracing, without writing code?
by DrHyde (Prior) on Oct 08, 2007 at 08:40 UTC
    It's for this task that I wrote Sub::WrapPackages, although right now you'll still have to write a bit of code to make it do exactly what you want. The Log::FunctionCalls module that was going to depend on it has been on my to-do list for, umm, far too long. Sorry.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found