From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id D51613858D28 for ; Sat, 29 Jul 2023 00:15:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D51613858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-997c4107d62so357863766b.0 for ; Fri, 28 Jul 2023 17:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690589729; x=1691194529; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=oOxmM1/XDfephEcFPNMvX6CSe1FjaIy1I5goaIEQvCI=; b=hSquL0pEHFpMomXSYs7yJ9OejeYHLXWPmN/UqEwoSnvV1HOehPhDfL1cDANuRpWyud xGPFitPYCjSI3Ymwad92f+xloT8dKV7YNKaxvRGlVg/2PcDVD39vqkuCPNlioK0juCkW oUF62OyLd3VwuDAbehkDQ8CIipTU6PhL5eSo9hXFSjF9AsMGhQx9thXScnVgdr62r6+J SeVub+h98K73lt+k52/Oy0N3v2UTjgDNpBwpSvyt8w/xICYxsasnbujzyqe3RP1nj3O4 cq+FjT23AohjsvUDkuaEk9azuGidaUiBXVG3ndqOBpfnkpsFyWUDx6WBD9j4l1B7W1ZA WyPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690589729; x=1691194529; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=oOxmM1/XDfephEcFPNMvX6CSe1FjaIy1I5goaIEQvCI=; b=Xs66P+8FnzKPsY9/MIneDPwQhoTXQWMm5rZMuOkC8b11xSJNlzsLqf2D0y0tJD7hSB U5rbWnioTJmQx8e/0+bvMbp6dBdi1RSLf+ZXUYwlsdE3XNZJULcGIYOPiDqYIgnzqaPJ 7mPK9t0+BO6IC2AOHGv/ptqRNrqF9fx3VG028YT6oN2yeEzH/iUTaWnJiyJtJwLGREtd 0mHT8JyMP5mg4vyB/vnfaS4gQxgrmiJ8mFNlo+8Bkwj9/oCC2Un6YeyK4Bln1Cou8R+S NSzgyq3E0SiDQt49Q4oBuSznZX2y015P58bbUTR0bxSoBj1u/ZJVojriZs+JDKcUnrnv RdpQ== X-Gm-Message-State: ABy/qLYjZ3VckWAC5RqT9vFVnGT/+p4epA6KmnUXGMKDEGGH8ur4SGq8 f7osa9B4qsr5ngRWGf3P+bCH0RV/ln0tvIHHehqAMxlqbQY= X-Google-Smtp-Source: APBJJlEeUq5fqgPlBq8BX2v7v6WL3vu/dv+vcEVLyTj1kOW0Z++qECLbmCiX31UNSSS+4Wj8rodHa7TWf3gtcsYCe1I= X-Received: by 2002:a17:907:2bc9:b0:991:d2a8:6588 with SMTP id gv9-20020a1709072bc900b00991d2a86588mr763227ejc.51.1690589728785; Fri, 28 Jul 2023 17:15:28 -0700 (PDT) MIME-Version: 1.0 References: <20230726215205.3995028-1-rnovds@gmail.com> <87lef1ib4o.fsf@tromey.com> In-Reply-To: <87lef1ib4o.fsf@tromey.com> From: Denis Revunov Date: Sat, 29 Jul 2023 03:14:47 +0300 Message-ID: Subject: Re: [RFC] [PATCH] Return intptr when dereferencing integer To: Tom Tromey Cc: Denis Revunov via Gdb-patches Content-Type: multipart/alternative; boundary="0000000000003ec9040601951843" X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,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: --0000000000003ec9040601951843 Content-Type: text/plain; charset="UTF-8" >>>>> "Tom" == Tom Tromey via Gdb-patches writes: Tom> Does this impact any test? I cannot be 100% sure because i get slightly different test results on consecutive runs even without any changes, but it seems the only failures appearing in gdb.sum diff (with/without the patch) are timeouts and some server stuff, and there's like 2-5 of them. So we're probably fine. Tom> If not, can a test be written for it? Sure, see a diff in the end. Tom> I guess from context the scenario is something like: "print *23", Tom> and here gdb acts like you typed "print *(int*)23"? That's right, and my point is to make it act like "print *(intptr_t*)23". Because int is intptr_t everywhere except 64-bit. Here's a diff for the test: --- gdb/testsuite/gdb.base/pointers.c | 5 ++++- gdb/testsuite/gdb.base/pointers.exp | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/gdb/testsuite/gdb.base/pointers.c b/gdb/testsuite/gdb.base/pointers.c index 96f2b52f5e8..d3a9689b46a 100644 --- a/gdb/testsuite/gdb.base/pointers.c +++ b/gdb/testsuite/gdb.base/pointers.c @@ -1,4 +1,4 @@ - +#include #if !defined (__STDC__) && !defined (_AIX) #define signed /**/ #endif @@ -71,6 +71,8 @@ float ** ptr_to_ptr_to_float; int y; +const intptr_t intptr_max = INTPTR_MAX; +intptr_t intptr_p; typedef long k[5]; @@ -170,6 +172,7 @@ void dummy() v_float_array[0] = v_float; v_double_array[0] = v_double; + intptr_p = (intptr_t)&intptr_max; } diff --git a/gdb/testsuite/gdb.base/pointers.exp b/gdb/testsuite/gdb.base/pointers.exp index d72fa5ad613..5787b873cca 100644 --- a/gdb/testsuite/gdb.base/pointers.exp +++ b/gdb/testsuite/gdb.base/pointers.exp @@ -202,6 +202,10 @@ gdb_test "print *( *(matrix+1) +2)" " = 5" \ gdb_test "print **ptr_to_ptr_to_float" " = 100" \ "print through ptr to ptr" +# when we attempt to dereference an integer, +# it should be treated as a pointer to intptr_t. +gdb_test "print *intptr_p == intptr_max" " = 1" "deref size is intptr" + # tests for pointers # with elementary type variables and pointers. # -- 2.41.0 On Thu, 27 Jul 2023 at 19:15, Tom Tromey wrote: > >>>>> "Denis" == Denis Revunov via Gdb-patches > writes: > > Denis> The code which makes default dereference type an int was intruduced > in > Denis> gdb-3.4(1c997a4ae869) in 1989, 10 years before AMD64 was released. > With > Denis> current adoption of 64-bit it makes sense to change default > dereference > Denis> size to match the native address size, which will enable us to > easily > Denis> inspect .got entries and follow chains of pointers on 64-bit systems > Denis> without excessive casting. This change won't affect 32-and-less bit > Denis> systems since intptr is the same as int there. > > Does this impact any test? > If not, can a test be written for it? > > I guess from context the scenario is something like: "print *23", > and here gdb acts like you typed "print *(int*)23"? > > Tom > --0000000000003ec9040601951843--