From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4fdd14c1fbfso467931e87.1 for ; Wed, 26 Jul 2023 14:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690408363; x=1691013163; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=r8HzBDoj/51ICV0+KfLAus9mMfc+bqAvZZRAU7BrbLU=; b=C4zxBnm3fZU5i+AERPcu5m517tGER6qBio6fxF6s+CyB5e1HlrsqB9MWoAdgIv7QRU ZNtBI5lHQEoCfis89f3Yf9kKxAGxiCsEiMOl+9Z5fgxFArLfxzCUokO8u9ND+TVNl0eo e+zh6ph78WITxLE2BOXPLQVPkK69HlxVMVOwSkPY8Is8DW+Z0xImtg0p4XemA63ZbACQ IOrMRvwTVDeddCUSgUhSPTm86sKqPWEnWWZQSvagmbJrIlptzUiq/SFnzK3X2rmHC/M8 Cx43z5K//Ah1axGkkamEd1gITkpVopetc6vNhoO7ybC4k4XKTVmgqPv06oSdX5Searot 2Xkg== 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) From: Denis Revunov 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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; -- 2.41.0