From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 281E33858403 for ; Wed, 30 Mar 2022 08:58:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 281E33858403 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-587-O6hq5CuzMTSKqRBcNOaPQg-1; Wed, 30 Mar 2022 04:58:11 -0400 X-MC-Unique: O6hq5CuzMTSKqRBcNOaPQg-1 Received: by mail-wm1-f69.google.com with SMTP id i6-20020a1c5406000000b0038c97ed0db5so7621902wmb.7 for ; Wed, 30 Mar 2022 01:58:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=bXGLZ6ASwgNAE1Alt6P0MMa1G3CE4cl2CyBjZrFFDPw=; b=rQ/eIXniaX0U8SL74gmGUUW7YjitgT+40HqYf/iD2jxE0TVmNzydGmPugzUxcDSAiG i86JC0mpdHrQfPMG5DTXYWGxkTS4fMgb4cf+YzdIo4lVNKANlWHDRxCIHh0TEB/tD9Kd +FCkPQaUnspBXWZT7xEiba6Esol8oy97scRJ717SWMErPE89id/Z+whRIpfFXsLXiDSj 42gsXG+ZHYYHeck4I8kSbf91r341HTDiG3AE6doUNFGG9Twx7ud8rlizBm661gVkWBQ+ QtA/MSdL4ryPeVoBGsABQiuMD5ai2gMYdVKEt9/RwBBO0CJNFlF28eV3ykcgbo1pijXa wK2w== X-Gm-Message-State: AOAM531bTi+T2FPi90KHkvS88GK54H2lb7mF2udGHbTLfolNbXk6lU8f Xin92qYhBno5sVE29EaDy0W9OHlruCLBmH+oEEXT2BXb/lfP9rxvITNf95k918+Flu+XPJtg7RN oNYwZpvHiSnr8voPdrpy6hXvo5aa6pc2tlw/h7k74iclsVF8P//kj2I5VDhi5I7yYBH+cgh5oYg == X-Received: by 2002:a05:600c:a06:b0:37b:fdd8:4f8 with SMTP id z6-20020a05600c0a0600b0037bfdd804f8mr3536322wmp.41.1648630690136; Wed, 30 Mar 2022 01:58:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK4+qzeiaNvNfpu7EozBdHGCv/NAAODD2CWFP62nfdvTq0hK+w+IZK9mq039SwdTFM4iqzpA== X-Received: by 2002:a05:600c:a06:b0:37b:fdd8:4f8 with SMTP id z6-20020a05600c0a0600b0037bfdd804f8mr3536305wmp.41.1648630689787; Wed, 30 Mar 2022 01:58:09 -0700 (PDT) Received: from localhost (host86-169-131-113.range86-169.btcentralplus.com. [86.169.131.113]) by smtp.gmail.com with ESMTPSA id e9-20020a5d6d09000000b00203ecdca5b7sm18127306wrq.33.2022.03.30.01.58.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Mar 2022 01:58:09 -0700 (PDT) From: Andrew Burgess To: Simon Farre via Gdb-patches , gdb-patches@sourceware.org Subject: Re: [PATCH 1/2] gdb/python: add gdb.Breakpoint.source_locations property In-Reply-To: <20220329212717.1184271-1-simon.farre.cx@gmail.com> References: <20220329212717.1184271-1-simon.farre.cx@gmail.com> Date: Wed, 30 Mar 2022 09:58:08 +0100 Message-ID: <87h77fakbj.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-12.4 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_LOW, 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Mar 2022 08:58:15 -0000 Simon Farre via Gdb-patches writes: > This attribute returns the source locations where > this breakpoint was installed. It's returned as a list > of tuples of type (file path: string, line: long). > > Currently it's not possible from the Python API to know > where a breakpoint has been installed. > > The rationale for this patch is for IDE or debug adapters > as they are called, for instance for VSCode, to be able > to fetch Breakpoint related data directly from Python, > but also makes it possible to get this data for plugins > without having the parse the string output of the command > `info breakpoints`. See my comments on patch 2/2. I think the same applies for this patch too. Thanks, Andrew > --- > gdb/NEWS | 5 +++++ > gdb/doc/python.texi | 8 ++++++++ > gdb/python/py-breakpoint.c | 31 +++++++++++++++++++++++++++++++ > 3 files changed, 44 insertions(+) > > diff --git a/gdb/NEWS b/gdb/NEWS > index e10062752d0..9e7e41d3bd6 100644 > --- a/gdb/NEWS > +++ b/gdb/NEWS > @@ -16,6 +16,11 @@ > This is the same format that GDB uses when printing address, symbol, > and offset information from the disassembler. > > + ** Added attribute Breakpoint.source_locations > + This returns a list of (file path, line number) tuples where the > + Breakpoint was installed. This is the information displayed > + by the 'info breakpoints' command. > + > *** Changes in GDB 12 > > * DBX mode is deprecated, and will be removed in GDB 13 > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index 7c414b01d70..0d842af6229 100644 > --- a/gdb/doc/python.texi > +++ b/gdb/doc/python.texi > @@ -6066,6 +6066,14 @@ commands, separated by newlines. If there are no commands, this > attribute is @code{None}. This attribute is writable. > @end defvar > > +@defvar Breakpoint.source_locations > +This attribute holds the source locations where the breakpoint installed. > +It returns a list of tuples containing the file path and the line number. > +If the breakpoint has no source location(s), either because it's a pending > +breakpoint or is of a type that doesn't have a source location related to it > +it returns @code{None}. This attribute is not writable. > +@end defvar > + > @node Finish Breakpoints in Python > @subsubsection Finish Breakpoints > > diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c > index 5891c3a9735..1b9ac6957a5 100644 > --- a/gdb/python/py-breakpoint.c > +++ b/gdb/python/py-breakpoint.c > @@ -692,6 +692,35 @@ bppy_get_ignore_count (PyObject *self, void *closure) > return gdb_py_object_from_longest (self_bp->bp->ignore_count).release (); > } > > +/* Python function to get all source locations where this breakpoint is set. > + returns a list of tuples containing the file path and the line number. */ > + > +static PyObject* bppy_get_source_locations(PyObject *self, void* closure) > +{ > + gdbpy_breakpoint_object *self_bp = (gdbpy_breakpoint_object *) self; > + struct breakpoint* bp = self_bp->bp; > + > + BPPY_REQUIRE_VALID (self_bp); > + > + if (!is_breakpoint (bp) || pending_breakpoint_p(bp)) > + Py_RETURN_NONE; > + > + gdbpy_ref<> list (PyList_New (0)); > + > + for (const bp_location* it = bp->loc; it != nullptr; it = it->next) > + { > + PyObject* tuple = PyTuple_New(2); > + if(PyTuple_SetItem(tuple, 0, host_string_to_python_string (it->symtab->filename).release ()) != 0) > + return nullptr; > + if(PyTuple_SetItem(tuple, 1, PyLong_FromLong(it->line_number)) != 0) > + return nullptr; > + if(PyList_Append(list.get(), tuple) != 0) > + return nullptr; > + } > + > + return list.release(); > +} > + > /* Internal function to validate the Python parameters/keywords > provided to bppy_init. */ > > @@ -1264,6 +1293,8 @@ or None if no condition set."}, > "Whether this breakpoint is a temporary breakpoint."}, > { "pending", bppy_get_pending, NULL, > "Whether this breakpoint is a pending breakpoint."}, > + { "source_locations", bppy_get_source_locations, NULL, > + "Source file locations where this breakpoint is installed"}, > { NULL } /* Sentinel. */ > }; > > > base-commit: b8e92c571baed4e794bd62b7bf417fa8bbaf5c95 > -- > 2.32.0