Blame SOURCES/gdb-rhbz1912985-libstdc++-assert.patch

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