From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id mFiDE6oAN2j0yzcAWB0awg (envelope-from ) for ; Wed, 28 May 2025 08:25:14 -0400 Received: by simark.ca (Postfix, from userid 112) id 4AC691E11C; Wed, 28 May 2025 08:25:14 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-9.0 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE 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 479CE1E102 for ; Wed, 28 May 2025 08:25:13 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E8C35385AC3F for ; Wed, 28 May 2025 12:25:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8C35385AC3F Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by sourceware.org (Postfix) with ESMTPS id F33ED3857BB0 for ; Wed, 28 May 2025 12:24:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F33ED3857BB0 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 F33ED3857BB0 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748435078; cv=none; b=Ryk5JMW9oElPFA6Z388ls/UU2UnAoVBjkLkgoBKg7rc+tBhXMl5yZS7Uydp2dY2cSoLaFrfshahT5EKBiiftLJZzqS70VQDEAZfYes4BMuxpwCjb1BlqZzlI6rIysfxW3OuIbu0aiNBZrJtn6wb1loNG3jxxkpMA6qbLJ1z4Qno= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748435078; c=relaxed/simple; bh=bqejJYAbxg3eUlF3b4V8ox1FQW60iZVQMNpA1Zh3dbs=; h=Message-ID:Date:MIME-Version:Subject:To:From; b=auqEehPg2VcVs8gMXXrUCHhqP7spdimnvVeGjldRviCYJUqcdldlyBO3UgPVJY8eduDFfhIw1aUXsb1BMaucf1ngrayb3FFIem8gDQottDLlt7mTFgsO05VZ4+5SIyJonqh2+LgNxm0JfGT7D+UuW3dZ/Ti6CxCD0Sc+rk2FLu4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F33ED3857BB0 Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-3a37d24e607so2161411f8f.1 for ; Wed, 28 May 2025 05:24:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748435077; x=1749039877; 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=PBNjnBSPFZSXakewo3445oZqqKbD9qRKLpj0DtKc6hY=; b=QX9kveMxnlWDufKj0f17i3JHgh/KenhAYdHDJPIiE66QQkDkWWn5rasYYtadyXsIe2 b6P0X6Ly05mChhZWYTGWW4kgCNt7mdMdGhqlKO/WEWlf7NQhc9hB0MB1XEAcZ3X765UC 1gcGNJpno5H+VaoAOYoHS5fmPwzv2ArmtKw/HSbxUo9muRS3VSfxrnDl9nHuTHU5oifd aCWaAyDp/rbOa7XsNhBJ4BU0xPRRXfq6darZAkptsHhheLYSQq08bX5qoy4Xculzlh01 nxEa9qE6rn1TT0saT33fFiVAzCzRUYMfykwgLsuCh4s2kSSxldyfTsKw57e5ROMRNKi7 cA9A== X-Gm-Message-State: AOJu0Yzdla8URLXnMDUq70saZ1kK323vIn2gV8td5wOmuNiufy9a6QB3 LFW1PhmK5qUy2hqpi/rKBcws7NzHRbSIyQGcdnKpTAeNggxg8pJwwCLROLAYBAXl X-Gm-Gg: ASbGnct0WfHf3RrY5+hl+A/Y5M7TxPB8mmWpVu1UPWFPOWfh8hWlDRRbZE1Z5lZwxdS QpRXJ5DSxm5O7QZAyvK+JWgMNWUB56++sQuH/LyitrqLlMhA/eXw3oLLHxSEfxpwM4stqvwQiNv N+XOEBiR/MSaIwUJL1eZXLXVrIihws+UXFDw6ouRLgUT8SEzLA8vu1JoaGhvM1ZmaqbAqopDsZG NGon0XRMnteqcSXIS8DSEpR9OLkjFk/69QoAc3QCuIzKCbwdaEX+HaJSz5tfRBWFgtZtkzejjyQ d19AmaDwPSyA7Kc0pLWmKOLcnJ7c1kXiRaQHX5RLd3A3a58GgwNZap+aRoGuTwp7XPvtzmuv0GM hVK1gmMBnUDXQtEF0SS4= X-Google-Smtp-Source: AGHT+IFK6OpmemKA491yfGw+9M/MPh8j0vMLEgw2Yp6j+BqS+xqPOsub/byThkaEyHoURGy+wtRTvw== X-Received: by 2002:a5d:5f87:0:b0:3a4:dc32:6cbb with SMTP id ffacd0b85a97d-3a4dc326dadmr8067293f8f.31.1748435076523; Wed, 28 May 2025 05:24:36 -0700 (PDT) Received: from ?IPV6:2001:8a0:facf:2b00:92c3:77a6:8c07:8a4c? ([2001:8a0:facf:2b00:92c3:77a6:8c07:8a4c]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4eac8a7f9sm1322888f8f.49.2025.05.28.05.24.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 May 2025 05:24:35 -0700 (PDT) Message-ID: <40009cde-bf88-45fe-9376-ff53c4b18a65@palves.net> Date: Wed, 28 May 2025 13:24:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdbserver: Update require_int function to parse offset for pread packet To: Kirill Radkin Cc: gdb-patches@sourceware.org References: <20250423161548.03f50c47@f41-zbm-amd> <20250528113513.3116529-1-kirill.radkin@syntacore.com> From: Pedro Alves Content-Language: en-US In-Reply-To: <20250528113513.3116529-1-kirill.radkin@syntacore.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit 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 2025-05-28 12:35, Kirill Radkin wrote: > Currently gdbserver uses require_int() function to parse the requested offset > (in vFile::pread packet and the like). This function allows integers up to > 0x7fffffff (to fit in 32-bit int), however the offset (for pread system call) > has an off_t type which can be larger than 32-bit. > > This patch allows require_int() function to parse offset up to the maximum > value implied by the off_t type. > --- > gdb/testsuite/gdb.server/pread-offset-size.S | 26 +++++++++++ > .../gdb.server/pread-offset-size.exp | 45 +++++++++++++++++++ > gdbserver/hostio.cc | 18 +++++--- > 3 files changed, 84 insertions(+), 5 deletions(-) > create mode 100644 gdb/testsuite/gdb.server/pread-offset-size.S > create mode 100644 gdb/testsuite/gdb.server/pread-offset-size.exp > > diff --git a/gdb/testsuite/gdb.server/pread-offset-size.S b/gdb/testsuite/gdb.server/pread-offset-size.S > new file mode 100644 > index 00000000000..f43e059653d > --- /dev/null > +++ b/gdb/testsuite/gdb.server/pread-offset-size.S > @@ -0,0 +1,26 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2025 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + Please add a short comment stating what this is trying to do. > + .text > + .globl _start > +_start: > + .skip 3742415472 Is this particular number significant? > + ret > + .globl f > + .type f, @function > +f: > + ret > diff --git a/gdb/testsuite/gdb.server/pread-offset-size.exp b/gdb/testsuite/gdb.server/pread-offset-size.exp > new file mode 100644 > index 00000000000..5faf2162ef0 > --- /dev/null > +++ b/gdb/testsuite/gdb.server/pread-offset-size.exp > @@ -0,0 +1,45 @@ > +# Copyright (C) 2025 Free Software Foundation, Inc. > +# > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + This needs a short blurb here stating what the testcase is testing. > +load_lib gdbserver-support.exp > + > +require allow_gdbserver_tests > + > +standard_testfile .S > + > +if { [prepare_for_testing ${testfile}.exp $testfile \ > + $srcfile {debug additional_flags=-nostdlib} ] } { > + return -1 > +} > + > +gdb_exit > +gdb_start clean_restart > + > +gdb_test_no_output "set remote exec-file $binfile" \ > +"set remote exec-file" Something's off with the indentation of the second line. As in, it's not indented. :-) Indent it by four spaces, like: gdb_test_no_output "set remote exec-file $binfile" \ "set remote exec-file" > + > +# Make sure we're disconnected, in case we're testing with an > +# extended-remote board, therefore already connected. > +gdb_test "disconnect" ".*" > + > +set res [gdbserver_spawn ""] > +set gdbserver_protocol [lindex $res 0] > +set gdbserver_gdbport [lindex $res 1] > + > +gdb_test "target $gdbserver_protocol $gdbserver_gdbport" \ > +"Remote debugging using .*" \ > +"target $gdbserver_protocol $gdbserver_gdbport" Ditto. But also, you'll notice that other tests doing something similar avoid putting the port number in gdb.sum, so that comparing test results is a bit more stable. So: gdb_test "target $gdbserver_protocol $gdbserver_gdbport" \ "Remote debugging using .*" \ "target $gdbserver_protocol" > + > +gdb_test "break f" "Breakpoint 1.*" Is this where the problem would manifest? Some comments would help. > diff --git a/gdbserver/hostio.cc b/gdbserver/hostio.cc > index 17b6179d8ca..e88f8d79728 100644 > --- a/gdbserver/hostio.cc > +++ b/gdbserver/hostio.cc > @@ -89,12 +89,18 @@ require_filename (char **pp, char *filename) > return 0; > } > > +template > static int > -require_int (char **pp, int *value) > +require_int (char **pp, T *value) > { > + constexpr bool is_signed = std::is_signed::value; > + > char *p; > int count, firstdigit; > > + /* Max count of hexadecimal digits in off_t (1 hex digit is 4 bits). */ "T", not "off_t". > + int max_count = sizeof(T) * CHAR_BIT / 4; Space before parens. > + > p = *pp; > *value = 0; > count = 0; > @@ -111,9 +117,9 @@ require_int (char **pp, int *value) > firstdigit = nib; > > /* Don't allow overflow. */ > - if (count >= 8 || (count == 7 && firstdigit >= 0x8)) > + if (count >= max_count > + || (is_signed && count == (max_count - 1) && firstdigit >= 0x8)) > return -1; > - Keep the empty line, so the comment above is clear to refer to the whole block up to the empty line. > *value = *value * 16 + nib; > p++; > count++; > @@ -343,7 +349,8 @@ handle_open (char *own_buf) > static void > handle_pread (char *own_buf, int *new_packet_len) > { > - int fd, ret, len, offset, bytes_sent; > + int fd, ret, len, bytes_sent; > + off_t offset; > char *p, *data; > static int max_reply_size = -1; > > @@ -410,7 +417,8 @@ handle_pread (char *own_buf, int *new_packet_len) > static void > handle_pwrite (char *own_buf, int packet_len) > { > - int fd, ret, len, offset; > + int fd, ret, len; > + off_t offset; > char *p, *data; > > p = own_buf + strlen ("vFile:pwrite:");