From patchwork Fri Mar 9 21:16:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 26264 Received: (qmail 28331 invoked by alias); 9 Mar 2018 21:16:23 -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 28138 invoked by uid 89); 9 Mar 2018 21:16:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-23.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 09 Mar 2018 21:16:20 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5FBB1406802D for ; Fri, 9 Mar 2018 21:16:19 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 112212026DFD for ; Fri, 9 Mar 2018 21:16:18 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 09/11] Factor out minsym_found/find_function_start_sal overload Date: Fri, 9 Mar 2018 21:16:10 +0000 Message-Id: <20180309211612.12941-10-palves@redhat.com> In-Reply-To: <20180309211612.12941-1-palves@redhat.com> References: <20180309211612.12941-1-palves@redhat.com> I need to make the ifunc resolving code in elfread.c skip the target function's prologue like minsym_found does. I thought of factoring that out to a separate function, but turns out there's already a comment in find_function_start_sal that says that should agree with minsym_found... Instead of making sure the code agrees with a comment, factor out the common code to a separate function and use it from both places. Note that the current find_function_start_sal does a bit more than minsym_found's equivalent (the "We always should ..." bit), though that's probably a latent bug. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * linespec.c (minsym_found): Use find_function_start_sal CORE_ADDR overload. * symtab.c (find_function_start_sal(CORE_ADDR, obj_section *,bool)): New, factored out from ... (find_function_start_sal(symbol *, int)): ... this. Reimplement and use bool. * symtab.h (find_function_start_sal(CORE_ADDR, obj_section *,bool)): New. (find_function_start_sal(symbol *, int)): Change boolean parameter type to bool. --- gdb/linespec.c | 20 +------------------- gdb/symtab.c | 45 +++++++++++++++++++++++++-------------------- gdb/symtab.h | 13 +++++++++++-- 3 files changed, 37 insertions(+), 41 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index abf31559f54..8154f62858e 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -4426,25 +4426,7 @@ minsym_found (struct linespec_state *self, struct objfile *objfile, is_function = msymbol_is_function (objfile, msymbol, &func_addr); if (is_function) - { - sal = find_pc_sect_line (func_addr, NULL, 0); - - if (self->funfirstline) - { - if (sal.symtab != NULL - && (COMPUNIT_LOCATIONS_VALID (SYMTAB_COMPUNIT (sal.symtab)) - || SYMTAB_LANGUAGE (sal.symtab) == language_asm)) - { - struct gdbarch *gdbarch = get_objfile_arch (objfile); - - sal.pc = func_addr; - if (gdbarch_skip_entrypoint_p (gdbarch)) - sal.pc = gdbarch_skip_entrypoint (gdbarch, sal.pc); - } - else - skip_prologue_sal (&sal); - } - } + sal = find_function_start_sal (func_addr, NULL, self->funfirstline); else { sal.objfile = objfile; diff --git a/gdb/symtab.c b/gdb/symtab.c index 567195304f4..13f67639da8 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -3575,46 +3575,36 @@ find_pc_line_pc_range (CORE_ADDR pc, CORE_ADDR *startptr, CORE_ADDR *endptr) return sal.symtab != 0; } -/* Given a function symbol SYM, find the symtab and line for the start - of the function. - If the argument FUNFIRSTLINE is nonzero, we want the first line - of real code inside the function. - This function should return SALs matching those from minsym_found, - otherwise false multiple-locations breakpoints could be placed. */ +/* See symtab.h. */ -struct symtab_and_line -find_function_start_sal (struct symbol *sym, int funfirstline) +symtab_and_line +find_function_start_sal (CORE_ADDR func_addr, obj_section *section, + bool funfirstline) { - fixup_symbol_section (sym, NULL); - - obj_section *section = SYMBOL_OBJ_SECTION (symbol_objfile (sym), sym); - symtab_and_line sal - = find_pc_sect_line (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)), section, 0); - sal.symbol = sym; + symtab_and_line sal = find_pc_sect_line (func_addr, section, 0); if (funfirstline && sal.symtab != NULL && (COMPUNIT_LOCATIONS_VALID (SYMTAB_COMPUNIT (sal.symtab)) || SYMTAB_LANGUAGE (sal.symtab) == language_asm)) { - struct gdbarch *gdbarch = symbol_arch (sym); + struct gdbarch *gdbarch = get_objfile_arch (sal.objfile); - sal.pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); + sal.pc = func_addr; if (gdbarch_skip_entrypoint_p (gdbarch)) sal.pc = gdbarch_skip_entrypoint (gdbarch, sal.pc); return sal; } /* We always should have a line for the function start address. - If we don't, something is odd. Create a plain SAL refering + If we don't, something is odd. Create a plain SAL referring just the PC and hope that skip_prologue_sal (if requested) can find a line number for after the prologue. */ - if (sal.pc < BLOCK_START (SYMBOL_BLOCK_VALUE (sym))) + if (sal.pc < func_addr) { sal = {}; sal.pspace = current_program_space; - sal.pc = BLOCK_START (SYMBOL_BLOCK_VALUE (sym)); + sal.pc = func_addr; sal.section = section; - sal.symbol = sym; } if (funfirstline) @@ -3623,6 +3613,21 @@ find_function_start_sal (struct symbol *sym, int funfirstline) return sal; } +/* See symtab.h. */ + +symtab_and_line +find_function_start_sal (symbol *sym, bool funfirstline) +{ + fixup_symbol_section (sym, NULL); + symtab_and_line sal + = find_function_start_sal (BLOCK_START (SYMBOL_BLOCK_VALUE (sym)), + SYMBOL_OBJ_SECTION (symbol_objfile (sym), sym), + funfirstline); + sal.symbol = sym; + return sal; +} + + /* Given a function start address FUNC_ADDR and SYMTAB, find the first address for that function that has an entry in SYMTAB's line info table. If such an entry cannot be found, return FUNC_ADDR diff --git a/gdb/symtab.h b/gdb/symtab.h index 483e643ebdb..e1f8f566135 100644 --- a/gdb/symtab.h +++ b/gdb/symtab.h @@ -1895,8 +1895,17 @@ int matching_obj_sections (struct obj_section *, struct obj_section *); extern struct symtab *find_line_symtab (struct symtab *, int, int *, int *); -extern struct symtab_and_line find_function_start_sal (struct symbol *sym, - int); +/* Given a function symbol SYM, find the symtab and line for the start + of the function. If FUNFIRSTLINE is true, we want the first line + of real code inside the function. */ +extern symtab_and_line find_function_start_sal (symbol *sym, bool + funfirstline); + +/* Same, but start with a function address/section instead of a + symbol. */ +extern symtab_and_line find_function_start_sal (CORE_ADDR func_addr, + obj_section *section, + bool funfirstline); extern void skip_prologue_sal (struct symtab_and_line *);