From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-4022.proton.ch (mail-4022.proton.ch [185.70.40.22]) by sourceware.org (Postfix) with ESMTPS id 16D763858280 for ; Tue, 25 Jul 2023 16:33:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 16D763858280 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=vrany.io Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrany.io Date: Tue, 25 Jul 2023 16:32:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrany.io; s=protonmail; t=1690302784; x=1690561984; bh=7VTxI1vGL4AtWfHQH17eSqpfntPGEYJ3SnCs3AEz57g=; h=Date:To:From:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=n1/JYHvQuPEs3dwSAIr1+QpSrkWSA2Cep268mV5zOidahqxqG97k0V86MBvlO4/oj F2RfcMiih4yTiyPORbHIqGDToumCyM+GtiD/Gay/ztUzb+CBY5sNpIyeYJHF0HRz5W HdnDQSh2qw4Nz9AU9nFsQ93sPpqe/JWXlzpcSd/6iimw+dCVZWq5b7uMRWvriPPV4V e94uqWyVMgelHfzYpbQobgy6HTjoglaQG0UpqFPJSxK+YICWws7punWXo64GmPMHU7 0Elpb/WUjSZgFgK/DIE+BYuo2W5357kTDUtGLs0TU+LfuRtYQ9oRkDkxBJd1GtCjhA 8fZNSkzXEOS+g== To: gdb@sourceware.org, meator From: Jan Vrany Subject: Re: How can I reload a pretty printer? Message-ID: In-Reply-To: <9fc91cc3-adbe-d2f8-8b27-4245071d6c72@gmail.com> References: <9fc91cc3-adbe-d2f8-8b27-4245071d6c72@gmail.com> Feedback-ID: 40767693:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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). >=20 > 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?). >=20 > 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:=20 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.=20 You may also be interested in "autodebug" hook:=20 https://swing.fit.cvut.cz/hg/jv-vdb/file/tip/python/vdb/__init__.py#l117 HTH, Jan >=20 > 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/1384062= 4