From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28737 invoked by alias); 2 Feb 2012 22:52:37 -0000 Received: (qmail 28728 invoked by uid 22791); 2 Feb 2012 22:52:36 -0000 X-SWARE-Spam-Status: No, hits=1.5 required=5.0 tests=AWL,BAYES_50,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,KAM_STOCKTIP,RCVD_IN_DNSWL_LOW,TW_BJ,TW_FN,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail-ee0-f73.google.com (HELO mail-ee0-f73.google.com) (74.125.83.73) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 02 Feb 2012 22:52:21 +0000 Received: by eekb57 with SMTP id b57so87185eek.0 for ; Thu, 02 Feb 2012 14:52:19 -0800 (PST) Received: by 10.14.100.136 with SMTP id z8mr1090874eef.1.1328223139868; Thu, 02 Feb 2012 14:52:19 -0800 (PST) Received: by 10.14.100.136 with SMTP id z8mr1090868eef.1.1328223139754; Thu, 02 Feb 2012 14:52:19 -0800 (PST) Received: from hpza9.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id x18si2705915eex.1.2012.02.02.14.52.19 (version=TLSv1/SSLv3 cipher=AES128-SHA); Thu, 02 Feb 2012 14:52:19 -0800 (PST) Received: from ruffy2.mtv.corp.google.com (ruffy2.mtv.corp.google.com [172.18.110.129]) by hpza9.eem.corp.google.com (Postfix) with ESMTP id 680A05C0050 for ; Thu, 2 Feb 2012 14:52:19 -0800 (PST) Received: by ruffy2.mtv.corp.google.com (Postfix, from userid 67641) id BB5DD1E25BF; Thu, 2 Feb 2012 14:52:18 -0800 (PST) To: gdb-patches@sourceware.org Subject: [RFA 2/2] Make names in gdbtypes.h,symtab.h const char *. Message-Id: <20120202225218.BB5DD1E25BF@ruffy2.mtv.corp.google.com> Date: Thu, 02 Feb 2012 22:52:00 -0000 From: dje@google.com (Doug Evans) X-IsSubscribed: yes 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: 2012-02/txt/msg00044.txt.bz2 Hi. The changes to these two files involve a teensy bit of extra work beyond simple mechanical changes. This patch requires the main patch in http://sourceware.org/ml/gdb-patches/2012-02/msg00043.html Ok to check in? 2012-02-02 Doug Evans * coffread.c (patch_type): Add (char*) cast to xfree parameter. Use xstrdup. (process_coff_symbol): Use xstrdup. * stabsread.c (stabs_method_name_from_physname): Renamed from update_method_name_from_physname. Change result type from void to char *. All callers updated. (read_member_functions): In has_destructor case, store name in objfile obstack instead of malloc space. In !has_stub case, fix mem leak. Index: coffread.c =================================================================== RCS file: /cvs/src/src/gdb/coffread.c,v retrieving revision 1.125 diff -u -p -r1.125 coffread.c --- coffread.c 4 Jan 2012 08:17:00 -0000 1.125 +++ coffread.c 2 Feb 2012 21:55:41 -0000 @@ -1455,10 +1455,11 @@ patch_type (struct type *type, struct ty if (TYPE_NAME (real_target)) { + /* The previous copy of TYPE_NAME is allocated by + process_coff_symbol. */ if (TYPE_NAME (target)) - xfree (TYPE_NAME (target)); - TYPE_NAME (target) = concat (TYPE_NAME (real_target), - (char *) NULL); + xfree ((char*) TYPE_NAME (target)); + TYPE_NAME (target) = xstrdup (TYPE_NAME (real_target)); } } @@ -1486,7 +1487,7 @@ patch_opaque_types (struct symtab *s) && TYPE_CODE (SYMBOL_TYPE (real_sym)) == TYPE_CODE_PTR && TYPE_LENGTH (TYPE_TARGET_TYPE (SYMBOL_TYPE (real_sym))) != 0) { - char *name = SYMBOL_LINKAGE_NAME (real_sym); + const char *name = SYMBOL_LINKAGE_NAME (real_sym); int hash = hashname (name); struct symbol *sym, *prev; @@ -1675,7 +1676,7 @@ process_coff_symbol (struct coff_symbol } else TYPE_NAME (SYMBOL_TYPE (sym)) = - concat (SYMBOL_LINKAGE_NAME (sym), (char *) NULL); + xstrdup (SYMBOL_LINKAGE_NAME (sym)); } /* Keep track of any type which points to empty structured Index: stabsread.c =================================================================== RCS file: /cvs/src/src/gdb/stabsread.c,v retrieving revision 1.142 diff -u -p -r1.142 stabsread.c --- stabsread.c 8 Jan 2012 21:02:45 -0000 1.142 +++ stabsread.c 2 Feb 2012 21:55:41 -0000 @@ -1173,7 +1173,7 @@ define_symbol (CORE_ADDR valu, char *str NULL, objfile); if (msym != NULL) { - char *new_name = gdbarch_static_transform_name + const char *new_name = gdbarch_static_transform_name (gdbarch, SYMBOL_LINKAGE_NAME (sym)); SYMBOL_SET_LINKAGE_NAME (sym, new_name); @@ -1367,7 +1367,7 @@ define_symbol (CORE_ADDR valu, char *str NULL, objfile); if (msym != NULL) { - char *new_name = gdbarch_static_transform_name + const char *new_name = gdbarch_static_transform_name (gdbarch, SYMBOL_LINKAGE_NAME (sym)); SYMBOL_SET_LINKAGE_NAME (sym, new_name); @@ -2232,10 +2232,11 @@ rs6000_builtin_type (int typenum, struct /* This page contains subroutines of read_type. */ -/* Replace *OLD_NAME with the method name portion of PHYSNAME. */ +/* Wrapper around method_name_from_physname to flag a complaint + if there is an error. */ -static void -update_method_name_from_physname (char **old_name, const char *physname) +static char * +stabs_method_name_from_physname (const char *physname) { char *method_name; @@ -2245,16 +2246,10 @@ update_method_name_from_physname (char * { complaint (&symfile_complaints, _("Method has bad physname %s\n"), physname); - return; + return NULL; } - if (strcmp (*old_name, method_name) != 0) - { - xfree (*old_name); - *old_name = method_name; - } - else - xfree (method_name); + return method_name; } /* Read member function stabs info for C++ classes. The form of each member @@ -2687,14 +2682,24 @@ read_member_functions (struct field_info - in -gstabs instead of -gstabs+ - or for static methods, which are output as a function type instead of a method type. */ + char *new_method_name = + stabs_method_name_from_physname (sublist->fn_field.physname); - update_method_name_from_physname (&new_fnlist->fn_fieldlist.name, - sublist->fn_field.physname); + if (new_method_name != NULL + && strcmp (new_method_name, + new_fnlist->fn_fieldlist.name) != 0) + { + new_fnlist->fn_fieldlist.name = new_method_name; + xfree (main_fn_name); + } + else + xfree (new_method_name); } else if (has_destructor && new_fnlist->fn_fieldlist.name[0] != '~') { new_fnlist->fn_fieldlist.name = - concat ("~", main_fn_name, (char *)NULL); + obconcat (&objfile->objfile_obstack, + "~", main_fn_name, (char *)NULL); xfree (main_fn_name); } else if (!has_stub) @@ -2711,6 +2716,7 @@ read_member_functions (struct field_info new_fnlist->fn_fieldlist.name = obsavestring (dem_opname, strlen (dem_opname), &objfile->objfile_obstack); + xfree (main_fn_name); } new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *) @@ -2753,7 +2759,7 @@ read_cpp_abbrev (struct field_info *fip, struct objfile *objfile) { char *p; - char *name; + const char *name; char cpp_abbrev; struct type *context; @@ -3266,7 +3272,7 @@ read_tilde_fields (struct field_info *fi i >= TYPE_N_BASECLASSES (t); --i) { - char *name = TYPE_FIELD_NAME (t, i); + const char *name = TYPE_FIELD_NAME (t, i); if (!strncmp (name, vptr_name, sizeof (vptr_name) - 2) && is_cplus_marker (name[sizeof (vptr_name) - 2])) @@ -3406,8 +3412,8 @@ attach_fields_to_type (struct field_info static void complain_about_struct_wipeout (struct type *type) { - char *name = ""; - char *kind = ""; + const char *name = ""; + const char *kind = ""; if (TYPE_TAG_NAME (type)) { @@ -4545,7 +4551,7 @@ cleanup_undefined_types_1 (void) struct pending *ppt; int i; /* Name of the type, without "struct" or "union". */ - char *typename = TYPE_TAG_NAME (*type); + const char *typename = TYPE_TAG_NAME (*type); if (typename == NULL) {