public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Jan Vrany <jan@vrany.io>
To: gdb@sourceware.org, meator <meator.dev@gmail.com>
Subject: Re: How can I reload a pretty printer?
Date: Tue, 25 Jul 2023 16:32:49 +0000	[thread overview]
Message-ID: <b516b5b432adecd04970718f9f6c0b182c073b39.camel@vrany.io> (raw)
In-Reply-To: <9fc91cc3-adbe-d2f8-8b27-4245071d6c72@gmail.com>

On Tue, 2023-07-25 at 18:13 +0200, meator via Gdb wrote:
> Hi. When writing a pretty printer, I want to repeatedly test it. This is
> pretty complicated because GDB has no builtin mechanisms to do such
> thing (that I know of) and breakpoint() pretty much can not be used
> because GDB's Python doesn't have access to the capable pty so
> interactive use of PDB is impossible. Even the classic "printf style"
> debugging doesn't work because Python's print() doesn't work
> (gdb.write() has to be used instead).
> 
> I need to test the pretty printer often because the official Python
> interface documentation is quite lacking and the interface itself is
> imperfect^1. Accessing the docstrings of the Python interface is
> difficult because the gdb module nor other modules can be imported in
> standalone Python (I've tried to add it to $PYTHONPATH but with no
> success; How are you supposed to access the docstrings?).
> 
> Therefore my last solution is to load the pretty printer, try it in gdb,
> modify the pretty printer and repeat. But a pretty printer can be
> sourced only once because the second source call will fail due to the
> fact that the pretty printer is already registered. I have to restart
> GDB every time I modify the pretty printer which is extremely
> impractical. Is there a way to live reload the pretty printer?

It is, though it requires a bit of custom Python hackery. You may find
the code I'm using - to my satisfaction - here: 

https://swing.fit.cvut.cz/hg/jv-vdb/file/tip/python/vdb/cli.py#l19

Each time I modify the code in editor, I either run "pr" command
from GDB CLI or "pr()" from Python's REPL and it reload everything,
live. It has some limitations comping from limits of Python itself
and of my knowledge of Python, but for me works well enough. 

You may also be interested in "autodebug" hook: 

https://swing.fit.cvut.cz/hg/jv-vdb/file/tip/python/vdb/__init__.py#l117

HTH, Jan

> 
> 1: There is no sane way to call member functions through gdb.Value which
> is kind of important in C++: https://stackoverflow.com/q/22774067/13840624



  reply	other threads:[~2023-07-25 16:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25 16:13 meator
2023-07-25 16:32 ` Jan Vrany [this message]
2023-07-25 16:37 meator

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b516b5b432adecd04970718f9f6c0b182c073b39.camel@vrany.io \
    --to=jan@vrany.io \
    --cc=gdb@sourceware.org \
    --cc=meator.dev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).