diff options
author | Doug Evans <dje@google.com> | 2008-02-08 00:42:07 +0000 |
---|---|---|
committer | Doug Evans <dje@google.com> | 2008-02-08 00:42:07 +0000 |
commit | 776592bf173a191aa5d142808ca9164fd243c0ce (patch) | |
tree | de93b4f22843af0ac994cdb88997e54683932eca /gdb | |
parent | b29242315eb0d6694d66d75895116361e20c8003 (diff) | |
download | gdb-776592bf173a191aa5d142808ca9164fd243c0ce.zip gdb-776592bf173a191aa5d142808ca9164fd243c0ce.tar.gz gdb-776592bf173a191aa5d142808ca9164fd243c0ce.tar.bz2 |
* breakpoint.c: #include "hashtab.h".
(ambiguous_names_p): New fn.
(update_breakpoint_locations): When restoring bp enable status, don't
compare function names if any functions have same name.
* Makefile.in (breakpoint.o): Add hashtab.h dependency.
* gdb.cp/mb-inline.exp: New.
* gdb.cp/mb-inline.h: New.
* gdb.cp/mb-inline1.cc: New.
* gdb.cp/mb-inline2.cc: New.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 8 | ||||
-rw-r--r-- | gdb/Makefile.in | 2 | ||||
-rw-r--r-- | gdb/breakpoint.c | 71 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/mb-inline.exp | 108 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/mb-inline.h | 30 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/mb-inline1.cc | 35 | ||||
-rw-r--r-- | gdb/testsuite/gdb.cp/mb-inline2.cc | 25 |
7 files changed, 271 insertions, 8 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 94b53da..ccf13dc 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2008-02-07 Doug Evans <dje@google.com> + + * breakpoint.c: #include "hashtab.h". + (ambiguous_names_p): New fn. + (update_breakpoint_locations): When restoring bp enable status, don't + compare function names if any functions have same name. + * Makefile.in (breakpoint.o): Add hashtab.h dependency. + 2008-02-07 Joel Brobecker <brobecker@adacore.com> * ada-lang.c (symbol_completion_add): Make SV parameter a VEC** diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 38c5fe2..a471f8e 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1950,7 +1950,7 @@ breakpoint.o: breakpoint.c $(defs_h) $(symtab_h) $(frame_h) $(breakpoint_h) \ $(objfiles_h) $(source_h) $(linespec_h) $(completer_h) $(gdb_h) \ $(ui_out_h) $(cli_script_h) $(gdb_assert_h) $(block_h) $(solib_h) \ $(solist_h) $(observer_h) $(exceptions_h) $(gdb_events_h) \ - $(mi_common_h) $(memattr_h) $(ada_lang_h) $(top_h) + $(mi_common_h) $(memattr_h) $(ada_lang_h) $(top_h) $(hashtab_h) bsd-kvm.o: bsd-kvm.c $(defs_h) $(cli_cmds_h) $(command_h) $(frame_h) \ $(regcache_h) $(target_h) $(value_h) $(gdbcore_h) $(gdb_assert_h) \ $(readline_h) $(bsd_kvm_h) diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c index c2bf50a..dca4ca1 100644 --- a/gdb/breakpoint.c +++ b/gdb/breakpoint.c @@ -21,6 +21,7 @@ #include "defs.h" #include <ctype.h> +#include "hashtab.h" #include "symtab.h" #include "frame.h" #include "breakpoint.h" @@ -7081,6 +7082,43 @@ all_locations_are_pending (struct bp_location *loc) return 1; } +/* Subroutine of update_breakpoint_locations to simplify it. + Return non-zero if multiple fns in list LOC have the same name. + Null names are ignored. */ + +static int +ambiguous_names_p (struct bp_location *loc) +{ + struct bp_location *l; + htab_t htab = htab_create_alloc (13, htab_hash_string, + (int (*) (const void *, const void *)) streq, + NULL, xcalloc, xfree); + + for (l = loc; l != NULL; l = l->next) + { + const char **slot; + const char *name = l->function_name; + + /* Allow for some names to be NULL, ignore them. */ + if (name == NULL) + continue; + + slot = (const char **) htab_find_slot (htab, (const void *) name, + INSERT); + /* NOTE: We can assume slot != NULL here because xcalloc never returns + NULL. */ + if (*slot != NULL) + { + htab_delete (htab); + return 1; + } + *slot = name; + } + + htab_delete (htab); + return 0; +} + static void update_breakpoint_locations (struct breakpoint *b, struct symtabs_and_lines sals) @@ -7143,18 +7181,37 @@ update_breakpoint_locations (struct breakpoint *b, /* If possible, carry over 'disable' status from existing breakpoints. */ { struct bp_location *e = existing_locations; + /* If there are multiple breakpoints with the same function name, + e.g. for inline functions, comparing function names won't work. + Instead compare pc addresses; this is just a heuristic as things + may have moved, but in practice it gives the correct answer + often enough until a better solution is found. */ + int have_ambiguous_names = ambiguous_names_p (b->loc); + for (; e; e = e->next) { if (!e->enabled && e->function_name) { struct bp_location *l = b->loc; - for (; l; l = l->next) - if (l->function_name - && strcmp (e->function_name, l->function_name) == 0) - { - l->enabled = 0; - break; - } + if (have_ambiguous_names) + { + for (; l; l = l->next) + if (e->address == l->address) + { + l->enabled = 0; + break; + } + } + else + { + for (; l; l = l->next) + if (l->function_name + && strcmp (e->function_name, l->function_name) == 0) + { + l->enabled = 0; + break; + } + } } } } diff --git a/gdb/testsuite/gdb.cp/mb-inline.exp b/gdb/testsuite/gdb.cp/mb-inline.exp new file mode 100644 index 0000000..1331a75 --- /dev/null +++ b/gdb/testsuite/gdb.cp/mb-inline.exp @@ -0,0 +1,108 @@ +# Copyright 2008 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 <http://www.gnu.org/licenses/>. + +# This file is part of the gdb testsuite. + +# This test verifies that setting breakpoint on line in inline +# function will fire in all instantiations of that function. + +if $tracelevel then { + strace $tracelevel +} + +if { [skip_cplus_tests] } { continue } + +set prms_id 0 +set bug_id 0 + +set testfile "mb-inline" +set hdrfile "${testfile}.h" +set srcfile1 "${testfile}1.cc" +set objfile1 "${testfile}1.o" +set srcfile2 "${testfile}2.cc" +set objfile2 "${testfile}2.o" +set binfile "${objdir}/${subdir}/${testfile}" + +if { [gdb_compile "$srcdir/$subdir/$srcfile1" "$objdir/$subdir/$objfile1" object {debug c++}] != "" } { + untested mb-inline.exp + return -1 +} + +if { [gdb_compile "$srcdir/$subdir/$srcfile2" "$objdir/$subdir/$objfile2" object {debug c++}] != "" } { + untested mb-inline.exp + return -1 +} + +if { [gdb_compile "$objdir/$subdir/$objfile1 $objdir/$subdir/$objfile2" "${binfile}" executable {debug c++}] != "" } { + untested mb-inline.exp + return -1 +} + +if [get_compiler_info ${binfile} "c++"] { + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} + +set bp_location [gdb_get_line_number "set breakpoint here" $hdrfile] + +# Set a breakpoint with multiple locations. + +gdb_test "break $hdrfile:$bp_location" \ + "Breakpoint.*at.* file .*$hdrfile, line.*\\(2 locations\\).*" \ + "set breakpoint" + +gdb_run_cmd +gdb_expect { + -re "Breakpoint \[0-9\]+,.*foo \\(i=0\\).*$gdb_prompt $" { + pass "run to breakpoint" + } + -re "$gdb_prompt $" { + fail "run to breakpoint" + } + timeout { + fail "run to breakpoint (timeout)" + } +} + +gdb_test "continue" \ + ".*Breakpoint.*foo \\(i=1\\).*" \ + "run to breakpoint 2" + +# Try disabling a single location. We also test +# that at least in simple cases, the enable/disable +# state of locations survive "run". +# Early bug would disable 1.1 and enable 1.2 when program is run. +gdb_test "disable 1.2" "" "disabling location: disable" + +gdb_run_cmd +gdb_expect { + -re "Breakpoint \[0-9\]+,.*foo \\(i=0\\).*$gdb_prompt $" { + pass "disabling location: run to breakpoint" + } + -re "$gdb_prompt $" { + fail "disabling location: run to breakpoint" + } + timeout { + fail "disabling location: run to breakpoint (timeout)" + } +} + +gdb_test "continue" \ + ".*Program exited normally.*" \ + "continue with disabled breakpoint 1.2" diff --git a/gdb/testsuite/gdb.cp/mb-inline.h b/gdb/testsuite/gdb.cp/mb-inline.h new file mode 100644 index 0000000..bc910a6 --- /dev/null +++ b/gdb/testsuite/gdb.cp/mb-inline.h @@ -0,0 +1,30 @@ +/* Test gdb support for setting multiple file:line breakpoints on static + functions. In practice the functions may be inline fns compiled with -O0. + We avoid using inline here for simplicity's sake. + + This testcase is part of GDB, the GNU debugger. + + Copyright 2008 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 <http://www.gnu.org/licenses/>. + */ + +static int +foo (int i) +{ + return i; // set breakpoint here +} + +extern int afn (); +extern int bfn (); diff --git a/gdb/testsuite/gdb.cp/mb-inline1.cc b/gdb/testsuite/gdb.cp/mb-inline1.cc new file mode 100644 index 0000000..0945269 --- /dev/null +++ b/gdb/testsuite/gdb.cp/mb-inline1.cc @@ -0,0 +1,35 @@ +/* Test gdb support for setting file:line breakpoints on inline fns. + + This testcase is part of GDB, the GNU debugger. + + Copyright 2008 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 <http://www.gnu.org/licenses/>. + */ + +#include "mb-inline.h" + +int +afn () +{ + return foo (0); +} + +int +main () +{ + int a = afn (); + int b = bfn (); + return a * b; +} diff --git a/gdb/testsuite/gdb.cp/mb-inline2.cc b/gdb/testsuite/gdb.cp/mb-inline2.cc new file mode 100644 index 0000000..bad0b88 --- /dev/null +++ b/gdb/testsuite/gdb.cp/mb-inline2.cc @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2008 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 <http://www.gnu.org/licenses/>. + */ + +#include "mb-inline.h" + +int +bfn () +{ + return foo (1); +} |