From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6907 invoked by alias); 19 Nov 2009 22:50:08 -0000 Received: (qmail 6896 invoked by uid 22791); 19 Nov 2009 22:50:06 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 19 Nov 2009 22:49:03 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 78AE82BAC5F; Thu, 19 Nov 2009 17:49:01 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id lGWfKouyYabd; Thu, 19 Nov 2009 17:49:01 -0500 (EST) Received: from joel.gnat.com (localhost.localdomain [127.0.0.1]) by rock.gnat.com (Postfix) with ESMTP id 5D5E52BABFF; Thu, 19 Nov 2009 17:49:01 -0500 (EST) Received: by joel.gnat.com (Postfix, from userid 1000) id BC8ADF5905; Thu, 19 Nov 2009 17:48:59 -0500 (EST) Date: Thu, 19 Nov 2009 22:50:00 -0000 From: Joel Brobecker To: Keith Seitz Cc: gdb-patches@sourceware.org Subject: Re: [RFA] Fix Ada memory corruption Message-ID: <20091119224859.GC10089@adacore.com> References: <4B0595B3.90001@redhat.com> <20091119191959.GA10089@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="pWyiEgJYm5f9v55/" Content-Disposition: inline In-Reply-To: <20091119191959.GA10089@adacore.com> User-Agent: Mutt/1.5.18 (2008-05-17) Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-11/txt/msg00418.txt.bz2 --pWyiEgJYm5f9v55/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-length: 560 > > * ada-lang.c (find_old_style_renaming_symbol): Change > > function_name to const and use strncpy to stript the > > suffix. I think there was a mistake in the last part of the patch and you would have ended up overwriting the function name with the _____XR portion. I was almost done with my own version of the change, so I finished it, tested it, and checked it in. While working on this, I also added handling for various suffixes that get introduced for nested/static procedures as well as special routines (Protected Objects). -- Joel --pWyiEgJYm5f9v55/ Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Fix-memory-corruption-during-old-style-renamings-pro.patch" Content-length: 2842 gdb/ * ada-lang.c (ada_remove_Xbn_suffix): New function. (find_old_style_renaming_symbol): Add handling for function suffixes present in the name of various procedures. Do not overwrite the function symbol's name. --- gdb/ada-lang.c | 36 +++++++++++++++++++++++++++++++----- 1 files changed, 31 insertions(+), 5 deletions(-) diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index b5590f7..3c9ab77 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -873,6 +873,26 @@ ada_remove_po_subprogram_suffix (const char *encoded, int *len) *len = *len - 1; } +/* Remove trailing X[bn]* suffixes (indicating names in package bodies). */ + +static void +ada_remove_Xbn_suffix (const char *encoded, int *len) +{ + int i = *len - 1; + + while (i > 0 && (encoded[i] == 'b' || encoded[i] == 'n')) + i--; + + if (encoded[i] != 'X') + return; + + if (i == 0) + return; + + if (isalnum (encoded[i-1])) + *len = i; +} + /* If ENCODED follows the GNAT entity encoding conventions, then return the decoded form of ENCODED. Otherwise, return "<%s>" where "%s" is replaced by ENCODED. @@ -6514,12 +6534,14 @@ find_old_style_renaming_symbol (const char *name, struct block *block) the XR type name, we need to make sure that this suffix is not included. So do not include any suffix in the function name length below. */ - const int function_name_len = ada_name_prefix_len (function_name); + int function_name_len = ada_name_prefix_len (function_name); const int rename_len = function_name_len + 2 /* "__" */ + strlen (name) + 6 /* "___XR\0" */ ; /* Strip the suffix if necessary. */ - function_name[function_name_len] = '\0'; + ada_remove_trailing_digits (function_name, &function_name_len); + ada_remove_po_subprogram_suffix (function_name, &function_name_len); + ada_remove_Xbn_suffix (function_name, &function_name_len); /* Library-level functions are a special case, as GNAT adds a ``_ada_'' prefix to the function name to avoid namespace @@ -6527,11 +6549,15 @@ find_old_style_renaming_symbol (const char *name, struct block *block) have this prefix, so we need to skip this prefix if present. */ if (function_name_len > 5 /* "_ada_" */ && strstr (function_name, "_ada_") == function_name) - function_name = function_name + 5; + { + function_name += 5; + function_name_len -= 5; + } rename = (char *) alloca (rename_len * sizeof (char)); - xsnprintf (rename, rename_len * sizeof (char), "%s__%s___XR", - function_name, name); + strncpy (rename, function_name, function_name_len); + xsnprintf (rename + function_name_len, rename_len - function_name_len, + "__%s___XR", name); } else { -- 1.6.0.4 --pWyiEgJYm5f9v55/--