From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id p47eNDOF0mC0bQAAWB0awg (envelope-from ) for ; Tue, 22 Jun 2021 20:49:55 -0400 Received: by simark.ca (Postfix, from userid 112) id C9F1D1F1F2; Tue, 22 Jun 2021 20:49:55 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 8CA121E54D for ; Tue, 22 Jun 2021 20:49:54 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0010B383D016 for ; Wed, 23 Jun 2021 00:49:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0010B383D016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1624409394; bh=pHzHq/+qkZUS5wpy9x4/AWLRK+Nd94RytAZs18sKXYk=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=NvDnabcLseHc4Gpeg09uiT5+Ztbhor/NatDMc4rzuth5zo4t92FGgxLIMs7CCFOLH /K2oj0dXPkCwuiiSz0WcvJP0Y6TNntmUuKKhgRk2c8pEycCCpUTC5EKlLQVCQ69tsE ZwdaRVy8/2SgKtbKzA5KERVq7KYsZ0Ad+rQpAGdg= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id B592B38515E7 for ; Wed, 23 Jun 2021 00:49:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B592B38515E7 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 15N0mKfP001010 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 22 Jun 2021 20:48:25 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 15N0mKfP001010 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id E90D31E54D; Tue, 22 Jun 2021 20:48:19 -0400 (EDT) Subject: Re: [PATCH 02/11] gdb: introduce intrusive_list, make thread_info use it To: Lancelot SIX , Pedro Alves References: <20210622165704.2404007-1-simon.marchi@polymtl.ca> <20210622165704.2404007-3-simon.marchi@polymtl.ca> <20210622231319.6hgxooumjnkns7pb@ubuntu.lan> Message-ID: Date: Tue, 22 Jun 2021 20:48:19 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210622231319.6hgxooumjnkns7pb@ubuntu.lan> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Wed, 23 Jun 2021 00:48:20 +0000 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: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Cc: Simon Marchi , gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" >> +class IntrusiveListPrinter: >> + """Print a struct intrusive_list.""" >> + >> + def __init__(self, val): >> + self._val = val >> + >> + # Type of linked items. >> + self._item_type = self._val.type.template_argument(0) >> + self._node_ptr_type = gdb.lookup_type( >> + f"intrusive_list_node<{self._item_type.tag}>" > > Hi, > > I do not know what are the compatibility constraints / minimum python > version required, but f-string do require at least python-3.6. This > covers all still supported python versions, but there might be distros > out-there that are not there yet (there are a few of those in this > file). Huh... right. It's not clear what we aim to support, I'd like if it was clearer. But we still support build against Python 2.7, so it would make sense to try to be compatible with it. I'll switch to using `"...".format(...)`. >> + ).pointer() >> + >> + # Type of value -> node converter. >> + self._conv_type = self._val.type.template_argument(1) >> + >> + if self._uses_member_node(): >> + # The second template argument of intrusive_member_node is a member >> + # pointer value. Its value is the offset of the node member in the >> + # enclosing type. >> + member_node_ptr = self._conv_type.template_argument(1) >> + member_node_ptr = member_node_ptr.cast(gdb.lookup_type("int")) >> + self._member_node_offset = int(member_node_ptr) >> + >> + # This is only needed in _as_node_ptr if using a member node. Look it >> + # up here so we only do it once. >> + self._char_ptr_type = gdb.lookup_type("char").pointer() >> + >> + def display_hint(self): >> + return "array" >> + >> + # Return True if the list items use a node as a member. Return False if >> + # they use a node as a base class. >> + def _uses_member_node(self): > > The documentation for the function should probably go as a doc string, > not a comment before the function: > > def _uses_member_node(self): > """ Return True if the list items use a node as a member. Return False > if they use a node as a base class. > """ > > The same remark stands for the other method in this file. Done. >> + if self._conv_type.name.startswith("intrusive_member_node<"): >> + return True >> + elif self._conv_type.name.startswith("intrusive_base_node<"): >> + return False >> + else: >> + raise RuntimeError( >> + f"Unexpected intrusive_list value -> node converter type: {self._conv_type.name}" >> + ) >> + >> + def to_string(self): >> + s = f"intrusive list of {self._item_type}" >> + >> + if self._uses_member_node(): >> + node_member = self._conv_type.template_argument(1) >> + s += f", linked through {node_member}" >> + >> + return s >> + >> + # Given ELEM_PTR, a pointer to a list element, return a pointer to the >> + # corresponding intrusive_list_node. >> + def _as_node_ptr(self, elem_ptr): >> + assert elem_ptr.type.code == gdb.TYPE_CODE_PTR >> + >> + if self._uses_member_node(): >> + # Node as a memer: add the member node offset from to the element's > > s/memer/member/ ? Fixed. I integrated the changes in my local tree. Simon PS: when you review, don't hesitate to trim the irrelevant parts of the diff, it will make your comments easier to find and harder to miss. I almost missed the last one, especially because it was after your signature! Still, thank you very much for looking at the various patches on the list, it's very appreciated.