Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix Ada crash with .debug_names
Date: Thu, 23 Apr 2020 14:43:06 +0200	[thread overview]
Message-ID: <33a3c626-75f9-326e-55d9-b379635dd8bd@suse.de> (raw)
In-Reply-To: <20200421152335.21282-1-tromey@adacore.com>

On 21-04-2020 17:23, Tom Tromey wrote:
> PR ada/25837 points out a crash in the gdb testsuite when .debug_names
> is used.  You can reproduce like:
> 
>     runtest --target_board=cc-with-debug-names \
>         gdb.ada/big_packed_array.exp
> 
> The bug was introduced by commit e0802d599 ("Avoid copying in
> lookup_name_info").  The problem is that the return type of
> language_lookup_name changed, but in a way that didn't cause existing
> callers to trigger a compilation error.  So, the matcher cache in
> dw2_expand_symtabs_matching_symbol, which stored a "const string &",
> would end up with invalid data.
> 

Hi,

it took me a while to realize that the problem is that the changed
return type of language_lookup_name caused a std::string copy
constructor to be invoked here:
...
      name_and_matcher key {
         name_matcher,
         lookup_name_without_params.language_lookup_name (lang_e)
      };
...
creating a temporary that has the lifetime of the loop body, in other
words, it'll be destroyed at the end of the loop body scope, while still
being referenced after the loop from the std::vector where we store "key".

Perhaps the log message could be extended to clarify that bit.

Otherwise, I've tested this with target board cc-with-debug-names, and
did not spot any new FAILs.

Thanks,
- Tom

---

$ cat test.c
#include <string>
#include <vector>
#include <iostream>
#include <string.h>

struct name_and_matcher
{
#if FIX
  const char *name;
#else
  const std::string &name;
#endif

  bool operator== (const name_and_matcher &other) const
  {
    bool res;
#if FIX
    res = strcmp (name, other.name) == 0;
#else
    res = name == other.name;
#endif
    return res;
  }
};

int
main (void)
{
  std::vector<name_and_matcher> matchers;

  const char *str[] = {
    "itsy", "bitsy", "spider"
  };

  int i;
  for (i = 0; i < 3; ++i)
    {
      name_and_matcher key {
         str[i]
      };

      matchers.push_back (std::move (key));
    }

  for(std::vector<name_and_matcher>::iterator it = matchers.begin ();
      it != matchers.end(); ++it)
    std::cout << it->name << "\n";

  return 0;
}

---

$ g++ test.c -O0 -DFIX=0
$ ./a.out
spider
spider
spider

---

$ g++ test.c -O0 -DFIX=1
itsy
bitsy
spider


  reply	other threads:[~2020-04-23 12:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-21 15:23 Tom Tromey
2020-04-23 12:43 ` Tom de Vries [this message]
2020-04-23 13:16   ` Tom Tromey

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=33a3c626-75f9-326e-55d9-b379635dd8bd@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.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