From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by sourceware.org (Postfix) with ESMTPS id EB2203857C63 for ; Sun, 4 Oct 2020 08:38:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EB2203857C63 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wm1-x343.google.com with SMTP id l15so3876572wmh.1 for ; Sun, 04 Oct 2020 01:38:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=O+i9kot1bMEzGeQG8r4ne9Z9N1kvxmx3xnQTbvtzUrY=; b=Dq15ChmjzZUiS7xXfuVOzNn5Vo/C4Kb/cRl7OMdAtOPhHsr7nFEYqugnFEMgZMG0vE Np9UbsHNEUQX20pcNGX5X6Lm9UKtLUHqamxrxIYUy6vCNudelolnbIhITZnkt1a+KjAf TLP0oMTBA0+QO1O3Z5cvoSskY6G91BLuTj9iqvqvjvz+v2MHNhuYPeJzOJKAdFSaWwIj Uq7vMXpdtcy3Q9VJSFBoFsLWMqmqNtSRz4nt6WoXL5AAlmyU5oM3FilBqLcFwzSsSL+n we/ivYtAwsvLmPDnP/uc48XXuW+VVRRnePgMrD10MmjRIs0v9B/nBBG9++leE1bjbqll arQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=O+i9kot1bMEzGeQG8r4ne9Z9N1kvxmx3xnQTbvtzUrY=; b=ti2r/A9ZLCYorNj7dLxvhxDOOymG8DKUptINcwdGzX4l0p/RJ10mNqXpuxGwOKP+ee ZzffC62Od8QAo+aCUoI8/RYHPvJ3kP2jC1BsbRx38MNwgQhXg9JnfiK3MGsRwChjuuaX oILvEghx8hgrMvM9aRxEKzeXTtxuhmyTt0PdAxcpMKrRMoxDZIP/tWqKltZuPGAILJXU gB1dMIoAOabT0QugUhEVxIuLVTo9gAbYdyA88Mc3Rr/EKApP8/EI2gHlHajWPzy+/WL3 LH5yuGNtzQLfbYtzzZ2XifY+avAvCOyAsb0pE64ZrqN4+EwAxECarXdOco4TGQT5HtJI WtBQ== X-Gm-Message-State: AOAM531pbEUBsTxGwKuyAtxQmPzfVXJclWb16KVdKjKppnkzKzxm6F1V uoNfLlNh4qLdKqTizA1NgaGCKuTNg1DLVQ== X-Google-Smtp-Source: ABdhPJycTBDyD4JZXABxSyHFpd4DNwC31qLispniQjZV+jMA+pIN203otetkWR6Lga2HFyh49XpN5Q== X-Received: by 2002:a7b:c081:: with SMTP id r1mr11001590wmh.158.1601800724946; Sun, 04 Oct 2020 01:38:44 -0700 (PDT) Received: from localhost (host109-151-23-62.range109-151.btcentralplus.com. [109.151.23.62]) by smtp.gmail.com with ESMTPSA id l19sm7727675wmi.8.2020.10.04.01.38.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Oct 2020 01:38:44 -0700 (PDT) Date: Sun, 4 Oct 2020 09:38:43 +0100 From: Andrew Burgess To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 3/6] build_section_table cannot fail Message-ID: <20201004083843.GB605036@embecosm.com> References: <20201003193735.2532-1-tom@tromey.com> <20201003193735.2532-4-tom@tromey.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201003193735.2532-4-tom@tromey.com> X-Operating-System: Linux/5.8.12-100.fc31.x86_64 (x86_64) X-Uptime: 09:37:59 up 23:50, 1 user, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Oct 2020 08:38:47 -0000 * Tom Tromey [2020-10-03 13:37:32 -0600]: > I noticed that build_section_table cannot fail. This patch changes it > to return a target_section_table and then removes the dead code. > > 2020-10-03 Tom Tromey > > * solib.c (solib_map_sections): Update. > * record-full.c (record_full_core_open_1): Update. > * exec.h (build_section_table): Return a target_section_table. > * exec.c (exec_file_attach): Update. > (build_section_table): Return a target_section_table. > * corelow.c (core_target::core_target): Update. > * bfd-target.c (target_bfd::target_bfd): Update. Nice cleanup. LGTM. Thanks, Andrew > --- > gdb/ChangeLog | 10 ++++++++++ > gdb/bfd-target.c | 4 ++-- > gdb/corelow.c | 4 +--- > gdb/exec.c | 28 +++++++++------------------- > gdb/exec.h | 5 ++--- > gdb/record-full.c | 8 +------- > gdb/solib.c | 6 +----- > 7 files changed, 26 insertions(+), 39 deletions(-) > > diff --git a/gdb/bfd-target.c b/gdb/bfd-target.c > index 8a58e92eb1c..d5defab9a80 100644 > --- a/gdb/bfd-target.c > +++ b/gdb/bfd-target.c > @@ -89,9 +89,9 @@ target_bfd::get_section_table () > } > > target_bfd::target_bfd (struct bfd *abfd) > - : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd)) > + : m_bfd (gdb_bfd_ref_ptr::new_reference (abfd)), > + m_table (build_section_table (abfd)) > { > - build_section_table (abfd, &m_table); > } > > target_ops * > diff --git a/gdb/corelow.c b/gdb/corelow.c > index 554561dbb36..193dccbeeb5 100644 > --- a/gdb/corelow.c > +++ b/gdb/corelow.c > @@ -161,9 +161,7 @@ core_target::core_target () > bfd_get_filename (core_bfd)); > > /* Find the data section */ > - if (build_section_table (core_bfd, &m_core_section_table)) > - error (_("\"%s\": Can't find sections: %s"), > - bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ())); > + m_core_section_table = build_section_table (core_bfd); > > build_file_mappings (); > } > diff --git a/gdb/exec.c b/gdb/exec.c > index e3e515fedec..d4b9b7bcf65 100644 > --- a/gdb/exec.c > +++ b/gdb/exec.c > @@ -413,7 +413,6 @@ exec_file_attach (const char *filename, int from_tty) > int load_via_target = 0; > const char *scratch_pathname, *canonical_pathname; > int scratch_chan; > - target_section_table sections; > char **matching; > > if (is_target_filename (filename)) > @@ -503,15 +502,7 @@ exec_file_attach (const char *filename, int from_tty) > gdb_bfd_errmsg (bfd_get_error (), matching).c_str ()); > } > > - if (build_section_table (exec_bfd, §ions)) > - { > - /* Make sure to close exec_bfd, or else "run" might try to use > - it. */ > - exec_close (); > - error (_("\"%ps\": can't find the file sections: %s"), > - styled_string (file_name_style.style (), scratch_pathname), > - bfd_errmsg (bfd_get_error ())); > - } > + target_section_table sections = build_section_table (exec_bfd); > > exec_bfd_mtime = bfd_get_mtime (exec_bfd); > > @@ -594,13 +585,13 @@ clear_section_table (struct target_section_table *table) > table->sections.clear (); > } > > -/* Builds a section table, given args BFD, TABLE. > - Returns 0 if OK, 1 on error. */ > +/* Builds a section table, given args BFD, TABLE. */ > > -int > -build_section_table (struct bfd *some_bfd, target_section_table *table) > +target_section_table > +build_section_table (struct bfd *some_bfd) > { > - table->sections.clear (); > + target_section_table table; > + > for (asection *asect : gdb_bfd_sections (some_bfd)) > { > flagword aflag; > @@ -615,16 +606,15 @@ build_section_table (struct bfd *some_bfd, target_section_table *table) > if (!(aflag & SEC_ALLOC)) > continue; > > - table->sections.emplace_back (); > - target_section § = table->sections.back (); > + table.sections.emplace_back (); > + target_section § = table.sections.back (); > sect.owner = NULL; > sect.the_bfd_section = asect; > sect.addr = bfd_section_vma (asect); > sect.endaddr = sect.addr + bfd_section_size (asect); > } > > - /* We could realloc the table, but it probably loses for most files. */ > - return 0; > + return table; > } > > /* Add the sections array defined by [SECTIONS..SECTIONS_END[ to the > diff --git a/gdb/exec.h b/gdb/exec.h > index d26eba49236..75177dda96a 100644 > --- a/gdb/exec.h > +++ b/gdb/exec.h > @@ -34,10 +34,9 @@ struct objfile; > #define exec_bfd_mtime current_program_space->ebfd_mtime > #define exec_filename current_program_space->pspace_exec_filename > > -/* Builds a section table, given args BFD, SECTABLE_PTR, SECEND_PTR. > - Returns 0 if OK, 1 on error. */ > +/* Builds a section table, given args BFD. */ > > -extern int build_section_table (struct bfd *, struct target_section_table *); > +extern target_section_table build_section_table (struct bfd *); > > /* Remove all entries from TABLE. */ > > diff --git a/gdb/record-full.c b/gdb/record-full.c > index 5dcb42d2f4e..40740f216ce 100644 > --- a/gdb/record-full.c > +++ b/gdb/record-full.c > @@ -923,13 +923,7 @@ record_full_core_open_1 (const char *name, int from_tty) > for (i = 0; i < regnum; i ++) > record_full_core_regbuf->raw_supply (i, *regcache); > > - if (build_section_table (core_bfd, &record_full_core_sections)) > - { > - delete record_full_core_regbuf; > - record_full_core_regbuf = NULL; > - error (_("\"%s\": Can't find sections: %s"), > - bfd_get_filename (core_bfd), bfd_errmsg (bfd_get_error ())); > - } > + record_full_core_sections = build_section_table (core_bfd); > > push_target (&record_full_core_ops); > record_full_restore (); > diff --git a/gdb/solib.c b/gdb/solib.c > index 906e1788c49..bd6a27d8983 100644 > --- a/gdb/solib.c > +++ b/gdb/solib.c > @@ -554,11 +554,7 @@ solib_map_sections (struct so_list *so) > > if (so->sections == nullptr) > so->sections = new target_section_table; > - if (build_section_table (so->abfd, so->sections)) > - { > - error (_("Can't find the file sections in `%s': %s"), > - bfd_get_filename (so->abfd), bfd_errmsg (bfd_get_error ())); > - } > + *so->sections = build_section_table (so->abfd); > > for (target_section &p : so->sections->sections) > { > -- > 2.17.2 >