From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id BIK9Kw7B5GDMSwAAWB0awg (envelope-from ) for ; Tue, 06 Jul 2021 16:46:06 -0400 Received: by simark.ca (Postfix, from userid 112) id A2ED01F1F4; Tue, 6 Jul 2021 16:46:06 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RDNS_DYNAMIC,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from 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 75CE71E54D for ; Tue, 6 Jul 2021 16:46:03 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 09051384783B for ; Tue, 6 Jul 2021 20:46:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 09051384783B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1625604363; bh=n7vMEL3gPW1+b/vEKiH1UhavBRb8tTJt1AUnUr630dc=; 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=lPZ4/zkobKbGTU93IuoCIqOb0NdeVMDONezGsyw0i6K6XHT0zudkq0l6dLILRZ+6f OvMM9KwBxWNXwUw2nCUm2jRX/2ELrCVsgfKNNNmwXJUdvCNstAL9KHgruaUiTlbfnw 2riccr78u0ICAEZQdZEuMq26KUUrzVhuyOoeJPVE= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 51615389853D for ; Tue, 6 Jul 2021 20:45:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 51615389853D 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 166KjW9X016671 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 6 Jul 2021 16:45:36 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 166KjW9X016671 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 D73E61E54D; Tue, 6 Jul 2021 16:45:12 -0400 (EDT) Subject: Re: [PATCH 02/11] gdb: introduce intrusive_list, make thread_info use it To: Pedro Alves , gdb-patches@sourceware.org References: <20210622165704.2404007-1-simon.marchi@polymtl.ca> <20210622165704.2404007-3-simon.marchi@polymtl.ca> <2466c5e0-36f4-ce47-f05f-022cda04bb04@palves.net> Message-ID: Date: Tue, 6 Jul 2021 16:45:12 -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: 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 Tue, 6 Jul 2021 20:45:32 +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 Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" > Or can we define a pretty printer on the `struct thread_info *` type, > such that when a thread_info pointer is printed, we can print some extra > information next to the pointer value? Like: > > (gdb) print tp > $1 = (thread_info *) 0x61700002c000 { id=1.1, ptid=1000.1000.0, state=THREAD_RUNNING } > > So presumably, when printing the list, that would give: > > $1 = intrusive list of thread_info = { > 0x61700002c000 {id = 1.1, ptid = 1000.1000.0, state = THREAD_RUNNING}, > 0x617000069080 {id = 1.3, ptid = 1000.1002.0, state = THREAD_STOPPED}, > 0x617000069400 {id = 1.5, ptid = 1000.3672.0, state = THREAD_STOPPED} > } > > But I don't even know if that is possible. I'll give it a try and report back. That kind of works: (top-gdb) p current_inferior_.m_obj .thread_list .m_front $5 = (struct thread_info *) 0x61700003b180 {id = 1.1, ptid = 2243033.2243033.0} (top-gdb) p current_inferior_.m_obj .thread_list $6 = intrusive list of struct thread_info = {(struct thread_info *) 0x61700003b180 {id = 1.1, ptid = 2243033.2243033.0}, (struct thread_info *) 0x61700003b500 {id = 1.2, ptid = 2243033.2243036.0}, (struct thread_info *) 0x61700003b880 {id = 1.3, ptid = 2243033.2243037.0}, (struct thread_info *) 0x61700003bc00 {id = 1.4, ptid = 2243033.2243038.0}} (top-gdb) set print array-indexes (top-gdb) p current_inferior_.m_obj .thread_list $7 = intrusive list of struct thread_info = {[0] = (struct thread_info *) 0x61700003b180 {id = 1.1, ptid = 2243033.2243033.0}, [1] = (struct thread_info *) 0x61700003b500 {id = 1.2, ptid = 2243033.2243036.0}, [2] = (struct thread_info *) 0x61700003b880 {id = 1.3, ptid = 2243033.2243037.0}, [3] = (struct thread_info *) 0x61700003bc00 {id = 1.4, ptid = 2243033.2243038.0}} It looks like the output of pretty-printers with display_hint 'array' isn't affected by "set print pretty", so it's always displayed on one line, that's strange. What I don't like about this solution is that I have to replicate the '(struct thread_info *) 0x12345' part of the display, that is normally displayed by GDB for a pointer: class ThreadInfoPointerPrinter: def __init__(self, val): self._val = val def to_string(self): ptid = self._val['ptid'] inf_num = self._val['inf']['num'] per_inf_num = self._val['per_inf_num'] return '(struct thread_info *) {} {{id = {}.{}, ptid = {}}}'.format(hex(int(self._val)), inf_num, per_inf_num, ptid) It would be nice if there was a way to just append some information after the default display. > Perhaps that could be done by pretending intrusive_list is a map, making > the display_hint method return 'map' instead of 'array': > > https://sourceware.org/gdb/onlinedocs/gdb/Pretty-Printing-API.html#Pretty-Printing-API I tried this, it does work: $1 = intrusive list of struct thread_info = { [0] = 0x61700003b180, [1] = 0x61700003b500, [2] = 0x61700003b880, [3] = 0x61700003bc00 } However, I see this as going around / abusing our pretty-printing API. If one doesn't want to see the indices, it becomes impossible (AFAIK). If you want array-indexes, why not just set array-indexes on? It is the same when printing an std::vector, you don't have indices: $1 = std::vector of length 10, capacity 16 = {0x55555556aeb0, 0x55555556aef0, 0x55555556aed0, 0x55555556af10, 0x55555556af60, 0x55555556afd0, 0x55555556aff0, 0x55555556b010, 0x55555556b030, 0x55555556b0e0} And for a vector, it's even more natural to index with []. There too, it becomes useful to enable array-indexes: $4 = std::vector of length 10, capacity 16 = {[0] = 0x55555556aeb0, [1] = 0x55555556aef0, [2] = 0x55555556aed0, [3] = 0x55555556af10, [4] = 0x55555556af60, [5] = 0x55555556afd0, [6] = 0x55555556aff0, [7] = 0x55555556b010, [8] = 0x55555556b030, [9] = 0x55555556b0e0} Simon