From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id iG49O41wNWbu/gQAWB0awg (envelope-from ) for ; Fri, 03 May 2024 19:17:33 -0400 Received: by simark.ca (Postfix, from userid 112) id E13DB1E0C1; Fri, 3 May 2024 19:17:33 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id C8F341E092 for ; Fri, 3 May 2024 19:17:31 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5072B3844754 for ; Fri, 3 May 2024 23:17:31 +0000 (GMT) Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by sourceware.org (Postfix) with ESMTPS id 00F5638460A2 for ; Fri, 3 May 2024 23:17:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 00F5638460A2 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 00F5638460A2 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714778234; cv=none; b=W337C2mr72A64l+AHbVvdwOeBltlNr1Rz+N6WT+NYA779rCEVFJSukhgdsWYUXIxvPyI4GsC+QNY2o9JyVReZYHKSoJwQxTIc+AFeBeAyI/WO0nrzh3Xg9oCFLl1mpm4Jft0eaeOF3+qEgMr8AT+C/WYtMWdQ4GRlyuC6KmvD1o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714778234; c=relaxed/simple; bh=JxekbnNX0zQYud/IAjcfeD8bXdRny2pmw39u1KqAtxg=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=ARMmRDHzD/8MwMUC7HtCuTh1lgF68lRQ5XRWpUOt12cmjsLfMpmeKwLR5FKQMXhNJpQST19wR0afFjR8SJosLv7dBIomtgzWSccmPihJdgYVaKuwU9ZYsmAukEtGvO2aXys+HtMAox46jmLoH/RGOGVRet6reO6oF9mBfP7G5Oc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-41c7ac71996so2226835e9.3 for ; Fri, 03 May 2024 16:17:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714778231; x=1715383031; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=B+GDpdOxzUtyqUkwt/khTwaS+zsy9YUvKOEuUcjMmEM=; b=hqz0KK6gikOnnRpn7mb4cvtxQY3DYlk1imiONcq4JFHAuWAc4rYt930bt3P65J0UjG vRgjsCvsMsqTTS05f49wudxqD1KPgi+c/IAzWrM+0AzqvrU1iUKZ5x+DyZ9Ga4xlmxCS fD3b9b9H1uQc9GVyVpCwO7UnzByDdxJWQE2EoSMT/gVKhwdr57dA/R7YoKTiYR7GHoeU EBMkqswfuAMukf4C2phejb1mmm6Ox0DpJFxQ9W/4L6UotWm3w4NQvCk04krArsd4CRyM 0EE6VkCzr2NCSN9jfKpB+PZjEoM0te51Vb5DjjOF9n4AdcTq4nYHS3kb6F61Krhvy6Qv CSSQ== X-Gm-Message-State: AOJu0Yxezfi8JU6HJFp0TL9kpp+XU3a997F3Qu14j1r+moQr61Kc8b+1 sdQogLsZqvwkddKAVFRwP5eRomrr9QGMfT9+BE6G6ZZIE+3D171X X-Google-Smtp-Source: AGHT+IEj/fcbshWMtKPK6XezkXJHfAGzkmje53xprexoAEoMzNPlgvS0AKkfbZ1e5hVB6CcQ0wg6Xw== X-Received: by 2002:adf:b317:0:b0:34c:120a:fbed with SMTP id j23-20020adfb317000000b0034c120afbedmr2958794wrd.15.1714778230419; Fri, 03 May 2024 16:17:10 -0700 (PDT) Received: from ?IPV6:2001:8a0:f93d:b900:18bd:4809:7583:abd1? ([2001:8a0:f93d:b900:18bd:4809:7583:abd1]) by smtp.gmail.com with ESMTPSA id dz1-20020a0560000e8100b0034ccb43dbbbsm4755825wrb.38.2024.05.03.16.17.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 03 May 2024 16:17:09 -0700 (PDT) Message-ID: Date: Sat, 4 May 2024 00:17:07 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] [gdb/exp] Fix cast handling for indirection To: Kevin Buettner Cc: gdb-patches@sourceware.org, Tom Tromey , Tom de Vries References: <20240502154902.22575-1-tdevries@suse.de> <20240502193145.5da7327d@f39-zbm-amd> <8734qyex0l.fsf@tromey.com> <51de396e-67fc-4451-a13e-091178d188f7@palves.net> <20240503103050.2ef46699@f39-zbm-amd> From: Pedro Alves Content-Language: en-US In-Reply-To: <20240503103050.2ef46699@f39-zbm-amd> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no 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+public-inbox=simark.ca@sourceware.org On 2024-05-03 18:30, Kevin Buettner wrote: > On Fri, 3 May 2024 17:04:41 +0100 > Pedro Alves wrote: > >>> I was wondering if this patch causes gdb to accept some weird things >>> that might have been rejected in the past, by introducing a hidden cast. >>> Maybe print (char) *85732 does something surprising now. I'm not >>> entirely sure if that's bad. >> >> I am totally surprised that: >> >> +# Regression test for PR31693. >> +gdb_test "p (char)*a_loc ()" " = 97 'a'" >> >> this actually works, instead of telling the user: >> >> "'a_loc' has unknown return type; cast the call to its declared return type" >> >> It seems like a misfeature to me to assume that "char *" is the right type. >> >> Thus, I don't agree with the patch. > > Using a GDB built with Tom de Vries's patch, I see: > > (gdb) p *a_loc() > 'a_loc' has unknown return type; cast the call to its declared return type > > This is the same as the pre-patch behavior. > > With Tom's patch, GDB now infers the function's return type, based > on the cast: > > (gdb) p (char)*a_loc() > $1 = 97 'a' > But that is not what GDB told you to do. It told you to cast the _call_, not the result of de-referencing the result of the call. It is telling cast to the declared return type, which is "char *". I.e., it is telling you to write: (gdb) p *(char *)a_loc() See 7022349d5c86 ("Stop assuming no-debug-info functions return int"). This cast here: (gdb) p (char)*a_loc() ... should not affect the call's return type. That is decided before the * operator is involved. In the same way, this: (gdb) p (long long)*a_loc() should not result in gdb assuming that a_loc() returns a "long long *", that it wrong. It should still error out with 'a_loc' has unknown return type; cast the call to its declared return type and so the user should write: (gdb) p (long long) *(char *)a_loc() and then with this last expression a proper sign extension is applied when char is converted to long long, if char is signed. I.e., in steps: 1: (char *)a_loc() -> call, and get char * return value 2: *(char *)a_loc() -> deref, and get char value 3: (long long) *(char *)a_loc() -> sign extend char value -> long long value > I like this behavior and certainly find it preferable to the behavior > without his patch: > > (gdb) p (char)*a_loc() > Cannot access memory at address 0x4 That's not what I am suggesting. Pedro Alves