From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id OIsWD40fAGmH0QwAWB0awg (envelope-from ) for ; Mon, 27 Oct 2025 21:42:37 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=imcan.dev header.i=@imcan.dev header.a=rsa-sha256 header.s=google header.b=Br9GJP1E; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2F9E41E0BC; Mon, 27 Oct 2025 21:42:37 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 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 420281E057 for ; Mon, 27 Oct 2025 21:42:36 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B19C63858CB6 for ; Tue, 28 Oct 2025 01:42:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B19C63858CB6 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=imcan.dev header.i=@imcan.dev header.a=rsa-sha256 header.s=google header.b=Br9GJP1E Received: from mail-yx1-xb135.google.com (mail-yx1-xb135.google.com [IPv6:2607:f8b0:4864:20::b135]) by sourceware.org (Postfix) with ESMTPS id 1335D3858C41 for ; Tue, 28 Oct 2025 01:03:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1335D3858C41 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=imcan.dev Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=imcan.dev ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1335D3858C41 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::b135 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761613389; cv=none; b=tiFV2asAUDXcy9kI5jl1eIvuLK3hb49Mey2NMyknhQN1lb7LHBuUwnZx+KFvK0bk+U8pA1tn/JWl2t3dDPxY96Cwhd3rXkKdcAlBAjz5i5+/nb8i/sVJg407Fz3C4p/KmO9sYV4CDrPkrbs4ezEE9C40XB2xkFz3/1oTEiotnLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1761613389; c=relaxed/simple; bh=bs0B/WyshHfcUjVsXOg2vtjrytSIQuMjsfWZUq9pQxQ=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=xJPuRvNif3OmAcsfwP+odmCKO6Fo5XC4Q0OrSqrhNvZqKwnzxFEfJ2KzQSHBhzu0qrm+iOFJU+VB/53gL644xnHFIulWyWSg80uulujWxeF/S6gP495j00bCOkhkKoqR58cc5DG4CjNdRJ54lhJpO36VFikjbeGGdLUgrMuKPWY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1335D3858C41 Received: by mail-yx1-xb135.google.com with SMTP id 956f58d0204a3-63e393c4a8aso6396554d50.2 for ; Mon, 27 Oct 2025 18:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=imcan.dev; s=google; t=1761613383; x=1762218183; darn=sourceware.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=xvPY2xL5HWBM98RxvJCJU3PS2lZe2D9U16NJXRfBhqY=; b=Br9GJP1EspufEdNRHT2fWl9Swyl4dIIVgUoxEzyF5IxoO7pGQJ8q83xgD17Z2fXWsU 788jaX5sHe81aiin2t8vsbYmnzcxcoR4Ok8knZagfnt+zgGmTx6QNys/JOUvRqPdypAd WTV0yRfNQ3YMlLO2kONn4F1sT/JJPsjrGL0BjzeSwXdsFoYBE1F6NN5mGVNcB9/+tf78 uDKDGlj67ZniFw1CnZTFpEEf+iwJCeA9Ee0JbQAQa3n1e/9TW++nStZuY6n7t0kYLfsw eBscRXbfCEpwhcLLUVsBxiFuXj2ao05BOTqYZyQYPejQW+fakI9jvsf3CSis1JGr7hHp 15ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761613383; x=1762218183; 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=xvPY2xL5HWBM98RxvJCJU3PS2lZe2D9U16NJXRfBhqY=; b=lzT631n7B/fgkCZprDaDbz/GhzLs1bnz20MZ0xmsVqZ818zFPYyBNAhenS8RVI+SKZ hcGOSqP57Y9KtYxNGvSSmFULx/8mP/xdrwbMDuXqt6KVt6bXlYcU1JwkhJor+i9y5MiZ DtJlVZBtywiCn12od2kfc1J/MhlnVymmlGF/LHKtaD6fxF/VUFdl2uQZRCAlE2T+TL5h HrUGedW5ydPiXTWRXGJwOA3gKr4ZpPCbpSn22RNnqvukhV9PHhOEl2kDMdE+vfzeCvMI W9VdyFLbiidRkOcWe3/jYNTTN8oRyhZUBST5ZZzi3mliBl91C8akpy++qIMWlQeggNmZ ThVA== X-Gm-Message-State: AOJu0YwdmrkbEgqKXKscN/bWmA4tQourxEzlCP8SqrOyTIFax6Mzs4A5 t8XgucH/7a2c+tVh7oZhNYA8WTK8ZEE/qCyBCmWRQ7HWC3LhfuzzA1XL8ZFOuluzPzfHVDtaoy8 ffqhS2rBb3dgKP/fMv9py+qLgpjvxJf2zXMuXCoULKeamSIjGnF8g1Kl26w== X-Gm-Gg: ASbGncshSQbYsASOorqJRuPuiFzUrCVyonPKXHCK+kEOoMTw59LesVgwxj7WhjJYZh0 s6brYxJSu3KEfwLohC99IqgnzIyGBRBdBgkK8GLvkizMxdt0Insq8StUQz8hyaElhrOBdp6TmRz eN1+p1tTJRoFCet/WuMqaod2MWjnjXLXSipPEpDADqRqHmoxYb8DDdnlJo8EeHaCPGp6bm9ixCq zew3j7CbiJ5A6kawo0YZdcCaW2jVOnvmqfOauYWeqhaDBUmcM1KkkYOm1KuqCo= X-Google-Smtp-Source: AGHT+IFtIhhCYHQxQ7K+dNPUG5yQXDR7uooP6fFopcy2y4A4gb1FzjIn7vqAO5q3XKMWsQLcFWiNgRvgDEQp6uWaup4= X-Received: by 2002:a53:edc9:0:b0:63e:29ad:ad8 with SMTP id 956f58d0204a3-63f6b9e2e72mr1190433d50.25.1761613383298; Mon, 27 Oct 2025 18:03:03 -0700 (PDT) MIME-Version: 1.0 References: <20251023214230.13646-1-canacar@imcan.dev> <878qh0jtzj.fsf@tromey.com> In-Reply-To: <878qh0jtzj.fsf@tromey.com> From: Can Acar Date: Mon, 27 Oct 2025 18:02:52 -0700 X-Gm-Features: AWmQ_bneP9OuKL2kJE0xAYwj-e69WpPvJeqIGSvsCyDh5wPZwhME793dDY0hiNQ Message-ID: Subject: Re: [PATCH] Fix: Sign extensions for DW_FORM_addrx were never considered To: Tom Tromey Cc: gdb-patches@sourceware.org Content-Type: multipart/alternative; boundary="000000000000f1895406422d93bc" 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 --000000000000f1895406422d93bc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable CC'ing gdb-patches@sourceware.org as well this time. Sorry for the multiple emails. On Fri, Oct 24, 2025 at 6:43=E2=80=AFAM Tom Tromey wrote: > >>>>> "Can" =3D=3D Can Acar writes: > > Can> DW_FORM_addr is converted (sign-extended) to a signed value when > Can> the dwarf size is less than the size of unrelocated_addr, if the > Can> target architecture "naturally" sign extends an address (bfd.c). > > Thanks for the patch. > > Can> static unrelocated_addr > Can> read_addr_index_1 (dwarf2_per_objfile *per_objfile, unsigned int > addr_index, > Can> - std::optional addr_base, int addr_size) > Can> + std::optional addr_base, unit_head *cu_heade= r) > > I think it'd be better to merge read_addr_index_1 and read_addr_index, > i.e. have it be: > > static unrelocated_addr > read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index) > ... > > Can> + return cu_header->read_address(abfd, info_ptr, &ignore_bytes_read= ); > > gdb puts a space before "(" > > Can> else > Can> { > Can> cutu_reader reader (*per_cu, *per_objfile, nullptr, nullptr, > false, > Can> language_minimal); > Can> addr_base =3D reader.cu ()->addr_base; > Can> - addr_size =3D reader.cu ()->header.addr_size; > Can> + cu_header =3D &reader.cu ()->header; > > I'm not sure it is safe to refer to hold this pointer after cutu_reader > is destroyed. > > Instead this could be refactored slightly to: > > std::optional reader; > if () > ... > else > { > reader.emplace (...) > cu =3D reader->cu (); > } > > thanks, > Tom > I've implemented your suggestions, and will be sending in a new patch version in a moment. Best regards, Can --000000000000f1895406422d93bc Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
CC'ing gdb-patches@sourceware.org as well this time. Sorry for the multi= ple emails.

On Fri, Oct 24, 2= 025 at 6:43=E2=80=AFAM Tom Tromey <tom@tromey.com> wrote:
>>>>> "Can" =3D=3D Can Acar &= lt;canacar@imcan.dev= > writes:

Can> DW_FORM_addr is converted (sign-extended) t= o a signed value when
Can> the dwarf size is less than the size of un= relocated_addr, if the
Can> target architecture "naturally"= sign extends an address (bfd.c).

Thanks for the patch.

Can&g= t;=C2=A0 static unrelocated_addr
Can>=C2=A0 read_addr_index_1 (dwarf2= _per_objfile *per_objfile, unsigned int addr_index,
Can> -=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0std::optional<ULONGEST> addr_ba= se, int addr_size)
Can> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0std::optional<ULONGEST> addr_base, unit_head *cu_header)
I think it'd be better to merge read_addr_index_1 and read_addr_index,=
i.e. have it be:

