Debugging a Perl(SNMP-NPAdmin) module - Not able to understand fewLOC

K

karthikd

Hello All,

I have some basic knowledge of Perl and I am troubleshooting a Perl
code(it is perl-SNMP-NPAdmin perl module)to debug a particular
problem.

I am not able to understand some part of the code (which is using some
hashes etc.).

The following snippet of code is used in NPAdmin.pm file:

sub model
{
#warn "model";
my $self= shift;

for ( $self->vendor()->{vendor} )
{
.....snipped code....

/^HP$/ && do {
my $str= $self->{Neon}->hp_gdStatusId()->{gdStatusId};
print "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: $str \n";
$self->{model}= ( $str =~ /;(?:MODEL|MDL):\s*(.+?)\s*;/ )[0];
last;
};

.....snipped code ...

}

return { model => $self->{model} };
}

I added the print statement to know what value is stored in $str.
While running the module, we found that $str value is empty.

My query is what the line below:

my $str= $self->{Neon}->hp_gdStatusId()->{gdStatusId};

does really and how to troubleshoot/debug it in a failure case.

hp_gdStatusId seems to be a key in a hash called %list_map defined in
another perl module called in Neon.pm

%list_map= (
# sub name oid list
# -------- --------
hp_npCfgSource => [ 0x0,
[ q:

[ '.iso.org.dod.internet.private.enterprises.hp.nm.interface.npCard.npCfg.npCfgSource',
0],
: ],
],
hp_gdStatusId => [ 0x0,
[ q:

[ '.iso.org.dod.internet.private.enterprises.hp.nm.system.net-
peripheral.net-printer.generalDeviceStatus.gdStatusId', 0]
: ],
],
);
and list_map is used like this in a subroutine called AUTOLOAD defined
in Neon.pm

sub AUTOLOAD
{
<code snipped >
elsif ( defined $list_map{$autoload} )
{
my @map= @{$list_map{$autoload}};
$sub= $list_code;
%tags= (
'##SUBNAME##' => $autoload,
'##MIBS##' => $map[0],
'##OIDLIST##' => @{$map[1]},
);
}
<code snipped>
}

Any help would be really appreciated.

Thanks & Regards,

Karthik
 
S

smallpond

Hello All,

I have some basic knowledge of Perl and I am troubleshooting a Perl
code(it is perl-SNMP-NPAdmin perl module)to debug a particular
problem.

I am not able to understand some part of the code (which is using some
hashes etc.).

The following snippet of code is used in NPAdmin.pm file:

sub model
{
#warn "model";
  my $self= shift;

  for ( $self->vendor()->{vendor} )
  {
      .....snipped code....

    /^HP$/ && do {
        my $str= $self->{Neon}->hp_gdStatusId()->{gdStatusId};
        print "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: $str \n";
        $self->{model}= ( $str =~ /;(?:MODEL|MDL):\s*(.+?)\s*;/ )[0];
        last;
        };

      .....snipped code ...

   }

     return { model => $self->{model} };

}

I added the print statement to know what value is stored in $str.
While running the module,  we found that $str value is empty.

My query is what the line below:

     my $str= $self->{Neon}->hp_gdStatusId()->{gdStatusId};

does really and how to troubleshoot/debug it in a failure case.

hp_gdStatusId seems to be a key in a hash called %list_map defined in
another perl module called in Neon.pm

hp_gdStatusId is a method call. Note the '()'
 
K

karthikd

karthikd said:
    /^HP$/ && do {
        my $str= $self->{Neon}->hp_gdStatusId()->{gdStatusId};
        print "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX: $str \n";
I added the print statement to know what value is stored in $str.
While running the module,  we found that $str value is empty.

Did you have warnings enabled?

It would help to know if it really contains the empty string
versus containing undef.
My query is what the line below:
     my $str= $self->{Neon}->hp_gdStatusId()->{gdStatusId};
does really and how to troubleshoot/debug it in a failure case.

If it is really the empty string, then it would seem that
the error was in storing the value rather than retrieving it.

It it is really undef, then you can "walk" the chain to figure out
where it was broken:

    warn "self\n" unless defined $self;
    warn "Neon\n" unless defined $self->{Neon};
    warn "hp_gdStatusId\n" unless defined $self->{Neon}->hp_gdStatusId();
    warn "gdStatusId\n" unless defined $str;




hp_gdStatusId seems to be a key in a hash called %list_map defined in
another perl module called in Neon.pm
     %list_map= (
#       sub name                  oid list
#       --------                        --------
        hp_npCfgSource          =>      [ 0x0,
                                       [ q:
[ '.iso.org.dod.internet.private.enterprises.hp.nm.interface.npCard.npCfg.npC­fgSource',
0],
                                       : ],
                                       ],
        hp_gdStatusId           =>      [ 0x0,
                                       [ q:
[ '.iso.org.dod.internet.private.enterprises.hp.nm.system.net-
peripheral.net-printer.generalDeviceStatus.gdStatusId', 0]
                                       : ],
                                       ],
        );

use Data::Dumper to see what complex data structures look like:

   use Data::Dumper;
   warn Dumper \%list_map;

--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"- Hide quoted text -

- Show quoted text -

Hi Tad,

Thanks for your help. I added the warning statements as mentioned and
found that

warn "gdStatusId\n" unless defined $str;

returned "gdStatusId" proving that $str was undefined. It looks like
{gdStatusId} seems to be undefined. On Dumping the object $self->
{Neon} we found that, it lists a complex structure and the correct
value we were looking for had the key value as "0", instead of
gdStatusId.

So, for time being we had changed the code to something like this:

my $str= $self->{Neon}->hp_gdStatusId()->{0};

I am not sure this is a correct way. My one more doubt is, I couldn't
find gdStatusId as key anywhere in the code(I checked all the .pm
files).

Is it that hash keys can be generated dynamically in Perl ??

Well, IMHO troubleshooting a Perl code is way complex than debugging C
programs.

Once again thanks for all your insights. My learning is enhanced.

Thanks & Regards,

Karthik
 

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,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top