From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26906 invoked by alias); 6 Jan 2014 17:11:45 -0000 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 Received: (qmail 26849 invoked by uid 89); 6 Jan 2014 17:11:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.2 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 06 Jan 2014 17:11:43 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s06HBgIC026482 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 6 Jan 2014 12:11:42 -0500 Received: from barimba.redhat.com (ovpn-113-85.phx2.redhat.com [10.3.113.85]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id s06HBepT011728; Mon, 6 Jan 2014 12:11:41 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/3] move main name into the progspace Date: Mon, 06 Jan 2014 17:11:00 -0000 Message-Id: <1389028297-16977-3-git-send-email-tromey@redhat.com> In-Reply-To: <1389028297-16977-1-git-send-email-tromey@redhat.com> References: <1389028297-16977-1-git-send-email-tromey@redhat.com> X-SW-Source: 2014-01/txt/msg00066.txt.bz2 This moves the "main" name and language into an object attached to the current progspace. This prevents problems if there are multiple inferiors tha have different ideas of "main" -- which matters at least for unwinding, see frame.c:inside_main_func. 2014-01-06 Tom Tromey * symtab.c (main_progspace_key): New global. (struct main_info): New. (name_of_main, language_of_main): Remove. (get_main_info, main_info_cleanup): New function. (set_main_name, main_name, main_language): Use get_main_info. (_initialize_symtab): Initialize main_progspace_key. --- gdb/ChangeLog | 9 +++++++ gdb/symtab.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index 188bc8a..d01a7d7 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -106,6 +106,23 @@ void _initialize_symtab (void); /* */ +/* Program space key for finding name and language of "main". */ + +static const struct program_space_data *main_progspace_key; + +/* Type of the data stored on the program space. */ + +struct main_info +{ + /* Name of "main". */ + + char *name_of_main; + + /* Language of "main". */ + + enum language language_of_main; +}; + /* When non-zero, print debugging messages related to symtab creation. */ unsigned int symtab_create_debug = 0; @@ -5005,22 +5022,56 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr) } /* Track MAIN */ -static char *name_of_main; -static enum language language_of_main = language_unknown; + +/* Return the "main_info" object for the current program space. If + the object has not yet been created, create it and fill in some + default values. */ + +static struct main_info * +get_main_info (void) +{ + struct main_info *info = program_space_data (current_program_space, + main_progspace_key); + + if (info == NULL) + { + info = XCNEW (struct main_info); + info->language_of_main = language_unknown; + set_program_space_data (current_program_space, main_progspace_key, + info); + } + + return info; +} + +/* A cleanup to destroy a struct main_info when a progspace is + destroyed. */ + +static void +main_info_cleanup (struct program_space *pspace, void *data) +{ + struct main_info *info = data; + + if (info != NULL) + xfree (info->name_of_main); + xfree (info); +} void set_main_name (const char *name, enum language lang) { - if (name_of_main != NULL) + struct main_info *info = get_main_info (); + + if (info->name_of_main != NULL) { - xfree (name_of_main); - name_of_main = NULL; - language_of_main = language_unknown; + xfree (info->name_of_main); + info->name_of_main = NULL; + info->language_of_main = language_unknown; } if (name != NULL) { - name_of_main = xstrdup (name); - language_of_main = lang; + info->name_of_main = xstrdup (name); + info->language_of_main = lang; } } @@ -5077,10 +5128,12 @@ find_main_name (void) char * main_name (void) { - if (name_of_main == NULL) + struct main_info *info = get_main_info (); + + if (info->name_of_main == NULL) find_main_name (); - return name_of_main; + return info->name_of_main; } /* Return the language of the main function. If it is not known, @@ -5089,7 +5142,12 @@ main_name (void) enum language main_language (void) { - return language_of_main; + struct main_info *info = get_main_info (); + + if (info->name_of_main == NULL) + find_main_name (); + + return info->language_of_main; } /* Handle ``executable_changed'' events for the symtab module. */ @@ -5278,6 +5336,9 @@ _initialize_symtab (void) { initialize_ordinary_address_classes (); + main_progspace_key + = register_program_space_data_with_cleanup (NULL, main_info_cleanup); + add_info ("variables", variables_info, _("\ All global and static variable names, or those matching REGEXP.")); if (dbx_commands) -- 1.8.1.4