Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* Re: [RFA] libiberty/cplus-dem.c:demangle_template() problem?
       [not found] <20031019055940.GD986@gnat.com>
@ 2003-10-20 23:27 ` Joel Brobecker
  2003-10-20 23:41   ` Andrew Cagney
  0 siblings, 1 reply; 4+ messages in thread
From: Joel Brobecker @ 2003-10-20 23:27 UTC (permalink / raw)
  To: gdb-patches

Hello,

I just committed the following change to libiberty in the GCC tree.
Apparently, the libiberty repository is not "shared" between GCC and
GDB. This fixes a SIGSEGV that occured in GDB. Is it ok to import
this change in the GDB sources?

Thanks,

On Sat, Oct 18, 2003 at 10:59:40PM -0700, Joel Brobecker wrote:
> I noticed a SIGSEGV inside GDB while reading the symbol table.
> What GDB does with each symbol is try to compute their demangled
> name. The SEGV occured because the compiler I used (GNAT) generated
> a symbol which the demangle did not like:
> 
>       _test_array__L_1__B23b___clean.6
> 
> GDB basically called cplus_demangle() with the above name, and kaboom!
> SIGSEGV inside work_stuff_copy_to_from().
> 
> What happened is that cplus_demangle() ends up trying to demangle the
> symbol using gnu_special() which tries to see if the symbol is a
> template by calling demangle_template().
> 
> The value given for parameter REMEMBER is 1, so the first thing the
> function does is registering a Btype inside the work_stuff structure.
> But as it realizes it actually is not a template, it aborts the
> execution and returns zero. However, the work->btypevec vector now
> contains a NULL entry. When the code later tries to make a copy of the
> work_stuff structure, if segfaults because it's trying to copy a NULL
> string. 
> 
> I think the right fix is to only register the Btype when we know we
> are going to store it. In the present case, the attached patch seemed
> to be the right fix. I also attached a patch for the testsuite.  The
> testdriver segfaults before I apply my patch, and runs to completion
> after. The output is unchanged.
> 
> 2003-10-19  J. Brobecker  <brobecker@gnat.com>
> 
> 	* cplus-dem.c (demangle_template): Register a new Btype only
> 	when needed.
> 	* testsuite/demangle-expected: Add a new test.
> 
> OK to apply?
> 
> Thanks,
> -- 
> Joel

Content-Description: cplus-dem.c.diff
> Index: cplus-dem.c
> ===================================================================
> RCS file: /nile.c/cvs/Dev/gdb/gdb-6.0/libiberty/cplus-dem.c,v
> retrieving revision 1.1.1.1
> diff -u -p -r1.1.1.1 cplus-dem.c
> --- cplus-dem.c	5 Oct 2003 10:40:46 -0000	1.1.1.1
> +++ cplus-dem.c	18 Oct 2003 06:42:31 -0000
> @@ -2043,13 +2043,10 @@ demangle_template (work, mangled, tname,
>    const char *start;
>    int is_java_array = 0;
>    string temp;
> -  int bindex = 0;
>  
>    (*mangled)++;
>    if (is_type)
>      {
> -      if (remember)
> -	bindex = register_Btype (work);
>        start = *mangled;
>        /* get template name */
>        if (**mangled == 'z')
> @@ -2226,7 +2223,10 @@ demangle_template (work, mangled, tname,
>      }
>  
>    if (is_type && remember)
> -    remember_Btype (work, tname->b, LEN_STRING (tname), bindex);
> +    {
> +      const int bindex = register_Btype (work);
> +      remember_Btype (work, tname->b, LEN_STRING (tname), bindex);
> +    }
>  
>    /*
>      if (work -> static_type)

> Index: demangle-expected
> ===================================================================
> RCS file: /cvs/src/src/libiberty/testsuite/demangle-expected,v
> retrieving revision 1.13
> diff -u -r1.13 demangle-expected
> --- demangle-expected	16 Oct 2003 15:22:27 -0000	1.13
> +++ demangle-expected	18 Oct 2003 19:25:46 -0000
> @@ -2864,3 +2864,9 @@
>  --format=auto
>  __CPR212____ct__Q3_3std141list__tm__128_Q2_3edm41THandle__tm__26_Q2_4emid15EMparticleChunkQ2_3std68allocator__tm__51_Q2_3edmJ37J14const_iteratorFRCQ3_3std18list__tm__7_Z1ZZ2Z8iterator
>  __CPR212____ct__Q3_3std141list__tm__128_Q2_3edm41THandle__tm__26_Q2_4emid15EMparticleChunkQ2_3std68allocator__tm__51_Q2_3edmJ37J14const_iteratorFRCQ3_3std18list__tm__7_Z1ZZ2Z8iterator
> +#
> +# This used to cause a crash. It doesn't follow the C++ encoding so
> +# the demangled name should be identical to the original symbol name.
> +--format=auto
> +_test_array__L_1__B23b___clean.6
> +_test_array__L_1__B23b___clean.6


-- 
Joel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] libiberty/cplus-dem.c:demangle_template() problem?
  2003-10-20 23:27 ` [RFA] libiberty/cplus-dem.c:demangle_template() problem? Joel Brobecker
@ 2003-10-20 23:41   ` Andrew Cagney
  2003-10-20 23:46     ` DJ Delorie
  2003-10-20 23:51     ` Joel Brobecker
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Cagney @ 2003-10-20 23:41 UTC (permalink / raw)
  To: Joel Brobecker; +Cc: gdb-patches, dj

> Hello,
> 
> I just committed the following change to libiberty in the GCC tree.
> Apparently, the libiberty repository is not "shared" between GCC and
> GDB. This fixes a SIGSEGV that occured in GDB. Is it ok to import
> this change in the GDB sources?

Yes.  Any dj approved upstream change to gcc/libiberty is implicitly 
approved for src/libiberty.

Andrew



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] libiberty/cplus-dem.c:demangle_template() problem?
  2003-10-20 23:41   ` Andrew Cagney
@ 2003-10-20 23:46     ` DJ Delorie
  2003-10-20 23:51     ` Joel Brobecker
  1 sibling, 0 replies; 4+ messages in thread
From: DJ Delorie @ 2003-10-20 23:46 UTC (permalink / raw)
  To: ac131313; +Cc: brobecker, gdb-patches


> Yes.  Any dj approved upstream change to gcc/libiberty is implicitly 
> approved for src/libiberty.

And if you don't do it yourself, the machine usually handles it after
a while.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] libiberty/cplus-dem.c:demangle_template() problem?
  2003-10-20 23:41   ` Andrew Cagney
  2003-10-20 23:46     ` DJ Delorie
@ 2003-10-20 23:51     ` Joel Brobecker
  1 sibling, 0 replies; 4+ messages in thread
From: Joel Brobecker @ 2003-10-20 23:51 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: gdb-patches, dj

> >I just committed the following change to libiberty in the GCC tree.
> >Apparently, the libiberty repository is not "shared" between GCC and
> >GDB. This fixes a SIGSEGV that occured in GDB. Is it ok to import
> >this change in the GDB sources?
> 
> Yes.  Any dj approved upstream change to gcc/libiberty is implicitly 
> approved for src/libiberty.

OK, thank you both for clarifying how it works. I just checked the
change in src as well.

-- 
Joel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-10-20 23:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20031019055940.GD986@gnat.com>
2003-10-20 23:27 ` [RFA] libiberty/cplus-dem.c:demangle_template() problem? Joel Brobecker
2003-10-20 23:41   ` Andrew Cagney
2003-10-20 23:46     ` DJ Delorie
2003-10-20 23:51     ` Joel Brobecker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox