From patchwork Wed Sep 17 11:53:06 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: 2879 Received: (qmail 14199 invoked by alias); 17 Sep 2014 11:53:25 -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 14187 invoked by uid 89); 17 Sep 2014 11:53:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.6 required=5.0 tests=AWL, 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-bl2on0132.outbound.protection.outlook.com (HELO na01-bl2-obe.outbound.protection.outlook.com) (65.55.169.132) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Wed, 17 Sep 2014 11:53:22 +0000 Received: from BY2PR03CA068.namprd03.prod.outlook.com (10.141.249.41) by BY2PR0301MB0630.namprd03.prod.outlook.com (25.160.125.28) with Microsoft SMTP Server (TLS) id 15.0.1024.12; Wed, 17 Sep 2014 11:53:17 +0000 Received: from BN1AFFO11FD052.protection.gbl (2a01:111:f400:7c10::142) by BY2PR03CA068.outlook.office365.com (2a01:111:e400:2c5d::41) with Microsoft SMTP Server (TLS) id 15.0.1029.13 via Frontend Transport; Wed, 17 Sep 2014 11:53:17 +0000 Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD052.mail.protection.outlook.com (10.58.53.67) with Microsoft SMTP Server (TLS) id 15.0.1019.14 via Frontend Transport; Wed, 17 Sep 2014 11:53:17 +0000 Received: from fsr-ub1464-101.ea.freescale.net (fsr-ub1464-101.ea.freescale.net [10.171.73.71]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id s8HBr87x006832; Wed, 17 Sep 2014 04:53:11 -0700 From: Mihail-Marian Nistor To: CC: Mihail-Marian Nistor Subject: [PATCH v2] Bug 17394: we cannot put a break-point at a global function for ASM file Date: Wed, 17 Sep 2014 14:53:06 +0300 Message-ID: <1410954786-17690-1-git-send-email-mihail.nistor@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:CAL; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(377424004)(199003)(54534003)(189002)(31966008)(83322001)(15975445006)(36756003)(105606002)(83072002)(50986999)(4396001)(99396002)(104166001)(19580395003)(44976005)(50226001)(6806004)(19580405001)(68736004)(85852003)(88136002)(229853001)(87936001)(20776003)(92566001)(76482002)(92726001)(89996001)(93916002)(64706001)(106466001)(575784001)(86362001)(87286001)(81542003)(47776003)(85306004)(90102001)(77982003)(21056001)(74662003)(81342003)(46102003)(77156001)(104016003)(102836001)(2351001)(110136001)(26826002)(50466002)(15202345003)(95666004)(97736003)(74502003)(79102003)(80022003)(62966002)(107046002)(33646002)(48376002)(84676001)(403724002)(2004002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR0301MB0630; H:tx30smr01.am.freescale.net; FPR:; MLV:ovrnspm; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;UriScan:; X-Forefront-PRVS: 0337AFFE9A Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Authentication-Results: spf=fail (sender IP is 192.88.168.50) 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 PR gdb/17394 * linespec.c (minsym_found): Add new "linespec_p" argument. Update all callers. (maybe_same_source_file) New function. gdb/testsuite/ChangeLog 2014-09-15 Mihail-Marian Nistor PR gdb/17394 * gdb.arch/break-asm-x86-file0.s: New file. * gdb.arch/break-asm-x86-file.c: New file. * gdb.arch/break-asm-x86-file.exp: New file. Signed-off-by: Mihail-Marian Nistor --- gdb/linespec.c | 126 +++++++++++++++++++++++++- gdb/testsuite/gdb.arch/break-asm-x86-file.c | 16 ++++ gdb/testsuite/gdb.arch/break-asm-x86-file.exp | 39 ++++++++ gdb/testsuite/gdb.arch/break-asm-x86-file0.s | 15 +++ 4 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.arch/break-asm-x86-file.c create mode 100644 gdb/testsuite/gdb.arch/break-asm-x86-file.exp create mode 100644 gdb/testsuite/gdb.arch/break-asm-x86-file0.s diff --git a/gdb/linespec.c b/gdb/linespec.c index 8a2c8e3..2592f37 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); @@ -1628,6 +1631,80 @@ linespec_parse_basic (linespec_parser *parser) 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 != NULL) + { + 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 != NULL) + { + int ims; + bound_minimal_symbol_d *minsym; + VEC (symbolp) *ignore_symbols; + VEC (bound_minimal_symbol_d) *minimal_syms; + + find_linespec_symbols (PARSER_STATE (parser), + file_symtabs, name, + &ignore_symbols, &minimal_syms); + + /* 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 (ignore_symbols) + VEC_free(symbolp, ignore_symbols); + + /* Copy information about function/method from minimal_syms + to minimal_symbols vector. */ + if (minimal_syms != NULL) + { + for (ims = 0; + VEC_iterate (bound_minimal_symbol_d, minimal_syms, + ims, minsym); + ++ims) + VEC_safe_push (bound_minimal_symbol_d, + minimal_symbols, minsym); + + VEC_free (bound_minimal_symbol_d, minimal_syms); + } + VEC_free (symtab_ptr, file_symtabs); + } + } + if (symbols != NULL || minimal_symbols != NULL) { PARSER_RESULT (parser)->function_symbols = symbols; @@ -2059,7 +2136,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 +2414,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 +3493,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. */ + if (ls->source_filename != NULL) + { + int ix; + struct symtab *elt; + 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 != NULL) + { + const char *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 +3555,8 @@ 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); } diff --git a/gdb/testsuite/gdb.arch/break-asm-x86-file.c b/gdb/testsuite/gdb.arch/break-asm-x86-file.c new file mode 100644 index 0000000..ebaaa72 --- /dev/null +++ b/gdb/testsuite/gdb.arch/break-asm-x86-file.c @@ -0,0 +1,16 @@ +void func2(); + +static func() +{ +} + +void func1() +{ + func2(); + func(); +} + +int main() +{ + func1(); +} diff --git a/gdb/testsuite/gdb.arch/break-asm-x86-file.exp b/gdb/testsuite/gdb.arch/break-asm-x86-file.exp new file mode 100644 index 0000000..db304c5 --- /dev/null +++ b/gdb/testsuite/gdb.arch/break-asm-x86-file.exp @@ -0,0 +1,39 @@ +# Copyright 2012-2014 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Bug 17394 +# Test for break-point at a global function only for a selected ASM file. + +standard_testfile .c +set execfile $testfile +set asm_file break-asm-x86-file0.s + +if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } then { + verbose "Skipping ${testfile}." + return +} + +if {[prepare_for_testing ${testfile}.exp $execfile \ + [list $asm_file $srcfile ] \ + {debug nowarnings optimize=-O0}]} { + untested "Skipping ${testfile}." + return +} + +clean_restart $execfile + +gdb_test "break $asm_file:func" \ + "Breakpoint 1 at 0x\[0-9a-fA-F\]+: file .*$asm_file, line 15\\\." \ + "set a break-point at a global function only for a selected ASM file." diff --git a/gdb/testsuite/gdb.arch/break-asm-x86-file0.s b/gdb/testsuite/gdb.arch/break-asm-x86-file0.s new file mode 100644 index 0000000..f6dd0c0 --- /dev/null +++ b/gdb/testsuite/gdb.arch/break-asm-x86-file0.s @@ -0,0 +1,15 @@ + .section .text + + .global _func2 +_func2: + .global func2 + .type func2, @function +func2: + ret + + .global _func +_func: + .global func + .type func, @function +func: + ret