Pass argument to perl file in debugger and set breakpoint in file executed by system

假装没事ソ 提交于 2019-12-07 06:15:45

问题


So I run a file in the perl debugger using perl -d file.pl. But then the file.pl is supposed to take arguments also. How do I supply arguments to the file.pl One more question: file.pl has this line in it:

system("./file2.pl");

Is there a way to set a breakpoint in file2.pl if it is running as system? I have spent 7 days on perl debugger and I am not able to set a breakpoint at file2.pl Please help

EDIT: Got an awesome response from DVK to add DB::single=1. I tested that on some files and it worked. But I have more than a 100 files and if I do this manually, it will take me a lot of time. I use .perldb and use afterinit to typeahead all commands. I have put in place an algorithm which finds the line number of each file where the breakpoint needs to go. I just can't randomly (automatically using an executable) open all those files and add DB::single=1 to where I like. The whole system can crash then. I want to set breakpoint as it more secure


回答1:


Yes, you can.

Add the following code to the line where you want to break in file2.pl:

$DB::single = 1;

To control the debugging automatically from that point, you need to manipulate @DB::typeahead array. From perldoc:

You can mock TTY input to debugger by adding arbitrary commands to @DB::typeahead. For example, your .perldb file might contain:

   sub afterinit { push @DB::typeahead, "b 4", "b 6"; }

This code can be either in a BEGIN {} block, or a special .perldb config file.




回答2:


You pass them as you would normally:

perl -d ./file2.pl arg1 arg2 arg3 ...


来源:https://stackoverflow.com/questions/17888986/pass-argument-to-perl-file-in-debugger-and-set-breakpoint-in-file-executed-by-sy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!