static unrelocated_addr
read_addr_index (str= uct dwarf2_cu *cu, unsigned int addr_index)
...

Can> +=C2=A0 r= eturn cu_header->read_address(abfd, info_ptr, &ignore_bytes_read);
gdb puts a space before "("

Can>=C2=A0 =C2=A0 els= e
Can>=C2=A0 =C2=A0 =C2=A0 {
Can>=C2=A0 =C2=A0 =C2=A0 =C2=A0 cu= tu_reader reader (*per_cu, *per_objfile, nullptr, nullptr, false,
Can>= ;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 language_minimal);
Can>=C2=A0 =C2=A0 =C2=A0 =C2=A0 addr_base =3D<= span class=3D"gmail-Apple-converted-space">=C2=A0reader.cu=C2=A0()->addr_base;
Can> -=C2= =A0 =C2=A0 =C2=A0 addr_size =3D= =C2=A0reader.cu=C2=A0(= )->header.addr_size;
Can> +=C2=A0 =C2=A0 =C2=A0 cu_header =3D &= ;reader.c= u=C2=A0()->header= ;

I'm not sure it is safe to refer to hold this pointer after cu= tu_reader
is destroyed.

Instead this could be refactored slightly= to:

std::optional<cutu_reader> reader;
if ()
...
els= e
=C2=A0 {
=C2=A0 =C2=A0 reader.emplace (...)
=C2=A0 =C2=A0 cu =3D= reader->cu ();
=C2=A0 }

thanks,
Tom
<= br>
I've implemented your suggestions, and will b= e sending in a new patch version=C2=A0in a moment.

Best regards,
Can
<= /div>
--000000000000f1895406422d93bc--