From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31894 invoked by alias); 15 Feb 2002 22:31:44 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 31798 invoked from network); 15 Feb 2002 22:31:43 -0000 Received: from unknown (HELO d0sgibnl1.fnal.gov) (131.225.226.68) by sources.redhat.com with SMTP; 15 Feb 2002 22:31:43 -0000 Received: from localhost (snyder@localhost) by d0sgibnl1.fnal.gov (SGI-8.9.3/8.9.3) with SMTP id QAA69091 for ; Fri, 15 Feb 2002 16:31:42 -0600 (CST) Message-Id: <200202152231.QAA69091@d0sgibnl1.fnal.gov> X-Authentication-Warning: d0sgibnl1.fnal.gov: snyder@localhost didn't use HELO protocol From: scott snyder Reply-To: scott snyder To: gdb-patches@sources.redhat.com Subject: PATCH to avoid infinite loop in cplus-dem.c on some EDG names Date: Fri, 15 Feb 2002 14:31:00 -0000 X-SW-Source: 2002-02/txt/msg00435.txt.bz2 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 * 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)