From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id tRT9CbuysWgsVQ8AWB0awg (envelope-from ) for ; Fri, 29 Aug 2025 10:01:31 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FkYcFpIz; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 084D91E04C; Fri, 29 Aug 2025 10:01:31 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_LOW,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id AA4601E043 for ; Fri, 29 Aug 2025 10:01:21 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5DF6B38438AC for ; Fri, 29 Aug 2025 14:01:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DF6B38438AC Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=FkYcFpIz Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id BAD9B3858C74 for ; Fri, 29 Aug 2025 14:00:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BAD9B3858C74 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine 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 BAD9B3858C74 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756476046; cv=none; b=lwVphggEFHUQUqQUO2iZoQ56mJC6AFsM9ykBg23ZnSl4Hn0dEDDmwvHGAYNGOo9zaFbYPP60efCn4WEwS//pFs0x6PyvInppr2uOEgqii8MktMHALd1/aWumlcHV8tRvTjx3h/qjIjSK45EngZMgPWBxeq3KFCBX0EP795rBgsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756476046; c=relaxed/simple; bh=SC4GWpG2CdyrKGcioFlUZChWxATaZT5Q1ceoKvCCDkw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ET43LZYaXHVPW4fFtk1DCT4xgA/Lz48Q6PatCV3S8gOJ64b6rLjBhvLLAaIsSP1D7Kjkck7OUO3MFq3AVYjalit1ZnAxiJV1yIkOowMMMBhA4Kiibsrqeq0h+lhiLCBHjPiFDkfHUftb02Vij0waGx7bcS4yzP+fYHM6VktZAlU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BAD9B3858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1756476046; 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: in-reply-to:in-reply-to:references:references; bh=eHJ+LdnA/SqCaNGQY14c3M64mwyA//h2aiXAnAEKZX0=; b=FkYcFpIzojjTjuFjNDUxvo1EUNoPCeEPiTXtxwpadQLRD5TQTMS0jzEQqe3lZMM65I3eAa /Nyu4rXoBjw6axHiFszh8LyjzuMexQH7l8op1vVKZ97Ag9VFkOdLXJILx4+Eo+mhUPUZfv /WUQO108qOHaVhYM+e1T8+bGQkLQV5U= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-88-L3flDkFGMnO2S5R96ztPDQ-1; Fri, 29 Aug 2025 10:00:45 -0400 X-MC-Unique: L3flDkFGMnO2S5R96ztPDQ-1 X-Mimecast-MFC-AGG-ID: L3flDkFGMnO2S5R96ztPDQ_1756476043 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3cba0146f7aso1061955f8f.3 for ; Fri, 29 Aug 2025 07:00:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756476042; x=1757080842; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eHJ+LdnA/SqCaNGQY14c3M64mwyA//h2aiXAnAEKZX0=; b=eF8UH1tEyn7u5k31Us5bTsvpXjNIcdxulxL8t99eQwIQwWaMYYnm9FO6dRGT5YldFN DVYsTuzawyJx3ei/zwLx+i4LCpau64FCUuEBnGlaVKvuIcM2e4CN7PJPXmBhG9n6O4iN iuCvIO+dhuqjF4s4h7AlC7TDIDZEneduOQ7/uDRTc4YBqxHG5Ois7rfqVkv6n8miCvoi rCvc5Gld3l/n3qlf93YpDWRmyOV/mT0QSyFrV/FU67q3SxmLZZB3EMxG1dztnAWpB65E fRRUQdHj92JPomOukoTMQfdOhV8+F59v5lsl5Mm2HXp9H7CTR4TFc2klZBWf3tcGR+u9 z8Rg== X-Forwarded-Encrypted: i=1; AJvYcCXYJzUvdA0Ie1qA1rHj/1Q9tCZDdcdXZ94lffy8jCYFSXz6EYMfQrGKoEB9mbxTyJMy9MvBczGtwXSZlQ==@sourceware.org X-Gm-Message-State: AOJu0YxEL+dDK9+GmXHDTucGBtij66fvAkfbArXeB8fYJY59ucGDrS0T GRas5TLlZ4xta45yTbghSyKCTPT6EXpvxx5dPK7lwAYYIJZ5xxbVF6RaXk/9uyPzpgviUnOPOTU 3arJICcivLpi4ocG5YjdVwj+copYziLv/IGGgY+jJH8RJRFRArMp/IDE9NY7MYArt/a4oQxc= X-Gm-Gg: ASbGncv1e28CY/yetfqg/WcdUVEwsNnRE86hPZzBJaCWZ/XWzF1rSs9WGmEEbJePINj SV4Gq3dx2mYmAE10ET+A1IwdrdtMCsgp1JHkS9G4Q27Q6AaIM37fmGdIRFXlJC/MbtBqffrh8p7 bjlBZDHmeMWM/XdO8Fnmwmqo0wuk7qqqV8FhTq9ZI88Q5ZqEsNCO/1jY/anSJhuhwVhCjBsWAdj dUcYvOoYLOPjZ1/OmIdWvuBX2IP1oinpHoCOSBP7/xVZ7Pgkt1kEGar2/m7nQTmnP67dBWwlqG+ WldvFaU8GaWf6Mkgb6G5Khrzj2juhMZxv/o= X-Received: by 2002:a05:6000:2c01:b0:3b3:9c75:acc6 with SMTP id ffacd0b85a97d-3c5de34badbmr21322834f8f.59.1756476042321; Fri, 29 Aug 2025 07:00:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGn4gEJInhH/9JLCKl1fqRmoFazDvwrJqs75aNr/xKQYjtKn1EWNeVNOhBKmUUSXinZ9LBr+g== X-Received: by 2002:a05:6000:2c01:b0:3b3:9c75:acc6 with SMTP id ffacd0b85a97d-3c5de34badbmr21322801f8f.59.1756476041772; Fri, 29 Aug 2025 07:00:41 -0700 (PDT) Received: from localhost ([31.111.84.207]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45b7e9c41cfsm38620795e9.21.2025.08.29.07.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Aug 2025 07:00:40 -0700 (PDT) From: Andrew Burgess To: Jan Vrany , gdb-patches@sourceware.org Cc: Jan Vrany , Eli Zaretskii Subject: Re: [RFC v5 15/18] gdb/python: add more attributes to gdb.LinetableEntry objects In-Reply-To: <20250623161013.650814-16-jan.vrany@labware.com> References: <20250623161013.650814-1-jan.vrany@labware.com> <20250623161013.650814-16-jan.vrany@labware.com> Date: Fri, 29 Aug 2025 15:00:39 +0100 Message-ID: <87h5xqqlbs.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ajDOG4P02pNa8wd_3jrmzzh1GHaWkV7IbT7M4CnBouw_1756476043 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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~public-inbox=simark.ca@sourceware.org Jan Vrany writes: > This commit adds is_stmt, prologue_end and epilogue_begin attributes > to linetable entry objects. > > This prompted change in gdb.Linetable.line() (ltpy_get_pcs_for_line). > In order to fill initialize new attributes we need complete entries > matching the line, not only PCs. > > Reviewed-By: Eli Zaretskii > --- > gdb/doc/python.texi | 17 ++++ > gdb/python/py-linetable.c | 101 +++++++++++++++++++--- > gdb/testsuite/gdb.python/py-linetable.exp | 10 +++ > 3 files changed, 116 insertions(+), 12 deletions(-) > > diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi > index 15f851e5fd0..7c3a87cdaad 100644 > --- a/gdb/doc/python.texi > +++ b/gdb/doc/python.texi > @@ -6822,6 +6822,23 @@ executable code for that source line resides in memory. This > attribute is not writable. > @end defvar > > +@defvar LineTableEntry.is_stmt > +True if pc (associated with this entry) is a good location to place > +a breakpoint for line (associated with this entry). This attribute is not > +writable. > +@end defvar > + > +@defvar LineTableEntry.prologue_end > +True if pc (associated with this entry) is a good location to place > +a breakpoint after a function prologue. This attribute is not > +writable. > +@end defvar > + > +@defvar LineTableEntry.epilogue_begin > +True if pc (associated with this entry) marks the start of the epilogue. > +This attribute is not writable. > +@end defvar > + > As there can be multiple addresses for a single source line, you may > receive multiple @code{LineTableEntry} objects with matching > @code{line} attributes, but with different @code{pc} attributes. The > diff --git a/gdb/python/py-linetable.c b/gdb/python/py-linetable.c > index 90cba09c88e..5eb40bf3c5b 100644 > --- a/gdb/python/py-linetable.c > +++ b/gdb/python/py-linetable.c > @@ -25,6 +25,12 @@ struct linetable_entry_object { > int line; > /* The pc associated with the source line. */ > CORE_ADDR pc; > + /* See is_stmt in stuct linetable_entry. */ > + bool is_stmt : 1; > + /* See prologue_end in stuct linetable_entry. */ > + bool prologue_end : 1; > + /* See epilogue_begin in struct linetable_entry. */ > + bool epilogue_begin : 1; > }; > > extern PyTypeObject linetable_entry_object_type > @@ -98,7 +104,8 @@ symtab_to_linetable_object (PyObject *symtab) > and an address. */ > > static PyObject * > -build_linetable_entry (int line, CORE_ADDR address) > +build_linetable_entry (int line, CORE_ADDR address, bool is_stmt, > + bool prologue_end, bool epilogue_begin) > { > linetable_entry_object *obj; > > @@ -108,6 +115,9 @@ build_linetable_entry (int line, CORE_ADDR address) > { > obj->line = line; > obj->pc = address; > + obj->is_stmt = is_stmt; > + obj->prologue_end = prologue_end; > + obj->epilogue_begin = epilogue_begin; > } > > return (PyObject *) obj; > @@ -120,22 +130,26 @@ build_linetable_entry (int line, CORE_ADDR address) > address. */ > > static PyObject * > -build_line_table_tuple_from_pcs (int line, const std::vector &pcs) > +build_line_table_tuple_from_entries ( > + const struct objfile *objfile, > + const std::vector &entries) > { > int i; > > - if (pcs.size () < 1) > + if (entries.size () < 1) > Py_RETURN_NONE; > > - gdbpy_ref<> tuple (PyTuple_New (pcs.size ())); > + gdbpy_ref<> tuple (PyTuple_New (entries.size ())); > > if (tuple == NULL) > return NULL; > > - for (i = 0; i < pcs.size (); ++i) > + for (i = 0; i < entries.size (); ++i) > { > - CORE_ADDR pc = pcs[i]; > - gdbpy_ref<> obj (build_linetable_entry (line, pc)); > + auto entry = entries[i]; > + gdbpy_ref<> obj (build_linetable_entry ( GDB style places the opening '(' on the same line as the argument list. > + entry->line, entry->pc (objfile), entry->is_stmt, > + entry->prologue_end, entry->epilogue_begin)); > > if (obj == NULL) > return NULL; > @@ -155,24 +169,35 @@ ltpy_get_pcs_for_line (PyObject *self, PyObject *args) > { > struct symtab *symtab; > gdb_py_longest py_line; > - const linetable_entry *best_entry = nullptr; > - std::vector pcs; > + std::vector entries; > > LTPY_REQUIRE_VALID (self, symtab); > > if (! PyArg_ParseTuple (args, GDB_PY_LL_ARG, &py_line)) > return NULL; > > + if (! symtab->linetable ()) > + Py_RETURN_NONE; > + > try > { > - pcs = find_pcs_for_symtab_line (symtab, py_line, &best_entry); Did you consider updating find_pcs_for_symtab_line to return 'std::vector' ? find_pcs_for_symtab_line already returns a linetable_entry* in the best_entry argument, so there's clearly no problem with the callers accessing that type. There are only two users of find_pcs_for_symtab_line (one of which is this one), so updating the function wouldn't be a huge amount of work. And this function uses a binary search to find the line table entry we're looking for, which will be better than the linear search you are using. > + const linetable_entry *entry; > + int i; > + for (entry = symtab->linetable ()->item, i = 0; > + i < symtab->linetable ()->nitems; > + entry++, i++) > + { > + if (entry->line == py_line) > + entries.push_back (entry); > + } > } > catch (const gdb_exception &except) > { > return gdbpy_handle_gdb_exception (nullptr, except); > } > > - return build_line_table_tuple_from_pcs (py_line, pcs); > + struct objfile *objfile = symtab->compunit ()->objfile (); > + return build_line_table_tuple_from_entries (objfile, entries); > } > > /* Implementation of gdb.LineTable.has_line (self, line) -> Boolean. > @@ -321,6 +346,50 @@ ltpy_entry_get_pc (PyObject *self, void *closure) > return gdb_py_object_from_ulongest (obj->pc).release (); > } > > +/* Implementation of gdb.LineTableEntry.is_stmt (self) -> bool. Returns > + True if associated PC is a good location to place a breakpoint for > + associatated LINE. */ > + > +static PyObject * > +ltpy_entry_get_is_stmt (PyObject *self, void *closure) > +{ > + linetable_entry_object *obj = (linetable_entry_object *) self; > + > + if (obj->is_stmt != 0) > + Py_RETURN_TRUE; > + else > + Py_RETURN_FALSE; > +} > + > +/* Implementation of gdb.LineTableEntry.prologue_end (self) -> bool. Returns > + True if associated PC is a good location to place a breakpoint after a > + function prologue. */ > + > +static PyObject * > +ltpy_entry_get_prologue_end (PyObject *self, void *closure) > +{ > + linetable_entry_object *obj = (linetable_entry_object *) self; > + > + if (obj->prologue_end) > + Py_RETURN_TRUE; > + else > + Py_RETURN_FALSE; > +} > + > +/* Implementation of gdb.LineTableEntry.prologue_end (self) -> bool. Returns > + True if this location marks the start of the epilogue. */ > + > +static PyObject * > +ltpy_entry_get_epilogue_begin (PyObject *self, void *closure) > +{ > + linetable_entry_object *obj = (linetable_entry_object *) self; > + > + if (obj->epilogue_begin) > + Py_RETURN_TRUE; > + else > + Py_RETURN_FALSE; > +} > + > /* LineTable iterator functions. */ > > /* Return a new line table iterator. */ > @@ -406,7 +475,8 @@ ltpy_iternext (PyObject *self) > } > > struct objfile *objfile = symtab->compunit ()->objfile (); > - obj = build_linetable_entry (item->line, item->pc (objfile)); > + obj = build_linetable_entry (item->line, item->pc (objfile), item->is_stmt, > + item->prologue_end, item->epilogue_begin ); > iter_obj->current_index++; > > return obj; > @@ -534,9 +604,16 @@ static gdb_PyGetSetDef linetable_entry_object_getset[] = { > "The line number in the source file.", NULL }, > { "pc", ltpy_entry_get_pc, NULL, > "The memory address for this line number.", NULL }, > + { "is_stmt", ltpy_entry_get_is_stmt, NULL, > + "Whether this is a good location to place a breakpoint for associated LINE.", NULL }, > + { "prologue_end", ltpy_entry_get_prologue_end, NULL, > + "Whether this is a good location to place a breakpoint after method prologue.", NULL }, > + { "epilogue_begin", ltpy_entry_get_epilogue_begin, NULL, > + "True if this location marks the start of the epilogue.", NULL }, s/NULL/nullptr/ please. Thanks, Andrew