From b0f4b84b5c44685c7880e9e3e013314590662a17 Mon Sep 17 00:00:00 2001 From: Daniel Jacobowitz Date: Mon, 2 Jul 2007 21:29:28 +0000 Subject: * infrun.c (inferior_ignoring_startup_exec_events): Delete. (start_remote): Use STOP_QUIETLY_REMOTE. (handle_inferior_event): Do not condition TARGET_WAITKIND_LOADED support on a SOLIB_ADD definition. Update breakpoints_inserted. Update to match shared library event breakpoint support. Only resume if appropriate. Handle STOP_QUIETLY_REMOTE. (normal_stop): Handle TARGET_WAITKIND_LOADED. * fork-child.c (startup_inferior): Do not set inferior_ignoring_startup_exec_events * inferior.h (inferior_ignoring_startup_exec_events): Delete declaration. (enum stop_kind): Improve documentation. Add STOP_QUIETLY_REMOTE. * config/gdbserver.exp (gdb_reconnect): New. * gdb.base/so-disc-shr.c, gdb.base/solib-disc.c, gdb.base/solib-disc.exp: New files. * lib/gdb.exp (gdb_test_multiple): Allow tests to match "Ending remote debugging". (gdb_compile): Add shlib_load flag. * lib/gdbserver-support.exp (gdbserver_run): Save the protocol and port. (gdbserver_reconnect): New. --- gdb/ChangeLog | 15 +++++ gdb/fork-child.c | 4 -- gdb/inferior.h | 26 +++----- gdb/infrun.c | 79 +++++++++++++++++++----- gdb/testsuite/ChangeLog | 12 ++++ gdb/testsuite/config/gdbserver.exp | 4 ++ gdb/testsuite/gdb.base/so-disc-shr.c | 25 ++++++++ gdb/testsuite/gdb.base/solib-disc.c | 57 +++++++++++++++++ gdb/testsuite/gdb.base/solib-disc.exp | 104 ++++++++++++++++++++++++++++++++ gdb/testsuite/lib/gdb.exp | 17 +++++- gdb/testsuite/lib/gdbserver-support.exp | 18 +++++- 11 files changed, 319 insertions(+), 42 deletions(-) create mode 100644 gdb/testsuite/gdb.base/so-disc-shr.c create mode 100644 gdb/testsuite/gdb.base/solib-disc.c create mode 100644 gdb/testsuite/gdb.base/solib-disc.exp (limited to 'gdb') diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 799bbde..3a517a9 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,18 @@ +2007-07-02 Daniel Jacobowitz + + * infrun.c (inferior_ignoring_startup_exec_events): Delete. + (start_remote): Use STOP_QUIETLY_REMOTE. + (handle_inferior_event): Do not condition TARGET_WAITKIND_LOADED + support on a SOLIB_ADD definition. Update breakpoints_inserted. + Update to match shared library event breakpoint support. Only + resume if appropriate. Handle STOP_QUIETLY_REMOTE. + (normal_stop): Handle TARGET_WAITKIND_LOADED. + * fork-child.c (startup_inferior): Do not set + inferior_ignoring_startup_exec_events + * inferior.h (inferior_ignoring_startup_exec_events): Delete + declaration. + (enum stop_kind): Improve documentation. Add STOP_QUIETLY_REMOTE. + 2007-07-02 Markus Deuling * breakpoint.c (insert_bp_location): Remove dead code diff --git a/gdb/fork-child.c b/gdb/fork-child.c index c9b3c96..6b01647 100644 --- a/gdb/fork-child.c +++ b/gdb/fork-child.c @@ -414,10 +414,6 @@ startup_inferior (int ntraps) init_wait_for_inferior (); - if (STARTUP_WITH_SHELL) - inferior_ignoring_startup_exec_events = ntraps; - else - inferior_ignoring_startup_exec_events = 0; inferior_ignoring_leading_exec_events = target_reported_exec_events_per_exec_call () - 1; diff --git a/gdb/inferior.h b/gdb/inferior.h index a18943e..39d3134 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -124,20 +124,7 @@ extern int target_executing; redisplay the prompt until the execution is actually over. */ extern int sync_execution; -/* This is only valid when inferior_ptid is non-zero. - - If this is 0, then exec events should be noticed and responded to - by the debugger (i.e., be reported to the user). - - If this is > 0, then that many subsequent exec events should be - ignored (i.e., not be reported to the user). - */ -extern int inferior_ignoring_startup_exec_events; - -/* This is only valid when inferior_ignoring_startup_exec_events is - zero. - - Some targets (stupidly) report more than one exec event per actual +/* Some targets (stupidly) report more than one exec event per actual call to an event() system call. If only the last such exec event need actually be noticed and responded to by the debugger (i.e., be reported to the user), then this is the number of "leading" @@ -351,10 +338,12 @@ extern enum step_over_calls_kind step_over_calls; extern int step_multi; -/* Nonzero means expecting a trap and caller will handle it - themselves. It is used when running in the shell before the child - program has been exec'd; and when running some kinds of remote - stuff (FIXME?). */ +/* Anything but NO_STOP_QUIETLY means we expect a trap and the caller + will handle it themselves. STOP_QUIETLY is used when running in + the shell before the child program has been exec'd and when running + through shared library loading. STOP_QUIETLY_REMOTE is used when + setting up a remote connection; it is like STOP_QUIETLY_NO_SIGSTOP + except that there is no need to hide a signal. */ /* It is also used after attach, due to attaching to a process. This is a bit trickier. When doing an attach, the kernel stops the @@ -378,6 +367,7 @@ enum stop_kind { NO_STOP_QUIETLY = 0, STOP_QUIETLY, + STOP_QUIETLY_REMOTE, STOP_QUIETLY_NO_SIGSTOP }; diff --git a/gdb/infrun.c b/gdb/infrun.c index 346e6c8..b7c0b70 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -84,7 +84,6 @@ static int prepare_to_proceed (void); void _initialize_infrun (void); -int inferior_ignoring_startup_exec_events = 0; int inferior_ignoring_leading_exec_events = 0; /* When set, stop the 'step' command if we enter a function which has @@ -828,7 +827,7 @@ start_remote (int from_tty) { init_thread_list (); init_wait_for_inferior (); - stop_soon = STOP_QUIETLY; + stop_soon = STOP_QUIETLY_REMOTE; trap_expected = 0; /* Always go on waiting for the target, regardless of the mode. */ @@ -1297,16 +1296,22 @@ handle_inferior_event (struct execution_control_state *ecs) case TARGET_WAITKIND_LOADED: if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_LOADED\n"); - /* Ignore gracefully during startup of the inferior, as it - might be the shell which has just loaded some objects, - otherwise add the symbols for the newly loaded objects. */ -#ifdef SOLIB_ADD + /* Ignore gracefully during startup of the inferior, as it might + be the shell which has just loaded some objects, otherwise + add the symbols for the newly loaded objects. Also ignore at + the beginning of an attach or remote session; we will query + the full list of libraries once the connection is + established. */ if (stop_soon == NO_STOP_QUIETLY) { + int breakpoints_were_inserted; + /* Remove breakpoints, SOLIB_ADD might adjust breakpoint addresses via breakpoint_re_set. */ + breakpoints_were_inserted = breakpoints_inserted; if (breakpoints_inserted) remove_breakpoints (); + breakpoints_inserted = 0; /* Check for any newly added shared libraries if we're supposed to be adding them automatically. Switch @@ -1328,17 +1333,50 @@ handle_inferior_event (struct execution_control_state *ecs) exec/process stratum, instead relying on the target stack to propagate relevant changes (stop, section table changed, ...) up to other layers. */ +#ifdef SOLIB_ADD SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); +#else + solib_add (NULL, 0, ¤t_target, auto_solib_add); +#endif target_terminal_inferior (); + /* Try to reenable shared library breakpoints, additional + code segments in shared libraries might be mapped in now. */ + re_enable_breakpoints_in_shlibs (); + + /* If requested, stop when the dynamic linker notifies + gdb of events. This allows the user to get control + and place breakpoints in initializer routines for + dynamically loaded objects (among other things). */ + if (stop_on_solib_events) + { + stop_stepping (ecs); + return; + } + + /* NOTE drow/2007-05-11: This might be a good place to check + for "catch load". */ + /* Reinsert breakpoints and continue. */ - if (breakpoints_inserted) - insert_breakpoints (); + if (breakpoints_were_inserted) + { + insert_breakpoints (); + breakpoints_inserted = 1; + } } -#endif - resume (0, TARGET_SIGNAL_0); - prepare_to_wait (ecs); - return; + + /* If we are skipping through a shell, or through shared library + loading that we aren't interested in, resume the program. If + we're running the program normally, also resume. But stop if + we're attaching or setting up a remote connection. */ + if (stop_soon == STOP_QUIETLY || stop_soon == NO_STOP_QUIETLY) + { + resume (0, TARGET_SIGNAL_0); + prepare_to_wait (ecs); + return; + } + + break; case TARGET_WAITKIND_SPURIOUS: if (debug_infrun) @@ -1862,7 +1900,8 @@ handle_inferior_event (struct execution_control_state *ecs) && (stop_signal == TARGET_SIGNAL_ILL || stop_signal == TARGET_SIGNAL_SEGV || stop_signal == TARGET_SIGNAL_EMT)) - || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP) + || stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_NO_SIGSTOP + || stop_soon == STOP_QUIETLY_REMOTE) { if (stop_signal == TARGET_SIGNAL_TRAP && stop_after_trap) { @@ -1875,7 +1914,7 @@ handle_inferior_event (struct execution_control_state *ecs) /* This is originated from start_remote(), start_inferior() and shared libraries hook functions. */ - if (stop_soon == STOP_QUIETLY) + if (stop_soon == STOP_QUIETLY || stop_soon == STOP_QUIETLY_REMOTE) { if (debug_infrun) fprintf_unfiltered (gdb_stdlog, "infrun: quietly stopped\n"); @@ -3160,6 +3199,18 @@ Further execution is probably impossible.\n")); switch (bpstat_ret) { case PRINT_UNKNOWN: + /* If we had hit a shared library event breakpoint, + bpstat_print would print out this message. If we hit + an OS-level shared library event, do the same + thing. */ + if (last.kind == TARGET_WAITKIND_LOADED) + { + printf_filtered (_("Stopped due to shared library event\n")); + source_flag = SRC_LINE; /* something bogus */ + do_frame_printing = 0; + break; + } + /* FIXME: cagney/2002-12-01: Given that a frame ID does (or should) carry around the function and does (or should) use that when doing a frame comparison. */ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 928b737..0508519 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2007-07-02 Daniel Jacobowitz + + * config/gdbserver.exp (gdb_reconnect): New. + * gdb.base/so-disc-shr.c, gdb.base/solib-disc.c, + gdb.base/solib-disc.exp: New files. + * lib/gdb.exp (gdb_test_multiple): Allow tests to match "Ending + remote debugging". + (gdb_compile): Add shlib_load flag. + * lib/gdbserver-support.exp (gdbserver_run): Save the protocol and + port. + (gdbserver_reconnect): New. + 2007-07-01 Nick Roberts Daniel Jacobowitz diff --git a/gdb/testsuite/config/gdbserver.exp b/gdb/testsuite/config/gdbserver.exp index 0e7e7b0..eb6068f 100644 --- a/gdb/testsuite/config/gdbserver.exp +++ b/gdb/testsuite/config/gdbserver.exp @@ -81,3 +81,7 @@ proc gdbserver_gdb_load { } { proc gdb_reload { } { return [gdbserver_run ""] } + +proc gdb_reconnect { } { + return [gdbserver_reconnect] +} diff --git a/gdb/testsuite/gdb.base/so-disc-shr.c b/gdb/testsuite/gdb.base/so-disc-shr.c new file mode 100644 index 0000000..e89f91a --- /dev/null +++ b/gdb/testsuite/gdb.base/so-disc-shr.c @@ -0,0 +1,25 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2007 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +#include + +void shrfunc (void) +{ + printf ("in shrfunc\n"); +} diff --git a/gdb/testsuite/gdb.base/solib-disc.c b/gdb/testsuite/gdb.base/solib-disc.c new file mode 100644 index 0000000..7677720 --- /dev/null +++ b/gdb/testsuite/gdb.base/solib-disc.c @@ -0,0 +1,57 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2007 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 2 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, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +#include +#include + +#ifdef __WIN32__ +#include +#define dlopen(name, mode) LoadLibrary (name) +#define dlsym(handle, func) GetProcAddress (handle, func) +#define dlclose(handle) FreeLibrary (handle) +#define dlerror() "an error occurred" +#else +#include +#endif + +int main() +{ + void *handle; + void (*func) (void); + + handle = dlopen (SHLIB_NAME, RTLD_LAZY); + if (!handle) + { + fprintf (stderr, dlerror ()); + exit (1); + } + + func = (void (*)(void)) dlsym (handle, "shrfunc"); + if (!func) + { + fprintf (stderr, dlerror ()); + exit (1); + } + + func (); + + dlclose (handle); + + return 0; +} diff --git a/gdb/testsuite/gdb.base/solib-disc.exp b/gdb/testsuite/gdb.base/solib-disc.exp new file mode 100644 index 0000000..0b9930d --- /dev/null +++ b/gdb/testsuite/gdb.base/solib-disc.exp @@ -0,0 +1,104 @@ +# Copyright 2007 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 2 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, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +# Test connecting and disconnecting at shared library events. + +if {[skip_shlib_tests]} { + return 0 +} + +if { [info proc gdb_reconnect] == "" } { + return 0 +} + +set testfile solib-disc +set libfile so-disc-shr +set srcfile ${testfile}.c +set binfile ${objdir}/${subdir}/${testfile} + +set libsrc "${srcdir}/${subdir}/${libfile}.c" +set libname "${libfile}.so" +set libobj "${objdir}/${subdir}/${libname}" +set execsrc "${srcdir}/${subdir}/${srcfile}" + +remote_exec build "rm -f ${binfile}" + +if [get_compiler_info ${binfile}] { + return -1 +} + +set exec_opts [list debug shlib_load additional_flags=-DSHLIB_NAME\=\"${libname}\"] + +if { [gdb_compile_shlib $libsrc $libobj {debug}] != "" + || [gdb_compile $execsrc ${binfile} executable $exec_opts] != "" } { + return -1 +} + +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir +gdb_load ${binfile} +gdb_load_shlibs $libobj + +if ![runto_main] then { + fail "Can't run to main" + return 0 +} + +gdb_test "set stop-on-solib-events 1" "" + +gdb_test "continue" "Stopped due to shared library event" "continue to load" + +set msg "save \$pc after load" +set saved_pc "" +gdb_test_multiple "print/x \$pc" $msg { + -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" { + set saved_pc $expect_out(1,string) + pass $msg + } +} + +gdb_test "disconnect" "Ending remote debugging\\." "disconnect after load" +if { [gdb_reconnect] == 0 } { + pass "reconnect after load" +} else { + fail "reconnect after load" + return 0 +} + +gdb_test "print/x \$pc" "\\\$$decimal = $saved_pc" "check \$pc after load" + + +gdb_test "continue" "Stopped due to shared library event" "continue to unload" + +set msg "save \$pc after unload" +set saved_pc "" +gdb_test_multiple "print/x \$pc" $msg { + -re "\\\$$decimal = (\[^\r\n\]*)\r\n$gdb_prompt $" { + set saved_pc $expect_out(1,string) + pass $msg + } +} + +gdb_test "disconnect" "Ending remote debugging\\." "disconnect after unload" +if { [gdb_reconnect] == 0 } { + pass "reconnect after unload" +} else { + fail "reconnect after unload" + return 0 +} + +gdb_test "print/x \$pc" "\\\$$decimal = $saved_pc" "check \$pc after unload" diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index d17185d..c87e488 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -671,6 +671,9 @@ proc gdb_test_multiple { command message user_code } { gdb_suppress_entire_file "GDB died"; set result -1; } + } + append code $processed_code + append code { -re "Ending remote debugging.*$gdb_prompt $" { if ![isnative] then { warning "Can`t communicate to remote target." @@ -679,9 +682,6 @@ proc gdb_test_multiple { command message user_code } { gdb_start set result -1 } - } - append code $processed_code - append code { -re "Undefined\[a-z\]* command:.*$gdb_prompt $" { perror "Undefined command \"$command\"." fail "$message" @@ -1543,6 +1543,17 @@ proc gdb_compile {source dest type options} { lappend options "additional_flags=-rpath ${objdir}/${subdir}" } } + } elseif { $opt == "shlib_load" } { + if { ([istarget "*-*-mingw*"] + || [istarget *-*-cygwin*] + || [istarget *-*-pe*] + || [istarget arm*-*-symbianelf*] + || [istarget hppa*-*-hpux*])} { + # Do not need anything. + } else { + lappend new_options "libs=-ldl" + lappend new_options "additional_flags=-Wl,-rpath,\\\$ORIGIN" + } } else { lappend new_options $opt } diff --git a/gdb/testsuite/lib/gdbserver-support.exp b/gdb/testsuite/lib/gdbserver-support.exp index 4d8f049..afe36ee 100644 --- a/gdb/testsuite/lib/gdbserver-support.exp +++ b/gdb/testsuite/lib/gdbserver-support.exp @@ -236,6 +236,9 @@ proc gdbserver_spawn { child_args } { # to it. Return 0 on success, or non-zero on failure. proc gdbserver_run { child_args } { + global gdbserver_protocol + global gdbserver_gdbport + # Kill anything running before we try to start gdbserver, in case # we are sharing a serial connection. global gdb_prompt @@ -252,8 +255,17 @@ proc gdbserver_run { child_args } { } set res [gdbserver_spawn $child_args] - set protocol [lindex $res 0] - set gdbport [lindex $res 1] + set gdbserver_protocol [lindex $res 0] + set gdbserver_gdbport [lindex $res 1] + + return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] +} + +# Reconnect to the previous gdbserver session. + +proc gdbserver_reconnect { } { + global gdbserver_protocol + global gdbserver_gdbport - return [gdb_target_cmd $protocol $gdbport] + return [gdb_target_cmd $gdbserver_protocol $gdbserver_gdbport] } -- cgit v1.1