From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ZDJwN1LUBmYMChsAWB0awg (envelope-from ) for ; Fri, 29 Mar 2024 10:46:42 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=obs-cr.20230601.gappssmtp.com header.i=@obs-cr.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=SYiGOyJP; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id D20D71E0C0; Fri, 29 Mar 2024 10:46:42 -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 7D52D1E030 for ; Fri, 29 Mar 2024 10:46:40 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EC6843858403 for ; Fri, 29 Mar 2024 14:46:39 +0000 (GMT) Received: from mail-vk1-xa29.google.com (mail-vk1-xa29.google.com [IPv6:2607:f8b0:4864:20::a29]) by sourceware.org (Postfix) with ESMTPS id B33D03858D1E for ; Fri, 29 Mar 2024 14:46:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B33D03858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=obs.cr Authentication-Results: sourceware.org; spf=none smtp.mailfrom=obs.cr ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B33D03858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::a29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711723580; cv=none; b=J+aIxgUCmRBauMoK6gaYDQw6o2EGxI41L7lNqpFuP5lO0u2uF6KEdLG+Q2SFX0MCkhzKl0hdpxUxMlpdiKrxgJ334ktM80uC3VjR5CfmjnBza9TEd5psDdHwGvQ98vPk3Zhcdc7orrQYQ7aoO+P8EjNBIeK/IneMjt2LdwTActU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711723580; c=relaxed/simple; bh=ntNquWoGXVFOKOxnccUyJ6IQdD7mB8qulKvJj5BUth8=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=j/lJpMaFc+tMSs3FvigyBFq5KN7U8SXqGo6RgowJ9vtb89IxZpRQDsfFja80tNDZviZnBR3S9MQ4AV0WmrS0rDVGGC0aPmDx3quIb7hXxGPPH0rXkMAqkvOFxbUx0iosTdkypZT1adNRXrHPeddZCze9pvKCxYMrpficiMey1Mw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-vk1-xa29.google.com with SMTP id 71dfb90a1353d-4d43c633fecso918290e0c.3 for ; Fri, 29 Mar 2024 07:46:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=obs-cr.20230601.gappssmtp.com; s=20230601; t=1711723577; x=1712328377; darn=sourceware.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=juo6NPc7RaUGEtwghCltCfdbIqPe6jGD/lVLEXfuTPY=; b=SYiGOyJP1ACYYr+0UEhiDGXf7Sz6oYalwXo/vbu5eXgbwCYDdJ95NVmyfk0skq+a3G f4CdTe5pU+eRB7jtlxlibKy3apcArpyWjwnEsGXDA+nd2YiyZOOLpFKSNjvmh11c6KJF hgDCiZZhMbq0peDsrfdKKDjF2uksagToc84fSCARoleLkcLRgXGKrTzyKa3ambSmUCUi Z90SBWkNonPHK6UZ7TwFnniB41F6zOfMjhkm5X2naUse67mwqSOvb04QbKLuKPH9/PAc 9gBFEEF885y3V7v6gKkfgNF0w02R4bTFngr3HKobMsHzJYqOROGfaIjVzgPruBaNRk/T pmTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711723577; x=1712328377; h=content-transfer-encoding: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=juo6NPc7RaUGEtwghCltCfdbIqPe6jGD/lVLEXfuTPY=; b=Y+u+8mGQsPEgCFGoUcNdhCkHKKln0mSQgIH0tYBd+hFI+yvmFwiyAul3nxjtnKJe7U NpbBKaIE+YtUbSM5JJA2pZS7vutZIXxunB1dGEvnLUkXa6SMPY03ba/HwnGMzln5+cR9 88qSgN8uo7EmZFtdWZpNHGGuZcBvgNBr9+g77blfBIgYj7MFXe+EAvfOczUiT9SaDzO7 8tlKfFJGXy29gOoRE9cIfrbbmkdowIQiiV9X67RcwSDYL3izcgtBUpt0lyL4NO6z3rD2 yMEsbYLnPQ4F7J24IoRKzLxHOoO0TuLRaRe7rHivGzioqWBEEt3kyQ2ZelaRWVz6AJaN 88WQ== X-Gm-Message-State: AOJu0YzZeUbVeLZmo+tyfK/o2zm8cbiwzP8Nf5UZb/WQlc0o2TCuCN8X +sCqHBsCNbPfhicVvMILZx3eLAMTpsTMBKlk8oinUe2Bq0GHjUjbPFq9OHRzUIACgNgcxpgzd/A MqANCdV9qGq17wxjM0w0xF324qMX/S3QZf7R3+e3Egu2TzvUp X-Google-Smtp-Source: AGHT+IH13WdAfyVEWKXI+njBPGMsmFua/OfiYELiUzkyNzEi5KeBoPHHLHhqeMiUF3+wYUXlGn1mV1m0fGKFfigwZSE= X-Received: by 2002:ac5:c890:0:b0:4d4:5480:1bc2 with SMTP id n16-20020ac5c890000000b004d454801bc2mr2388878vkl.14.1711723577530; Fri, 29 Mar 2024 07:46:17 -0700 (PDT) MIME-Version: 1.0 References: <20240324011828.145140-1-hawkinsw@obs.cr> <20240325140103.157217-1-hawkinsw@obs.cr> In-Reply-To: <20240325140103.157217-1-hawkinsw@obs.cr> From: Will Hawkins Date: Fri, 29 Mar 2024 10:46:06 -0400 Message-ID: Subject: Re: [PATCH v2] Make source.c:search_command_helper use source cache To: gdb-patches@sourceware.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham 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 I am sorry for the PING. I know that I am supposed to wait for 2 weeks before pinging (according to the Contributing documentation) but I am nervous that I have not followed the proper procedures for sending the patch. Granting the premise that the patch is something that is useful, I am sure that you will have feedback. I am more than willing to make any changes to get it into shape. As I said before, thank you for the work that you all do maintaining such an incredible piece of software. Will On Mon, Mar 25, 2024 at 10:01=E2=80=AFAM Will Hawkins wro= te: > > The current implementation of search_command_helper accesses the line > offsets of the current program spaces's source code through > the source cache but then accesses its contents through the disk. This > PR updates the implementation so that the access of the contents is also > through the source cache. > > Tested on x86_64-redhat-linux. > > Signed-off-by: Will Hawkins > --- > v1 -> v2: > Remove leftover debugging code. > > Rationale: > Supporting access through the source cache during searching will = make it > easier to implement the embedded source functionality of DW_LNCT_= source. > > gdb/source.c | 79 +++++++++++++++++++++++++--------------------------- > 1 file changed, 38 insertions(+), 41 deletions(-) > > diff --git a/gdb/source.c b/gdb/source.c > index bbeb4154258..ef042b0e96e 100644 > --- a/gdb/source.c > +++ b/gdb/source.c > @@ -1617,46 +1617,45 @@ search_command_helper (const char *regex, int fro= m_tty, bool forward) > if (!source_open) > error (_("source code access disabled")); > > - scoped_fd desc (open_source_file (loc->symtab ())); > - if (desc.get () < 0) > - perror_with_name (symtab_to_filename_for_display (loc->symtab ()), > - -desc.get ()); > - > - int line =3D (forward > - ? last_line_listed + 1 > - : last_line_listed - 1); > - > const std::vector *offsets; > - if (line < 1 > - || !g_source_cache.get_line_charpos (loc->symtab (), &offsets) > - || line > offsets->size ()) > + if (!g_source_cache.get_line_charpos (loc->symtab (), &offsets)) > error (_("Expression not found")); > > - if (lseek (desc.get (), (*offsets)[line - 1], 0) < 0) > - perror_with_name (symtab_to_filename_for_display (loc->symtab ())); > + std::string lines; > + if (!g_source_cache.get_source_lines (loc->symtab (), 1, offsets->size= (), > + &lines)) > + perror_with_name (symtab_to_filename_for_display (loc->symtab ()), -= ENOENT); > + > + int line_no =3D (forward > + ? last_line_listed + 1 > + : last_line_listed - 1); > > - gdb_file_up stream =3D desc.to_file (FDOPEN_MODE); > - clearerr (stream.get ()); > + if (line_no < 1 > + || line_no > offsets->size ()) > + error (_("Expression not found")); > + > + size_t current_line_start =3D (*offsets)[line_no - 1]; > > - gdb::def_vector buf; > - buf.reserve (256); > + std::string buf; > > while (1) > { > - buf.resize (0); > - > - int c =3D fgetc (stream.get ()); > - if (c =3D=3D EOF) > + /* Invariant: current_line_start is either the index > + of the start of the current line in LINES *or* the > + length of the source code (LINES, when there is nothing > + else to do). */ > + if (current_line_start =3D=3D lines.length ()) > break; > - do > - { > - buf.push_back (c); > - } > - while (c !=3D '\n' && (c =3D fgetc (stream.get ())) >=3D 0); > + > + size_t current_line_end =3D ((line_no + 1) > offsets->size () > + ? lines.size () - 1 > + : (*offsets)[line_no] - 1); > + > + size_t sz =3D current_line_end - current_line_start; > + buf =3D lines.substr (current_line_start, sz); > > /* Remove the \r, if any, at the end of the line, otherwise > regular expressions that end with $ or \n won't work. */ > - size_t sz =3D buf.size (); > if (sz >=3D 2 && buf[sz - 2] =3D=3D '\r') > { > buf[sz - 2] =3D '\n'; > @@ -1664,29 +1663,27 @@ search_command_helper (const char *regex, int fro= m_tty, bool forward) > } > > /* We now have a source line in buf, null terminate and match. */ > - buf.push_back ('\0'); > + buf +=3D '\0'; > if (re_exec (buf.data ()) > 0) > { > /* Match! */ > - print_source_lines (loc->symtab (), line, line + 1, 0); > - set_internalvar_integer (lookup_internalvar ("_"), line); > - loc->set (loc->symtab (), std::max (line - lines_to_list / 2, 1= )); > + print_source_lines (loc->symtab (), line_no, line_no + 1, 0); > + set_internalvar_integer (lookup_internalvar ("_"), line_no); > + loc->set (loc->symtab (), std::max (line_no - lines_to_list / 2= , 1)); > return; > } > > if (forward) > - line++; > + { > + line_no++; > + current_line_start =3D current_line_end + 1; > + } > else > { > - line--; > - if (line < 1) > + line_no--; > + if (line_no < 1) > break; > - if (fseek (stream.get (), (*offsets)[line - 1], 0) < 0) > - { > - const char *filename > - =3D symtab_to_filename_for_display (loc->symtab ()); > - perror_with_name (filename); > - } > + current_line_start =3D (*offsets)[line_no - 1]; > } > } > > -- > 2.44.0 >