4a80f0
From FEDORA_PATCHES Mon Sep 17 00:00:00 2001
4a80f0
From: Kevin Buettner <kevinb@redhat.com>
4a80f0
Date: Wed, 17 Feb 2021 17:58:54 -0700
4a80f0
Subject: gdb-rhbz1912985-libstdc++-assert.patch
4a80f0
4a80f0
;; Backport fix for libstdc++ assert when performing tab completion
4a80f0
;; (RH BZ 1912985).
4a80f0
4a80f0
Fix completion related libstdc++ assert when using -D_GLIBCXX_DEBUG
4a80f0
4a80f0
This commit fixes a libstdc++ assertion failure encountered when
4a80f0
running gdb.base/completion.exp.  In order to see this problem,
4a80f0
GDB must be built with the follow CFLAGS and CXXFLAGS as part
4a80f0
of the configure line:
4a80f0
4a80f0
  CFLAGS='-D_GLIBCXX_DEBUG' CXXFLAGS='-D_GLIBCXX_DEBUG'
4a80f0
4a80f0
(Also, this problem was encountered using Fedora rawhide.  It might
4a80f0
not be reproducible in Fedora versions prior to Fedora 34.)
4a80f0
4a80f0
Using the gdb.base/completion.exp test program, the problem can be
4a80f0
observed as follows:
4a80f0
4a80f0
[kev@rawhide-1 gdb]$ ./gdb -q testsuite/outputs/gdb.base/completion/completion
4a80f0
Reading symbols from testsuite/outputs/gdb.base/completion/completion...
4a80f0
(gdb) start
4a80f0
Temporary breakpoint 1 at 0x401179: file ../../worktree-master/gdb/testsuite/gdb.base/break.c, line 43.
4a80f0
Starting program: testsuite/outputs/gdb.base/completion/completion
4a80f0
4a80f0
Temporary breakpoint 1, main (argc=1, argv=0x7fffffffd718, envp=0x7fffffffd728) at ../../worktree-master/gdb/testsuite/gdb.base/break.c:43
4a80f0
43	    if (argc == 12345) {  /* an unlikely value < 2^16, in case uninited */ /* set breakpoint 6 here */
4a80f0
(gdb) p <TAB>/usr/include/c++/11/string_view:211: constexpr const value_type& std::basic_string_view<_CharT, _Traits>::operator[](std::basic_string_view<_CharT, _Traits>::size_type) const [with _CharT = char; _Traits = std::char_traits<char>; std::basic_string_view<_CharT, _Traits>::const_reference = const char&; std::basic_string_view<_CharT, _Traits>::size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed.
4a80f0
Aborted (core dumped)
4a80f0
4a80f0
(Note that I added "<TAB>" to make it clear where the tab key was
4a80f0
pressed.)
4a80f0
4a80f0
gdb/ChangeLog:
4a80f0
4a80f0
	* ada-lang.c (ada_fold_name): Check for non-empty string prior
4a80f0
	to accessing it.
4a80f0
	(ada_lookup_name_info): Likewise.
4a80f0
4a80f0
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
4a80f0
--- a/gdb/ada-lang.c
4a80f0
+++ b/gdb/ada-lang.c
4a80f0
@@ -997,7 +997,7 @@ ada_fold_name (gdb::string_view name)
4a80f0
   int len = name.size ();
4a80f0
   GROW_VECT (fold_buffer, fold_buffer_size, len + 1);
4a80f0
 
4a80f0
-  if (name[0] == '\'')
4a80f0
+  if (!name.empty () && name[0] == '\'')
4a80f0
     {
4a80f0
       strncpy (fold_buffer, name.data () + 1, len - 2);
4a80f0
       fold_buffer[len - 2] = '\000';
4a80f0
@@ -13597,7 +13597,7 @@ ada_lookup_name_info::ada_lookup_name_info (const lookup_name_info &lookup_name)
4a80f0
 {
4a80f0
   gdb::string_view user_name = lookup_name.name ();
4a80f0
 
4a80f0
-  if (user_name[0] == '<')
4a80f0
+  if (!user_name.empty () && user_name[0] == '<')
4a80f0
     {
4a80f0
       if (user_name.back () == '>')
4a80f0
 	m_encoded_name