From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id QXLOJDb+Pmj9ej8AWB0awg (envelope-from ) for ; Tue, 03 Jun 2025 09:52:54 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=syntacore.com header.i=@syntacore.com header.a=rsa-sha256 header.s=m header.b=Ystpz5Ub; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 7B8811E102; Tue, 3 Jun 2025 09:52:54 -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.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 861991E0C2 for ; Tue, 3 Jun 2025 09:52:53 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 030C63858435 for ; Tue, 3 Jun 2025 13:52:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 030C63858435 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=syntacore.com header.i=@syntacore.com header.a=rsa-sha256 header.s=m header.b=Ystpz5Ub Received: from m.syntacore.com (m.syntacore.com [178.249.69.228]) by sourceware.org (Postfix) with ESMTPS id 5A7853858401 for ; Tue, 3 Jun 2025 13:52:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5A7853858401 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=syntacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=syntacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5A7853858401 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=178.249.69.228 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748958731; cv=none; b=N2k8d2GKyEZ0Npg0LufxVTBK2ioY9xcG6EHTOPgho+8wHz9nNAwwA1WbU9YZiqjiaOqNticBJ9uAKORkw31UPHx0gdGUeppTfDW0OU/ZTT9DfccX6BvVgdImH/DR7zIPR36u9l0bODtV0oocm2upZ/AeP9gHrzdpWpMcn48bEck= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1748958731; c=relaxed/simple; bh=ByGObhwI/vxiDuokqikI1tyA96hYlvPsPqfO6TzLcz8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=V3OSQf0mFWG6Exl30goxfIoV2sIsvJ85IytQgA5ynsav8mUyDhgF1S/j7xigRMdzm7qQX8NZmBfw5jlrrJhrGRzFD1XXe9c/++sEGhr72iw2WIUhEPNhHb6VgVZRM/OAycdqoB/xgrWzC7PJaLbzNXC3lxyvaeFXtlNGaL08OMs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5A7853858401 Received: from MRN-SC-KSMG-01.corp.syntacore.com (localhost [127.0.0.1]) by m.syntacore.com (Postfix) with ESMTP id E5BE71A0002; Tue, 3 Jun 2025 13:52:09 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 m.syntacore.com E5BE71A0002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; s=m; t=1748958729; bh=lJNprjkgMmDHks1bgPJvi0haot3XT0nFY409/CeO2v0=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=Ystpz5UbjY6jI+v0REk6g0OQVdRDeU6YZqCRZJVG78xAiJzEofcNJgafiPOeF7s42 Ft+Veu+afA3yFxEt/yAuJ4CbzTn4foxlC7Y06uAGx6Jeqtb17eEv3TAz/cNFSEL+31 1M4qRUq6NLssWUX8f1EviQXoOYeUya5RDGnKARoyH7eHiDPzeJOV/Q7do2ujvQC8Tq ERTrmNj2AepIoDceXKI5CG83h/deiq94N4kWeIh3LmbHsE5wpKbllAfMI/lRqUiaWI BgpOdd4c+YwIa0nMrzSCV2ZVOqNOdXpELYaX+WcBl8YzsSjbrYDijQ43yq69c9ZDeP oovlX92slHABA== Received: from S-SC-EXCH-01.corp.syntacore.com (exchange.syntacore.com [10.76.202.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by m.syntacore.com (Postfix) with ESMTPS; Tue, 3 Jun 2025 13:52:09 +0000 (UTC) Received: from ouran.high.school.host.club (172.17.15.248) by S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Tue, 3 Jun 2025 16:51:29 +0300 From: Kirill Radkin To: CC: , Subject: [PATCH] gdbserver: Update require_int function to parse offset for pread packet Date: Tue, 3 Jun 2025 16:48:23 +0300 Message-ID: <20250603134822.327506-2-kirill.radkin@syntacore.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <40009cde-bf88-45fe-9376-ff53c4b18a65@palves.net> References: <40009cde-bf88-45fe-9376-ff53c4b18a65@palves.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [172.17.15.248] X-ClientProxiedBy: S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) To S-SC-EXCH-01.corp.syntacore.com (10.76.202.20) X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 2.1.1.8310, bases: 2025/06/03 09:30:00 #27534232 X-KSMG-AntiVirus-Status: NotDetected, skipped X-KSMG-LinksScanning: NotDetected, bases: 2025/06/03 12:55:00 X-KSMG-Message-Action: skipped X-KSMG-Rule-ID: 5 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 I've addressed all review comments. Also, additional information about issue was added to commit message. --- Recently I have encountered an issue with gdbserver not being able to send debug information from large \ files (> 2Gb). I found that this issue is connected with parsing offsets (integer) from vFile::pread \ packets. There is already a patch (https://sourceware.org/bugzilla/show_bug.cgi?id=23198) that allows to \ parse integers up to 0x7fffffff (32-bit integer), but it doesn't fix the problem at all, because offsets \ can have a off_t type which can be larger than 32-bit integer (it depends on system). This patch allows require_int() function to parse offset up to the maximum value implied by the off_t \ type. 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 | 29 +++++++++++ .../gdb.server/pread-offset-size.exp | 50 +++++++++++++++++++ gdbserver/hostio.cc | 17 +++++-- 3 files changed, 92 insertions(+), 4 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..63b2faa213d --- /dev/null +++ b/gdb/testsuite/gdb.server/pread-offset-size.S @@ -0,0 +1,29 @@ +/* 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 . */ + +/* Here we are trying to create a large binary (> 2 GB), + 3742415472 bytes is about 3,5 gigabytes. */ + + .text + .globl _start +_start: + .skip 3742415472 + 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..e224e971ad5 --- /dev/null +++ b/gdb/testsuite/gdb.server/pread-offset-size.exp @@ -0,0 +1,50 @@ +# 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 . +# +# Testing fix of a problem with gdbserver not being able to send +# debug information from large files (> 2GB) + +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 +} + +clean_restart + +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" + +# If load of a large binary was successful, +# we should be able to place a break on f + +gdb_test "break f" "Breakpoint 1.*" diff --git a/gdbserver/hostio.cc b/gdbserver/hostio.cc index 17b6179d8ca..4e77253750a 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 T (1 hex digit is 4 bits). */ + int max_count = sizeof (T) * CHAR_BIT / 4; + p = *pp; *value = 0; count = 0; @@ -111,7 +117,8 @@ 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; *value = *value * 16 + nib; @@ -343,7 +350,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 +418,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:"); -- 2.43.0