From patchwork Wed Jan 10 15:54:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 83763 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DC97C385842F for ; Wed, 10 Jan 2024 15:57:13 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id D3103385DC01 for ; Wed, 10 Jan 2024 15:55:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D3103385DC01 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D3103385DC01 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704902111; cv=none; b=FqVXIzdXPPXm8NgLRzvwmR9srVOTWU2vnd8qhqwC3qaI3Fh2xCV56ibNOb9qibrVB57pcInDGrrd9qhqMkjVS0D1DW3yakPwrETJJBW+hZ14wY3jiZrAWI28JoJ4GyUECUlTRzOFaQKSKJs7kGCEzn0etxmH1FkKB48JlSWE5oI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704902111; c=relaxed/simple; bh=pRNYo7K/gKQMk5sNZfzmysUyTZaZTkJdphA5A7zhNz4=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=KcUv95aYwlziKm59/6Y+Ly56IkP9yVn1V3syhwg6VYNQjvp9hk4nyJIsSGkRPIFTD64c2IePAZq/fXtd0x873fIIJ/t7rXBqne47c1I9CWMiHl1I/uOWyy7qpjsET3TePVI8TP5CTdHB0zVnp5hdqNszl82cZlqPTHHD8sBV08s= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704902107; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P6xHVkkzcRE7FDvy1s+fIkbme0s+3K0QO62ijO09mHk=; b=i0/BJX68jw5fvqFAFznGzCP2x4q/fWkWgDIaIRUz3yXFbmHjJud6N4zQsjlrO7w6byVRlZ Jyxd/X6aSh1zJaY9//zTSuWcj5WO0gNw/1R++VhwCya/pYfliTFFVRtIbtPi0hwveennCS 7QOVwNikKqOxe8GESDtWFC9k7VxhR+g= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-581-xW2t0AHIM5u8hJR_STtyOw-1; Wed, 10 Jan 2024 10:55:05 -0500 X-MC-Unique: xW2t0AHIM5u8hJR_STtyOw-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-40e41740b6eso36925785e9.3 for ; Wed, 10 Jan 2024 07:55:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704902103; x=1705506903; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P6xHVkkzcRE7FDvy1s+fIkbme0s+3K0QO62ijO09mHk=; b=GycI0TTqwCgrwZiPiV5ecz2AFAOiNCFiT8TyaW45CPj5fR2orjrep/AdaeQamOpfMF hNAawI7hI7ErSooK/HQ2bktwQ2CbXLMHPPrKSCZ4oQbSGSeLBJVyFJLK07mo1Yr86xZM pjOJEXh7oUpRyrzEIJwhUZWmnSkWzybqoc3JYDGPidV8olXLKvaAgeNfob6NeXIqlSFC SUbR07+oqnwCetCfFKb84NhS53o3PpkMR5DMrpBX2LZN+xWaCzORX4poYYVa1mM12GXb EvK1KcRjBWvFbivciOxh1ECSBGh7OCRWihYqP+ZKvuHbCErFbTpkT8zHvg1FzxfWJZww vgJA== X-Gm-Message-State: AOJu0Yz7CkVSTRSy9+iUYZn0BK2keCd7or2tIg8TpL1SktqXDRWhzDXA 4O9fd2KUEMW59uXV54VPHeHPXNs4UoRh3pKRN0DiiXQBSNQnzfj6o0fPufZpWNom3m3TUDKaHki JDWvUQRk88TqFinRBuXBN2WKMX22YeXl2usi6L8o03vQ2g1JsIUyhHi7HW2JoQYAA/+CNh35sKg UQ3PqIes7Uv79Gsw== X-Received: by 2002:a7b:ca45:0:b0:40e:370e:1d89 with SMTP id m5-20020a7bca45000000b0040e370e1d89mr713323wml.36.1704902102962; Wed, 10 Jan 2024 07:55:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IG5Oe2njUgljg3pG8qNTdPb/RoLl0/+P1FyHVN+uK2+TGGjF/PQOijS6XYdDZatqw3dfUvvLg== X-Received: by 2002:a7b:ca45:0:b0:40e:370e:1d89 with SMTP id m5-20020a7bca45000000b0040e370e1d89mr713319wml.36.1704902102692; Wed, 10 Jan 2024 07:55:02 -0800 (PST) Received: from localhost (185.223.159.143.dyn.plus.net. [143.159.223.185]) by smtp.gmail.com with ESMTPSA id ek10-20020a05600c3eca00b0040d81ca11casm2546383wmb.28.2024.01.10.07.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 07:55:01 -0800 (PST) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCHv2 8/8] gdb/doc: update examples in gdb.Progspace and gdb.Objfile docs Date: Wed, 10 Jan 2024 15:54:45 +0000 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org This commit updates the Python example code in the gdb.Progspace and gdb.Objfile sections of the docs. Changes made: 1. Use @value{GDBP} for the GDB prompt rather than hard-coding (gdB), 2. Use @group...@end group to split the example code into unbreakable chunks, and 3. Add parenthesis to the Python print() calls in the examples. In Python 2 it was OK to drop the parenthesis, but now GDB is Python 3 only, example code should include the parenthesis. --- gdb/doc/python.texi | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi index 40803274a27..0b240c76dce 100644 --- a/gdb/doc/python.texi +++ b/gdb/doc/python.texi @@ -5416,13 +5416,16 @@ will be loaded. @smallexample -(gdb) python +(@value{GDBP}) python +@group def clear_objfiles_handler(event): event.progspace.expensive_computation = None def expensive(symbol): """A mock routine to perform an "expensive" computation on symbol.""" print ("Computing the answer to the ultimate question ...") return 42 +@end group +@group def new_objfile_handler(event): objfile = event.new_objfile progspace = objfile.progspace @@ -5437,15 +5440,18 @@ gdb.events.clear_objfiles.connect(clear_objfiles_handler) gdb.events.new_objfile.connect(new_objfile_handler) end -(gdb) file /tmp/hello +@end group +@group +(@value{GDBP}) file /tmp/hello Reading symbols from /tmp/hello... Computing the answer to the ultimate question ... -(gdb) python print gdb.current_progspace().expensive_computation +(@value{GDBP}) python print(gdb.current_progspace().expensive_computation) 42 -(gdb) run +(@value{GDBP}) run Starting program: /tmp/hello Hello. [Inferior 1 (process 4242) exited normally] +@end group @end smallexample @node Objfiles In Python @@ -5576,17 +5582,21 @@ loaded the objfile. @smallexample -(gdb) python +@group +(@value{GDBP}) python import datetime def new_objfile_handler(event): # Set the time_loaded attribute of the new objfile. event.new_objfile.time_loaded = datetime.datetime.today() gdb.events.new_objfile.connect(new_objfile_handler) end -(gdb) file ./hello +@end group +@group +(@value{GDBP}) file ./hello Reading symbols from ./hello... -(gdb) python print gdb.objfiles()[0].time_loaded +(@value{GDBP}) python print(gdb.objfiles()[0].time_loaded) 2014-10-09 11:41:36.770345 +@end group @end smallexample A @code{gdb.Objfile} object has the following methods: