Re: Reloading pretty-printers

Jean-Marc Saffroy <[email protected]>
Newsgroups gmane.comp.gdb.devel
Message-ID <CAM5YWZfSQSVUR7JSPq=jfW5mXupVvn805jc7dNS7cJR4v4wt1Q@mail.gmail.com>
Hi,

On Sun, May 19, 2019 at 3:00 PM 🐝 <[email protected]> wrote:

> Hello,
>
> I'm writing some pretty-printers for a codebase, and when I modify the
> python files with gdb running, I can't seem to use the new version.
> giving `source $GDBINIT` or `source $PRETTYPRINTERDOTPY` gives
> `pretty-printer already registered`
>
> Is there a solution to this other than restarting gdb?
>

When I faced the same problem, I found it useful to simply generate a
random name when registering the pretty printer:

def _build_pretty_printer():
> # hack: random name allows reloading in the same gdb session!
> pp = gdb.printing.RegexpCollectionPrettyPrinter(
> "xxx.%d"%(random.randint(0, 1000000)))
> pp.add_printer('BIGNUM', '^bignum_st$', BNPrinter)
> return pp
>
> gdb.printing.register_pretty_printer(
> gdb.current_objfile(),
> _build_pretty_printer())
>
>
Cheers,
JM


-- 
Jean-Marc Saffroy - [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.