Limiting the amount of information printed by the Perl debugger

One of my favorite scammers with Perl debugging code (on the debbugger command line, perl -d) is the fact that erroneous printing (via the command x) ensures that the contents of the huge data structure will delay your terminal forever and half, while 100 page pages print . Especially if this happens through a slow network.

Thus, I would like to be able to limit the amount of data that xprints.

I see two approaches - I would like to try if someone knows how to do this.

  • Limit the amount of data to any single command in the debugger prints.

  • Even better, somehow replace the built-in command xwith a custom Perl method (which will calculate the "size" of the data structure and refuse to print its contents without confirmation).

I specifically ask: “How to replace xwith custom code” - creating “Good enough” is too big a data structure. "The Perl method is something that I can do on my own without much effort, although I see enough traps that prevent the" ideal "due to the fact that this is pretty unpleasant work. Heck, just doing Data :: Dumper-> Dump and taking line length can do the trick :)

Please note that I know very well how to manually avoid the problem by recursively examining the layers of the data structure (for example, print ref, print the number of keys / elements of an array, etc.) ... all I want to be able to avoid thoughtlessly entering text x $huge_pile_of_datawithout thinking - or stumbling over an error filling a huge pile of data into what should be a scalar.

+5
source share
2 answers

A command |in the debugger passes another command to your pager, for example

  DB <1> | x% huge_datastructure
+8
source

x . , N , .

  DB<1> %h = (a => { b => { c => 1 } } )

  DB<2> x %h
0  'a'
1  HASH(0x1d5ff44)
   'b' => HASH(0x1d61424)
      'c' => 1

  DB<3> x 2 %h
0  'a'
1  HASH(0x1d5ff44)
   'b' => HASH(0x1d61424)

o,

DB<1>o dumpDepth=1

.perldb , .

x DB::dumpit(), dumpval.pl (, , main::dumpValue() sub, ). / script . , .

+11

All Articles