From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id YUxgJYTbomoiMj0AWB0awg (envelope-from ) for ; Thu, 10 Sep 2026 12:32:04 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DidowPp0; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 926181E09E; Thu, 10 Sep 2026 12:32:04 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (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 08EA41E033 for ; Thu, 10 Sep 2026 12:32:04 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2FAC448FDC8D for ; Thu, 10 Sep 2026 16:32:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2FAC448FDC8D Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DidowPp0 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 5C6B64BAE7DF for ; Thu, 10 Sep 2026 16:31:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5C6B64BAE7DF Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5C6B64BAE7DF Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789057897; cv=none; b=Ipo6IKQYK7safBQM+UWbyU6SMwPIB/Y1jJf9eNs0g+JV/JPs6m7GNwEhYEcfXAH8NJVzMaBsp7uDiaIxG1/ymi/o/hMatjV84vHN+tKSZ9Pl9M7a3ZXNwgvLICew0iFNWiHkLNCwI1bRlP2YVYzR5ucjKfPeJm0BeLdZVh0jVGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1789057897; c=relaxed/simple; bh=4K5jue3uv6eGhOqFTunFaM9Pe4uYhuH+YL5zFcRiVAw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vt2phzzD6rEJbRHvE5uLEDjZ8jxExD+cM450ie8fCKdTW2+T6hXT45Ffi29GHAZA5knIq7r1LDZJU8tftRiM34f/yXYqajuh8HAFGBgiAkaAX7NiWvDCRCAvC4p5VE7xmyZsUax4kH4W18YhdyEj4pGYssvtdq+qUQYIowkK6cw= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DidowPp0 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5C6B64BAE7DF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1789057896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=aXkYLabn3lQrvZlu0UI3UpiAcdM1T34zk4WFvicsAkI=; b=DidowPp0BBPvwrG5m70HaWk11tYxq2ID06EuSt6dQNvsHc7n280FX6krVuZbSAZFBtZWSS wwkPj0jSdY7SYvwotCeLCwKgcYpTyoZvWACQE/YkCYQyDpUUSWjtpASWyMV8x8aZmJXRlI GhDFdEE0sDuBWQr5JPx73UCHCNv0cJ4= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-SPaS-nqGOvq7eRbOxfW4ZA-1; Thu, 10 Sep 2026 12:31:34 -0400 X-MC-Unique: SPaS-nqGOvq7eRbOxfW4ZA-1 X-Mimecast-MFC-AGG-ID: SPaS-nqGOvq7eRbOxfW4ZA_1789057893 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-49991beee7aso149475e9.2 for ; Thu, 10 Sep 2026 09:31:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1789057893; x=1789662693; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=aXkYLabn3lQrvZlu0UI3UpiAcdM1T34zk4WFvicsAkI=; b=VgjyqsZ0ihlHTBLE4UYCyuqen1qc5fYi6Pd+NjFpucuh38mquZz2HRkeEyCy0SgLFa PiwxmIYtapeKu7hplFtJLIxLhcmDz9KxX0fTU6vqZEGZtiHp9pp3JxhK+BU8/1DjTZLa 3wqpzhwZMzM4cohY20iL0ZMEuwG/vcJIJOj3OoKs56+Ez0geAgTSPlu0fSkUmQv8pHOZ 1uUsgRTmAs5TWIh7lr0xdvic8U+8WrdpIv28e+R9PsX6p/47i/2MYZRuuPwy0fQ+cThs v24dxK73wgv9rcfgvrAL7xJm1w8YZGjg9UqG7kH7uv7cR6egtVV3DLUFujsI2SjW2F9P Eqfw== X-Forwarded-Encrypted: i=1; AKwUvBwpWpDAYyCs55AbhOJE6VgqdYgVHCiU5sd93Z92xjnPfkWXSzSVDKQL8h5by5pY99XRKiKFmU6+UujVyg==@sourceware.org X-Gm-Message-State: AFuF++nWKF+6Ou4TVZkdgqf1GQY9ql+Y6O2oZO6W6xmsUwkoU7PBnAxX r3qN2LduSAygXBg5R/+Jk32lHS7KqIGb+kb5WW1c363lHmnLgGlG5DlGID3bvC4xVUFfsrrRH9l pFYhlxw00K/SsnIZ3zLnn5zgdQHMeSNiA6Hnn8cWSJHwd6XwQd0phHCWUR+1w1gI= X-Gm-Gg: AYBFou1NlZc9swWg65VHYvg6rGLZZxNMe484Zz07N0HAxWSst2ENGv1TZ68UMIL0PSE /Ny9n0t3Frb3BQfUKc+XoxwErmJPOeEPvTg+DnMdlHyetDTDdzmnMWaSBhO54uztoWZ5AfSqO6g TuoKZXGCUkmY1+8rxBfPYVn8B7Bk5BuGMH1hTuvfxBhdSlJPr0pkkL/Wf6qFTKmDLEO2A1nfue1 YkjxBViVoMMtTpoYBt4tKuuQEJvAGRCc/coRlvI+w47duMiJX+hPVgIH3dDlESmrGXT6kHbkJqS HR7y3mk0/RLNXB+cwLO7tZ0x/4NTRJN84l6NheBzw2yieBb6WP4QsvpAxHgkpjxyylhhXOi9s5M dqivCDX6TGfIItio0 X-Received: by 2002:a05:600c:638d:b0:49d:2450:68ac with SMTP id 5b1f17b1804b1-49d258dfc8bmr186167005e9.5.1789057893241; Thu, 10 Sep 2026 09:31:33 -0700 (PDT) X-Received: by 2002:a05:600c:638d:b0:49d:2450:68ac with SMTP id 5b1f17b1804b1-49d258dfc8bmr186165805e9.5.1789057892724; Thu, 10 Sep 2026 09:31:32 -0700 (PDT) Received: from localhost (59.6.93.209.dyn.plus.net. [209.93.6.59]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49db038401fsm58251025e9.13.2026.09.10.09.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2026 09:31:31 -0700 (PDT) From: Andrew Burgess To: Matthieu Longo , gdb-patches@sourceware.org Cc: Simon Marchi , Thiago Jung Bauermann , Luis Machado , Luis Machado , Christina Joos , Kevin Buettner , Matthieu Longo Subject: Re: [PATCH v2 4/6] gdb/linux-tdep: migrate linux_info_proc to file_reader_t In-Reply-To: <20260825100912.514232-5-matthieu.longo@arm.com> References: <20260825100912.514232-1-matthieu.longo@arm.com> <20260825100912.514232-5-matthieu.longo@arm.com> Date: Thu, 10 Sep 2026 17:31:29 +0100 Message-ID: <87a4ppdq5a.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 0GhHLnno2GqQJWYrMViMfV6iLX20XJ6Jz5BU4HbSlf0_1789057893 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 Matthieu Longo writes: > The patch migrates the code of linux_info_proc to use file_reader_t to > read the procfs files. > The availability of array_views allows to also simplify the logic in > several places, where null-terminating characters are replaced by spaces, > or where the file content is iterated line by line. > In the last case, a new helper function, extract_string_view_from_buffer, > encapsulates the logic for such iterations where string are separated by > tokens. > > Reviewed-By: Thiago Jung Bauermann > --- > gdb/linux-tdep.c | 135 +++++++++++++++++++++++++++++------------------ > 1 file changed, 84 insertions(+), 51 deletions(-) > > diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c > index 84614bc91a0..e2c5b2d8815 100644 > --- a/gdb/linux-tdep.c > +++ b/gdb/linux-tdep.c > @@ -866,6 +866,39 @@ dump_note_entry_p (filter_flags filterflags, const smaps_data &map) > return true; > } > > +/* Extract a string view from BUFFER starting at START and ending at the > + first occurrence of SEPARATOR. > + Return the extracted view together with an iterator to the beginning of > + the next entry, skipping any successive separators. If no separator > + is found, return the remainder of BUFFER starting at START. If there is > + no following entry, the returned iterator is BUFFER.end (). */ > + > +static std::pair, gdb::array_view::iterator> > +extract_string_view_from_buffer (gdb::array_view &buffer, The gdbsupport/array-view.h header says that gdb::array_view objects should usually be passed by value. Is there a reason why this needs to be passed by reference here? > @@ -914,25 +947,23 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, > > if (cmdline_f) > { > - xsnprintf (filename, sizeof filename, "/proc/%ld/cmdline", ptid.lwp ()); > - gdb_byte *buffer; > - LONGEST len = target_fileio_read_alloc (nullptr, filename, &buffer); > - > - if (len > 0) > + file_reader_t cmdline_freader > + (string_printf ("/proc/%ld/cmdline", ptid.lwp ())); > + if (cmdline_freader) > { > - gdb::unique_xmalloc_ptr cmdline ((char *) buffer); > - ssize_t pos; > - > - for (pos = 0; pos < len - 1; pos++) > - { > - if (buffer[pos] == '\0') > - buffer[pos] = ' '; > - } > - buffer[len - 1] = '\0'; > - gdb_printf ("cmdline = '%s'\n", buffer); > + /* /proc//cmdline stores the command-line arguments as a > + sequence of NUL-separated strings. */ > + gdb::array_view cmdline = cmdline_freader.cast_view (); > + gdb_assert (cmdline[cmdline.size () - 1] == '\0'); We shouldn't assert on data from an outside source. This should be either an error, or a warning if GDB is able to handle this and push on. > @@ -997,12 +1025,16 @@ linux_info_proc (struct gdbarch *gdbarch, const char *args, > current_uiout->table_header (0, ui_left, "objfile", "File"); > current_uiout->table_body (); > > - char *saveptr; > - for (const char *line = strtok_r (map.get (), "\n", &saveptr); > - line != nullptr; > - line = strtok_r (nullptr, "\n", &saveptr)) > + auto content = map_freader.view (); > + for (auto it = content.begin (); it != content.end ();) > { > - struct mapping m = read_mapping (line); > + auto [line, next_line_begin] > + = extract_string_view_from_buffer (content, it, '\n'); > + it = next_line_begin; > + > + /* read_mapping() expects a null-terminated string. */ > + *std::prev (it) = '\0'; If the buffer contains two consecutive '\n' characters then this will overwrite the wrong one I think, e.g. "abc\n\ndef\n". IT will point at the 'd', and this will overwrite the second '\n', not the first, which I think is what you want. Also, extract_string_view_from_buffer handles a missing final '\n', so if the buffer is "abc\bdef" then IT will point to the character after 'f', and the above will overwrite 'f'. Given that extract_string_view_from_buffer handles these cases, I think this code should also handle them, or throw an error if we see data in a form that you don't expect. Thanks, Andrew