From patchwork Wed Jul 26 21:52:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Revunov Denis X-Patchwork-Id: 73251 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 D45F73858C60 for ; Wed, 26 Jul 2023 21:53:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D45F73858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1690408389; bh=r8HzBDoj/51ICV0+KfLAus9mMfc+bqAvZZRAU7BrbLU=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=i3Ow6Oz3ZrJB7NNpeFo62piDGr0J8fAxmGV2H4G//gXRccN5qesxQsho5waf0Oh0H oguq+sJVlvgeACiJHF7MWSGwmxRkOlth7fTfZ4eelmHFMZNsTFVC5F6A7MKt85gXKR wtKdtMZbnXcQEUEJ6Uwq5VBAMshdayy2SZw3n5+I= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by sourceware.org (Postfix) with ESMTPS id 1A4B83858D35 for ; Wed, 26 Jul 2023 21:52:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1A4B83858D35 Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4fdd14c1fbfso467931e87.1 for ; Wed, 26 Jul 2023 14:52:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690408363; x=1691013163; 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=r8HzBDoj/51ICV0+KfLAus9mMfc+bqAvZZRAU7BrbLU=; b=f47YFn5SXW92WPk5NCLKj5pRxSebqUVfsaGXMjUOgNjOpEuyfe63wERYvt9scM44cJ dFfMiVpLDNWooj6fDqnjXky/6wc8FuwebYTsco6kPZ5L/I1fODiUFUscD5DPzwdIa8Ym UR4X0D679+28FEHnz87LCo/uvLmfl8OW6YOwSUwE+l8HmfMo7t4j+Lj6IQE8bnzPdtWa FKXZrAAHuaEXtAcUfyiZ2VNx4lXW6oFmzFgGbtdrmP4rUf66bViTlIOpxG/E5eQ1bJuV e1YPE1tDO/Uw9ki94m97DE8ZJ9uAMj3dZOnPqXXZICV9pnTZCwOWyU0HjfzAYmO6fDxE lvow== X-Gm-Message-State: ABy/qLYg4BQ15b/iW1ryUe1XUsUZ0ELCfs9S+69Ec3LkcEb3Mh55Jl+7 hXGYMO88alT7QQiXwgIzYk7/SB4S9Tw= X-Google-Smtp-Source: APBJJlH0veWQpftDuy7y7xk1hb9FTp40yKqKuf7wMaG59AGvPnaynQ6ANZAsbc1TjhkEeMEE3u0pBg== X-Received: by 2002:a05:6512:6c4:b0:4fb:8b78:4a93 with SMTP id u4-20020a05651206c400b004fb8b784a93mr246291lff.7.1690408362483; Wed, 26 Jul 2023 14:52:42 -0700 (PDT) Received: from localhost.localdomain (sc6ad6218.fastvps-server.com. [46.36.219.105]) by smtp.gmail.com with ESMTPSA id q13-20020ac246ed000000b004fdd9d42b1asm3533lfo.157.2023.07.26.14.52.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jul 2023 14:52:42 -0700 (PDT) To: gdb-patches@sourceware.org Cc: Denis Revunov Subject: [RFC] [PATCH] Return intptr when dereferencing integer Date: Thu, 27 Jul 2023 00:52:05 +0300 Message-ID: <20230726215205.3995028-1-rnovds@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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 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: , X-Patchwork-Original-From: Denis Revunov via Gdb-patches From: Revunov Denis Reply-To: Denis Revunov Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" The code which makes default dereference type an int was intruduced in gdb-3.4(1c997a4ae869) in 1989, 10 years before AMD64 was released. With current adoption of 64-bit it makes sense to change default dereference size to match the native address size, which will enable us to easily inspect .got entries and follow chains of pointers on 64-bit systems without excessive casting. This change won't affect 32-and-less bit systems since intptr is the same as int there. --- gdb/eval.c | 7 +++---- gdb/gdbtypes.c | 3 +++ gdb/gdbtypes.h | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gdb/eval.c b/gdb/eval.c index 457a6697923..23568d8ed3c 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -1672,11 +1672,10 @@ eval_op_ind (struct type *expect_type, struct expression *exp, } /* Allow * on an integer so we can cast it to whatever we want. - This returns an int, which seems like the most C-like thing to - do. "long long" variables are rare enough that - BUILTIN_TYPE_LONGEST would seem to be a mistake. */ + This returns an intptr, which has the same size as a native + address and thus can be treated as a pointer on any machine. */ if (type->code () == TYPE_CODE_INT) - return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int, + return value_at_lazy (builtin_type (exp->gdbarch)->builtin_intptr, (CORE_ADDR) value_as_address (arg1)); return value_ind (arg1); } diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index c5272979cb9..9deacd94ce2 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -6026,6 +6026,9 @@ create_gdbtypes_data (struct gdbarch *gdbarch) = init_integer_type (alloc, 128, 0, "int128_t"); builtin_type->builtin_uint128 = init_integer_type (alloc, 128, 1, "uint128_t"); + builtin_type->builtin_intptr + = init_integer_type (alloc, gdbarch_addr_bit (gdbarch), 0, + "intptr_t"); builtin_type->builtin_int8->set_instance_flags (builtin_type->builtin_int8->instance_flags () diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index aedaf53cd5d..222f92815a9 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -2079,6 +2079,7 @@ struct builtin_type struct type *builtin_uint64 = nullptr; struct type *builtin_int128 = nullptr; struct type *builtin_uint128 = nullptr; + struct type *builtin_intptr = nullptr; /* Wide character types. */ struct type *builtin_char16 = nullptr;