From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id RyZ1ErcSmF/rQgAAWB0awg (envelope-from ) for ; Tue, 27 Oct 2020 08:29:43 -0400 Received: by simark.ca (Postfix, from userid 112) id 3EC721EFBB; Tue, 27 Oct 2020 08:29:43 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 6FD431E58E for ; Tue, 27 Oct 2020 08:29:42 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7084B3950C68; Tue, 27 Oct 2020 12:29:41 +0000 (GMT) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id B27B83861896 for ; Tue, 27 Oct 2020 12:29:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B27B83861896 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C5A0BB2ED for ; Tue, 27 Oct 2020 12:29:37 +0000 (UTC) Date: Tue, 27 Oct 2020 13:29:36 +0100 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [committed][gdb/symtab] Use early continue in find_pc_sect_compunit_symtab Message-ID: <20201027122919.GA24648@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) 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: , Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" Hi, Function find_pc_sect_compunit_symtab contains a loop: ... for (compunit_symtab *cust : obj_file->compunits ()) { ... if (...) { /* Lots of code. */ } } ... Reduce indentation level and improve readability by using early continue. Tested on x86_64-linux. Committed to trunk. Thanks, - Tom [gdb/symtab] Use early continue in find_pc_sect_compunit_symtab gdb/ChangeLog: 2020-10-27 Tom de Vries * symtab.c (find_pc_sect_compunit_symtab): Use early continue. --- gdb/symtab.c | 94 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/gdb/symtab.c b/gdb/symtab.c index a4f8239a8a..eda33a7eb4 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -2883,7 +2883,7 @@ struct compunit_symtab * find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) { struct compunit_symtab *best_cust = NULL; - CORE_ADDR distance = 0; + CORE_ADDR best_cust_range = 0; struct bound_minimal_symbol msymbol; /* If we know that this is not a text address, return failure. This is @@ -2914,56 +2914,62 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section) { for (compunit_symtab *cust : obj_file->compunits ()) { - const struct block *b; - const struct blockvector *bv; + const struct blockvector *bv = COMPUNIT_BLOCKVECTOR (cust); + const struct block *global_block + = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); + CORE_ADDR start = BLOCK_START (global_block); + CORE_ADDR end = BLOCK_END (global_block); + bool in_range_p = start <= pc && pc < end; + if (!in_range_p) + continue; - bv = COMPUNIT_BLOCKVECTOR (cust); - b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); + CORE_ADDR range = end - start; + if (best_cust != nullptr + && range >= best_cust_range) + /* Cust doesn't have a smaller range than best_cust, skip it. */ + continue; + + /* For an objfile that has its functions reordered, + find_pc_psymtab will find the proper partial symbol table + and we simply return its corresponding symtab. */ + /* In order to better support objfiles that contain both + stabs and coff debugging info, we continue on if a psymtab + can't be found. */ + if ((obj_file->flags & OBJF_REORDERED) && obj_file->sf) + { + struct compunit_symtab *result; + + result + = obj_file->sf->qf->find_pc_sect_compunit_symtab (obj_file, + msymbol, + pc, + section, + 0); + if (result != NULL) + return result; + } - if (BLOCK_START (b) <= pc - && BLOCK_END (b) > pc - && (distance == 0 - || BLOCK_END (b) - BLOCK_START (b) < distance)) + if (section != 0) { - /* For an objfile that has its functions reordered, - find_pc_psymtab will find the proper partial symbol table - and we simply return its corresponding symtab. */ - /* In order to better support objfiles that contain both - stabs and coff debugging info, we continue on if a psymtab - can't be found. */ - if ((obj_file->flags & OBJF_REORDERED) && obj_file->sf) + struct symbol *sym = NULL; + struct block_iterator iter; + + ALL_BLOCK_SYMBOLS (global_block, iter, sym) { - struct compunit_symtab *result; - - result - = obj_file->sf->qf->find_pc_sect_compunit_symtab (obj_file, - msymbol, - pc, - section, - 0); - if (result != NULL) - return result; + fixup_symbol_section (sym, obj_file); + if (matching_obj_sections (SYMBOL_OBJ_SECTION (obj_file, + sym), + section)) + break; } - if (section != 0) - { - struct block_iterator iter; - struct symbol *sym = NULL; - - ALL_BLOCK_SYMBOLS (b, iter, sym) - { - fixup_symbol_section (sym, obj_file); - if (matching_obj_sections (SYMBOL_OBJ_SECTION (obj_file, - sym), - section)) - break; - } - if (sym == NULL) - continue; /* No symbol in this symtab matches + if (sym == NULL) + continue; /* No symbol in this symtab matches section. */ - } - distance = BLOCK_END (b) - BLOCK_START (b); - best_cust = cust; } + + /* Cust is best found sofar, save it. */ + best_cust = cust; + best_cust_range = range; } }