This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
PATCH to avoid infinite loop in cplus-dem.c on some EDG names
- From: scott snyder <snyder at fnal dot gov>
- To: gdb-patches at sources dot redhat dot com
- Date: Fri, 15 Feb 2002 16:31:41 CST
- Subject: PATCH to avoid infinite loop in cplus-dem.c on some EDG names
- Reply-to: scott snyder <snyder at fnal dot gov>
hi -
The following name, emitted by an EDG-based compiler (kcc 4.0),
causes the demangler to go into an infinite loop when run with
auto demangling. (Try running test-filter with `--format=auto'.)
__CPR212____ct__Q3_3std141list__tm__128_Q2_3edm41THandle__tm__26_Q2_4emid15EMparticleChunkQ2_3std68allocator__tm__51_Q2_3edmJ37J14const_iteratorFRCQ3_3std18list__tm__7_Z1ZZ2Z8iterator
This makes it difficult to use gdb on binaries containing such names ---
gdb hangs while reading in the symbol table.
It's getting stuck in the loop in demangle_arm_hp_template(), where we have:
while (args < e) {
...
switch (*args)
{
...
default:
/* Not handling other HP cfront stuff */
if (!do_type (work, &args, &arg))
goto cfront_template_args_done;
}
...
}
For this case, args is pointing here:
(gdb) p args
$1 = 0x80564c4 "__7_Z1ZZ2Z8iterator"
But do_type doesn't recognize a type of `_' --- and in that case,
it returns without making any progress, leaving its arguments unchanged.
So we loop here forever.
Here's a simple patch to prevent this --- we simply give up if do_type()
doesn't make any progress. We still don't correctly demangle the name,
but at least we don't hang forever.
thanks,
sss
2002-02-15 scott snyder <snyder@fnal.gov>
* testsuite/demangle-expected: Add test case for infinite loop in
demangler.
* cplus-dem.c (demangle_arm_hp_template): Stop trying to demangle
if do_type() doesn't make any progress --- prevents an infinite
loop.
Index: cplus-dem.c
===================================================================
RCS file: /cvs/src/src/libiberty/cplus-dem.c,v
retrieving revision 1.29
diff -u -p -c -r1.29 cplus-dem.c
*** cplus-dem.c 2002/02/05 17:53:17 1.29
--- cplus-dem.c 2002/02/15 22:26:35
*************** demangle_arm_hp_template (work, mangled,
*** 2403,2410 ****
break;
default:
/* Not handling other HP cfront stuff */
! if (!do_type (work, &args, &arg))
! goto cfront_template_args_done;
}
string_appends (declp, &arg);
string_append (declp, ",");
--- 2403,2417 ----
break;
default:
/* Not handling other HP cfront stuff */
! {
! const char* old_args = args;
! if (!do_type (work, &args, &arg))
! goto cfront_template_args_done;
!
! /* Fail if we didn't make any progress: prevent infinite loop. */
! if (args == old_args)
! return;
! }
}
string_appends (declp, &arg);
string_append (declp, ",");
Index: testsuite/demangle-expected
===================================================================
RCS file: /cvs/src/src/libiberty/testsuite/demangle-expected,v
retrieving revision 1.7
diff -u -p -c -r1.7 demangle-expected
*** demangle-expected 2002/01/31 02:21:27 1.7
--- demangle-expected 2002/02/15 22:26:43
*************** _Utf58_0_1__1_2147483647__2147483648
*** 2594,2596 ****
--- 2594,2602 ----
--format=gnu-v3
St9bad_alloc
std::bad_alloc
+ #
+ # This caused an infinite loop.
+ # We still don't demangle this correctly, but at least we don't hang.
+ --format=auto
+ __CPR212____ct__Q3_3std141list__tm__128_Q2_3edm41THandle__tm__26_Q2_4emid15EMparticleChunkQ2_3std68allocator__tm__51_Q2_3edmJ37J14const_iteratorFRCQ3_3std18list__tm__7_Z1ZZ2Z8iterator
+ _Z1ZZ2Z::__CPR212____ct__Q3_3std141list__tm__128_Q2_3edm41THandle__tm__26_Q2_4emid15EMparticleChunkQ2_3std68allocator__tm__51_Q2_3edmJ37J14const_iteratorFRCQ3_3std18list__tm(iterator)