+2019-04-22 Pedro Alves <palves@redhat.com>
+
+ * solib-svr4.c (svr4_free_objfile_observer): New.
+ (probe_and_action::objfile): New field.
+ (probes_table_htab_remove_objfile_probes)
+ (probes_table_remove_objfile_probes): New functions.
+ (register_solib_event_probe): Add 'objfile' parameter. Store it
+ in the new probe_and_action. Don't store the probe in 'lookup'.
+ (svr4_create_probe_breakpoints): Pass objfile to
+ register_solib_event_probe.
+ (_initialize_svr4_solib): Register a free_objfile observer.
+
2019-04-19 Tom Tromey <tom@tromey.com>
* common/queue.h: Remove.
static int svr4_have_link_map_offsets (void);
static void svr4_relocate_main_executable (void);
static void svr4_free_library_list (void *p_list);
+static void probes_table_remove_objfile_probes (struct objfile *objfile);
/* On SVR4 systems, a list of symbols in the dynamic linker where
GDB can try to place a breakpoint to monitor shared library
CORE_ADDR main_lm;
};
+/* This module's 'free_objfile' observer. */
+
+static void
+svr4_free_objfile_observer (struct objfile *objfile)
+{
+ probes_table_remove_objfile_probes (objfile);
+}
+
/* Implementation for target_so_ops.free_so. */
static void
/* The action. */
enum probe_action action;
+
+ /* The objfile where this probe was found. */
+ struct objfile *objfile;
};
/* Returns a hash code for the probe_and_action referenced by p. */
return pa1->address == pa2->address;
}
+/* Traversal function for probes_table_remove_objfile_probes. */
+
+static int
+probes_table_htab_remove_objfile_probes (void **slot, void *info)
+{
+ probe_and_action *pa = (probe_and_action *) *slot;
+ struct objfile *objfile = (struct objfile *) info;
+
+ if (pa->objfile == objfile)
+ htab_clear_slot (get_svr4_info ()->probes_table, slot);
+
+ return 1;
+}
+
+/* Remove all probes that belong to OBJFILE from the probes table. */
+
+static void
+probes_table_remove_objfile_probes (struct objfile *objfile)
+{
+ svr4_info *info = get_svr4_info ();
+ if (info->probes_table != nullptr)
+ htab_traverse_noresize (info->probes_table,
+ probes_table_htab_remove_objfile_probes, objfile);
+}
+
/* Register a solib event probe and its associated action in the
probes table. */
static void
-register_solib_event_probe (probe *prob, CORE_ADDR address,
+register_solib_event_probe (struct objfile *objfile,
+ probe *prob, CORE_ADDR address,
enum probe_action action)
{
struct svr4_info *info = get_svr4_info ();
equal_probe_and_action,
xfree, xcalloc, xfree);
- lookup.prob = prob;
lookup.address = address;
slot = htab_find_slot (info->probes_table, &lookup, INSERT);
gdb_assert (*slot == HTAB_EMPTY_ENTRY);
pa->prob = prob;
pa->address = address;
pa->action = action;
+ pa->objfile = objfile;
*slot = pa;
}
CORE_ADDR address = p->get_relocated_address (objfile);
create_solib_event_breakpoint (gdbarch, address);
- register_solib_event_probe (p, address, action);
+ register_solib_event_probe (objfile, p, address, action);
}
}
svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
svr4_so_ops.handle_event = svr4_handle_solib_event;
+
+ gdb::observers::free_objfile.attach (svr4_free_objfile_observer);
}
+2019-04-22 Pedro Alves <palves@redhat.com>
+
+ * gdb.base/solib-probes-nosharedlibrary.c,
+ gdb.base/solib-probes-nosharedlibrary.exp: New files.
+
2019-04-19 Tom Tromey <tromey@adacore.com>
* gdb.ada/ptype_union.c: New file.
--- /dev/null
+/* This testcase is part of GDB, the GNU debugger.
+
+ Copyright 2019 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/>. */
+
+int
+main ()
+{
+ return 0;
+}
--- /dev/null
+# Copyright 2005-2019 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/>.
+
+# Regression test for a bug where GDB would misbehave (most likely
+# crash) if you ran the "nosharelibrary" command, continued execution,
+# and then the program hit the shared library event breakpoint. GDB
+# would deference a dangling solib event probe pointer.
+
+standard_testfile
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+ return -1
+}
+
+if {$use_gdb_stub && [target_info exists gdb,do_reload_on_run]} {
+ # This is the path taken by gdbserver "target remote" boards.
+ if { [gdb_reload] != 0 } {
+ untested "could not run to initial instruction"
+ return
+ }
+ pass "stopped at entry"
+} else {
+ if { [gdb_starti_cmd] < 0 } {
+ untested "could not run to initial instruction"
+ return
+ }
+ gdb_test "" "Program stopped.*" "stopped at entry"
+}
+
+# The program should stop at the first instruction, before the shared
+# library event breakpoint is first hit. On systems where probes are
+# present in the dynamic linker, such as GNU/Linux, discarding all
+# shared libraries discards such probes too. The probes-based
+# interface can no longer be used.
+gdb_test_no_output "nosharedlibrary"
+
+# Continue to main(), past the solib event.
+gdb_breakpoint main
+gdb_continue_to_breakpoint "main"