From patchwork Sun Oct 6 19:40:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Burgess X-Patchwork-Id: 98444 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 25543385F014 for ; Sun, 6 Oct 2024 19:40:54 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org 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 6C09F3858CD9 for ; Sun, 6 Oct 2024 19:40:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6C09F3858CD9 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 6C09F3858CD9 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=1728243633; cv=none; b=qLBktSSYGpjArLCu8+QUHHxJ60a8bXJAWeNVNWja5f7s6uY/y2AsDK57RUZNemDBscl4XqF1BsoNkOT9D2D0mmx4OSF3voDp+AMbo6RU6qLGtSjEYYvNePW5ZPvV1zyNMbCXGDcAw46QNE7k4s6q2Q7cP5inBFsL8aGNHUv4mjo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728243633; c=relaxed/simple; bh=VOd6y8VvY8hDjhOYZFNkPpbyv4+VDCsxpWfQUPlc5eA=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=HQXa5CiMK+WQrSzo2mE8q7fGc1I4oDsHY2iZXEFduDomETdk/NtSxMUMPZmylNy52HHbsPgFg4NgbJpo/DSWRiN55XkJNaBZ1d41535X+73jVim9vzuGHYAeeumnT7wcpIITkpBVySOumnTYAaMMfsinMbdJ9Xk6W6aBq3JtdKo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1728243629; 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: content-transfer-encoding:content-transfer-encoding; bh=Z8LDk+zYYOR1deaR8XOVVDSuCusUEqASoC0D6xUyv1c=; b=KAYOSz3YDEhNKyjK2ZFdRZbEWSNfle3O2XqXoy5x18HQt8704QSUCv+j+65eb+WxR6+yip UUPR276CrR21hAjO3ee3Fvu97q9WDK7gIeA/gOvXiSHuKJ8qnY286ol6aJgUPpXY6XVgUD 0DVwgny2pc1UsGW/x7eqEbQCKuPxI/c= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-212-4mwo6SlEPsi8VfEKoopNyg-1; Sun, 06 Oct 2024 15:40:27 -0400 X-MC-Unique: 4mwo6SlEPsi8VfEKoopNyg-1 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-5c878e2dbb0so4899864a12.1 for ; Sun, 06 Oct 2024 12:40:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728243626; x=1728848426; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z8LDk+zYYOR1deaR8XOVVDSuCusUEqASoC0D6xUyv1c=; b=vItHe8pmbYUzHPMMDwapswXOxj5vEPrj4EEQd5owzaxy09cB2hO1ncZKbVlmZSHK5a 76ieARt0j7pUExFzgY2L68dJCwe7cNJZfzyb0aLdU+30gjAr1+KnAIpJ654spkNKpMK7 lY6gmA4t8XASG3EK5yzHBnvJVeoq1IMsEMsmZaH5mgxdcHFmHCXNJBU9ci2WwdpyiYzh cwpd0y9GqjxV2k6gfhh0tVD8v6Q1pz9cCmcc5Z158LNrQVWOXuSVmpDPVefABYzYIxbx U9G3XCcqwExixiZ/iqsiijowAJODeiblOQL1f2+sOFtj9JTa5wiotmA+jXrOHK/bbCB6 ZgDw== X-Gm-Message-State: AOJu0YxxplrhqrJEQ9xbgzeEZNu0Pfnc8o4m42Ped/aMFMWvwS0ID8ec Q4W63pYRX7dTJnOVLFdW7XjpOMpzYg+EEHKUQo7r/8ura9e8TL5IFHwNDCUQnvoyZV3N7lc8xMu 7PAyBCCoE9LjCbXU5/Fdavj8lVy4cZ5tcTTLDjmFg0yVgVDHoJYGUw+F5l4y9KNZcVutp0z7bk7 XB4VAYBcgkKlS9nWuvtlx9HxMCefx1N8RTV6jc3M1hdgI= X-Received: by 2002:a05:6402:35c4:b0:5c8:8844:7874 with SMTP id 4fb4d7f45d1cf-5c8c0a1fe0emr14578746a12.10.1728243626381; Sun, 06 Oct 2024 12:40:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFuxT90wi45M92C2jWwtliX2Sqj74x2w891Fbd7VMYde4M9rK5a4eT0CjoG007sxorqSSw5pA== X-Received: by 2002:a05:6402:35c4:b0:5c8:8844:7874 with SMTP id 4fb4d7f45d1cf-5c8c0a1fe0emr14578728a12.10.1728243625881; Sun, 06 Oct 2024 12:40:25 -0700 (PDT) Received: from localhost (243.223.159.143.dyn.plus.net. [143.159.223.243]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c8e0594a61sm2354160a12.5.2024.10.06.12.40.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Oct 2024 12:40:25 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH] gdb/guile: add get-basic-type Date: Sun, 6 Oct 2024 20:40:23 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.8 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_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org 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~patchwork=sourceware.org@sourceware.org A question was asked on stackoverflow.com about the guile function get-basic-type[1] which is mentioned in the docs along with an example of its use. The problem is, the function was apparently never actually added to GDB. But it turns out that it's pretty easy to implement, so lets add it now. Better late than never. The implementation mirrors the Python get_basic_type function. I've added a test which is a copy of the documentation example. One issue is that the docs suggest that the type will be returned as just "int", however, I'm not sure what this actually means. It makes more sense that the function return a gdb:type object which would be represented as "#", so I've updated the docs to show this output. [1] https://stackoverflow.com/questions/79058691/unbound-variable-get-basic-type-in-gdb-guile-session Reviewed-by: Kevin Buettner --- gdb/doc/guile.texi | 2 +- gdb/guile/lib/gdb/types.scm | 19 +++++++++++++++++++ gdb/testsuite/gdb.guile/types-module.cc | 4 ++++ gdb/testsuite/gdb.guile/types-module.exp | 5 +++++ 4 files changed, 29 insertions(+), 1 deletion(-) base-commit: bcb92f7ba7b22ac882c000cabfd7ca8bea47c184 diff --git a/gdb/doc/guile.texi b/gdb/doc/guile.texi index a66e8bfe16b..bd1262ea0cb 100644 --- a/gdb/doc/guile.texi +++ b/gdb/doc/guile.texi @@ -3946,7 +3946,7 @@ (gdb) guile (use-modules (gdb) (gdb types)) (gdb) guile (define foo-ref (parse-and-eval "foo_ref")) (gdb) guile (get-basic-type (value-type foo-ref)) -int +# @end smallexample @end deffn diff --git a/gdb/guile/lib/gdb/types.scm b/gdb/guile/lib/gdb/types.scm index 198de9d3b72..7d8d3c639b9 100644 --- a/gdb/guile/lib/gdb/types.scm +++ b/gdb/guile/lib/gdb/types.scm @@ -55,6 +55,25 @@ (search-class type)) +(define-public (get-basic-type type) + "Return the \"basic\" type of a given type. + + Arguments: + type: The type to reduce to its basic type. + + Returns: + TYPE with const/volatile stripped away, and typedefs/references + converted to the underlying type." + + (while (or (= (type-code type) TYPE_CODE_REF) + (= (type-code type) TYPE_CODE_RVALUE_REF) + (= (type-code type) TYPE_CODE_TYPEDEF)) + (if (= (type-code type) TYPE_CODE_TYPEDEF) + (set! type (type-strip-typedefs type)) + (set! type (type-target type)))) + + (type-unqualified type)) + (define-public (make-enum-hashtable enum-type) "Return a hash table from a program's enum type. diff --git a/gdb/testsuite/gdb.guile/types-module.cc b/gdb/testsuite/gdb.guile/types-module.cc index 9b32f672ab0..f3992c04145 100644 --- a/gdb/testsuite/gdb.guile/types-module.cc +++ b/gdb/testsuite/gdb.guile/types-module.cc @@ -31,6 +31,10 @@ class derived : public base derived d; +typedef const int const_int; +const_int foo (3); +const_int &foo_ref (foo); + int main (void) { diff --git a/gdb/testsuite/gdb.guile/types-module.exp b/gdb/testsuite/gdb.guile/types-module.exp index d95ff21df5e..ee558041fa6 100644 --- a/gdb/testsuite/gdb.guile/types-module.exp +++ b/gdb/testsuite/gdb.guile/types-module.exp @@ -59,3 +59,8 @@ gdb_test "guile (define bad-enum-htab (make-enum-hashtable #f))" \ gdb_test "guile (define bad-enum-htab (make-enum-hashtable (lookup-type \"int\")))" \ "Wrong type argument in position 1 \\(expecting enum\\): #.*" \ "make-enum-hashtable from int" + +gdb_test_no_output "guile (define foo-ref (parse-and-eval \"foo_ref\"))" \ + "get foo-ref value" +gdb_test "guile (get-basic-type (value-type foo-ref))" "#" \ + "check get-basic-type"