From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id BhV4LlJ3IGZeFzMAWB0awg (envelope-from ) for ; Wed, 17 Apr 2024 21:28:50 -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=cIZipP0H; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B17A61E0C0; Wed, 17 Apr 2024 21:28:50 -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 6E1391E030 for ; Wed, 17 Apr 2024 21:28:48 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0C017384DD04 for ; Thu, 18 Apr 2024 01:28:48 +0000 (GMT) Received: from mail-qv1-xf2c.google.com (mail-qv1-xf2c.google.com [IPv6:2607:f8b0:4864:20::f2c]) by sourceware.org (Postfix) with ESMTPS id 6BFD53858D20 for ; Thu, 18 Apr 2024 01:28:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6BFD53858D20 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 6BFD53858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::f2c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713403707; cv=none; b=F7lCLvDg+Z2RqHt7rOJ+5BAyZd3RK7WSY+W3/ObGN3Z5GG+PILGA2VctGzHzt3C4NGmukaYKkc+KvHDUIY1gXZYLZsNiAPIfTRaSJNEHhYokpHRGC/r7PBiALzi0a/geWk6ENvwwN7E5RCPWyjOJPhEzcNoiZmNwdPJAemjAHcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713403707; c=relaxed/simple; bh=tzAxJpBoNDCBDcJvhp47xYe8dvBjxbxWSpUTo6G8RTI=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=koKkalk2NuKETjYKsgv8ImQuez+Sm45a2qHSdqPtMKk+iwR4MEnd5SGZqj1OUQ8grHZM8W6ZF91PpWE3otB7OT3/TBXrewy9RS7U6cRahL5ajcGspKCQ8EMFIcN1GX8PbZHb+hZ56uvbhAIgD9HEYnbtsKW16rAb4SXQALSeRSI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qv1-xf2c.google.com with SMTP id 6a1803df08f44-69b4043b7b3so2406736d6.1 for ; Wed, 17 Apr 2024 18:28:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=obs-cr.20230601.gappssmtp.com; s=20230601; t=1713403704; x=1714008504; 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=yHr8gkdRF557vvf7Ezd8TcURajG4w1oExCm9UtuAY1I=; b=cIZipP0H3+yvZTp8wmFvEaUYyY6RbAEYR+oXqazukQn/tRHCiumsFnEf4dOWa3l+YV avtwdEMKSggPe85otZJOceShjcTe6fUdCrDX0uQt+wYHPsw0jZlRA0jCuNPIXbPGMJeI EJbtunl4ULacIlZBZbpnVxC9b1Y34DpCL6kW8ocy80OWtPzGcMBwSq/9LD9S+lQKDfLY aXJgOApCrxQowAbHr3/ieQ365OQE1W650sb+Y7fZ+duMRxTDuhsTcfy0IKDGlZvtlOlE KdTKNc/JpSnw03A1rFjuiYnPaO8HayOQGvoLYH14X8GmYF+q1zkcfoZ1xpw6PBBvd939 jMGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713403704; x=1714008504; 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=yHr8gkdRF557vvf7Ezd8TcURajG4w1oExCm9UtuAY1I=; b=EU+5PlS5YpmpErHVBicLBSGGBuklMPcXxhowH2ebKtzRhyNUHDEGVgramuO6WSTXHF 5EzYVSeYa4aXwLxhh8mTlSLS4rg8SpAV/fVLhCXoC0PqR47EA8YgU8/FMJQkqHK190L1 eAYFHLqNwraDbeHKbwGZa6H4NHbLthXkRRfRz0oMdbL4d40lNG73TYUQGTvJ8taIacta MYJZQwwMsF1ydGKPS3juYuRpdlR31FLCADpsYPizRbUrd5f+wTXq8qvFFWaVK6EdDqYZ gmXZV99GFoW/RKOVT96xxyvNJ1zlAA1TlsrNi8TpaZ1juAkpEyPcjmNmPdxcFCn9ZqiW ezpw== X-Gm-Message-State: AOJu0YzxX6D5jOulZ3uYTY78OA087ZkQ3rCzJmPD9w1Nvi1ZzZy7MdtM 6u/JsxG5IJ73+hw+EM33bvtIVKfc3NI/lh6ScK4/3T5z2j9qw403CH4dZ4wbZgPcIocBFo3EAPi G4UwSzebeT06bpGtqbHkxuHfsJF186uw7DmvM/lb8JHWzk8JjmpQ= X-Google-Smtp-Source: AGHT+IEykn5ZOCfczzMeINeljFmgvKxLHFn9GiWCvCYBcBpPtJVMSfy7wJqqjT2GvKInc5mdTDlGgd5nKz1z55+Ggs0= X-Received: by 2002:ad4:41c7:0:b0:696:7597:5141 with SMTP id a7-20020ad441c7000000b0069675975141mr1076380qvq.56.1713403704596; Wed, 17 Apr 2024 18:28:24 -0700 (PDT) MIME-Version: 1.0 References: <20240324011828.145140-1-hawkinsw@obs.cr> <20240325140103.157217-1-hawkinsw@obs.cr> In-Reply-To: From: Will Hawkins Date: Wed, 17 Apr 2024 21:28:13 -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=-6.9 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 Hello! As ever, thank you for the work that you all put into gdb. If the patch below is something that you would consider accepting and there are things that need to be improved, please just let me know! Thank you, again! Will On Mon, Apr 8, 2024 at 2:12=E2=80=AFPM Will Hawkins wrote= : > > Hello! > > I hope that everyone is having a great Monday! If there is something > that I can do to make this patch better, please let me know. I am > sincerely enjoying the opportunity to contribute to GDB and I hope > that you find these patches helpful! > > Sincerely, > Will > > On Fri, Mar 29, 2024 at 10:46=E2=80=AFAM Will Hawkins w= rote: > > > > 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 = wrote: > > > > > > 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. Thi= s > > > PR updates the implementation so that the access of the contents is a= lso > > > 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 w= ill make it > > > easier to implement the embedded source functionality of DW_L= NCT_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= from_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= from_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 > > >