From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) by sourceware.org (Postfix) with ESMTPS id 554743858408 for ; Thu, 22 Jun 2023 16:19:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 554743858408 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-77e2df49a91so242282539f.2 for ; Thu, 22 Jun 2023 09:19:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1687450772; x=1690042772; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8RRFTe7Xj+12Sq9MXrz5P2pjXghh6uh2rHfK2+2/IXk=; b=ZMqzEGvEu1bbE9oRAI7EBmCHOqRUMfZSg0dH+Plbg7sl4UP8wabKfFaigOckNYw0bS nxtTFodrLupPufyVG4dSPfy0gXHlCjQqYWiZBXNe/Co8Y96zoc8eLJ3LJJzwbcSHGfhq HFz8A0SLWa844p6MdWoPDyLMmXI/992Acc++FNbgSVOGpxt+KJEjz9nq3c+37uuD95CA PQvlvZn8fhZuMS6+joj3xjSFYz36LxSZg2Xa4tTDSTww/9uuGyJSz4XlXhtptRgkOrdy VaobSJr9RYDkszJWMu4klyaBQJmjZ0hkX4zN1vliKy76uNQpaikSVRakEmSzlMyFz7fo pi2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687450772; x=1690042772; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8RRFTe7Xj+12Sq9MXrz5P2pjXghh6uh2rHfK2+2/IXk=; b=ejcVg4V+hcQZr89VLKM8KoAE0qa7CkTTXggajc3x1OW8fnGtj3ndNfyd8vrgNl6HF/ LydWE7A8IqDUJCt3a6tObjmnOvttzvE4Au4lzALIpon7WCEj9e/MLS77JVv+iVE1WOVF UEGWtGo1kziWgDDUR+p7V/oQyW9u/ojfyZZbyOx/TEybcJ4odjtyeFZECk07Wr2yh+10 i0HlxGPh+4t7KaDkZH7+CxGFkc0vP/jCjQMkgFsFGZAmcZsyzPI5HRFPBpauvJjiNOXn turhvnx5awCbZI1Ec4C9n2YeOYFin4BUVfHn0HNQtUzFkFq9MfrLHNZwaU2HaR5dootD 5V2w== X-Gm-Message-State: AC+VfDzzukDbrC5jXkwcgT+Yx1OWCQpHERzba1iloTqh6Nhb3k2CVBmS k+qtOjOm+x/oUwQgn2MolmM4hv2xe1CFhSybfecZoA== X-Google-Smtp-Source: ACHHUZ7qNwBkoyqelh6sdZcoEXGh8eT/kY2K5CUw7AfAybsdnw7yd7q3K3nDXdHt8UJb2+7TaXjAqA== X-Received: by 2002:a6b:7f01:0:b0:780:ce89:ca6a with SMTP id l1-20020a6b7f01000000b00780ce89ca6amr2070455ioq.10.1687450771944; Thu, 22 Jun 2023 09:19:31 -0700 (PDT) Received: from localhost.localdomain (75-166-136-83.hlrn.qwest.net. [75.166.136.83]) by smtp.gmail.com with ESMTPSA id y8-20020a6bd808000000b0077ac2261248sm2201987iob.5.2023.06.22.09.19.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 09:19:31 -0700 (PDT) From: Tom Tromey Date: Thu, 22 Jun 2023 10:19:32 -0600 Subject: [PATCH v2 6/7] Handle typedefs in no-op pretty printers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230614-dap-frame-decor-v2-6-10628dfa6b60@adacore.com> References: <20230614-dap-frame-decor-v2-0-10628dfa6b60@adacore.com> In-Reply-To: <20230614-dap-frame-decor-v2-0-10628dfa6b60@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.2 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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 List-Id: The no-ops pretty-printers that were introduced for DAP have a classic gdb bug: they neglect to call check_typedef. This will cause some strange behavior; for example not showing the children of a variable whose type is a typedef of a structure type. This patch fixes the oversight. --- gdb/python/lib/gdb/printing.py | 23 ++++++++++++----------- gdb/testsuite/gdb.dap/scopes.c | 6 +++--- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/gdb/python/lib/gdb/printing.py b/gdb/python/lib/gdb/printing.py index 353427d000a..a668bd0e3fc 100644 --- a/gdb/python/lib/gdb/printing.py +++ b/gdb/python/lib/gdb/printing.py @@ -282,9 +282,9 @@ class NoOpScalarPrinter: class NoOpArrayPrinter: """A no-op pretty printer that wraps an array value.""" - def __init__(self, value): + def __init__(self, ty, value): self.value = value - (low, high) = self.value.type.range() + (low, high) = ty.range() self.low = low self.high = high # This is a convenience to the DAP code and perhaps other @@ -305,14 +305,15 @@ class NoOpArrayPrinter: class NoOpStructPrinter: """A no-op pretty printer that wraps a struct or union value.""" - def __init__(self, value): + def __init__(self, ty, value): + self.ty = ty self.value = value def to_string(self): return "" def children(self): - for field in self.value.type.fields(): + for field in self.ty.fields(): if field.name is not None: yield (field.name, self.value[field]) @@ -327,14 +328,14 @@ def make_visualizer(value): if result is not None: # Found a pretty-printer. pass - elif value.type.code == gdb.TYPE_CODE_ARRAY: - result = gdb.printing.NoOpArrayPrinter(value) - (low, high) = value.type.range() - result.n_children = high - low + 1 - elif value.type.code in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION): - result = gdb.printing.NoOpStructPrinter(value) else: - result = gdb.printing.NoOpScalarPrinter(value) + ty = value.type.strip_typedefs() + if ty.code == gdb.TYPE_CODE_ARRAY: + result = gdb.printing.NoOpArrayPrinter(ty, value) + elif ty.code in (gdb.TYPE_CODE_STRUCT, gdb.TYPE_CODE_UNION): + result = gdb.printing.NoOpStructPrinter(ty, value) + else: + result = gdb.printing.NoOpScalarPrinter(value) return result diff --git a/gdb/testsuite/gdb.dap/scopes.c b/gdb/testsuite/gdb.dap/scopes.c index ce87db1f13d..8f17c0d9039 100644 --- a/gdb/testsuite/gdb.dap/scopes.c +++ b/gdb/testsuite/gdb.dap/scopes.c @@ -17,13 +17,13 @@ int main () { - struct dei_struct + typedef struct dei_struct { int x; int more[5]; - }; + } dei_type; - struct dei_struct dei = { 2, { 3, 5, 7, 11, 13 } }; + dei_type dei = { 2, { 3, 5, 7, 11, 13 } }; static int scalar = 23; -- 2.40.1