From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id jeZcALYzFGa8QigAWB0awg (envelope-from ) for ; Mon, 08 Apr 2024 14:13:10 -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=UIklYZ3v; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id DF7CF1E0C0; Mon, 8 Apr 2024 14:13:09 -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 88E5C1E030 for ; Mon, 8 Apr 2024 14:13:07 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C4B3385842A for ; Mon, 8 Apr 2024 18:13:07 +0000 (GMT) Received: from mail-qk1-x736.google.com (mail-qk1-x736.google.com [IPv6:2607:f8b0:4864:20::736]) by sourceware.org (Postfix) with ESMTPS id 4B81E3858D28 for ; Mon, 8 Apr 2024 18:12:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B81E3858D28 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 4B81E3858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::736 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712599969; cv=none; b=ATiyOspjtyj6u72B7yTGj46mur9xIy5IxXDoCge9rPA8Op/CIeeLEQH8DDIOnRRJ3mJRDsDXMG6aPK1tXtmRtrxcpTmR+pf3fJsNS4643iWTig2nzZAaHRxomaf8NIL5RGYI7PtQNBuWqCMj8oMmYPNQE0I9/Oh+PsU4WZ1e2GM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1712599969; c=relaxed/simple; bh=fFemZm4kmRxQdU9SRuyvnkycFP0OAL2QaK2e4AAnmDk=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=njqgJUqENy/sVE2l/eQgZ+b80D5GDc53ByhsUyCT+dzR+gElWPRK7KPXsMRlQ7TWbR+zVh0AQ6a71flAViQ0k3Zc2sWKrIJ/FE5fo/g9A4K3hofssqy6d9TI/XI8u6hdTWLzRsSi3MtgY/hqUkFLTl9fp+U9chMjjGadGELePTY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-78d68c08df7so61355185a.2 for ; Mon, 08 Apr 2024 11:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=obs-cr.20230601.gappssmtp.com; s=20230601; t=1712599965; x=1713204765; 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=6qidaWwEtCziIHIulFlV3cIxFilFWo7FFh8ZSwkimz0=; b=UIklYZ3vd1TTrRbet+amO4l1w7CIddtm5A7zImVUyr2XE9ipndXZv3eRH0lDV/6c4T M3KHgaZLI6SKcbBKexAq62xcc4LJEdAqq0o1yn9GOYyj8OC91gsZAFgY0xM4x0c2TdSD hLeRdkbvOE/2Ge7X0uX7uEyxM/VyDM75ScC0xvZmb0VZJU+AhMA3xL1E5uGysAfgdSQF UzCE1eKTGF3vQMnFphhUB/phRzCBPONy9AnxjPbjd9m9468/57DlysekCgCV8QFdJFzv Kn/xFdCYews/VrfH/jxEaKKNxPnp0M9Tc3hrdm/iY0rd6rK7ceViZ9lWYoBBr2drPelQ JWWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712599965; x=1713204765; 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=6qidaWwEtCziIHIulFlV3cIxFilFWo7FFh8ZSwkimz0=; b=n2Gyvwl28vzwRRIunKzTMObQuXS/1GcsxMRS3JcZ6i+dGGhT575u8R4WUAMjfFWB7g W+eNY04Um8IrOFj0dJbKr45BtFNZ5+1ssoXueKNRqSPAeb2UzqSQ/MThXMPwo0kvUWpj xDo2M9a0txFViiYj4YhbijxQe3rc5WHhRSuXaqHlhxjImva6UuM+AudkcgOAbPouDxsW M/p7BVtWJjN5tg1tdVaNNgPpvQmuqT7oylSHjEKpGgKKpSPAjC5dmCzbNeK2BIaEq0MU NS/j0oTa/LhI/0LcNuE2W1TFJpy0VcJKPeloA3SPfCc4kV2ZfY6mGapbszPUIJ4oRzVa SBdw== X-Gm-Message-State: AOJu0YzWD3m7JlgXXiEKazeVYIp7/uMwMbNAsUMfyfupFa8CT+OWZHGG aT9HNQ0mYtqNk3Yg5q0/1kywVZ/mMCCEXpffVcCLFaVKoGffzlKpYMbvbJeJD4QIqOz4lAw3/jF G0nxXnQHxgLWOg0BTRivgTZPd6ggVOYRa3NMoKSs/cWdxzLvxmKc= X-Google-Smtp-Source: AGHT+IEZzc4UYZbfXkP02OBO+xGodRumbrSs6twVYvwKddpVpNlchFb/yxg8gdIMxXryeZ2xAtb+d47l29RNlcg88Bw= X-Received: by 2002:a05:6214:5298:b0:69b:16bb:d6a1 with SMTP id kj24-20020a056214529800b0069b16bbd6a1mr4915533qvb.37.1712599965374; Mon, 08 Apr 2024 11:12:45 -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: Mon, 8 Apr 2024 14:12:34 -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.3 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! 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 wro= te: > > 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 w= rote: > > > > 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 als= o > > 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 wil= l make it > > easier to implement the embedded source functionality of DW_LNC= T_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 f= rom_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->si= ze (), > > + &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 f= rom_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 > >