From patchwork Mon Sep 15 14:21:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihail-Marian Nistor X-Patchwork-Id: 2848 Received: (qmail 23020 invoked by alias); 15 Sep 2014 14:22:16 -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 23006 invoked by uid 89); 15 Sep 2014 14:22:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.3 required=5.0 tests=BAYES_50, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=no version=3.3.2 X-HELO: na01-bl2-obe.outbound.protection.outlook.com Received: from mail-bl2on0145.outbound.protection.outlook.com (HELO na01-bl2-obe.outbound.protection.outlook.com) (65.55.169.145) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 15 Sep 2014 14:22:12 +0000 Received: from BY2PR03CA051.namprd03.prod.outlook.com (10.141.249.24) by BY2PR0301MB0630.namprd03.prod.outlook.com (25.160.125.28) with Microsoft SMTP Server (TLS) id 15.0.1024.12; Mon, 15 Sep 2014 14:22:08 +0000 Received: from BY2FFO11FD018.protection.gbl (2a01:111:f400:7c0c::177) by BY2PR03CA051.outlook.office365.com (2a01:111:e400:2c5d::24) with Microsoft SMTP Server (TLS) id 15.0.1029.13 via Frontend Transport; Mon, 15 Sep 2014 14:22:08 +0000 Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11FD018.mail.protection.outlook.com (10.1.14.106) with Microsoft SMTP Server (TLS) id 15.0.1019.14 via Frontend Transport; Mon, 15 Sep 2014 14:22:07 +0000 Received: from fsr-ub1464-101.ea.freescale.net (fsr-ub1464-101.ea.freescale.net [10.171.73.71]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id s8FEM3qL013280; Mon, 15 Sep 2014 07:22:05 -0700 From: Mihail-Marian Nistor To: CC: Mihail-Marian Nistor Subject: [PATCH] Bug 17394: we cannot put a break-point at a global function for ASM file Date: Mon, 15 Sep 2014 17:21:58 +0300 Message-ID: <1410790918-18986-1-git-send-email-mihail.nistor@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(54534003)(189002)(199003)(377424004)(4396001)(62966002)(44976005)(50466002)(106466001)(99396002)(83322001)(50226001)(69596002)(81342001)(46102001)(81156004)(90102001)(26826002)(86362001)(81542001)(21056001)(33646002)(104016003)(93916002)(48376002)(104166001)(74662001)(77156001)(83072002)(80022001)(229853001)(95666004)(79102001)(19580405001)(76482001)(64706001)(84676001)(50986999)(107046002)(6806004)(74502001)(92726001)(87936001)(92566001)(19580395003)(31966008)(87286001)(102836001)(68736004)(77982001)(85306004)(88136002)(20776003)(36756003)(85852003)(110136001)(97736003)(2351001)(105606002)(47776003)(89996001)(403724002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR0301MB0630; H:az84smr01.freescale.net; FPR:; MLV:ovrnspm; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;UriScan:; X-Forefront-PRVS: 03355EE97E Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=mihail.nistor@freescale.com; X-OriginatorOrg: freescale.com We need to cover the following test case: the user wants to do an action only for the function that was defined into a selected file name. An example: the user wants to put a breakpoint only for functions "func" that was defined in the file name "file.s" e.i. of gdb command line: b file.s:func Due to the limitation that the GAS doesn't generate debug info for functions/symbols, we cannot find the function information if we look only in file symbtabs that was collected by using the file name specified by the user. We need to look into a global default symtab if we want to find minimal information about functions that were written in the ASM file. And after that, we need to select only functions that were defined into the file name specified by the user. gdb/ChangeLog 2014-09-15 Mihail-Marian Nistor * linespec.c (minsym_found): Add new "linespec_p" argument. Update all callers. (maybe_same_source_file) New function. Signed-off-by: Mihail-Marian Nistor --- gdb/linespec.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 118 insertions(+), 5 deletions(-) diff --git a/gdb/linespec.c b/gdb/linespec.c index 8a2c8e3..e6b5ad7 100644 --- a/gdb/linespec.c +++ b/gdb/linespec.c @@ -363,8 +363,11 @@ static void decode_digits_list_mode (struct linespec_state *self, struct symtabs_and_lines *values, struct symtab_and_line val); +static int maybe_same_source_file (struct symtab_and_line* sal, linespec_p ls); + static void minsym_found (struct linespec_state *self, struct objfile *objfile, struct minimal_symbol *msymbol, + linespec_p ls, struct symtabs_and_lines *result); static int compare_symbols (const void *a, const void *b); @@ -1582,7 +1585,7 @@ linespec_parse_basic (linespec_parser *parser) VEC (symbolp) *symbols, *labels; VEC (bound_minimal_symbol_d) *minimal_symbols; struct cleanup *cleanup; - + /* Get the next token. */ token = linespec_lexer_lex_one (parser); @@ -1625,8 +1628,74 @@ linespec_parse_basic (linespec_parser *parser) /* Try looking it up as a function/method. */ find_linespec_symbols (PARSER_STATE (parser), - PARSER_RESULT (parser)->file_symtabs, name, - &symbols, &minimal_symbols); + PARSER_RESULT (parser)->file_symtabs, + name, &symbols, &minimal_symbols); + + /* We need to cover the following test case: the user wants to do an action + only for the function that was defined into a selected file name. + An example: the user wants to put a breakpoint only for functions "func" + that was defined in the file name "file.s" + e.i. of gdb command line: b file.s:func + Due to the limitation that the GAS doesn't generate debug info for functions/symbols, + we cannot find the function information if we look only in file symbtabs that was collected + by using the file name specified by the user. We need to look into a global default symtab + if we want to find minimal information about functions that were written in the ASM file. + And after that, we need to select only functions that were defined into the file name + specified by the user. We do this action into the mimi_found in the minsym_found function */ + + /* Verify if the user has specified a file name that was used to build the current file symtabs. */ + if (PARSER_RESULT (parser)->source_filename) + { + VEC (symtab_ptr) * file_symtabs = NULL; + + int ix; + struct symtab *elt; + int global_symtabs = 0; + + /* Verify if we have already used the global default symtab information to find the function/method. */ + for (ix = 0; VEC_iterate (symtab_ptr, PARSER_RESULT (parser)->file_symtabs, ix, elt); ++ix) + { + VEC_safe_push (symtab_ptr, file_symtabs, elt); + if (elt == NULL) + global_symtabs = 1; + } + + if (!global_symtabs) + { + VEC_safe_push (symtab_ptr, file_symtabs, NULL); + } + + if (file_symtabs) + { + int ims; + bound_minimal_symbol_d *minsym; + + VEC (symbolp) *symbols1; + VEC (bound_minimal_symbol_d) *minimal_symbols1; + + find_linespec_symbols (PARSER_STATE (parser), + file_symtabs, + name, &symbols1, &minimal_symbols1); + + /* We should ignore information about function/method that were found by using .debug_info information, + because this information was already stored into the symbols vector. */ + if (symbols1) + VEC_free(symbolp, symbols1); + + /* Copy information about function/method from minimal_symbols1 to minimal_symbols vector. */ + if (minimal_symbols1) + { + for (ims = 0; VEC_iterate (bound_minimal_symbol_d, minimal_symbols1, ims, minsym); ++ims) + { + VEC_safe_push (bound_minimal_symbol_d, minimal_symbols, minsym); + } + + VEC_free (bound_minimal_symbol_d, minimal_symbols1); + } + + VEC_free (symtab_ptr, file_symtabs); + } + } if (symbols != NULL || minimal_symbols != NULL) { @@ -2059,7 +2128,7 @@ convert_linespec_to_sals (struct linespec_state *state, linespec_p ls) { pspace = elem->objfile->pspace; set_current_program_space (pspace); - minsym_found (state, elem->objfile, elem->minsym, &sals); + minsym_found (state, elem->objfile, elem->minsym, ls, &sals); } } } @@ -2337,6 +2406,13 @@ parse_linespec (linespec_parser *parser, const char **argptr) values = convert_linespec_to_sals (PARSER_STATE (parser), PARSER_RESULT (parser)); + if (values.nelts == 0) + { + /* The symbol is not found. */ + symbol_not_found_error (PARSER_RESULT (parser)->function_name, + PARSER_RESULT (parser)->source_filename); + } + return values; } @@ -3409,12 +3485,49 @@ collect_symbols (struct symbol *sym, void *data) return 1; /* Continue iterating. */ } +/* Check whether the user source file is the same as the source file from SAL. + If so, return 1. Otherwise, return 0. */ +static int +maybe_same_source_file (struct symtab_and_line* sal, linespec_p ls) +{ + /* We know if the user has specified a source file name by using the source_filename field from linespec. */ + int need_filter = (ls->source_filename != NULL) ? 1 : 0; + if (need_filter) + { + int ix; + struct symtab *elt; + const char *name; + const char *fullname; + + if (sal->symtab == NULL) + return 0; + + fullname = symtab_to_fullname(sal->symtab); + + for (ix = 0; VEC_iterate (symtab_ptr, ls->file_symtabs, ix, elt); ++ix) + { + if (elt) + { + name = symtab_to_fullname (elt); + + if (strcmp(fullname, name) == 0) + return 1; + } + } + + return 0; + } + + return 1; +} + /* We've found a minimal symbol MSYMBOL in OBJFILE to associate with our linespec; return the SAL in RESULT. */ static void minsym_found (struct linespec_state *self, struct objfile *objfile, struct minimal_symbol *msymbol, + linespec_p ls, struct symtabs_and_lines *result) { struct gdbarch *gdbarch = get_objfile_arch (objfile); @@ -3434,7 +3547,7 @@ minsym_found (struct linespec_state *self, struct objfile *objfile, if (self->funfirstline) skip_prologue_sal (&sal); - if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc)) + if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc) && maybe_same_source_file (&sal, ls)) add_sal_to_sals (self, result, &sal, MSYMBOL_NATURAL_NAME (msymbol), 0); }