perl - How to locate the source file of a subroutine call when debugging a complex CPAN distribution? -


i trying debug tk program while now. problem seems deiconify() call top level window, not able locate source file deiconify() sub defined. here made-up example illustrate mean:

test.pl:

use strict; use warnings; use tk;  $mw = mainwindow->new( -title => "main window" ); $mw->label(-text => "debugging", -font => "times 20")->pack( ); $mw->button(     -text    => 'quit',     -command => sub { exit }, )->pack; $mw->button(     -text    => 'show window',     -command => \&show_window, )->pack;  $tl = $mw->toplevel( -title => "toplevel 1" ); $tl->button(     -text    => 'quit',     -command => sub { exit }, )->pack; $tl->withdraw(); mainloop;  sub show_window {     #$db::single = 1;     $tl->deiconify();  # <--- sub defined??     $tl->raise(); } 

i first tried grep distribution sub name1:

  • find . -name '*.pm' -exec grep -hn deiconify {} \;
  • find . -name '*.xs' -exec grep -hn deiconify {} \;
  • find . -name '*.al' -exec grep -hn deiconify {} \;
  • find . -name '*.h' -exec grep -hn deiconify {} \;

then tried run script under debugger

perl -d test.pl 

and set breakpoint before call $tl->deiconify() (see above). when pressed s @ breakpoint

  db<1> s tk::submethods::code(0x56245540c658)(/home/hakon/perlbrew/perls/perl-5.24.1/lib/site_perl/5.24.1/x86_64-linux/tk/submethods.pm:37): 37:      *{$package.'::'.$sub} = sub { shift->$fn($sub,@_) }; 

it shows line deiconify() defined anonymous subroutine ( line 37 of tk::submethods ), when press s again step anonymous subroutine, step on , returns line 32 in test.pl.

i suspect method must defined in tk::wm somehow (since related window manager) maybe auto load mechanism or dynaloader?

footnotes

1. commands run toplevel directory of tk distribution. set up, run first:

 cpan -g tk  tar zxvf tk-804.033.tar.gz  cd tk-804.033 

grepping source little more liberally (specifically including *.c files) finds string this procedure invoked process "wm deiconify" tcl command in file ptk/mtk/win/tkwinwm.c. it's in comment introducing c function wmdeiconifycmd, looks it's actual implementation of functionality.

i haven't bothered how tk module xs code exposes c function perl level, if that's you're interested in, know endpoints , have fill in middle :-)

once function exposed perl level, line in tk::submethods quote above gets injected appropriate symbol table can called via $tl->deiconify().


Comments