Debugging gdb pretty printers

I started experimenting with gdb lowercase printers for some of my C ++ data structures, but the documentation is pretty thin.

As a result, I need to guess how to do this, and often my pretty printers just crash with the irreplaceable python exception without indicating where the real problem is.

Is there a good way to debug a pretty printer? I have had success in other python programs by inserting an explicit pydb call into the code:

import pydb
pydb.debugger()

but this does not work when starting python in gdb - it just passes the call debuggerand does not stop, does not say or does nothing.

+4
source share
1

pdb ( python) gdb. gdb :

(gdb) print (ObjectSignature *) 0x7f71e4018000
$1 = (ObjectSignature *) 0x7f71e4018000
(gdb) python import pdb
(gdb) python pdb.run('gdb.execute("print $1[0]")')
> <string>(1)<module>()
(Pdb) from svtprinters.printers import ObjectSignaturePrinter
(Pdb) b ObjectSignaturePrinter.to_string
Breakpoint 1 at /svtfs/svtprinters/printers.py:195
(Pdb) c
$2 = > /svtfs/svtprinters/printers.py(196)to_string()
-> sizetypestr = 'invalid'
(Pdb) n
> /svtfs/svtprinters/printers.py(197)to_string()
-> sizetypeidx = int(self.val['mSizeType'])
(Pdb) self.val['mSizeType']
<gdb.Value object at 0x7effc90ff430>
(Pdb) int(self.val['mSizeType'])
3
(Pdb) n
> /svtfs/svtprinters/printers.py(199)to_string()
-> if sizetypeidx < len(self.sizetypes):
(Pdb) self.sizetypes
['unknown', 'meta_1K', 'data_4K', 'data_8K', 'data_16K', 'data_32K', 'data_64K']
(Pdb) n
> /svtfs/svtprinters/printers.py(200)to_string()
-> sizetypestr = self.sizetypes[sizetypeidx]
(Pdb) 
> /svtfs/svtprinters/printers.py(202)to_string()
-> return (20*"%02x"+" %s") % tuple([self.val['mValue'][i] for i in range(20)]+[sizetypestr])
(Pdb) sizetypestr
'data_8K'
(Pdb) c
98d6687a2ea63a134901f0df140b13112e64bfb7 data_8K
(gdb) 

ObjectSignaturePrinter - , gdb.pretty_printers ObjectSignature $1. print ; $2 = , pdb continue.

, python.

+1

Source: https://habr.com/ru/post/1616815/


All Articles