From patchwork Tue Jun 3 00:00:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Evans X-Patchwork-Id: 1251 Received: (qmail 28928 invoked by alias); 3 Jun 2014 00:01:01 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 28912 invoked by uid 89); 3 Jun 2014 00:01:00 -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, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-yh0-f73.google.com Received: from mail-yh0-f73.google.com (HELO mail-yh0-f73.google.com) (209.85.213.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Tue, 03 Jun 2014 00:00:59 +0000 Received: by mail-yh0-f73.google.com with SMTP id f73so1119941yha.4 for ; Mon, 02 Jun 2014 17:00:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-type; bh=gsQMjIfLcc6bEsbF/efUNoFfYMwCUNLB0iV4AvvWzpQ=; b=jzMjdKZ3r3eqZXkWiJHhafvPBFaeFM+Xqg4okjjq8bfiYsW1eUAz5HmZWutD2nGUxC /S+E5ju4zsFx0QXOD64cI0vGB3ltO2dcsj7Z27myRFyb6VXZhXdJ3VgysydECxdcrT3R KyD8OUYGhzlqBwOgE3w4WMFRW2u5h2leDi+M3L9H7n25lF7NxvgqIMUCreYWE1fED/hK RhlgSISO/85uDCiIQUN0H7MNKPXpz+jonv1v2VWsLny90jPXiKQ79E90gIPlrkUkecwh bgQVOEtg7o4M/hv+m0VyZ4+Q62yQeaULL/8qPdx/c1gppHYTF3i3+ESASXBsZDGoBBfO /IKQ== X-Gm-Message-State: ALoCoQn1QiL9rW4zp1r6t2wRKI7r3aVq2DXNnBiFk7wrdXH9bz3tvaahh+rTvUAfgHU81h870+M6hbH8mJqMBDYMMpRacciKyVRW6jKPGbLrDD9hLT1zRG7amjCAhZYEHWhKXJf6ZOck X-Received: by 10.236.222.36 with SMTP id s34mr14006450yhp.24.1401753657630; Mon, 02 Jun 2014 17:00:57 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id h13si948553yhj.0.2014.06.02.17.00.57 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jun 2014 17:00:57 -0700 (PDT) Received: from ruffy.mtv.corp.google.com (ruffy.mtv.corp.google.com [172.17.128.44]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 39B2C31C40A for ; Mon, 2 Jun 2014 17:00:57 -0700 (PDT) From: Doug Evans To: gdb-patches@sourceware.org Subject: [PATCH] clean up resize_section_table Date: Mon, 02 Jun 2014 17:00:56 -0700 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi. This patch is a simple cleanup to resize_section_table. Some callers do a two-step dance to clear the table, this replaces that with a new function that does what it says. Plus the argument "num_added" was a bit confusing so I renamed it. Regression tested on amd64-linux. [There's still a gdb segv caught by corefile.exp, but that's a different patch.] 2014-06-02 Doug Evans * exec.c (exec_close_1): Call clear_section_table instead of resize_section_table. (clear_section_table): New function. (resize_section_table): Make static. Rename arg num_added to adjustment. * exec.h (clear_section_table): Declare. (resize_section_table): Delete. * progspace.c (release_program_space): Call clear_section_table instead of resize_section_table. diff --git a/gdb/exec.c b/gdb/exec.c index ca59c72..087c122 100644 --- a/gdb/exec.c +++ b/gdb/exec.c @@ -125,12 +125,7 @@ exec_close_1 (struct target_ops *self) ALL_PSPACES (ss) { set_current_program_space (ss); - - /* Delete all target sections. */ - resize_section_table - (current_target_sections, - -resize_section_table (current_target_sections, 0)); - + clear_section_table (current_target_sections); exec_close (); } @@ -366,15 +361,29 @@ add_to_section_table (bfd *abfd, struct bfd_section *asect, (*table_pp)++; } -int -resize_section_table (struct target_section_table *table, int num_added) +/* See exec.h. */ + +void +clear_section_table (struct target_section_table *table) +{ + xfree (table->sections); + table->sections = table->sections_end = NULL; +} + +/* Resize section table TABLE by ADJUSTMENT. + ADJUSTMENT may be negative, in which case the caller must have already + removed the sections being deleted. + Returns the old size. */ + +static int +resize_section_table (struct target_section_table *table, int adjustment) { int old_count; int new_count; old_count = table->sections_end - table->sections; - new_count = num_added + old_count; + new_count = adjustment + old_count; if (new_count) { @@ -383,10 +392,7 @@ resize_section_table (struct target_section_table *table, int num_added) table->sections_end = table->sections + new_count; } else - { - xfree (table->sections); - table->sections = table->sections_end = NULL; - } + clear_section_table (table); return old_count; } diff --git a/gdb/exec.h b/gdb/exec.h index 44f1367..304310f 100644 --- a/gdb/exec.h +++ b/gdb/exec.h @@ -41,10 +41,9 @@ extern struct target_ops exec_ops; extern int build_section_table (struct bfd *, struct target_section **, struct target_section **); -/* Resize the section table held by TABLE, by NUM_ADDED. Returns the - old size. */ +/* Remove all entries from TABLE. */ -extern int resize_section_table (struct target_section_table *, int); +extern void clear_section_table (struct target_section_table *table); /* Read from mappable read-only sections of BFD executable files. Return TARGET_XFER_OK, if read is successful. Return diff --git a/gdb/progspace.c b/gdb/progspace.c index 88f59f4..a74b6ab 100644 --- a/gdb/progspace.c +++ b/gdb/progspace.c @@ -160,8 +160,7 @@ release_program_space (struct program_space *pspace) free_all_objfiles (); if (!gdbarch_has_shared_address_space (target_gdbarch ())) free_address_space (pspace->aspace); - resize_section_table (&pspace->target_sections, - -resize_section_table (&pspace->target_sections, 0)); + clear_section_table (&pspace->target_sections); clear_program_space_solib_cache (pspace); /* Discard any data modules have associated with the PSPACE. */ program_space_free_data (pspace);