I tried several ways, none work:
b file开发者_StackOverflow中文版:line
f file
b line
b load <file>
what's wrong here?
I don't fully understand your question but all of the options for 'b' in the perl debugger can be viewed with 'h b':
DB<3> h b
b Sets breakpoint on current line)
b [line] [condition]
Set breakpoint; line defaults to the current execution line;
condition breaks if it evaluates to true, defaults to '1'.
b subname [condition]
Set breakpoint at first line of subroutine.
b $var Set breakpoint at first line of subroutine referenced by $var.
b load filename Set breakpoint on 'require'ing the given file.
b postpone subname [condition]
Set breakpoint at first line of subroutine after
it is compiled.
b compile subname
Stop after the subroutine is compiled.
There doesn't appear to be a 'one usage for all cases' pattern. In my experience you can:
- step through the debugger a few statements until the module(s) you are interested in are loaded
- 'use' the module you want to set the break point in
Once your module of interest is loaded you can use the 'b [subname]' pattern. Don't forget that you might need to fully qualify the sub name with the package name:
DB<5> use JSON;
DB<6> b JSON::import
DB<7> JSON->import
JSON::import(/opt/xt/xt-perl/lib/site_perl/5.12.4/JSON.pm:78):
78: my $pkg = shift;
auto(-1) DB<<8>> v
75
76
77 sub import {
78==>b my $pkg = shift;
79: my @what_to_export;
80: my $no_export;
81
82: for my $tag (@_) {
83: if ($tag eq '-support_by_pp') {
84: if (!$_ALLOW_UNSUPPORTED++) {
You could also
- add "$DB::single=1;" in your source code (don't forget to remove it when your done though!)
and just 'c' to continue through the debugger until you hot that line in your code. Having to add and remove special markers in your source goes against the general principle of debugging but is sometimes a useful way of stopping easily at somewhere difficult, or slow, to reach stepping through the debugger.
I suppose, you have started a perl script in the debugger, which uses some modules with some packages.
You can use the debugger command
S
to list the available subroutines. An optional regex pattern can be used to filter the list:S [[!]pat] List subroutine names [not] matching pattern
To set a break point for a function in some package, you can use this form of the breakpoint commands
b package::function
. It could have been documented better, I guess.
I had the same problem some time ago, and i use it like this now.
Update: I just checked the sequence
f file
b line
This works for me when the module has been loaded before with use package
or require package
. The path for file
is specified relative to the current directory.
精彩评论