From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id bG0fFnP5v2QJui4AWB0awg (envelope-from ) for ; Tue, 25 Jul 2023 12:33:55 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Yrte8YEg; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 4D50A1E0C0; Tue, 25 Jul 2023 12:33:55 -0400 (EDT) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 327651E00F for ; Tue, 25 Jul 2023 12:33:53 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 22DC9385AF97 for ; Tue, 25 Jul 2023 16:33:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 22DC9385AF97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690302832; bh=7VTxI1vGL4AtWfHQH17eSqpfntPGEYJ3SnCs3AEz57g=; h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Yrte8YEgTYs5AwsIJyWzBQ5Nj8uz9IEAxjktTGRHN9qDI5TLZec1bTXG+kRTyMUfw IFor45UIhv3rHxACzqIEwYJssbDliTCMvKsa6dKMl1jFNpvp5nauS2PXafC36HsWzV 79D/ZF9SZed1E9v0D+8eA5tQ9/sgVA34euLFlwjU= 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 Date: Tue, 25 Jul 2023 16:32:49 +0000 To: gdb@sourceware.org, meator 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 X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Jan Vrany via Gdb Reply-To: Jan Vrany Errors-To: gdb-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb" 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