Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: Jan Kratochvil <jan.kratochvil@redhat.com>
Cc: Simon Marchi <simon.marchi@polymtl.ca>, <gdb-patches@sourceware.org>
Subject: Re: Regression with -D_GLIBCXX_DEBUG [Re: [PATCH 1/5] Make delim_string_to_char_ptr_vec return an std::vector]
Date: Tue, 10 Apr 2018 20:52:00 -0000	[thread overview]
Message-ID: <521d0a15-f9de-82ee-5261-867050ce8fde@ericsson.com> (raw)
In-Reply-To: <20180410203942.GA4613@host1.jankratochvil.net>

On 2018-04-10 04:39 PM, Jan Kratochvil wrote:
> On Tue, 10 Apr 2018 22:32:46 +0200, Simon Marchi wrote:
>> Of course, thanks for reporting.  Does this fix it?
>>
>> >From fddee555819b2631920bf4a86854bb0d76ac121f Mon Sep 17 00:00:00 2001
>> From: Simon Marchi <simon.marchi@ericsson.com>
>> Date: Tue, 10 Apr 2018 16:31:52 -0400
>> Subject: [PATCH] Iterate by index
> 
> Yes.

Thanks, here's what I pushed:

From 6e22e10d63addd60f39114cef81ade290b15b2c8 Mon Sep 17 00:00:00 2001
From: Simon Marchi <simon.marchi@ericsson.com>
Date: Tue, 10 Apr 2018 16:50:59 -0400
Subject: [PATCH] Iterate by index in auto_load_safe_path_vec_update

As reported by Jan, we get this error when building with -D_GLIBCXX_DEBUG:

/usr/include/c++/7/debug/safe_iterator.h:297:
Error: attempt to increment a singular iterator.
Objects involved in the operation:
    iterator "this" @ 0x0x7fffffffd140 {
      type = __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<std::unique_ptr<char, gdb::xfree_deleter<char> >*, std::__cxx1998::vector<std::unique_ptr<char, gdb::xfree_deleter<char> >, std::allocator<std::unique_ptr<char, gdb::xfree_deleter<char> > > > >, std::__debug::vector<std::unique_ptr<char, gdb::xfree_deleter<char> >, std::allocator<std::unique_ptr<char, gdb::xfree_deleter<char> > > > > (mutable iterator);
      state = singular;
      references sequence with type 'std::__debug::vector<std::unique_ptr<char, gdb::xfree_deleter<char> >, std::allocator<std::unique_ptr<char, gdb::xfree_deleter<char> > > >' @ 0x0x265db40
    }

The bug was introduced by commit

commit e80aaf6183c6692ecc167bf26cbdc53f8f1a55f0
Author: Simon Marchi <simon.marchi@polymtl.ca>
Date:   Fri Mar 2 23:22:06 2018 -0500
Make delim_string_to_char_ptr_vec return an std::vector

The problem is that we iterate using a range-based for on a vector to
which we push in the loop.  Pushing to the vector invalidates the
iterator used in the loop.  Instead, change the code to iterate by index
as was done in the previous code.

gdb/ChangeLog:

	* auto-load.c (auto_load_safe_path_vec_update): Iterate by
	index.
---
 gdb/ChangeLog   | 5 +++++
 gdb/auto-load.c | 7 +++----
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index d46ecdd..6ed9d6c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2018-04-10  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* auto-load.c (auto_load_safe_path_vec_update): Iterate by
+	index.
+
 2018-04-10  Pedro Alves  <palves@redhat.com>

 	* gdbthread.h (finish_thread_state_cleanup): Delete declaration.
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index e426468..33d282a 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -197,20 +197,19 @@ auto_load_expand_dir_vars (const char *string)
 static void
 auto_load_safe_path_vec_update (void)
 {
-  unsigned len;
-  int ix;
-
   if (debug_auto_load)
     fprintf_unfiltered (gdb_stdlog,
 			_("auto-load: Updating directories of \"%s\".\n"),
 			auto_load_safe_path);

   auto_load_safe_path_vec = auto_load_expand_dir_vars (auto_load_safe_path);
+  size_t len = auto_load_safe_path_vec.size ();

   /* Apply tilde_expand and gdb_realpath to each AUTO_LOAD_SAFE_PATH_VEC
      element.  */
-  for (gdb::unique_xmalloc_ptr<char> &in_vec : auto_load_safe_path_vec)
+  for (size_t i = 0; i < len; i++)
     {
+      gdb::unique_xmalloc_ptr<char> &in_vec = auto_load_safe_path_vec[i];
       gdb::unique_xmalloc_ptr<char> expanded (tilde_expand (in_vec.get ()));
       gdb::unique_xmalloc_ptr<char> real_path = gdb_realpath (expanded.get ());

-- 
2.7.4



      reply	other threads:[~2018-04-10 20:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-25 16:32 [PATCH 1/5] Make delim_string_to_char_ptr_vec return an std::vector Simon Marchi
2018-02-25 16:32 ` [PATCH 3/5] Make program_space::deleted_solibs a vector of std::string Simon Marchi
2018-02-25 16:32 ` [PATCH 4/5] C++ify charsets Simon Marchi
2018-02-25 16:33 ` [PATCH 5/5] Remove free_char_ptr_vec Simon Marchi
2018-02-25 16:47 ` [PATCH 2/5] C++ify program_space Simon Marchi
2018-03-03  4:23 ` [PATCH 1/5] Make delim_string_to_char_ptr_vec return an std::vector Simon Marchi
2018-04-10 19:58 ` Regression with -D_GLIBCXX_DEBUG [Re: [PATCH 1/5] Make delim_string_to_char_ptr_vec return an std::vector] Jan Kratochvil
2018-04-10 20:33   ` Simon Marchi
2018-04-10 20:39     ` Jan Kratochvil
2018-04-10 20:52       ` Simon Marchi [this message]

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=521d0a15-f9de-82ee-5261-867050ce8fde@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=jan.kratochvil@redhat.com \
    --cc=simon.marchi@polymtl.ca \
    /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