From 1c8cdcb14fe619a64accf1cc11d5d7009d76c748 Mon Sep 17 00:00:00 2001 From: Jan Kratochvil Date: Mon, 27 Aug 2012 16:55:39 +0000 Subject: [PATCH] gdb/ * breakpoint.c (parse_breakpoint_sals) <(*address) == NULL>: New variable pc. Call find_pc_line instead of find_pc_overlay, restore original PC for it. gdb/testsuite/ * gdb.base/break-caller-line.c: New file. * gdb.base/break-caller-line.exp: New file. --- gdb/ChangeLog | 6 +++ gdb/breakpoint.c | 10 +++- gdb/testsuite/ChangeLog | 5 ++ gdb/testsuite/gdb.base/break-caller-line.c | 31 +++++++++++ gdb/testsuite/gdb.base/break-caller-line.exp | 55 ++++++++++++++++++++ 5 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 gdb/testsuite/gdb.base/break-caller-line.c create mode 100644 gdb/testsuite/gdb.base/break-caller-line.exp diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 1b478ea8f9..e20414ba2a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2012-08-27 Jan Kratochvil + + * breakpoint.c (parse_breakpoint_sals) <(*address) == NULL>: New + variable pc. Call find_pc_line instead of find_pc_overlay, restore + original PC for it. + 2012-08-27 Eli Zaretskii Jan Kratochvil diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index b2a00be020..b074ecc4ee 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -9126,21 +9126,27 @@ parse_breakpoint_sals (char **address, { struct linespec_sals lsal; struct symtab_and_line sal; + CORE_ADDR pc; init_sal (&sal); /* Initialize to zeroes. */ lsal.sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line)); /* Set sal's pspace, pc, symtab, and line to the values - corresponding to the last call to print_frame_info. */ + corresponding to the last call to print_frame_info. + Be sure to reinitialize LINE with NOTCURRENT == 0 + as the breakpoint line number is inappropriate otherwise. + find_pc_line would adjust PC, re-set it back. */ get_last_displayed_sal (&sal); - sal.section = find_pc_overlay (sal.pc); + pc = sal.pc; + sal = find_pc_line (pc, 0); /* "break" without arguments is equivalent to "break *PC" where PC is the last displayed codepoint's address. So make sure to set sal.explicit_pc to prevent GDB from trying to expand the list of sals to include all other instances with the same symtab and line. */ + sal.pc = pc; sal.explicit_pc = 1; lsal.sals.sals[0] = sal; diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 13937de7e2..0a3d01a1ce 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-08-27 Jan Kratochvil + + * gdb.base/break-caller-line.c: New file. + * gdb.base/break-caller-line.exp: New file. + 2012-08-27 Jan Kratochvil * gdb.ada/rdv_wait.exp (set debug-file-directory): New command. diff --git a/gdb/testsuite/gdb.base/break-caller-line.c b/gdb/testsuite/gdb.base/break-caller-line.c new file mode 100644 index 0000000000..59d15ee296 --- /dev/null +++ b/gdb/testsuite/gdb.base/break-caller-line.c @@ -0,0 +1,31 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2012 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 . */ + +static int v; + +static void +callee (void) +{ + v++; +} + +int +main (void) +{ + callee (); + return 0; +} diff --git a/gdb/testsuite/gdb.base/break-caller-line.exp b/gdb/testsuite/gdb.base/break-caller-line.exp new file mode 100644 index 0000000000..45abe47686 --- /dev/null +++ b/gdb/testsuite/gdb.base/break-caller-line.exp @@ -0,0 +1,55 @@ +# Copyright (C) 2012 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 . + +standard_testfile + +if { [prepare_for_testing ${testfile}.exp ${testfile}] } { + return -1 +} + +if ![runto callee] { + return 0 +} + +set test "up" +gdb_test_multiple $test $test { + -re "\r\n(\[0-9\]+)\[ \t\]+callee \\(\\);\r\n$gdb_prompt $" { + set notcurrent $expect_out(1,string) + pass $test + } +} + +set test {info line *$pc} +gdb_test_multiple $test $test { + -re "\r\nLine (\[0-9\]+) of .*\r\n$gdb_prompt $" { + set current $expect_out(1,string) + pass $test + } +} + +if {$notcurrent == $current} { + untested "target arch has an instruction after call as part of the caller line" + return 0 +} + +set test "break" +gdb_test_multiple $test $test { + -re "\r\nBreakpoint \[0-9\]+ at .*, line $current\\.\r\n$gdb_prompt $" { + pass $test + } + -re "\r\nBreakpoint \[0-9\]+ at .*, line $notcurrent\\.\r\n$gdb_prompt $" { + fail "$test (caller line)" + } +}