public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: linuxmaker <linuxmaker@163.com>, Tom Tromey <tom@tromey.com>
Cc: Zheng Zhan Liang via Gdb-patches <gdb-patches@sourceware.org>,
	Zheng Zhan <zzlossdev@163.com>
Subject: Re:Re: [PATCH] I'm debugging https://github.com/helix-editor/helix.git@63dcaae1b9083396fb3faaef9eaa2421f7e48fb9, which is a editor implemented with rust lang. When I type gdb command below: (gdb) b pars gdb dumped. I got: m_match = 0x7fffd8173cc7 "parse::h3bbecc5bbd82b347" m_ignored_ranges = { first = 0x7fffd8173cbb "<impl str>::parse::h3bbecc5bbd82b347", second = 0x7fffd8173cc5 "::parse::h3bbecc5bbd82b347" }
Date: Fri, 06 Jan 2023 15:53:48 +0000	[thread overview]
Message-ID: <87lemfy7zn.fsf@redhat.com> (raw)
In-Reply-To: <548304b6.2be2.185850681f6.Coremail.linuxmaker@163.com>

linuxmaker via Gdb-patches <gdb-patches@sourceware.org> writes:

> At 2023-01-06 04:24:42, "Tom Tromey" <tom@tromey.com> wrote:
>>>>>>> "Zheng" == Zheng Zhan Liang via Gdb-patches <gdb-patches@sourceware.org> writes:
>>
>>Zheng> From: Zheng Zhan <zzlossdev@163.com>
>>
>>Hi.  Thank you for the patch.
>>
>>The text all seemed to end up in the Subject line.  Probably you need
>>another newline after the first line of the commit message.
>>
>>Zheng> --- a/gdb/completer.h
>>Zheng> +++ b/gdb/completer.h
>>Zheng> @@ -163,8 +163,11 @@ class completion_match_for_lcd
>>Zheng>  	const char *prev = m_match;
>>Zheng>  	for (const auto &range : m_ignored_ranges)
>>Zheng>  	  {
>>Zheng> -	    m_finished_storage.append (prev, range.first);
>>Zheng> -	    prev = range.second;
>>Zheng> +            if (prev < range.first)
>>Zheng> +              {
>>Zheng> +                m_finished_storage.append (prev, range.first);
>>Zheng> +                prev = range.second;
>>Zheng> +              }
>>
>>Is there any way to construct a test case for this?
> seems pretty common in rust. you can test it like below:
> fn main() {
>     let four: u8 = "4".parse().unwrap();
>     println!("{}", four);
> }
> (gdb) b pars[TAB]

I haven't reviewed the fix.  But in case this makes it easier for
anyone, below is the original patch along with the test written as a
script for GDB's testsuite.  I can confirm that the new test passes with
the fix, and fails without.

I haven't done a full testsuite run yet, so I don't know if there are
any other regressions.

Thanks,
Andrew

---

diff --git a/gdb/completer.h b/gdb/completer.h
index 8b4ad8ec4d4..e2f340c0ce8 100644
--- a/gdb/completer.h
+++ b/gdb/completer.h
@@ -163,8 +163,11 @@ class completion_match_for_lcd
 	const char *prev = m_match;
 	for (const auto &range : m_ignored_ranges)
 	  {
-	    m_finished_storage.append (prev, range.first);
-	    prev = range.second;
+	    if (prev < range.first)
+	      {
+		m_finished_storage.append (prev, range.first);
+		prev = range.second;
+	      }
 	  }
 	m_finished_storage.append (prev);
 
diff --git a/gdb/testsuite/gdb.rust/completion.exp b/gdb/testsuite/gdb.rust/completion.exp
new file mode 100644
index 00000000000..00923db14a6
--- /dev/null
+++ b/gdb/testsuite/gdb.rust/completion.exp
@@ -0,0 +1,34 @@
+# Copyright (C) 2023 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 <http://www.gnu.org/licenses/>.
+
+# Test a completion case that was causing GDB to crash.
+
+load_lib rust-support.exp
+if {[skip_rust_tests]} {
+    return
+}
+
+standard_testfile .rs
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile {debug rust}]} {
+    return -1
+}
+
+set line [gdb_get_line_number "set breakpoint here"]
+if {![runto ${srcfile}:$line]} {
+    untested "could not run to breakpoint"
+    return -1
+}
+
+gdb_test "complete break pars" ".*"
diff --git a/gdb/testsuite/gdb.rust/completion.rs b/gdb/testsuite/gdb.rust/completion.rs
new file mode 100644
index 00000000000..8396e3f4086
--- /dev/null
+++ b/gdb/testsuite/gdb.rust/completion.rs
@@ -0,0 +1,19 @@
+// Copyright (C) 2023 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 <http://www.gnu.org/licenses/>.
+
+fn main() {
+    let four: u8 = "4".parse().unwrap();
+    println!("{}", four);	// set breakpoint here
+}


  reply	other threads:[~2023-01-06 15:53 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-02 12:43 Zheng Zhan Liang
2023-01-05 20:24 ` Tom Tromey
2023-01-06  3:01   ` linuxmaker
2023-01-06 15:53     ` Andrew Burgess [this message]
2023-01-07  8:58       ` Zheng
2023-01-12 19:06         ` Andrew Burgess
2023-01-13  5:24           ` Zheng
2023-01-13 14:46             ` Andrew Burgess
2023-03-20 13:56           ` Tom Tromey
2023-03-20 16:08             ` Andrew Burgess

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lemfy7zn.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=linuxmaker@163.com \
    --cc=tom@tromey.com \
    --cc=zzlossdev@163.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).